aorecomp

Anarchy Online classic in the browser

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


server/npc_visuals_test.go (3297B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"bytes"
      6 	"encoding/binary"
      7 	"testing"
      8 )
      9 
     10 func TestRecoveredNPCVisualsSurviveReloadWithoutEquipment(t *testing.T) {
     11 	for _, test := range []struct {
     12 		definition   string
     13 		head, helmet uint32
     14 		weapon       uint32
     15 	}{
     16 		{"705/district/0/fixed/15", 40171, 20038, 35566},
     17 		{"705/district/0/fixed/9", 40209, 20055, 35566},
     18 		{"705/district/0/fixed/13", 40635, 20089, 35566},
     19 		{"705/district/0/fixed/10", 40629, 20089, 35566},
     20 		{"710/district/0/fixed/4", 40687, 20106, 35566},
     21 		{"705/district/0/fixed/12", 40629, 20089, 0},
     22 		{"705/district/0/fixed/16", 40111, 20005, 0},
     23 	} {
     24 		t.Run(test.definition, func(t *testing.T) {
     25 			data := testNPCData()
     26 			data.Playfields[0].Districts[0].Groups[0] = *gamedata.NPCGroups[test.definition]
     27 			useNPCData(t, data)
     28 			world := newTestServer(t)
     29 
     30 			if err := world.flushWorld(); err != nil {
     31 				t.Fatal(err)
     32 			}
     33 			cold := newTestInventoryServer(t)
     34 
     35 			for _, current := range []*server{world, cold} {
     36 				npc := current.characters[1000000]
     37 				if len(npc.inventory.Items) != 0 || npc.combatProfile != nil || npc.attackableNPC() || npc.equipmentBonus(90) != 0 {
     38 					t.Fatal("visual reconstruction invented equipment or combat stats")
     39 				}
     40 				packet := targetPacket(characterPacket(npc))
     41 				packet = packet[:binary.BigEndian.Uint16(packet[6:8])]
     42 				if binary.BigEndian.Uint32(packet[30:34])&0x4000b != 0x4000a {
     43 					t.Fatal("recovered human appearance lost humanoid NPC initialization or clothing")
     44 				}
     45 				// Original 14.9.1 clothing layers, mesh attachments and implicit attack row.
     46 				meshes := [][4]uint32{{0, test.helmet, 0, 2}, {0, test.head, 0, 4}}
     47 				if test.weapon != 0 {
     48 					meshes = append(meshes, [4]uint32{1, test.weapon, 0, 2})
     49 				}
     50 				reader := bytes.NewReader(packet[len(packet)-92-10*len(meshes):])
     51 				count, _ := reader.ReadByte()
     52 				if count != 5 {
     53 					t.Fatal("officer has no five-part armor texture list", count)
     54 				}
     55 				for index, texture := range []uint32{15806, 15809, 15807, 15808, 15805} {
     56 					slot, _ := reader.ReadByte()
     57 					var row [3]uint32
     58 					if err := binary.Read(reader, binary.BigEndian, &row); err != nil {
     59 						t.Fatal(err)
     60 					}
     61 					if slot != byte(index) || row != [3]uint32{uint32(index), texture, 1} {
     62 						t.Fatalf("wrong armor part: slot=%d row=%v", slot, row)
     63 					}
     64 				}
     65 				var layers [2]byte
     66 				var meshCount uint32
     67 				binary.Read(reader, binary.BigEndian, &layers)
     68 				binary.Read(reader, binary.BigEndian, &meshCount)
     69 				if layers != [2]byte{} || meshCount != uint32(len(meshes)+1)*1009 {
     70 					t.Fatal("clothing layer and mesh list boundaries changed", layers, meshCount)
     71 				}
     72 				for _, want := range meshes {
     73 					slot, _ := reader.ReadByte()
     74 					var row [2]uint32
     75 					binary.Read(reader, binary.BigEndian, &row)
     76 					layer, _ := reader.ReadByte()
     77 					if [4]uint32{uint32(slot), row[0], row[1], uint32(layer)} != want {
     78 						t.Fatalf("missing helmet, head or gun: %d %v %d", slot, row, layer)
     79 					}
     80 				}
     81 				var weapon [5]uint32
     82 				if err := binary.Read(reader, binary.BigEndian, &weapon); err != nil {
     83 					t.Fatal(err)
     84 				}
     85 				if weapon != [5]uint32{2018, 43712, 43713, 100, 1} || reader.Len() != 0 {
     86 					t.Fatal("visual gun changed the attack template or packet alignment", weapon, reader.Len())
     87 				}
     88 			}
     89 		})
     90 	}
     91 }