package common import ( "encoding/json" "testing" goproto "gac-hkrpg-go/protocol/proto" "google.golang.org/protobuf/proto" ) func TestStandaloneBattleRelicWire(t *testing.T) { relic := Relic{ RelicID: 61151, Level: 15, MainAffixID: 1, InternalUID: 42, SubAffixes: []SubAffix{{SubAffixID: 7, Count: 3, Step: 3}, {SubAffixID: 8, Count: 3, Step: 0}}, } encoded, err := proto.Marshal(relic.ToBattleRelic()) if err != nil { t.Fatal(err) } var decoded goproto.BattleRelic if err := proto.Unmarshal(encoded, &decoded); err != nil { t.Fatal(err) } if decoded.UniqueId != 0 { t.Fatal("standalone battle relic must not use inventory ID") } if decoded.Id != 61151 || decoded.MainAffixId != 1 || len(decoded.SubAffixList) != 2 { t.Fatalf("relic or affixes lost on wire: %v", &decoded) } if decoded.SubAffixList[0].Cnt != 3 || decoded.SubAffixList[0].Step != 3 || decoded.SubAffixList[1].Step != 0 { t.Fatalf("sub-affix values changed on wire: %v", decoded.SubAffixList) } if relic.ToProtoRelic().UniqueId != 42 || relic.ToEquipRelic().RelicUniqueId != 42 { t.Fatal("inventory and equipped relic references must retain their IDs") } } func TestAvatarPathSkillTreePointIds(t *testing.T) { // 1. avatar with explicit Skills map uses real PointIDs directly av := AvatarJson{ AvatarID: 1213, Data: AvatarData{ Rank: 0, Skills: map[uint32]uint32{ 1213001: 6, 1213002: 10, }, SkillsByAnchorType: map[uint32]uint32{ 1: 6, 2: 10, }, }, } proto := av.ToAvatarPathDataProto(nil, nil, 0) if len(proto.AvatarPathSkillTree) != 2 { t.Fatalf("expected 2 skill tree nodes, got %d", len(proto.AvatarPathSkillTree)) } if proto.AvatarPathSkillTree[0].PointId != 1213001 || proto.AvatarPathSkillTree[1].PointId != 1213002 { t.Fatalf("point ids must be real config point IDs, got %v", proto.AvatarPathSkillTree) } // 2. avatar with only SkillsByAnchorType resolves from AvatarSkillTreeConfig.json avAnchorOnly := AvatarJson{ AvatarID: 1001, Data: AvatarData{ Rank: 0, SkillsByAnchorType: map[uint32]uint32{ 1: 6, }, }, } protoAnchor := avAnchorOnly.ToAvatarPathDataProto(nil, nil, 0) if len(protoAnchor.AvatarPathSkillTree) != 1 { t.Fatalf("expected 1 skill tree node, got %d", len(protoAnchor.AvatarPathSkillTree)) } if protoAnchor.AvatarPathSkillTree[0].PointId != 1001001 { t.Fatalf("expected resolved point ID 1001001 for March Point01, got %d", protoAnchor.AvatarPathSkillTree[0].PointId) } } func TestSubAffixUnmarshal(t *testing.T) { var sub1 SubAffix if err := json.Unmarshal([]byte(`{"sub_affix_id": 7, "cnt": 4, "step": 2}`), &sub1); err != nil { t.Fatal(err) } if sub1.Count != 4 || sub1.SubAffixID != 7 || sub1.Step != 2 { t.Fatalf("cnt alias failed: %+v", sub1) } var sub2 SubAffix if err := json.Unmarshal([]byte(`{"sub_affix_id": 8, "count": 3, "step": 1}`), &sub2); err != nil { t.Fatal(err) } if sub2.Count != 3 || sub2.SubAffixID != 8 || sub2.Step != 1 { t.Fatalf("count parsing failed: %+v", sub2) } }