aorecomp

Anarchy Online classic in the browser

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


server/neutral_fauna_test.go (4442B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"fmt"
      6 	"slices"
      7 	"testing"
      8 )
      9 
     10 func TestNeutralFaunaAdmissionKeepsReviewedRangesAndCodes(t *testing.T) {
     11 	for _, row := range []struct {
     12 		code      string
     13 		monster   uint32
     14 		low, high uint16
     15 	}{{"ANDR", 17649, 1, 4}, {"BIOF", 30258, 1, 4}, {"CLAW", 38387, 1, 3},
     16 		{"EY01", 17653, 2, 4}, {"EY02", 17653, 2, 4}, {"BOMJ", 45873, 4, 4}, {"RT02", 30365, 1, 4}} {
     17 		for _, change := range []string{"low", "high", "below", "above", "code", "placeholder"} {
     18 			// Level zero is rejected by population validation before profile admission.
     19 			if change == "below" && row.low == 1 {
     20 				continue
     21 			}
     22 			t.Run(row.code+"/"+change, func(t *testing.T) {
     23 				// Build the selected binding with one changed admission condition.
     24 				data := testNPCData()
     25 				group := &data.Playfields[0].Districts[0].Groups[0]
     26 				group.TemplateCode, group.MonsterData, group.AppearanceStatus = row.code, row.monster, "inferred_species"
     27 				level := row.low
     28 				switch change {
     29 				case "high":
     30 					level = row.high
     31 				case "below":
     32 					level--
     33 				case "above":
     34 					level = row.high + 1
     35 				case "code":
     36 					group.TemplateCode = "OTHER"
     37 				case "placeholder":
     38 					group.AppearanceStatus = "placeholder_creature"
     39 				}
     40 				group.Levels = [2]uint16{level, level}
     41 				useNPCData(t, data)
     42 
     43 				world := newTestServer(t)
     44 
     45 				admitted := change == "low" || change == "high"
     46 				if (world.characters[1000000].combatProfile != nil) != admitted {
     47 					t.Fatal("neutral starter profile crossed its declared admission boundary")
     48 				}
     49 			})
     50 		}
     51 	}
     52 }
     53 
     54 func TestNeutralFaunaDeathsKeepSelectedLootAndColdLifecycle(t *testing.T) {
     55 	for _, attack := range []string{"unarmed", "axe", "pistol", "fling", "fast", "nano"} {
     56 		for _, row := range []struct {
     57 			group   string
     58 			monster uint32
     59 			level   uint16
     60 			xp      uint32
     61 			items   []ownedItem
     62 		}{
     63 			{"954/district/0/group/0/authored_point", 17649, 2, 100, []ownedItem{{Type: 51005, Template: 42620, Quality: 1, Count: 1}, {Type: 51005, Template: 136646, Quality: 1, Slot: 1, Count: 1}}},
     64 			{"954/district/4/group/0/authored_point", 17649, 4, 150, []ownedItem{{Type: 51005, Template: 42620, Quality: 3, Count: 1}, {Type: 51005, Template: 136646, Quality: 3, Slot: 1, Count: 1}}},
     65 			{"954/district/4/group/1/spread_authored_point", 30258, 4, 150, []ownedItem{{Type: 51005, Template: 42640, Quality: 3, Count: 1}, {Type: 51005, Template: 136646, Quality: 3, Slot: 1, Count: 1}}},
     66 			{"954/district/0/group/2/spread_authored_point", 38387, 3, 125, []ownedItem{{Type: 51005, Template: 42640, Quality: 2, Count: 1}, {Type: 51005, Template: 136646, Quality: 2, Slot: 1, Count: 1}}},
     67 			{"954/district/4/group/2/spread_authored_point", 17653, 4, 150, []ownedItem{{Type: 51005, Template: 42640, Quality: 3, Count: 1}, {Type: 51005, Template: 136646, Quality: 3, Slot: 1, Count: 1}}},
     68 			{"954/district/5/fixed/0", 45873, 4, 150, []ownedItem{{Type: 51022, Template: 85596, Quality: 3, Count: 1}, {Type: 51018, Template: 123742, Quality: 3, Slot: 1, Count: 1}, {Type: 51005, Template: 136610, Quality: 3, Slot: 2, Count: 1}, {Type: 51022, Template: 136618, Quality: 3, Slot: 3, Count: 1}}},
     69 		} {
     70 			t.Run(fmt.Sprintf("%s/%d/%d", attack, row.monster, row.level), func(t *testing.T) {
     71 				// Reach death through each supported attack, preserving the actual loot policy.
     72 				world, _ := newKillExperienceWorld(t, attack)
     73 				target := world.characters[1000000]
     74 				target.monsterData, target.level, target.npcDefinitionID = row.monster, row.level, row.group
     75 				target.combatProfile = gamedata.NPCCombatProfiles[row.monster][row.level]
     76 				world.combatRoll = func(uint32) uint32 { return 0 }
     77 				for index := range row.items {
     78 					row.items[index].ID = world.nextItem + uint32(index) + 1
     79 				}
     80 				if err := world.flushWorld(); err != nil {
     81 					t.Fatal(err)
     82 				}
     83 
     84 				attackForExperience(t, world, attack)
     85 				cold := newTestInventoryServer(t)
     86 
     87 				for _, current := range []*server{world, cold} {
     88 					npc := current.characters[1000000]
     89 					if npc.health != 0 || npc.corpse == nil || !slices.Equal(npc.corpse.items, row.items) || npc.corpse.credits != 1 ||
     90 						current.characters[1].experience != row.xp || npc.corpse.expiresAt.IsZero() || len(current.npcRespawns) != 1 ||
     91 						npc.combatProfile != gamedata.NPCCombatProfiles[row.monster][row.level] {
     92 						t.Fatal("neutral death lost exact rewards, lifecycle or its recovered profile", npc.corpse)
     93 					}
     94 				}
     95 			})
     96 		}
     97 	}
     98 }