server/starter_shop_test.go (2861B)
1 package main 2 3 import ( 4 "ao/server/gamedata" 5 "encoding/binary" 6 "fmt" 7 "slices" 8 "testing" 9 ) 10 11 func TestStarterTerminalsSellOriginalRecoveryAndAmmunitionPackages(t *testing.T) { 12 for _, scenario := range []struct { 13 machine, credits uint32 14 }{ 15 {0xc00003b6, 345}, {0xc00003b8, 314}, {0xc00003ba, 314}, {0xc00103ba, 314}, 16 } { 17 t.Run(fmt.Sprintf("%x", scenario.machine), func(t *testing.T) { 18 world, _ := newPurchaseWorld(t) 19 player, client := world.characters[1], world.clients[1] 20 machine := gamedata.ShopMachines[scenario.machine] 21 player.playfield, player.position = machine.Playfield, machine.Position 22 player.appearance = map[uint32]uint16{950: 0x515, 952: 0x315, 954: 0x115}[machine.Playfield] 23 player.stats.TradeRepair.ComputerLiteracy, player.stats.Abilities.Intelligence = 0, 0 24 request := shopUseRequest(2) 25 binary.BigEndian.PutUint32(request[44:48], scenario.machine) 26 27 if err := world.handleShopUse(client, request); err != nil { 28 t.Fatal(err) 29 } 30 if client.shop == nil || len(client.shop.stock) < 7 || !slices.Equal(client.shop.stock[:7], []gamedata.ShopItem{ 31 {Template: 25812, Quality: 1}, {Template: 85366, Quality: 1}, {Template: 25820, Quality: 1}, 32 {Template: 21605, Quality: 1}, {Template: 21609, Quality: 1}, {Template: 21613, Quality: 1}, {Template: 21601, Quality: 1}, 33 }) { 34 t.Fatal("starter terminal has no usable recovery/ammunition catalog") 35 } 36 for index := range uint32(7) { 37 if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, scenario.machine}, [2]uint32{111, index})[20:]); err != nil { 38 t.Fatal(err) 39 } 40 } 41 accept := shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:] 42 if err := world.handleTrade(client, accept); err != nil { 43 t.Fatal(err) 44 } 45 if err := world.handleTrade(client, accept); err != nil { 46 t.Fatal(err) 47 } 48 cold := newTestInventoryServer(t).characters[1].inventory 49 50 expected := []ownedItem{ 51 {ID: 2, Type: 51005, Template: 25812, Quality: 1, Slot: 65, Count: 50}, 52 {ID: 3, Type: 51005, Template: 85366, Quality: 1, Slot: 66, Count: 25}, 53 {ID: 4, Type: 51005, Template: 25820, Quality: 1, Slot: 67, Count: 50}, 54 {ID: 5, Type: 51005, Template: 21605, Quality: 1, Slot: 68, Count: 100}, 55 {ID: 6, Type: 51005, Template: 21609, Quality: 1, Slot: 69, Count: 100}, 56 {ID: 7, Type: 51005, Template: 21613, Quality: 1, Slot: 70, Count: 100}, 57 {ID: 8, Type: 51005, Template: 21601, Quality: 1, Slot: 71, Count: 100}, 58 } 59 if cold.Credits != scenario.credits || player.inventory.Credits != scenario.credits || len(cold.Items) != 8 || 60 !slices.Equal(cold.Items[1:], expected) || !slices.Equal(cold.Items, player.inventory.Items) || world.nextItem != 8 { 61 t.Fatal("starter purchase changed authored prices, packages or durable identities", cold) 62 } 63 }) 64 } 65 }