aorecomp

Anarchy Online classic in the browser

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


server/combat_stats_test.go (1741B)


      1 package main
      2 
      3 import (
      4 	"encoding/binary"
      5 	"testing"
      6 )
      7 
      8 func TestCombatPlayerHealthMatchesBreedAndSoldierTitle(t *testing.T) {
      9 	for _, scenario := range []struct {
     10 		breed  uint16
     11 		level  uint16
     12 		title  uint32
     13 		health uint32
     14 	}{
     15 		{1, 1, 1, 37}, {2, 1, 1, 41}, {3, 1, 1, 29}, {4, 1, 1, 59},
     16 		{5, 1, 1, 65}, {0, 1, 1, 18}, {6, 1, 1, 18}, {7, 1, 1, 18},
     17 		{1, 14, 1, 115}, {1, 15, 2, 136}, {1, 49, 2, 374},
     18 		{1, 50, 3, 431}, {1, 99, 3, 823}, {1, 100, 4, 931},
     19 		{1, 149, 4, 1372}, {1, 150, 5, 1531}, {1, 189, 5, 1921},
     20 		{1, 190, 6, 2121}, {1, 200, 6, 2231},
     21 	} {
     22 		data := userData{ID: 1, Level: scenario.level, Appearance: scenario.breed << 4, Stats: testCharacterStats()}
     23 
     24 		player := data.character()
     25 		packet := fullCharacterPacket(player)
     26 		stats := make(map[uint32]uint32)
     27 		count := binary.BigEndian.Uint32(packet[64:68])/1009 - 1
     28 		for offset := 68; offset < 68+int(count)*8; offset += 8 {
     29 			stats[binary.BigEndian.Uint32(packet[offset:offset+4])] = binary.BigEndian.Uint32(packet[offset+4 : offset+8])
     30 		}
     31 
     32 		if player.health != scenario.health || stats[27] != scenario.health || stats[1] != scenario.health || stats[37] != scenario.title || stats[60] != 1 {
     33 			t.Fatalf("breed %d level %d: health=%d stats=%v", scenario.breed, scenario.level, player.health, stats)
     34 		}
     35 	}
     36 }
     37 
     38 func TestCombatProfileEditClampsHealthToNewMaximum(t *testing.T) {
     39 	t.Chdir(t.TempDir())
     40 	world, _ := newCombatWorld(t)
     41 	world.characters[1].health = 59
     42 	destination := world.characters[1].userData()
     43 	destination.Level = 1
     44 	destination.Appearance = 3 << 4
     45 
     46 	err := world.updateUser(destination)
     47 
     48 	if err != nil || world.characters[1].health != 29 {
     49 		t.Fatalf("profile edit left health over its maximum: %d, %v", world.characters[1].health, err)
     50 	}
     51 }