aorecomp

Anarchy Online classic in the browser

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


server/combat_range_test.go (1850B)


      1 package main
      2 
      3 import (
      4 	"fmt"
      5 	"testing"
      6 )
      7 
      8 func TestCombatMeleeUsesActorExtentsAtThreeDimensionalBoundary(t *testing.T) {
      9 	for _, scenario := range []struct {
     10 		name     string
     11 		position [3]float32
     12 		accepted bool
     13 	}{
     14 		{"axis boundary", [3]float32{9, 0, 0}, true},
     15 		{"outside axis", [3]float32{9.125, 0, 0}, false},
     16 		{"diagonal boundary", [3]float32{6, 3, 6}, true},
     17 		{"outside diagonal", [3]float32{6, 3.125, 6}, false},
     18 	} {
     19 		t.Run(scenario.name, func(t *testing.T) {
     20 			world, _ := newCombatWorld(t)
     21 			npc := world.characters[1000000]
     22 			npc.monsterData, npc.position = 17655, scenario.position
     23 
     24 			err := world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:])
     25 			if world.characters[1].fighting != 0 {
     26 				world.advanceCombat(world.characters[1].nextAttack)
     27 			}
     28 
     29 			if err != nil || (npc.health < 100) != scenario.accepted || (world.characters[1].fighting != 0) != scenario.accepted {
     30 				t.Fatalf("extent-based 9m range: accepted=%v hp=%d err=%v", scenario.accepted, npc.health, err)
     31 			}
     32 		})
     33 	}
     34 }
     35 
     36 func TestCombatLeetRangeIncludesItsOwnExtentTwice(t *testing.T) {
     37 	for _, distance := range []float32{10, 10.125} {
     38 		if !t.Run(fmt.Sprint(distance), func(t *testing.T) {
     39 			world, _ := newCombatWorld(t)
     40 			player, npc := world.characters[1], world.characters[1000000]
     41 			npc.monsterData = 17655
     42 			world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:])
     43 			world.advanceCombat(player.nextAttack)
     44 			world.handleCombat(world.clients[1], stopFightPacket(1)[20:])
     45 			player.position[0] = npc.position[0] + distance
     46 			before := player.health
     47 
     48 			world.advanceCombat(npc.nextAttack)
     49 
     50 			if (player.health < before) != (distance == 10) || (npc.fighting != 0) != (distance == 10) {
     51 				t.Fatalf("Leet 10m range: distance=%v health=%d target=%d", distance, player.health, npc.fighting)
     52 			}
     53 		}) {
     54 			return
     55 		}
     56 	}
     57 }