aorecomp

Anarchy Online classic in the browser

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


server/npc_growth_test.go (4290B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"fmt"
      6 	"testing"
      7 )
      8 
      9 func TestMissionEarlyGrowthLevelsSurviveColdAcceptance(t *testing.T) {
     10 	for _, expected := range []struct {
     11 		level   uint16
     12 		health  uint32
     13 		rating  int32
     14 		credits uint32
     15 	}{
     16 		{3, 30, 10, 7}, {4, 40, 15, 6}, {5, 50, 20, 5}, {6, 60, 25, 4},
     17 		{7, 70, 30, 3}, {8, 80, 35, 2}, {9, 90, 40, 1}, {10, 100, 45, 0},
     18 	} {
     19 		t.Run(fmt.Sprint(expected.level), func(t *testing.T) {
     20 			world, _ := newMissionOfferWorld(t)
     21 			player, client := world.characters[1], world.clients[1]
     22 			player.level, world.nextNPC = expected.level, 2000000
     23 			player.inventory.Credits = 10
     24 			if err := world.saveInventory(player, player.inventory); err != nil {
     25 				t.Fatal(err)
     26 			}
     27 			definition := gamedata.MissionTemplates[3221228472]
     28 			definition.RewardItems = []uint32{122691}
     29 			definition.Encounters = []gamedata.MissionEncounter{{Definition: "950/district/2/group/0/authored_point", Positions: [][3]float32{{15, 0, 43}}}}
     30 			gamedata.MissionTemplates[3221228472] = definition
     31 
     32 			if err := world.handleMissionOffers(client, missionOffersRequest()); err != nil {
     33 				t.Fatal(err)
     34 			}
     35 			if client.missionOffer == nil {
     36 				t.Fatal("reviewed early encounter was rejected")
     37 			}
     38 			if err := world.handleMissionAcceptance(client, missionAcceptanceRequest(*client.missionOffer)); err != nil {
     39 				t.Fatal(err)
     40 			}
     41 			cold := reloadMissionEntranceWorld(t)
     42 
     43 			npc := cold.characters[2000000]
     44 			if npc == nil || npc.level != expected.level || npc.health != expected.health || npc.combatProfile != gamedata.NPCCombatProfiles[17655][expected.level] ||
     45 				npc.attackRating() != expected.rating || npc.weaponRating(npc.attackWeapon(), 13) != expected.rating ||
     46 				cold.characters[1].inventory.Credits != expected.credits || cold.characters[1].missions[0].offer.definition.RewardQuality != uint32(expected.level) {
     47 				t.Fatal("cold encounter lost its level, resources, raw ratings, reward quality or fee", npc)
     48 			}
     49 		})
     50 	}
     51 }
     52 
     53 func TestEarlyGrowthKillRewardsRetainSelectedQualityAcrossRestart(t *testing.T) {
     54 	for _, expected := range []struct {
     55 		level      uint16
     56 		experience uint32
     57 		quality    uint32
     58 	}{
     59 		{3, 125, 2}, {4, 150, 3}, {5, 175, 4}, {6, 200, 5},
     60 		{7, 225, 6}, {8, 250, 7}, {9, 275, 8}, {10, 300, 9},
     61 	} {
     62 		for _, attack := range []string{"unarmed", "pistol", "nano"} {
     63 			t.Run(fmt.Sprintf("%d/%s", expected.level, attack), func(t *testing.T) {
     64 				world, _ := newKillExperienceWorld(t, attack)
     65 				target := world.characters[1000000]
     66 				target.level, target.combatProfile = expected.level, gamedata.NPCCombatProfiles[17655][expected.level]
     67 				world.combatRoll = func(uint32) uint32 { return 0 }
     68 				if err := world.flushWorld(); err != nil {
     69 					t.Fatal(err)
     70 				}
     71 
     72 				attackForExperience(t, world, attack)
     73 				cold := newTestInventoryServer(t)
     74 
     75 				for _, current := range []*server{world, cold} {
     76 					corpse := current.characters[1000000].corpse
     77 					if corpse == nil || len(corpse.items) != 1 || corpse.items[0].Template != 42640 || corpse.items[0].Quality != expected.quality ||
     78 						corpse.credits != 1 || current.characters[1].experience != expected.experience || current.characters[1000000].health != 0 {
     79 						t.Fatal("early growth death lost its selected quality, cash or XP", corpse)
     80 					}
     81 				}
     82 			})
     83 		}
     84 	}
     85 }
     86 
     87 func TestNPCProfileFoundationsUseExistingRatingAndArmorConsumers(t *testing.T) {
     88 	data := testNPCData()
     89 	data.Playfields[0].Districts[0].Groups[0].AppearanceStatus = "inferred_species"
     90 	data.Playfields[0].Districts[0].Groups[0].Levels = [2]uint16{4, 4}
     91 	useNPCData(t, data)
     92 	world := newTestServer(t)
     93 	npc := world.characters[1000000]
     94 	profile := *npc.combatProfile
     95 	profile.Modifiers = map[uint32]int32{276: 5, 277: 7, 91: 20}
     96 	npc.combatProfile = &profile
     97 
     98 	attack := npc.attackRating()
     99 	defense := npc.weaponRating(npc.attackWeapon(), 13)
    100 	armor := npc.equipmentBonus(91)
    101 
    102 	if npc.maximumHealth() != 40 || attack != 20 || defense != 22 || armor != 20 || npc.baseStats().Speed.NanoResist != 15 ||
    103 		npc.baseStats().Speed.DodgeRanged != 15 || npc.baseStats().Speed.DuckExplosions != 15 || len(gamedata.NPCCombatProfiles[17655][4].Modifiers) != 0 {
    104 		t.Fatal("NPC foundations gained player trickle, bypassed consumers or changed shared data", attack, defense, armor, npc.baseStats().Speed)
    105 	}
    106 }