server/minibull_test.go (4348B)
1 package main 2 3 import ( 4 "ao/server/gamedata" 5 "encoding/binary" 6 "slices" 7 "testing" 8 "time" 9 ) 10 11 func TestMinibullPopulationRetainsAuthoredRangeAndNativeWeapon(t *testing.T) { 12 data := testNPCData() 13 data.Playfields[0].ID = 550 14 group := *gamedata.NPCGroups["550/district/4/group/8/spread_authored_point"] 15 data.PlacementStatuses[group.PlacementStatus] = gamedata.NPCs.PlacementStatuses[group.PlacementStatus] 16 data.Playfields[0].Districts[0].Groups[0] = group 17 useNPCData(t, data) 18 world := newTestServer(t) 19 if err := world.flushWorld(); err != nil { 20 t.Fatal(err) 21 } 22 23 cold := newTestInventoryServer(t) 24 25 for _, current := range []*server{world, cold} { 26 for index, position := range group.Positions { 27 npc := current.characters[1000000+uint32(index)] 28 level := uint16(index + 4) 29 if npc.monsterData != 30360 || npc.level != level || npc.position != position || npc.npcDefinitionID != group.ID { 30 t.Fatal("Minibull admission changed the authored population", npc) 31 } 32 if level > 10 { 33 if npc.combatProfile != nil { 34 t.Fatal("Minibull profile extrapolated beyond its supported range", level) 35 } 36 continue 37 } 38 if npc.combatProfile != gamedata.NPCCombatProfiles[30360][level] || npc.health != 40+10*uint32(index) || 39 npc.attackRating() != 15+5*int32(index) || !slices.Equal(npc.combatProfile.TemplateCodes, []string{"MB01"}) { 40 t.Fatal("Minibull population lost its bounded profile", npc.id, npc.combatProfile) 41 } 42 packet := targetPacket(characterPacket(npc)) 43 end := int(binary.BigEndian.Uint16(packet[6:8])) 44 if binary.BigEndian.Uint32(packet[end-16:end-12]) != 120961 || binary.BigEndian.Uint32(packet[end-12:end-8]) != 120962 || 45 binary.BigEndian.Uint32(packet[end-4:end]) != uint32(level) { 46 t.Fatal("native Minibull spawn lost original Headbutt endpoints or actor QL") 47 } 48 } 49 } 50 } 51 52 func TestMinibullAdmissionRejectsOtherCodesBodiesEvidenceAndLevels(t *testing.T) { 53 for _, scenario := range []string{"level1", "level10", "level11", "other code", "other body", "placeholder"} { 54 t.Run(scenario, func(t *testing.T) { 55 data := testNPCData() 56 group := &data.Playfields[0].Districts[0].Groups[0] 57 group.TemplateCode, group.MonsterData, group.Levels, group.AppearanceStatus = "MB01", 30360, [2]uint16{1, 1}, "inferred_species" 58 switch scenario { 59 case "level10": 60 group.Levels = [2]uint16{10, 10} 61 case "level11": 62 group.Levels = [2]uint16{11, 11} 63 case "other code": 64 group.TemplateCode = "MB02" 65 case "other body": 66 group.MonsterData = 17687 67 case "placeholder": 68 group.AppearanceStatus = "placeholder_creature" 69 } 70 useNPCData(t, data) 71 72 world := newTestServer(t) 73 74 npc := world.characters[1000000] 75 if scenario == "level1" || scenario == "level10" { 76 if npc.combatProfile != gamedata.NPCCombatProfiles[30360][group.Levels[0]] { 77 t.Fatal("supported Minibull boundary lost its profile") 78 } 79 } else if npc.combatProfile != nil { 80 t.Fatal("unreviewed Minibull binding inherited the profile", scenario) 81 } 82 }) 83 } 84 } 85 86 func TestMinibullHeadbuttUsesOriginalDamageAndPhases(t *testing.T) { 87 data := testNPCData() 88 group := &data.Playfields[0].Districts[0].Groups[0] 89 group.TemplateCode, group.MonsterData, group.Levels, group.AppearanceStatus = "MB01", 30360, [2]uint16{4, 4}, "inferred_species" 90 useNPCData(t, data) 91 world := newTestServer(t) 92 player := world.newCharacter() 93 player.position = group.Positions[0] 94 world.clients[player.id] = &worldClient{id: player.id, conn: &combatTestConn{}, target: true, ready: true, npcs: map[uint32]bool{1000000: true}} 95 world.combatRoll = landedCombatRoll 96 97 if err := world.handleCombat(world.clients[player.id], attackPacket(player.id, 1000000)[20:]); err != nil { 98 t.Fatal(err) 99 } 100 start := player.nextAttack 101 world.advanceCombat(start) 102 world.advanceCombat(start.Add(2350*time.Millisecond - time.Nanosecond)) 103 if player.health != 34 { 104 t.Fatal("Headbutt landed before its catalog attack phase ended", player.health) 105 } 106 world.advanceCombat(start.Add(2350 * time.Millisecond)) 107 108 npc := world.characters[1000000] 109 if itemStat(npc.attackWeapon(), 286) != 12 || itemStat(npc.attackWeapon(), 285) != 23 || 110 player.health != 11 || npc.nextAttack != start.Add(7050*time.Millisecond) { 111 t.Fatal("Headbutt lost catalog damage or attack/recharge phases", player.health, npc.nextAttack.Sub(start)) 112 } 113 }