aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit ff73d4ae361cd95a1371cd77a806ffe1b31eb75b
parent 4293a14a4a7b9136fd9f0466f20b9a7acdbf026b
Author: anon <anon@example.com>
Date:   Thu, 22 Oct 2026 21:38:28 +0000

Support the authored Kodaik ground vehicle effects

Diffstat:
MTODO.md | 11++++++++++-
Adocs/vehicles.md | 156+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/combat.go | 10+++++++---
Mserver/equipment.go | 25+++++++++++++++++++++----
Mserver/gamedata/playfields.yaml | 186+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/gamedata/types.go | 1+
Mserver/inventory.go | 4++--
Mserver/stats.go | 3++-
Mserver/target_protocol.go | 2+-
Mserver/target_protocol_test.go | 2+-
Aserver/vehicle.go | 14++++++++++++++
Aserver/vehicle_test.go | 272+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/world.go | 1+
Mserver/zoning.go | 10++++++++--
Atools/data/extract_vehicle.py | 47+++++++++++++++++++++++++++++++++++++++++++++++
15 files changed, 729 insertions(+), 15 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -342,8 +342,10 @@ checks are recorded in [treatment kits](docs/treatment-kit.md). and the native client arrives in the correct playfield. - [x] Leave the Grid through one exit. Check: the exit's requirements and destination are correct and the character remains usable after reconnect. -- [ ] Use one ground vehicle. Check: equipping/using it changes movement speed +- [x] Use one ground vehicle. Check: equipping/using it changes movement speed under the applicable requirements and ending use restores ordinary movement. +- [ ] Restore the Kodaik's shipped materials in the WASM client. Check: its two + textured surfaces render for the driver and observer after equip and reconnect. - [ ] Use one flying vehicle. Check: altitude and movement modes replicate to an observer and zoning does not leave the character stuck in the wrong mode. - [x] Resolve one currently unmapped door. Check: source evidence identifies its @@ -360,6 +362,13 @@ Grid form, restart persistence, exit and usable reconnect. Authored records and the provisional exit envelope are in [the Borealis Grid route](docs/zoning.md#1491-borealis-grid-route). +QL 15 Kodaik Turbo IX supports HUD1 equip/removal, skill and outdoor checks, +native model/scale/fighting effects, and sourced movement changes. Two WASM +clients verified restart and removal without duplicated bonuses. Its body +currently renders white despite the shipped metal/glass textures; the remaining +renderer diagnosis and indoor playshift uncertainty are recorded in +[ground vehicles](docs/vehicles.md). + ## Pets - [ ] Summon one pet. Check: one owned entity appears to its owner and an diff --git a/docs/vehicles.md b/docs/vehicles.md @@ -0,0 +1,156 @@ +# Kodaik ground vehicle in 14.9.1 + +The supported vehicle is the exact QL 15 Kodaik Turbo IX, template 117294, +native item type 51022. Its owned identity remains stable when moving between +ordinary inventory and HUD1 (slot 1, equipment page 101). Acquisition can use +the existing test fixture grant; no vehicle provisioning interface is added. +Other qualities and vehicles are not inferred from this endpoint. + +## Authored requirements and effects + +Resource 1000020/117294, in `server/gamedata/items/items_035.yaml`, has slot +mask 298 equal to 2 and default slot 88 equal to 1: HUD1 only. EquipDelay 211 +is 1000 centiseconds, giving a ten-second delay. Its Wear action 8 requires +all of the following: + +- PlayfieldType 438 equal to 1, ground/outdoors. +- Effective VehicleGround 166 strictly greater than 80, meaning at least 81. +- InBattle 410 equal to zero. +- Form 359 equal to zero. + +VehicleGround is a persisted trained skill. Resource 1000204/166 gives ability +weights `[0,20,0,20,60,0]` in STR/AGI/STA/INT/SEN/PSY order. Abilities of 10 +add two points, so trained 78 fails and trained 79 qualifies. Its native starting +value is 5 (`kkr.dll 0x100729fa`, default array offset 166*4). Equip eligibility +is checked before scheduling and again at completion. Existing combat policy +rejects outgoing and incoming fights; the original producer of stat 410 is +still unresolved. Removal does not recheck the equip skill, and a full ordinary +inventory cannot lose the worn item or its effects. + +The unconditional OnWear event 14 executes these functions in authored order: + +| Function | Arguments | Effect | +| --- | --- | --- | +| Modify 53045 | 156, 150 | Add 150 Run Speed. | +| ChangeShape 53060 | 99468, 0 | Set Form 359 to vehicle model 99468 and rebuild appearance. | +| RestrictAction 53068 | 2, 0 | Clear Fighting feature bit 2; restore it on removal. | +| ChangeStat 53110 | 360, 20 | Save the original base Scale and set 20; restore it on removal. | + +Native removal invokes the same event with its removal flag, subtracting the +speed modifier, clearing the matching shape, restoring the fighting feature, +and restoring the saved scale. The ordinary radius 421 is 2; native physical +extent is `Scale * radius * 0.01`, giving 0.4 while driving and 2 afterward. +The server rejects forged attack requests while the vehicle is equipped. + +Existing TemplateAction `0x35505644` action 6/7, page 101 and slot 1 applies +and removes the effects for both the owner and same-playfield observers. +Owner FullCharacter initialization already applies worn effects once, so it +must retain raw base RunSpeed 100 and avoid another owner wear replay. +Observers receive one wear effect after the corresponding actor is created. +No separate model, feature or scale stat packet is combined with OnWear. + +## Movement and outdoor metadata + +The native 14.9.1 movement getter uses RunSpeed mode 3: raw base plus modifiers, +excluding ability trickle-down. With current base 100, the vehicle raises this +to 250. Healthy, unencumbered running speeds are: + +| Movement | Human | Vehicle | +| --- | --- | --- | +| Forward, `4 + RunSpeed * 0.005` | 4.5 m/s | 5.25 m/s | +| Backward, `3 + RunSpeed * 0.0035` | 3.35 m/s | 3.875 m/s | +| Walking mode | 1.5 m/s | 1.5 m/s | + +The running helpers cap their result at 15 m/s, with a final minimum of 0.1. +Below 15 percent maximum HP they first replace RunSpeed with +`(RunSpeed + 500) * HP / (MaxHP * 0.15) - 500`. Scale changes body extent; +it is not a movement-speed multiplier. The server's bounded movement estimate +uses these values and anchors held movement when equip/removal changes speed, +so the new speed is not applied retroactively to earlier motion. Acceleration, +braking, collision surfaces and encumbrance remain outside that estimate. + +Outdoor metadata comes from the exact native tilemap classification. +`kkr.dll 0x1006e8c0` writes stat 438 from `n3Playfield::IsGround` or `IsDungeon`. +The `bbr.dll` tilemap reader at `0x100a3dd0` classifies original resource +1000009 magic CHGA as ground, GNDA/UOHA as dungeon. The maintained playfield +catalog now marks the 186 existing catalog identities whose selected-client +records are CHGA. The extractor retains all 188 CHGA identities, including +two absent from the maintained catalog. Terrain-height availability is not +used as an outdoor heuristic. + +## Evidence and remaining limits + +Run `python3 tools/data/extract_vehicle.py` to produce +`local/reports/vehicle-14.9.1.json`. It retains the complete selected item, +payload digest, skill weights and ground-record digests; review its ground +identities against the `outdoor` entries in `server/gamedata/playfields.yaml`. +The item payload SHA-256 is +`397932a778f03656d0b3ab143fb1bd935a8fb77bbd040d8a359e0d8c7c8edd75`; +index SHA-256 is +`46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`. +The [Auno pre-Shadowlands 14.8.1 catalog](https://auno.org/ao/db.php?id=117294&patch=14080100) +corroborates the item labels and values. The selected 14.9.1 bytes take +precedence over later descriptions or interpolated qualities. + +`local/vehicle-smoke/native-source-audit.json` retains original bytes and 43 +source procedures. Effects are in `client/game/kkr.dll/lifted-0057.c`, +movement in `lifted-0023.c`, outdoor assignment in `lifted-0033.c`, and the +tilemap reader in `client/game/bbr.dll/lifted-0036.c`. Addresses refer to the +original DLL bases, not generated relocations. Shipped DLL SHA-256 values: + +- kkr.dll: `a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`. +- bbr.dll: `28f196f650edbb1573fb874ccaf7746453d3e4a183e1d86db1d790c1c32ecc2c`. +- llr.dll: `ebb09047f6ead192388f7ddfb4795da5013a60f7c2d1c3933ec02eef58a10132`. + +The separate Playshift action 136 requires only outdoor type 1 and Form 0; +it does not include VehicleGround or combat checks. The native evaluator is +verified, but the original server's indoor zoning policy is not: automatic +unequip, effect suppression and full-inventory fallback remain unresolved. +This implementation verifies outdoor equip/removal and same-playfield +reconnect; it does not claim canonical indoor vehicle lifecycle handling. +Historical source boundaries are retained in +`local/vehicle-smoke/source-ledger.json` and `indoor-followup.json`. + +## Verification + +`TestGroundVehicle*` checks native HUD1 decoding, the ten-second deadline, +80/81 skill boundary, inventory ownership/pages, stale/dead/loading/unready +sessions, outdoor eligibility, outgoing/incoming combat, and requirement +changes during the delay. It checks persistent removal after losing skill, +full-inventory rejection, fighting restoration, observer effects, movement +anchoring, healthy forward/backward/walking speeds, and the low-health path. +The native initialization-layout expectation includes the additional base +VehicleGround stat. + +Two WASM clients verified native rejection at effective VehicleGround 80 and +HUD1 equip at 81. The initial manual attempt exposed the missing HUD1 exception +in `decodeInventory1491`; the public inventory regression reproduced it before +the decoder fix. After ten seconds the driver and observer both had native +model 99468, Features 4, Scale 20 and extent 0.4. Read-only guest-memory probes +confirmed configured maximum speed 5.25 while holding forward and 3.875 while +holding backward, alongside real position changes. A server restart and page +reload retained the owned HUD1 item, form and single speed bonus. + +Native click-pick/drop from HUD1 into ordinary inventory removed the vehicle +after its delay. Both clients restored Form 0, Features 6, Scale 100 and extent +2; a held-forward probe returned 4.5 m/s. Another page reload retained the item +in ordinary inventory and the human state. Health, credits and the observer's +inventory remained unchanged. The isolated fixture, screenshots, packets, +read-only probes and 24 checks are retained in +`local/vehicle-smoke/verification.json`. All temporary clients and the server +were closed before the full test runs. + +The vehicle renders as a bright-white body in these WASM captures. This does +not match the shipped material art: mesh 99458, resource 1010002, references +Material #2b / `light_sportscraft1b.png` (30043) and Material #2a / +`light_sportscraft1a.png` (30044). The extracted 256x256 RGB textures show metal, +glass and engine details. The item has no missing authored texture effect. +The port implements normal normalization, but its reached state for the car +has not been captured. `local/vehicle-smoke/material-source-audit.json` retains +the CIR and texture provenance. The remaining renderer task needs the car +draw's bound textures, material/lighting values and normalization flag; the +current evidence does not justify a speculative graphics fix. + +The maintained full server suite passed in 119.538 seconds. Five race-enabled +passes over the ground vehicle, shared equipment publication, whom-pah and +Grid return paths passed in 96.863 seconds. diff --git a/server/combat.go b/server/combat.go @@ -51,7 +51,7 @@ func (server *server) handleCombat(client *worldClient, body []byte) error { // Only visible creatures participate in this initial unarmed PvE loop. target := server.characters[binary.BigEndian.Uint32(body[20:24])] now := time.Now() - if binary.BigEndian.Uint32(body[16:20]) == 50000 && target != nil && target.npc && + if !player.driving() && binary.BigEndian.Uint32(body[16:20]) == 50000 && target != nil && target.npc && target.appearance>>4&7 == 6 && client.npcs[target.id] && target.health > 0 && target.playfield == player.playfield && server.combatInRange_locked(player, target, now) { server.startAttack_locked(player, target, now, updates) @@ -177,14 +177,18 @@ func (attacker *character) normalDamage(target *character, roll func(uint32) uin } func (character *character) physicalExtent() float32 { - // FUN_1005a790 scales CharRadius421. Published actors currently use Scale360=100. + // FUN_1005a790 scales CharRadius421 by Scale360; Kodaik OnWear sets it to 20. + scale := uint32(100) + if character.driving() { + scale = 20 + } radius := uint32(2) if monster, exists := gamedata.MonsterTemplates[character.monsterData]; exists { if value, exists := monster.Stats[421]; exists { radius = value } } - return float32(int32(100*radius)) * float32(0.01) + return float32(int32(scale*radius)) * float32(0.01) } func (server *server) combatInRange_locked(attacker, target *character, now time.Time) bool { diff --git a/server/equipment.go b/server/equipment.go @@ -21,6 +21,9 @@ func (item ownedItem) isKineticAxe() bool { } func (item ownedItem) fitsEquipmentSlot(slot uint32) bool { + if item.isKodaik() { + return slot == 1 + } if item.isKineticAxe() { return slot == 6 } @@ -45,6 +48,11 @@ func (item ownedItem) fitsEquipmentSlot(slot uint32) bool { } func (character *character) canEquip(item ownedItem) bool { + if item.isKodaik() { + stats := character.baseStats() + return gamedata.Playfields[character.playfield].Outdoor && !character.driving() && + stats.effectiveSkill(stats.VehicleGround, [6]uint32{0, 20, 0, 20, 60, 0}) > 80 + } if item.fitsEquipmentSlot(7) || item.fitsEquipmentSlot(9) { stats := character.baseStats() return stats.effectiveSkill(stats.ComputerLiteracy, [6]uint32{0, 0, 0, 100, 0, 0}) > 5 @@ -134,7 +142,7 @@ func (character *character) canWieldKineticAxe() bool { func itemMovePacket(owner, source, destination uint32) []byte { page := uint32(104) - if source == 6 || source == 7 || source >= 9 && source <= 14 { + if source == 1 || source == 6 || source == 7 || source >= 9 && source <= 14 { page = 101 } else if source == 21 || source == 30 { page = 102 @@ -215,6 +223,10 @@ func (server *server) advanceEquipment(now time.Time) { } // Save the entire move before publishing inventory or appearance changes. + position := character.position + if move.source == 1 || move.destination == 1 { + position = predictedPosition_locked(character, client, now) + } item := character.inventory.Items[index] inventory := character.inventory inventory.Items = slices.Clone(character.inventory.Items) @@ -224,7 +236,12 @@ func (server *server) advanceEquipment(now time.Time) { updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.source)) continue } - if move.source == 7 || move.source >= 9 && move.source <= 14 || move.source == 21 || move.source == 30 || move.source == 37 { + if move.source == 1 || move.destination == 1 { + // Anchor held movement at the speed before the vehicle effect changed. + character.position = position + client.movementStarted = now + } + if move.source == 1 || move.source == 7 || move.source >= 9 && move.source <= 14 || move.source == 21 || move.source == 30 || move.source == 37 { server.queueCombat_locked(updates, character, character, equipmentActionPacket(character.id, item, 7)) } if move.source == 6 { @@ -236,7 +253,7 @@ func (server *server) advanceEquipment(now time.Time) { } } updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.requestedSlot)) - if move.destination == 7 || move.destination >= 9 && move.destination <= 14 || move.destination == 21 || move.destination == 30 || move.destination == 37 { + if move.destination == 1 || move.destination == 7 || move.destination >= 9 && move.destination <= 14 || move.destination == 21 || move.destination == 30 || move.destination == 37 { server.queueCombat_locked(updates, character, character, equipmentActionPacket(character.id, character.inventory.Items[index], 6)) } if move.source == 6 || move.destination == 6 { @@ -293,7 +310,7 @@ func equipmentActionPacket(owner uint32, item ownedItem, action uint32) []byte { func equippedItemPackets(character *character) [][]byte { packets := equippedWeaponPackets(character) for _, item := range character.inventory.Items { - if item.Slot == 7 || item.Slot >= 9 && item.Slot <= 14 || item.Slot == 21 || item.Slot == 30 || item.Slot == 37 { + if item.Slot == 1 || item.Slot == 7 || item.Slot >= 9 && item.Slot <= 14 || item.Slot == 21 || item.Slot == 30 || item.Slot == 37 { packets = append(packets, equipmentActionPacket(character.id, item, 6)) } } diff --git a/server/gamedata/playfields.yaml b/server/gamedata/playfields.yaml @@ -1,5 +1,6 @@ 100: name: Needed PF-stuff + outdoor: true origin: [0, 0] spawn: [0, 0, 0] unavailable: true @@ -40,6 +41,7 @@ unavailable: false 102: name: Monster and NPC dependencies + outdoor: true origin: [0, 0] spawn: [0, 0, 0] unavailable: true @@ -50,6 +52,7 @@ unavailable: false 103: name: Shop and Item Dependencies + outdoor: true origin: [0, 0] spawn: [0, 0, 0] unavailable: true @@ -265,6 +268,7 @@ unavailable: false 1410: name: items + outdoor: true origin: [0, 0] spawn: [0, 0, 0] unavailable: true @@ -850,651 +854,781 @@ unavailable: false 3000: name: Omni-1 Entertainment Backyard 1 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3001: name: Omni-1 Entertainment Backyard 2 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3002: name: Omni-1 Entertainment Backyard 3 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3003: name: Omni-1 Entertainment Backyard 4 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3004: name: Omni-1 Entertainment Backyard 5 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3005: name: Omni-1 Entertainment Backyard 6 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3006: name: Omni-1 Entertainment Backyard 7 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3007: name: Omni-1 Entertainment Backyard 8 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3008: name: Omni-1 Entertainment Backyard 9 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3009: name: Omni-1 Entertainment Backyard 10 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3010: name: Omni-1 Entertainment Backyard 11 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3011: name: Omni-1 Entertainment Backyard 12 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3012: name: Omni-1 Entertainment Backyard 13 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3013: name: Omni-1 Entertainment Backyard 14 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3014: name: Omni-1 Entertainment Backyard 15 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3015: name: Omni-1 Entertainment Backyard 16 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3016: name: Omni-1 Entertainment Backyard 17 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3017: name: Omni-1 Entertainment Backyard 18 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3018: name: Omni-1 Entertainment Backyard 19 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3019: name: Omni-1 Entertainment Backyard 20 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3020: name: Omni-1 Trade Backyard 1 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3021: name: Omni-1 Trade Backyard 2 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3022: name: Omni-1 Trade Backyard 3 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3023: name: Omni-1 Trade Backyard 4 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3024: name: Omni-1 Trade Backyard 5 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3025: name: Omni-1 Trade Backyard 6 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3026: name: Omni-1 Trade Backyard 7 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3027: name: Omni-1 Trade Backyard 8 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3028: name: Omni-1 Trade Backyard 9 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3029: name: Omni-1 Trade Backyard 10 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3030: name: Omni-1 Trade Backyard 11 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3031: name: Omni-1 Trade Backyard 12 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3032: name: Omni-1 Trade Backyard 13 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3033: name: Omni-1 Trade Backyard 14 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3034: name: Omni-1 Trade Backyard 15 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3035: name: Omni-1 Trade Backyard 16 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3036: name: Omni-1 Trade Backyard 17 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3037: name: Omni-1 Trade Backyard 18 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3038: name: Omni-1 Trade Backyard 19 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3039: name: Omni-1 Trade Backyard 20 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3040: name: Rome Blue Backyard 1 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3041: name: Rome Blue Backyard 2 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3042: name: Rome Blue Backyard 3 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3043: name: Rome Blue Backyard 4 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3044: name: Rome Blue Backyard 5 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3045: name: Rome Blue Backyard 6 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3046: name: Rome Blue Backyard 7 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3047: name: Rome Blue Backyard 8 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3048: name: Rome Blue Backyard 9 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3049: name: Rome Blue Backyard 10 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3050: name: Rome Green Backyard 1 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3051: name: Rome Green Backyard 2 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3052: name: Rome Green Backyard 3 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3053: name: Rome Green Backyard 4 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3054: name: Rome Green Backyard 5 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3055: name: Rome Green Backyard 6 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3056: name: Rome Green Backyard 7 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3057: name: Rome Green Backyard 8 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3058: name: Rome Green Backyard 9 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3059: name: Rome Green Backyard 10 + outdoor: true origin: [0, 0] spawn: [100, 115.5, 120] unavailable: false 3060: name: Newland Backyard 1 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3061: name: Newland Backyard 2 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3062: name: Newland Backyard 3 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3063: name: Newland Backyard 4 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3064: name: Newland Backyard 5 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3065: name: Newland Backyard 6 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3066: name: Newland Backyard 7 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3067: name: Newland Backyard 8 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3068: name: Newland Backyard 9 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3069: name: Newland Backyard 10 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3070: name: Newland Backyard 11 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3071: name: Newland Backyard 12 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3080: name: Borealis Backyard 1 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3081: name: Borealis Backyard 2 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3082: name: Borealis Backyard 3 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3083: name: Borealis Backyard 4 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3084: name: Borealis Backyard 5 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3085: name: Borealis Backyard 6 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3086: name: Borealis Backyard 7 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3087: name: Borealis Backyard 8 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3088: name: Borealis Backyard 9 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3089: name: Borealis Backyard 10 + outdoor: true origin: [0, 0] spawn: [100, 39.5, 100] unavailable: false 3100: name: Tir Backyard 1 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3101: name: Tir Backyard 2 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3102: name: Tir Backyard 3 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3103: name: Tir Backyard 4 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3104: name: Tir Backyard 5 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3105: name: Tir Backyard 6 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3106: name: Tir Backyard 7 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3107: name: Tir Backyard 8 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3108: name: Tir Backyard 9 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3109: name: Tir Backyard 10 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3110: name: Tir Backyard 11 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3111: name: Tir Backyard 12 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3112: name: Tir Backyard 13 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3113: name: Tir Backyard 14 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3114: name: Tir Backyard 15 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3115: name: Tir Backyard 16 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3116: name: Tir Backyard 17 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3117: name: Tir Backyard 18 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3120: name: Old Athen Backyard 1 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3121: name: Old Athen Backyard 2 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3122: name: Old Athen Backyard 3 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3123: name: Old Athen Backyard 4 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3124: name: Old Athen Backyard 5 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3125: name: Old Athen Backyard 6 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3126: name: Old Athen Backyard 7 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3127: name: Old Athen Backyard 8 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3128: name: Old Athen Backyard 9 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3129: name: Old Athen Backyard 10 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3130: name: Old Athen Backyard 11 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3131: name: Old Athen Backyard 12 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3132: name: Old Athen Backyard 13 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3133: name: Old Athen Backyard 14 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3134: name: Old Athen Backyard 15 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3135: name: Old Athen Backyard 16 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3136: name: Old Athen Backyard 17 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3137: name: Old Athen Backyard 18 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3138: name: Old Athen Backyard 19 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3139: name: Old Athen Backyard 20 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3140: name: West Athen Backyard 1 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3141: name: West Athen Backyard 2 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3142: name: West Athen Backyard 3 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3143: name: West Athen Backyard 4 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3144: name: West Athen Backyard 5 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3145: name: West Athen Backyard 6 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3146: name: West Athen Backyard 7 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3147: name: West Athen Backyard 8 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3148: name: West Athen Backyard 9 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false 3149: name: West Athen Backyard 10 + outdoor: true origin: [0, 0] spawn: [80, 25.5, 80] unavailable: false @@ -1570,11 +1704,13 @@ unavailable: false 500: name: Parnassos + outdoor: true origin: [0, 0] spawn: [300, 0.5, 240] unavailable: false 505: name: Avalon + outdoor: true origin: [0, 0] spawn: [1720, 11.5, 2320] unavailable: false @@ -1610,21 +1746,25 @@ unavailable: true 540: name: Old Athen + outdoor: true origin: [0, 0] spawn: [400, 14.5, 400] unavailable: false 545: name: West Athens + outdoor: true origin: [0, 0] spawn: [400, 5.7, 400] unavailable: false 550: name: Athen Shire + outdoor: true origin: [0, 0] spawn: [1520, 48.3, 1200] unavailable: false 551: name: Wailing Wastes + outdoor: true origin: [0, 0] spawn: [1520, 27.9, 2000] unavailable: false @@ -1635,26 +1775,31 @@ unavailable: true 560: name: Mort + outdoor: true origin: [0, 0] spawn: [1960, 36.3, 2000] unavailable: false 565: name: Newland Desert + outdoor: true origin: [0, 0] spawn: [1960, 37.4, 1640] unavailable: false 566: name: Newland City GOLD + outdoor: true origin: [0, 0] spawn: [300, 32.9, 300] unavailable: false 567: name: Newland + outdoor: true origin: [0, 0] spawn: [1000, 43.9, 740] unavailable: false 570: name: The Perpetual Wastelands + outdoor: true origin: [0, 0] spawn: [2160, 68.6, 1840] unavailable: false @@ -1670,71 +1815,85 @@ unavailable: true 585: name: Aegean + outdoor: true origin: [0, 0] spawn: [1320, 21.5, 1560] unavailable: false 586: name: Wartorn Valley + outdoor: true origin: [0, 0] spawn: [620, 8.6, 660] unavailable: false 590: name: Central Artery Valley + outdoor: true origin: [0, 0] spawn: [1920, 12.2, 1680] unavailable: false 595: name: Deep Artery Valley + outdoor: true origin: [0, 0] spawn: [1800, 39.7, 2200] unavailable: false 600: name: Varmint Woods + outdoor: true origin: [0, 0] spawn: [2300, 16.4, 1700] unavailable: false 605: name: Belial Forest GOLD + outdoor: true origin: [0, 0] spawn: [1800, 30.3, 1720] unavailable: false 610: name: Southern Artery Valley + outdoor: true origin: [0, 0] spawn: [1920, 22.7, 1600] unavailable: false 615: name: Southern Fouls Hills + outdoor: true origin: [0, 0] spawn: [1560, 31.7, 1800] unavailable: false 620: name: Eastern Fouls Plains + outdoor: true origin: [0, 0] spawn: [1560, 25.1, 2200] unavailable: false 625: name: Milky Way + outdoor: true origin: [0, 0] spawn: [2620, 45.2, 1540] unavailable: false 630: name: Pleasant Meadows + outdoor: true origin: [0, 0] spawn: [1800, 0.5, 1560] unavailable: false 635: name: Stret East Bank GOLD + outdoor: true origin: [0, 0] spawn: [1200, 49.7, 1720] unavailable: false 640: name: Tir + outdoor: true origin: [0, 0] spawn: [400, 8.5, 400] unavailable: false 641: name: Tir Arena + outdoor: true origin: [0, 0] spawn: [620, 8, 460] unavailable: false @@ -1745,21 +1904,25 @@ unavailable: true 646: name: Tir County + outdoor: true origin: [0, 0] spawn: [1820, 16.4, 920] unavailable: false 647: name: Greater Tir County + outdoor: true origin: [0, 0] spawn: [1820, 21.2, 1740] unavailable: false 650: name: Upper Stret East Bank GOLD + outdoor: true origin: [0, 0] spawn: [1200, 7.1, 1680] unavailable: false 655: name: Andromeda + outdoor: true origin: [0, 0] spawn: [2600, 0.5, 1520] unavailable: false @@ -1770,11 +1933,13 @@ unavailable: true 665: name: Broken Shores + outdoor: true origin: [0, 0] spawn: [1320, 3.9, 2600] unavailable: false 670: name: Clondyke GOLD + outdoor: true origin: [0, 0] spawn: [1600, 8.7, 2360] unavailable: false @@ -1790,11 +1955,13 @@ unavailable: true 685: name: Galway County GOLD + outdoor: true origin: [0, 0] spawn: [1560, 39.5, 1560] unavailable: false 687: name: Galway Shire GOLD + outdoor: true origin: [0, 0] spawn: [640, 24.1, 1240] unavailable: false @@ -1805,31 +1972,37 @@ unavailable: true 695: name: Lush Fields + outdoor: true origin: [0, 0] spawn: [2000, 12.3, 2000] unavailable: false 696: name: Mutant Domain + outdoor: true origin: [0, 0] spawn: [720, 11.9, 900] unavailable: false 700: name: Omni1-HEADQUARTER + outdoor: true origin: [0, 0] spawn: [600, 9.3, 400] unavailable: false 705: name: Omni1 Entertainment + outdoor: true origin: [0, 0] spawn: [600, 4.1, 600] unavailable: false 706: name: Omni Entertainment Arena + outdoor: true origin: [0, 0] spawn: [180, 16.4, 220] unavailable: false 710: name: Omni-1 Trade + outdoor: true origin: [0, 0] spawn: [400, 17.5, 400] unavailable: false @@ -1840,11 +2013,13 @@ unavailable: true 716: name: Omni Forest + outdoor: true origin: [0, 0] spawn: [680, 38.1, 1800] unavailable: false 717: name: Greater Omni Forest + outdoor: true origin: [0, 0] spawn: [1300, 0.5, 1800] unavailable: false @@ -1860,16 +2035,19 @@ unavailable: true 730: name: Rome Park + outdoor: true origin: [0, 0] spawn: [320, 14.1, 320] unavailable: false 735: name: Rome Blue + outdoor: true origin: [0, 0] spawn: [500, 17.9, 320] unavailable: false 740: name: Rome Green + outdoor: true origin: [0, 0] spawn: [500, 14.1, 320] unavailable: false @@ -1890,6 +2068,7 @@ unavailable: true 760: name: 4 Holes + outdoor: true origin: [0, 0] spawn: [1200, 14.1, 1400] unavailable: false @@ -1920,21 +2099,25 @@ unavailable: true 790: name: Stret West Bank + outdoor: true origin: [0, 0] spawn: [1400, 0.5, 1840] unavailable: false 791: name: Holes in the Wall + outdoor: true origin: [0, 0] spawn: [660, 1.3, 1180] unavailable: false 795: name: The Longest Road + outdoor: true origin: [0, 0] spawn: [2320, 44.5, 1000] unavailable: false 800: name: Borealis + outdoor: true origin: [37107, 38360] spawn: [679.625, 74.75, 537.875] unavailable: false @@ -1945,16 +2128,19 @@ unavailable: false 950: name: Omni Training + outdoor: true origin: [0, 0] spawn: [52.625, 14.75, 56.875] unavailable: false 952: name: Clan Training + outdoor: true origin: [0, 0] spawn: [120, 15.3, 120] unavailable: false 954: name: Neutral Training + outdoor: true origin: [0, 0] spawn: [160, 14.3, 120] unavailable: false diff --git a/server/gamedata/types.go b/server/gamedata/types.go @@ -288,6 +288,7 @@ type TerrainGridEvidence struct { type Playfield struct { Name string `yaml:"name"` + Outdoor bool `yaml:"outdoor,omitempty"` Origin [2]uint32 `yaml:"origin"` Spawn [3]float32 `yaml:"spawn"` Unavailable bool `yaml:"unavailable"` diff --git a/server/inventory.go b/server/inventory.go @@ -178,13 +178,13 @@ func (server *server) handleInventory(client *worldClient, body []byte) error { return server.syncStacks_locked(client) } if index < 0 || (sourceSlot >= 64 && sourceType != 104) || - ((sourceSlot == 6 || sourceSlot == 7 || sourceSlot >= 9 && sourceSlot <= 14) && sourceType != 101) || + ((sourceSlot == 1 || sourceSlot == 6 || sourceSlot == 7 || sourceSlot >= 9 && sourceSlot <= 14) && sourceType != 101) || (sourceSlot == 37 && sourceType != 103) || ((sourceSlot == 21 || sourceSlot == 30) && sourceType != 102) { return nil } destination := binary.BigEndian.Uint32(body[32:36]) - if key == 0x47537a24 && (sourceSlot < 64 || destination == 6 || destination == 7 || destination >= 9 && destination <= 14 || destination == 21 || destination == 30 || destination == 37) { + if key == 0x47537a24 && (sourceSlot < 64 || destination == 1 || destination == 6 || destination == 7 || destination >= 9 && destination <= 14 || destination == 21 || destination == 30 || destination == 37) { if binary.BigEndian.Uint32(body[24:28]) != 50000 || binary.BigEndian.Uint32(body[28:32]) != client.id { return nil } diff --git a/server/stats.go b/server/stats.go @@ -18,10 +18,11 @@ type characterStats struct { Treatment uint16 `yaml:"treatment"` ComputerLiteracy uint16 `yaml:"computer_literacy"` FirstAid uint16 `yaml:"first_aid"` + VehicleGround uint16 `yaml:"vehicle_ground"` } func defaultCharacterStats() characterStats { - return characterStats{10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5} + return characterStats{10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5} } func (character *character) baseStats() characterStats { diff --git a/server/target_protocol.go b/server/target_protocol.go @@ -165,7 +165,7 @@ func decodeInventory1491(body []byte) { binary.BigEndian.PutUint32(body[20:24], decodeInventorySlot1491(binary.BigEndian.Uint32(body[20:24]))) } destination := binary.BigEndian.Uint32(body[32:36]) - if binary.BigEndian.Uint32(body[24:28]) == 50000 && destination != 6 && destination != 7 && !(destination >= 9 && destination <= 14) && destination != 21 && destination != 30 && destination != 37 && destination != 111 { + if binary.BigEndian.Uint32(body[24:28]) == 50000 && destination != 1 && destination != 6 && destination != 7 && !(destination >= 9 && destination <= 14) && destination != 21 && destination != 30 && destination != 37 && destination != 111 { binary.BigEndian.PutUint32(body[32:36], decodeInventorySlot1491(destination)) } case 0x5e477770: diff --git a/server/target_protocol_test.go b/server/target_protocol_test.go @@ -82,7 +82,7 @@ initialized: if hex.EncodeToString(npc[60:89]) != "000001cb0b456469746564204e50430000000000000000000000000007" { t.Fatalf("target NPC appearance, name and new stats: %x", npc[60:89]) } - if hex.EncodeToString(full[57:73]) != "000003f100007e200000003600000001" { + if hex.EncodeToString(full[57:73]) != "000003f1000082110000003600000001" { t.Fatalf("target seventh list and first stat: %x", full[57:73]) } } diff --git a/server/vehicle.go b/server/vehicle.go @@ -0,0 +1,14 @@ +package main + +func (item ownedItem) isKodaik() bool { + return item.Type == 51022 && item.Template == 117294 && item.Quality == 15 +} + +func (character *character) driving() bool { + for _, item := range character.inventory.Items { + if item.Slot == 1 && item.isKodaik() { + return true + } + } + return false +} diff --git a/server/vehicle_test.go b/server/vehicle_test.go @@ -0,0 +1,272 @@ +package main + +import ( + "encoding/binary" + "encoding/json" + "math" + "net/http/httptest" + "testing" + "time" +) + +func newVehicleWorld(t *testing.T) (*server, *combatTestConn) { + t.Helper() + t.Chdir(t.TempDir()) + world, conn := newCombatWorld() + player := world.newCharacter() + player.playfield, player.position = 800, [3]float32{600, 67, 700} + player.stats.VehicleGround = 79 // Effective 81 with the fixture's abilities. + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, 117294); err != nil || !granted { + t.Fatal(granted, err) + } + return world, conn +} + +func TestGroundVehicleNativeEquipDelayAndRestart(t *testing.T) { + world, conn := newVehicleWorld(t) + player, client := world.characters[1], world.clients[1] + started := time.Now() + + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + if client.equipment == nil { + t.Fatal("qualifying ground vehicle was not scheduled for HUD1") + } + finish := client.equipment.readyAt + if finish.Before(started.Add(10*time.Second)) || finish.After(time.Now().Add(10*time.Second)) { + t.Fatal("ground vehicle did not use its authored ten-second equip delay") + } + world.advanceEquipment(finish.Add(-time.Nanosecond)) + if len(conn.packets) != 0 || player.inventory.Items[0].Slot != 64 { + t.Fatal("vehicle appeared before the equip delay expired") + } + world.advanceEquipment(finish) + restored := newTestInventoryServer(t).characters[1] + + if restored.inventory.Items[0].Slot != 1 || restored.inventory.equipmentBonus(156) != 150 || restored.stats.VehicleGround != 79 || + len(conn.packets) != 2 || binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x35505644 || binary.BigEndian.Uint32(conn.packets[1][45:49]) != 6 { + t.Fatal("vehicle identity, speed bonus, skill or native wear effect did not persist") + } +} + +func TestGroundVehicleNativeHUD1DestinationSurvivesInventoryDecoding(t *testing.T) { + world, _ := newVehicleWorld(t) + client := world.clients[1] + request := inventoryMovePacket(1, 48, 1)[20:] + + decodeInventory1491(request) + if err := world.handleInventory(client, request); err != nil { + t.Fatal(err) + } + + if client.equipment == nil || client.equipment.source != 64 || client.equipment.destination != 1 { + t.Fatal("native HUD1 was interpreted as an ordinary inventory index") + } +} + +func TestGroundVehicleRejectsIneligibleEquipment(t *testing.T) { + for _, scenario := range []string{"skill 80", "indoor", "Grid", "outgoing combat", "incoming combat", "wrong slot", "wrong quality", "wrong page", "wrong owner", "stale session", "dead", "loading", "not ready"} { + t.Run(scenario, func(t *testing.T) { + world, conn := newVehicleWorld(t) + player, client := world.characters[1], world.clients[1] + request := inventoryMovePacket(1, 64, 1)[20:] + switch scenario { + case "skill 80": + player.stats.VehicleGround = 78 + case "indoor": + player.playfield = 1183 + case "Grid": + player.playfield = 152 + case "outgoing combat": + player.fighting = 1000000 + world.fighting[1] = player + case "incoming combat": + world.characters[1000000].fighting = 1 + world.fighting[1000000] = world.characters[1000000] + case "wrong slot": + binary.BigEndian.PutUint32(request[32:36], 2) + case "wrong quality": + player.inventory.Items[0].Quality = 14 + case "wrong page": + binary.BigEndian.PutUint32(request[16:20], 101) + case "wrong owner": + binary.BigEndian.PutUint32(request[28:32], 2) + case "stale session": + world.clients[1] = &worldClient{id: 1} + case "dead": + player.health = 0 + case "loading": + client.loading = true + case "not ready": + client.ready = false + } + + if err := world.handleInventory(client, request); err != nil { + t.Fatal(err) + } + + if client.equipment != nil || player.inventory.Items[0].Slot != 64 || len(conn.packets) > 1 { + t.Fatal("ineligible vehicle move changed equipment or published effects") + } + }) + } +} + +func TestGroundVehicleRechecksRequirementsAfterDelay(t *testing.T) { + for _, scenario := range []string{"skill", "playfield", "combat"} { + t.Run(scenario, func(t *testing.T) { + world, conn := newVehicleWorld(t) + player, client := world.characters[1], world.clients[1] + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + finish := client.equipment.readyAt + switch scenario { + case "skill": + player.stats.VehicleGround = 78 + case "playfield": + player.playfield = 1183 + case "combat": + world.characters[1000000].fighting = 1 + world.fighting[1000000] = world.characters[1000000] + } + + world.advanceEquipment(finish) + + if player.inventory.Items[0].Slot != 64 || player.inventory.equipmentBonus(156) != 0 || len(conn.packets) != 1 { + t.Fatal("vehicle used stale eligibility from the start of its equip delay") + } + }) + } +} + +func TestGroundVehicleRemovalRestoresEffectsAndAllowsCombat(t *testing.T) { + world, conn := newVehicleWorld(t) + player, client := world.characters[1], world.clients[1] + observer := &combatTestConn{} + world.characters[2] = &character{id: 2, playfield: 800, health: 100} + world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true} + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + world.characters[1000000].playfield, world.characters[1000000].position = 800, player.position + + if err := world.handleCombat(client, attackPacket(1, 1000000)[20:]); err != nil || player.fighting != 0 { + t.Fatal("a vehicle driver started fighting") + } + if math.Abs(float64(player.physicalExtent())-0.4) > 0.000001 || len(equippedItemPackets(player)) != 1 { + t.Fatal("worn vehicle did not apply its native scale or reconnect effects") + } + player.stats.VehicleGround = 0 + if err := world.handleInventory(client, itemMovePacket(1, 1, 111)[20:]); err != nil { + t.Fatal(err) + } + if client.equipment == nil { + t.Fatal("removing the vehicle incorrectly required its equip skill") + } + world.advanceEquipment(client.equipment.readyAt) + restored := newTestInventoryServer(t).characters[1] + if err := world.handleCombat(client, attackPacket(1, 1000000)[20:]); err != nil { + t.Fatal(err) + } + + if restored.inventory.Items[0] != (ownedItem{1, 51022, 117294, 15, 64, 1}) || restored.inventory.equipmentBonus(156) != 0 || + restored.physicalExtent() != 2 || len(equippedItemPackets(restored)) != 0 || player.fighting != 1000000 { + t.Fatal("removal lost identity or failed to restore speed, scale and fighting") + } + if binary.BigEndian.Uint32(observer.packets[0][45:49]) != 6 || binary.BigEndian.Uint32(observer.packets[1][45:49]) != 7 || len(conn.packets) != 6 { + t.Fatal("owner and observer did not receive exactly one native wear/unwear effect") + } +} + +func TestGroundVehicleMovementUsesNativeRunSpeed(t *testing.T) { + for _, scenario := range []struct { + name string + worn, running bool + forward float32 + health uint32 + z float32 + }{ + {"human forward", false, true, 1, 100, 90}, + {"human backward", false, true, -1, 100, -67}, + {"vehicle forward", true, true, 1, 100, 105}, + {"vehicle backward", true, true, -1, 100, -77.5}, + {"vehicle walking", true, false, 1, 100, 30}, + {"injured human", false, true, 1, 10, 70}, + {"injured vehicle", true, true, 1, 10, 80}, + } { + t.Run(scenario.name, func(t *testing.T) { + world, _ := newVehicleWorld(t) + player, client := world.characters[1], world.clients[1] + player.appearance, player.stats.BodyDevelopment = 277, 26 // Maximum HP 100. + player.position, player.rotation = [3]float32{}, [4]float32{0, 0, 0, 1} + player.running, player.health = scenario.running, scenario.health + if scenario.worn { + player.inventory.Items[0].Slot = 1 + } + client.forward, client.movementStarted = scenario.forward, time.Now().Add(-30*time.Second) + response := httptest.NewRecorder() + + world.mapPlayers(response, httptest.NewRequest("GET", "/map/players", nil)) + var result struct{ Players []mapPlayer } + if err := json.Unmarshal(response.Body.Bytes(), &result); err != nil { + t.Fatal(err) + } + + if len(result.Players) != 1 || math.Abs(float64(result.Players[0].Position[2]-scenario.z)) > 0.0001 { + t.Fatalf("twenty-second native movement estimate: %+v", result.Players) + } + }) + } +} + +func TestGroundVehicleSpeedChangesDoNotRepriceEarlierMovement(t *testing.T) { + world, _ := newVehicleWorld(t) + player, client := world.characters[1], world.clients[1] + player.running, player.rotation = true, [4]float32{0, 0, 0, 1} + client.forward = 1 + + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + finish := client.equipment.readyAt + client.movementStarted = finish.Add(-10 * time.Second) + world.advanceEquipment(finish) + if player.position != [3]float32{600, 67, 745} || client.movementStarted != finish { + t.Fatal("equipping applied the new speed to the previous ten seconds of movement") + } + if err := world.handleInventory(client, itemMovePacket(1, 1, 111)[20:]); err != nil { + t.Fatal(err) + } + finish = client.equipment.readyAt + client.movementStarted = finish.Add(-10 * time.Second) + world.advanceEquipment(finish) + + if player.position != [3]float32{600, 67, 797.5} || client.movementStarted != finish { + t.Fatal("removing the vehicle lost movement accumulated at vehicle speed") + } +} + +func TestGroundVehicleRemovalFromFullInventoryKeepsTheVehicle(t *testing.T) { + world, conn := newVehicleWorld(t) + player, client := world.characters[1], world.clients[1] + player.inventory.Items[0].Slot = 1 + player.inventory.LastID = 93 + for slot := uint32(64); slot < 94; slot++ { + player.inventory.Items = append(player.inventory.Items, ownedItem{slot, 51018, 121567, 1, slot, 1}) + } + + if err := world.handleInventory(client, itemMovePacket(1, 1, 111)[20:]); err != nil { + t.Fatal(err) + } + + if client.equipment != nil || len(player.inventory.Items) != 31 || player.inventory.Items[0].Slot != 1 || + player.inventory.equipmentBonus(156) != 150 || len(conn.packets) != 1 { + t.Fatal("full inventory lost the vehicle or removed its effects") + } +} diff --git a/server/world.go b/server/world.go @@ -165,6 +165,7 @@ func fullCharacterPacket(character *character) []byte { base := character.baseStats() stats := [][2]uint32{{54, uint32(character.level)}, {4, uint32(character.appearance >> 4 & 7)}, {60, 1}, {33, uint32(character.appearance >> 9 & 3)}, {59, uint32(character.appearance >> 7 & 3)}, {156, 100}, {16, uint32(base.Strength)}, {17, uint32(base.Agility)}, {18, uint32(base.Stamina)}, {19, uint32(base.Intelligence)}, {20, uint32(base.Sense)}, {21, uint32(base.Psychic)}, {27, character.health}, {1, character.maximumHealth()}, {123, uint32(base.FirstAid)}, {124, uint32(base.Treatment)}, {37, character.titleLevel()}} stats = append(stats, [2]uint32{51, uint32(character.aggDef)}, [2]uint32{161, uint32(base.ComputerLiteracy)}, [2]uint32{61, character.inventory.Credits}) + stats = append(stats, [2]uint32{166, uint32(base.VehicleGround)}) if time.Now().Before(character.implantChangesUntil) { stats = append(stats, [2]uint32{224, 16}) } diff --git a/server/zoning.go b/server/zoning.go @@ -230,10 +230,16 @@ func predictedPosition_locked(character *character, client *worldClient, now tim seconds := math.Min(now.Sub(client.movementStarted).Seconds(), 20) speed := float32(1.5) if character.running { - speed = 4.5 + // Native movement reads RunSpeed without ability trickle-down. + runSpeed := float32(100 + character.inventory.equipmentBonus(156)) + if float32(character.health) < float32(character.maximumHealth())*float32(0.15) { + runSpeed = (runSpeed+500)*(float32(character.health)/(float32(character.maximumHealth())*float32(0.15))) - 500 + } + speed = 4 + runSpeed*float32(0.005) if client.forward < 0 { - speed = 3.35 + speed = 3 + runSpeed*float32(0.0035) } + speed = max(float32(0.1), min(15, speed)) } x, y, z, w := character.rotation[0], character.rotation[1], character.rotation[2], character.rotation[3] position := character.position diff --git a/tools/data/extract_vehicle.py b/tools/data/extract_vehicle.py @@ -0,0 +1,47 @@ +import hashlib +import json +import pathlib +import struct + +import ao_database +import extract_items + + +def main(): + client = pathlib.Path('anarchy-vanilla-14.9.1') + assert (client / 'version.id').read_text().strip() == '14.9.1' + database = ao_database.Database(client) + + # Retain the exact supported QL rather than interpolating vehicle requirements. + payload = database.read(1000020, 117294) + item = extract_items.parse_item(payload, 1000020, 117294) + assert item['header_words'][0] == 51022 and item['quality'] == 15 + assert dict(item['stats'])[298] == 2 and dict(item['stats'])[211] == 1000 + assert item['name'] == 'Kodaik Turbo IX' + weights = {} + for skill in (156, 166): + raw = database.read(1000204, skill) + weights[skill] = dict(weights=struct.unpack('<6i', raw), payload_hex=raw.hex(), + payload_sha256=hashlib.sha256(raw).hexdigest()) + + # The native RDBTilemap reader classifies CHGA as ground, GNDA/UOHA as dungeon. + outdoors = {} + for kind, identity in sorted(database.records): + if kind != 1000009: + continue + raw = database.read(kind, identity) + assert raw[:4] in (b'CHGA', b'GNDA', b'UOHA'), (identity, raw[:4]) + if raw[:4] == b'CHGA': + outdoors[identity] = hashlib.sha256(raw).hexdigest() + database.close() + + output = pathlib.Path('local/reports/vehicle-14.9.1.json') + output.parent.mkdir(parents=True, exist_ok=True) + output.write_text(json.dumps(dict(index_sha256=hashlib.sha256(database.index).hexdigest(), + item=item, payload_sha256=hashlib.sha256(payload).hexdigest(), + skill_weights=weights, outdoor_playfields=outdoors), indent=2) + '\n') + print(output) + + +if __name__ == '__main__': + main()