aorecomp

Anarchy Online classic in the browser

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


server/east_wind_damage_test.go (2225B)


      1 package main
      2 
      3 import (
      4 	"testing"
      5 	"time"
      6 )
      7 
      8 func TestEastWindWeightedDamageAndCadenceWithoutAmmunition(t *testing.T) {
      9 	for _, critical := range []bool{false, true} {
     10 		t.Run(map[bool]string{false: "normal", true: "critical"}[critical], func(t *testing.T) {
     11 			world, _ := newRangedWorld(t)
     12 			player, target := world.characters[1], world.characters[1000000]
     13 			player.profession = 6
     14 			player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
     15 			player.stats.Melee.TwoHandEdged, player.stats.Melee.MeleeEnergy, player.stats.Body.Brawling = 401, 202, 20
     16 			player.stats.Speed.MeleeInitiative, player.aggDef = 0, 75
     17 			player.inventory.Items[0].Template, player.inventory.Items[0].Quality, player.inventory.Items[0].Ammo = 160216, 2, 0
     18 			target.position = [3]float32{1, 0, 0}
     19 			if err := world.saveUser(player); err != nil {
     20 				t.Fatal(err)
     21 			}
     22 			if err := world.saveInventory(player, player.inventory); err != nil {
     23 				t.Fatal(err)
     24 			}
     25 			world.combatRoll = func(limit uint32) uint32 {
     26 				if limit == 10000 || limit == 100 && critical {
     27 					return 0
     28 				}
     29 				return limit - 1
     30 			}
     31 
     32 			if err := world.handleCombat(world.clients[1], attackPacket(1, target.id)[20:]); err != nil {
     33 				t.Fatal(err)
     34 			}
     35 			hit := player.nextAttack
     36 			world.advanceCombat(hit)
     37 			cold := newTestInventoryServer(t)
     38 
     39 			expectedHealth := uint32(956)
     40 			if critical {
     41 				expectedHealth = 933
     42 			}
     43 			// Nonlethal HP waits for the normal checkpoint; item state stays durable.
     44 			if player.attackRating() != 334 || target.health != expectedHealth || cold.characters[1000000].health != 1000 ||
     45 				player.rechargeUntil.Sub(hit) != 2500*time.Millisecond || player.nextAttack.Sub(hit) != 5*time.Second ||
     46 				player.inventory.Items[0].Ammo != 0 || cold.characters[1].inventory.Items[0].Ammo != 0 ||
     47 				cold.characters[1].inventory.Items[1].Count != 100 {
     48 				t.Fatalf("rating=%d health=%d coldHealth=%d recharge=%v next=%v ammo=%d coldAmmo=%d stack=%d",
     49 					player.attackRating(), target.health, cold.characters[1000000].health, player.rechargeUntil.Sub(hit), player.nextAttack.Sub(hit),
     50 					player.inventory.Items[0].Ammo, cold.characters[1].inventory.Items[0].Ammo, cold.characters[1].inventory.Items[1].Count)
     51 			}
     52 		})
     53 	}
     54 }