aorecomp

Anarchy Online classic in the browser

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


server/backpack_catalog_effects_test.go (3786B)


      1 package main
      2 
      3 import (
      4 	"fmt"
      5 	"testing"
      6 )
      7 
      8 func TestBackpackCatalogEffectsAfterWearAndRemoval(t *testing.T) {
      9 	for _, scenario := range []struct {
     10 		template, quality, slot uint32
     11 		bonuses                 map[uint32]int32
     12 	}{
     13 		{99228, 1, 19, map[uint32]int32{}},
     14 		{99241, 1, 19, map[uint32]int32{}},
     15 		{143832, 1, 19, map[uint32]int32{}},
     16 		{152039, 1, 19, map[uint32]int32{16: 1, 17: 1, 18: 1, 19: 1, 20: 1, 21: 1, 123: 10, 138: 25, 141: 150, 156: 10, 319: 1, 360: 3}},
     17 		{156831, 1, 19, map[uint32]int32{16: 1, 17: 1, 18: 1, 19: 1, 20: 1, 21: 1, 123: 10, 138: 25, 141: 150, 156: 10, 319: 1, 360: -3}},
     18 		{157682, 1, 19, map[uint32]int32{103: 5, 118: 5, 155: 5}},
     19 		{157683, 1, 19, map[uint32]int32{149: 10, 221: 20}},
     20 		{157684, 1, 19, map[uint32]int32{135: 5, 136: 5, 164: 5, 165: 5}},
     21 		{157685, 1, 19, map[uint32]int32{119: 10, 380: 2}},
     22 		{157686, 1, 19, map[uint32]int32{95: 280}},
     23 		{157687, 1, 19, map[uint32]int32{138: 24}},
     24 		{157688, 1, 19, map[uint32]int32{156: 24}},
     25 		{157689, 1, 19, map[uint32]int32{}},
     26 		{157690, 1, 19, map[uint32]int32{}},
     27 		{157691, 1, 19, map[uint32]int32{}},
     28 		{157692, 1, 19, map[uint32]int32{}},
     29 		{157693, 1, 19, map[uint32]int32{}},
     30 		{157694, 1, 19, map[uint32]int32{}},
     31 		{157695, 1, 19, map[uint32]int32{}},
     32 		{158790, 1, 19, map[uint32]int32{1: 400, 90: 900, 91: 900, 92: 900, 93: 600, 94: 900, 95: 900, 96: 900, 97: 900, 278: 60, 280: 60, 282: 60, 316: 60}},
     33 		{164564, 140, 19, map[uint32]int32{90: 700, 91: 700, 92: 900, 93: 500, 94: 900, 95: 900, 96: 500, 97: 900, 221: 40}},
     34 		{165201, 200, 19, map[uint32]int32{1: 45, 90: 1050, 91: 1050, 92: 950, 93: 950, 94: 950, 95: 550, 96: 950, 97: 550, 153: 15, 154: 15, 155: 15, 156: 15, 221: 45}},
     35 		{168658, 200, 20, map[uint32]int32{92: 30, 181: 5}},
     36 		{200461, 200, 19, map[uint32]int32{1: 90, 90: 1200, 91: 1200, 92: 1100, 93: 750, 94: 1100, 95: 1000, 96: 1000, 97: 750, 136: 15, 140: 5, 153: 30, 164: 15, 221: 90}},
     37 		{206730, 50, 19, map[uint32]int32{90: 250, 91: 250, 92: 200, 93: 250, 94: 200, 95: 300, 96: 250, 97: 300, 136: 11}},
     38 		{206731, 150, 19, map[uint32]int32{90: 750, 91: 750, 92: 600, 93: 750, 94: 600, 95: 900, 96: 750, 97: 900, 136: 33}},
     39 		{207254, 1, 19, map[uint32]int32{}},
     40 		{206730, 100, 19, map[uint32]int32{90: 500, 91: 500, 92: 400, 93: 500, 94: 400, 95: 600, 96: 500, 97: 600, 136: 22}},
     41 	} {
     42 		t.Run(fmt.Sprintf("%d/QL%d", scenario.template, scenario.quality), func(t *testing.T) {
     43 			world, _ := newEquipmentWorld(t)
     44 			player, client := world.characters[1], world.clients[1]
     45 			player.stats.Body.Adventuring, player.stats.TradeRepair.ComputerLiteracy, player.stats.NanoAiding.TimeAndSpace = 1000, 1000, 1000
     46 			player.stats.Abilities.Intelligence = 420
     47 			player.level, player.profession = 200, 6
     48 			world.saveUser(player)
     49 			world.grantItem(player, scenario.template)
     50 			player.inventory.Items[1].Quality = scenario.quality
     51 			world.saveInventory(player, player.inventory)
     52 
     53 			err := world.handleInventory(client, inventoryMovePacket(1, 65, scenario.slot)[20:])
     54 			if client.equipment == nil {
     55 				t.Fatal("catalog wear rejected", err)
     56 			}
     57 			world.advanceEquipment(client.equipment.readyAt)
     58 			restarted := newTestInventoryServer(t).characters[1]
     59 
     60 			for stat := uint32(0); stat <= 380; stat++ {
     61 				if player.inventory.equipmentBonus(stat) != scenario.bonuses[stat] || restarted.inventory.equipmentBonus(stat) != scenario.bonuses[stat] {
     62 					t.Fatal("catalog effect differs before or after restart", stat, scenario.bonuses[stat])
     63 				}
     64 			}
     65 
     66 			world.handleInventory(client, itemMovePacket(1, scenario.slot, 111)[20:])
     67 			world.advanceEquipment(client.equipment.readyAt)
     68 
     69 			for stat := uint32(0); stat <= 380; stat++ {
     70 				if player.inventory.equipmentBonus(stat) != 0 {
     71 					t.Fatal("removal retained a catalog effect", stat)
     72 				}
     73 			}
     74 		})
     75 	}
     76 }