server/gamedata/npc_combat_test.go (5916B)
1 package gamedata 2 3 import ( 4 "maps" 5 "slices" 6 "testing" 7 ) 8 9 func TestNPCLevelAnchorsResolveBoundedIndependentProfiles(t *testing.T) { 10 first := &NPCCombatProfile{TemplateCodes: []string{"SN01", "SN02"}, Groups: []string{"selected"}, Health: 125, Experience: 125, Skills: map[uint32]int32{100: 10}, 11 Modifiers: map[uint32]int32{276: 3, 277: -3}, Loot: []NPCLoot{{Template: 42640, Quality: [2]uint32{2, 4}, Chance: 50}}} 12 second := &NPCCombatProfile{TemplateCodes: []string{"SN01", "SN02"}, Groups: []string{"selected"}, Health: 175, Experience: 175, Skills: map[uint32]int32{100: 20}, 13 Modifiers: map[uint32]int32{276: 8, 277: -8}, Loot: []NPCLoot{{Template: 42640, Quality: [2]uint32{4, 6}, Chance: 50}}} 14 profiles := map[uint32]map[uint16]*NPCCombatProfile{17655: {3: first, 5: second}} 15 16 err := interpolateNPCProfiles(profiles) 17 profile := profiles[17655][4] 18 19 if err != nil || len(profiles[17655]) != 3 || profile == nil || profile.Health != 150 || profile.Experience != 150 || 20 profile.Skills[100] != 15 || profile.Modifiers[276] != 5 || profile.Modifiers[277] != -5 || profile.Loot[0].Quality != [2]uint32{3, 5} { 21 t.Fatal("bounded interpolation changed numeric rounding or omitted a foundation", profile, err) 22 } 23 profile.Skills[100], profile.Modifiers[276], profile.Loot[0].Quality[0], profile.TemplateCodes[0] = 99, 99, 99, "other" 24 profile.Groups[0] = "other" 25 if first.Skills[100] != 10 || second.Skills[100] != 20 || first.Modifiers[276] != 3 || second.Modifiers[276] != 8 || 26 first.Loot[0].Quality != [2]uint32{2, 4} || second.Loot[0].Quality != [2]uint32{4, 6} || 27 !slices.Equal(first.TemplateCodes, []string{"SN01", "SN02"}) || !slices.Equal(second.TemplateCodes, []string{"SN01", "SN02"}) || 28 first.Groups[0] != "selected" || second.Groups[0] != "selected" { 29 t.Fatal("resolved profile shares mutable data with an anchor") 30 } 31 } 32 33 func TestNPCLevelAnchorsRejectAmbiguousIntermediateIdentity(t *testing.T) { 34 for _, change := range []string{"template", "group", "weapon", "initiative", "aggdef", "respawn", "corpse", "cash", "loot count", "loot template", "loot chance", "loot evidence", "loot inference", "skill count", "skill identity", "modifier identity"} { 35 t.Run(change, func(t *testing.T) { 36 first := &NPCCombatProfile{Health: 100, Skills: map[uint32]int32{100: 5}, Modifiers: map[uint32]int32{276: 5}, 37 Loot: []NPCLoot{{Template: 42640, Quality: [2]uint32{1, 1}, Chance: 50}}} 38 second := *first 39 switch change { 40 case "template": 41 second.TemplateCodes = []string{"other"} 42 case "group": 43 second.Groups = []string{"other"} 44 case "weapon": 45 second.Weapon = [2]uint32{120910, 120911} 46 case "initiative": 47 second.Initiative = 1 48 case "aggdef": 49 second.AggDef = 1 50 case "respawn": 51 second.RespawnSeconds = 1 52 case "corpse": 53 second.CorpseSeconds = 1 54 case "cash": 55 second.Credits = [2]uint32{1, 5} 56 case "loot count": 57 second.Loot = nil 58 case "loot template": 59 second.Loot = []NPCLoot{{Template: 85596, Quality: [2]uint32{1, 1}, Chance: 50}} 60 case "loot chance": 61 second.Loot = []NPCLoot{{Template: 42640, Quality: [2]uint32{1, 1}, Chance: 100}} 62 case "loot evidence": 63 second.Loot = slices.Clone(first.Loot) 64 second.Loot[0].Evidence = "different observation" 65 case "loot inference": 66 second.Loot = slices.Clone(first.Loot) 67 second.Loot[0].Inference = "different assumption" 68 case "skill count": 69 second.Skills = nil 70 case "skill identity": 71 second.Skills = map[uint32]int32{155: 5} 72 case "modifier identity": 73 second.Modifiers = map[uint32]int32{277: 5} 74 } 75 profiles := map[uint32]map[uint16]*NPCCombatProfile{17655: {3: first, 5: &second}} 76 77 err := interpolateNPCProfiles(profiles) 78 79 if err == nil || profiles[17655][4] != nil { 80 t.Fatal("ambiguous anchor acquired an intermediate combat profile", err) 81 } 82 }) 83 } 84 } 85 86 func TestProductionNPCGrowthRetainsBaselineAndStopsAtReviewedBoundary(t *testing.T) { 87 expected := []struct{ health, experience, skill, qualityLow, qualityHigh int32 }{ 88 {20, 100, 5, 1, 1}, {20, 100, 5, 1, 3}, {30, 125, 10, 2, 4}, {40, 150, 15, 3, 5}, {50, 175, 20, 4, 6}, 89 {60, 200, 25, 5, 7}, {70, 225, 30, 6, 8}, {80, 250, 35, 7, 9}, {90, 275, 40, 8, 10}, {100, 300, 45, 9, 11}, 90 } 91 92 profiles := NPCCombatProfiles[17655] 93 94 for index, want := range expected { 95 profile := profiles[uint16(index+1)] 96 if profile == nil || profile.Health != uint32(want.health) || profile.Experience != uint32(want.experience) || 97 !maps.Equal(profile.Skills, map[uint32]int32{100: want.skill, 153: want.skill, 154: want.skill, 155: want.skill, 168: want.skill}) || 98 profile.Loot[0].Quality != [2]uint32{uint32(want.qualityLow), uint32(want.qualityHigh)} || profile.Weapon != [2]uint32{120910, 120911} { 99 t.Fatal("production profile changed the declared bounded growth", index+1, profile) 100 } 101 } 102 if len(profiles) != 10 || profiles[0] != nil || profiles[11] != nil || len(NPCCombatProfiles[30354]) != 1 || !slices.Equal(NPCCombatProfiles[30354][4].TemplateCodes, []string{"BSML"}) { 103 t.Fatal("growth extrapolated beyond its reviewed range or changed boss scope") 104 } 105 } 106 107 func TestTrainingHumanProfilesStayWithinSixReviewedPopulations(t *testing.T) { 108 expected := map[string]bool{ 109 "950/district/1/group/0/authored_point": true, "950/district/3/group/0/authored_point": true, "950/district/4/group/0/authored_point": true, 110 "952/district/2/group/0/authored_point": true, "952/district/3/group/1/authored_point": true, "954/district/4/group/3/spread_authored_point": true, 111 } 112 for _, group := range NPCGroups { 113 if group.Appearance>>4&7 >= 6 { 114 continue 115 } 116 for level := group.Levels[0]; level <= group.Levels[1]; level++ { 117 profile := NPCCombatProfiles[group.MonsterData][level] 118 if group.SupportsCombatProfile(group.MonsterData, profile) != expected[group.ID] { 119 t.Fatal("human combat escaped the reviewed population/level scope", group.ID, level) 120 } 121 } 122 } 123 }