aorecomp

Anarchy Online classic in the browser

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


server/weapon_rating_test.go (2366B)


      1 package main
      2 
      3 import (
      4 	"ao/server/gamedata"
      5 	"fmt"
      6 	"testing"
      7 )
      8 
      9 func TestWeaponRatingsMatchNativeWeightedSkillContract(t *testing.T) {
     10 	for _, kind := range []uint32{12, 13} {
     11 		for _, scenario := range []struct {
     12 			npc                  bool
     13 			first, second        uint16
     14 			weight               uint32
     15 			skillBonus, modifier int32
     16 			want                 int32
     17 		}{
     18 			{false, 125, 125, 50, 0, 7, 131},
     19 			{true, 125, 125, 50, 100, 7, 131},
     20 			{false, 125, 125, 50, 100, 7, 231},
     21 			{false, 3, 3, 33, 0, 99, 0},
     22 			{false, 125, 129, 50, -128, 99, -1},
     23 			{false, 125, 131, 50, -128, 99, 0},
     24 			{false, 3, 3, 50, 0, -7, -5},
     25 			{true, 3, 3, 50, -128, -7, -5},
     26 		} {
     27 			t.Run(fmt.Sprintf("%d/%+v", kind, scenario), func(t *testing.T) {
     28 				actor := &character{npc: scenario.npc, stats: testCharacterStats()}
     29 				actor.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
     30 				first, second, modifier := int32(100), int32(102), int32(276)
     31 				actor.stats.Body.MartialArts, actor.stats.Melee.OneHandBlunt = scenario.first, scenario.second
     32 				if kind == 13 {
     33 					first, second, modifier = 155, 154, 277
     34 					actor.stats.Speed.EvadeClose, actor.stats.Speed.DodgeRanged = scenario.first, scenario.second
     35 				}
     36 				weights := [][2]uint32{{uint32(first), scenario.weight}, {uint32(second), scenario.weight}}
     37 				entries := []gamedata.ItemEntry{{Type: &kind, Stats: &weights}}
     38 				weapon := &gamedata.Item{Sections: []gamedata.ItemSection{{Type: 4, Subtype: 4, Entries: &entries}}}
     39 				functions := []gamedata.ItemFunction{
     40 					{ID: 53045, Arguments: []gamedata.ItemArgument{{Integer: &first}, {Integer: &scenario.skillBonus}}},
     41 					{ID: 53045, Arguments: []gamedata.ItemArgument{{Integer: &second}, {Integer: &scenario.skillBonus}}},
     42 					{ID: 53045, Arguments: []gamedata.ItemArgument{{Integer: &modifier}, {Integer: &scenario.modifier}}},
     43 				}
     44 				original := gamedata.NanoTemplates[43371]
     45 				program := *original
     46 				program.Sections = []gamedata.ItemSection{{Type: 2, Subtype: 0, Functions: &functions}}
     47 				gamedata.NanoTemplates[43371] = &program
     48 				t.Cleanup(func() { gamedata.NanoTemplates[43371] = original })
     49 				actor.activeNanos = []activeNano{{program: 43371}}
     50 
     51 				rating := actor.weaponRating(weapon, kind)
     52 
     53 				if rating != scenario.want {
     54 					t.Fatalf("native weighted rating: got %d want %d", rating, scenario.want)
     55 				}
     56 			})
     57 		}
     58 	}
     59 }