server/mission_placement_test.go (2365B)
1 package main 2 3 import "testing" 4 5 func TestFixedMissionEncounterPlacementsAdmitClearCombatAndRejectWalls(t *testing.T) { 6 for _, scenario := range []struct { 7 name string 8 npc uint32 9 position [3]float32 10 blocked bool 11 }{ 12 {"far room", 2000000, [3]float32{15, .011, 44.5}, false}, 13 {"middle room", 2000001, [3]float32{15, .011, 41.5}, false}, 14 {"near passage", 2000002, [3]float32{15, .011, 34.5}, false}, 15 {"entrance passage", 2000003, [3]float32{15, .011, 26.5}, false}, 16 {"raised entrance", 2000004, [3]float32{14.01, 1.5625, 22.01}, false}, 17 {"back wall", 2000000, [3]float32{15, .011, 48.5}, true}, 18 {"side wall", 2000000, [3]float32{20, .011, 44.5}, true}, 19 } { 20 t.Run(scenario.name, func(t *testing.T) { 21 world, client, _ := enteredMissionEncounterWorld(t) 22 player, npc := world.characters[1], world.characters[scenario.npc] 23 player.position, player.stats = scenario.position, testCharacterStats() 24 player.inventory.LastID = world.nextItem + 1 25 player.inventory.Items = append(player.inventory.Items, ownedItem{ID: player.inventory.LastID, Type: 51018, Template: 123742, Quality: 1, Slot: 6, Count: 1, Ammo: 3}) 26 if err := world.saveInventory(player, player.inventory); err != nil { 27 t.Fatal(err) 28 } 29 world.combatRoll = landedCombatRoll 30 31 if err := world.handleCombat(client, attackPacket(1, npc.id)[20:]); err != nil { 32 t.Fatal(err) 33 } 34 world.advanceCombat(player.nextAttack) 35 if err := world.flushWorld(); err != nil { 36 t.Fatal(err) 37 } 38 cold := reloadMissionEntranceWorld(t) 39 40 if scenario.blocked { 41 if npc.health != 20 || cold.characters[npc.id].health != 20 || world.items[player.inventory.LastID].Ammo != 3 || cold.items[player.inventory.LastID].Ammo != 3 { 42 t.Fatal("a wall allowed damage or an ammunition cost", npc.health) 43 } 44 } else if npc.health == 0 || npc.health >= 20 || cold.characters[npc.id].health != npc.health || world.items[player.inventory.LastID].Ammo != 2 || cold.items[player.inventory.LastID].Ammo != 2 { 45 t.Fatal("accepted encounter could not receive an ordinary clear-path hit", npc.position, npc.health) 46 } 47 var kills int 48 if err := cold.db.QueryRow("SELECT sum(killed) FROM mission_encounters").Scan(&kills); err != nil { 49 t.Fatal(err) 50 } 51 if kills != 0 { 52 t.Fatal("placement check unexpectedly killed an encounter", kills) 53 } 54 }) 55 } 56 }