commit 2f779f4aa763f77025675289b7e7c3dfeee83e28 parent 643e743f30a6018a427b97d454c543b6b13007f5 Author: anon <anon@example.com> Date: Sun, 25 Oct 2026 03:41:50 +0000 Add provisional critical hits to shared weapon combat Diffstat:
26 files changed, 530 insertions(+), 76 deletions(-)
diff --git a/TODO.md b/TODO.md @@ -189,8 +189,11 @@ capacity checks are recorded in [belts and NCU](docs/belts-ncu.md). the expected critical damage and client feedback. Include CriticalIncrease stat 379; Sniper's Friend modifies weapon range stat 380 instead. The unchanged original activation/queue/impact path now has Linux and WASM - contract coverage. Probability, critical AC/OE arithmetic and the server - selection remain open. See [critical-result findings](docs/critical-hits.md). + contract coverage. Ordinary attacks, Fast Attack and Fling now share a + tested provisional 3% base plus worn stat379 chance and max-plus-bonus damage. + Verify the original baseline/caps, AR/evade/AggDef terms, critical AC/OE + arithmetic and nano function53012 before marking this canonical milestone + complete. See [critical-hit rules and limits](docs/critical-hits.md). - [x] Apply damage-type equipment modifiers to normal hits in the recovered order. Check: Robust Backpack's projectile, energy, radiation and fire bonuses affect the matching attacks, leave other types unchanged, and interact correctly with diff --git a/docs/catalog-weapons.md b/docs/catalog-weapons.md @@ -11,7 +11,8 @@ The existing combat calculations read damage, protection type, range, attack skill weights, initiative, attack/recharge delay and overequipping thresholds from that definition. This enables the original Baseballbat, Oak Bo, Meta Shield and five solar guns. Left-hand scheduling, dual wield, QL interpolation, -critical/hit selection and unimplemented item functions remain separate work. +original critical/hit selection and unimplemented item functions remain separate +work; [critical outcomes](critical-hits.md) now have a provisional shared path. A reversed damage range, including template 123868, is rejected until the original interpretation is established; unsigned damage arithmetic must not turn it into an enormous hit. diff --git a/docs/combat-attack-rating.md b/docs/combat-attack-rating.md @@ -58,7 +58,9 @@ 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. [Equipment damage additions](combat-equipment-modifiers.md) -follow the AC floor. Criticals and hit/miss rolls remain separate work. These +follow the AC floor. Criticals now use the shared multiplier with the +[provisional critical rules](critical-hits.md); ordinary hit/miss selection +remains separate work. These limits prevent a claim of complete canonical damage balance. ## Verification diff --git a/docs/combat-equipment-modifiers.md b/docs/combat-equipment-modifiers.md @@ -33,9 +33,10 @@ its matching addition. Currently accepted damage bonuses are nonnegative. Unsupported equipment and effect interpreters are not enabled by this mapping. The supported partial [overequipping](overequipping.md) tiers adjust weapon endpoints before attack rating; they do not scale the flat equipment addition. -Critical resolution, signed damage debuffs, reflect/absorb ordering and the -eligibility of a weapon at zero effectiveness remain separate work. No original -critical or miss probability is inferred from this change. The current arithmetic +The [critical reconstruction](critical-hits.md) also adds matching flat damage +after its AC floor; its original order still needs verification. Signed damage +debuffs, reflect/absorb ordering and eligibility at zero weapon effectiveness +remain separate work. No original miss probability is inferred from this mapping. The current arithmetic adds the flat bonus even if overequipping reduces both base endpoints to zero; the original server's attack eligibility at that tier is not established. diff --git a/docs/combat-npc-balance.md b/docs/combat-npc-balance.md @@ -67,7 +67,8 @@ and AggDef outside -100..100. | Maximum health | 100 | Provisional, retained pending a historical measurement | | Solo XP reward | 100 | Provisional; the atomic [XP path](kill-experience.md) does not establish original reward size or eligibility | | Weapon | LeetBite1_001, 120910, QL 1 | Shipped definition verified; binding and choice of variant provisional | -| Normal damage endpoints | 4-8 | Verified weapon values; uniform always-hit roll and omission of rating/armor remain local | +| Normal damage endpoints | 4-8 | Verified weapon values; uniform always-hit roll and omitted actor rating remain local | +| Critical damage before AC | 12 | Verified maximum8 plus bonus4; [critical chance and AC policy](critical-hits.md) are provisional | | Initiative | 0 | Provisional actor value | | AggDef | 75 | Provisional actor value | | Attack/recharge phases | 1.75s / 1.75s | Derived from the shipped 175 cs delays and the selected initiative/AggDef using the recovered timing formula | diff --git a/docs/combat-rules.md b/docs/combat-rules.md @@ -39,7 +39,7 @@ Its three skill requirements, 1.5-second equip delay, persistent right-hand slot and native owner/observer replication are described in [inventory and equipment](inventory.md). Combat swapping is not implemented. -The server still selects QL 1 regardless of MA skill and omits hit/critical +The server still selects QL 1 regardless of MA skill and omits hit/miss rolls. Supported Metaplast armor now reduces normal hits using the weapon's damage type and minimum floor; [armor notes](armor.md) distinguish sourced rules from provisional integer ordering. Level-1 Leets use an explicit @@ -209,8 +209,9 @@ attributes a minimum 3% critical chance, plus one percentage point per 10% that attack rating exceeds evade, to Sybex. This is a contemporary secondary claim: the original book was not inspected, the guide excludes criticals from its calculator, and no 14.9.1 experiment establishes its caps or roll ordering. -It remains a hypothesis. Subconscious Guidance 95526 authors an additive -CriticalIncrease stat 379 modifier of 8; the native default for that modifier +The current [critical reconstruction](critical-hits.md) uses its 3% baseline +provisionally, without the unverified rating/evade term. Subconscious Guidance +95526 authors an additive CriticalIncrease stat 379 modifier of 8; the native default for that modifier is 0. Neither fact establishes a hidden baseline or the total chance equation. The bounded source ledger is `local/combat-outcomes-smoke/source-ledger.json`; native outcome layouts and their limits are in the diff --git a/docs/critical-hits.md b/docs/critical-hits.md @@ -1,9 +1,9 @@ -# Critical results: verified routing and unresolved selection +# Critical hits: provisional server rules and verified native delivery -The server still emits normal weapon results. Critical probability and damage -selection remain open; result code 5 alone does not calculate critical damage. -The original client accepts an already resolved damage amount and presents it -through the weapon animation queue. +Ordinary weapon attacks, Fast Attack and Fling Shot now share critical selection +and damage. The numerical server rules below are provisional. The original +client accepts an already resolved damage amount and presents it through the +weapon animation queue; its result code 5 does not calculate critical damage. ## Original-code contract @@ -94,3 +94,92 @@ defenses. Sniper's Friend modifies range stat 380, not critical chance. The bounded follow-up found no stronger target-era numerical proof. Exact source dates, provenance and search limits are retained in `local/critical-hit-research/period-sources.md`. + + +## Current server reconstruction + +One percentage roll selects a critical when it is below +`clamp(3 + worn CriticalIncrease379, 0, 100)`. The 3% base follows the period +Sybex attribution above; treating it as an additive term, clamping, integer +percentage rolls and applying it equally to players and NPCs are provisional. +Attack rating versus evades, AggDef, level differences, critical resistance, +hit/miss ordering and original caps remain unimplemented. In particular, the +current NPC profiles do not establish their attack or defense ratings. Their +prototype trained-stat defaults must not silently become historical ratings. +All accepted attacks still land; this change does not implement ordinary misses +or add the later defensive checks to pre-15.5.5 specials. + +Critical damage uses the current weapon's authored bonus284: + +```text +minimum = base_minimum286 + critical_bonus284 +maximum = base_maximum285 + critical_bonus284 +apply the existing weapon OE adjustment to both endpoints +apply the existing player AR multiplier to both endpoints +critical_damage = maximum - min(maximum - minimum, selected_AC / 10) +add the matching flat damage modifier +cap the published damage to the target's remaining HP +``` + +There is no ordinary damage-range roll for a critical. The period example +supports the unarmored maximum-plus-bonus multiplier. The critical minimum, +OE ordering, integer truncation and modifier ordering above are explicit local +policies pending independent original-server evidence. NPCs retain their +unscaled catalog endpoints; QL1 player fists use their authored bonus3. +Prototype NPCs without a catalog weapon keep their flat damage5 and have no +invented critical bonus. Zero-effectiveness attack eligibility is still open. + +Worn stat379 uses the existing signed equipment contribution and armor OE +calculation. The QL1 Agent Kevlar Wool Balaclava Helmet160568 adds one point; +unequipping it removes that contribution, and both states survive reopening +SQLite with the same item instance. Unsupported gear is still unsupported. +Critical nanos, including Subconscious Guidance's distinct function53012 and +special metadata, remain disabled until their complete contracts are supported; +this change does not admit only their visible critical modifier. + +Ordinary AttackInfo carries result5 for a critical, including killing hits. +The special-result body has no critical flag: Fast Attack and Fling publish the +resolved critical damage in the existing named-special message. Normal attacks +consume their usual single round; these pre-15.5.5 specials leave ammo unchanged. +Damage, ammunition where applicable, contribution, corpse, XP and special lock +continue through their existing atomic transactions before feedback. + +## Server verification + +`server/critical_hit_test.go` exercises controlled percentage boundaries, +signed negative and excessive equipment contributions, exact draw bounds, +normal versus critical feedback, player AR through1200, critical AC floors, +partial OE, flat damage additions, fists, catalog Leet Bite and prototype NPCs. +Tests use native combat, special and equipment requests. They also check +matching observer results, capped killing damage, single ammo/XP changes, +cold recovery, repeated requests and transaction failures. Armor tests cover +all nine protection types and invalid-type fallback for critical damage. +The process-crash special tests force critical living and killing outcomes +on both sides of SQLite commit, then reopen and retry through a new session. + +These checks validate the documented reconstruction, not the unresolved +original probability formula or canonical creature balance. + +## Live server-selected WASM outcomes + +Two headed Chromium clients on the GPU tested the shared HTTPS preview with +unmodified incoming packets and ordinary native inventory/combat controls. +The QL1 Agent helmet was equipped as instance83; both clients exposed its +CriticalIncrease379 contribution of1. The player then fought the existing +level1 Leet using QL1 fists and received ordinary and critical results. + +The server selected one8-damage player critical and one12-damage Leet critical. +Both clients received identical N3 bodies for each outcome, queued result5 +with the supplied amount and displayed the corresponding `Critical hit!` text. +Read-only native heap samples captured an8-point NPC HP subtraction and a +12-point player HP subtraction in each client. Regeneration continued during +queued animation delivery, so earlier queue samples can include intervening +healing; they are not independent damage formulas. These live observations +verify presentation and the supplied amounts, not an original-server chance. + +The sole preview was stopped and reopened against the same SQLite database. +Both clients restored the same helmet instance and its single +1 contribution. +Native removal returned that instance to inventory and removed the contribution +on both clients; the database immediately retained the new slot. No client +exception or unimplemented adapter was observed. Artifacts, packet/heap checks, +GPU identity and cleanup evidence are retained in `local/critical-combat-smoke/`. diff --git a/docs/fast-attack.md b/docs/fast-attack.md @@ -2,8 +2,8 @@ The QL1 Kinetic Axe209283 supports native Fast Attack147 through the shared weapon-special handler. It publishes named damage feedback and an independent, -persistent skill lock. This is a prototype of the normal-damage branch; -critical selection and the historical rules below remain open. +persistent skill lock. This prototype supports ordinary and critical damage; +the original critical-selection formula and historical rules below remain open. ## Original content and native path @@ -71,11 +71,11 @@ the request without damage or success feedback. Several action gates remain reconstruction policy pending period verification. Line of sight remains the existing combat TODO; dual wield and its source selection are not implemented. -Fast Attack currently reuses normal weapon damage, including weapon attack -rating, AC, overequipping and damage additions. The precise special distribution, -critical selection and arithmetic ordering are not established. The action -preserves existing normal-attack/recharge and nano-cast clocks. It triggers NPC -retaliation and contribution/corpse/respawn handling, without starting the owner's +Fast Attack reuses ordinary or critical weapon damage, including weapon attack +rating, AC, overequipping and damage additions. The precise special distribution +remains open; the shared [critical selection and arithmetic](critical-hits.md) +are provisional. The action preserves existing normal-attack/recharge and +nano-cast clocks. It triggers NPC retaliation and contribution/corpse/respawn handling, without starting the owner's normal attack. Historical start/animation/interruption rules remain open. Damage and its skill lock use the existing atomic SQLite outcome transaction diff --git a/docs/fling-shot.md b/docs/fling-shot.md @@ -2,8 +2,8 @@ Catalog main-hand weapons with Can bit 12 support the native Fling Shot request, named damage feedback and a persistent shared skill lock. This is a -prototype of the normal-damage branch. The ranged-special milestone stays open: -critical outcomes and several historical rules below are not yet established. +prototype with ordinary and critical damage. The ranged-special milestone stays +open: critical selection and several historical rules below remain provisional. ## Target-era evidence @@ -82,10 +82,10 @@ active reload/equip, sitting, vehicles and an existing lock. Some of those actio gates are reconstruction policy pending period verification. Server line of sight remains the existing combat TODO. -Accepted shots currently reuse `normalDamage`, including attack rating, AC, -overequipping and damage modifiers. Fling-specific damage distribution and -critical selection are not established; the prototype emits normal damage -only. It does not reset an existing normal attack/recharge or nano cast. +Accepted shots reuse the shared weapon-hit calculation, including ordinary or +critical damage, attack rating, AC, overequipping and damage modifiers. The +[critical chance and damage policies](critical-hits.md) are provisional. +Fling-specific damage distribution and original critical selection remain open. It does not reset an existing normal attack/recharge or nano cast. It triggers normal NPC retaliation and the existing contribution, corpse and respawn lifecycle. Starting the player's normal attack automatically and special firing animation/request forwarding remain unverified. @@ -108,8 +108,8 @@ forced process termination immediately around commit is covered below. ## Verification `server/fling_crash_test.go` starts real child processes with disposable SQLite -databases for both Fling and Fast Attack. For both a living and a killing hit, -the parent sends a forced kill +databases for both Fling and Fast Attack. For controlled critical hits against +surviving and killed targets, the parent sends a forced kill at either SQLite's commit hook or the first native special-result write. The commit-hook stop occurs after the transaction's writes and before commit; the output stop occurs after commit and before any result bytes are published. diff --git a/server/armor_damage_test.go b/server/armor_damage_test.go @@ -50,16 +50,23 @@ func TestArmorDamageUsesTheAttacksProtectionType(t *testing.T) { npc := world.characters[1000000] npc.combatProfile = &gamedata.NPCCombatProfile{Weapon: 120911} - damage := npc.normalDamage(world.characters[1], func(limit uint32) uint32 { + damage := npc.weaponDamage(world.characters[1], false, func(limit uint32) uint32 { if limit != 352 { t.Fatalf("unexpected QL 400 Leet Bite roll bound: %d", limit) } return 145 }) + critical := npc.weaponDamage(world.characters[1], true, func(uint32) uint32 { + t.Fatal("critical damage used the ordinary range roll") + return 0 + }) if damage != attack.damage { t.Fatalf("damage type %d: got %d want %d", attack.kind, damage, attack.damage) } + if critical != attack.damage+300 { + t.Fatalf("critical protection type %d: got %d want %d", attack.kind, critical, attack.damage+300) + } }) } } @@ -71,7 +78,7 @@ func TestArmorDamageCannotCrossWeaponMinimum(t *testing.T) { var hits []uint32 for _, roll := range []uint32{0, 1, 2, 3, 4} { - hits = append(hits, npc.normalDamage(world.characters[1], func(limit uint32) uint32 { + hits = append(hits, npc.weaponDamage(world.characters[1], false, func(limit uint32) uint32 { if limit != 5 { t.Fatalf("unexpected QL 1 Leet Bite roll bound: %d", limit) } diff --git a/server/armor_overequipping_test.go b/server/armor_overequipping_test.go @@ -37,7 +37,7 @@ func TestArmorOverequippingDustResourcesDamageAndRestart(t *testing.T) { profile.Stats.TradeRepair.ComputerLiteracy = scenario.computerLiteracy err := world.updateUser(profile) - damage := npc.normalDamage(player, func(uint32) uint32 { return 145 }) + damage := npc.weaponDamage(player, false, func(uint32) uint32 { return 145 }) restarted := newTestInventoryServer(t).characters[1] if err != nil || player.maximumHealth() != scenario.health || restarted.maximumHealth() != scenario.health || damage != scenario.damage { @@ -155,7 +155,7 @@ func TestArmorOverequippingLevelRequirementAlsoReducesAddedDamage(t *testing.T) profile.Level = scenario.level err := world.updateUser(profile) - damage := player.normalDamage(world.characters[1000000], func(uint32) uint32 { return 0 }) + damage := player.weaponDamage(world.characters[1000000], false, 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) diff --git a/server/attack_rating_test.go b/server/attack_rating_test.go @@ -26,8 +26,8 @@ func TestAttackRatingAxeDamageEndpoints(t *testing.T) { 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 }) + minimum := player.weaponDamage(world.characters[1000000], false, func(uint32) uint32 { return 0 }) + maximum := player.weaponDamage(world.characters[1000000], false, 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) @@ -48,12 +48,12 @@ func TestAttackRatingUnequipAndRestartSelectTheCurrentSkill(t *testing.T) { 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) + axe := player.weaponDamage(target, false, maximum) + restarted := newTestInventoryServer(t).characters[1].weaponDamage(target, false, 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) + fists := player.weaponDamage(target, false, maximum) + unarmedRestart := newTestInventoryServer(t).characters[1].weaponDamage(target, false, 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) @@ -72,8 +72,8 @@ func TestAttackRatingFistEndpointsIncludeZeroSkill(t *testing.T) { attacker.stats.Body.MartialArts, attacker.stats.Melee.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 }) + minimum := attacker.weaponDamage(target, false, func(uint32) uint32 { return 0 }) + maximum := attacker.weaponDamage(target, false, 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) @@ -90,7 +90,7 @@ func TestAttackRatingScaledMinimumPrecedesArmor(t *testing.T) { var hits []uint32 for _, roll := range []uint32{0, 15, 30} { - hits = append(hits, attacker.normalDamage(world.characters[1], func(limit uint32) uint32 { + hits = append(hits, attacker.weaponDamage(world.characters[1], false, func(limit uint32) uint32 { if limit != 31 { t.Fatalf("AR 400 axe range: got %d want 31", limit) } diff --git a/server/briefcase_weapon_test.go b/server/briefcase_weapon_test.go @@ -109,8 +109,8 @@ func TestBriefcaseWeaponDamageUsesAuthoredSkillAndEveryOERequirement(t *testing. player.stats.TradeRepair.Psychology, player.level = scenario.psychology, scenario.level player.stats.Melee.OneHandEdged, player.stats.Ranged.Pistol = 5000, 5000 - minimum := player.normalDamage(world.characters[1000000], func(uint32) uint32 { return 0 }) - maximum := player.normalDamage(world.characters[1000000], func(limit uint32) uint32 { return limit - 1 }) + minimum := player.weaponDamage(world.characters[1000000], false, func(uint32) uint32 { return 0 }) + maximum := player.weaponDamage(world.characters[1000000], false, func(limit uint32) uint32 { return limit - 1 }) if minimum != scenario.minimum || maximum != scenario.maximum || player.attackRating() != int32(scenario.psychology) { t.Fatalf("Psychology %d level %d: got %d..%d AR%d, want %d..%d", scenario.psychology, scenario.level, minimum, maximum, player.attackRating(), scenario.minimum, scenario.maximum) diff --git a/server/combat.go b/server/combat.go @@ -173,12 +173,24 @@ func (character *character) attackRating() int32 { return rating } -func (attacker *character) normalDamage(target *character, roll func(uint32) uint32) uint32 { +func (server *server) weaponHit_locked(attacker, target *character) (uint32, bool) { + roll := server.combatRoll + if roll == nil { + roll = rand.Uint32N + } + // The period 3% baseline is provisional; NPC ratings are not established. + chance := min(100, max(0, int64(3)+int64(attacker.equipmentBonus(379)))) + critical := int64(roll(100)) < chance + return min(attacker.weaponDamage(target, critical, roll), target.health), critical +} + +func (attacker *character) weaponDamage(target *character, critical bool, roll func(uint32) uint32) uint32 { // Exact catalog endpoints and the weapon's native protection type. - minimum, maximum, damageType := uint32(3), uint32(5), uint32(91) + minimum, maximum, bonus, damageType := uint32(3), uint32(5), uint32(3), uint32(91) weapon := attacker.attackWeapon() if weapon != nil { minimum, maximum = itemStat(weapon, 286), itemStat(weapon, 285) + bonus = itemStat(weapon, 284) // kkr.dll 100abb20 seeds omitted DamageType436 with MeleeAC91. for _, stat := range weapon.Stats { if stat[0] == 436 { @@ -191,6 +203,12 @@ func (attacker *character) normalDamage(target *character, roll func(uint32) uin } } else if attacker.npc { minimum, maximum = 5, 5 + bonus = 0 // Prototype NPCs without a catalog weapon have no critical bonus. + } + if critical { + // The critical AC floor and OE ordering are provisional; see critical-hits.md. + minimum += bonus + maximum += bonus } // Player fists use MA; equipped weapons use their authored attack skills. @@ -208,7 +226,10 @@ 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 := maximum + if !critical { + damage = minimum + roll(maximum-minimum+1) + } damage -= min(damage-minimum, uint32(target.equipmentBonus(damageType))/10) // Add the matching damage modifier after attack rating and the AC floor. @@ -352,7 +373,7 @@ func (server *server) advanceCombat(now time.Time) { if now.Before(attacker.nextAttack) { continue } - damage := min(attacker.normalDamage(target, rand.Uint32N), target.health) + damage, critical := server.weaponHit_locked(attacker, target) previous := *target fired, award, err := server.applyWeaponDamage_locked(attacker, target, damage, now) if err != nil { @@ -367,7 +388,7 @@ func (server *server) advanceCombat(now time.Time) { attack, recharge := attacker.attackDelays() attacker.rechargeUntil = now.Add(recharge) attacker.nextAttack = attacker.rechargeUntil.Add(attack) - server.queueCombat_locked(updates, attacker, target, hitPacket(attacker, target, damage)) + server.queueCombat_locked(updates, attacker, target, hitPacket(attacker, target, damage, critical)) server.finishDamageEffects_locked(attacker, target, previous, now, updates) server.applyExperienceAward_locked(award, now, updates) } @@ -517,7 +538,7 @@ func (server *server) sendCombatUpdates(updates map[*worldClient][][]byte) { } } -func hitPacket(attacker, target *character, damage uint32) []byte { +func hitPacket(attacker, target *character, damage uint32, critical bool) []byte { // kkr.dll 0x100aec00: damage, ammo, slot, target identity, death reason and result. body := binary.BigEndian.AppendUint32(nil, damage) slot := uint32(0) @@ -530,7 +551,11 @@ func hitPacket(attacker, target *character, damage uint32) []byte { ammo = item.Ammo } } - for _, value := range []uint32{ammo, slot, 50000, target.id, 0, 4} { + result := uint32(4) + if critical { + result = 5 + } + for _, value := range []uint32{ammo, slot, 50000, target.id, 0, result} { body = binary.BigEndian.AppendUint32(body, value) } if target.health == 0 { diff --git a/server/combat_equipment_modifiers_test.go b/server/combat_equipment_modifiers_test.go @@ -83,10 +83,10 @@ func TestRobustDamageSelectsOnlyTheMatchingType(t *testing.T) { t.Cleanup(func() { gamedata.ItemTemplates[123742] = original }) player.inventory.Items = append(player.inventory.Items, ownedItem{ID: 3, Type: 51017, Template: 158790, Quality: 1, Slot: 19, Count: 1}) - minimum := player.normalDamage(target, func(limit uint32) uint32 { return 0 }) - maximum := player.normalDamage(target, func(limit uint32) uint32 { return limit - 1 }) + minimum := player.weaponDamage(target, false, func(limit uint32) uint32 { return 0 }) + maximum := player.weaponDamage(target, false, func(limit uint32) uint32 { return limit - 1 }) player.inventory.Items[2].Slot = 65 - removed := player.normalDamage(target, func(limit uint32) uint32 { return limit - 1 }) + removed := player.weaponDamage(target, false, func(limit uint32) uint32 { return limit - 1 }) if minimum != scenario.minimum || maximum != scenario.maximum || removed != 12 { t.Fatalf("matching added damage: minimum %d maximum %d removed %d", minimum, maximum, removed) @@ -118,8 +118,8 @@ func TestRobustDamageIsAddedAfterRatingOverequippingAndArmor(t *testing.T) { target.inventory.Items = []ownedItem{{ID: 4, Type: 51022, Template: 85685, Quality: 200, Slot: 21, Count: 1}} } - minimum := player.normalDamage(target, func(limit uint32) uint32 { return 0 }) - maximum := player.normalDamage(target, func(limit uint32) uint32 { return limit - 1 }) + minimum := player.weaponDamage(target, false, func(limit uint32) uint32 { return 0 }) + maximum := player.weaponDamage(target, false, func(limit uint32) uint32 { return limit - 1 }) if minimum != scenario.minimum || maximum != scenario.maximum { t.Fatalf("modifier was scaled or reduced by armor: %d..%d", minimum, maximum) @@ -232,7 +232,7 @@ func TestRobustFailedRemovalRetainsDamageBonus(t *testing.T) { } world.advanceEquipment(world.clients[1].equipment.readyAt) restarted := newTestInventoryServer(t).characters[1] - damage := player.normalDamage(world.characters[1000000], func(limit uint32) uint32 { return 0 }) + damage := player.weaponDamage(world.characters[1000000], false, func(limit uint32) uint32 { return 0 }) if damage != 63 || player.inventory.Items[2].Slot != 19 || restarted.inventory.Items[2].Slot != 19 || restarted.inventory.equipmentBonus(278) != 60 || len(restarted.inventory.Items) != 3 { t.Fatal("failed removal lost the item or damage bonus", damage, restarted.inventory) diff --git a/server/combat_test.go b/server/combat_test.go @@ -31,7 +31,8 @@ func newCombatWorld() (*server, *combatTestConn) { clients: map[uint32]*worldClient{ 1: {id: 1, conn: conn, target: true, ready: true, npcs: map[uint32]bool{1000000: true}}, }, - fighting: make(map[uint32]*character), + fighting: make(map[uint32]*character), + combatRoll: func(limit uint32) uint32 { return limit - 1 }, }, conn } diff --git a/server/critical_hit_test.go b/server/critical_hit_test.go @@ -0,0 +1,314 @@ +package main + +import ( + "ao/server/gamedata" + "bytes" + "encoding/binary" + "fmt" + "slices" + "testing" + "time" +) + +func TestCriticalDamageRatingArmorOverequippingAndAddedDamage(t *testing.T) { + for _, scenario := range []struct { + name string + skill uint16 + armored bool + fling uint16 + backpack bool + want uint32 + }{ + {"base pistol", 5, false, 5, false, 24}, + {"AR 400", 398, false, 5, false, 48}, + {"AR 800", 798, false, 5, false, 72}, + {"AR 1200", 1198, false, 5, false, 96}, + {"critical AC floor", 398, true, 5, false, 30}, + {"critical AC floor AR 800", 798, true, 5, false, 45}, + {"75 percent OE", 5, false, 2, false, 18}, + {"50 percent OE", 5, false, 1, false, 12}, + {"damage addition after scaling", 398, false, 5, true, 108}, + {"damage addition after armor", 398, true, 5, true, 90}, + {"damage addition after OE", 5, false, 1, true, 72}, + } { + t.Run(scenario.name, func(t *testing.T) { + world, _ := newRangedWorld(t) + player, target := world.characters[1], world.characters[1000000] + player.stats.Ranged.Pistol, player.stats.Ranged.FlingShot = scenario.skill, scenario.fling + player.level, player.stats.Body.Adventuring = 120, 1000 + if scenario.armored { + target.inventory.Items = []ownedItem{{ID: 4, Type: 51022, Template: 85685, Quality: 200, Slot: 21, Count: 1}} + } + if scenario.backpack { + player.inventory.Items = append(player.inventory.Items, ownedItem{ID: 3, Type: 51017, Template: 158790, Quality: 1, Slot: 19, Count: 1}) + } + world.combatRoll = func(limit uint32) uint32 { + if limit != 100 { + t.Fatal("a critical must not roll the ordinary damage range", limit) + } + return 0 + } + + if err := world.handleCombat(world.clients[1], attackPacket(1, target.id)[20:]); err != nil { + t.Fatal(err) + } + world.advanceCombat(player.nextAttack) + + if target.health != 1000-scenario.want || player.inventory.Items[0].Ammo != 2 { + t.Fatalf("critical damage: got %d want %d", 1000-target.health, scenario.want) + } + }) + } +} + +func TestCriticalChanceBoundariesUseSignedWornModifiers(t *testing.T) { + for _, scenario := range []struct { + bonus int32 + roll uint32 + critical bool + }{ + {-100, 0, false}, {-3, 0, false}, {-2, 0, true}, {-2, 1, false}, + {0, 0, true}, {0, 2, true}, {0, 3, false}, {0, 99, false}, + {8, 10, true}, {8, 11, false}, {97, 99, true}, {2147483647, 99, true}, + } { + t.Run(fmt.Sprintf("%d/%d", scenario.bonus, scenario.roll), func(t *testing.T) { + world, conn := newRangedWorld(t) + player, target := world.characters[1], world.characters[1000000] + original := gamedata.ItemTemplates[158790] + backpack := *original + backpack.Sections = slices.Clone(original.Sections) + stat := int32(379) + functions := []gamedata.ItemFunction{{ID: 53045, Arguments: []gamedata.ItemArgument{{Integer: &stat}, {Integer: &scenario.bonus}}}} + for index, section := range backpack.Sections { + if section.Type == 2 && section.Subtype == 14 { + backpack.Sections[index].Functions = &functions + } + } + gamedata.ItemTemplates[158790] = &backpack + t.Cleanup(func() { gamedata.ItemTemplates[158790] = original }) + player.level, player.stats.Body.Adventuring = 120, 1000 + player.inventory.Items = append(player.inventory.Items, ownedItem{ID: 3, Type: 51017, Template: 158790, Quality: 1, Slot: 19, Count: 1}) + var bounds []uint32 + world.combatRoll = func(limit uint32) uint32 { + bounds = append(bounds, limit) + if len(bounds) == 1 { + return scenario.roll + } + return limit - 1 + } + + world.handleCombat(world.clients[1], attackPacket(1, target.id)[20:]) + now := player.nextAttack + world.advanceCombat(now) + world.advanceCombat(now) + + wantDamage, wantResult := uint32(12), uint32(4) + wantBounds := []uint32{100, 10} + if scenario.critical { + wantDamage, wantResult, wantBounds = 24, 5, []uint32{100} + } + if !slices.Equal(bounds, wantBounds) || target.health != 1000-wantDamage || player.inventory.Items[0].Ammo != 2 || + binary.BigEndian.Uint32(conn.packets[1][29:33]) != wantDamage || binary.BigEndian.Uint32(conn.packets[1][53:57]) != wantResult { + t.Fatal("chance threshold, draw count or native result mismatch", bounds, target.health, conn.packets) + } + }) + } +} + +func TestCriticalFistsAndNPCWeaponUseTheirOwnCatalogBonus(t *testing.T) { + for _, scenario := range []struct { + name string + npc, weapon bool + want uint32 + }{ + {"player fists", false, false, 8}, {"Leet Bite", true, true, 12}, {"prototype NPC", true, false, 5}, + } { + t.Run(scenario.name, func(t *testing.T) { + world, conn := newCombatWorld() + attacker, target := world.characters[1], world.characters[1000000] + if scenario.npc { + attacker, target = target, attacker + if scenario.weapon { + attacker.combatProfile = gamedata.NPCCombatProfiles[17655][1] + } + } + world.combatRoll = func(uint32) uint32 { return 0 } + attacker.fighting, attacker.nextAttack = target.id, time.Now() + world.fighting[attacker.id] = attacker + + world.advanceCombat(attacker.nextAttack) + + if target.health != 100-scenario.want || binary.BigEndian.Uint32(conn.packets[0][29:33]) != scenario.want || + binary.BigEndian.Uint32(conn.packets[0][53:57]) != 5 { + t.Fatal("critical selected another weapon's bonus", target.health, conn.packets) + } + }) + } +} + +func TestCriticalWeaponSpecialsPersistDamageLockAndUnchangedAmmunition(t *testing.T) { + for _, skill := range []uint32{147, 150} { + for _, killing := range []bool{false, true} { + t.Run(fmt.Sprintf("%d/kill=%t", skill, killing), func(t *testing.T) { + var world *server + var owner *combatTestConn + request, want := flingShotRequest(1, 1000000), uint32(24) + if skill == 147 { + world, owner = newFastAttackWorld(t) + request, want = fastAttackRequest(1, 1000000), 25 + } else { + world, owner = newRangedWorld(t) + } + player, target := world.characters[1], world.characters[1000000] + target.monsterData, target.level = 17655, 1 + target.combatProfile = gamedata.NPCCombatProfiles[17655][1] + if killing { + target.health, want = 7, 7 + } + initial := target.health + world.combatRoll = func(uint32) uint32 { return 0 } + 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}} + + if err := world.handleWeaponSpecial(world.clients[1], request[20:]); err != nil { + t.Fatal(err) + } + world.handleWeaponSpecial(world.clients[1], request[20:]) + cold := newTestInventoryServer(t) + + if target.health != initial-want || cold.characters[target.id].health != target.health || + !cold.characters[1].skillLocks[skill].Equal(player.skillLocks[skill]) || + !bytes.Equal(owner.packets[0][16:], observer.packets[0][16:]) || + binary.BigEndian.Uint32(owner.packets[0][29:33]) != 6 || binary.BigEndian.Uint32(owner.packets[0][33:37]) != want { + t.Fatal("critical special did not commit one matching outcome for both observers", target.health, owner.packets) + } + if skill == 150 && (player.inventory.Items[0].Ammo != 3 || cold.characters[1].inventory.Items[0].Ammo != 3) { + t.Fatal("critical Fling consumed pre-15.5.5 ammunition") + } + if killing && (cold.characters[target.id].corpse == nil || binary.BigEndian.Uint32(owner.packets[0][53:57]) != 4) { + t.Fatal("critical special lost death routing") + } + }) + } + } +} + +func TestCriticalFailedTransactionsPublishNoDamageResult(t *testing.T) { + for _, skill := range []uint32{0, 147, 150} { + t.Run(fmt.Sprint(skill), func(t *testing.T) { + var world *server + var conn *combatTestConn + if skill == 147 { + world, conn = newFastAttackWorld(t) + } else { + world, conn = newRangedWorld(t) + } + world.combatRoll = func(uint32) uint32 { return 0 } + target := world.characters[1000000] + if _, err := world.saveDeath_locked(target, time.Now()); err != nil { + t.Fatal(err) + } + statement := "CREATE TRIGGER fail_critical BEFORE INSERT ON skill_locks BEGIN SELECT RAISE(FAIL, 'critical lock failure'); END" + if skill == 0 { + statement = "CREATE TRIGGER fail_critical BEFORE UPDATE OF ammo ON items BEGIN SELECT RAISE(FAIL, 'critical ammo failure'); END" + world.handleCombat(world.clients[1], attackPacket(1, target.id)[20:]) + } + if _, err := world.db.Exec(statement); err != nil { + t.Fatal(err) + } + conn.packets = nil + + if skill == 0 { + world.advanceCombat(world.characters[1].nextAttack) + } else { + request := flingShotRequest(1, target.id) + if skill == 147 { + request = fastAttackRequest(1, target.id) + } + if err := world.handleWeaponSpecial(world.clients[1], request[20:]); err == nil { + t.Fatal("failed critical transaction was accepted") + } + } + cold := newTestInventoryServer(t) + + if target.health != 1000 || cold.characters[target.id].health != 1000 || + len(world.characters[1].skillLocks) != 0 || len(cold.characters[1].skillLocks) != 0 || + len(target.damageContributors) != 0 || len(cold.characters[target.id].damageContributors) != 0 { + t.Fatal("failed critical mutated live or durable damage state") + } + for _, packet := range conn.packets { + key := binary.BigEndian.Uint32(packet[16:20]) + if key == 0x46002f16 || key == 0x754f1115 { + t.Fatal("failed critical published a damage result") + } + } + if skill != 147 && (world.characters[1].inventory.Items[0].Ammo != 3 || cold.characters[1].inventory.Items[0].Ammo != 3) { + t.Fatal("failed critical consumed ammunition") + } + }) + } +} + +func TestCriticalOriginalHelmetWearRemovalAndColdRecovery(t *testing.T) { + world, _ := newRangedWorld(t) + player, client := world.characters[1], world.clients[1] + player.profession = 5 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, 160568); err != nil || !granted { + t.Fatal(granted, err) + } + + if err := world.handleInventory(client, inventoryMovePacket(1, 65, 18)[20:]); err != nil { + t.Fatal(err) + } + if client.equipment == nil { + t.Fatal("original Agent helmet was rejected") + } + world.advanceEquipment(client.equipment.readyAt) + worn := player.equipmentBonus(379) + cold := newTestInventoryServer(t).characters[1] + if err := world.handleInventory(client, itemMovePacket(1, 18, 111)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + removed := newTestInventoryServer(t).characters[1] + + if worn != 1 || cold.equipmentBonus(379) != 1 || removed.equipmentBonus(379) != 0 || player.equipmentBonus(379) != 0 || + player.inventory.Items[2].ID != cold.inventory.Items[2].ID || removed.inventory.Items[2].ID != cold.inventory.Items[2].ID || + cold.inventory.Items[2].Slot != 18 || removed.inventory.Items[2].Slot != 65 { + t.Fatal("critical modifier did not follow the same original item across wear, removal and restart") + } +} + +func TestCriticalKillingShotCommitsAmmoCorpseAndExperienceTogether(t *testing.T) { + world, owner := newRangedWorld(t) + player, target := world.characters[1], world.characters[1000000] + player.experience = 1400 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + target.health, target.monsterData, target.level = 7, 17655, 1 + target.combatProfile = gamedata.NPCCombatProfiles[17655][1] + 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}} + world.combatRoll = func(uint32) uint32 { return 0 } + + world.handleCombat(world.clients[1], attackPacket(1, target.id)[20:]) + now := player.nextAttack + world.advanceCombat(now) + world.advanceCombat(now.Add(time.Minute)) + cold := newTestInventoryServer(t) + + if target.health != 0 || cold.characters[target.id].health != 0 || cold.characters[target.id].corpse.looter != 1 || + player.inventory.Items[0].Ammo != 2 || cold.characters[1].inventory.Items[0].Ammo != 2 || + player.level != 2 || player.experience != 50 || cold.characters[1].level != 2 || cold.characters[1].experience != 50 || + !bytes.Equal(owner.packets[1][16:], observer.packets[1][16:]) || + binary.BigEndian.Uint32(owner.packets[1][29:33]) != 7 || binary.BigEndian.Uint32(owner.packets[1][49:53]) != 4 || + binary.BigEndian.Uint32(owner.packets[1][53:57]) != 5 { + t.Fatal("critical overkill separated damage, death, ammunition or the single XP award", target.health, owner.packets) + } +} diff --git a/server/fling_crash_test.go b/server/fling_crash_test.go @@ -43,6 +43,7 @@ func runFlingCrashChild(t *testing.T, mode string) { } else { world, output = newRangedWorld(t) } + world.combatRoll = func(uint32) uint32 { return 0 } world.characters[1].experience = 1400 if err := world.saveUser_locked(world.characters[1]); err != nil { t.Fatal(err) @@ -192,6 +193,13 @@ func TestFlingShotProcessCrashRecovery(t *testing.T) { t.Fatalf("first post-commit output was not the native special result: %x", checkpoint.Packet) } damage := binary.BigEndian.Uint32(checkpoint.Packet[33:37]) + expected := uint32(24) + if skill == 147 { + expected = 25 + } + if damage != min(expected, initialHealth) { + t.Fatal("crash fixture did not resolve the controlled critical", damage) + } if damage == 0 || damage > initialHealth || target.health != initialHealth-damage || !player.skillLocks[skill].After(time.Now()) || binary.BigEndian.Uint32(checkpoint.Packet[49:53]) != skill || initialHealth != 1 && target.damageContributors[damageContributor{player: 1}] != damage { diff --git a/server/inventory_test.go b/server/inventory_test.go @@ -165,7 +165,7 @@ func TestInventoryNativeMoveDeleteAndRestart(t *testing.T) { func newTestInventoryServer(t *testing.T) *server { t.Helper() - world := &server{characters: make(map[uint32]*character), clients: make(map[uint32]*worldClient), fighting: make(map[uint32]*character), roamingNPCs: make(map[uint32][]*character)} + world := &server{characters: make(map[uint32]*character), clients: make(map[uint32]*worldClient), fighting: make(map[uint32]*character), roamingNPCs: make(map[uint32][]*character), combatRoll: func(limit uint32) uint32 { return limit - 1 }} if _, err := world.loadNPCs(); err != nil { t.Fatal(err) } diff --git a/server/npcs_test.go b/server/npcs_test.go @@ -37,6 +37,7 @@ func newTestServer(t *testing.T) *server { t.Helper() t.Chdir(t.TempDir()) world := newServer() + world.combatRoll = func(limit uint32) uint32 { return limit - 1 } t.Cleanup(func() { world.db.Close() }) return world } diff --git a/server/overequipping_test.go b/server/overequipping_test.go @@ -33,8 +33,8 @@ func TestOverequippingAxeChecksEveryRequiredSkill(t *testing.T) { player.stats.Abilities.Sense = 1 player.stats.Melee.OneHandEdged, player.stats.Body.Brawling, player.stats.Melee.FastAttack = scenario.oneHandEdged, scenario.brawling, scenario.fastAttack - minimum := player.normalDamage(world.characters[1000000], func(uint32) uint32 { return 0 }) - maximum := player.normalDamage(world.characters[1000000], func(limit uint32) uint32 { return limit - 1 }) + minimum := player.weaponDamage(world.characters[1000000], false, func(uint32) uint32 { return 0 }) + maximum := player.weaponDamage(world.characters[1000000], false, func(limit uint32) uint32 { return limit - 1 }) if minimum != scenario.minimum || maximum != scenario.maximum || player.inventory.Items[0].Slot != 6 { t.Fatalf("equipped axe damage: got %d..%d want %d..%d, items %+v", minimum, maximum, scenario.minimum, scenario.maximum, player.inventory.Items) @@ -56,17 +56,17 @@ func TestOverequippingIncludesTrickleAndRecoversAfterRestart(t *testing.T) { target := world.characters[1000000] maximum := func(limit uint32) uint32 { return limit - 1 } - reduced := player.normalDamage(target, maximum) + reduced := player.weaponDamage(target, false, maximum) restarted := newTestInventoryServer(t).characters[1] - persisted := restarted.normalDamage(target, maximum) + persisted := restarted.weaponDamage(target, false, maximum) restarted.stats.Body.Brawling = 2 // Effective 4 removes the penalty without re-equipping. - restored := restarted.normalDamage(target, maximum) + restored := restarted.weaponDamage(target, false, maximum) if err := world.saveUser_locked(restarted); err != nil { t.Fatal(err) } secondRestart := newTestInventoryServer(t).characters[1] - if reduced != 30 || persisted != 30 || restored != 40 || secondRestart.normalDamage(target, maximum) != 40 || + if reduced != 30 || persisted != 30 || restored != 40 || secondRestart.weaponDamage(target, false, maximum) != 40 || len(secondRestart.inventory.Items) != 1 || secondRestart.inventory.Items[0].Slot != 6 { t.Fatalf("OE did not follow persistent effective skills: reduced %d persisted %d restored %d items %+v", reduced, persisted, restored, secondRestart.inventory.Items) } @@ -79,7 +79,7 @@ func TestOverequippingAdjustedMinimumPrecedesArmor(t *testing.T) { }} attacker.stats.Melee.OneHandEdged, attacker.stats.Body.Brawling = 398, 1 - damage := attacker.normalDamage(world.characters[1], func(limit uint32) uint32 { + damage := attacker.weaponDamage(world.characters[1], false, func(limit uint32) uint32 { if limit != 23 { t.Fatalf("OE and AR adjusted range: got %d want 23", limit) } @@ -104,13 +104,13 @@ func TestOverequippingDoesNotPenalizeFistsAfterUnequip(t *testing.T) { t.Fatal(err) } - axe := player.normalDamage(target, maximum) + axe := player.weaponDamage(target, false, maximum) world.handleInventory(world.clients[1], itemMovePacket(1, 6, 111)[20:]) world.advanceEquipment(world.clients[1].equipment.readyAt) - fists := player.normalDamage(target, maximum) + fists := player.weaponDamage(target, false, maximum) restarted := newTestInventoryServer(t).characters[1] - if axe != 0 || fists != 10 || restarted.normalDamage(target, maximum) != 10 || restarted.inventory.Items[0].Slot != 64 { + if axe != 0 || fists != 10 || restarted.weaponDamage(target, false, maximum) != 10 || restarted.inventory.Items[0].Slot != 64 { t.Fatalf("unequipped axe retained its penalty: axe %d fists %d items %+v", axe, fists, restarted.inventory.Items) } } diff --git a/server/signed_stats_test.go b/server/signed_stats_test.go @@ -204,7 +204,7 @@ func TestSignedNegativeMartialArtsDoesNotWrapDamageScaling(t *testing.T) { player.activeNanos = syntheticNanoModifiers(t, [][2]int32{{100, -105}}) rating := player.attackRating() - damage := player.normalDamage(world.characters[1000000], func(limit uint32) uint32 { return limit - 1 }) + damage := player.weaponDamage(world.characters[1000000], false, func(limit uint32) uint32 { return limit - 1 }) if rating != -100 || damage != 4 { t.Fatalf("signed attack rating or provisional scaling wrapped: %d/%d", rating, damage) diff --git a/server/starter_weapons_test.go b/server/starter_weapons_test.go @@ -398,7 +398,7 @@ func TestZeroWeaponRequirementCannotDivideByZeroAfterSkillLoss(t *testing.T) { t.Cleanup(func() { gamedata.ItemTemplates[123057] = original }) player.inventory.Items[0].Template, player.inventory.Items[0].Slot = 123057, 6 - damage := player.normalDamage(world.characters[1000000], func(limit uint32) uint32 { return 0 }) + damage := player.weaponDamage(world.characters[1000000], false, func(limit uint32) uint32 { return 0 }) value, known := player.effectiveStat(103) if !known || value != actual || damage != 2 { diff --git a/server/state.go b/server/state.go @@ -130,6 +130,7 @@ type server struct { corpseExpiry []*character clients map[uint32]*worldClient fighting map[uint32]*character + combatRoll func(uint32) uint32 chats map[uint32]*chatClient chatLogMutex sync.Mutex browserStreams map[string]*browserStream diff --git a/server/weapon_special.go b/server/weapon_special.go @@ -4,7 +4,6 @@ import ( "ao/server/gamedata" "encoding/binary" "fmt" - "math/rand/v2" "time" ) @@ -59,7 +58,7 @@ func (server *server) handleWeaponSpecial(client *worldClient, body []byte) erro // Prepare a detached result so a failed transaction changes no live actor. seconds := player.weaponSpecialLockSeconds(gamedata.ItemTemplates[item.Template], skill) - damage := min(player.normalDamage(target, rand.Uint32N), target.health) + damage, _ := server.weaponHit_locked(player, target) candidate := prepareDamage(player, target, damage, now) award, err := server.saveSpecialAttack_locked(player, &candidate, skill, now.Add(time.Duration(player.skillLockSeconds(seconds))*time.Second), now) if err != nil { diff --git a/server/weapon_stats_test.go b/server/weapon_stats_test.go @@ -79,7 +79,7 @@ func TestBriefcaseWeaponOmittedDamageTypeUsesMeleeArmor(t *testing.T) { }} attacker.stats.TradeRepair.Psychology = 298 - damage := attacker.normalDamage(world.characters[1], func(limit uint32) uint32 { return limit - 1 }) + damage := attacker.weaponDamage(world.characters[1], false, func(limit uint32) uint32 { return limit - 1 }) if damage != 131 { t.Fatalf("omitted damage type did not use melee armor: %d", damage)