commit 5ecf67df1a3b137b05e661d7a646ed516da1e749
parent b455c245ff1066ac9ee63a294626fc8d3c7f036a
Author: anon <anon@example.com>
Date: Sat, 24 Oct 2026 00:15:03 +0000
Apply original armor and backpack overequipping penalties
Diffstat:
13 files changed, 623 insertions(+), 34 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -116,15 +116,17 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
and remains correct after reconnect and removal.
- [x] Apply overequipping rules to one weapon. Check: dropping below a verified
requirement threshold changes effectiveness at the correct boundary.
-- [ ] Apply armor/backpack overequipping to AC and maximum health. Check:
+- [x] Apply armor/backpack overequipping to AC and maximum health. Check:
recovered requirement tiers, rounding and restoration agree with the native
- client, including after reconnect and in team resource snapshots. A Dust
- Collector assigned below its requirements loses its 90 HP/1200 ProjectileAC
- bonuses in the original client while the server still grants them; its 90
- maximum-nano bonus remains. Qualifying the wearer restores native agreement.
- Captures: `local/team-resources-research/equipped-fresh-solo.json` and
- `qualified-solo.json`. Do not generalize one zero-effectiveness case to all
- armor tiers or reduce unrelated bonuses without recovering their rules.
+ client, including after reconnect and in team resource snapshots. The recovered
+ table also reduces selected damage/range/skill bonuses while preserving nano
+ and utility effects. Native Dust Collector tiers, live skill recovery,
+ rejected re-equipping and QL100 Metaplast boundaries are verified in
+ [armor overequipping](docs/armor-overequipping.md).
+- [ ] Recover original maximum-HP clamp timing when armor effectiveness falls.
+ Check: original server/capture evidence distinguishes transient native modifier
+ replacement from final resource loss and fixes the ordering of HP publication.
+ Current inventory transactions clamp and persist the final resources atomically.
The supported Metaplast pieces, native appearance, combined AC bonuses and
server-side damage checks are recorded in [armor](docs/armor.md). These stat
diff --git a/docs/armor-overequipping.md b/docs/armor-overequipping.md
@@ -0,0 +1,149 @@
+# Armor and backpack overequipping in 14.9.1
+
+Clothing keeps its placement, appearance and contents when requirements fall.
+Selected equipment bonuses lose effectiveness in four 25-percent steps and
+recover when the effective requirements recover. The server derives the current
+bonuses from equipped instances and current character stats; it does not persist
+a second effectiveness state.
+
+## Original client evidence
+
+The original `anarchy-vanilla-14.9.1/kkr.dll` has SHA-256
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+Independent generated-instruction/catalog audits and four original-binary REA
+function dossiers are retained under `local/armor-oe-research/`.
+
+`FUN_10062f80` scans occupied clothing slots 16 through 31, skips NPC actors
+and inventory entries flagged 0x40, then evaluates `FUN_10090f10(6, actor)`.
+Its original dossier is
+`ev_a64f9e1c85cca6b2dd9aef9fc66293f96fbab04052c68dbaa4db8ee2cb0ef5b7`.
+Supported equipment uses ordinary entry flags. Item stat-0 flags such as NoDrop
+do not supply this slot exemption.
+
+The criterion evaluator considers every operator-2 requirement of action 6,
+including level and title level, and selects the worst tier. Equality and
+Boolean operators do not enter that arithmetic. Effective abilities, skill
+trickle and unpenalized requirement bonuses participate. It uses the authored
+requirement value as the denominator, independently of the strict comparison
+used when equipping. Missing action 6 gives tier zero: Pre-Universe Storage
+Device's action-8 requirements do not reduce its clothing bonuses.
+
+For each positive requirement with a lower effective value:
+
+```text
+tier = clamp(trunc((10 - effective / requirement * 10) * 0.5), 0, 4)
+```
+
+The server uses the equivalent nonnegative integer expression
+`min(4, (requirement - effective) * 5 / requirement)`. Original instructions
+retain an x87 intermediate. A host extended-precision C comparison checks all
+integer inputs below every denominator 1..1000, covering the supported catalog,
+and finds no disagreement with the integer expression. This comparison supports
+the arithmetic; it is not a historical server execution or an exhaustive claim
+for unsupported values. Criterion dossier:
+`ev_de9f9adf75f6be9dc20699c183224a80a67c57c6a991cf1248b5b13dce6317b6`.
+
+`FUN_10063130` selects event-14 Modify functions (53045) and, for each affected
+stat, removes the old contribution and adds the new contribution. Its dossier
+is `ev_fb148da07aea9c6f6c835956a3f7e87083f41291c35c4298b310e01c4f470981`.
+`FUN_10062f60` computes each signed effect as:
+
+```text
+adjusted = original - trunc_toward_zero(original * tier * 0.25)
+```
+
+Rounding is per effect before summation. A +90 bonus becomes 90, 68, 45, 23,
+0. Two separate +1 effects still total 2 at tier 1. Removing equipment first
+restores its old tier to zero through `FUN_100630e0`, allowing ordinary OnUnWear
+to remove the original contribution without leaving a residual modifier.
+
+`FUN_100734e0` selects an initialized native table of 47 affected stats:
+
+```text
+1,
+90,91,92,93,94,95,96,97,
+118,119,120,149,168,
+205,206,207,208,216,217,219,
+225,226,227,228,229,230,231,233,234,
+276,277,278,279,280,281,282,
+311,316,317,318,341,379,380,382,383,393
+```
+
+The original table initializer and PE zero-fill boundary are checked in
+`native-table.json`; predicate dossier:
+`ev_c28c25bf855fbf502273998e990a77883b83d1ceec6e91d25d10e207adb72748`.
+Maximum nano 221, NCU 181, run speed 156, abilities and Dust Collector's utility
+skills are absent. Robust Backpack's added damage and the rifle/range bonuses
+of Large Backpack - Ranged Weapons are present. Modified Pioneer's negative
+scale remains unchanged. No supported template has a negative affected bonus;
+the signed subtraction rule comes from the native arithmetic, not an invented
+catalog example.
+
+## Resources and observers
+
+Ordinary remote SimpleChar actors skip the local stat-driven OE refresh in
+`FUN_100714a0`; FullCharacter initialization and local stat refresh apply it to
+the owning actor. Thus the authored inventory bonus and the owning character's
+effective bonus are distinct quantities. Requirement evaluation retains access
+to raw bonuses; none of the supported requirement stats is in the affected
+table, so there is no feedback loop to solve.
+
+The owning FullCharacter packet supplies a foundation excluding its effective
+HP bonus. Public SimpleChar/stat corrections exclude the authored OnWear bonus
+instead, so remote OnWear produces the correct public total. After a team
+snapshot clears a remote actor's maximum modifier, the existing per-observer
+absorbed-bonus accounting still uses the authored contribution. Skill training
+that restores effectiveness and removal of reduced equipment use that same
+basis. See [team resources](team-resources.md) for combat ordering and actor
+replacement rules.
+
+Important equipment/skill changes remain immediately durable. No OE-derived
+cache or periodic modifier update is written to SQLite. Existing removal and
+resource-clamp transactions remain responsible for durable inventory/vitals.
+
+## Verification and limits
+
+Go regressions exercise all five Dust Collector effectiveness levels through
+profile updates, actual incoming damage, unchanged nano/utility bonuses and
+database reopen. Metaplast cases cover both required abilities, two sleeve
+instances, recovery without re-equipping, QL100 interpolated denominators and
+exact QL200 threshold equalities. Other cases cover Robust's level criterion
+and added damage, Survival's title criterion with an excluded profession
+equality, Pre-Universe's missing action 6, reduced rifle/range and preserved
+Pioneer bonuses. Native skill training crosses the Intelligence trickle boundary
+at 356/357, restoring the HP bonus for the owner, current teammate and former
+teammate without changing raw requirement/ownership data.
+
+The complete `go test ./server/... -count=1` suite passed in 287 seconds.
+Focused armor, team-resource, Robust, range and backpack checks passed twice
+under the race detector in 183 seconds. Removal checks also passed twice under
+the race detector.
+
+Two WASM clients rendered through the GPU verify Dust Collector's native
+HP bonuses 90/68/45/23/0 and ProjectileAC 1200/900/600/300/0, with unchanged
+maximum nano and utility modifiers. Both team bars use HP maxima
+1201/1179/1156/1134/1111. A fresh zero-effectiveness reconnect preserves the
+same item and derived maximum. Native training from Intelligence 355 to 357
+crosses the existing trickle boundary, restores HP 1201 for owner/teammate and
+leaves the accepted IP balance 78. The owning raw HP foundation remains 1111.
+
+An 18-sample fight retains maximum HP 1179 in both clients. Native impact
+animations differ transiently in phase, while both clients receive seven
+identical hit packets; the subsequent loaded state agrees on current HP.
+Native pickup/return removes the overequipped bag into inventory with the
+same instance identity and no residual HP/AC bonus. A re-equip attempt below
+requirements is rejected by the native UI and retains that inventory instance.
+QL100 Metaplast pants confirm native AC 312/234/156/78/0 at Strength
+186/185/139/92/46, restoration to 312 and removal to 0.
+
+`local/armor-oe-research/verification.json` checks these captures, received
+packets, item identities and conservation of all 192 original records and
+placements. Both temporary items were deleted through native confirmation
+dialogs; the team dissolved and edited profiles were restored exactly. All
+owned browser contexts closed without page/adapter errors. The single shared
+LAN preview remains available on HTTPS 8443.
+
+Historical server scheduling of resource clamps, unsupported conditional effect
+opcodes and feedback involving future item requirements remain separate evidence
+questions. The implementation covers the currently supported equipment catalog;
+it does not claim that every original item function is implemented.
diff --git a/docs/overequipping.md b/docs/overequipping.md
@@ -78,7 +78,9 @@ Zero effectiveness produces zero normal damage in this implementation; whether
the original server also blocked starting or continuing attacks is unresolved.
No additional attack-eligibility rule is inferred from the arithmetic alone.
Critical damage is not implemented, so its native adjustment is documented
-but not used by the server. Armor OE and other item types remain separate work.
+but not used by the server. [Armor and backpack OE](armor-overequipping.md)
+uses the recovered clothing path and affected-stat table. Other item types
+remain separate work.
The [July 2002 weapon guide](https://forums-archive.anarchy-online.com/showthread.php?37266-How-to-Choose-A-Weapon-Guide-for-the-MP=)
describes maintaining skill within 20% of the requirement and red hatching for
diff --git a/docs/team-resources.md b/docs/team-resources.md
@@ -114,10 +114,12 @@ the native inventory, the team dissolved and both edited profiles restored.
All owned browser contexts were closed without page/adapter errors. The single
shared LAN preview remains available on HTTPS 8443.
-The equipped fixture also exposed a separate server gap: assigning a Dust
-Collector below its requirements leaves native HP and AC bonuses at zero,
-while the server grants them. Nano retains its bonus. This occurs in a fresh
-solo client too, and qualifying the wearer restores HP/AC. The paired
+The equipped fixture also isolates armor effectiveness: assigning a Dust
+Collector below its requirements leaves native HP and AC bonuses at zero;
+nano retains its bonus. This occurs in a fresh solo client too, and qualifying
+the wearer restores HP/AC. The paired
`equipped-fresh-solo.json` and `qualified-solo.json` captures preserve that
-discriminator. Armor/backpack overequipping remains an explicit TODO; resource
-transport must not conceal it by modifying the native equipment behavior.
+discriminator. [Armor/backpack overequipping](armor-overequipping.md) now applies
+the recovered penalties on the server. Raw authored bonuses remain the basis
+for remote OnWear and observer absorption accounting, while the owning actor's
+foundation excludes its effective bonus.
diff --git a/server/armor_overequipping.go b/server/armor_overequipping.go
@@ -0,0 +1,67 @@
+package main
+
+import "ao/server/gamedata"
+
+func (character *character) equipmentBonus(stat uint32) int32 {
+ // FUN_100734e0's initialized table selects the bonuses affected by armor OE.
+ switch stat {
+ case 1, 90, 91, 92, 93, 94, 95, 96, 97, 118, 119, 120, 149, 168,
+ 205, 206, 207, 208, 216, 217, 219, 225, 226, 227, 228, 229, 230, 231, 233, 234,
+ 276, 277, 278, 279, 280, 281, 282, 311, 316, 317, 318, 341, 379, 380, 382, 383, 393:
+ default:
+ return character.inventory.equipmentBonus(stat)
+ }
+ if character.npc {
+ return character.inventory.equipmentBonus(stat)
+ }
+ var bonus int32
+ for _, item := range character.inventory.Items {
+ tier := uint32(0)
+ if item.Slot >= 16 && item.Slot < 32 && item.fitsEquipmentSlot(item.Slot) {
+ tier = character.armorOverequippingTier(item)
+ }
+ bonus += item.equipmentBonus(stat, tier)
+ }
+ return bonus
+}
+
+func (character *character) armorOverequippingTier(item ownedItem) uint32 {
+ // FUN_10062f80/10090f10 uses action 6 and every operator-2 criterion.
+ low, high := item.templateIDs()
+ first, second := gamedata.ItemTemplates[low], gamedata.ItemTemplates[high]
+ stats := character.baseStats()
+ var tier uint32
+ for sectionIndex, section := range first.Sections {
+ if section.Actions == nil {
+ continue
+ }
+ for actionIndex, action := range *section.Actions {
+ if action.Type != 6 {
+ continue
+ }
+ for index, requirement := range action.Requirements {
+ if requirement.Operator != 2 {
+ continue
+ }
+ var actual uint32
+ switch requirement.Stat {
+ case 16, 17, 19:
+ actual = character.effectiveAbility(uint32(requirement.Stat))
+ case 37:
+ actual = character.titleLevel()
+ case 54:
+ actual = uint32(character.level)
+ case 137:
+ actual = character.effectiveSkill(137, stats.Body.Adventuring, [6]uint32{20, 50, 30, 0, 0, 0})
+ case 161:
+ actual = character.effectiveSkill(161, stats.TradeRepair.ComputerLiteracy, [6]uint32{0, 0, 0, 100, 0, 0})
+ }
+ value := interpolateItemValue(requirement.Value, (*second.Sections[sectionIndex].Actions)[actionIndex].Requirements[index].Value, *first.Quality, *second.Quality, item.Quality)
+ if int32(actual) < value {
+ tier = max(tier, min(4, (uint32(value)-actual)*5/uint32(value)))
+ }
+ }
+ }
+ }
+ return tier
+}
diff --git a/server/armor_overequipping_test.go b/server/armor_overequipping_test.go
@@ -0,0 +1,346 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "encoding/binary"
+ "fmt"
+ "testing"
+ "time"
+)
+
+func TestArmorOverequippingDustResourcesDamageAndRestart(t *testing.T) {
+ for _, scenario := range []struct {
+ computerLiteracy uint16
+ health, damage uint32
+ }{
+ {850, 121, 80}, {650, 99, 110}, {450, 76, 140}, {250, 54, 170}, {100, 31, 200},
+ } {
+ t.Run(fmt.Sprint(scenario.computerLiteracy), func(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ player.stats.Body.Adventuring, player.stats.TradeRepair.ComputerLiteracy = 1000, 850
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if granted, err := world.grantItem_locked(player, 200461); err != nil || !granted {
+ t.Fatal("Dust Collector grant failed", err)
+ }
+ if err := world.handleInventory(client, inventoryMovePacket(1, 65, 19)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("qualified wear failed", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ npc := world.characters[1000000]
+ npc.combatProfile = &gamedata.NPCCombatProfile{Weapon: 120911}
+ profile := player.userData()
+ profile.Stats.TradeRepair.ComputerLiteracy = scenario.computerLiteracy
+
+ err := world.updateUser(profile)
+ damage := npc.normalDamage(player, func(uint32) uint32 { return 145 })
+ restarted := newTestInventoryServer(t).characters[1]
+
+ if err != nil || player.maximumHealth() != scenario.health || restarted.maximumHealth() != scenario.health || damage != scenario.damage {
+ t.Fatalf("OE resources/damage: err=%v HP=%d/%d damage=%d, want HP%d damage%d", err, player.maximumHealth(), restarted.maximumHealth(), damage, scenario.health, scenario.damage)
+ }
+ if player.maximumNano() != 119 || restarted.maximumNano() != 119 || player.effectiveSkill(136, 5, [6]uint32{0, 0, 0, 0, 100, 0}) != 20 {
+ t.Fatal("OE reduced an unaffected nano or skill bonus")
+ }
+ if len(restarted.inventory.Items) != 2 || restarted.inventory.Items[1].ID != 2 || restarted.inventory.Items[1].Slot != 19 {
+ t.Fatalf("OE changed ownership or equipment: %+v", restarted.inventory.Items)
+ }
+ })
+ }
+}
+
+func TestArmorOverequippingMetaplastTiersAndPerItemRounding(t *testing.T) {
+ for _, scenario := range []struct {
+ ability uint16
+ bodyAC, sleeveAC int32
+ }{{7, 5, 1}, {5, 4, 1}, {4, 3, 1}, {2, 2, 1}, {1, 0, 0}} {
+ for _, stat := range []string{"strength", "agility"} {
+ t.Run(fmt.Sprintf("%s/%d", stat, scenario.ability), func(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player, client := world.characters[1], world.clients[1]
+ for _, template := range []uint32{85686, 85742, 85742} {
+ if granted, err := world.grantItem_locked(player, template); err != nil || !granted {
+ t.Fatal("armor grant failed", err)
+ }
+ }
+ for index, slot := range []uint32{21, 23, 25} {
+ if err := world.handleInventory(client, inventoryMovePacket(1, uint32(65+index), slot)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("armor wear failed", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ }
+ profile := player.userData()
+ if stat == "strength" {
+ profile.Stats.Abilities.Strength = scenario.ability
+ } else {
+ profile.Stats.Abilities.Agility = scenario.ability
+ }
+
+ err := world.updateUser(profile)
+ armor := player.equipmentBonus(90)
+ profile.Stats.Abilities.Strength, profile.Stats.Abilities.Agility = 8, 8
+ recovery := world.updateUser(profile)
+ restarted := newTestInventoryServer(t).characters[1]
+
+ if err != nil || recovery != nil || armor != scenario.bodyAC+2*scenario.sleeveAC || player.equipmentBonus(90) != 7 || restarted.equipmentBonus(90) != 7 {
+ t.Fatalf("per-item armor rounding/recovery: %v %v AC=%d recovered=%d", err, recovery, armor, restarted.equipmentBonus(90))
+ }
+ if len(restarted.inventory.Items) != 4 || restarted.inventory.Items[1].Slot != 21 || restarted.inventory.Items[2].Slot != 23 || restarted.inventory.Items[3].Slot != 25 {
+ t.Fatal("OE removed or exchanged an equipped instance", restarted.inventory.Items)
+ }
+ })
+ }
+ }
+}
+
+func TestArmorOverequippingUsesInterpolatedRequirementsAtEachBoundary(t *testing.T) {
+ for _, scenario := range []struct {
+ quality uint32
+ strength uint16
+ armor int32
+ }{
+ {100, 186, 312}, {100, 185, 234}, {100, 140, 234}, {100, 139, 156},
+ {100, 93, 156}, {100, 92, 78}, {100, 47, 78}, {100, 46, 0},
+ {200, 369, 625}, {200, 368, 469}, {200, 367, 469},
+ {200, 277, 469}, {200, 276, 313}, {200, 275, 313},
+ } {
+ t.Run(fmt.Sprintf("QL%d/%d", scenario.quality, scenario.strength), func(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Abilities.Strength, player.stats.Abilities.Agility = 461, 511
+ if granted, err := world.grantItem_locked(player, 85512); err != nil || !granted {
+ t.Fatal("pants grant failed", err)
+ }
+ player.inventory.Items[1].Quality = scenario.quality
+ if err := world.handleInventory(client, inventoryMovePacket(1, 65, 27)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("pants wear failed", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ profile := player.userData()
+ profile.Stats.Abilities.Strength = scenario.strength
+
+ err := world.updateUser(profile)
+
+ if err != nil || player.equipmentBonus(90) != scenario.armor {
+ t.Fatalf("interpolated OE boundary: %v AC=%d want %d", err, player.equipmentBonus(90), scenario.armor)
+ }
+ })
+ }
+}
+
+func TestArmorOverequippingLevelRequirementAlsoReducesAddedDamage(t *testing.T) {
+ for _, scenario := range []struct {
+ level uint16
+ bonus int32
+ damage uint32
+ }{{119, 400, 63}, {96, 400, 63}, {95, 300, 48}, {71, 200, 33}, {47, 100, 18}, {23, 0, 3}} {
+ t.Run(fmt.Sprint(scenario.level), func(t *testing.T) {
+ world, _ := newRangedWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ player.level, player.stats.Body.Adventuring = 120, 1000
+ if granted, err := world.grantItem_locked(player, 158790); err != nil || !granted {
+ t.Fatal("Robust grant failed", err)
+ }
+ if err := world.handleInventory(client, inventoryMovePacket(1, 65, 19)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("Robust wear failed", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ profile := player.userData()
+ profile.Level = scenario.level
+
+ err := world.updateUser(profile)
+ damage := player.normalDamage(world.characters[1000000], func(uint32) uint32 { return 0 })
+
+ if err != nil || player.equipmentBonus(1) != scenario.bonus || damage != scenario.damage {
+ t.Fatalf("level OE did not affect HP/damage together: %v HPbonus=%d damage=%d", err, player.equipmentBonus(1), damage)
+ }
+ })
+ }
+}
+
+func TestArmorOverequippingRestorationKeepsOwnerAndObserverFoundations(t *testing.T) {
+ for _, left := range []bool{false, true} {
+ t.Run(fmt.Sprint(left), func(t *testing.T) {
+ world, connections := newResourceBackpackTeam(t)
+ player := world.characters[1]
+ player.level = 120
+ player.stats.Abilities = characterAbilitiesStats{10, 10, 10, 355, 10, 10}
+ player.stats.Body.Adventuring, player.stats.TradeRepair.ComputerLiteracy = 1000, 591
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ start := time.Unix(100, 0)
+ for _, client := range world.clients {
+ client.regenerationAt = start
+ }
+ world.advanceRegeneration(start.Add(2 * time.Second))
+ if player.maximumHealth() != 1179 {
+ t.Fatal("Dust Collector was not initially at tier 1", player.maximumHealth())
+ }
+ if left {
+ if err := world.handleTeamAction(world.clients[1], teamRequest(1, 24, 0, 0)); err != nil {
+ t.Fatal(err)
+ }
+ }
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+ stats := player.baseStats()
+ stats.Abilities.Intelligence = 356
+
+ first := world.handleSkillTraining(world.clients[1], skillTrainingRequest(stats)[20:])
+ before := player.maximumHealth()
+ stats.Abilities.Intelligence = 357
+ err := world.handleSkillTraining(world.clients[1], skillTrainingRequest(stats)[20:])
+
+ if first != nil || err != nil || before != 1179 || player.maximumHealth() != 1201 || player.stats.ImprovementPoints != 78 {
+ t.Fatal("training did not cross the native trickle boundary", first, err, before, player.maximumHealth(), player.stats.ImprovementPoints)
+ }
+ for index, want := range []uint32{1111, 1201, 1111} {
+ var found []uint32
+ for _, packet := range connections[index].packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x2b333d6e && binary.BigEndian.Uint32(packet[24:28]) == 1 && binary.BigEndian.Uint32(packet[29:33]) == 1 {
+ found = append(found, binary.BigEndian.Uint32(packet[33:37]))
+ }
+ }
+ if len(found) != 1 || found[0] != want {
+ t.Fatalf("observer %d maximum foundation=%v want%d", index+1, found, want)
+ }
+ }
+ })
+ }
+}
+
+func TestArmorOverequippingTitleRequirementIgnoresProfessionEquality(t *testing.T) {
+ for _, scenario := range []struct {
+ level uint16
+ armor int32
+ }{{100, 750}, {49, 563}, {1, 188}} {
+ t.Run(fmt.Sprint(scenario.level), func(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player, client := world.characters[1], world.clients[1]
+ player.level, player.profession, player.stats.Body.Adventuring = 100, 6, 1000
+ if granted, err := world.grantItem_locked(player, 206731); err != nil || !granted {
+ t.Fatal("Survival grant failed", err)
+ }
+ if err := world.handleInventory(client, inventoryMovePacket(1, 65, 19)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("Survival wear failed", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ profile := player.userData()
+ profile.Level, profile.Profession = scenario.level, 1
+
+ err := world.updateUser(profile)
+
+ if err != nil || player.equipmentBonus(90) != scenario.armor || player.equipmentBonus(136) != 33 {
+ t.Fatalf("title/profession OE selection: %v AC=%d Perception=%d", err, player.equipmentBonus(90), player.equipmentBonus(136))
+ }
+ })
+ }
+}
+
+func TestArmorOverequippingDoesNotUseThePreUniverseWieldRequirements(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player, client := world.characters[1], world.clients[1]
+ player.level = 150
+ player.stats.Body.Adventuring, player.stats.TradeRepair.ComputerLiteracy, player.stats.NanoAiding.TimeAndSpace = 1000, 1000, 1000
+ if granted, err := world.grantItem_locked(player, 168658); err != nil || !granted {
+ t.Fatal("Pre-Universe grant failed", err)
+ }
+ if err := world.handleInventory(client, inventoryMovePacket(1, 65, 20)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("Pre-Universe wear failed", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ profile := player.userData()
+ profile.Level = 1
+ profile.Stats.Body.Adventuring, profile.Stats.TradeRepair.ComputerLiteracy, profile.Stats.NanoAiding.TimeAndSpace = 0, 0, 0
+
+ err := world.updateUser(profile)
+ restarted := newTestInventoryServer(t).characters[1]
+
+ if err != nil || player.equipmentBonus(92) != 30 || restarted.equipmentBonus(92) != 30 || player.maximumNCU() != 13 {
+ t.Fatal("action-8-only requirements incorrectly reduced clothing bonuses", err, player.equipmentBonus(92))
+ }
+}
+
+func TestArmorOverequippingSelectsRifleAndRangeButPreservesPioneerEffects(t *testing.T) {
+ for _, template := range []uint32{157685, 156831} {
+ t.Run(fmt.Sprint(template), func(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Body.Adventuring = 1000
+ if granted, err := world.grantItem_locked(player, template); err != nil || !granted {
+ t.Fatal("backpack grant failed", err)
+ }
+ if err := world.handleInventory(client, inventoryMovePacket(1, 65, 19)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("backpack wear failed", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ profile := player.userData()
+ profile.Stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ profile.Stats.Body.Adventuring = 0
+
+ err := world.updateUser(profile)
+
+ if err != nil {
+ t.Fatal(err)
+ }
+ if template == 157685 {
+ if player.effectiveSkill(119, 5, [6]uint32{0, 60, 0, 0, 40, 0}) != 5 || player.equipmentBonus(380) != 0 {
+ t.Fatal("OE did not reduce rifle and range modifiers")
+ }
+ } else if player.effectiveAbility(16) != 2 || player.equipmentBonus(360) != -3 || player.equipmentBonus(123) != 10 || player.equipmentBonus(319) != 1 {
+ t.Fatal("OE stripped unaffected ability, skill, XP or signed scale bonuses")
+ }
+ })
+ }
+}
+
+func TestArmorOverequippingRemovalClampsVitalsAndKeepsObserverBasis(t *testing.T) {
+ world, connections := newResourceBackpackTeam(t)
+ player, client := world.characters[1], world.clients[1]
+ player.stats.TradeRepair.ComputerLiteracy = 650
+ player.health = 117
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ start := time.Unix(100, 0)
+ for _, other := range world.clients {
+ other.regenerationAt = start
+ }
+ world.advanceRegeneration(start.Add(2 * time.Second))
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+
+ err := world.handleInventory(client, itemMovePacket(1, 19, 111)[20:])
+ if client.equipment == nil {
+ t.Fatal("overequipped removal was rejected", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ restarted := newTestInventoryServer(t).characters[1]
+
+ if err != nil || player.maximumHealth() != 49 || player.health != 49 || restarted.health != 49 || restarted.inventory.Items[0].ID != 1 || restarted.inventory.Items[0].Slot != 64 {
+ t.Fatal("overequipped removal lost ownership or durable vitals", err, player.health, restarted.inventory.Items)
+ }
+ for index, want := range []uint32{49, 139, 49} {
+ var found []uint32
+ for _, packet := range connections[index].packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x2b333d6e && binary.BigEndian.Uint32(packet[24:28]) == 1 && binary.BigEndian.Uint32(packet[29:33]) == 1 {
+ found = append(found, binary.BigEndian.Uint32(packet[33:37]))
+ }
+ }
+ if len(found) != 1 || found[0] != want {
+ t.Fatalf("observer %d removal foundation=%v want%d", index+1, found, want)
+ }
+ }
+}
diff --git a/server/combat.go b/server/combat.go
@@ -125,7 +125,7 @@ func (character *character) maximumHealth() uint32 {
stats := [8][3]uint32{{2, 2, 2}, {10, 6, 3}, {15, 5, 3}, {10, 5, 2}, {25, 6, 4}, {15, 8, 6}, {2, 2, 2}, {2, 2, 2}}[character.appearance>>4&7]
base := character.baseStats()
bodyDevelopment := character.effectiveSkill(152, base.Body.BodyDevelopment, [6]uint32{0, 0, 100, 0, 0, 0})
- return stats[0] + uint32(character.level)*(stats[1]+gamedata.ProfessionTitles[max(1, character.profession)].Health[character.titleLevel()-1]) + bodyDevelopment*stats[2] + uint32(character.inventory.equipmentBonus(1))
+ return stats[0] + uint32(character.level)*(stats[1]+gamedata.ProfessionTitles[max(1, character.profession)].Health[character.titleLevel()-1]) + bodyDevelopment*stats[2] + uint32(character.equipmentBonus(1))
}
func (character *character) maximumNano() uint32 {
@@ -191,14 +191,14 @@ func (attacker *character) normalDamage(target *character, roll func(uint32) uin
// 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)
- damage -= min(damage-minimum, uint32(target.inventory.equipmentBonus(damageType))/10)
+ damage -= min(damage-minimum, uint32(target.equipmentBonus(damageType))/10)
// Add the matching damage modifier after attack rating and the AC floor.
modifier := uint32(315) // NanoDamageModifier
if damageType >= 90 && damageType <= 97 {
modifier = [8]uint32{278, 279, 280, 281, 282, 311, 317, 316}[damageType-90]
}
- return damage + uint32(attacker.inventory.equipmentBonus(modifier))
+ return damage + uint32(attacker.equipmentBonus(modifier))
}
func (character *character) physicalExtent() float32 {
@@ -232,7 +232,7 @@ func (server *server) combatInRange_locked(attacker, target *character, now time
}
// client/game/kkr.dll/lifted-0050.c::sub_360AAE10 uses a signed product
// and float32 .01, without a float32 store before truncation and the 40 cap.
- itemRange = min(40, int32(float64(itemRange*attacker.inventory.equipmentBonus(380))*float64(float32(0.01))+float64(itemRange)))
+ itemRange = min(40, int32(float64(itemRange*attacker.equipmentBonus(380))*float64(float32(0.01))+float64(itemRange)))
// FUN_10078cb0 adds the attacker's extent twice and the target's once.
distance := float32(itemRange) + 2*attacker.physicalExtent() + target.physicalExtent()
return distance >= 0 && x*x+y*y+z*z <= distance*distance
diff --git a/server/combat_equipment_modifiers_test.go b/server/combat_equipment_modifiers_test.go
@@ -22,6 +22,7 @@ func TestWeaponRangeMatchesOriginalClientRoundingAndBoundary(t *testing.T) {
t.Run(fmt.Sprintf("%d/%d", scenario.itemRange, scenario.modifier), func(t *testing.T) {
world, _ := newRangedWorld(t)
player, target := world.characters[1], world.characters[1000000]
+ player.stats.Body.Adventuring = 200
originalWeapon, originalBag := gamedata.ItemTemplates[123742], gamedata.ItemTemplates[157685]
weapon, bag := *originalWeapon, *originalBag
weapon.Stats, bag.Sections = slices.Clone(weapon.Stats), slices.Clone(bag.Sections)
@@ -69,6 +70,7 @@ func TestRobustDamageSelectsOnlyTheMatchingType(t *testing.T) {
t.Run(scenario.name, func(t *testing.T) {
world, _ := newRangedWorld(t)
player, target := world.characters[1], world.characters[1000000]
+ player.level, player.stats.Body.Adventuring = 120, 1000
original := gamedata.ItemTemplates[123742]
weapon := *original
weapon.Stats = slices.Clone(weapon.Stats)
@@ -109,6 +111,7 @@ func TestRobustDamageIsAddedAfterRatingOverequippingAndArmor(t *testing.T) {
t.Run(scenario.name, func(t *testing.T) {
world, _ := newRangedWorld(t)
player, target := world.characters[1], world.characters[1000000]
+ player.level, player.stats.Body.Adventuring = 120, 1000
player.stats.Ranged.Pistol, player.stats.Ranged.FlingShot = scenario.pistol, scenario.fling
player.inventory.Items = append(player.inventory.Items, ownedItem{ID: 3, Type: 51017, Template: 158790, Quality: 1, Slot: 19, Count: 1})
if scenario.armored {
@@ -212,6 +215,10 @@ func TestRobustFailedAmmoSaveDoesNotDealBonusDamage(t *testing.T) {
func TestRobustFailedRemovalRetainsDamageBonus(t *testing.T) {
world, conn := newRangedWorld(t)
player := world.characters[1]
+ player.level, player.stats.Body.Adventuring = 120, 1000
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
player.inventory.Items = append(player.inventory.Items, ownedItem{ID: 3, Type: 51017, Template: 158790, Quality: 1, Slot: 19, Count: 1})
player.inventory.LastID = 3
if err := world.saveInventory_locked(player, player.inventory); err != nil {
diff --git a/server/equipment.go b/server/equipment.go
@@ -103,22 +103,30 @@ func (character *character) canEquip(item ownedItem) bool {
}
func (inventory playerInventory) equipmentBonus(stat uint32) int32 {
- // Supported equipment has unconditional OnWear Modify effects, including negatives.
+ // Authored bonuses remain available for requirements and remote OnWear effects.
var bonus int32
for _, item := range inventory.Items {
- if !item.fitsEquipmentSlot(item.Slot) {
+ bonus += item.equipmentBonus(stat, 0)
+ }
+ return bonus
+}
+
+func (item ownedItem) equipmentBonus(stat, tier uint32) int32 {
+ if !item.fitsEquipmentSlot(item.Slot) {
+ return 0
+ }
+ low, high := item.templateIDs()
+ first, second := gamedata.ItemTemplates[low], gamedata.ItemTemplates[high]
+ var bonus int32
+ for sectionIndex, section := range first.Sections {
+ if section.Type != 2 || section.Subtype != 14 {
continue
}
- low, high := item.templateIDs()
- first, second := gamedata.ItemTemplates[low], gamedata.ItemTemplates[high]
- for sectionIndex, section := range first.Sections {
- if section.Type != 2 || section.Subtype != 14 {
- continue
- }
- for index, function := range *section.Functions {
- if function.ID == 53045 && uint32(*function.Arguments[0].Integer) == stat {
- bonus += interpolateItemValue(*function.Arguments[1].Integer, *(*second.Sections[sectionIndex].Functions)[index].Arguments[1].Integer, *first.Quality, *second.Quality, item.Quality)
- }
+ for index, function := range *section.Functions {
+ if function.ID == 53045 && uint32(*function.Arguments[0].Integer) == stat {
+ value := interpolateItemValue(*function.Arguments[1].Integer, *(*second.Sections[sectionIndex].Functions)[index].Arguments[1].Integer, *first.Quality, *second.Quality, item.Quality)
+ // FUN_10063130/10062f60: subtract each signed, truncated penalty.
+ bonus += value - value*int32(tier)/4
}
}
}
diff --git a/server/stats.go b/server/stats.go
@@ -155,7 +155,7 @@ func (character *character) effectiveSkill(stat uint32, base uint16, weights [6]
weighted += character.effectiveAbility(16+uint32(index)) * weight
}
// Preserve the native float constants before truncating at integer boundaries.
- return uint32(int32(base) + int32(float64(weighted)*float64(float32(0.01))*0.25) + character.inventory.equipmentBonus(stat))
+ return uint32(int32(base) + int32(float64(weighted)*float64(float32(0.01))*0.25) + character.equipmentBonus(stat))
}
type trainedStat struct {
diff --git a/server/team_resources.go b/server/team_resources.go
@@ -75,7 +75,10 @@ func (server *server) queueResourceMaximum_locked(updates map[*worldClient][][]b
continue
}
value := base
- if id != actor.id {
+ if id == actor.id && stat == 1 {
+ // The owner applies OE locally; remote actors retain authored OnWear bonuses.
+ value += uint32(actor.inventory.equipmentBonus(1) - actor.equipmentBonus(1))
+ } else if id != actor.id {
if stat == 1 {
value += uint32(client.absorbedBonuses[actor.id].health)
} else {
diff --git a/server/team_resources_test.go b/server/team_resources_test.go
@@ -177,6 +177,9 @@ func TestTeamResourcesUseEquippedMaximumsInAndOutOfCombat(t *testing.T) {
formTestTeam(t, world, 1, 2)
player := world.characters[1]
player.stats.Body.Adventuring, player.stats.TradeRepair.ComputerLiteracy = 98, 848
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
if granted, err := world.grantItem_locked(player, 200461); err != nil || !granted {
t.Fatal("resource backpack grant failed", err)
}
diff --git a/server/world.go b/server/world.go
@@ -200,7 +200,7 @@ func fullCharacterPacket(character *character) []byte {
[2]uint32{33, uint32(character.appearance >> 9 & 3)},
[2]uint32{59, uint32(character.appearance >> 7 & 3)},
// OnWear applies the direct modifiers; transmit their derived bases once.
- [2]uint32{27, character.health}, [2]uint32{1, character.maximumHealth() - uint32(character.inventory.equipmentBonus(1))},
+ [2]uint32{27, character.health}, [2]uint32{1, character.maximumHealth() - uint32(character.equipmentBonus(1))},
[2]uint32{37, character.titleLevel()}, [2]uint32{368, uint32(max(1, character.profession))},
[2]uint32{51, uint32(character.aggDef)}, [2]uint32{61, character.inventory.Credits},
[2]uint32{47, uint32(character.appearance >> 2 & 3)},