aorecomp

Anarchy Online classic in the browser

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


server/resurrection_shock_test.go (3952B)


      1 package main
      2 
      3 import (
      4 	"fmt"
      5 	"testing"
      6 	"time"
      7 )
      8 
      9 func TestResurrectionShockMatchesOriginalGetter(t *testing.T) {
     10 	player := &character{stats: testCharacterStats(), resurrectionShock: 5000}
     11 	player.stats.Abilities = characterAbilitiesStats{200, 200, 200, 200, 200, 200}
     12 	player.activeNanos = syntheticNanoModifiers(t, [][2]int32{{21, 15}, {162, 20}})
     13 
     14 	ability := player.effectiveAbility(21)
     15 	skill := player.effectiveSkill(162, 300, [6]uint32{0, 0, 0, 0, 0, 100})
     16 	player.resurrectionShock = 27
     17 	lastAbility := player.effectiveAbility(21)
     18 	lastSkill := player.effectiveSkill(162, 300, [6]uint32{0, 0, 0, 0, 0, 100})
     19 
     20 	if ability != 116 || skill != 185 || lastAbility != 215 || lastSkill != 373 || player.stats.Abilities.Psychic != 200 {
     21 		t.Fatalf("native reduction/trickle/direct bonuses: %d/%d, final %d/%d", ability, skill, lastAbility, lastSkill)
     22 	}
     23 }
     24 
     25 func TestResurrectionShockStartsAtLevelFifteenAndPersists(t *testing.T) {
     26 	for _, level := range []uint16{14, 15} {
     27 		t.Run(fmt.Sprint(level), func(t *testing.T) {
     28 			t.Chdir(t.TempDir())
     29 			world, _ := newCombatWorld(t)
     30 			loadResurrectionLocations(t, world)
     31 			player := world.characters[1]
     32 			player.name, player.appearance = "Shock", 0x515
     33 			player.level, player.health = level, 0
     34 			if err := world.saveUser(player); err != nil {
     35 				t.Fatal(err)
     36 			}
     37 
     38 			if err := world.handleResurrection(world.clients[1], resurrectionRequest(1)[20:]); err != nil {
     39 				t.Fatal(err)
     40 			}
     41 			cold := newServerForTest(t)
     42 
     43 			want := uint32(0)
     44 			if level == 15 {
     45 				want = 5000
     46 			}
     47 			if player.resurrectionShock != want || cold.characters[1].resurrectionShock != want || cold.characters[1].health != 1 {
     48 				t.Fatal("resurrection lost the level gate or durable onset")
     49 			}
     50 		})
     51 	}
     52 }
     53 
     54 func TestResurrectionShockRecoversOnNativePhaseAndCheckpoints(t *testing.T) {
     55 	t.Chdir(t.TempDir())
     56 	world, _, start := newRegenerationWorld(t)
     57 	player := world.characters[1]
     58 	player.name, player.appearance = "Shock", 0x515
     59 	player.rotation = [4]float32{0, 0, 0, 1}
     60 	player.resurrectionShock = 5000
     61 	if err := world.saveUser(player); err != nil {
     62 		t.Fatal(err)
     63 	}
     64 
     65 	world.advanceRegeneration(start.Add(2*time.Second - time.Nanosecond))
     66 	if player.resurrectionShock != 5000 {
     67 		t.Fatal("shock recovered before the two-second phase")
     68 	}
     69 	world.advanceRegeneration(start.Add(2 * time.Second))
     70 	if player.resurrectionShock != 4973 || player.savedVitals.ResurrectionShock != 5000 {
     71 		t.Fatal("shock tick changed its decrement or persisted simulation state immediately")
     72 	}
     73 	for second := 4; second <= 370; second += 2 {
     74 		world.advanceRegeneration(start.Add(time.Duration(second) * time.Second))
     75 	}
     76 	if player.resurrectionShock != 5 {
     77 		t.Fatal("shock reached zero before the 186th check")
     78 	}
     79 	world.advanceRegeneration(start.Add(372 * time.Second))
     80 	if err := world.savePosition(player); err != nil {
     81 		t.Fatal(err)
     82 	}
     83 	cold := newServerForTest(t)
     84 
     85 	if player.resurrectionShock != 0 || cold.characters[1].resurrectionShock != 0 {
     86 		t.Fatal("shock underflowed or returned after a cold load")
     87 	}
     88 }
     89 
     90 func TestResurrectionShockBlocksWeaponQualificationUntilRecovery(t *testing.T) {
     91 	player := &character{level: 100, profession: 7, stats: testCharacterStats()}
     92 	player.stats.Abilities = characterAbilitiesStats{200, 200, 200, 200, 200, 200}
     93 	player.stats.Ranged.Shotgun = 300
     94 	item := ownedItem{Type: 51018, Template: 124261, Quality: 75}
     95 	if !player.canEquip(item) {
     96 		t.Fatal("unpenalized control cannot equip the weapon")
     97 	}
     98 	maximumHealth, maximumNano := player.maximumHealth(), player.maximumNano()
     99 
    100 	player.resurrectionShock = 5000
    101 	canEquip := player.canEquip(item)
    102 	health, nano := player.maximumHealth(), player.maximumNano()
    103 	player.resurrectionShock = 0
    104 
    105 	if canEquip || !player.canEquip(item) || health >= maximumHealth || nano >= maximumNano || player.maximumHealth() != maximumHealth || player.maximumNano() != maximumNano {
    106 		t.Fatal("shock did not affect qualification and restore derived resources")
    107 	}
    108 }