aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


server/reet_test.go (5598B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"encoding/binary"
      6 	"fmt"
      7 	"slices"
      8 	"testing"
      9 	"time"
     10 )
     11 
     12 func TestReetStarterPopulationsRetainProfilesAndNativeWeapons(t *testing.T) {
     13 	for _, id := range []string{"950/district/2/group/1/authored_point", "950/district/3/group/2/authored_point", "952/district/0/group/2/authored_point", "952/district/4/group/3/authored_point"} {
     14 		t.Run(id, func(t *testing.T) {
     15 			data := testNPCData()
     16 			data.Playfields[0].Districts[0].Groups[0] = *gamedata.NPCGroups[id]
     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 := range data.Playfields[0].Districts[0].Groups[0].Positions {
     27 					npc := current.characters[1000000+uint32(index)]
     28 					if npc.name != "Reet of Paradise" || npc.monsterData != 30365 || npc.level < 1 || npc.level > 2 ||
     29 						npc.combatProfile == nil || !slices.Equal(npc.combatProfile.TemplateCodes, []string{"RT01", "RT02"}) || npc.maximumHealth() != 20 ||
     30 						npc.health != 20 || npc.attackRating() != 5 || itemStat(npc.attackWeapon(), 286) != 4 ||
     31 						itemStat(npc.attackWeapon(), 285) != uint32(8+npc.level) {
     32 						t.Fatal("original Reet population lost its bounded profile, level or weapon", npc.id, npc.level, npc.combatProfile)
     33 					}
     34 					packet := targetPacket(characterPacket(npc))
     35 					end := int(binary.BigEndian.Uint16(packet[6:8]))
     36 					if binary.BigEndian.Uint32(packet[end-16:end-12]) != 121038 || binary.BigEndian.Uint32(packet[end-12:end-8]) != 121039 ||
     37 						binary.BigEndian.Uint32(packet[end-4:end]) != uint32(npc.level) {
     38 						t.Fatal("native Reet spawn lost its selected-quality Peck weapon")
     39 					}
     40 				}
     41 			}
     42 		})
     43 	}
     44 }
     45 
     46 func TestReetProfileRejectsOtherCodesBodiesAndLevels(t *testing.T) {
     47 	for _, change := range []string{"other code", "placeholder", "other body", "level 3"} {
     48 		t.Run(change, func(t *testing.T) {
     49 			data := testNPCData()
     50 			group := &data.Playfields[0].Districts[0].Groups[0]
     51 			group.TemplateCode, group.MonsterData, group.Levels, group.AppearanceStatus = "RT01", 30365, [2]uint16{1, 1}, "inferred_species"
     52 			switch change {
     53 			case "other code":
     54 				group.TemplateCode = "OTHER"
     55 			case "placeholder":
     56 				group.AppearanceStatus = "placeholder_creature"
     57 			case "other body":
     58 				group.MonsterData = 17708
     59 			case "level 3":
     60 				group.Levels = [2]uint16{3, 3}
     61 			}
     62 			useNPCData(t, data)
     63 			world := newTestServer(t)
     64 			if err := world.flushWorld(); err != nil {
     65 				t.Fatal(err)
     66 			}
     67 
     68 			cold := newTestInventoryServer(t)
     69 
     70 			if world.characters[1000000].combatProfile != nil || cold.characters[1000000].combatProfile != nil {
     71 				t.Fatal("unreviewed Reet identity or level inherited an admitted profile")
     72 			}
     73 		})
     74 	}
     75 }
     76 
     77 func TestReetCombatUsesOriginalPeckTiming(t *testing.T) {
     78 	data := testNPCData()
     79 	group := &data.Playfields[0].Districts[0].Groups[0]
     80 	group.TemplateCode, group.MonsterData, group.Levels, group.AppearanceStatus = "RT01", 30365, [2]uint16{1, 1}, "inferred_species"
     81 	useNPCData(t, data)
     82 	world := newTestServer(t)
     83 	player := world.newCharacter()
     84 	player.position = group.Positions[0]
     85 	world.clients[player.id] = &worldClient{id: player.id, conn: &combatTestConn{}, target: true, ready: true, npcs: map[uint32]bool{1000000: true}}
     86 	world.combatRoll = func(limit uint32) uint32 {
     87 		if limit == 100 {
     88 			return 50
     89 		}
     90 		return 0
     91 	}
     92 
     93 	if err := world.handleCombat(world.clients[player.id], attackPacket(player.id, 1000000)[20:]); err != nil {
     94 		t.Fatal(err)
     95 	}
     96 	start := player.nextAttack
     97 	world.advanceCombat(start)
     98 	world.advanceCombat(start.Add(2350*time.Millisecond - time.Nanosecond))
     99 	if player.health != 34 {
    100 		t.Fatal("Peck landed before its original attack phase ended")
    101 	}
    102 	world.advanceCombat(start.Add(2350 * time.Millisecond))
    103 
    104 	if player.health != 30 || world.characters[1000000].nextAttack != start.Add(7050*time.Millisecond) {
    105 		t.Fatal("Reet did not use original Peck damage and attack/recharge phases", player.health, world.characters[1000000].nextAttack.Sub(start))
    106 	}
    107 }
    108 
    109 func TestReetDeathsRetainSelectedQualityRewardsAcrossActions(t *testing.T) {
    110 	for _, attack := range []string{"unarmed", "axe", "pistol", "fling", "fast", "nano"} {
    111 		for _, expected := range []struct {
    112 			level   uint16
    113 			quality uint32
    114 		}{{1, 1}, {2, 3}} {
    115 			t.Run(fmt.Sprintf("%s/%d", attack, expected.level), func(t *testing.T) {
    116 				world, _ := newKillExperienceWorld(t, attack)
    117 				target := world.characters[1000000]
    118 				target.monsterData, target.level, target.npcDefinitionID = 30365, expected.level, "952/district/4/group/3/authored_point"
    119 				target.combatProfile = gamedata.NPCCombatProfiles[30365][expected.level]
    120 				world.combatRoll = func(limit uint32) uint32 {
    121 					if limit == 3 {
    122 						return 2
    123 					}
    124 					return 0
    125 				}
    126 				identity := world.nextItem + 1
    127 				if err := world.flushWorld(); err != nil {
    128 					t.Fatal(err)
    129 				}
    130 
    131 				attackForExperience(t, world, attack)
    132 				cold := newTestInventoryServer(t)
    133 
    134 				for _, current := range []*server{world, cold} {
    135 					npc := current.characters[1000000]
    136 					if npc.health != 0 || npc.corpse == nil || npc.corpse.credits != 1 || current.characters[1].experience != 100 ||
    137 						!slices.Equal(npc.corpse.items, []ownedItem{{ID: identity, Type: 51005, Template: 42640, Quality: expected.quality, Count: 1}}) ||
    138 						current.nextItem != identity || npc.combatProfile != gamedata.NPCCombatProfiles[30365][expected.level] {
    139 						t.Fatal("Reet death lost shared XP/cash/loot or its cold profile", npc.corpse)
    140 					}
    141 				}
    142 			})
    143 		}
    144 	}
    145 }