commit a4b6834403ae7de717ca11d1cb25bfe68eb86132
parent 9008962bf2a9b41bf5211b37c659e692518d3618
Author: anon <anon@example.com>
Date: Fri, 6 Nov 2026 01:47:13 +0000
Implement concealed opening Aimed Shot with persistent cooldown
Diffstat:
18 files changed, 788 insertions(+), 37 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -146,8 +146,11 @@ research separately. More screenshots and test cases do not count as new gamepla
cooldown, with fists and stocked Sledgehammer input/recovery checks.
[Dimach](docs/dimach.md) now has its independent item damage, native action
and persistent 30-minute cooldown, with the same fists/Sledgehammer input
- and recovery checks. Aimed Shot remains an explicit weapon-special gap and
- depends on the unfinished sneak/concealment lifecycle.
+ and recovery checks. [Aimed Shot](docs/aimed-shot.md) now supports the issued
+ Agent rifle and stocked Gripo through native Sneak and opening-shot input,
+ with atomic damage/rewards, reveal and persistent cooldown. Concealment
+ admission and damage use explicit provisional PvE rules; historical
+ detection and player-versus-player invisibility remain deferred.
Remaining profession essentials stay open. The
[bounded earned affordability sample](docs/early-shop-stock.md#earned-affordability-sample-november-5)
now completes an ordinary level-two Omni mission, buys and wears gloves,
diff --git a/docs/aimed-shot.md b/docs/aimed-shot.md
@@ -0,0 +1,107 @@
+# Aimed Shot and PvE concealment
+
+Aimed Shot (151) now executes for the issued Agent Solar Powered Rifle (121568)
+and stocked QL5/10 Gripo-Com AKR 1K20 (123976). It requires a supported main-hand
+weapon with Can bit14, an approved sneak state and an unsuspecting creature.
+This completes the demonstrated A5 weapon-special rejection. Full historical
+stealth and player-versus-player concealment remain deferred.
+
+## Evidence and provisional rules
+
+The original `cd_image/text/help/How do I play this Game in a Team.txt` describes
+a concealed puller's opening Aimed Shot against an unsuspecting target. The
+Solar rifle tip describes equipping the rifle and placing its special from the
+Command View on a shortcut. Its Q-then-special instructions do not establish the
+concealment admission rule. The tested alpha path starts with Sneak, selects the
+target, and presses O without first starting ordinary combat.
+
+Retained native evidence is in `local/old/player-frozen/research/sneak/README.md`.
+The original KKR SHA256 is
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+Special action19 sends CharacterAction163; acknowledgement162 causes the owner
+to send movement26. Movement26 enters primary6, and movement32 restores preferred
+walking2/running3. The callbacks retain rest, velocity, controls and gravity;
+Features224 bit128 and command presentation follow the transition. Exact lifted
+helpers are `client/game/kkr.dll/lifted-0022.c`, `sub_36046630` and `sub_36046740`.
+The exported SneakToggle function is an empty stub; the native Command View is
+the verified input route. The command icon mapping is retained in
+`local/old/fast-attack-research/native/0x10056cf0-procedure_pseudo_code-aae70120.txt`:
+entry19 uses icon49575, exit79 uses82476.
+
+The original `100aaf10` supplies Can bit14. The `100ab060` recharge helper gives
+`RechargeDelay210 * 40 - AimedShot151 * 3` centiseconds, floored at1000. The server
+rounds up to seconds and applies the shared SkillLockModifier382 conversion.
+As with Burst, the observed client caller discards the return value; adopting
+this arithmetic as authoritative server timing is provisional.
+
+The following are explicit alpha rules, not recovered original server code:
+
+- Sneak entry requires a living, ready, walking/running player who is neither
+ attacking nor being attacked, equipping, reloading, driving or casting.
+ The server establishes primary6 before acknowledgement; unsolicited movement26
+ cannot grant sneak. Ordinary movement can continue in primary6.
+- Aimed Shot requires effective Concealment164 at least equal to the creature's
+ Perception136, no player fight, and no target fight or retained threat. The
+ existing range, line-of-sight, weapon, posture, reload and skill-lock gates
+ still apply. Failed admission preserves concealment and consumes nothing.
+- Damage uses the weapon's maximum ordinary hit or critical hit, with the shared
+ critical chance, attack rating, overequipping, matching AC and damage bonuses.
+ Multiply by a uniform integer from1 through `max(1, AimedShot / 100)`, then cap
+ at10000 and target HP. Exact historical multiplier, armor ordering and cap
+ remain unverified. There is no defensive hit roll. A finite clip must contain
+ a round, but this special does not debit ammunition under the existing
+ [pre-15.5 policy](fling-shot.md#target-era-evidence).
+- Successful attacks, incoming combat and successfully reserved nano casts end
+ sneak. Movement transitions out of primary6 also end it. Reconnect and zoning
+ reset movement; sneak is not durable. Other players can still see the actor:
+ per-observer invisibility and periodic detection rolls are outside this scope.
+ Clinic permission expiry preserves the independent sneak feature.
+
+## Atomic outcome and native presentation
+
+Damage, skill151's deadline, contribution, corpse/loot and XP commit together.
+Only then does the server reveal the shooter, start ordinary combat against a
+surviving target, and publish the named special result and lock. This provides
+the opening shot's native animation path. Existing idle presentation limitations
+for other specials are unchanged. Failed writes preserve concealment as well as
+all live and durable combat/reward state. Retries and reconnect cannot bypass
+the independent cooldown.
+
+## Verification
+
+`TestAimedShot*` covers the opening damage/reveal/combat transition, persistent
+lock and target HP, independent skill multiplier and recharge floor, invalid
+concealment/alertness/equipment/session requests, and failed or ignored lock,
+health, loot and XP writes followed by successful retry. `TestSneak*` covers
+request/acknowledgement admission, forged movement refusal, retained walking/run
+preference, movement while sneaking, explicit exit, combat/cast reveal to owner
+and observer, and preservation through both clinic permission expiry paths.
+
+`TestBrowserAimedShot` uses real inventory equip, Command View Sneak, target
+selection and O. It compares native HP and Features224 with server state, checks
+the opening fight and cooldown, retries the action, reconnects, and cold-loads
+the damage, inventory and lock. The Solar case is an ordinary level-one Agent.
+The Gripo case uses the existing cap-checked level-ten fixture and stocked QL10
+rifle with eight rounds. A nearby controlled Leet has1000HP and ordinary swings
+are held to isolate the special. These are input/recovery checks, not earned
+progression or affordability evidence.
+
+November5: 145 distinct selected server test roots pass across the broad run and
+focused rerun, including all nine new Aimed Shot/sneak roots. The broad run's
+sole failure was the new reveal assertion reading the compact movement format
+incorrectly; the corrected assertion verifies the raw correction byte0xa0 for
+both owner and observer. JavaScript syntax, diff checks and `go vet ./server`
+also pass. Logs are `local/alpha-aimed-shot/{regressions,final-focused,vet}.log`.
+
+The native Solar case passes with12 damage and the Gripo with88, preserving all
+eight Gripo rounds. Reconnect and cold recovery retain damage and cooldown.
+Solar evidence is `local/alpha-aimed-shot/20261105-174109/solar/`; final Gripo
+evidence is `local/alpha-aimed-shot/20261105-174413/gripo/`. Each contains
+`verification.json`, screenshots and native traces. The browser command-window
+wait now observes the actual command grid before interacting. Both successful
+cases took about20seconds. Test browsers and isolated servers exited.
+
+No new historical search was needed: this change uses the bounded retained
+native evidence and makes the remaining balance/detection assumptions explicit.
+It closes A5's named Aimed Shot dependency, not the remaining profession
+requirements or A7's faction/progression matrix.
diff --git a/docs/early-shop-stock.md b/docs/early-shop-stock.md
@@ -215,8 +215,8 @@ coverage are in [M-10 pistols](catalog-weapons.md), [E-Beamers](e-beamer.md),
[Gripo rifles](gripo-rifles.md) and [Kerans SMGs](kerans.md). All six support ordinary
attacks. M-10/E-Beamer Fling and [Kerans Burst](burst.md) use the shared special
handler. [Brawl](brawl.md) and [Dimach](dimach.md) now support fists and the
-stocked Sledgehammer. Gripo Aimed Shot remains unimplemented; stock does not
-complete it. The Kerans also applies its
+stocked Sledgehammer. [Gripo Aimed Shot](aimed-shot.md) now supports a concealed
+opening shot, with native input and recovery checks. The Kerans also applies its
original +2 Sense wear bonus.
Unfinished profession essentials remain outstanding. These funded checks do not
establish that ordinary early rewards can pay the listed prices.
@@ -292,8 +292,9 @@ subdirectories `c005049f`, `c026049c` and `c01204a2`. The three-shop run took
`regressions.log`. `go vet ./server`, JavaScript syntax and diff checks also pass
(`vet.log`). Test servers and Chromium processes were closed. The remaining
A5 work is profession essentials; the earned affordability sample is above.
-Aimed Shot remains an explicit combat gap. [Burst now executes](burst.md), with
-separate starter Solar SMG and stocked Kerans native checks.
+[Aimed Shot now executes](aimed-shot.md), with separate issued Agent rifle and
+stocked Gripo native concealment/recovery checks. [Burst now executes](burst.md),
+with separate starter Solar SMG and stocked Kerans native checks.
## Basic nano crystals
diff --git a/docs/player-movement.md b/docs/player-movement.md
@@ -256,19 +256,16 @@ Sneak's recovered flow is special action19 -> CharacterAction163 request, then
server acknowledgement162 -> movement26. Ordinary send suppresses26 while
seated; the receiver requires its weapon-holder state and no effective InFight410.
Helper26/32 changes primary6/preferred and presentation/Features128, preserving
-rest, velocity, controls and gravity. The server request/acknowledgement policy
-and concealment/visibility rules remain unresolved; incoming26/32 stay excluded.
-
-November5 A5 dependency check: Aimed Shot on the issued Agent rifle and stocked
-Gripo requires this lifecycle. The shipped
-`cd_image/text/help/How do I play this Game in a Team.txt` describes a concealed
-puller's opening shot against an unsuspecting target. The retained movement
-producer/helper evidence establishes163/162/26/32 but does not establish the
-server's concealment contest, cancellation or observer visibility policy. The
-bounded check stopped at that boundary. Implement a documented, coherent
-concealment policy and test the native handshake before admitting Aimed Shot;
-do not repeat broad historical searches without a concrete new source or
-reproduced packet failure to investigate.
+rest, velocity, controls and gravity. The server now supports the request/acknowledgement flow and gates incoming26
+on prior approval. Incoming32 exits sneak. See [Aimed Shot](aimed-shot.md) for
+the explicit PvE concealment rules and deferred observer invisibility.
+
+November5 A5 dependency: the issued Agent rifle and stocked Gripo now use this
+lifecycle for an opening Aimed Shot. Bounded retained evidence establishes the
+163/162/26/32 sequence; authoritative concealment admission and damage remain
+explicit provisional rules. Native input and server regressions are recorded
+in the Aimed Shot document. Reopen historical detection research only with a
+concrete new source or reproduced failure.
## Water and retained rest
diff --git a/server/aimed_shot_test.go b/server/aimed_shot_test.go
@@ -0,0 +1,204 @@
+package main
+
+import (
+ "encoding/binary"
+ "fmt"
+ "reflect"
+ "testing"
+ "time"
+)
+
+func aimedShotRequest(owner, target uint32) []byte {
+ request := flingShotRequest(owner, target)
+ binary.BigEndian.PutUint32(request[len(request)-4:], 151)
+ return request
+}
+
+func newAimedShotWorld(t *testing.T) (*server, *combatTestConn) {
+ t.Helper()
+ world, output := newKillExperienceWorld(t, "unarmed")
+ player := world.characters[1]
+ player.profession = 5
+ player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ player.stats.Ranged.Rifle, player.stats.Ranged.AimedShot = 20, 10
+ player.stats.Spying.Concealment = 20
+ player.inventory.LastID = 1
+ player.inventory.Items = []ownedItem{{ID: 1, Type: 51018, Template: 121568, Quality: 1, Count: 1, Slot: 6}}
+ world.characters[1000000].health = 1000
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.flushWorld(); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleSneak(world.clients[1], characterActionPacket(1, [5]uint32{163})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if player.movement.components[0] != 6 {
+ t.Fatal("sneak not approved")
+ }
+ output.packets = nil
+ return world, output
+}
+
+func TestAimedShotCommitsOpeningDamageRevealsAndRecoversLock(t *testing.T) {
+ world, output := newAimedShotWorld(t)
+ player, target := world.characters[1], world.characters[1000000]
+ inventory := player.inventory
+ before := time.Now()
+ world.combatRoll = func(uint32) uint32 { return 0 }
+
+ err := world.handleWeaponSpecial(world.clients[1], aimedShotRequest(1, target.id)[20:])
+ cold := newTestInventoryServer(t)
+
+ if err != nil || target.health != 988 || player.fighting != target.id || player.movement.components[0] == 6 ||
+ player.skillLocks[151].Before(before.Add(40*time.Second)) || player.skillLocks[151].After(time.Now().Add(40*time.Second)) || !reflect.DeepEqual(inventory, player.inventory) {
+ t.Fatal("opening shot omitted damage/reveal/fight/lock", target.health, player.movement.components, player.skillLocks, err)
+ }
+ if cold.characters[target.id].health != 988 || !cold.characters[1].skillLocks[151].Equal(player.skillLocks[151]) || cold.characters[1].movement.components[0] == 6 {
+ t.Fatal("cold recovery changed damage/lock or retained sneak")
+ }
+ found := false
+ for _, packet := range output.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x754f1115 {
+ found = binary.BigEndian.Uint32(packet[33:37]) == 12 && binary.BigEndian.Uint32(packet[49:53]) == 151
+ }
+ }
+ if !found {
+ t.Fatal("missing named Aimed Shot result")
+ }
+ if err := world.handleWeaponSpecial(world.clients[1], aimedShotRequest(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if target.health != 988 {
+ t.Fatal("retry dealt damage")
+ }
+}
+
+func TestAimedShotRejectsInvalidOpeningWithoutOutcome(t *testing.T) {
+ for _, scenario := range []string{"revealed", "fighting", "alerted", "threat", "perception", "range", "weapon", "empty", "reload", "equipping", "locked", "sitting", "hidden", "unready", "owner", "dead"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, output := newAimedShotWorld(t)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ request := aimedShotRequest(1, target.id)[20:]
+ switch scenario {
+ case "revealed":
+ player.movement.components[0] = 2
+ case "fighting":
+ player.fighting = target.id
+ case "alerted":
+ target.fighting = 2
+ case "threat":
+ target.threat = map[uint32]int64{2: 1}
+ case "perception":
+ player.stats.Spying.Concealment = 0
+ case "range":
+ target.position[0] = 50
+ case "weapon":
+ player.inventory.Items[0].Template = 123742
+ case "empty":
+ player.inventory.Items[0].Template, player.inventory.Items[0].Quality = 123976, 10
+ case "reload":
+ client.reloadUntil = time.Now().Add(time.Minute)
+ case "equipping":
+ client.equipment = &equipmentMove{}
+ case "locked":
+ player.setSkillLock_locked(151, time.Now().Add(time.Minute))
+ case "sitting":
+ player.sitting = true
+ case "hidden":
+ delete(client.npcs, target.id)
+ case "unready":
+ client.ready = false
+ case "owner":
+ binary.BigEndian.PutUint32(request[8:], 2)
+ case "dead":
+ player.health = 0
+ }
+ mode, deadline := player.movement.components[0], player.skillLocks[151]
+
+ err := world.handleWeaponSpecial(client, request)
+
+ if err != nil || target.health != 1000 || player.movement.components[0] != mode || !player.skillLocks[151].Equal(deadline) || len(output.packets) != 0 {
+ t.Fatal("rejected opening changed state", err)
+ }
+ })
+ }
+}
+
+func TestAimedShotDamageMultiplierAndCooldown(t *testing.T) {
+ for _, scenario := range []struct {
+ skill uint16
+ damage, seconds uint32
+ }{{10, 6, 40}, {200, 12, 34}, {1000, 60, 10}} {
+ t.Run(fmt.Sprint(scenario.skill), func(t *testing.T) {
+ world, _ := newAimedShotWorld(t)
+ player := world.characters[1]
+ player.stats.Ranged.AimedShot = scenario.skill
+ world.combatRoll = func(limit uint32) uint32 { return limit - 1 }
+ before := time.Now()
+
+ err := world.handleWeaponSpecial(world.clients[1], aimedShotRequest(1, 1000000)[20:])
+
+ if err != nil || world.characters[1000000].health != 1000-scenario.damage || player.skillLocks[151].Before(before.Add(time.Duration(scenario.seconds)*time.Second)) || player.skillLocks[151].After(time.Now().Add(time.Duration(scenario.seconds)*time.Second)) {
+ t.Fatal("incorrect multiplier/recharge", world.characters[1000000].health, player.skillLocks, err)
+ }
+ })
+ }
+}
+
+func TestAimedShotFailedKillPreservesConcealmentAndAtomicOutcome(t *testing.T) {
+ for index, failure := range []string{
+ "BEFORE INSERT ON skill_locks BEGIN SELECT RAISE(IGNORE); END",
+ "BEFORE UPDATE OF health ON characters WHEN NEW.id=1000000 BEGIN SELECT RAISE(FAIL,'target'); END",
+ "BEFORE INSERT ON items BEGIN SELECT RAISE(FAIL,'loot'); END",
+ "BEFORE UPDATE OF experience ON characters WHEN NEW.id=1 BEGIN SELECT RAISE(IGNORE); END",
+ } {
+ t.Run(fmt.Sprint(index), func(t *testing.T) {
+ world, output := newAimedShotWorld(t)
+ player, target := world.characters[1], world.characters[1000000]
+ world.combatRoll = func(uint32) uint32 { return 0 }
+ target.health = 1
+ if err := world.flushWorld(); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := world.db.Exec("CREATE TRIGGER fail_aimed " + failure); err != nil {
+ t.Fatal(err)
+ }
+
+ err := world.handleWeaponSpecial(world.clients[1], aimedShotRequest(1, target.id)[20:])
+ cold := newTestInventoryServer(t)
+
+ if err == nil || target.health != 1 || target.corpse != nil || !player.skillLocks[151].IsZero() || player.experience != 0 || player.movement.components[0] != 6 || player.fighting != 0 || len(output.packets) != 0 || cold.characters[target.id].health != 1 || !cold.characters[1].skillLocks[151].IsZero() || cold.characters[1].experience != 0 {
+ t.Fatal("failed shot retained effects", err)
+ }
+ if _, err := world.db.Exec("DROP TRIGGER fail_aimed"); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleWeaponSpecial(world.clients[1], aimedShotRequest(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ cold = newTestInventoryServer(t)
+ if target.health != 0 || target.corpse == nil || len(target.corpse.items) != 1 || player.experience != 100 || player.movement.components[0] == 6 || cold.characters[1].experience != 100 || cold.characters[1].skillLocks[151].IsZero() {
+ t.Fatal("retry did not commit kill/reveal/reward")
+ }
+ })
+ }
+}
+
+func TestAimedShotCapsMultipliedDamage(t *testing.T) {
+ world, _ := newAimedShotWorld(t)
+ player, target := world.characters[1], world.characters[1000000]
+ player.stats.Ranged.Rifle, player.stats.Ranged.AimedShot = 10000, 60000
+ target.health = 20000
+ world.combatRoll = func(limit uint32) uint32 { return limit - 1 }
+
+ err := world.handleWeaponSpecial(world.clients[1], aimedShotRequest(1, target.id)[20:])
+
+ if err != nil || target.health != 10000 {
+ t.Fatal("multiplied damage exceeded the alpha cap", target.health, err)
+ }
+}
diff --git a/server/browser_aimed_shot_test.go b/server/browser_aimed_shot_test.go
@@ -0,0 +1,114 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "reflect"
+ "runtime"
+ "testing"
+ "time"
+)
+
+func TestBrowserAimedShot(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for native issued and stocked rifle Aimed Shot")
+ }
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/alpha-aimed-shot", time.Now().Format("20060102-150405"))
+ for _, name := range []string{"solar", "gripo"} {
+ t.Run(name, func(t *testing.T) {
+ world := newTestServer(t)
+ fields := creationForm()
+ fields.Set("profession", "5")
+ if response := creationRequest(world, accountVisitor(t, world), fields); response.Code != http.StatusNoContent {
+ t.Fatal(response.Code, response.Body.String())
+ }
+ player := world.characters[2]
+ damage := 12
+ if name == "gripo" {
+ // The stocked QL10 upgrade uses the existing cap-checked checkpoint.
+ trainBasicShopWeaponFixture(t, player)
+ player.inventory.Items[3].Type, player.inventory.Items[3].Template, player.inventory.Items[3].Quality = 51018, 123976, 10
+ player.profession = 5
+ player.inventory.Items[3].Ammo = 8
+ damage = 88
+ }
+ world.combatRoll = func(uint32) uint32 { return 0 }
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("aimed_shot")))
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ var target *character
+ for _, actor := range world.characters {
+ if actor.npc && actor.playfield == 950 && actor.monsterData == 17655 && actor.level == 1 && actor.combatProfile != nil && (target == nil || actor.id < target.id) {
+ target = actor
+ }
+ }
+ if target == nil {
+ t.Fatal("original Leet unavailable")
+ }
+ forward, _ := bodyAxes(player.rotation)
+ target.position = [3]float32{player.position[0] + 2*forward[0], player.position[1], player.position[2] + 2*forward[2]}
+ target.health = 1000
+ if err := world.flushWorld(); err != nil {
+ t.Fatal(err)
+ }
+ mux := http.NewServeMux()
+ mux.Handle("/", world.httpHandler())
+ mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) {
+ world.mutex.Lock()
+ defer world.mutex.Unlock()
+ json.NewEncoder(w).Encode(map[string]any{"target": target.id, "health": target.health, "fighting": player.fighting,
+ "locked": time.Now().Before(player.skillLocks[151]), "remaining": time.Until(player.skillLocks[151]).Seconds(), "inventory": player.inventory, "level": player.level,
+ "ip": player.stats.ImprovementPoints, "damage": damage, "weapon": name, "sneaking": player.movement.components[0] == 6})
+ })
+ host := httptest.NewServer(mux)
+ defer host.Close()
+ defer closeTestSessions(t, world)
+ ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
+ stopped := make(chan struct{})
+ go func() {
+ defer close(stopped)
+ ticker := time.NewTicker(20 * time.Millisecond)
+ defer ticker.Stop()
+ for {
+ select {
+ case now := <-ticker.C:
+ // Isolate AimedShot from ordinary swings, retaining real equip/lock updates.
+ world.advanceEquipment(now)
+ world.advanceItemEffects(now)
+ case <-ctx.Done():
+ return
+ }
+ }
+ }()
+ defer func() { cancel(); <-stopped }()
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_aimed_shot.mjs"), host.URL, filepath.Join(output, name))
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ err := command.Run()
+ cancel()
+ <-stopped
+ closeTestSessions(t, world)
+ t.Logf("Browser artifacts: %s", filepath.Join(output, name))
+ if err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+ if cold.characters[target.id].health != uint32(1000-damage) || !reflect.DeepEqual(cold.characters[2].inventory, player.inventory) ||
+ !cold.characters[2].skillLocks[151].Equal(player.skillLocks[151]) || cold.characters[2].skillLocks[151].IsZero() {
+ t.Fatal("native AimedShot damage, ownership or lock changed on cold recovery")
+ }
+ })
+ }
+}
diff --git a/server/combat.go b/server/combat.go
@@ -347,6 +347,8 @@ func (server *server) combatInRange_locked(attacker, target *character, now time
}
func (server *server) startAttack_locked(attacker, target *character, now time.Time, updates map[*worldClient][][]byte) {
+ server.leaveSneak_locked(attacker, now, updates)
+ server.leaveSneak_locked(target, now, updates)
// Repeated requests must not restart or accelerate the attack clock.
if attacker.fighting == target.id {
return
diff --git a/server/implants.go b/server/implants.go
@@ -124,12 +124,7 @@ func (server *server) advanceItemEffects(now time.Time) {
if !player.implantChangesUntil.IsZero() && !now.Before(player.implantChangesUntil) {
player.implantChangesUntil = time.Time{}
body := binary.BigEndian.AppendUint32(nil, 224)
- // Restore normal features, including the permission to cast programs.
- features := uint32(6)
- if player.canChangeImplants(now) {
- features |= 16
- }
- body = binary.BigEndian.AppendUint32(body, features)
+ body = binary.BigEndian.AppendUint32(body, player.features(now))
updates[client] = append(updates[client], n3Packet(0x2b333d6e, 50000, id, body))
}
}
diff --git a/server/main.go b/server/main.go
@@ -609,6 +609,10 @@ func (server *server) serveWorldClient(client *worldClient) error {
}
action := binary.BigEndian.Uint32(body[16:20])
switch action {
+ case 163:
+ if err := server.handleSneak(client, body); err != nil {
+ return err
+ }
case 22, 24, 25, 26, 28, 127, 145:
if err := server.handleTeamAction(client, body); err != nil {
return err
diff --git a/server/nano_buffs.go b/server/nano_buffs.go
@@ -393,12 +393,8 @@ func (server *server) removeNano_locked(player *character, index int, now time.T
*player = candidate
server.queueCombat_locked(updates, player, player, characterActionPacket(player.id, [5]uint32{65, 0, 0, effect.caster, effect.program}))
if effect.program == 157490 {
- features := uint32(6)
- if player.canChangeImplants(now) {
- features |= 16
- }
body := binary.BigEndian.AppendUint32(nil, 224)
- body = binary.BigEndian.AppendUint32(body, features)
+ body = binary.BigEndian.AppendUint32(body, player.features(now))
server.queueCombat_locked(updates, player, player, n3Packet(0x2b333d6e, 50000, player.id, body))
}
if !player.npc {
diff --git a/server/nano_casting.go b/server/nano_casting.go
@@ -236,6 +236,7 @@ func (server *server) handleNanoCast(client *worldClient, body []byte) error {
return err
}
*player = candidate
+ server.leaveSneak_locked(player, now, updates)
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))
diff --git a/server/player_movement.go b/server/player_movement.go
@@ -496,7 +496,10 @@ func (movement *playerMovement) action(player *character, action uint32) bool {
movement.strafe = 0
}
movement.vertical = 0
- case 31, 34:
+ case 26:
+ // Native sneak callbacks retain rest, controls, velocity and gravity.
+ movement.components[0] = 6
+ case 31, 32, 34:
movement.components[0] = 2
if player.running {
movement.components[0] = 3
diff --git a/server/player_sneak.go b/server/player_sneak.go
@@ -0,0 +1,61 @@
+package main
+
+import (
+ "encoding/binary"
+ "fmt"
+ "time"
+)
+
+func (server *server) handleSneak(client *worldClient, body []byte) error {
+ if len(body) != 36 {
+ return fmt.Errorf("invalid sneak action length")
+ }
+ server.updateMutex.Lock()
+ defer server.updateMutex.Unlock()
+ server.mutex.Lock()
+ player := server.characters[client.id]
+ now := time.Now()
+ if server.clients[client.id] != client || !client.target || !client.ready || client.loading || player.health == 0 ||
+ binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id || binary.BigEndian.Uint32(body[16:20]) != 163 ||
+ player.sitting || player.driving() || player.fighting != 0 || client.nanoCast != nil || client.equipment != nil || now.Before(client.reloadUntil) {
+ server.mutex.Unlock()
+ return nil
+ }
+ for _, attacker := range server.fighting {
+ if attacker.fighting == player.id {
+ server.mutex.Unlock()
+ return nil
+ }
+ }
+ player.anchorMovement_locked(now)
+ if player.movement.components[0] != 2 && player.movement.components[0] != 3 {
+ server.mutex.Unlock()
+ return nil
+ }
+ // Approval establishes server state; the owner's acknowledgement emits movement26.
+ player.followTarget = 0
+ player.movement.action(player, 26)
+ server.mutex.Unlock()
+ return client.send(characterActionPacket(player.id, [5]uint32{162}))
+}
+
+func (server *server) leaveSneak_locked(player *character, now time.Time, updates map[*worldClient][][]byte) {
+ if player.movement.components[0] != 6 {
+ return
+ }
+ player.anchorMovement_locked(now)
+ player.movement.action(player, 32)
+ // The correction bit also applies the transition to the controlled owner.
+ server.queueCombat_locked(updates, player, player, npcMovementPacket(player, 0xa0))
+}
+
+func (player *character) features(now time.Time) uint32 {
+ features := uint32(6)
+ if player.canChangeImplants(now) {
+ features |= 16
+ }
+ if player.movement.components[0] == 6 {
+ features |= 128
+ }
+ return features
+}
diff --git a/server/player_sneak_test.go b/server/player_sneak_test.go
@@ -0,0 +1,156 @@
+package main
+
+import (
+ "encoding/binary"
+ "testing"
+ "time"
+)
+
+func TestSneakRequiresApprovalAndPreservesMovementPreference(t *testing.T) {
+ for _, running := range []bool{false, true} {
+ world, output := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ player.running = running
+ if err := world.handleMovement(client, playerMovementRequest(player, 26)); err != nil {
+ t.Fatal(err)
+ }
+ if player.movement.components[0] == 6 {
+ t.Fatal("unsolicited movement entered sneak")
+ }
+
+ if err := world.handleSneak(client, characterActionPacket(1, [5]uint32{163})[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if player.movement.components[0] != 6 || player.running != running || player.features(time.Now()) != 134 || len(output.packets) != 1 || binary.BigEndian.Uint32(output.packets[0][29:33]) != 162 {
+ t.Fatal("missing approval or sneak feature", player.movement.components, len(output.packets))
+ }
+ if err := world.handleMovement(client, playerMovementRequest(player, 26)); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleMovement(client, playerMovementRequest(player, 1)); err != nil {
+ t.Fatal(err)
+ }
+ if player.movement.components[0] != 6 || player.movement.forward != 1 {
+ t.Fatal("walking lost sneak")
+ }
+ if err := world.handleMovement(client, playerMovementRequest(player, 32)); err != nil {
+ t.Fatal(err)
+ }
+ expected := byte(2)
+ if running {
+ expected = 3
+ }
+ if player.movement.components[0] != expected || player.features(time.Now()) != 6 {
+ t.Fatal("exit lost preferred movement")
+ }
+ }
+}
+
+func TestSneakRejectsUnavailablePlayerStates(t *testing.T) {
+ for _, scenario := range []string{"fighting", "attacked", "seated", "swimming", "flying", "dead", "unready", "owner", "casting", "equipping", "reload"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, output := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ request := characterActionPacket(1, [5]uint32{163})[20:]
+ switch scenario {
+ case "fighting":
+ player.fighting = 2
+ case "attacked":
+ world.fighting = map[uint32]*character{2: {id: 2, fighting: 1}}
+ case "seated":
+ player.sitting = true
+ case "swimming":
+ player.movement.components[0] = 4
+ case "flying":
+ player.movement.components[0] = 7
+ case "dead":
+ player.health = 0
+ case "unready":
+ client.ready = false
+ case "owner":
+ binary.BigEndian.PutUint32(request[8:], 2)
+ case "casting":
+ client.nanoCast = &nanoCast{}
+ case "equipping":
+ client.equipment = &equipmentMove{}
+ case "reload":
+ client.reloadUntil = time.Now().Add(time.Minute)
+ }
+
+ err := world.handleSneak(client, request)
+
+ if err != nil || player.movement.components[0] == 6 || len(output.packets) != 0 {
+ t.Fatal("unavailable player entered sneak", err)
+ }
+ })
+ }
+}
+
+func TestSneakEndsWhenAnAttackOrCastStarts(t *testing.T) {
+ for _, action := range []string{"attack", "cast"} {
+ t.Run(action, func(t *testing.T) {
+ world, output := newNanoCastingWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: player.playfield, health: 100}
+ world.clients[2] = &worldClient{id: 2, conn: observer, ready: true, target: true, npcs: map[uint32]bool{1000000: true}}
+ if err := world.handleSneak(client, characterActionPacket(1, [5]uint32{163})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ output.packets = nil
+
+ var err error
+ if action == "attack" {
+ err = world.handleCombat(client, attackPacket(1, 1000000)[20:])
+ } else {
+ err = world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1000000, 53019, 29618})[20:])
+ }
+
+ if err != nil || player.movement.components[0] == 6 {
+ t.Fatal("action did not end sneak", err)
+ }
+ for _, packets := range [][][]byte{output.packets, observer.packets} {
+ if len(packets) == 0 || binary.BigEndian.Uint32(packets[0][16:20]) != 0x54111123 || packets[0][29] != 0xa0 {
+ t.Fatal("owner or observer missed reveal before action")
+ }
+ }
+ })
+ }
+}
+
+func TestSneakSurvivesClinicPermissionExpiry(t *testing.T) {
+ for _, stationary := range []bool{false, true} {
+ world, output := newStationaryClinicWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ finish := time.Now().Add(time.Minute)
+ if stationary {
+ if err := world.handleTerminalUse(client, stationaryClinicUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ finish = player.activeNanos[0].expiresAt
+ } else {
+ player.implantChangesUntil = finish
+ }
+ if err := world.handleSneak(client, characterActionPacket(1, [5]uint32{163})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ output.packets = nil
+
+ if stationary {
+ world.advanceNanos(finish)
+ } else {
+ world.advanceItemEffects(finish)
+ }
+
+ found := false
+ for _, packet := range output.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x2b333d6e && binary.BigEndian.Uint32(packet[29:33]) == 224 {
+ found = binary.BigEndian.Uint32(packet[33:37]) == 134
+ }
+ }
+ if !found || player.movement.components[0] != 6 {
+ t.Fatal("clinic expiry erased sneak feature")
+ }
+ }
+}
diff --git a/server/weapon_special.go b/server/weapon_special.go
@@ -10,6 +10,11 @@ import (
func (player *character) weaponSpecialLockSeconds(weapon *gamedata.Item, skill uint32) uint32 {
value, _ := player.effectiveStat(skill)
+ if skill == 151 {
+ // Client recharge helper, adopted provisionally; see docs/aimed-shot.md.
+ centiseconds := int64(itemStat(weapon, 210))*40 - int64(value)*3
+ return uint32((max(1000, centiseconds) + 99) / 100)
+ }
if skill == 148 {
// kkr.dll 100ab060: recharge * 20 + BurstCycle - Burst * 4, floor 800cs.
// Using the client helper for server timing is provisional; see docs/burst.md.
@@ -34,7 +39,7 @@ func (server *server) handleWeaponSpecial(client *worldClient, body []byte) erro
implicit := skill == 142 || skill == 144
if server.clients[client.id] != client || !client.target || !client.ready || client.loading || player.health == 0 ||
binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id ||
- binary.BigEndian.Uint32(body[16:20]) != 50000 || (!implicit && skill != 147 && skill != 148 && skill != 150) {
+ binary.BigEndian.Uint32(body[16:20]) != 50000 || (!implicit && skill != 147 && skill != 148 && skill != 150 && skill != 151) {
server.mutex.Unlock()
return nil
}
@@ -47,6 +52,14 @@ func (server *server) handleWeaponSpecial(client *worldClient, body []byte) erro
server.mutex.Unlock()
return nil
}
+ if skill == 151 {
+ // PvE opening-shot policy; exact historical detection rolls remain deferred.
+ concealment, _ := player.effectiveStat(164)
+ if player.movement.components[0] != 6 || player.fighting != 0 || target.fighting != 0 || len(target.threat) != 0 || concealment < target.combatSkill(136) {
+ server.mutex.Unlock()
+ return nil
+ }
+ }
// WeaponItem 100aaf10 supplies each special's held-weapon capability.
capability := uint32(1 << 12)
if skill == 142 {
@@ -57,6 +70,8 @@ func (server *server) handleWeaponSpecial(client *worldClient, body []byte) erro
capability = 1 << 18
} else if skill == 148 {
capability = 1 << 11
+ } else if skill == 151 {
+ capability = 1 << 14
}
var item *ownedItem
for index := range player.inventory.Items {
@@ -116,6 +131,17 @@ func (server *server) handleWeaponSpecial(client *worldClient, body []byte) erro
critical := int64(roll(100)) < chance
damage = min(target.health, player.itemDamage(target, weapon, critical, roll))
}
+ } else if skill == 151 {
+ // Maximum weapon hit and skill multiplier are explicit alpha balance rules.
+ roll := server.combatRoll
+ if roll == nil {
+ roll = rand.Uint32N
+ }
+ chance := min(100, max(0, int64(3)+int64(player.equipmentBonus(379))+int64(player.nanoBonus(379))))
+ critical := int64(roll(100)) < chance
+ value, _ := player.effectiveStat(151)
+ multiplier := 1 + roll(uint32(max(1, value/100)))
+ damage = min(10000, target.health, player.weaponDamage(target, critical, func(limit uint32) uint32 { return limit - 1 })*multiplier)
} else if skill == 148 {
// Three independent noncritical hits; no later defensive checks or ammo debit.
roll := server.combatRoll
@@ -140,8 +166,12 @@ func (server *server) handleWeaponSpecial(client *worldClient, body []byte) erro
previous := *target
*target = candidate
updates := make(map[*worldClient][][]byte)
+ server.leaveSneak_locked(player, now, updates)
+ if skill == 151 && target.health != 0 {
+ server.startAttack_locked(player, target, now, updates)
+ }
// Native 10078a40 uses the current fight target and checks the skill lock.
- // Idle startup remains open; do not leave a special queued for a later fight.
+ // Only a matching fight receives animation; never queue a later fight's special.
if player.fighting == target.id {
server.queueCombat_locked(updates, player, target, n3Packet(0x51492120, 50000, player.id, body[16:28]))
}
diff --git a/server/world.go b/server/world.go
@@ -271,9 +271,9 @@ func fullCharacterPacket(character *character) []byte {
[2]uint32{47, uint32(character.appearance >> 2 & 3)},
[2]uint32{360, uint32(scale)},
[2]uint32{214, character.nano}, [2]uint32{221, character.maximumNano() - uint32(character.inventory.equipmentBonus(221))})
- if character.canChangeImplants(time.Now()) {
- // Surgery access supplements the native base Features value of 6.
- stats = append(stats, [2]uint32{224, 6 | 16})
+ if features := character.features(time.Now()); features != 6 {
+ // Surgery and sneak supplement the native base Features value of 6.
+ stats = append(stats, [2]uint32{224, features})
}
body = binary.BigEndian.AppendUint32(body, uint32(len(stats)+1)*1009)
for _, stat := range stats {
diff --git a/server/world_actions.go b/server/world_actions.go
@@ -151,7 +151,7 @@ func (server *server) handleMovement(client *worldClient, body []byte) error {
// Native receivers also execute internal equipment events such as 27/35.
action := binary.BigEndian.Uint32(body[16:20])
switch action {
- case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 22, 23:
+ case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 26, 32:
default:
return nil
}
@@ -162,6 +162,11 @@ func (server *server) handleMovement(client *worldClient, body []byte) error {
server.mutex.Unlock()
return nil
}
+ // Entry needs a prior163 approval; exit is meaningful only while sneaking.
+ if (action == 26 || action == 32) && character.movement.components[0] != 6 {
+ server.mutex.Unlock()
+ return nil
+ }
previousPosition := character.position
now := time.Now()
character.anchorMovement_locked(now)
diff --git a/tools/client/test_aimed_shot.mjs b/tools/client/test_aimed_shot.mjs
@@ -0,0 +1,72 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs/promises';
+import {createRequire} from 'node:module';
+import {GameTest} from './game_test.mjs';
+
+const {chromium} = createRequire(import.meta.url)('playwright');
+const [url, output] = process.argv.slice(2);
+const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [
+ '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
+ '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
+let game;
+const evidence = {};
+try {
+ const context = await browser.newContext({viewport: {width: 1024, height: 768}});
+ await context.addCookies([{name: 'ao_client', value: 'aimed_shot', url}]);
+ const page = await context.newPage();
+ game = await GameTest.attach(page);
+ const server = async () => (await page.request.get(url + '/test-state')).json();
+ const waitServer = (label, predicate) => game.waitFor(label, async () => predicate(await server()));
+ const checkNative = async health => game.wait('native Aimed Shot HP agrees', state =>
+ state.actors.find(actor => actor.type === 50000 && actor.id === evidence.initial.target)?.stats[27] === health);
+ await page.goto(url);
+ await game.ready();
+ if (!game.state.camera.firstPerson) await game.key('F8');
+ await game.key('KeyI');
+ evidence.initial = await server();
+ const cell = game.state.grids.flatMap(grid => grid.cells).find(cell => cell.identity[0] === 104 && cell.identity[1] === 51 && !cell.dummy);
+ assert(cell, 'issued or stocked rifle is visible');
+ await game.click((cell.bounds[0]+cell.bounds[2])/2, (cell.bounds[1]+cell.bounds[3])/2, 'right');
+ await waitServer('rifle equipped normally', state => state.inventory.Items.some(item => item.ID === 4 && item.Slot === 6));
+ await game.wait('native equipped weapon ready', state => game.local(state).weapons.some(weapon => weapon.slot === 6));
+ evidence.equipped = await server();
+ await page.keyboard.press('Control+2');
+ await game.wait('native command grid opens', state => state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 57008 && cell.identity[1] === 49575 && !cell.dummy)));
+ await game.save(output + '/commands');
+ const sneak = game.state.grids.flatMap(grid => grid.cells).find(cell => cell.identity[0] === 57008 && cell.identity[1] === 49575 && !cell.dummy);
+ assert(sneak, 'native Sneak command is visible');
+ await game.click((sneak.bounds[0]+sneak.bounds[2])/2, (sneak.bounds[1]+sneak.bounds[3])/2, 'right');
+ await waitServer('server approves concealment', state => state.sneaking);
+ await game.wait('native sneak feature set', state => (game.local(state).stats[224] & 128) !== 0);
+ evidence.sneaking = await server();
+ await game.save(output + '/sneaking');
+ await game.key('Tab');
+ await game.wait('original Leet selected', state => state.selected[0] === 50000 && state.selected[1] === evidence.initial.target);
+ await game.key('KeyO');
+ await waitServer('opening shot damage and lock committed', state => state.health === 1000-state.damage && state.locked && !state.sneaking && state.fighting === state.target);
+ await checkNative(1000-evidence.initial.damage);
+ await game.wait('native sneak feature cleared', state => (game.local(state).stats[224] & 128) === 0);
+ evidence.first = await server();
+ assert(evidence.first.remaining > 25 && evidence.first.remaining <= 52);
+ assert.deepEqual(evidence.first.inventory, evidence.equipped.inventory);
+ await game.save(output + '/first');
+
+ await game.key('KeyO');
+ assert.equal((await server()).health, evidence.first.health);
+ await page.reload();
+ await game.ready();
+ evidence.reconnected = await server();
+ assert(evidence.reconnected.locked && !evidence.reconnected.sneaking);
+ assert.equal(evidence.reconnected.health, evidence.first.health);
+ assert.deepEqual(evidence.reconnected.inventory, evidence.first.inventory);
+ await checkNative(evidence.first.health);
+ await game.save(output + '/reconnected');
+ assert.deepEqual(game.errors, []);
+ console.log('PASS:', evidence.initial.weapon, 'native sneak, opening Aimed Shot, reveal, cooldown, unchanged inventory and reconnect');
+} finally {
+ try {
+ await fs.mkdir(output, {recursive: true});
+ await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
+ if (game) await game.save(output + '/final');
+ } finally { await browser.close(); }
+}