aorecomp

Anarchy Online classic in the browser

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


server/mission_key_purchase_test.go (3062B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"encoding/binary"
      6 	"slices"
      7 	"testing"
      8 )
      9 
     10 func TestMissionKeyDuplicatorStockPreservesToolsRows(t *testing.T) {
     11 	expected := []gamedata.ShopItem{{Template: 95577, Quality: 1}, {Template: 28564, Quality: 1}}
     12 
     13 	var vendors []uint32
     14 	for template, stock := range gamedata.ShopStock {
     15 		if slices.Contains(stock, gamedata.ShopItem{Template: 28564, Quality: 1}) {
     16 			vendors = append(vendors, template)
     17 		}
     18 	}
     19 
     20 	slices.Sort(vendors)
     21 	if !slices.Equal(vendors, []uint32{27054, 99487, 99488, 99489, 99491, 99492, 99493, 99500, 99519, 99522,
     22 		99523, 99527, 99528, 99530, 99539, 99555, 99569, 99600, 99601, 99603, 99643, 100034, 100035,
     23 		152006, 152007, 152008, 152012, 155595, 156004, 158698}) {
     24 		t.Fatal("duplicator vendors differ from the expanded stock catalogs", vendors)
     25 	}
     26 	// Starter tool rows retain their purchase indices as catalogs expand.
     27 	for _, template := range []uint32{99491, 99492, 99493, 99527, 99528, 99530, 99601, 152008, 152012} {
     28 		if len(gamedata.ShopStock[template]) < 2 || !slices.Equal(gamedata.ShopStock[template][:2], expected) {
     29 			t.Fatal("Tools subset omitted the original QL1 duplicator or changed the Lock Pick", template)
     30 		}
     31 	}
     32 }
     33 
     34 func TestMissionKeyDuplicatorPurchaseCanImmediatelyCopyTheHeldKey(t *testing.T) {
     35 	world, _ := newAcceptedMissionWorld(t)
     36 	player, client := world.characters[1], world.clients[1]
     37 	player.playfield, player.position, player.appearance = 1183, [3]float32{188, 5.75, 135.5}, 0x515
     38 	inventory := player.inventory
     39 	inventory.Credits = 100
     40 	if err := world.saveUser(player); err != nil {
     41 		t.Fatal(err)
     42 	}
     43 	if err := world.saveInventory(player, inventory); err != nil {
     44 		t.Fatal(err)
     45 	}
     46 	request := shopUseRequest(1)
     47 	binary.BigEndian.PutUint32(request[44:48], 3221488799)
     48 	if err := world.handleShopUse(client, request); err != nil {
     49 		t.Fatal(err)
     50 	}
     51 
     52 	for _, request := range [][]byte{
     53 		shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221488799}, [2]uint32{111, 1})[20:],
     54 		shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:],
     55 		shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:],
     56 	} {
     57 		if err := world.handleTrade(client, request); err != nil {
     58 			t.Fatal(err)
     59 		}
     60 	}
     61 	if err := world.handleItemCombination(client, combinationRequest(1, 66, 65)); err != nil {
     62 		t.Fatal(err)
     63 	}
     64 	cold := newTestInventoryServer(t)
     65 	var mission uint32
     66 	err := cold.db.QueryRow("SELECT mission_id FROM mission_keys WHERE item_id=4").Scan(&mission)
     67 
     68 	if err != nil || mission != 2 || cold.characters[1].inventory.Credits != 80 || cold.nextItem != 4 ||
     69 		!slices.Equal(cold.characters[1].inventory.Items, []ownedItem{
     70 			{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 64, Count: 1},
     71 			{ID: 2, Type: 51053, Template: 28577, Quality: 1, Slot: 65, Count: 1},
     72 			{ID: 3, Type: 51054, Template: 28564, Quality: 1, Slot: 66, Count: 1},
     73 			{ID: 4, Type: 51053, Template: 28577, Quality: 1, Slot: 67, Count: 1}}) {
     74 		t.Fatal("tool purchase/repeated Accept or immediate copy lost debit, reusable inputs or binding", err)
     75 	}
     76 }