aorecomp

Anarchy Online classic in the browser

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


server/tenth_level_training_test.go (3991B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"slices"
      6 	"testing"
      7 	"time"
      8 )
      9 
     10 func TestEarnedTenthLevelNeedsStaminaForBodyDevelopmentTraining(t *testing.T) {
     11 	world, _ := newKillExperienceWorld(t, "unarmed")
     12 	player, client := world.characters[1], world.clients[1]
     13 	player.appearance = player.appearance&^(7<<4) | 4<<4
     14 	player.profession, player.level, player.experience = 9, 9, 6350
     15 	player.stats = defaultCharacterStats(4)
     16 	player.stats.Abilities = characterAbilitiesStats{28, 31, 23, 6, 8, 3}
     17 	player.stats.Body.BodyDevelopment, player.stats.Melee.OneHandBlunt = 45, 45
     18 	player.stats.ImprovementPoints, player.health = 27793, 180
     19 	if err := world.saveUser(player); err != nil {
     20 		t.Fatal(err)
     21 	}
     22 
     23 	// Retain earned equipment and bought supplies across training and cold loads.
     24 	items := []ownedItem{
     25 		{ID: 3, Type: 51018, Template: 122691, Quality: 10, Slot: 6, Count: 1},
     26 		{ID: 4, Type: 51022, Template: 85686, Quality: 10, Slot: 21, Count: 1},
     27 		{ID: 5, Type: 51022, Template: 85512, Quality: 10, Slot: 27, Count: 1},
     28 		{ID: 6, Type: 51005, Template: 25812, Quality: 1, Slot: 64, Count: 21},
     29 		{ID: 7, Type: 51005, Template: 25820, Quality: 1, Slot: 65, Count: 47},
     30 	}
     31 	if err := world.saveInventory(player, playerInventory{LastID: 7, Items: slices.Clone(items), Credits: 1303}); err != nil {
     32 		t.Fatal(err)
     33 	}
     34 
     35 	// Isolate the level-ten award with a one-health level-ten encounter.
     36 	world.combatRoll = func(uint32) uint32 { return 0 }
     37 	world.characters[1000000].level = 10
     38 	world.characters[1000000].combatProfile = gamedata.NPCCombatProfiles[17655][10]
     39 	trained := player.baseStats()
     40 	trained.Abilities.Stamina = 28
     41 	trained.Body.BodyDevelopment, trained.Melee.OneHandBlunt = 55, 55
     42 
     43 	if err := world.handleSkillTraining(client, skillTrainingRequest(trained)[20:]); err != nil {
     44 		t.Fatal(err)
     45 	}
     46 	cold := newTestInventoryServer(t)
     47 
     48 	for _, current := range []*server{world, cold} {
     49 		owner := current.characters[1]
     50 		if owner.level != 9 || owner.experience != 6350 || owner.stats.ImprovementPoints != 27793 ||
     51 			owner.stats.Abilities.Stamina != 23 || owner.stats.Body.BodyDevelopment != 45 || owner.stats.Melee.OneHandBlunt != 45 ||
     52 			owner.health != 180 || owner.maximumHealth() != 288 || !slices.Equal(owner.inventory.Items, items) {
     53 			t.Fatal("level-nine cap changed training, health or retained items", owner.profile(), owner.inventory)
     54 		}
     55 	}
     56 
     57 	attackForExperience(t, world, "unarmed")
     58 	world.advanceCombat(player.rechargeUntil.Add(time.Second))
     59 	trained.Abilities.Stamina = 23
     60 	if err := world.handleSkillTraining(client, skillTrainingRequest(trained)[20:]); err != nil {
     61 		t.Fatal(err)
     62 	}
     63 	cold = newTestInventoryServer(t)
     64 
     65 	for _, current := range []*server{world, cold} {
     66 		owner := current.characters[1]
     67 		if owner.level != 10 || owner.experience != 150 || owner.stats.ImprovementPoints != 31793 ||
     68 			owner.stats.Abilities.Stamina != 23 || owner.stats.Body.BodyDevelopment != 45 || owner.stats.Melee.OneHandBlunt != 45 ||
     69 			owner.health != 180 || owner.maximumHealth() != 295 || !slices.Equal(owner.inventory.Items, items) {
     70 			t.Fatal("ability-capped batch changed the earned award or retained state", owner.profile(), owner.inventory)
     71 		}
     72 	}
     73 
     74 	trained.Abilities.Stamina = 28
     75 	if err := world.handleSkillTraining(client, skillTrainingRequest(trained)[20:]); err != nil {
     76 		t.Fatal(err)
     77 	}
     78 	cold = newTestInventoryServer(t)
     79 
     80 	for _, current := range []*server{world, cold} {
     81 		owner := current.characters[1]
     82 		if owner.level != 10 || owner.experience != 150 || owner.stats.ImprovementPoints != 30678 ||
     83 			owner.stats.Abilities != (characterAbilitiesStats{28, 31, 28, 6, 8, 3}) ||
     84 			owner.stats.Body.BodyDevelopment != 55 || owner.stats.Melee.OneHandBlunt != 55 ||
     85 			owner.combatSkill(102) != 62 ||
     86 			owner.health != 180 || owner.maximumHealth() != 339 || owner.inventory.Credits != 1303 ||
     87 			!slices.Equal(owner.inventory.Items, items) {
     88 			t.Fatal("qualified training lost its 1115-IP cost, health or retained items", owner.profile(), owner.inventory)
     89 		}
     90 	}
     91 }