aorecomp

Anarchy Online classic in the browser

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


server/starter_level_test.go (5527B)


      1 package main
      2 
      3 import (
      4 	"encoding/binary"
      5 	"net/http"
      6 	"slices"
      7 	"testing"
      8 	"time"
      9 )
     10 
     11 func TestCreatedEnforcerEarnsFirstAbilityCapWithoutSeededExperience(t *testing.T) {
     12 	// Keep one admitted full-health Leet beside the ordinary creation position.
     13 	data := testNPCData()
     14 	group := &data.Playfields[0].Districts[0].Groups[0]
     15 	group.Levels, group.AppearanceStatus = [2]uint16{1, 1}, "inferred_species"
     16 	group.Positions = [][3]float32{{54.5, 14.75, 58}}
     17 	originalResources := resources
     18 	useNPCData(t, data)
     19 	resources = originalResources
     20 	world := newTestServer(t)
     21 	fields := creationForm()
     22 	fields.Set("head_mesh", "40132")
     23 	fields.Set("profession", "9")
     24 	if response := creationRequest(world, accountVisitor(t, world), fields); response.Code != http.StatusNoContent {
     25 		t.Fatal(response.Code, response.Body.String())
     26 	}
     27 	player := world.characters[2]
     28 	client := &worldClient{id: 2, conn: &combatTestConn{}, target: true, ready: true, npcs: map[uint32]bool{1000000: true}}
     29 	world.clients[2] = client
     30 	items := slices.Clone(player.inventory.Items)
     31 	if player.level != 1 || player.experience != 0 || player.inventory.Credits != 0 || player.stats.ImprovementPoints != 1500 || len(items) != 7 {
     32 		t.Fatal("ordinary creation did not start with zero earned progression", player.profile(), player.inventory)
     33 	}
     34 
     35 	trained := player.baseStats()
     36 	trained.Abilities.Agility, trained.Abilities.Stamina, trained.Body.BodyDevelopment = 9, 13, 10
     37 	request := skillTrainingRequest(trained)
     38 	binary.BigEndian.PutUint32(request[28:32], player.id)
     39 	if err := world.handleSkillTraining(client, request[20:]); err != nil {
     40 		t.Fatal(err)
     41 	}
     42 	if err := world.handleInventory(client, inventoryMovePacket(2, 67, 6)[20:]); err != nil || client.equipment == nil {
     43 		t.Fatal("issued bat did not begin equipping", err)
     44 	}
     45 	world.advanceEquipment(client.equipment.readyAt)
     46 	items[3].Slot = 6
     47 	trained = player.baseStats()
     48 	trained.Abilities.Agility = 11
     49 	request = skillTrainingRequest(trained)
     50 	binary.BigEndian.PutUint32(request[28:32], player.id)
     51 	if err := world.handleSkillTraining(client, request[20:]); err != nil {
     52 		t.Fatal(err)
     53 	}
     54 
     55 	if player.stats.ImprovementPoints != 1390 || player.stats.Abilities.Agility != 9 || player.maximumHealth() != 84 || player.health != 60 ||
     56 		!slices.Equal(player.inventory.Items, items) {
     57 		t.Fatal("training/equipping granted health, bypassed the level cap or changed issued items", player.stats, player.health, player.inventory)
     58 	}
     59 
     60 	// Controlled endpoint rolls isolate progression, rather than random survival balance.
     61 	world.combatRoll = func(limit uint32) uint32 {
     62 		if limit == 100 {
     63 			return 99
     64 		}
     65 		if limit == 4 {
     66 			return 3
     67 		}
     68 		return 0
     69 	}
     70 	now := time.Now().Add(time.Second)
     71 	client.regenerationAt = now
     72 	npc := world.characters[1000000]
     73 
     74 	for index, experience := range []uint32{100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 50} {
     75 		// Advance real recovery ticks; never refill resources or reset an enemy's HP.
     76 		if err := world.handlePosture(client, characterActionPacket(2, [5]uint32{86})[20:]); err != nil {
     77 			t.Fatal(err)
     78 		}
     79 		for ticks := 0; ticks < 500 && (player.health < player.maximumHealth() || len(world.npcRespawns) != 0); ticks++ {
     80 			now = now.Add(2 * time.Second)
     81 			world.advanceRegeneration(now)
     82 			world.advanceNPCRespawns(now)
     83 		}
     84 		if index != 0 {
     85 			world.advanceCorpseExpiry(now)
     86 			npc = world.characters[world.nextNPC-1]
     87 		}
     88 		if player.health != 84 || npc == nil || npc.health != 20 || npc.corpse != nil {
     89 			t.Fatal("ordinary recovery/respawn did not prepare a full-health encounter", index, player.health, npc)
     90 		}
     91 		if err := world.handlePosture(client, characterActionPacket(2, [5]uint32{87})[20:]); err != nil {
     92 			t.Fatal(err)
     93 		}
     94 		if err := world.handleCombat(client, attackPacket(2, npc.id)[20:]); err != nil {
     95 			t.Fatal(err)
     96 		}
     97 		for ticks := 0; ticks < 1200 && player.health != 0 && npc.health != 0; ticks++ {
     98 			now = now.Add(100 * time.Millisecond)
     99 			world.advanceCombat(now)
    100 			world.advanceRegeneration(now)
    101 		}
    102 		cold := newTestInventoryServer(t).characters[2]
    103 
    104 		level, points := uint16(1), uint32(1390)
    105 		if index == 14 {
    106 			level, points = 2, 5390
    107 		}
    108 		if player.health == 0 || npc.health != 0 || npc.corpse == nil || npc.corpse.looter != 2 ||
    109 			player.level != level || player.experience != experience || player.stats.ImprovementPoints != points ||
    110 			cold.level != level || cold.experience != experience || cold.stats != player.stats ||
    111 			!slices.Equal(player.inventory.Items, items) || !slices.Equal(cold.inventory.Items, items) ||
    112 			player.inventory.Credits != 0 || cold.inventory.Credits != 0 {
    113 			t.Fatal("full encounter changed the earned level, IP or issued ownership", index, player.health, npc.health, player.profile(), cold.profile())
    114 		}
    115 	}
    116 
    117 	trained = player.baseStats()
    118 	trained.Abilities.Agility = 11
    119 	request = skillTrainingRequest(trained)
    120 	binary.BigEndian.PutUint32(request[28:32], player.id)
    121 	if err := world.handleSkillTraining(client, request[20:]); err != nil {
    122 		t.Fatal(err)
    123 	}
    124 	cold := newTestInventoryServer(t).characters[2]
    125 
    126 	if player.level != 2 || player.experience != 50 || player.stats.Abilities.Agility != 11 || player.stats.ImprovementPoints != 5352 ||
    127 		player.maximumHealth() != 91 || cold.stats != player.stats || cold.level != 2 || cold.experience != 50 ||
    128 		!slices.Equal(player.inventory.Items, items) || !slices.Equal(cold.inventory.Items, items) {
    129 		t.Fatal("earned cap training changed its price, level or original item identities", player.profile(), cold.profile())
    130 	}
    131 }