aorecomp

Anarchy Online classic in the browser

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


server/eighth_level_training_test.go (3897B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"slices"
      6 	"testing"
      7 	"time"
      8 )
      9 
     10 func TestEarnedEighthLevelNeedsStaminaForBodyDevelopmentTraining(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, 7, 5350
     15 	player.stats = defaultCharacterStats(4)
     16 	player.stats.Abilities = characterAbilitiesStats{24, 26, 22, 6, 7, 3}
     17 	player.stats.Body.BodyDevelopment, player.stats.Melee.OneHandBlunt = 40, 40
     18 	player.stats.ImprovementPoints, player.health = 21074, 150
     19 	if err := world.saveUser(player); err != nil {
     20 		t.Fatal(err)
     21 	}
     22 
     23 	// Retain the worn rewards and bought recovery supplies.
     24 	items := []ownedItem{
     25 		{ID: 3, Type: 51018, Template: 122691, Quality: 8, Slot: 6, Count: 1},
     26 		{ID: 4, Type: 51022, Template: 85686, Quality: 8, Slot: 21, Count: 1},
     27 		{ID: 5, Type: 51022, Template: 85512, Quality: 8, Slot: 27, Count: 1},
     28 		{ID: 6, Type: 51005, Template: 25812, Quality: 1, Slot: 64, Count: 3},
     29 		{ID: 7, Type: 51005, Template: 25820, Quality: 1, Slot: 65, Count: 48},
     30 	}
     31 	if err := world.saveInventory(player, playerInventory{LastID: 7, Items: slices.Clone(items), Credits: 546}); err != nil {
     32 		t.Fatal(err)
     33 	}
     34 
     35 	// Use the level-ten Leet profile at one health to isolate the earned award.
     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.Body.BodyDevelopment, trained.Melee.OneHandBlunt = 45, 45
     41 
     42 	if err := world.handleSkillTraining(client, skillTrainingRequest(trained)[20:]); err != nil {
     43 		t.Fatal(err)
     44 	}
     45 	cold := newTestInventoryServer(t)
     46 
     47 	for _, current := range []*server{world, cold} {
     48 		owner := current.characters[1]
     49 		if owner.level != 7 || owner.experience != 5350 || owner.stats.ImprovementPoints != 21074 ||
     50 			owner.stats.Body.BodyDevelopment != 40 || owner.stats.Melee.OneHandBlunt != 40 ||
     51 			owner.health != 150 || owner.maximumHealth() != 254 || !slices.Equal(owner.inventory.Items, items) {
     52 			t.Fatal("level-seven training changed capped skills, IP, health or retained items", owner.profile())
     53 		}
     54 	}
     55 
     56 	attackForExperience(t, world, "unarmed")
     57 	world.advanceCombat(player.rechargeUntil.Add(time.Second))
     58 	trained.Body.BodyDevelopment = 44
     59 	if err := world.handleSkillTraining(client, skillTrainingRequest(trained)[20:]); err != nil {
     60 		t.Fatal(err)
     61 	}
     62 	cold = newTestInventoryServer(t)
     63 
     64 	for _, current := range []*server{world, cold} {
     65 		owner := current.characters[1]
     66 		if owner.level != 8 || owner.experience != 150 || owner.stats.ImprovementPoints != 25074 ||
     67 			owner.stats.Abilities.Stamina != 22 || owner.stats.Body.BodyDevelopment != 40 || owner.stats.Melee.OneHandBlunt != 40 ||
     68 			owner.health != 150 || owner.maximumHealth() != 261 || !slices.Equal(owner.inventory.Items, items) {
     69 			t.Fatal("the ability limit allowed a partial training batch or changed earned state", owner.profile())
     70 		}
     71 	}
     72 
     73 	trained.Abilities.Stamina = 23
     74 	trained.Body.BodyDevelopment = 45
     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 != 8 || owner.experience != 150 || owner.stats.ImprovementPoints != 24632 ||
     83 			owner.stats.Abilities != (characterAbilitiesStats{24, 26, 23, 6, 7, 3}) ||
     84 			owner.stats.Body.BodyDevelopment != 45 || owner.stats.Melee.OneHandBlunt != 45 ||
     85 			owner.health != 150 || owner.maximumHealth() != 281 || owner.inventory.Credits != 546 ||
     86 			!slices.Equal(owner.inventory.Items, items) {
     87 			t.Fatal("qualified training lost its cost, health maximum or retained ownership", owner.profile(), owner.inventory)
     88 		}
     89 	}
     90 }