commit a4beee14a7d51d07f921926be4894b007a5a7b22
parent 9d20d5537fb19b8537a0cd99793ad82c861301a7
Author: anon <anon@example.com>
Date: Thu, 22 Oct 2026 15:38:40 +0000
Support chest implants and portable clinic self-use
Diffstat:
16 files changed, 640 insertions(+), 32 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -67,7 +67,7 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
exactly once and unequipping restores the baseline.
- [x] Combine two equipment bonuses to the same stat. Check: removing either
item leaves precisely the other item's contribution.
-- [ ] Equip one implant. Check: its slot, treatment/ability requirements and
+- [x] Equip one implant. Check: its slot, treatment/ability requirements and
bonuses work independently of armor and weapon slots.
- [ ] Equip one belt. Check: the corresponding deck slots become available and
invalid belt removal cannot strand installed equipment.
@@ -81,6 +81,9 @@ server-side damage checks are recorded in [armor](docs/armor.md). These stat
bonus milestones use AC; broader skill and resource modifiers remain future work.
The axe's requirement tiers, native field adjustment, checks and remaining
server arithmetic limits are recorded in [overequipping](docs/overequipping.md).
+The QL 1 chest implant, portable clinic self-use, Treatment requirements,
+cooldown persistence and native verification are recorded in
+[implants](docs/implants.md).
## Combat calculations
diff --git a/docs/implants.md b/docs/implants.md
@@ -0,0 +1,147 @@
+# Chest implant and portable surgery clinic
+
+The supported implant is template 101173, exact QL 1, native type 51022:
+Chest Implant: Melee/Ma AC, Shiny. Its shipped record is in
+`server/gamedata/items/items_011.yaml`, with payload SHA-256
+`9cafdcadc8aa4b78a079b9265a758fe0a061d2256c967da42bf93fbd405af4e9`.
+[Auno's historical 14.8 record](https://auno.org/ao/db.php?id=101173&patch=14080000)
+corroborates the requirements and bonus.
+
+| Property | Recovered value |
+| --- | --- |
+| Implant class, stat 76 | 3 |
+| Location mask, stat 298 | 32, bit 5 |
+| Native placement | Page 103, absolute slot 37 |
+| Install action 6 | Treatment > 10 and Strength > 5 |
+| OnWear | Modify 53045, Melee AC 91 +8 |
+| EquipDelay 211 | Inherited 10 centiseconds; no template override |
+
+The implant uses neither chest armor slot 21 nor weapon slot 6. Server AC is
+derived from the currently equipped armor and implant, without saving a second
+modifier balance. The QL 1 Metaplast chest, boots and implant total Melee AC 14;
+removing the implant leaves 6. Other AC types keep the armor's contributions.
+Installing requires the effective Treatment skill, including ability trickle;
+removal does not recheck the install requirements.
+
+Treatment is a persisted base skill. Resource 1000204/124 supplies weights
+`[0,30,0,50,20,0]` for Strength, Agility, Stamina, Intelligence, Sense and Psychic.
+The native skill calculation is documented in [starting stats](combat-starting-stats.md).
+The native default initializer `10072760`, specifically its store at `10072853`,
+sets Treatment base 5. New and older profiles missing this field use that
+baseline, replacing the server's previous fixed Treatment 100 placeholder.
+This is verified client default behavior; historical server character-creation
+values remain unproven. FullCharacter transmits the base skill so the client
+applies trickle once.
+
+## Surgery permission and cooldown
+
+Portable Surgery Clinic 43552, exact QL 1, type 51005, is supported for self-use
+from ordinary inventory. Select yourself before using it. Other selected
+targets are rejected; friendly clinic use and stationary clinics remain future
+work. The item comes from `server/gamedata/items/items_002.yaml` and
+[Auno's historical 14.2.1 record](https://auno.org/ao/db.php?id=43552&patch=14020100).
+
+The clinic requires Treatment > 5 and a selected character. Its raw
+`SelectedTarget 431 & 35` condition describes selection, independently of the
+Treatment cooldown. Native LookAt `2252445f` reports the selected identity and
+mode. The request's separate user identity must still be its actual owner.
+
+Authored Use effects lock the target's Treatment for 600 seconds and grant
+Features 224 bit 0x10 for 30 seconds. The portable clinic adds no Treatment
+bonus. Both installation and removal require this permission, including at
+completion of a pending equipment move. A full ordinary inventory cannot
+discard an installed implant during removal. Combat equipment restrictions,
+ownership checks and atomic inventory saves also apply.
+
+The server saves absolute permission and cooldown deadlines before acknowledging
+use. Repeated requests cannot extend either deadline. Reconnect/restart restores
+the remaining window and cooldown, without re-executing the 30-second Use effect.
+Expiry removes the permission and unlocks Treatment. The supported profile has
+SkillLockModifier 382 equal to zero. Historical handling of portable permission
+across zoning, death and server downtime remains unverified; retaining these
+absolute deadlines is the current persistence policy.
+
+## Native messages
+
+The ordinary item remains a template proxy. GenericCmd `52526858` success only
+updates a proxy's inventory state; it does not execute the resource's Use effects.
+The server therefore follows the acknowledgement with TemplateAction `35505644`:
+
+```text
+43552,43552,1,1,3,104,nativeSlot,50000,ownerID
+```
+
+The auxiliary identity selects the effect recipient. It is required for the
+clinic's target-3 effects. Ordinary placement slots are translated between saved
+64..93 and native 48..77, including this message. CharacterAction `5e477770`
+with body `{170,0,0,124,remainingSeconds}` installs the native Treatment lock;
+`{164,0,0,0,124}` clears it. LockSkill's authored function reaches an original
+client stub, so the explicit server lock response is necessary.
+
+The owner restores active Features 224 bit 0x10 through FullCharacter. StatIIR
+`2b333d6e` clears it on authoritative expiry. The supported server currently
+authors no other Features bits.
+
+Implant moves use ContainerAddItem `47537a24`: source page 104 for installation,
+page 103/slot 37 for removal, and destination 111 for first free ordinary slot.
+TemplateAction 6/7 applies/removes the implant bonus using placement 103/37.
+FullCharacter already applies installed implant effects during initialization;
+another owner wear message would double the bonus. Observers receive one wear
+action after their SimpleChar snapshot, as with armor.
+
+## Evidence
+
+Original `kkr.dll` SHA-256:
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+Addresses use its original base 0x10000000; generated C uses 0x36000000.
+The retained `local/reports/implant-protocol-1491-evidence.json` has 136 REA
+records. Catalog and historical-page extracts are in
+`local/implant-smoke/source-ledger.json` and `treatment-weights.json`.
+
+| Finding | Original function | Evidence ID |
+| --- | --- | --- |
+| Permission gate | `10059ba0` | `ev_984c68d7c48db7c554b9e1980aa680567937286aad254fc0667d4c14434c0099` |
+| Implant slot conversion | `1002a1f0` | `ev_178142dff667fea800df25ab5ae2730e84892895651154915ea1bb29f35215d3` |
+| Owner initialization | `1005f220` | `ev_1a427a9cc632357b64ee07772afccbc7de2100a84b966a0ecfeb46b5364b7bbf` |
+| Clinic restriction effect | `100c1730` | `ev_7a516b3bcdb7faf5d10a93c80663030360858125f5b5705ba96548bdc6a38268` |
+| Skill lock installation | `10073ae0` | `ev_96a64081194dab5d44fcfa4d96a4c18476f94d2434ebea56d9229ec484519ed1` |
+| Proxy Use dispatch | `1005e790` | `ev_d6fce7cdf8a26b4feb90ba17fcd1711f9ae42241843a86f766749070d244b871` |
+| LookAt serialization | `1007fd60` | `ev_26112f2ec7e8d5ffd44d370e8ce17445746b16c22d645f421c6773020a1a8c64` |
+
+Native `1008e840` establishes the inherited equip delay; stat 2 = 205 is Mass,
+not a delay. Internal timer signal 128 removes local permission but is not a
+supported network CharacterAction.
+
+## Verification
+
+The maintained `go test ./server/... -count=1` suite passed in 98.280 seconds.
+Focused race tests covering implants, clinics, armor, equipment, backpacks and
+character stats passed in 120.598 seconds. Tests cover exact requirement
+boundaries, inherited delay, source-page validation, occupied slots, full
+inventory removal, failed saves, permission expiry during a pending move,
+request replay, cooldown expiry, ownership and persistent state. FullCharacter
+checks verify base Treatment and restored permission without duplicating AC.
+
+Actual Chromium WASM tests are retained in `local/implant-smoke/`, including
+screenshots, packet logs, five read-only native inventory snapshots and three
+native Treatment-lock snapshots. The native UI installed the implant in slot
+37, changed Melee AC from 6 to 14, removed it back to 6, and reinstalled it.
+Projectile AC stayed 6 and attack rating stayed 400. Treatment 10 and Strength
+5 failed; the qualifying fixture used Treatment 11 and Strength 10. Removing
+after the real 30-second access expiry failed. A second browser character kept
+its empty inventory and zero AC.
+
+Reconnect and server restart restored the same five item identities and native
+AC 14, with no duplicate OnWear bonus. The Treatment-lock list contained stat
+124 with 589 seconds after use, 524 after reconnect, and 407 after the final
+server restart. Its saved absolute deadline stayed unchanged when use was
+rejected during cooldown. The test fixture advanced the clinic clock between
+repeat scenarios; production exposes no such endpoint. Native permission
+restoration is covered by FullCharacter stat assertions; an early UI removal
+attempt during a short reload was inconclusive and is excluded from the
+manual completion checks.
+
+There were no client exceptions or adapter failures. Seven connection-refused
+console messages occurred during the intentional server restart. All test
+browser contexts, temporary server and native analysis sessions were closed;
+the temporary fixture binary was removed.
diff --git a/server/backpacks.go b/server/backpacks.go
@@ -51,7 +51,7 @@ func backpackClosePacket(owner, bag uint32) []byte {
return n3Packet(0x2049527c, 51017, bag, body)
}
-func (server *server) handleBackpackUse(client *worldClient, body []byte) error {
+func (server *server) handleOwnedItemUse(client *worldClient, body []byte) error {
server.updateMutex.Lock()
defer server.updateMutex.Unlock()
server.mutex.Lock()
@@ -69,6 +69,14 @@ func (server *server) handleBackpackUse(client *worldClient, body []byte) error
return nil
}
client.useSequence = sequence
+ if binary.BigEndian.Uint32(body[40:44]) == 104 {
+ index := slices.IndexFunc(player.inventory.Items, func(item ownedItem) bool {
+ return item.Slot == binary.BigEndian.Uint32(body[44:48]) && item.Template == 43552
+ })
+ if index >= 0 {
+ return server.useClinic_locked(client, index, body)
+ }
+ }
slot := binary.BigEndian.Uint32(body[44:48])
page := binary.BigEndian.Uint32(body[40:44])
if page == 104 && (slot < 64 || slot >= 94) {
diff --git a/server/backpacks_test.go b/server/backpacks_test.go
@@ -53,7 +53,7 @@ func TestBackpackOpenCloseAndDistinctHandles(t *testing.T) {
binary.BigEndian.PutUint32(request[60:64], 51017)
binary.BigEndian.PutUint32(request[64:68], 3)
}
- if err := world.handleBackpackUse(client, request[20:]); err != nil {
+ if err := world.handleOwnedItemUse(client, request[20:]); err != nil {
t.Fatal(err)
}
}
@@ -136,16 +136,16 @@ func TestBackpackNativeWireTransferAndRestart(t *testing.T) {
func TestBackpackTransferBetweenClosedAndOpenBags(t *testing.T) {
world, _ := newBackpackWorld(t)
client := world.clients[1]
- world.handleBackpackUse(client, backpackUseRequest(1, 66, 1)[20:])
- world.handleBackpackUse(client, backpackUseRequest(1, 67, 2)[20:])
- world.handleBackpackUse(client, backpackUseRequest(1, 66, 3)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 2)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 3)[20:])
for _, request := range [][]byte{backpackMoveRequest(104, 68, 51017, 3, 111), backpackUseRequest(1, 66, 4)} {
var err error
if binary.BigEndian.Uint32(request[20:24]) == 0x47537a24 {
err = world.handleInventory(client, request[20:])
} else {
- err = world.handleBackpackUse(client, request[20:])
+ err = world.handleOwnedItemUse(client, request[20:])
}
if err != nil {
t.Fatal(err)
@@ -164,7 +164,7 @@ func TestBackpackRejectsInvalidOwnershipAndPlacement(t *testing.T) {
t.Run(scenario, func(t *testing.T) {
world, conn := newBackpackWorld(t)
client, player := world.clients[1], world.characters[1]
- world.handleBackpackUse(client, backpackUseRequest(1, 66, 1)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:])
world.handleInventory(client, backpackMoveRequest(104, 68, 51017, 3, 111)[20:])
request := backpackMoveRequest(107, 1<<16, 50000, 1, 111)[20:]
switch scenario {
@@ -175,7 +175,7 @@ func TestBackpackRejectsInvalidOwnershipAndPlacement(t *testing.T) {
case "unknown handle":
request = backpackMoveRequest(107, 8<<16, 50000, 1, 111)[20:]
case "closed source":
- world.handleBackpackUse(client, backpackUseRequest(1, 66, 2)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 2)[20:])
case "unseen bag":
request = backpackMoveRequest(104, 64, 51017, 4, 111)[20:]
case "foreign owner":
@@ -210,7 +210,7 @@ func TestBackpackRejectsInvalidOwnershipAndPlacement(t *testing.T) {
func TestBackpackCapacityTwentyOneAndFullMainInventory(t *testing.T) {
world, _ := newBackpackWorld(t)
client, player := world.clients[1], world.characters[1]
- world.handleBackpackUse(client, backpackUseRequest(1, 66, 1)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:])
for range 21 {
item := player.inventory.Items[len(player.inventory.Items)-1]
if err := world.handleInventory(client, backpackMoveRequest(104, item.Slot, 51017, 3, 111)[20:]); err != nil {
@@ -240,7 +240,7 @@ func TestBackpackCapacityTwentyOneAndFullMainInventory(t *testing.T) {
func TestBackpackConcurrentTransferAndFailedSave(t *testing.T) {
world, conn := newBackpackWorld(t)
client := world.clients[1]
- world.handleBackpackUse(client, backpackUseRequest(1, 66, 1)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:])
conn.packets = nil
request := backpackMoveRequest(104, 68, 51017, 3, 111)[20:]
var workers sync.WaitGroup
@@ -273,7 +273,7 @@ func TestBackpackConcurrentTransferAndFailedSave(t *testing.T) {
func TestBackpackStackSplitJoinAndDelete(t *testing.T) {
world, _ := newBackpackWorld(t)
client := world.clients[1]
- world.handleBackpackUse(client, backpackUseRequest(1, 66, 1)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:])
world.handleInventory(client, backpackMoveRequest(104, 64, 51017, 3, 111)[20:])
action := func(kind, source, otherPage, argument uint32) []byte {
var body []byte
@@ -304,7 +304,7 @@ func TestBackpackContentsSurviveReclaim(t *testing.T) {
if err := world.saveUser_locked(player); err != nil {
t.Fatal(err)
}
- world.handleBackpackUse(client, backpackUseRequest(1, 66, 1)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:])
world.handleInventory(client, backpackMoveRequest(104, 64, 51017, 3, 111)[20:])
defeatReclaimPlayer(t, world)
@@ -321,7 +321,7 @@ func TestBackpackContentsSurviveReclaim(t *testing.T) {
t.Fatal("backpack was lost from reclaim")
}
err := world.handleInventory(client, reclaimTakeRequest(uint32(slot)))
- world.handleBackpackUse(client, backpackUseRequest(1, 64, 2)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 64, 2)[20:])
if err != nil || !reflect.DeepEqual(contents, []ownedItem{{1, 51005, 152030, 42, 0, 3}}) ||
!reflect.DeepEqual(player.inventory.Containers[3], contents) || !slices.Contains(player.inventory.Items, ownedItem{3, 51017, 99228, 1, 64, 1}) || !client.backpacks[1].open {
@@ -332,7 +332,7 @@ func TestBackpackContentsSurviveReclaim(t *testing.T) {
func TestBackpackDeleteRemovesContentsAtomically(t *testing.T) {
world, _ := newBackpackWorld(t)
client := world.clients[1]
- world.handleBackpackUse(client, backpackUseRequest(1, 66, 1)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 66, 1)[20:])
world.handleInventory(client, backpackMoveRequest(104, 68, 51017, 3, 111)[20:])
request := inventoryDeletePacket(1, 66)[20:]
binary.BigEndian.PutUint32(request[28:32], 99228)
@@ -406,7 +406,7 @@ func TestBackpackRejectsInvalidUse(t *testing.T) {
world.clients[1] = &worldClient{id: 1}
}
- err := world.handleBackpackUse(client, request)
+ err := world.handleOwnedItemUse(client, request)
if err != nil || len(client.backpacks) != 0 || len(conn.packets) != 0 {
t.Fatal("invalid use opened a backpack", err)
diff --git a/server/control.go b/server/control.go
@@ -237,6 +237,8 @@ func (server *server) updateUser_locked(destination userData) error {
updated.inventory = character.inventory
updated.browserTokenHash = character.browserTokenHash
updated.resurrectionTerminal = character.resurrectionTerminal
+ updated.implantChangesUntil = character.implantChangesUntil
+ updated.treatmentLockedUntil = character.treatmentLockedUntil
updated.savedProfile = character.savedProfile
updated.savedPosition = character.savedPosition
updated.nextPositionSave = character.nextPositionSave
diff --git a/server/equipment.go b/server/equipment.go
@@ -33,12 +33,18 @@ func (item ownedItem) equipmentSlot() uint32 {
return 21
case 85638:
return 30
+ case 101173:
+ return 37
}
}
return 0
}
func (character *character) canEquip(item ownedItem) bool {
+ if item.equipmentSlot() == 37 {
+ stats := character.baseStats()
+ return stats.Strength > 5 && stats.effectiveSkill(stats.Treatment, [6]uint32{0, 30, 0, 50, 20, 0}) > 10
+ }
if item.isKineticAxe() {
return character.canWieldKineticAxe()
}
@@ -50,10 +56,10 @@ func (character *character) canEquip(item ownedItem) bool {
}
func (character *character) armorClass(stat uint32) uint32 {
- // Supported Metaplast pieces have unconditional positive OnWear AC modifiers.
+ // Supported armor and the chest implant have unconditional OnWear AC modifiers.
var armor uint32
for _, item := range character.inventory.Items {
- if item.Slot != 21 && item.Slot != 30 {
+ if item.Slot != 21 && item.Slot != 30 && item.Slot != 37 {
continue
}
for _, section := range gamedata.ItemTemplates[item.Template].Sections {
@@ -105,6 +111,8 @@ func itemMovePacket(owner, source, destination uint32) []byte {
page = 101
} else if source == 21 || source == 30 {
page = 102
+ } else if source == 37 {
+ page = 103
}
var body []byte
for _, value := range []uint32{page, source, 50000, owner, destination} {
@@ -140,6 +148,7 @@ func (server *server) beginEquipment_locked(client *worldClient, index int, dest
if item.equipmentSlot() == 0 || destination == item.Slot ||
(destination != item.equipmentSlot() && (destination < 64 || destination >= 94)) ||
(destination < 64 && !character.canEquip(item)) ||
+ (item.equipmentSlot() == 37 && !time.Now().Before(character.implantChangesUntil)) ||
slices.ContainsFunc(character.inventory.Items, func(other ownedItem) bool { return other.Slot == destination }) ||
server.equipmentBlocked_locked(character, time.Now()) {
return client.send(itemMovePacket(client.id, item.Slot, item.Slot))
@@ -147,6 +156,10 @@ func (server *server) beginEquipment_locked(client *worldClient, index int, dest
// Leave the owned item at its source until the catalog's equip delay expires.
delay := time.Duration(itemStat(gamedata.ItemTemplates[item.Template], 211)) * 10 * time.Millisecond
+ if item.equipmentSlot() == 37 {
+ // Beholder FUN_1008e840 defaults EquipDelay to 10; this implant has no override.
+ delay = 100 * time.Millisecond
+ }
client.equipment = &equipmentMove{item.ID, item.Slot, destination, requestedSlot, time.Now().Add(delay)}
return nil
}
@@ -171,6 +184,7 @@ func (server *server) advanceEquipment(now time.Time) {
continue
}
if server.equipmentBlocked_locked(character, now) ||
+ (character.inventory.Items[index].equipmentSlot() == 37 && !now.Before(character.implantChangesUntil)) ||
(move.destination < 64 && !character.canEquip(character.inventory.Items[index])) ||
slices.ContainsFunc(character.inventory.Items, func(item ownedItem) bool { return item.Slot == move.destination }) {
updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.source))
@@ -187,8 +201,8 @@ func (server *server) advanceEquipment(now time.Time) {
updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.source))
continue
}
- if move.source == 21 || move.source == 30 {
- server.queueCombat_locked(updates, character, character, armorActionPacket(character.id, item, 7))
+ if move.source == 21 || move.source == 30 || move.source == 37 {
+ server.queueCombat_locked(updates, character, character, equipmentActionPacket(character.id, item, 7))
}
if move.source == 6 {
server.queueCombat_locked(updates, character, character, weaponUnequipPacket(client.id))
@@ -199,8 +213,8 @@ func (server *server) advanceEquipment(now time.Time) {
}
}
updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.requestedSlot))
- if move.destination == 21 || move.destination == 30 {
- server.queueCombat_locked(updates, character, character, armorActionPacket(character.id, character.inventory.Items[index], 6))
+ if 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 {
server.queueCombat_locked(updates, character, character, equippedWeaponPackets(character)...)
@@ -238,10 +252,14 @@ func equippedWeaponPackets(character *character) [][]byte {
return nil
}
-func armorActionPacket(owner uint32, item ownedItem, action uint32) []byte {
+func equipmentActionPacket(owner uint32, item ownedItem, action uint32) []byte {
// kkr.dll FUN_100848d0: template endpoints, QL, count, action and two identities.
+ page := uint32(102)
+ if item.Slot == 37 {
+ page = 103
+ }
var body []byte
- for _, value := range []uint32{item.Template, item.Template, item.Quality, 1, action, 102, item.Slot, 0, 0} {
+ for _, value := range []uint32{item.Template, item.Template, item.Quality, 1, action, page, item.Slot, 0, 0} {
body = binary.BigEndian.AppendUint32(body, value)
}
return n3Packet(0x35505644, 50000, owner, body)
@@ -250,8 +268,8 @@ func armorActionPacket(owner uint32, item ownedItem, action uint32) []byte {
func equippedItemPackets(character *character) [][]byte {
packets := equippedWeaponPackets(character)
for _, item := range character.inventory.Items {
- if item.Slot == 21 || item.Slot == 30 {
- packets = append(packets, armorActionPacket(character.id, item, 6))
+ if item.Slot == 21 || item.Slot == 30 || item.Slot == 37 {
+ packets = append(packets, equipmentActionPacket(character.id, item, 6))
}
}
return packets
diff --git a/server/implants.go b/server/implants.go
@@ -0,0 +1,102 @@
+package main
+
+import (
+ "encoding/binary"
+ "fmt"
+ "time"
+)
+
+func (server *server) handleTargetSelection(client *worldClient, body []byte) error {
+ if len(body) != 28 {
+ return fmt.Errorf("invalid target selection length")
+ }
+ server.mutex.Lock()
+ defer server.mutex.Unlock()
+ if server.clients[client.id] == client && client.ready && !client.loading &&
+ binary.BigEndian.Uint32(body[4:8]) == 50000 && binary.BigEndian.Uint32(body[8:12]) == client.id &&
+ binary.BigEndian.Uint32(body[24:28]) <= 2 {
+ client.selectedTarget = [2]uint32{binary.BigEndian.Uint32(body[16:20]), binary.BigEndian.Uint32(body[20:24])}
+ }
+ return nil
+}
+
+func (server *server) useClinic_locked(client *worldClient, index int, body []byte) error {
+ player := server.characters[client.id]
+
+ // Portable clinic self-use requires selecting the owner.
+ slot := binary.BigEndian.Uint32(body[44:48])
+ stats := player.baseStats()
+ now := time.Now()
+ accepted := client.selectedTarget == [2]uint32{50000, client.id} && slot >= 64 && slot < 94 &&
+ player.inventory.Items[index].Type == 51005 && player.inventory.Items[index].Template == 43552 && player.inventory.Items[index].Quality == 1 &&
+ stats.effectiveSkill(stats.Treatment, [6]uint32{0, 30, 0, 50, 20, 0}) > 5 && !now.Before(player.treatmentLockedUntil)
+ if accepted {
+ // Save the cooldown and access window before acknowledging any authored effects.
+ updated := *player
+ updated.implantChangesUntil = now.Add(30 * time.Second)
+ updated.treatmentLockedUntil = now.Add(600 * time.Second)
+ if err := server.saveUser_locked(&updated); err != nil {
+ return err
+ }
+ *player = updated
+ }
+ reply := append([]byte(nil), body[16:]...)
+ binary.BigEndian.PutUint32(reply, 2)
+ if accepted {
+ binary.BigEndian.PutUint32(reply, 1)
+ }
+ if err := client.send(n3Packet(0x52526858, 50000, client.id, reply)); err != nil {
+ return err
+ }
+ if !accepted {
+ return nil
+ }
+
+ // Template proxies need an explicit Use action; their acknowledgement only updates counts.
+ item := player.inventory.Items[index]
+ var action []byte
+ for _, value := range []uint32{item.Template, item.Template, item.Quality, 1, 3, 104, slot, 50000, client.id} {
+ action = binary.BigEndian.AppendUint32(action, value)
+ }
+ if err := client.send(n3Packet(0x35505644, 50000, client.id, action)); err != nil {
+ return err
+ }
+ return client.send(treatmentLockPacket(client.id, 600))
+}
+
+func treatmentLockPacket(owner, seconds uint32) []byte {
+ var body []byte
+ for _, value := range []uint32{170, 0, 0, 124, seconds} {
+ body = binary.BigEndian.AppendUint32(body, value)
+ }
+ return n3Packet(0x5e477770, 50000, owner, body)
+}
+
+func (server *server) advanceClinics(now time.Time) {
+ server.updateMutex.Lock()
+ defer server.updateMutex.Unlock()
+ server.mutex.Lock()
+ updates := make(map[*worldClient][][]byte)
+ for id, client := range server.clients {
+ if !client.ready || client.loading {
+ continue
+ }
+ player := server.characters[id]
+ if !player.implantChangesUntil.IsZero() && !now.Before(player.implantChangesUntil) {
+ player.implantChangesUntil = time.Time{}
+ body := binary.BigEndian.AppendUint32(nil, 224)
+ body = binary.BigEndian.AppendUint32(body, 0)
+ updates[client] = append(updates[client], n3Packet(0x2b333d6e, 50000, id, body))
+ }
+ if !player.treatmentLockedUntil.IsZero() && !now.Before(player.treatmentLockedUntil) {
+ player.treatmentLockedUntil = time.Time{}
+ var body []byte
+ for _, value := range []uint32{164, 0, 0, 0, 124} {
+ body = binary.BigEndian.AppendUint32(body, value)
+ }
+ updates[client] = append(updates[client], n3Packet(0x5e477770, 50000, id, body))
+ }
+ }
+ server.mutex.Unlock()
+ server.sendCombatUpdates(updates)
+}
diff --git a/server/implants_test.go b/server/implants_test.go
@@ -0,0 +1,302 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "os"
+ "reflect"
+ "testing"
+ "time"
+)
+
+func newImplantWorld(t *testing.T) (*server, *combatTestConn) {
+ t.Helper()
+ world, conn := newArmorWorld(t)
+ world.characters[1].stats.Treatment = 9
+ world.clients[1].selectedTarget = [2]uint32{50000, 1}
+ for _, template := range []uint32{43552, 101173} {
+ if granted, err := world.grantItem_locked(world.characters[1], template); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ return world, conn
+}
+
+func TestImplantClinicEquipBonusesAndRestart(t *testing.T) {
+ world, conn := newImplantWorld(t)
+ player, client := world.characters[1], world.clients[1]
+
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ for _, move := range [][2]uint32{{64, 6}, {65, 21}, {66, 30}, {68, 37}} {
+ started := time.Now()
+ if err := world.handleInventory(client, inventoryMovePacket(1, move[0], move[1])[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if client.equipment == nil {
+ t.Fatalf("equipment move rejected: %v", move)
+ }
+ if move[1] == 37 && (client.equipment.readyAt.Before(started.Add(100*time.Millisecond)) || client.equipment.readyAt.After(time.Now().Add(100*time.Millisecond))) {
+ t.Fatal("implant did not inherit its native 100 ms equip delay")
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ }
+ restarted := newTestInventoryServer(t)
+ restored := restarted.characters[1]
+
+ if player.armorClass(91) != 14 || player.armorClass(90) != 6 || player.armorClass(94) != 2 || player.meleeWeapon() == nil {
+ t.Fatalf("independent equipment bonuses: %+v", player.inventory.Items)
+ }
+ if !reflect.DeepEqual(restored.inventory, player.inventory) || restored.armorClass(91) != 14 ||
+ restored.implantChangesUntil.UnixNano() != player.implantChangesUntil.UnixNano() ||
+ restored.treatmentLockedUntil.UnixNano() != player.treatmentLockedUntil.UnixNano() || restored.stats.Treatment != 9 {
+ t.Fatalf("implant or clinic state did not persist: %+v", restored)
+ }
+ last := conn.packets[len(conn.packets)-1]
+ if binary.BigEndian.Uint32(last[16:20]) != 0x35505644 || binary.BigEndian.Uint32(last[49:53]) != 103 || binary.BigEndian.Uint32(last[53:57]) != 37 {
+ t.Fatalf("implant wear placement: %x", last)
+ }
+ if len(equippedItemPackets(restored)) != 4 {
+ t.Fatal("observer equipment snapshot lost an item")
+ }
+ packet := fullCharacterPacket(restored)
+ cursor := 64 + len(restored.inventory.Items)*32
+ count := int(binary.BigEndian.Uint32(packet[cursor:])/1009 - 1)
+ values := make(map[uint32]uint32)
+ for offset := cursor + 4; offset < cursor+4+count*8; offset += 8 {
+ values[binary.BigEndian.Uint32(packet[offset:])] = binary.BigEndian.Uint32(packet[offset+4:])
+ }
+ if values[124] != 9 || values[224] != 16 || values[91] != 0 {
+ t.Fatalf("FullCharacter duplicated trickle, equipment bonuses or lost access: %v", values)
+ }
+}
+
+func TestImplantRequirementsAndNativeSlotConversion(t *testing.T) {
+ for _, scenario := range []string{"treatment 10", "treatment 11", "strength 5", "strength 6", "no clinic", "wrong slot", "wrong quality", "wrong type", "occupied"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, _ := newImplantWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 1)[20:])
+ destination := uint32(37)
+ switch scenario {
+ case "treatment 10":
+ player.stats.Treatment = 8
+ case "strength 5":
+ player.stats.Strength = 5
+ case "strength 6":
+ player.stats.Strength = 6
+ case "no clinic":
+ player.implantChangesUntil = time.Time{}
+ case "wrong slot":
+ destination = 21
+ case "wrong quality":
+ player.inventory.Items[4].Quality = 200
+ case "wrong type":
+ player.inventory.Items[4].Type = 51005
+ case "occupied":
+ player.inventory.Items = append(player.inventory.Items, ownedItem{6, 51022, 101173, 1, 37, 1})
+ }
+ request := inventoryMovePacket(1, 52, destination)[20:]
+
+ decodeInventory1491(request)
+ err := world.handleInventory(client, request)
+ accepted := client.equipment != nil
+ if accepted {
+ world.advanceEquipment(client.equipment.readyAt)
+ }
+
+ if err != nil || accepted != (scenario == "treatment 11" || scenario == "strength 6") {
+ t.Fatalf("implant eligibility: accepted=%v err=%v", accepted, err)
+ }
+ if scenario != "wrong slot" && binary.BigEndian.Uint32(request[32:36]) != 37 {
+ t.Fatal("ordinary inventory conversion shifted the implant destination")
+ }
+ })
+ }
+}
+
+func TestImplantRemovalRetainsOtherEquipmentAndNeedsClinic(t *testing.T) {
+ world, conn := newImplantWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 1)[20:])
+ for _, move := range [][2]uint32{{65, 21}, {66, 30}, {68, 37}} {
+ world.handleInventory(client, inventoryMovePacket(1, move[0], move[1])[20:])
+ world.advanceEquipment(client.equipment.readyAt)
+ }
+ deadline := player.implantChangesUntil
+ world.advanceClinics(deadline)
+ before := player.inventory
+
+ world.handleInventory(client, itemMovePacket(1, 37, 111)[20:])
+ if client.equipment != nil || !reflect.DeepEqual(before, player.inventory) || player.armorClass(91) != 14 {
+ t.Fatal("implant removed after surgery access expired")
+ }
+ world.advanceClinics(player.treatmentLockedUntil)
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 2)[20:])
+ // Removal does not recheck the implant's install requirements.
+ player.stats.Treatment, player.stats.Strength = 0, 1
+ conn.packets = nil
+ world.handleInventory(client, itemMovePacket(1, 37, 111)[20:])
+ world.advanceEquipment(client.equipment.readyAt)
+ restarted := newTestInventoryServer(t)
+
+ if restarted.characters[1].armorClass(91) != 6 || player.armorClass(90) != 6 || player.inventory.Items[4].Slot != 65 || len(player.inventory.Items) != 5 {
+ t.Fatalf("removing implant changed other equipment: %+v", player.inventory)
+ }
+ if len(conn.packets) != 2 || binary.BigEndian.Uint32(conn.packets[0][45:49]) != 7 ||
+ binary.BigEndian.Uint32(conn.packets[0][49:53]) != 103 || binary.BigEndian.Uint32(conn.packets[1][29:33]) != 103 {
+ t.Fatalf("native implant removal: %x", conn.packets)
+ }
+}
+
+func TestImplantPendingMoveRechecksClinicAndSave(t *testing.T) {
+ for _, scenario := range []string{"expired clinic", "failed save"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, _ := newImplantWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 1)[20:])
+ world.handleInventory(client, inventoryMovePacket(1, 68, 37)[20:])
+ finish := client.equipment.readyAt
+ if scenario == "expired clinic" {
+ player.implantChangesUntil = finish
+ } else {
+ os.Remove("data/players/1/inventory.yaml")
+ os.Mkdir("data/players/1/inventory.yaml", 0700)
+ }
+
+ world.advanceEquipment(finish)
+
+ if player.inventory.Items[4].Slot != 68 || player.armorClass(91) != 0 || client.equipment != nil {
+ t.Fatal("interrupted implant installation changed ownership or bonuses")
+ }
+ })
+ }
+}
+
+func TestImplantRemovalRejectsWrongPageAndFullInventory(t *testing.T) {
+ world, _ := newImplantWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 1)[20:])
+ world.handleInventory(client, inventoryMovePacket(1, 68, 37)[20:])
+ world.advanceEquipment(client.equipment.readyAt)
+ for {
+ granted, err := world.grantItem_locked(player, 121567)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !granted {
+ break
+ }
+ }
+ before := player.inventory
+ wrongPage := itemMovePacket(1, 37, 111)[20:]
+ binary.BigEndian.PutUint32(wrongPage[16:20], 102)
+
+ world.handleInventory(client, wrongPage)
+ world.handleInventory(client, itemMovePacket(1, 37, 111)[20:])
+
+ if client.equipment != nil || !reflect.DeepEqual(before, player.inventory) || player.armorClass(91) != 8 {
+ t.Fatal("rejected removal lost an implant or its bonus")
+ }
+}
+
+func TestPortableClinicTracksNativeSelfSelection(t *testing.T) {
+ world, _ := newImplantWorld(t)
+ client := world.clients[1]
+ client.selectedTarget = [2]uint32{}
+ var body []byte
+ for _, value := range []uint32{50000, 1, 1} {
+ body = binary.BigEndian.AppendUint32(body, value)
+ }
+ request := n3Packet(0x2252445f, 50000, 1, body)[20:]
+
+ if err := world.handleTargetSelection(client, request); err != nil {
+ t.Fatal(err)
+ }
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 1)[20:])
+ binary.BigEndian.PutUint32(request[8:12], 2)
+ binary.BigEndian.PutUint32(request[20:24], 2)
+ world.handleTargetSelection(client, request)
+
+ if world.characters[1].implantChangesUntil.IsZero() || client.selectedTarget != [2]uint32{50000, 1} {
+ t.Fatal("self selection was not used or foreign selection replaced it")
+ }
+}
+
+func TestPortableClinicCooldownAndExpiry(t *testing.T) {
+ world, conn := newImplantWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ started := time.Now()
+
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 1)[20:])
+ window, cooldown := player.implantChangesUntil, player.treatmentLockedUntil
+ first := append([][]byte(nil), conn.packets...)
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 1)[20:])
+ world.handleOwnedItemUse(client, backpackUseRequest(1, 67, 2)[20:])
+ world.advanceClinics(window.Add(-time.Nanosecond))
+ if len(conn.packets) != 4 || !player.implantChangesUntil.Equal(window) || !player.treatmentLockedUntil.Equal(cooldown) {
+ t.Fatal("replay or cooldown use extended clinic effects")
+ }
+ world.advanceClinics(window)
+ world.advanceClinics(cooldown)
+ world.advanceClinics(cooldown.Add(time.Second))
+
+ if window.Before(started.Add(30*time.Second)) || window.After(time.Now().Add(30*time.Second)) || cooldown.Sub(window) != 570*time.Second {
+ t.Fatalf("clinic duration: window=%v cooldown=%v", window.Sub(started), cooldown.Sub(started))
+ }
+ if len(first) != 3 || binary.BigEndian.Uint32(first[0][29:33]) != 1 || binary.BigEndian.Uint32(first[1][45:49]) != 3 ||
+ binary.BigEndian.Uint32(first[1][57:61]) != 50000 || binary.BigEndian.Uint32(first[1][61:65]) != 1 ||
+ binary.BigEndian.Uint32(first[2][29:33]) != 170 || binary.BigEndian.Uint32(first[2][41:45]) != 124 || binary.BigEndian.Uint32(first[2][45:49]) != 600 {
+ t.Fatalf("clinic Use or cooldown wire: %x", first)
+ }
+ if len(conn.packets) != 6 || binary.BigEndian.Uint32(conn.packets[4][29:33]) != 224 || binary.BigEndian.Uint32(conn.packets[4][33:37]) != 0 ||
+ binary.BigEndian.Uint32(conn.packets[5][29:33]) != 164 || !player.implantChangesUntil.IsZero() || !player.treatmentLockedUntil.IsZero() {
+ t.Fatalf("clinic expiry repeated or omitted: %x", conn.packets)
+ }
+}
+
+func TestPortableClinicRejectsInvalidUseAndFailedSave(t *testing.T) {
+ for _, scenario := range []string{"treatment 5", "no target", "other target", "foreign owner", "foreign user", "wrong type", "wrong quality", "dead", "loading", "failed save"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, conn := newImplantWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ request := backpackUseRequest(1, 67, 1)[20:]
+ switch scenario {
+ case "treatment 5":
+ player.stats.Treatment = 3
+ case "no target":
+ client.selectedTarget = [2]uint32{}
+ case "other target":
+ client.selectedTarget = [2]uint32{50000, 2}
+ case "foreign owner":
+ binary.BigEndian.PutUint32(request[8:12], 2)
+ case "foreign user":
+ binary.BigEndian.PutUint32(request[36:40], 2)
+ case "wrong type":
+ player.inventory.Items[3].Type = 51022
+ case "wrong quality":
+ player.inventory.Items[3].Quality = 200
+ case "dead":
+ player.health = 0
+ case "loading":
+ client.loading = true
+ case "failed save":
+ os.Remove("data/players/1/player.yaml")
+ os.Mkdir("data/players/1/player.yaml", 0700)
+ }
+ before := player.inventory
+
+ err := world.handleOwnedItemUse(client, request)
+
+ if (err != nil) != (scenario == "failed save") || !player.implantChangesUntil.IsZero() || !player.treatmentLockedUntil.IsZero() || !reflect.DeepEqual(before, player.inventory) {
+ t.Fatalf("invalid clinic use changed state: %v", err)
+ }
+ for _, packet := range conn.packets {
+ if !bytes.Equal(packet[16:20], []byte{0x52, 0x52, 0x68, 0x58}) || binary.BigEndian.Uint32(packet[29:33]) != 2 {
+ t.Fatalf("rejected clinic use emitted effects: %x", packet)
+ }
+ }
+ })
+ }
+}
diff --git a/server/inventory.go b/server/inventory.go
@@ -167,11 +167,12 @@ func (server *server) handleInventory(client *worldClient, body []byte) error {
}
if index < 0 || (sourceSlot >= 64 && sourceType != 104) ||
(sourceSlot == 6 && 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 == 21 || destination == 30) {
+ if key == 0x47537a24 && (sourceSlot < 64 || destination == 6 || 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/main.go b/server/main.go
@@ -331,6 +331,9 @@ func (server *server) serveWorldClient(client *worldClient) error {
}
updates = append(updates, fullCharacterPacket(character))
updates = append(updates, equippedWeaponPackets(character)...)
+ if remaining := time.Until(character.treatmentLockedUntil); remaining > 0 {
+ updates = append(updates, treatmentLockPacket(character.id, uint32((remaining+time.Second-1)/time.Second)))
+ }
updates = append(updates, server.combatInterest_locked(client, nil)...)
updates = append(updates, gameTimePacket(character.id, server.gameSeconds_locked()))
spawn := characterPacket(character)
@@ -405,10 +408,14 @@ func (server *server) serveWorldClient(client *worldClient) error {
decodeInventory1491(body)
}
switch binary.BigEndian.Uint32(body[0:4]) {
+ case 0x2252445f:
+ if err := server.handleTargetSelection(client, body); err != nil {
+ return err
+ }
case 0x52526858:
var err error
if len(body) == 48 && (binary.BigEndian.Uint32(body[40:44]) == 104 || binary.BigEndian.Uint32(body[40:44]) == 51017) {
- err = server.handleBackpackUse(client, body)
+ err = server.handleOwnedItemUse(client, body)
} else if len(body) == 48 && (binary.BigEndian.Uint32(body[40:44]) == 51005 || binary.BigEndian.Uint32(body[40:44]) == 51059) {
err = server.handleTerminalUse(client, body)
} else {
diff --git a/server/roaming.go b/server/roaming.go
@@ -23,6 +23,7 @@ func (server *server) roamNPCs() {
server.advanceNPCRespawns(now)
server.advanceNPCs(now)
server.advanceEquipment(now)
+ server.advanceClinics(now)
server.advanceCombat(now)
server.advanceRegeneration(now)
}
diff --git a/server/state.go b/server/state.go
@@ -39,6 +39,8 @@ type character struct {
browserTokenHash string
resurrectionTerminal uint32
+ implantChangesUntil time.Time
+ treatmentLockedUntil time.Time
savedProfile playerProfile
savedPosition playerPosition
nextPositionSave time.Time
@@ -63,6 +65,7 @@ type worldClient struct {
reclaimItems []uint32
backpacks map[uint32]backpackHandle
useSequence uint32
+ selectedTarget [2]uint32
}
func (client *worldClient) send(packet []byte) error {
diff --git a/server/stats.go b/server/stats.go
@@ -15,10 +15,11 @@ type characterStats struct {
PhysicalInitiative uint16 `yaml:"physical_initiative"`
BodyDevelopment uint16 `yaml:"body_development"`
NanoPool uint16 `yaml:"nano_pool"`
+ Treatment uint16 `yaml:"treatment"`
}
func defaultCharacterStats() characterStats {
- return characterStats{10, 10, 10, 10, 10, 10, 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}
}
func (character *character) baseStats() characterStats {
diff --git a/server/target_protocol.go b/server/target_protocol.go
@@ -113,6 +113,10 @@ func targetPacket(packet []byte) []byte {
if packet[60] == 104 {
packet[61] -= 16
}
+ case 0x35505644:
+ if binary.BigEndian.Uint32(packet[56:60]) == 104 {
+ binary.BigEndian.PutUint32(packet[60:64], binary.BigEndian.Uint32(packet[60:64])-16)
+ }
case 0x52526858:
if len(packet) == 68 && binary.BigEndian.Uint32(packet[60:64]) == 104 {
binary.BigEndian.PutUint32(packet[64:68], binary.BigEndian.Uint32(packet[64:68])-16)
@@ -161,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 != 21 && destination != 30 && destination != 111 {
+ if binary.BigEndian.Uint32(body[24:28]) == 50000 && destination != 6 && destination != 21 && destination != 30 && destination != 37 && destination != 111 {
binary.BigEndian.PutUint32(body[32:36], decodeInventorySlot1491(destination))
}
case 0x5e477770:
diff --git a/server/users.go b/server/users.go
@@ -45,6 +45,8 @@ type playerProfile struct {
Running bool `yaml:"running"`
BrowserTokenHash string `yaml:"browser_token_hash,omitempty"`
ResurrectionTerminal uint32 `yaml:"resurrection_terminal,omitempty"`
+ ImplantChangesUntil time.Time `yaml:"implant_changes_until,omitempty"`
+ TreatmentLockedUntil time.Time `yaml:"treatment_locked_until,omitempty"`
}
type playerPosition struct {
@@ -172,6 +174,8 @@ func (server *server) loadUsers() error {
return fmt.Errorf("%s: unknown resurrection terminal", path)
}
server.characters[user.ID].resurrectionTerminal = profile.ResurrectionTerminal
+ server.characters[user.ID].implantChangesUntil = profile.ImplantChangesUntil
+ server.characters[user.ID].treatmentLockedUntil = profile.TreatmentLockedUntil
inventoryPath := filepath.Join("data/players", file.Name(), "inventory.yaml")
contents, err = os.ReadFile(inventoryPath)
if err != nil && !os.IsNotExist(err) {
@@ -221,7 +225,8 @@ func (server *server) users_locked() []userData {
func (server *server) saveUser_locked(character *character) error {
// Ordinary movement never rewrites identity, credentials or character properties.
profile := playerProfile{character.id, character.name, character.appearance, character.monsterData,
- character.level, character.baseStats(), character.running, character.browserTokenHash, character.resurrectionTerminal}
+ character.level, character.baseStats(), character.running, character.browserTokenHash, character.resurrectionTerminal,
+ character.implantChangesUntil, character.treatmentLockedUntil}
if profile == character.savedProfile {
return nil
}
diff --git a/server/world.go b/server/world.go
@@ -4,6 +4,7 @@ import (
"ao/server/gamedata"
"encoding/binary"
"math"
+ "time"
)
func n3Packet(key, identityType, instance uint32, body []byte) []byte {
@@ -162,8 +163,11 @@ func fullCharacterPacket(character *character) []byte {
body = binary.BigEndian.AppendUint32(body, 1009)
}
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, 100}, {124, 100}, {37, character.titleLevel()}}
+ 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, 100}, {124, uint32(base.Treatment)}, {37, character.titleLevel()}}
stats = append(stats, [2]uint32{51, uint32(character.aggDef)})
+ if time.Now().Before(character.implantChangesUntil) {
+ stats = append(stats, [2]uint32{224, 16})
+ }
stats = append(stats, [2]uint32{47, uint32(character.appearance >> 2 & 3)})
stats = append(stats, [2]uint32{214, character.nano}, [2]uint32{221, character.maximumNano()})
stats = append(stats, [2]uint32{100, uint32(base.MartialArts)}, [2]uint32{120, uint32(base.PhysicalInitiative)},