aorecomp

Anarchy Online classic in the browser

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


server/seventh_level_reward_test.go (4659B)


      1 package main
      2 
      3 import (
      4 	"slices"
      5 	"testing"
      6 	"time"
      7 )
      8 
      9 func TestEarnedSeventhLevelUnlocksRetainedQualityEightArmor(t *testing.T) {
     10 	world := newOmniTrainingBossKillWorld(t, "unarmed")
     11 	player, client := world.characters[1], world.clients[1]
     12 	player.appearance = player.appearance&^(7<<4) | 4<<4
     13 	player.profession, player.level, player.experience = 9, 6, 4925
     14 	player.stats = defaultCharacterStats(4)
     15 	player.stats.Abilities = characterAbilitiesStats{19, 21, 22, 6, 7, 3}
     16 	player.stats.Body.BodyDevelopment, player.stats.Melee.OneHandBlunt = 35, 35
     17 	player.stats.Body.Brawling, player.stats.Body.Dimach = 21, 11
     18 	player.stats.Melee.SneakAttack, player.stats.Melee.FastAttack = 19, 19
     19 	player.stats.Speed.EvadeClose = 27
     20 	player.stats.ImprovementPoints, player.health = 17792, 150
     21 	if err := world.saveUser(player); err != nil {
     22 		t.Fatal(err)
     23 	}
     24 
     25 	// Retain both unqualified rewards beside the worn equipment and supplies.
     26 	items := []ownedItem{
     27 		{ID: 3, Type: 51018, Template: 122691, Quality: 8, Slot: 6, Count: 1},
     28 		{ID: 4, Type: 51005, Template: 25812, Quality: 1, Slot: 64, Count: 31},
     29 		{ID: 5, Type: 51022, Template: 85686, Quality: 5, Slot: 21, Count: 1},
     30 		{ID: 6, Type: 51022, Template: 85686, Quality: 8, Slot: 65, Count: 1},
     31 		{ID: 7, Type: 51022, Template: 85512, Quality: 8, Slot: 66, Count: 1},
     32 	}
     33 	if err := world.saveInventory(player, playerInventory{LastID: 7, Items: slices.Clone(items), Credits: 665}); err != nil {
     34 		t.Fatal(err)
     35 	}
     36 
     37 	// The one-hit encounter isolates earned caps, training and retained rewards.
     38 	world.combatRoll = func(uint32) uint32 { return 0 }
     39 	trained := player.baseStats()
     40 	trained.Abilities.Strength, trained.Abilities.Agility = 24, 26
     41 	trained.Body.BodyDevelopment, trained.Melee.OneHandBlunt = 40, 40
     42 
     43 	if err := world.handleSkillTraining(client, skillTrainingRequest(trained)[20:]); err != nil {
     44 		t.Fatal(err)
     45 	}
     46 	if err := world.handleInventory(client, inventoryMovePacket(1, 66, 27)[20:]); err != nil {
     47 		t.Fatal(err)
     48 	}
     49 	cold := newTestInventoryServer(t)
     50 
     51 	if player.level != 6 || player.experience != 4925 || player.stats.Abilities != (characterAbilitiesStats{19, 21, 22, 6, 7, 3}) ||
     52 		player.stats.Body.BodyDevelopment != 35 || player.stats.Melee.OneHandBlunt != 35 || player.stats.ImprovementPoints != 17792 ||
     53 		client.equipment != nil || player.health != 150 || player.maximumHealth() != 227 || cold.characters[1].stats != player.stats ||
     54 		!slices.Equal(cold.characters[1].inventory.Items, items) {
     55 		t.Fatal("level-six cap or rejected wear changed retained rewards, skills or IP", player.stats, player.inventory)
     56 	}
     57 
     58 	attackForExperience(t, world, "unarmed")
     59 	world.advanceCombat(player.rechargeUntil.Add(time.Second))
     60 	cold = newTestInventoryServer(t)
     61 
     62 	for _, current := range []*server{world, cold} {
     63 		owner := current.characters[1]
     64 		if owner.level != 7 || owner.experience != 75 || owner.stats.ImprovementPoints != 21792 || owner.health != 150 || owner.maximumHealth() != 234 ||
     65 			owner.stats.Body.BodyDevelopment != 35 || owner.stats.Melee.OneHandBlunt != 35 || !slices.Equal(owner.inventory.Items, items) || owner.inventory.Credits != 665 {
     66 			t.Fatal("earned level changed current health or lost its IP award or retained rewards", owner.profile(), owner.inventory)
     67 		}
     68 	}
     69 
     70 	if err := world.handleSkillTraining(client, skillTrainingRequest(trained)[20:]); err != nil {
     71 		t.Fatal(err)
     72 	}
     73 	time.Sleep(time.Until(player.rechargeUntil))
     74 	for _, move := range [][2]uint32{{66, 27}, {21, 66}, {65, 21}} {
     75 		request := inventoryMovePacket(1, move[0], move[1])
     76 		if move[0] < 64 {
     77 			request = itemMovePacket(1, move[0], move[1])
     78 		}
     79 		if err := world.handleInventory(client, request[20:]); err != nil || client.equipment == nil {
     80 			t.Fatal("earned training did not allow retained armor wear or removal", move, err, player.stats)
     81 		}
     82 		world.advanceEquipment(client.equipment.readyAt)
     83 		for index := range items {
     84 			if items[index].Slot == move[0] {
     85 				items[index].Slot = move[1]
     86 			}
     87 		}
     88 		cold = newTestInventoryServer(t)
     89 
     90 		for _, current := range []*server{world, cold} {
     91 			owner := current.characters[1]
     92 			if owner.level != 7 || owner.experience != 75 || owner.stats.ImprovementPoints != 21087 || owner.health != 150 || owner.maximumHealth() != 254 ||
     93 				owner.stats.Abilities != (characterAbilitiesStats{24, 26, 22, 6, 7, 3}) || owner.stats.Body.BodyDevelopment != 40 || owner.stats.Melee.OneHandBlunt != 40 ||
     94 				owner.stats.Speed.EvadeClose != 27 || !slices.Equal(owner.inventory.Items, items) || owner.inventory.Credits != 665 {
     95 				t.Fatal("earned armor wear lost exact training cost, current health, identity or quality", move, owner.profile(), owner.inventory)
     96 			}
     97 		}
     98 	}
     99 }