commit 9947ccf7fef60c2c87db91dbd6c233f3392d1406
parent a4beee14a7d51d07f921926be4894b007a5a7b22
Author: anon <anon@example.com>
Date: Thu, 22 Oct 2026 16:16:51 +0000
Support belt and NCU memory equipment
Diffstat:
13 files changed, 553 insertions(+), 47 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -69,9 +69,9 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
item leaves precisely the other item's contribution.
- [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
+- [x] Equip one belt. Check: the corresponding deck slots become available and
invalid belt removal cannot strand installed equipment.
-- [ ] Install one NCU memory. Check: available NCU changes by the item's amount
+- [x] Install one NCU memory. Check: available NCU changes by the item's amount
and remains correct after reconnect and removal.
- [x] Apply overequipping rules to one weapon. Check: dropping below a verified
requirement threshold changes effectiveness at the correct boundary.
@@ -84,6 +84,8 @@ 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).
+The Ti-100X belt, QL 1 memory, deck placement rules, native delays and persistent
+capacity checks are recorded in [belts and NCU](docs/belts-ncu.md).
## Combat calculations
diff --git a/docs/belts-ncu.md b/docs/belts-ncu.md
@@ -0,0 +1,143 @@
+# Belt and NCU memory in 14.9.1
+
+The supported items are exact QL 1 endpoints from
+`server/gamedata/items/items_001.yaml`, native type 51022, ItemClass 76 = 1.
+Their catalog action 8 requires Computer Literacy 161 strictly greater than 5.
+Neither has profession restrictions or authored removal requirements.
+
+| Item | Template | Native placement | OnWear modifier | EquipDelay 211 |
+| --- | --- | --- | --- | --- |
+| Belt Component Platform Ti-100X | 36783 | Page 101, slot 7 | BeltSlots 45 +1 | 7000 centiseconds, 70 seconds |
+| 2 - 3 NCU Memory | 36779 | Page 101, slots 9..14 | MaxNCU 181 +2 | 1000 centiseconds, 10 seconds |
+
+The shipped records have payload SHA-256 values
+`5cefb7653517d67f673ffc1d9b67915d615dffc7b90f1ebc1c20ee17c4aa9d94`
+and `139d9af1a46a516558f0dea5f558ab345fad2b257faca1bbba46722db157da13`.
+Historical 14.2.1 records corroborate the
+[belt](https://auno.org/ao/db.php?id=36783&patch=14020100) and
+[memory](https://auno.org/ao/db.php?id=36779&patch=14020100).
+The memory's name describes a range across qualities; this exact QL 1 item
+adds 2 NCU. Higher qualities and other belts are not yet supported.
+
+## Capacity and equipment rules
+
+Original client defaults establish BeltSlots 45 = 0, used NCU 180 = 0 and
+MaxNCU 181 = 8. With no active programs the native display is therefore:
+
+| Equipment | Enabled deck positions | Used / maximum NCU |
+| --- | --- | --- |
+| None | None | 0 / 8 |
+| Ti-100X belt | Slot 9, Deck 1 | 0 / 8 |
+| Belt and QL 1 memory | Slot 9, Deck 1 | 0 / 10 |
+| Memory removed, belt retained | Slot 9, Deck 1 | 0 / 8 |
+
+The memory's location mask is 0x7e00, permitting slots 9..14. Native validation
+also requires `slot - 9 < effective BeltSlots`. This one-slot belt therefore
+enables only slot 9. The server checks availability before beginning the move
+and again before committing it. Loading persisted inventory rejects memory
+in a disabled slot or without its belt.
+
+Belt removal requires every slot 9..14 to be empty, regardless of the class of
+the installed item. The native client enforces the same rule for belt
+replacement. The server rejects occupied equipment destinations generally;
+replacing equipped items remains outside its current move support. Native
+replacement timing would add both source and destination delays: 140 seconds
+for two of these belts, or 20 seconds for two of these memories.
+
+The client starts its equip timer and sends ContainerAddItem immediately.
+The server waits the authored delay once. A pending move leaves the saved item
+at its source; completion atomically saves the move before sending an
+acknowledgement or effects. Ownership, equipment combat restrictions, occupied
+positions and full ordinary inventory removal checks remain enforced.
+Unequipping does not require retaining the installation skill.
+
+Computer Literacy is a persisted base skill. Resource 1000204/161 assigns all
+its trickle weight to Intelligence: `[0,0,0,100,0,0]`. The native initializer
+sets its default base to 5. New and older profiles missing the field use that
+client baseline; historical server character-creation values remain unproven.
+The [recovered skill formula](combat-starting-stats.md) adds the ability
+contribution, while FullCharacter sends the base skill. In the fixture,
+Intelligence 10 plus base Computer Literacy 4 produces effective skill 6.
+
+Server equipment bonuses are derived from the equipped inventory's
+unconditional OnWear Modify 53045 functions. Belt capacity, NCU capacity and
+AC use this shared sum. Totals are not persisted as another mutable balance.
+Maximum NCU is native baseline 8 plus the equipped MaxNCU modifiers.
+
+Used NCU is distinct from maximum and free capacity: native buff bookkeeping
+adds or subtracts each program's NCU cost from stat 180. Active nano programs
+are not implemented by this milestone. Memory removal has no used-versus-maximum
+rejection in the recovered move validation, but the historical handling of
+existing buffs after capacity shrinks remains unresolved.
+
+## Native protocol and evidence
+
+Moves use ContainerAddItem `47537a24`. Installation starts from ordinary page
+104; belt/deck removal starts from page 101. Destination 111 requests the first
+free ordinary position. Only ordinary slots are translated between saved
+64..93 and native 48..77; equipment slots 7 and 9..14 keep their native values.
+
+TemplateAction `35505644` action 6 executes the item's OnWear effects; action 7
+removes them. Placement is page 101 and the actual worn slot. This differs from
+the catalog's action-8 requirement check. Utility items use these template
+effects and do not require a WeaponItem instance. Observer initialization sends
+the corresponding wear actions. The owner's FullCharacter already restores
+these effects, so it must not receive another wear action on initialization.
+
+Original `kkr.dll` SHA-256:
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+Addresses below use its original base 0x10000000; generated C uses 0x36000000.
+`local/reports/belt-ncu-protocol-1491-evidence.json` retains 26 REA records.
+Catalog, historical-page and skill-weight extracts are retained in
+`local/belt-ncu-smoke/source-ledger.json` and companion files.
+
+| Finding | Original function | Evidence ID |
+| --- | --- | --- |
+| Default belt, NCU and Computer Literacy stats | `10072760` | `ev_262150600e8d5205a324934ce17968bf1440814efc918e5344b3ad29103466e9` |
+| Enabled deck count | `1005dc80` | `ev_b76f6a7a32b0606c40b7871a088238279a97cfac4ca46c11929755ee760f7350` |
+| Belt removal and replacement restrictions | `10060510` | `ev_c0637c99b0b32adec9081a8f14509f3804654ea2e9cd93dd3d5f6f96b556c2aa` |
+| Owner equipment effect initialization | `1005f150` | `ev_2f66eca0926b9507b6a9bc79113271eb694bd9260f2b79cc46fa35a57f2923c9` |
+| Equip delay sum | `100628b0` | `ev_eca04975cbda45cb61403839b013e83355fd2635c09844a221e637a6b9ea84d2` |
+| Immediate move request | `1002a1f0` | `ev_178142dff667fea800df25ab5ae2730e84892895651154915ea1bb29f35215d3` |
+
+## Verification
+
+The maintained `go test ./server/... -count=1` suite passed in 88.445 seconds.
+Focused race checks for belt/NCU, existing equipment, backpacks, stats and world
+initialization passed in 121.596 seconds.
+
+Focused Go tests cover both requirement boundaries, persisted Computer Literacy
+and its missing-field default, real catalog delays, first-free removal,
+disabled deck positions, occupied equipment, unsupported item identities and
+qualities, interrupted installs, failed saves and invalid persisted deck state.
+The existing armor, implant and stack equipment tests also pass with the shared
+equipment bonus calculation.
+
+The two-client Chromium WASM run is retained in `local/belt-ncu-smoke/`, with
+screenshots, packet excerpts, seven read-only native inventory snapshots and
+`verification.json`. It used the full 70-second belt and 10-second memory
+delays. The server retained each item at its source until its deadline.
+Native checks observed:
+
+- Baseline 0/8 NCU; memory without a belt and Computer Literacy 5 were rejected.
+- Belt in native slot 7 and memory in slot 9, with 0/10 NCU after installation.
+- Rejected belt removal retained the installed memory, its capacity and both
+ memory copies. The observer kept an empty inventory and 0/8 NCU.
+- Server restart restored 0/10, without another +2 modifier.
+- Memory removal below the install-skill requirement returned to 0/8;
+ reinstallation at skill 6 restored 0/10, and another removal returned to 0/8.
+- Empty belt removal also worked below the install requirement, taking the
+ full 70 seconds. A second server restart restored both items in ordinary
+ inventory, no enabled deck positions, and 0/8 NCU.
+
+All seven item IDs and quantities matched saved inventory in the native heap.
+Projectile AC stayed 6, Melee AC 14 and attack rating 400 throughout; existing
+weapon, armor and implant slots were unaffected. A gesture aimed at disabled
+Deck 2 also triggered a request for the occupied preferred slot 9, so that
+gesture is not counted as direct native evidence of slot-10 server validation;
+the Go tests cover all disabled slots 10..14.
+
+There were no client exceptions or adapter failures. The 29 connection-refused
+console messages were confined to the two intentional server restarts. All
+test-owned browser contexts, servers and native analysis sessions were closed.
+The temporary fixture binary was removed.
diff --git a/server/armor_damage_test.go b/server/armor_damage_test.go
@@ -98,13 +98,13 @@ func TestArmorDamageBonusesFollowOwnershipAcrossRemovalAndRestart(t *testing.T)
player := world.characters[1]
world.handleInventory(world.clients[1], inventoryMovePacket(1, 66, 30)[20:])
world.advanceEquipment(world.clients[1].equipment.readyAt)
- before := [3]uint32{player.armorClass(90), player.armorClass(91), player.armorClass(94)}
+ before := [3]uint32{player.inventory.equipmentBonus(90), player.inventory.equipmentBonus(91), player.inventory.equipmentBonus(94)}
world.handleInventory(world.clients[1], itemMovePacket(1, scenario.slot, 111)[20:])
world.advanceEquipment(world.clients[1].equipment.readyAt)
world.handleInventory(world.clients[1], itemMovePacket(1, scenario.slot, 111)[20:])
restarted := newTestInventoryServer(t).characters[1]
- after := [3]uint32{restarted.armorClass(90), restarted.armorClass(91), restarted.armorClass(94)}
+ after := [3]uint32{restarted.inventory.equipmentBonus(90), restarted.inventory.equipmentBonus(91), restarted.inventory.equipmentBonus(94)}
if before != [3]uint32{1001, 876, 151} || after != scenario.armor || len(restarted.inventory.Items) != 4 {
t.Fatalf("armor contributions were duplicated or lost: before%v after%v items%+v", before, after, restarted.inventory.Items)
@@ -117,7 +117,7 @@ func TestArmorDamageBonusesFollowOwnershipAcrossRemovalAndRestart(t *testing.T)
}
world.handleInventory(world.clients[1], itemMovePacket(1, remaining, 111)[20:])
world.advanceEquipment(world.clients[1].equipment.readyAt)
- if player.armorClass(90) != 0 || player.armorClass(91) != 0 || player.armorClass(94) != 0 {
+ if player.inventory.equipmentBonus(90) != 0 || player.inventory.equipmentBonus(91) != 0 || player.inventory.equipmentBonus(94) != 0 {
t.Fatalf("unequipping retained armor bonuses: %+v", player.inventory)
}
})
diff --git a/server/belts_test.go b/server/belts_test.go
@@ -0,0 +1,329 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "os"
+ "reflect"
+ "strings"
+ "testing"
+ "time"
+)
+
+func newBeltWorld(t *testing.T) (*server, *combatTestConn) {
+ t.Helper()
+ world, conn := newArmorWorld(t)
+ world.characters[1].stats.ComputerLiteracy = 4
+ if err := world.saveUser_locked(world.characters[1]); err != nil {
+ t.Fatal(err)
+ }
+ for _, template := range []uint32{36783, 36779, 36779} {
+ if granted, err := world.grantItem_locked(world.characters[1], template); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ return world, conn
+}
+
+func TestBeltNCUEquipDelaysAndRestart(t *testing.T) {
+ world, conn := newBeltWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: player.playfield, health: 100}
+ world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true}
+
+ for _, move := range []struct {
+ source, destination uint32
+ delay time.Duration
+ }{{67, 7, 70 * time.Second}, {68, 9, 10 * time.Second}} {
+ before, err := os.ReadFile("data/players/1/inventory.yaml")
+ if err != nil {
+ t.Fatal(err)
+ }
+ packets := len(conn.packets)
+ started := time.Now()
+ if err := world.handleInventory(client, inventoryMovePacket(1, move.source, move.destination)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if client.equipment == nil {
+ t.Fatal("qualifying equipment was rejected")
+ }
+ finish := client.equipment.readyAt
+ if finish.Before(started.Add(move.delay)) || finish.After(time.Now().Add(move.delay)) {
+ t.Fatalf("catalog equip delay: %v", finish.Sub(started))
+ }
+ world.advanceEquipment(finish.Add(-time.Nanosecond))
+ unchanged, err := os.ReadFile("data/players/1/inventory.yaml")
+ if err != nil || !bytes.Equal(before, unchanged) || len(conn.packets) != packets {
+ t.Fatalf("pending equipment changed before its deadline: %v", err)
+ }
+ world.advanceEquipment(finish)
+ }
+ restored := newTestInventoryServer(t).characters[1]
+
+ if player.inventory.equipmentBonus(45) != 1 || player.maximumNCU() != 10 || restored.maximumNCU() != 10 ||
+ !reflect.DeepEqual(restored.inventory, player.inventory) || restored.stats.ComputerLiteracy != 4 {
+ t.Fatalf("belt or NCU state did not persist: %+v", restored)
+ }
+ if len(conn.packets) != 4 || len(observer.packets) != 2 || len(equippedItemPackets(restored)) != 2 {
+ t.Fatalf("equipment replication: owner=%d observer=%d", len(conn.packets), len(observer.packets))
+ }
+ for index, slot := range []uint32{7, 9} {
+ packet := conn.packets[index*2+1]
+ if binary.BigEndian.Uint32(packet[16:20]) != 0x35505644 || binary.BigEndian.Uint32(packet[45:49]) != 6 ||
+ binary.BigEndian.Uint32(packet[49:53]) != 101 || binary.BigEndian.Uint32(packet[53:57]) != slot ||
+ !bytes.Equal(packet[16:], observer.packets[index][16:]) {
+ t.Fatalf("native belt/deck effects: %x", packet)
+ }
+ }
+ 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[161] != 4 || values[45] != 0 || values[181] != 0 {
+ t.Fatalf("FullCharacter serialized effective skills or duplicated OnWear bonuses: %v", values)
+ }
+}
+
+func TestBeltRemovalRequiresEmptyDeck(t *testing.T) {
+ world, conn := newBeltWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ for _, move := range [][2]uint32{{67, 7}, {68, 9}} {
+ world.handleInventory(client, inventoryMovePacket(1, move[0], move[1])[20:])
+ world.advanceEquipment(client.equipment.readyAt)
+ }
+ before := player.inventory
+ conn.packets = nil
+
+ world.handleInventory(client, itemMovePacket(1, 7, 111)[20:])
+ if client.equipment != nil || !reflect.DeepEqual(before, player.inventory) || player.maximumNCU() != 10 || len(conn.packets) != 1 {
+ t.Fatal("belt removal stranded installed memory")
+ }
+ // Removal does not require retaining the install skill.
+ player.stats.ComputerLiteracy = 0
+ for _, slot := range []uint32{9, 7} {
+ world.handleInventory(client, itemMovePacket(1, slot, 111)[20:])
+ if client.equipment == nil {
+ t.Fatal("emptying the deck or removing the empty belt was rejected")
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ }
+ restored := newTestInventoryServer(t).characters[1]
+
+ if player.maximumNCU() != 8 || player.inventory.equipmentBonus(45) != 0 || restored.maximumNCU() != 8 ||
+ player.inventory.Items[3].Slot != 68 || player.inventory.Items[4].Slot != 67 || len(player.inventory.Items) != 6 {
+ t.Fatalf("belt/deck removal lost equipment or bonuses: %+v", player.inventory)
+ }
+ if len(conn.packets) != 5 || binary.BigEndian.Uint32(conn.packets[1][45:49]) != 7 ||
+ binary.BigEndian.Uint32(conn.packets[1][49:53]) != 101 || binary.BigEndian.Uint32(conn.packets[1][53:57]) != 9 ||
+ binary.BigEndian.Uint32(conn.packets[2][29:33]) != 101 {
+ t.Fatalf("native deck removal: %x", conn.packets)
+ }
+}
+
+func TestBeltAndMemoryRequireComputerLiteracySix(t *testing.T) {
+ for _, slot := range []uint32{7, 9} {
+ for _, skill := range []uint16{3, 4} {
+ t.Run(fmt.Sprintf("slot%d/base%d", slot, skill), func(t *testing.T) {
+ world, _ := newBeltWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ source := uint32(67)
+ if slot == 9 {
+ world.handleInventory(client, inventoryMovePacket(1, 67, 7)[20:])
+ world.advanceEquipment(client.equipment.readyAt)
+ source = 68
+ }
+ player.stats.ComputerLiteracy = skill
+ request := inventoryMovePacket(1, source-16, slot)[20:]
+
+ decodeInventory1491(request)
+ err := world.handleInventory(client, request)
+
+ if err != nil || (client.equipment != nil) != (skill == 4) || binary.BigEndian.Uint32(request[32:36]) != slot {
+ t.Fatalf("CL eligibility or native equipment position: pending=%+v err=%v", client.equipment, err)
+ }
+ })
+ }
+ }
+}
+
+func TestNCURejectsMissingBeltAndDisabledSlots(t *testing.T) {
+ for _, slot := range []uint32{9, 10, 11, 12, 13, 14} {
+ t.Run(fmt.Sprintf("slot%d", slot), func(t *testing.T) {
+ world, _ := newBeltWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ if slot != 9 {
+ world.handleInventory(client, inventoryMovePacket(1, 67, 7)[20:])
+ world.advanceEquipment(client.equipment.readyAt)
+ }
+ before := player.inventory
+
+ world.handleInventory(client, inventoryMovePacket(1, 68, slot)[20:])
+
+ if client.equipment != nil || player.maximumNCU() != 8 || !reflect.DeepEqual(before, player.inventory) {
+ t.Fatal("memory installed into a disabled deck slot")
+ }
+ })
+ }
+}
+
+func TestBeltRejectsAnyOccupiedDeckPosition(t *testing.T) {
+ for _, slot := range []uint32{9, 10, 11, 12, 13, 14} {
+ t.Run(fmt.Sprintf("slot%d", slot), func(t *testing.T) {
+ world, _ := newBeltWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ world.handleInventory(client, inventoryMovePacket(1, 67, 7)[20:])
+ world.advanceEquipment(client.equipment.readyAt)
+ // The native rule checks occupied positions, regardless of item class.
+ player.inventory.Items = append(player.inventory.Items, ownedItem{7, 51018, 121567, 1, slot, 1})
+
+ world.handleInventory(client, itemMovePacket(1, 7, 111)[20:])
+
+ if client.equipment != nil || player.inventory.Items[3].Slot != 7 {
+ t.Fatal("belt removal ignored an occupied deck position")
+ }
+ })
+ }
+}
+
+func TestNCUPendingMoveRechecksBeltAndRequirement(t *testing.T) {
+ for _, scenario := range []string{"belt removed", "skill lost", "failed save"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, _ := newBeltWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ world.handleInventory(client, inventoryMovePacket(1, 67, 7)[20:])
+ world.advanceEquipment(client.equipment.readyAt)
+ world.handleInventory(client, inventoryMovePacket(1, 68, 9)[20:])
+ finish := client.equipment.readyAt
+ switch scenario {
+ case "belt removed":
+ player.inventory.Items[3].Slot = 67
+ case "skill lost":
+ player.stats.ComputerLiteracy = 3
+ case "failed save":
+ 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.maximumNCU() != 8 || client.equipment != nil {
+ t.Fatal("interrupted NCU installation changed ownership or capacity")
+ }
+ })
+ }
+}
+
+func TestNCULoadRejectsStrandedEquipment(t *testing.T) {
+ for _, scenario := range []string{"without belt", "disabled slot"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, _ := newBeltWorld(t)
+ player := world.characters[1]
+ player.inventory.Items[4].Slot = 9
+ if scenario == "disabled slot" {
+ player.inventory.Items[3].Slot = 7
+ player.inventory.Items[4].Slot = 10
+ }
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ restored := &server{characters: make(map[uint32]*character)}
+
+ err := restored.loadUsers()
+
+ if err == nil {
+ t.Fatal("loaded NCU memory without its enabled deck position")
+ }
+ })
+ }
+}
+
+func TestBeltNCURejectsUnsupportedItemsAndOccupiedDeck(t *testing.T) {
+ for _, scenario := range []string{"belt quality", "belt type", "belt position", "memory quality", "memory type", "occupied deck"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, _ := newBeltWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ source, destination := uint32(67), uint32(7)
+ if strings.HasPrefix(scenario, "memory") || scenario == "occupied deck" {
+ world.handleInventory(client, inventoryMovePacket(1, 67, 7)[20:])
+ world.advanceEquipment(client.equipment.readyAt)
+ source, destination = 68, 9
+ }
+ switch scenario {
+ case "belt quality":
+ player.inventory.Items[3].Quality = 20
+ case "belt type":
+ player.inventory.Items[3].Type = 51005
+ case "belt position":
+ destination = 9
+ case "memory quality":
+ player.inventory.Items[4].Quality = 2
+ case "memory type":
+ player.inventory.Items[4].Type = 51005
+ case "occupied deck":
+ world.handleInventory(client, inventoryMovePacket(1, 69, 9)[20:])
+ world.advanceEquipment(client.equipment.readyAt)
+ }
+ before := player.inventory
+
+ world.handleInventory(client, inventoryMovePacket(1, source, destination)[20:])
+
+ if client.equipment != nil || !reflect.DeepEqual(before, player.inventory) {
+ t.Fatal("invalid or occupied equipment move changed ownership")
+ }
+ })
+ }
+}
+
+func TestNCURemovalRejectsWrongPageAndFullInventory(t *testing.T) {
+ world, _ := newBeltWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ for _, move := range [][2]uint32{{67, 7}, {68, 9}} {
+ world.handleInventory(client, inventoryMovePacket(1, move[0], move[1])[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
+ request := itemMovePacket(1, 9, 111)[20:]
+ binary.BigEndian.PutUint32(request[16:20], 102)
+
+ world.handleInventory(client, request)
+ world.handleInventory(client, itemMovePacket(1, 9, 111)[20:])
+
+ if client.equipment != nil || !reflect.DeepEqual(before, player.inventory) || player.maximumNCU() != 10 {
+ t.Fatal("rejected memory removal lost the item or its capacity")
+ }
+}
+
+func TestBeltLoadsMissingComputerLiteracy(t *testing.T) {
+ newBeltWorld(t)
+ contents, err := os.ReadFile("data/players/1/player.yaml")
+ if err != nil {
+ t.Fatal(err)
+ }
+ profile := strings.ReplaceAll(string(contents), " computer_literacy: 4\n", "")
+ if strings.Contains(profile, "computer_literacy") {
+ t.Fatal("fixture still contains Computer Literacy")
+ }
+ if err := os.WriteFile("data/players/1/player.yaml", []byte(profile), 0600); err != nil {
+ t.Fatal(err)
+ }
+
+ restored := newTestInventoryServer(t).characters[1]
+
+ if restored.stats.ComputerLiteracy != 5 || restored.stats.Strength != 8 || restored.maximumNCU() != 8 {
+ t.Fatalf("missing trained skill did not retain the native default: %+v", restored.stats)
+ }
+}
diff --git a/server/combat.go b/server/combat.go
@@ -173,7 +173,7 @@ func (attacker *character) normalDamage(target *character, roll func(uint32) uin
// Period AC rule: reduce the rolled hit without crossing the weapon minimum.
// Truncating AC/10 before subtraction is provisional integer ordering.
damage := minimum + roll(maximum-minimum+1)
- return damage - min(damage-minimum, target.armorClass(damageType)/10)
+ return damage - min(damage-minimum, target.inventory.equipmentBonus(damageType)/10)
}
func (server *server) combatInRange_locked(attacker, target *character, now time.Time) bool {
diff --git a/server/equipment.go b/server/equipment.go
@@ -20,28 +20,36 @@ func (item ownedItem) isKineticAxe() bool {
return item.Type == 51018 && item.Template == 209283 && item.Quality == 1
}
-func (item ownedItem) equipmentSlot() uint32 {
+func (item ownedItem) fitsEquipmentSlot(slot uint32) bool {
if item.isKineticAxe() {
- return 6
+ return slot == 6
}
if item.Type == 51022 && item.Template == 85685 && item.Quality == 200 {
- return 21
+ return slot == 21
}
if item.Type == 51022 && item.Quality == 1 {
switch item.Template {
case 85686:
- return 21
+ return slot == 21
case 85638:
- return 30
+ return slot == 30
case 101173:
- return 37
+ return slot == 37
+ case 36783:
+ return slot == 7
+ case 36779:
+ return slot >= 9 && slot <= 14
}
}
- return 0
+ return false
}
func (character *character) canEquip(item ownedItem) bool {
- if item.equipmentSlot() == 37 {
+ if item.fitsEquipmentSlot(7) || item.fitsEquipmentSlot(9) {
+ stats := character.baseStats()
+ return stats.effectiveSkill(stats.ComputerLiteracy, [6]uint32{0, 0, 0, 100, 0, 0}) > 5
+ }
+ if item.fitsEquipmentSlot(37) {
stats := character.baseStats()
return stats.Strength > 5 && stats.effectiveSkill(stats.Treatment, [6]uint32{0, 30, 0, 50, 20, 0}) > 10
}
@@ -55,11 +63,11 @@ func (character *character) canEquip(item ownedItem) bool {
return character.baseStats().Strength > 7 && character.baseStats().Agility > 7
}
-func (character *character) armorClass(stat uint32) uint32 {
- // 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 && item.Slot != 37 {
+func (inventory playerInventory) equipmentBonus(stat uint32) uint32 {
+ // Supported equipment has unconditional positive OnWear Modify effects.
+ var bonus uint32
+ for _, item := range inventory.Items {
+ if !item.fitsEquipmentSlot(item.Slot) {
continue
}
for _, section := range gamedata.ItemTemplates[item.Template].Sections {
@@ -68,12 +76,31 @@ func (character *character) armorClass(stat uint32) uint32 {
}
for _, function := range *section.Functions {
if function.ID == 53045 && uint32(*function.Arguments[0].Integer) == stat {
- armor += uint32(*function.Arguments[1].Integer)
+ bonus += uint32(*function.Arguments[1].Integer)
}
}
}
}
- return armor
+ return bonus
+}
+
+func (character *character) maximumNCU() uint32 {
+ return 8 + character.inventory.equipmentBonus(181)
+}
+
+func (character *character) canMoveEquipment(item ownedItem, destination uint32, now time.Time) bool {
+ if destination < 64 && (!item.fitsEquipmentSlot(destination) || !character.canEquip(item)) {
+ return false
+ }
+ if item.fitsEquipmentSlot(37) && !now.Before(character.implantChangesUntil) {
+ return false
+ }
+
+ // The native belt validator requires every deck position to be empty on removal.
+ if item.Slot == 7 && slices.ContainsFunc(character.inventory.Items, func(other ownedItem) bool { return other.Slot >= 9 && other.Slot <= 14 }) {
+ return false
+ }
+ return destination < 9 || destination > 14 || destination-9 < character.inventory.equipmentBonus(45)
}
func (character *character) meleeWeapon() *gamedata.Item {
@@ -107,7 +134,7 @@ func (character *character) canWieldKineticAxe() bool {
func itemMovePacket(owner, source, destination uint32) []byte {
page := uint32(104)
- if source == 6 {
+ if source == 6 || source == 7 || source >= 9 && source <= 14 {
page = 101
} else if source == 21 || source == 30 {
page = 102
@@ -145,10 +172,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)) ||
+ if destination == item.Slot || destination >= 94 || !character.canMoveEquipment(item, destination, time.Now()) ||
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))
@@ -156,7 +180,7 @@ 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 {
+ if item.fitsEquipmentSlot(37) {
// Beholder FUN_1008e840 defaults EquipDelay to 10; this implant has no override.
delay = 100 * time.Millisecond
}
@@ -184,8 +208,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])) ||
+ !character.canMoveEquipment(character.inventory.Items[index], move.destination, now) ||
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))
continue
@@ -201,7 +224,7 @@ 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 || move.source == 37 {
+ if 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 {
@@ -213,7 +236,7 @@ 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 || move.destination == 37 {
+ if 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 {
@@ -255,7 +278,9 @@ func equippedWeaponPackets(character *character) [][]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 {
+ if item.Slot < 16 {
+ page = 101
+ } else if item.Slot == 37 {
page = 103
}
var body []byte
@@ -268,7 +293,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 == 21 || item.Slot == 30 || item.Slot == 37 {
+ if 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/implants_test.go b/server/implants_test.go
@@ -45,10 +45,10 @@ func TestImplantClinicEquipBonusesAndRestart(t *testing.T) {
restarted := newTestInventoryServer(t)
restored := restarted.characters[1]
- if player.armorClass(91) != 14 || player.armorClass(90) != 6 || player.armorClass(94) != 2 || player.meleeWeapon() == nil {
+ if player.inventory.equipmentBonus(91) != 14 || player.inventory.equipmentBonus(90) != 6 || player.inventory.equipmentBonus(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 ||
+ if !reflect.DeepEqual(restored.inventory, player.inventory) || restored.inventory.equipmentBonus(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)
@@ -129,7 +129,7 @@ func TestImplantRemovalRetainsOtherEquipmentAndNeedsClinic(t *testing.T) {
before := player.inventory
world.handleInventory(client, itemMovePacket(1, 37, 111)[20:])
- if client.equipment != nil || !reflect.DeepEqual(before, player.inventory) || player.armorClass(91) != 14 {
+ if client.equipment != nil || !reflect.DeepEqual(before, player.inventory) || player.inventory.equipmentBonus(91) != 14 {
t.Fatal("implant removed after surgery access expired")
}
world.advanceClinics(player.treatmentLockedUntil)
@@ -141,7 +141,7 @@ func TestImplantRemovalRetainsOtherEquipmentAndNeedsClinic(t *testing.T) {
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 {
+ if restarted.characters[1].inventory.equipmentBonus(91) != 6 || player.inventory.equipmentBonus(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 ||
@@ -167,7 +167,7 @@ func TestImplantPendingMoveRechecksClinicAndSave(t *testing.T) {
world.advanceEquipment(finish)
- if player.inventory.Items[4].Slot != 68 || player.armorClass(91) != 0 || client.equipment != nil {
+ if player.inventory.Items[4].Slot != 68 || player.inventory.equipmentBonus(91) != 0 || client.equipment != nil {
t.Fatal("interrupted implant installation changed ownership or bonuses")
}
})
@@ -196,7 +196,7 @@ func TestImplantRemovalRejectsWrongPageAndFullInventory(t *testing.T) {
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 {
+ if client.equipment != nil || !reflect.DeepEqual(before, player.inventory) || player.inventory.equipmentBonus(91) != 8 {
t.Fatal("rejected removal lost an implant or its bonus")
}
}
diff --git a/server/inventory.go b/server/inventory.go
@@ -39,7 +39,7 @@ func (inventory playerInventory) validate() error {
for _, item := range inventory.Items {
if item.ID == 0 || item.ID > inventory.LastID || ids[item.ID] || item.Count == 0 ||
(item.Count != 1 && !item.isEssenceStack()) ||
- (item.Slot < 64 && (item.equipmentSlot() == 0 || item.Slot != item.equipmentSlot())) ||
+ (item.Slot < 64 && !item.fitsEquipmentSlot(item.Slot)) ||
item.Slot >= 94 || slots[item.Slot] {
return fmt.Errorf("invalid inventory item identity or slot")
}
@@ -48,6 +48,12 @@ func (inventory playerInventory) validate() error {
bags[item.ID] = true
}
}
+ deckSlots := inventory.equipmentBonus(45)
+ for slot := uint32(9); slot <= 14; slot++ {
+ if slots[slot] && slot-9 >= deckSlots {
+ return fmt.Errorf("equipment in a disabled deck slot")
+ }
+ }
for _, entry := range inventory.Reclaim {
if entry.Item.ID == 0 || entry.Item.ID > inventory.LastID || ids[entry.Item.ID] || entry.Item.Count == 0 ||
(entry.Item.Count != 1 && !entry.Item.isEssenceStack()) || entry.Item.Slot < 64 || entry.Item.Slot >= 94 {
@@ -166,13 +172,13 @@ func (server *server) handleInventory(client *worldClient, body []byte) error {
return server.syncStacks_locked(client)
}
if index < 0 || (sourceSlot >= 64 && sourceType != 104) ||
- (sourceSlot == 6 && sourceType != 101) ||
+ ((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 == 21 || destination == 30 || destination == 37) {
+ if key == 0x47537a24 && (sourceSlot < 64 || 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/stacks_test.go b/server/stacks_test.go
@@ -302,7 +302,7 @@ func TestStackRejectedSplitRebuildsOnlySupportedStacks(t *testing.T) {
if err != nil || len(deleted) != 29 || slices.Contains(deleted, 50) ||
!reflect.DeepEqual(moved, [][2]uint32{{48, 49}, {48, 54}}) || !reflect.DeepEqual(added, []uint32{3, 3}) ||
- !reflect.DeepEqual(player.inventory.Items, before) || player.armorClass(90) != 5 {
+ !reflect.DeepEqual(player.inventory.Items, before) || player.inventory.equipmentBonus(90) != 5 {
t.Fatalf("correction changed non-stack items/equipment or restored wrong slots: delete%v move%v count%v %v", deleted, moved, added, err)
}
}
diff --git a/server/stats.go b/server/stats.go
@@ -16,10 +16,11 @@ type characterStats struct {
BodyDevelopment uint16 `yaml:"body_development"`
NanoPool uint16 `yaml:"nano_pool"`
Treatment uint16 `yaml:"treatment"`
+ ComputerLiteracy uint16 `yaml:"computer_literacy"`
}
func defaultCharacterStats() characterStats {
- return characterStats{10, 10, 10, 10, 10, 10, 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}
}
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 != 21 && destination != 30 && destination != 37 && destination != 111 {
+ if binary.BigEndian.Uint32(body[24:28]) == 50000 && 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]) != "000003f10000763e0000003600000001" {
+ if hex.EncodeToString(full[57:73]) != "000003f100007a2f0000003600000001" {
t.Fatalf("target seventh list and first stat: %x", full[57:73])
}
}
diff --git a/server/world.go b/server/world.go
@@ -164,7 +164,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, 100}, {124, uint32(base.Treatment)}, {37, character.titleLevel()}}
- stats = append(stats, [2]uint32{51, uint32(character.aggDef)})
+ stats = append(stats, [2]uint32{51, uint32(character.aggDef)}, [2]uint32{161, uint32(base.ComputerLiteracy)})
if time.Now().Before(character.implantChangesUntil) {
stats = append(stats, [2]uint32{224, 16})
}