commit fd5d2319215b766d9112783095539ce810dcfe8f
parent 0d112e604721f336868587731726480eeccf5253
Author: anon <anon@example.com>
Date: Thu, 22 Oct 2026 12:33:15 +0000
Scale player weapon damage with attack rating
Diffstat:
8 files changed, 262 insertions(+), 12 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -80,7 +80,7 @@ bonus milestones use AC; broader skill and resource modifiers remain future work
sourced results, including the minimum-damage boundary.
- [x] Select armor by damage type. Check: changing only the attack's damage type
selects the corresponding protection rather than a universal armor value.
-- [ ] Scale one weapon's damage with attack rating. Check: fixed stats and rolls
+- [x] Scale one weapon's damage with attack rating. Check: fixed stats and rolls
match documented expected amounts at representative boundaries.
- [ ] Select Martial Arts fist QL from skill. Check: known MA values select the
evidenced template/QL and change damage without equipping a weapon.
@@ -92,6 +92,10 @@ bonus milestones use AC; broader skill and resource modifiers remain future work
long native fight, prediction drift is corrected to server HP without extra
nanobot-damage chat or floating damage, including for an observer.
+The supported axe and fixed-QL fists use the period attack-rating multiplier;
+fractional endpoint rounding remains provisional. See
+[attack-rating damage](docs/combat-attack-rating.md) for sources and checks.
+
## Additional weapon actions
- [ ] Fire one ranged weapon with a loaded magazine. Check: it attacks outside
diff --git a/docs/armor.md b/docs/armor.md
@@ -56,7 +56,8 @@ The [September 2001 Vampi weapon guide](https://martin.brenner.de/ao/vampiguide/
describes damage reduction of AC/10, bounded by the weapon's adjusted minimum.
The [July 2002 player experiments](https://forums-archive.anarchy-online.com/printthread.php?page=1&pp=20&t=36008)
corroborate the ratio and minimum floor. These are period observations rather
-than a recovered server implementation. The current normal-hit calculation is:
+than a recovered server implementation. Player endpoints and the minimum floor
+first include [attack rating](combat-attack-rating.md). The normal-hit reduction is:
```text
raw = uniform_integer(weapon_minimum, weapon_maximum)
@@ -67,9 +68,9 @@ Truncating AC/10 before subtraction is provisional: the sources do not settle
integer ordering for fractional reductions. For example, raw 200 with 1000 AC
becomes 100, while a QL 1 Leet Bite roll of 4..8 against 875 Melee AC becomes
4. Tests also record the provisional fractional case, 200 against 875 becoming
-113. Attack-rating scaling, damage additions, hit/critical rolls, NPC armor,
-absorbs, reflects and shields remain separate work. Fists still use the QL 1
-3..5 endpoints; supported weapons retain their catalog endpoints.
+113. Damage additions, hit/critical rolls, NPC armor, absorbs, reflects and
+shields remain separate work. Fists still use the QL 1 3..5 base endpoints;
+supported weapons retain their catalog endpoints.
## Native move and effect messages
diff --git a/docs/combat-attack-rating.md b/docs/combat-attack-rating.md
@@ -0,0 +1,96 @@
+# Player attack-rating damage in 14.9.1
+
+The supported QL 1 Kinetic Axe now scales normal damage with effective
+1-Hand Edged. Its catalog entry, template 209283 in
+`server/gamedata/items/items_165.yaml`, selects 100% stat 103 in attack-skill
+section 12. Its unscaled damage is 5..20. Effective skill includes the shipped
+30% Strength, 40% Agility and 30% Stamina trickle, with the native floating-point
+truncation already used by the [editable stats](combat-regeneration.md).
+
+The [July 2002 weapon guide](https://forums-archive.anarchy-online.com/showthread.php?37266-How-to-Choose-A-Weapon-Guide-for-the-MP=)
+attributes the multiplier `1 + AR/400` to Rustot and illustrates tripling
+weapon endpoints at AR 800. The
+[July 2002 damage experiments](https://forums-archive.anarchy-online.com/printthread.php?page=1&pp=20&t=36008)
+independently describe the same ratio. These are contemporary player findings,
+not the original server code. The implementation follows that period linear
+formula, including ratings above 1000.
+
+The client-side rating calculation is established separately in
+[client stat research](combat-client-stats.md): `FUN_1008f1f0` weights attack
+skills and adds stat 276 to a positive rating; `FUN_1007c120` selects the
+weapon's rating or Martial Arts when unarmed. The currently supported gear
+has no Add All Offense modifiers or mixed attack-skill weights. The server
+therefore uses effective 1-Hand Edged with the axe and effective Martial Arts
+with fists, without introducing a generic stat-effect interpreter.
+
+Normal player hits follow this order:
+
+```text
+minimum = base_minimum + floor(base_minimum * AR / 400)
+maximum = base_maximum + floor(base_maximum * AR / 400)
+rolled = uniform_integer(minimum, maximum)
+damage = rolled - min(rolled - minimum, floor(selected_AC / 10))
+```
+
+The scaled minimum is the AC floor. Uniform sampling of integer endpoints,
+truncating fractional endpoints before rolling, and truncating AC/10 before
+subtraction remain explicit reconstruction policies. The sources establish
+the multiplier, not those exact integer and random-number operations.
+
+| Effective axe AR | Normal endpoints before AC |
+| --- | --- |
+| 5 | 5..20 |
+| 99 | 6..24 |
+| 100 | 6..25 |
+| 399 | 9..39 |
+| 400 | 10..40 |
+| 401 | 10..40 |
+| 800 | 15..60 |
+| 1000 | 17..70 |
+| 1200 | 20..80 |
+
+The fractional cases in this table describe the provisional truncation policy.
+At AR 400, any axe roll against the supported 875 Melee AC chest bottoms out
+at 10, rather than the unscaled minimum of 5.
+
+NPC profiles still provide their unscaled catalog damage: their attack skills
+and Add All Offense values are not known. Player fists receive the multiplier
+but remain on the fixed QL 1 3..5 record; selecting their proper QL from Martial
+Arts is a separate TODO. Criticals, hit/miss rolls, damage additions and
+overequipping also remain separate work. These limits prevent a claim of
+complete canonical damage balance.
+
+## Verification
+
+`server/attack_rating_test.go` uses controlled endpoint rolls around the
+multiplier boundaries, a deliberately different Martial Arts skill to detect
+the wrong skill selection, native equip/unequip requests, persistent stats and
+ownership across restart, the scaled AC floor, and matching native damage/HP
+for owner and observer. Existing armor tests continue to verify that NPC bites
+retain their catalog damage.
+
+The two-client WASM comparison is retained in `local/attack-rating-smoke/`.
+Native controls equip and remove the axe and start Q combat. The existing
+profile editor raises base 1-Hand Edged from 398 to 798; the actor reconnects
+with that saved skill and the same equipped item. The native Stats window
+shows 800 while unarmed, 400 with the first axe profile and 800 after the edit.
+Temporary tracing confirms 10..40 axe endpoints at AR 400, 15..60 at AR 800,
+and 9..15 for the fixed-QL fists after removal. Owner and observer combat
+text show matching damage and weapon appearance.
+
+The fixture raises owner Body Development and the Leet's HP to sustain the
+comparison. Between encounters, fixture-only cancellation restores HP and
+stops both actors. These are test controls, not production NPC balance rules.
+
+`verification.json` and `tmp_verify.py` retain and check seven axe hits at AR
+400, seven at AR 800, five fist hits, and eight axe hits after server restart.
+The same item ID 102, QL 1 and right-hand slot 6 persist with base skill 798;
+the native Stats window still reports AR 800. Both clients restore weapon
+appearance and matching combat feedback. There are zero page errors or adapter
+failures, and 16 expected socket refusals during the intentional restart.
+The driver's `finally` closes both contexts and terminates the fixture server
+before Go regression builds.
+
+The full `go test ./server/...` suite passes. Focused `-race` checks for
+attack rating, character stats, armor, equipment, combat, inventory and reclaim
+also pass. Logs are retained alongside the WASM evidence.
diff --git a/docs/combat-client-reconstruction.md b/docs/combat-client-reconstruction.md
@@ -75,7 +75,8 @@ unknowns for each area:
| Health/death presentation and ordering | Native handlers plus browser encounters | Implemented for basic PvE; native player resurrection uses a provisional starter return |
| Weapon initiative/AggDef formulas | Exact native arithmetic and integer conversion | QL 1 fists, editable Physical Initiative and ability trickle; 250 ms resolution tick |
| AggDef request and stat update | Native request/serializer plus real slider request | Implemented; scheduled swing keeps its deadline |
-| QL 1 fist damage endpoints | Shipped item record | Normal uniform 3-5 roll; distribution and always-hit policy are local |
+| QL 1 fist damage endpoints | Shipped item record | Base 3..5, scaled by effective MA; distribution and always-hit policy are local |
+| Player attack-rating damage | Period AR/400 rule and native skill selection | Axe/fist normal endpoints and minimum floor scale; fractional truncation is provisional; [damage notes](combat-attack-rating.md) |
| Player max/current health and nano | Native formula, breed/title resources, browser 37/37 | Derived from editable abilities and base Body Development/Nano Pool; Soldier profession |
| Martial Arts selecting fist QL | Period observation; exact native selector not found | Fixed QL 1, not a recovered MA-to-QL selection rule |
| NPC health, damage and weapons | Level-1 Leet weapon data verified; binding and actor stats provisional | Exact-level Leet profile with replicated bite weapon; other NPCs retain prototype values |
diff --git a/docs/combat-rules.md b/docs/combat-rules.md
@@ -10,7 +10,10 @@ The REA records cited below are exported locally in
## Current implementation boundary
-Player fists now roll 3-5 normal damage from the shipped QL 1 record and use
+Player fists use the shipped QL 1 3..5 base endpoints, scaled by effective
+Martial Arts with the period `1 + AR/400` multiplier. The axe uses effective
+1-Hand Edged. Fractional endpoint truncation and the uniform normal roll remain
+provisional; see [attack-rating damage](combat-attack-rating.md). Timing uses
the native initiative/AggDef calculation below. Starting effective Physical
Initiative is 7. The native slider request updates server stat 51, and that
setting survives zoning and reconnection within the running server. A swing
diff --git a/docs/inventory.md b/docs/inventory.md
@@ -19,7 +19,7 @@ Only individual items at an exact catalog quality are supported. Template
endpoints are identical; arbitrary-quality interpolation, stacks, backpacks
and starter loadouts remain separate milestones. Native corpse pickup is
described in [the corpse and loot protocol](corpse-loot.md). QL 1 Kinetic Axe equipment
-is described below. Exact QL 1 Metaplast chest armor and boots use the
+is described below. Exact QL 1/200 Metaplast chest armor and QL 1 boots use the
[native armor path](armor.md). Other equipment remains unsupported.
## Native messages
@@ -152,8 +152,10 @@ is in `server/gamedata/items/items_165.yaml`. The Wield action requires effectiv
skill-weight resources are recorded in [editable stats](combat-regeneration.md).
The catalog supplies 5..20 base damage, attack/recharge delays 125 centiseconds,
equip delay 150 centiseconds, Melee Initiative 118 and mesh 40079
-(`weapon_handaxe.abiff`). Damage scaling, armor, criticals and specials remain
-separate milestones; the normal-damage distribution is still provisional.
+(`weapon_handaxe.abiff`). [Attack rating](combat-attack-rating.md) scales its
+normal damage and [armor](armor.md) reduces it to the scaled minimum floor.
+Criticals and specials remain separate work; the normal-damage distribution
+and fractional rounding are still provisional.
The native Wear window accepts left-click pickup from inventory and placement
into the right hand. `ContainerAddItem` uses source page 104 and logical slot
diff --git a/server/attack_rating_test.go b/server/attack_rating_test.go
@@ -0,0 +1,130 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "reflect"
+ "testing"
+)
+
+func TestAttackRatingAxeDamageEndpoints(t *testing.T) {
+ for _, scenario := range []struct {
+ name string
+ skill uint16
+ minimum, maximum uint32
+ }{
+ {"minimum wield skill", 3, 5, 20},
+ {"AR 99", 97, 6, 24}, {"AR 100", 98, 6, 25},
+ {"AR 399", 397, 9, 39}, {"AR 400", 398, 10, 40},
+ {"AR 401", 399, 10, 40}, {"AR 800", 798, 15, 60},
+ {"AR 1000", 998, 17, 70}, {"AR 1200", 1198, 20, 80},
+ } {
+ t.Run(scenario.name, func(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ player := world.characters[1]
+ player.stats.OneHandEdged, player.stats.MartialArts = scenario.skill, 2000
+ world.handleInventory(world.clients[1], inventoryMovePacket(1, 64, 6)[20:])
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+
+ minimum := player.normalDamage(world.characters[1000000], func(uint32) uint32 { return 0 })
+ maximum := player.normalDamage(world.characters[1000000], func(limit uint32) uint32 { return limit - 1 })
+
+ if minimum != scenario.minimum || maximum != scenario.maximum {
+ t.Fatalf("axe endpoints: got %d..%d want %d..%d", minimum, maximum, scenario.minimum, scenario.maximum)
+ }
+ })
+ }
+}
+
+func TestAttackRatingUnequipAndRestartSelectTheCurrentSkill(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ player := world.characters[1]
+ player.stats.OneHandEdged, player.stats.MartialArts = 398, 798
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ world.handleInventory(world.clients[1], inventoryMovePacket(1, 64, 6)[20:])
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+ target := world.characters[1000000]
+
+ maximum := func(limit uint32) uint32 { return limit - 1 }
+ axe := player.normalDamage(target, maximum)
+ restarted := newTestInventoryServer(t).characters[1].normalDamage(target, maximum)
+ world.handleInventory(world.clients[1], itemMovePacket(1, 6, 111)[20:])
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+ fists := player.normalDamage(target, maximum)
+ unarmedRestart := newTestInventoryServer(t).characters[1].normalDamage(target, maximum)
+
+ if axe != 40 || restarted != 40 || fists != 15 || unarmedRestart != 15 {
+ t.Fatalf("damage retained the wrong weapon/skill: axe %d restart %d fists %d restart %d", axe, restarted, fists, unarmedRestart)
+ }
+}
+
+func TestAttackRatingFistEndpointsIncludeZeroSkill(t *testing.T) {
+ for _, scenario := range []struct {
+ skill uint16
+ minimum, maximum uint32
+ }{
+ {0, 3, 5}, {400, 6, 10}, {800, 9, 15},
+ } {
+ attacker := &character{stats: defaultCharacterStats()}
+ attacker.stats.Strength, attacker.stats.Agility, attacker.stats.Psychic = 0, 0, 0
+ attacker.stats.MartialArts, attacker.stats.OneHandEdged = scenario.skill, 2000
+ target := &character{}
+
+ minimum := attacker.normalDamage(target, func(uint32) uint32 { return 0 })
+ maximum := attacker.normalDamage(target, func(limit uint32) uint32 { return limit - 1 })
+
+ if minimum != scenario.minimum || maximum != scenario.maximum {
+ t.Fatalf("fixed QL 1 fists at AR %d: got %d..%d want %d..%d", scenario.skill, minimum, maximum, scenario.minimum, scenario.maximum)
+ }
+ }
+}
+
+func TestAttackRatingScaledMinimumPrecedesArmor(t *testing.T) {
+ world, _ := newArmorDamageWorld(t)
+ attacker := &character{stats: defaultCharacterStats(), inventory: playerInventory{
+ Items: []ownedItem{{1, 51018, 209283, 1, 6}},
+ }}
+ attacker.stats.OneHandEdged = 398
+ var hits []uint32
+
+ for _, roll := range []uint32{0, 15, 30} {
+ hits = append(hits, attacker.normalDamage(world.characters[1], func(limit uint32) uint32 {
+ if limit != 31 {
+ t.Fatalf("AR 400 axe range: got %d want 31", limit)
+ }
+ return roll
+ }))
+ }
+
+ if !reflect.DeepEqual(hits, []uint32{10, 10, 10}) {
+ t.Fatalf("armor crossed the scaled weapon minimum: %v", hits)
+ }
+}
+
+func TestAttackRatingNativeDamageMatchesBothObservers(t *testing.T) {
+ world, owner := newEquipmentWorld(t)
+ player, target := world.characters[1], world.characters[1000000]
+ player.stats.OneHandEdged = 398
+ world.handleInventory(world.clients[1], inventoryMovePacket(1, 64, 6)[20:])
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: 950, health: 100}
+ world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true, npcs: map[uint32]bool{1000000: true}}
+ owner.packets = nil
+
+ world.handleCombat(world.clients[1], attackPacket(1, target.id)[20:])
+ world.advanceCombat(player.nextAttack)
+ damage := binary.BigEndian.Uint32(owner.packets[1][29:33])
+ for index, packet := range owner.packets {
+ if len(observer.packets) <= index || !bytes.Equal(packet[16:], observer.packets[index][16:]) {
+ t.Fatal("observers disagree on attack-rating damage")
+ }
+ }
+
+ if damage < 10 || damage > 40 || target.health != 100-damage || len(owner.packets) != len(observer.packets) ||
+ binary.BigEndian.Uint32(owner.packets[1][37:41]) != 6 {
+ t.Fatalf("scaled native axe hit: damage %d HP %d packets %x", damage, target.health, owner.packets)
+ }
+}
diff --git a/server/combat.go b/server/combat.go
@@ -134,9 +134,10 @@ func (character *character) maximumNano() uint32 {
}
func (attacker *character) normalDamage(target *character, roll func(uint32) uint32) uint32 {
- // Exact catalog endpoints; attack-rating scaling remains a separate rule.
+ // Exact catalog endpoints and the weapon's native protection type.
minimum, maximum, damageType := uint32(3), uint32(5), uint32(91)
- if weapon := attacker.meleeWeapon(); weapon != nil {
+ weapon := attacker.meleeWeapon()
+ if weapon != nil {
minimum, maximum, damageType = itemStat(weapon, 286), itemStat(weapon, 285), itemStat(weapon, 436)
// kkr.dll FUN_100ab7b0 accepts the eight ACs and NanoAC, else ProjectileAC.
if (damageType < 90 || damageType > 97) && damageType != 168 {
@@ -146,6 +147,18 @@ func (attacker *character) normalDamage(target *character, roll func(uint32) uin
minimum, maximum = 5, 5
}
+ // Player fists use MA; the supported axe uses 100% 1-Hand Edged.
+ // NPC attack skills remain unknown. Fractional endpoint truncation is provisional.
+ if !attacker.npc {
+ stats := attacker.baseStats()
+ rating := stats.effectiveSkill(stats.MartialArts, [6]uint32{20, 50, 0, 0, 0, 30})
+ if weapon != nil {
+ rating = stats.effectiveSkill(stats.OneHandEdged, [6]uint32{30, 40, 30, 0, 0, 0})
+ }
+ minimum += minimum * rating / 400
+ maximum += maximum * rating / 400
+ }
+
// Period AC rule: reduce the rolled hit without crossing the weapon minimum.
// Truncating AC/10 before subtraction is provisional integer ordering.
damage := minimum + roll(maximum-minimum+1)