aorecomp

Anarchy Online classic in the browser

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


server/combat_health_refresh_test.go (2397B)


      1 package main
      2 
      3 import (
      4 	"encoding/binary"
      5 	"testing"
      6 	"time"
      7 )
      8 
      9 func TestHealthBuffCombatCorrectionFollowsEffectAndRetainsAttack(t *testing.T) {
     10 	for _, scenario := range []string{"refresh", "upgrade", "replace clamp", "cancel clamp"} {
     11 		t.Run(scenario, func(t *testing.T) {
     12 			world, output := newMaximumHealthNanoWorld(t)
     13 			player, npc := world.characters[1], world.characters[1000000]
     14 			player.inventory.LearnedNanos = []uint32{29091, 95696, 29254, 95693}
     15 			initial, replacement, expected := uint32(29091), uint32(29091), uint32(57)
     16 			switch scenario {
     17 			case "upgrade":
     18 				replacement = 95696
     19 			case "replace clamp":
     20 				initial, replacement, expected = 29254, 95693, 398
     21 			case "cancel clamp":
     22 				expected = 37
     23 			}
     24 			castTestBuff(t, world, 1, 1, initial)
     25 			player.health = player.maximumHealth()
     26 			player.nanoRechargeUntil = time.Time{}
     27 			if err := world.savePosition(player); err != nil {
     28 				t.Fatal(err)
     29 			}
     30 			updates := make(map[*worldClient][][]byte)
     31 			world.startAttack(npc, player, time.Now(), updates)
     32 			attack, recharge := npc.nextAttack, npc.rechargeUntil
     33 			output.packets = nil
     34 
     35 			if scenario == "cancel clamp" {
     36 				if err := world.handleNanoRemoval(world.clients[1], characterActionPacket(1, [5]uint32{65, 0, 0, 53019, initial})[20:]); err != nil {
     37 					t.Fatal(err)
     38 				}
     39 			} else {
     40 				castTestBuff(t, world, 1, 1, replacement)
     41 			}
     42 			cold := newTestInventoryServer(t)
     43 
     44 			effect, correction, snapshots := -1, -1, 0
     45 			for index, packet := range output.packets {
     46 				if binary.BigEndian.Uint32(packet[16:20]) == 0x5e477770 {
     47 					action := binary.BigEndian.Uint32(packet[29:33])
     48 					if action == 65 || action == 177 {
     49 						effect = index
     50 					}
     51 				}
     52 				if binary.BigEndian.Uint32(packet[16:20]) == 0x3710256c {
     53 					correction, snapshots = index, snapshots+1
     54 					if binary.BigEndian.Uint32(packet[29:33]) != expected || binary.BigEndian.Uint32(packet[33:37]) != 0 {
     55 						t.Fatal("combat correction changed real HP or added damage feedback")
     56 					}
     57 				}
     58 			}
     59 			if effect < 0 || correction <= effect || snapshots != 1 || player.health != expected || cold.characters[1].health != expected ||
     60 				npc.fighting != 1 || npc.nextAttack != attack || npc.rechargeUntil != recharge {
     61 				t.Fatal("health modifier completion lacked ordered combat-safe correction or changed the incoming attack", effect, correction, snapshots, player.health)
     62 			}
     63 		})
     64 	}
     65 }