commit 4565f3ec1d3df63dccbf48c8cae4dec46f20a652
parent 6089d0e4ae93625115ec3a61af670a7c7060df67
Author: anon <anon@example.com>
Date: Sun, 25 Oct 2026 20:39:35 +0000
Coordinate ordinary nano and weapon attack phases
Allow casts to preempt unfinished weapon windup, preserve suspended recharge and release only an aborted execution window's unused pause. Keep weapon timing independent from moved refund-retry deadlines, and leave nano recharge available for ordinary attacks.
Cover duplicate/start-stop requests, early and late cancellation, instant execution, failed reservation/refund and COMMIT. Full suite: 8064 tests/subtests; focused combat: 213; repeated race: 208; vet/build pass. Two GPU WASM clients verify windup restart, suspended recharge, an exact 44-point cancellation refund and a shot during nano recharge. Preserve explicit original-server animation/packet-timing TODOs.
Diffstat:
7 files changed, 415 insertions(+), 27 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -920,8 +920,20 @@ introduction and starting-item gameplay remain open below.
reflected damage and multiple-hit/periodic grouping before claiming canonical
rolls. Preserve compound NanoResist168 plus Level54 defenses; they do not sum
to100. The current supported hostile-cast path has no resistance roll.
-- [ ] Coordinate a nano with weapon combat. Check: casting, interruption and
- recharge follow shared action rules without accelerating either action.
+- [x] Coordinate ordinary nano execution with weapon combat. Shared casting
+ preempts partial windup, preserves suspended weapon recharge, releases only
+ an aborted cast's unused pause and permits weapons during nano recharge.
+ Check duplicate/start-stop requests, early/late cancellation, instant casts,
+ failed reservation/refund and COMMIT. Two native clients verify the phase
+ transitions, exact refund and a shot during nano recharge. See
+ [shared timing and verification](docs/nano-weapon-timing.md).
+- [ ] Establish original authoritative weapon/nano scheduling beyond the
+ execution-window reconstruction. Check separate native controller and nano
+ queue clocks across AggDef, short nano recharge, late107, reload overlap and
+ queued results. Distinguish newly scheduled shots from already received
+ damage drained by native animation/StopFight. Inspect held recharge flag0x20
+ and first-result delivery rather than accepting eventual health agreement
+ alone. See [timing evidence and limits](docs/nano-weapon-timing.md).
The QL 1 Meta-Physicist startup crystal now learns Lesser Anger Manifestation
through the native upload effect. Two WASM clients verified requirements,
diff --git a/docs/nano-damage.md b/docs/nano-damage.md
@@ -75,13 +75,16 @@ the original server's packet ordering has not been captured.
Native admission includes standing still, including keyboard turning, and
excludes swimming, falling and flight. The supported server checks forward,
-strafe and turn state, posture, driving, pending equipment and the caster's
-weapon phase. Movement commands 1/3/5/7/13 or a changed position cancel a
+strafe and turn state, posture, driving and pending equipment.
+Movement commands 1/3/5/7/13 or a changed position cancel a
pending cast. Orientation-only updates do not infer an interruption rule.
The native range predicate uses direct three-dimensional distance without
creature extents; the server checks the 25-metre boundary at admission and
completion. Active casts defer an existing or newly started weapon attack;
-weapon recharge is never shortened.
+remaining weapon recharge is suspended rather than spent by casting. Casts can
+interrupt weapon windup; nano recharge still permits ordinary attacks. See
+[shared weapon/nano timing](nano-weapon-timing.md) for the phase rules, verification
+and original-server timing boundaries.
## Resource arithmetic and policy limits
diff --git a/docs/nano-weapon-timing.md b/docs/nano-weapon-timing.md
@@ -0,0 +1,105 @@
+# Nano execution and ordinary weapon timing
+
+Ordinary nano casting can interrupt a weapon attack that has not landed. The
+interrupted windup restarts from its full attack delay. If the weapon is already
+recharging, its remaining recharge is suspended rather than spent by the cast.
+Nano recharge itself permits ordinary weapon attacks.
+
+These rules use the shared casting and combat paths for all admitted programs;
+there are no program-ID scheduling branches. A successful reservation publishes
+one preemption. Repeated cast requests, target changes, and stopping/restarting
+combat cannot spend the suspended recharge or preserve partial windup.
+
+## Evidence and boundaries
+
+The matching original client controller uses actor+184. Nano admission through
+100650f0 allocates a category 3 timer with10052630 and preempts the active timer
+through100529a0. A preempted attack loses its partial progress. Controller tick
+100527c0 returns before its recharge scan while another attack timer remains
+active, preserving the weapon's remaining recharge. Abort108 removes the owned
+nano timer through10066690 ->10065420 ->100526a0. Queued weapon results remain
+independent server-supplied damage;10079250 can drain results already received.
+A visible impact during casting therefore does not establish a new server shot.
+
+The retained original Evidence IDs include
+`ev_54c8e5911c3ccf91ab6ce87b5b2df8506f06ab9850e3ae78da5b0cb38fc13d7c`
+(controller operations),
+`ev_9081c9ee969a3f64c9cfb5aec6a5d90477aa638090d6ed38e5791a3d0d58eeda`
+(nano queue), and
+`ev_839516fbf9737749e969200bc7698259fa6decf43f39b3025dc440c60acd95f3`
+(weapon stop). The ledger and 38 checked source/extract hashes are under
+`local/cast-weapon-research/controller/`. Original KKR SHA256 is
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+No new binary session or export was used.
+
+The public native request path10022180 ->100646a0 has no ordinary weapon-phase
+veto. Its busy test1006473f reads casting/activity state10071ad0, not the weapon
+attack/recharge timer. This supports admitting casts during weapon windup rather
+than imposing a recharge-only gate. A [March 2002 player report](https://forums-archive.anarchy-online.com/showthread.php?15020-nt-weapons-amp-ip=)
+on the official forum describes a new nuke interrupting an unfinished weapon
+shot. [October 2002 discussion](https://forums-archive.anarchy-online.com/showthread.php?56578-Question-regarding-weapon-speeds=)
+distinguishes actions during recharge; a [May 2003 report](https://forums-archive.anarchy-online.com/showthread.php?138367-Weapon-Attack-Recharge=)
+corroborates that NanoC Init changes execution but not nano recharge. These are
+contemporary player reports, not Funcom server specifications. Retained web
+extracts and their retrieval/date limitations are in
+`local/cast-weapon-research/period/`.
+
+## Server reconstruction
+
+The server suspends weapon timing for the admitted execution window, clamped
+at zero for instant nanos. It adds that duration to any remaining weapon
+recharge, then schedules a full attack. A new fight started during execution
+uses the same window. An early successful cancellation removes only the unused
+pause. Cancellation after that window leaves the already resumed weapon clock
+alone. No additional attack or recharge starts merely because nano completion
+or a cancellation was processed late.
+
+Admission prepares weapon clocks on the detached caster and publishes them only
+after its durable nano reservation succeeds. A failed or ignored update or a
+failed COMMIT changes no weapon clock and sends no admission. A failed refund
+retains its reservation and cancellation state. Its retry deadline may move;
+its original weapon window does not. This keeps stopping/restarting combat
+from accidentally substituting a refund-retry deadline for cast execution.
+
+The native temporary controller and nano queue are distinct clocks. Its integer
+controller duration omits the queue's AggDef subtraction. Queue completion107
+releases an effect gate but does not itself remove the controller; queue expiry
+or abort can remove it later. The server execution-window policy above does not
+claim to reproduce every resulting animation-timer discrepancy. Exact original
+server scheduling across AggDef, short nano recharge, late107, simultaneous
+reload/other controllers and failure timing remains open. The retained client
+controller alone cannot establish authoritative packet timing. Specials and
+incoming-hit interruption probabilities remain separate unfinished contracts.
+
+## Verification
+
+`server/nano_weapon_test.go` exercises windup preemption, remaining recharge,
+duplicate requests, stop/restart attempts, early/late cancellation, reservation
+FAIL/IGNORE/deferred-COMMIT failures, failed-refund retry, instant execution and
+ordinary attacks during nano recharge. Existing casting, reservation, outcome,
+reload and special regressions also run against the shared paths.
+
+The full server/data-exporter run passed 8,064 tests/subtests in 1226.964 seconds.
+The focused combat run passed 213 checks; 208 race checks across two repetitions,
+vet and the preview build also passed. Assets and the exporter have no tests.
+
+Two headed GPU WASM clients uploaded the original crystals and used the
+native program window during ordinary pistol combat. Read-only samples show
+partial 224cs weapon windup resetting to 224cs at category3 preemption. The first
+shot arrived 4.569 seconds after admission, after execution and a full windup.
+A recharge cast lengthened the shot interval to 6.278 seconds. Movement cancelled
+another cast after 0.667 seconds, restored exactly 44 nano in the native samples,
+removed its temporary timer and shortened the shot interval to 4.744 seconds.
+Both observers then showed the same 59 HP NPC and the unchanged existing buff.
+Ice Flechette supplied the longer recharge check: a pistol shot arrived
+1.754 seconds after completion, 742ms before the committed recharge deadline,
+while the native nano queue remained in phase2 with its finish gate released.
+Both clients also installed its authored initiative child. No WASM errors occurred.
+
+Snapshots also expose the native held-recharge flag0x20 and its dependence on
+supplied results/animation. These samples support the phase rules and the
+server's measured cadence; they do not establish every original animation or
+packet-delivery boundary. The corresponding fidelity TODO stays open.
+Captures, complete packet streams, native/SQLite snapshots and the assertion
+script are retained under `local/cast-weapon-smoke/`. Gameplay used GUI input;
+no gameplay request injection, native calls or heap writes were used.
diff --git a/server/combat.go b/server/combat.go
@@ -299,8 +299,8 @@ func (server *server) startAttack_locked(attacker, target *character, now time.T
if attacker.nextAttack.Before(attacker.rechargeUntil) {
attacker.nextAttack = attacker.rechargeUntil
}
- if client := server.clients[attacker.id]; client != nil && client.nanoCast != nil && attacker.nextAttack.Before(client.nanoCast.readyAt) {
- attacker.nextAttack = client.nanoCast.readyAt
+ if client := server.clients[attacker.id]; client != nil && client.nanoCast != nil && attacker.nextAttack.Before(client.nanoCast.weaponResumeAt) {
+ attacker.nextAttack = client.nanoCast.weaponResumeAt
}
attack, _ := attacker.attackDelays()
attacker.nextAttack = attacker.nextAttack.Add(attack)
diff --git a/server/nano_casting.go b/server/nano_casting.go
@@ -12,10 +12,11 @@ import (
)
type nanoCast struct {
- program uint32
- target uint32
- readyAt time.Time
- cancelled bool
+ program uint32
+ target uint32
+ readyAt time.Time
+ weaponResumeAt time.Time // Refund retries do not extend the weapon pause.
+ cancelled bool
}
func nanoStat(program, stat uint32) uint32 {
@@ -143,7 +144,7 @@ func (server *server) handleNanoCast(client *worldClient, body []byte) error {
accepted := targetType == 50000 && binary.BigEndian.Uint32(body[28:32]) == 53019 &&
slices.Contains(player.inventory.LearnedNanos, program) && player.nanoRequirementsMet(program) && player.nano >= nanoCost(program) &&
!player.sitting && !player.driving() && client.forward == 0 && !client.strafing && !client.turning && client.equipment == nil &&
- (player.fighting == 0 || now.Before(player.rechargeUntil)) && server.nanoTarget_locked(player, target, client, program, now)
+ server.nanoTarget_locked(player, target, client, program, now)
if !accepted {
updates[client] = append(updates[client], characterActionPacket(player.id, [5]uint32{108}))
@@ -156,16 +157,27 @@ func (server *server) handleNanoCast(client *worldClient, body []byte) error {
candidate := *player
candidate.nanoReserved = nanoCost(program)
candidate.nano -= candidate.nanoReserved
+ delay := player.nanoCastDelay(program)
+ weaponResumeAt := now.Add(max(0, delay))
+
+ // Suspend remaining recharge; an interrupted attack restarts from its full delay.
+ if now.Before(candidate.rechargeUntil) {
+ candidate.rechargeUntil = candidate.rechargeUntil.Add(max(0, delay))
+ }
+ if candidate.fighting != 0 {
+ candidate.nextAttack = weaponResumeAt
+ if candidate.nextAttack.Before(candidate.rechargeUntil) {
+ candidate.nextAttack = candidate.rechargeUntil
+ }
+ attack, _ := candidate.attackDelays()
+ candidate.nextAttack = candidate.nextAttack.Add(attack)
+ }
if err := server.saveNanoBalance_locked(&candidate); err != nil {
server.mutex.Unlock()
return err
}
*player = candidate
- client.nanoCast = &nanoCast{program: program, target: target.id, readyAt: now.Add(player.nanoCastDelay(program))}
- if player.fighting != 0 && client.nanoCast.readyAt.After(player.rechargeUntil) {
- attack, _ := player.attackDelays()
- player.nextAttack = client.nanoCast.readyAt.Add(attack)
- }
+ client.nanoCast = &nanoCast{program: program, target: target.id, readyAt: now.Add(delay), weaponResumeAt: weaponResumeAt}
server.queueCombat_locked(updates, player, target, characterActionPacket(player.id, [5]uint32{18, 50000, target.id, 0, program}))
updates[client] = append(updates[client], nanoPointsPacket(player))
server.mutex.Unlock()
@@ -185,15 +197,21 @@ func (server *server) abortNano_locked(client *worldClient, now time.Time, updat
log.Printf("Nano refund: %v", err)
return
}
- client.nanoCast = nil
- if player.fighting != 0 {
- attack, _ := player.attackDelays()
- player.nextAttack = now
- if now.Before(player.rechargeUntil) {
- player.nextAttack = player.rechargeUntil
+ // An early abort releases only the unspent pause; a late result cannot reset progress.
+ if now.Before(client.nanoCast.weaponResumeAt) {
+ if player.rechargeUntil.After(client.nanoCast.weaponResumeAt) {
+ player.rechargeUntil = player.rechargeUntil.Add(-client.nanoCast.weaponResumeAt.Sub(now))
+ }
+ if player.fighting != 0 {
+ attack, _ := player.attackDelays()
+ player.nextAttack = now
+ if now.Before(player.rechargeUntil) {
+ player.nextAttack = player.rechargeUntil
+ }
+ player.nextAttack = player.nextAttack.Add(attack)
}
- player.nextAttack = player.nextAttack.Add(attack)
}
+ client.nanoCast = nil
server.queueCombat_locked(updates, player, player, characterActionPacket(player.id, [5]uint32{108}))
updates[client] = append(updates[client], nanoPointsPacket(player))
}
diff --git a/server/nano_casting_test.go b/server/nano_casting_test.go
@@ -66,7 +66,7 @@ func TestWinterBiteTimesOneResultAndRecharge(t *testing.T) {
}
func TestWinterBiteRejectsInvalidAdmission(t *testing.T) {
- for _, scenario := range []string{"unlearned", "profession", "psychology", "creation", "nano", "sitting", "forward", "strafe", "turn", "equipment", "weapon attack", "hidden", "dead target", "player target", "empty identity", "item identity", "wrong zone", "range", "range vertical", "wrong program", "wrong resource", "foreign owner", "loading", "not ready", "stale", "dead caster"} {
+ for _, scenario := range []string{"unlearned", "profession", "psychology", "creation", "nano", "sitting", "forward", "strafe", "turn", "equipment", "hidden", "dead target", "player target", "empty identity", "item identity", "wrong zone", "range", "range vertical", "wrong program", "wrong resource", "foreign owner", "loading", "not ready", "stale", "dead caster"} {
t.Run(scenario, func(t *testing.T) {
world, _ := newNanoCastingWorld(t)
player, client, npc := world.characters[1], world.clients[1], world.characters[1000000]
@@ -93,8 +93,6 @@ func TestWinterBiteRejectsInvalidAdmission(t *testing.T) {
client.turning = true
case "equipment":
client.equipment = &equipmentMove{}
- case "weapon attack":
- player.fighting = npc.id
case "hidden":
delete(client.npcs, npc.id)
case "dead target":
diff --git a/server/nano_weapon_test.go b/server/nano_weapon_test.go
@@ -0,0 +1,252 @@
+package main
+
+import (
+ "encoding/binary"
+ "fmt"
+ "testing"
+ "time"
+)
+
+func TestNanoInterruptsWeaponWindupAndRestartsItsFullAttack(t *testing.T) {
+ world, _ := newNanoCastingWorld(t)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ before := player.nextAttack
+ attack, _ := player.attackDelays()
+
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, 29618})[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if client.nanoCast == nil || player.nano != 21 || player.nextAttack != client.nanoCast.readyAt.Add(attack) || !player.rechargeUntil.IsZero() {
+ t.Fatal("nano did not interrupt and restart weapon windup", client.nanoCast, player.nextAttack, player.rechargeUntil, player.nano)
+ }
+ world.advanceCombat(before)
+ if target.health != 100 {
+ t.Fatal("interrupted weapon windup still hit", target.health)
+ }
+ world.advanceNanos(client.nanoCast.readyAt.Add(time.Nanosecond))
+ health := target.health
+ world.advanceCombat(player.nextAttack.Add(-time.Nanosecond))
+ if target.health != health {
+ t.Fatal("weapon completed before its full restarted attack")
+ }
+ world.advanceCombat(player.nextAttack)
+ if target.health >= health {
+ t.Fatal("weapon did not resume after nano execution", target.health, health)
+ }
+}
+
+func TestNanoPreservesRemainingWeaponRecharge(t *testing.T) {
+ for _, restart := range []bool{false, true} {
+ t.Run(fmt.Sprintf("restart=%t", restart), func(t *testing.T) {
+ world, _ := newNanoCastingWorld(t)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceCombat(player.nextAttack)
+ before, recharge := player.nextAttack, player.rechargeUntil
+
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, 29618})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, 29618})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if restart {
+ for range 3 {
+ if err := world.handleCombat(client, stopFightPacket(1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ }
+ }
+
+ if client.nanoCast == nil || player.rechargeUntil != recharge.Add(2575000047*time.Nanosecond) || player.nextAttack != before.Add(2575000047*time.Nanosecond) {
+ t.Fatal("nano spent the suspended weapon recharge", player.rechargeUntil.Sub(recharge), player.nextAttack.Sub(before))
+ }
+ world.advanceNanos(client.nanoCast.readyAt.Add(time.Nanosecond))
+ health := target.health
+ world.advanceCombat(before)
+ if target.health != health {
+ t.Fatal("weapon bypassed suspended recharge", health, target.health)
+ }
+ world.advanceCombat(player.nextAttack)
+ if target.health >= health {
+ t.Fatal("weapon did not resume after its remaining recharge")
+ }
+ })
+ }
+}
+
+func TestLateNanoAbortDoesNotRestartAWeaponThatAlreadyResumed(t *testing.T) {
+ world, conn := newNanoCastingWorld(t)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, 29618})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ next := player.nextAttack
+ at := client.nanoCast.readyAt.Add(500 * time.Millisecond)
+ target.position[0] = 26
+ conn.packets = nil
+
+ world.advanceNanos(at)
+
+ if client.nanoCast != nil || player.nextAttack != next || player.nano != 30 || player.nanoReserved != 0 || target.health != 100 {
+ t.Fatal("late invalid completion reset weapon progress or retained nano cost", player.nextAttack.Sub(next), client.nanoCast, player.nano)
+ }
+ if len(conn.packets) != 2 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 108 {
+ t.Fatal("late cancellation did not publish exactly one refund")
+ }
+}
+
+func TestEarlyNanoAbortResumesOnlyTheRemainingWeaponRecharge(t *testing.T) {
+ world, _ := newNanoCastingWorld(t)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceCombat(player.nextAttack)
+ recharge := player.rechargeUntil
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, 29618})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ started := client.nanoCast.readyAt.Add(-2575000047 * time.Nanosecond)
+ attack, _ := player.attackDelays()
+ before := time.Now()
+
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{108})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ after := time.Now()
+
+ if client.nanoCast != nil || player.nano != 30 || player.nanoReserved != 0 ||
+ player.rechargeUntil.Before(recharge.Add(before.Sub(started))) || player.rechargeUntil.After(recharge.Add(after.Sub(started))) ||
+ player.nextAttack != player.rechargeUntil.Add(attack) {
+ t.Fatal("early abort spent or repeated remaining recharge", player.rechargeUntil.Sub(recharge), player.nextAttack, client.nanoCast)
+ }
+}
+
+func TestNanoReservationFailurePreservesWeaponPhases(t *testing.T) {
+ for _, failure := range []string{
+ "CREATE TRIGGER fail_phase BEFORE UPDATE OF nano_reserved ON characters BEGIN SELECT RAISE(FAIL,'test phase'); END",
+ "CREATE TRIGGER fail_phase BEFORE UPDATE OF nano_reserved ON characters BEGIN SELECT RAISE(IGNORE); END",
+ "CREATE TABLE pending_phase (player_id INTEGER REFERENCES players(id) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER fail_phase AFTER UPDATE OF nano_reserved ON characters BEGIN INSERT INTO pending_phase VALUES(999999); END",
+ } {
+ t.Run(failure, func(t *testing.T) {
+ world, conn := newNanoCastingWorld(t)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceCombat(player.nextAttack)
+ next, recharge := player.nextAttack, player.rechargeUntil
+ if _, err := world.db.Exec(failure); err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+
+ err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, 29618})[20:])
+
+ if err == nil || client.nanoCast != nil || player.nano != 30 || player.nanoReserved != 0 ||
+ player.nextAttack != next || player.rechargeUntil != recharge || len(conn.packets) != 0 {
+ t.Fatal("failed reservation changed weapon timing or published admission", err, player.nextAttack, player.rechargeUntil, player.nano)
+ }
+ })
+ }
+}
+
+func TestFailedNanoRefundRetainsItsOriginalWeaponWindow(t *testing.T) {
+ world, conn := newNanoCastingWorld(t)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, 29618})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ next, deadline := player.nextAttack, client.nanoCast.readyAt
+ if _, err := world.db.Exec("CREATE TRIGGER fail_weapon_refund BEFORE UPDATE OF nano_reserved ON characters BEGIN SELECT RAISE(FAIL,'test refund'); END"); err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{108})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleCombat(client, stopFightPacket(1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if client.nanoCast == nil || !client.nanoCast.cancelled || client.nanoCast.weaponResumeAt != deadline ||
+ player.nextAttack != next || player.nano != 21 || player.nanoReserved != 9 {
+ t.Fatal("refund retry changed the weapon window", client.nanoCast, player.nextAttack.Sub(next))
+ }
+ for _, packet := range conn.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x5e477770 && binary.BigEndian.Uint32(packet[29:33]) == 108 {
+ t.Fatal("failed refund acknowledged cancellation")
+ }
+ }
+ if _, err := world.db.Exec("DROP TRIGGER fail_weapon_refund"); err != nil {
+ t.Fatal(err)
+ }
+ retriedAt := client.nanoCast.readyAt.Add(time.Nanosecond)
+ attack, _ := player.attackDelays()
+ world.advanceNanos(retriedAt)
+ if client.nanoCast != nil || player.nano != 30 || player.nanoReserved != 0 || player.nextAttack != retriedAt.Add(attack) || target.health != 100 {
+ t.Fatal("refund retry did not release only the remaining pause", client.nanoCast, player.nextAttack, player.nano)
+ }
+}
+
+func TestWeaponAttacksContinueDuringNanoRecharge(t *testing.T) {
+ world, _ := newNanoCastingWorld(t)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ player.profession = 11
+ player.stats.NanoAiding.MatterCreation = 7
+ player.inventory.LearnedNanos = []uint32{28612}
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, 28612})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceNanos(client.nanoCast.readyAt.Add(time.Nanosecond))
+ health, at := target.health, player.nextAttack
+
+ world.advanceCombat(at)
+
+ if !at.Before(player.nanoRechargeUntil) || target.health >= health || client.nanoCast != nil || player.nano != 23 {
+ t.Fatal("nano recharge blocked an ordinary weapon attack", at, player.nanoRechargeUntil, target.health, health, player.nano)
+ }
+}
+
+func TestInstantNanoDoesNotMoveWeaponRechargeBackwards(t *testing.T) {
+ world, _ := newNanoCastingWorld(t)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ player.stats.Speed.NanoInitiative = 1000
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceCombat(player.nextAttack)
+ next, recharge := player.nextAttack, player.rechargeUntil
+
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, target.id, 53019, 29618})[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if client.nanoCast == nil || !client.nanoCast.readyAt.Before(client.nanoCast.weaponResumeAt) ||
+ player.rechargeUntil != recharge || player.nextAttack != next {
+ t.Fatal("negative execution delay accelerated weapon recharge", client.nanoCast, player.rechargeUntil.Sub(recharge), player.nextAttack.Sub(next))
+ }
+}