aorecomp

Anarchy Online classic in the browser

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


commit 9aa5131b632e7d674260a4348cebff6b241eff76
parent 04fc5e11f5959cd67a8c497b2cbee1df1abbdcd3
Author: anon <anon@example.com>
Date:   Sat, 24 Oct 2026 22:24:08 +0000

Support catalog clothing and shared equipment requirements

Diffstat:
MTODO.md | 23+++++++++++++++++++----
Mdocs/armor.md | 4+++-
Adocs/clothing.md | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/armor_overequipping.go | 21+++++++--------------
Aserver/clothing.go | 33+++++++++++++++++++++++++++++++++
Aserver/clothing_test.go | 243+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/equipment.go | 32++++++--------------------------
Aserver/equipment_requirements.go | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/equipment_requirements_test.go | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/equipment_test.go | 4++--
Mserver/starter_weapons_test.go | 2+-
Mserver/weapon_stats.go | 26--------------------------
12 files changed, 536 insertions(+), 74 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -109,7 +109,7 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). Meta Shield's three +10 AC bonuses follow its equipment state. See [catalog weapons](docs/catalog-weapons.md). - [ ] Extend catalog weapons beyond current exact-QL, main-hand support. Check: - recover interpolation endpoint families, OR/NOT/faction-rank/unsupported-stat + recover interpolation endpoint families, faction-rank/unsupported-stat requirements, original malformed damage ranges (including template 123868), all OnWear/OnHit functions and action gates. Do not silently satisfy unknown requirements or invent normalization for reversed min/max damage. @@ -117,6 +117,12 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). trips, checking source-row usability, later re-equip and exactly-once bonuses. - [x] Equip one armor piece. Check: the correct native slot and appearance update, and its armor stats appear and disappear with equip/unequip. +- [x] Admit clothing through shared catalog slot/effect rules and native postfix + requirements. Check: the issued Omni shirt adds/removes 10 Melee AC and its + appearance on both WASM clients; wrong-faction wear retains the item. Both + basic boards wear at the neck without invented faction gates or bonuses. + Item identities and effects survive a cold server restart. See + [catalog clothing](docs/clothing.md) for supported effects and remaining gaps. - [x] Apply one equipment stat bonus. Check: a known bonus affects derived stats exactly once and unequipping restores the baseline. - [x] Combine two equipment bonuses to the same stat. Check: removing either @@ -469,13 +475,22 @@ introduction and starting-item gameplay remain open below. one QL1 robot shell. This does not complete their gameplay support. Audit equip/use/unequip, requirements, charge consumption, deaths/reclaim and cold recovery for every issued item. Starter weapons now equip and attack through - shared catalog rules, including Meta Shield AC and solar Fling. Startup - crystals, healing-kit use, maps, shell, boards, shirt and remaining weapon - specials (Burst, Aimed Shot, Brawl and Dimach) still need gameplay support. + shared catalog rules, including Meta Shield AC and solar Fling. + Omni shirt and basic boards now wear through shared catalog clothing rules; + owner/observer appearance/AC, faction rejection and cold recovery are verified. + Startup crystals, healing-kit use, maps, shell, board upgrades and remaining + weapon specials (Burst, Aimed Shot, Brawl and Dimach) still need gameplay support. Verify those actions and each starting profession in its real training ground. Corroborate the four provisional pistol allocations, MA Oak Bo allocation, and observed laboratory/first-aid issue counts 25/3; see [starting-state evidence](docs/character-creation.md). +- [ ] Complete catalog clothing gameplay beyond shared wear/stat modifiers. + Verify exact-QL slot masks and postfix requirements across armor, social + clothing and jewelry. Implement remaining OnWear gameplay functions and + stats, expansion/token predicates, use/upgrade actions and reviewed quality + endpoint pairs. Keep unsupported effects explicit rather than granting + partial bonuses silently. Audit the older Pre-Universe container action-8 + fallback against the native action-6 gate. See [clothing](docs/clothing.md). - [ ] Reconstruct the original Arrival Hall and training-ground introduction. Check all three factions' entry/exit flow, authored tutorial NPC identities, dialogues, starter instructions and camera state. Replace training NPC diff --git a/docs/armor.md b/docs/armor.md @@ -22,7 +22,9 @@ equipment tick. Stat 298 supplies the permitted armor-slot mask, starting at 16; stat 88 supplies the default position within that range. Sleeves permit both bits 7 and 9, so two separate instances can be worn together. The native inventory remains 48..77; armor slots are not shifted by the ordinary-inventory -conversion. Other armor families remain explicitly unsupported. +conversion. Other clothing can use exact authored qualities through the shared +[catalog clothing rules](clothing.md); their intermediate qualities remain +unsupported until endpoint pairing is established. The chest's OnWear section (type 2, subtype 14) adds 5 to AC stats 90..93 and 1 to 94..97. The boots add 1 to all eight. These are authored Modify 53045 diff --git a/docs/clothing.md b/docs/clothing.md @@ -0,0 +1,91 @@ +# Catalog clothing in 14.9.1 + +Clothing admission uses the item's actual native type 51022, ItemType 76 equal +to 2, Can 30 bit 4, and slot mask 298. Clothing mask bit zero means absolute +slot 16. A template's header must match the owned identity type. Qualities must +equal the authored record, except for the existing reviewed Metaplast pairs. +This avoids treating vehicles, belts, NCU and implants as body clothing merely +because they share native type 51022. + +The original `kkr.dll` SHA-256 is +`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`. +Dispatcher `10060510` routes ItemTypes 2/3 to the common gate `10090970`, +which checks CanWear and action 6. Missing action 6 succeeds. ItemType 1 uses +`10090c70` and action 8. Move sender `1002a1f0` adds 16 to clothing slots and +32 to implant slots; utility/weapon slots remain unshifted. Retained evidence +and the five starter/vehicle catalog records are under +`local/starter-equipment-research/`. + +The shared server requirement interpreter follows the native postfix stack +for equality, strict comparisons, AND, OR and NOT. Empty lists succeed; the +final top value is the result, with no implicit AND for leftover operands. +Unknown stats/operators and stack underflow fail the entire evaluation, even +inside an OR or NOT. Unequal is supported for intrinsic breed, faction, title, +level, sex, profession and race; other stats need proof of native getter-mode +2 semantics. Metaplast requirement values retain quality interpolation. +See [requirement evidence](combat-client-requirements.md). + +## Effects and starter gifts + +OnWear Skill 53012 and Modify 53045 contribute their authored signed stat +amounts. Both use native additive handler `100bd600` (Modify wrapper +`100bd4d0`); removal subtracts the corresponding instance contribution. +Supported clothing modifiers must be unconditional, target the wearer, and +have one tick with zero interval. Native mesh, texture and visual handlers +53030/53035/53037/53038/53039/53054/53055/53079 remain client presentation. +53051, 53100 and 53162 do nothing in this client, which does not establish +their authoritative server meaning. They and other unknown OnWear functions +are rejected until their gameplay effects are understood and implemented. +See [effect handlers](combat-client-effect-handlers.md). + +| Starter gift | Template | Absolute slot | Wear criteria | OnWear | +| --- | ---: | ---: | --- | --- | +| Omni-Tek Shirt | 29426 | 21, chest | Side 33 equals 2 | Melee AC 91 +10; texture 14038/category 1 | +| Clan Merits - Basic Board | 96358 | 17, neck | None | None | +| Omni-Tek Award - Basic Board | 99719 | 17, neck | None | None | + +The basic boards' faction/token predicates belong to their use/upgrade +functions. They do not restrict wearing and do not grant the next board's +advertised bonuses. Since both have CanUse bit 8, native right-click invokes +use; drag them to the neck slot to wear. Token collection and upgrades remain +unimplemented. + +Wear completion rechecks requirements and commits the existing item identity +and destination atomically before notifying owner and observers. Failed +validation/persistence leaves the source item intact. Cold bootstrap uses +the existing native OnWear reconstruction, avoiding duplicate effects. +Armor overequipping now obtains all six abilities and supported skills from +the shared stat lookup, and ignores zero raw thresholds without division. +Signed penalties still apply per effect using the recovered armor table. + +## Remaining boundaries + +This is catalog admission and shared stat-modifier support, not full gameplay +for every garment. Expansion/token predicates, unmodeled stats, active +OnWear effects, use actions and unpaired intermediate qualities remain open. +The existing Pre-Universe wearable-container action-8 fallback is a separate +server policy: its ItemType 2 native common gate reads action 6 only. Resolve +that older uncertainty before claiming universal container requirements. + +## Verification + +Public inventory-move tests cover all factions for the three gifts, real +Pilgrim armor profession alternatives and strict Stamina boundaries, malformed +and unknown criteria, unsupported/conditional/repeating effects, completion +revalidation, failed writes, item conservation and cold recovery. All six +abilities are checked across armor OE tiers, including a zero raw threshold +with a negative effective ability. +Counterfactual runs against the preceding implementation reproduce the missing +admission and boolean-expression handling. + +Two actual GPU/OpenGL WASM clients verified a newly issued shirt's +appearance and Melee AC sequence 10/0/10 for wear/removal/re-wear on owner and +observer. A Clan wear attempt retained the shirt with zero AC. Both basic +boards reached neck slot 17, including a Clan board worn by an Omni character, +with zero added AC. After a cold server restart the same shirt/board instance +IDs and slots returned, with exactly 10 Melee AC on both clients. Screenshots, +native heap observations, WebSocket traces and SQLite snapshots are retained +under `local/starter-equipment-smoke/`. Browser errors remained empty. +The final conservative unknown-effect guard was also exercised in the built +server with two WASM clients; its snapshots and production source hashes are +under `local/clothing-final-smoke/`. diff --git a/server/armor_overequipping.go b/server/armor_overequipping.go @@ -29,7 +29,6 @@ func (character *character) armorOverequippingTier(item ownedItem) uint32 { // FUN_10062f80/10090f10 uses action 6 and every operator-2 criterion. low, high := item.templateIDs() first, second := gamedata.ItemTemplates[low], gamedata.ItemTemplates[high] - stats := character.baseStats() var tier uint32 for sectionIndex, section := range first.Sections { if section.Actions == nil { @@ -43,20 +42,14 @@ func (character *character) armorOverequippingTier(item ownedItem) uint32 { if requirement.Operator != 2 { continue } - var actual int32 - switch requirement.Stat { - case 16, 17, 19: - actual = character.effectiveAbility(uint32(requirement.Stat)) - case 37: - actual = int32(character.titleLevel()) - case 54: - actual = int32(character.level) - case 137: - actual = character.effectiveSkill(137, stats.Body.Adventuring, [6]uint32{20, 50, 30, 0, 0, 0}) - case 161: - actual = character.effectiveSkill(161, stats.TradeRepair.ComputerLiteracy, [6]uint32{0, 0, 0, 100, 0, 0}) - } value := interpolateItemValue(requirement.Value, (*second.Sections[sectionIndex].Actions)[actionIndex].Requirements[index].Value, *first.Quality, *second.Quality, item.Quality) + if value == 0 { + continue + } + actual, known := character.effectiveStat(uint32(requirement.Stat)) + if !known { + return 4 + } if actual < value { tier = max(tier, min(4, uint32((int64(value)-int64(actual))*5/int64(value)))) } diff --git a/server/clothing.go b/server/clothing.go @@ -0,0 +1,33 @@ +package main + +import "ao/server/gamedata" + +func (item ownedItem) isClothing() bool { + definition := gamedata.ItemTemplates[item.Template] + if item.Type != 51022 || definition == nil || definition.HeaderWords[0] != item.Type || + itemStat(definition, 76) != 2 || itemStat(definition, 30)&4 == 0 || + !item.isMetaplast() && item.Quality != *definition.Quality { + return false + } + + // Admit stat modifiers and native presentation, not unimplemented gameplay effects. + for _, section := range definition.Sections { + if section.Type != 2 || section.Subtype != 14 { + continue + } + for _, function := range *section.Functions { + switch function.ID { + case 53012, 53045: + if function.Target != 2 || len(function.Requirements) != 0 || function.TickCount != 1 || function.TickInterval != 0 { + return false + } + case 53030, 53035, 53037, 53038, 53039, 53054, 53055, 53079: + // Mesh, texture and visual effects execute in the native client. + default: + // A client no-op does not establish a server-side no-op. + return false + } + } + } + return true +} diff --git a/server/clothing_test.go b/server/clothing_test.go @@ -0,0 +1,243 @@ +package main + +import ( + "ao/server/gamedata" + "bytes" + "encoding/binary" + "fmt" + "reflect" + "slices" + "testing" +) + +func TestStarterClothingWearRestrictionsAndColdRecovery(t *testing.T) { + for _, template := range []uint32{29426, 96358, 99719} { + for side := uint16(0); side <= 2; side++ { + t.Run(fmt.Sprintf("%d/side%d", template, side), func(t *testing.T) { + world, owner := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + appearance := unpackAppearance(player.appearance) + appearance.Side = side + player.appearance = appearance.packed() + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51022, Template: template, Quality: 1, Slot: 64, Count: 1} + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + before, _ := readTestItemStore(world) + observer := &combatTestConn{} + world.characters[2] = &character{id: 2, playfield: 950, health: 100} + world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true} + slot, bonus := uint32(17), int32(0) + if template == 29426 { + slot, bonus = 21, 10 + } + + if err := world.handleInventory(client, inventoryMovePacket(1, 64, slot)[20:]); err != nil { + t.Fatal(err) + } + if template == 29426 && side != 2 { + after, _ := readTestItemStore(world) + if client.equipment != nil || !bytes.Equal(before, after) || player.inventory.Items[0].Slot != 64 || len(owner.packets) != 2 || len(observer.packets) != 0 { + t.Fatal("wrong-side shirt request changed ownership or equipment") + } + return + } + if client.equipment == nil { + t.Fatal("catalog clothing was rejected") + } + world.advanceEquipment(client.equipment.readyAt) + restored := newTestInventoryServer(t).characters[1] + if err := world.handleInventory(client, itemMovePacket(1, slot, 111)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + removed := newTestInventoryServer(t).characters[1] + + if !reflect.DeepEqual(restored.inventory.Items, []ownedItem{{ID: 1, Type: 51022, Template: template, Quality: 1, Slot: slot, Count: 1}}) || + !reflect.DeepEqual(removed.inventory.Items, []ownedItem{{ID: 1, Type: 51022, Template: template, Quality: 1, Slot: 64, Count: 1}}) || + restored.equipmentBonus(91) != bonus || removed.equipmentBonus(91) != 0 || player.equipmentBonus(91) != 0 { + t.Fatal("wear/removal lost identity, persisted the wrong slot or misapplied AC") + } + if len(owner.packets) != 4 || len(observer.packets) != 2 || + binary.BigEndian.Uint32(owner.packets[1][16:20]) != 0x35505644 || + !bytes.Equal(owner.packets[1][16:], observer.packets[0][16:]) || + binary.BigEndian.Uint32(observer.packets[1][45:49]) != 7 { + t.Fatal("owner and observer did not receive the same wear/removal effects") + } + }) + } + } +} + +func TestCatalogClothingProfessionAlternativesAndStrictAbilityBounds(t *testing.T) { + for _, scenario := range []struct { + profession uint16 + stamina uint16 + accepted bool + }{{1, 10, true}, {9, 10, true}, {2, 10, false}, {1, 9, false}} { + t.Run(fmt.Sprintf("profession%d/stamina%d", scenario.profession, scenario.stamina), func(t *testing.T) { + world, _ := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + appearance := unpackAppearance(player.appearance) + appearance.Side = 1 + player.appearance = appearance.packed() + player.profession, player.stats.Abilities.Stamina = scenario.profession, scenario.stamina + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51022, Template: 201201, Quality: 1, Slot: 64, Count: 1} + + err := world.handleInventory(client, inventoryMovePacket(1, 64, 27)[20:]) + if client.equipment != nil { + world.advanceEquipment(client.equipment.readyAt) + } + + if err != nil || (player.inventory.Items[0].Slot == 27) != scenario.accepted { + t.Fatal("catalog AND/OR expression or strict stamina boundary was misinterpreted", err) + } + }) + } +} + +func TestClothingRejectedEffectsAndPlacementPreserveItems(t *testing.T) { + for _, scenario := range []string{"wrong slot", "wrong quality", "wrong identity", "cannot wear", "unsupported effect", "client no-op", "conditional modifier", "wrong target", "repeated modifier", "modifier interval", "changed faction", "failed save"} { + t.Run(scenario, func(t *testing.T) { + world, owner := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + player.appearance = (appearanceFields{Race: 1, Breed: 1, Sex: 2, Side: 2}).packed() + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51022, Template: 29426, Quality: 1, Slot: 64, Count: 1} + original := gamedata.ItemTemplates[29426] + definition := *original + definition.Stats = slices.Clone(original.Stats) + if scenario == "cannot wear" { + for index, stat := range definition.Stats { + if stat[0] == 30 { + definition.Stats[index][1] &^= 4 + } + } + } + switch scenario { + case "unsupported effect", "client no-op", "conditional modifier", "wrong target", "repeated modifier", "modifier interval": + definition.Sections = slices.Clone(original.Sections) + functions := slices.Clone(*definition.Sections[0].Functions) + switch scenario { + case "unsupported effect": + functions[0].ID = 53002 + case "client no-op": + functions[0].ID = 53051 + case "conditional modifier": + functions[0].Requirements = []gamedata.ItemRequirement{{Stat: 33, Value: 2, Operator: 0}} + case "wrong target": + functions[0].Target = 3 + case "repeated modifier": + functions[0].TickCount = 2 + case "modifier interval": + functions[0].TickInterval = 1 + } + definition.Sections[0].Functions = &functions + } + gamedata.ItemTemplates[29426] = &definition + t.Cleanup(func() { gamedata.ItemTemplates[29426] = original }) + destination := uint32(21) + if scenario == "wrong slot" { + destination = 18 + } else if scenario == "wrong quality" { + player.inventory.Items[0].Quality = 2 + } else if scenario == "wrong identity" { + player.inventory.Items[0].Type = 51018 + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + before, _ := readTestItemStore(world) + + err := world.handleInventory(client, inventoryMovePacket(1, 64, destination)[20:]) + if scenario == "changed faction" || scenario == "failed save" { + if client.equipment == nil { + t.Fatal("valid initial wear did not start") + } + if scenario == "changed faction" { + player.appearance = (appearanceFields{Race: 1, Breed: 1, Sex: 2, Side: 1}).packed() + } else { + world.db.Close() + } + world.advanceEquipment(client.equipment.readyAt) + } + restored := newTestInventoryServer(t).characters[1] + + if err != nil || client.equipment != nil || player.inventory.Items[0].Slot != 64 || + !reflect.DeepEqual(player.inventory.Items, restored.inventory.Items) || player.equipmentBonus(91) != 0 || len(owner.packets) != 2 { + t.Fatal("rejected/failed wear lost the item or published a bonus", err) + } + if scenario != "failed save" { + after, _ := readTestItemStore(world) + if !bytes.Equal(before, after) { + t.Fatal("rejected wear changed persisted equipment") + } + } + }) + } +} + +func TestClothingAllAbilitiesDriveOverequipping(t *testing.T) { + for _, stat := range []int32{16, 17, 18, 19, 20, 21} { + t.Run(fmt.Sprint(stat), func(t *testing.T) { + world, _ := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + original := gamedata.ItemTemplates[29426] + definition := *original + actions := []gamedata.ItemAction{{Type: 6, Requirements: []gamedata.ItemRequirement{{Stat: stat, Value: 9, Operator: 2}}}} + definition.Sections = slices.Clone(original.Sections) + definition.Sections[1].Actions = &actions + gamedata.ItemTemplates[29426] = &definition + t.Cleanup(func() { gamedata.ItemTemplates[29426] = original }) + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51022, Template: 29426, Quality: 1, Slot: 64, Count: 1} + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 21)[20:]); err != nil || client.equipment == nil { + t.Fatal("qualified clothing did not begin wear", err) + } + world.advanceEquipment(client.equipment.readyAt) + + for _, scenario := range []struct { + ability uint16 + bonus int32 + }{{9, 10}, {7, 8}, {5, 5}, {3, 3}, {0, 0}, {10, 10}} { + player.stats.Abilities = characterAbilitiesStats{scenario.ability, scenario.ability, scenario.ability, scenario.ability, scenario.ability, scenario.ability} + bonus := player.equipmentBonus(91) + + if bonus != scenario.bonus || player.inventory.Items[0].ID != 1 || player.inventory.Items[0].Slot != 21 { + t.Fatalf("ability %d: AC %d, want %d; equipment %+v", scenario.ability, bonus, scenario.bonus, player.inventory.Items) + } + } + }) + } +} + +func TestClothingSkillEffectAndZeroOverequippingThreshold(t *testing.T) { + world, _ := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + original := gamedata.ItemTemplates[29426] + definition := *original + definition.Sections = slices.Clone(original.Sections) + functions := slices.Clone(*definition.Sections[0].Functions) + functions[0].ID = 53012 + definition.Sections[0].Functions = &functions + actions := []gamedata.ItemAction{{Type: 6, Requirements: []gamedata.ItemRequirement{{Stat: 18, Value: 0, Operator: 2}}}} + definition.Sections[1].Actions = &actions + gamedata.ItemTemplates[29426] = &definition + t.Cleanup(func() { gamedata.ItemTemplates[29426] = original }) + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51022, Template: 29426, Quality: 1, Slot: 64, Count: 1} + + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 21)[20:]); err != nil || client.equipment == nil { + t.Fatal("qualified Skill modifier garment was rejected", err) + } + world.advanceEquipment(client.equipment.readyAt) + player.stats.Abilities.Stamina = 0 + player.activeNanos = syntheticNanoModifiers(t, [][2]int32{{18, -10}}) + bonus := player.equipmentBonus(91) + world.handleInventory(client, itemMovePacket(1, 21, 111)[20:]) + world.advanceEquipment(client.equipment.readyAt) + + if player.effectiveAbility(18) != -10 || bonus != 10 || player.equipmentBonus(91) != 0 || player.inventory.Items[0].Slot != 64 { + t.Fatal("Skill modifier or zero-denominator OE changed its native semantics") + } +} diff --git a/server/equipment.go b/server/equipment.go @@ -26,7 +26,7 @@ func (item ownedItem) fitsEquipmentSlot(slot uint32) bool { if item.isWieldableWeapon() { return slot == 6 } - if item.isMetaplast() { + if item.isClothing() { return slot >= 16 && slot < 32 && itemStat(gamedata.ItemTemplates[item.Template], 298)&(1<<(slot-16)) != 0 } if item.Type == 51022 && item.Quality == 1 { @@ -65,30 +65,10 @@ func (character *character) canEquip(item ownedItem) bool { return character.effectiveAbility(16) > 5 && character.effectiveSkill(124, stats.NanoAiding.Treatment, [6]uint32{0, 30, 0, 50, 20, 0}) > 10 } if item.isWieldableWeapon() { - return character.weaponRequirementsMet(item) - } - if item.isMetaplast() { - low, high := item.templateIDs() - first, second := gamedata.ItemTemplates[low], gamedata.ItemTemplates[high] - // These authored wear lists require Strength and Agility with strict bounds. - for sectionIndex, section := range first.Sections { - if section.Actions == nil { - continue - } - for actionIndex, action := range *section.Actions { - if action.Type != 6 { - continue - } - for index, requirement := range action.Requirements { - value := interpolateItemValue(requirement.Value, (*second.Sections[sectionIndex].Actions)[actionIndex].Requirements[index].Value, *first.Quality, *second.Quality, item.Quality) - if requirement.Stat == 16 && character.effectiveAbility(16) <= value || - requirement.Stat == 17 && character.effectiveAbility(17) <= value { - return false - } - } - } - } - return true + return character.equipmentRequirementsMet(item, 8) + } + if item.isClothing() { + return character.equipmentRequirementsMet(item, 6) } return false } @@ -114,7 +94,7 @@ func (item ownedItem) equipmentBonus(stat, tier uint32) int32 { continue } for index, function := range *section.Functions { - if function.ID == 53045 && uint32(*function.Arguments[0].Integer) == stat { + if (function.ID == 53012 || function.ID == 53045) && uint32(*function.Arguments[0].Integer) == stat { value := interpolateItemValue(*function.Arguments[1].Integer, *(*second.Sections[sectionIndex].Functions)[index].Arguments[1].Integer, *first.Quality, *second.Quality, item.Quality) // FUN_10063130/10062f60: subtract each signed, truncated penalty. bonus += value - value*int32(tier)/4 diff --git a/server/equipment_requirements.go b/server/equipment_requirements.go @@ -0,0 +1,73 @@ +package main + +import "ao/server/gamedata" + +func (character *character) equipmentRequirementsMet(item ownedItem, actionType uint32) bool { + low, high := item.templateIDs() + first, second := gamedata.ItemTemplates[low], gamedata.ItemTemplates[high] + for sectionIndex, section := range first.Sections { + if section.Actions == nil { + continue + } + for actionIndex, action := range *section.Actions { + if action.Type != actionType { + continue + } + + // kkr.dll 100056e0 evaluates postfix operators without short circuiting. + var stack []bool + for index, requirement := range action.Requirements { + switch requirement.Operator { + case 3, 4: + if len(stack) < 2 { + return false + } + last := len(stack) - 1 + if requirement.Operator == 3 { + stack[last-1] = stack[last-1] || stack[last] + } else { + stack[last-1] = stack[last-1] && stack[last] + } + stack = stack[:last] + case 42: + if len(stack) == 0 { + return false + } + stack[len(stack)-1] = !stack[len(stack)-1] + case 0, 1, 2, 24: + // Unequal uses getter mode 2. Only intrinsic stats have proven parity. + if requirement.Operator == 24 { + switch requirement.Stat { + case 4, 33, 37, 54, 59, 60, 89: + default: + return false + } + } + actual, known := character.effectiveStat(uint32(requirement.Stat)) + if !known { + return false + } + value := interpolateItemValue(requirement.Value, (*second.Sections[sectionIndex].Actions)[actionIndex].Requirements[index].Value, *first.Quality, *second.Quality, item.Quality) + passed := actual == value + switch requirement.Operator { + case 1: + passed = actual < value + case 2: + passed = actual > value + case 24: + passed = actual != value + } + stack = append(stack, passed) + default: + // Unknown predicates cannot grant equipment, including inside OR/NOT. + return false + } + } + // Native evaluation accepts an empty list and returns the final top value. + if len(stack) != 0 && !stack[len(stack)-1] { + return false + } + } + } + return true +} diff --git a/server/equipment_requirements_test.go b/server/equipment_requirements_test.go @@ -0,0 +1,58 @@ +package main + +import ( + "ao/server/gamedata" + "testing" +) + +func TestEquipmentPostfixRequirementsThroughInventoryMove(t *testing.T) { + for _, scenario := range []struct { + name string + requirements []gamedata.ItemRequirement + accepted bool + }{ + {"empty", nil, true}, + {"strict greater pass", []gamedata.ItemRequirement{{Stat: 16, Value: 9, Operator: 2}}, true}, + {"strict greater equality", []gamedata.ItemRequirement{{Stat: 16, Value: 10, Operator: 2}}, false}, + {"strict less pass", []gamedata.ItemRequirement{{Stat: 16, Value: 11, Operator: 1}}, true}, + {"strict less equality", []gamedata.ItemRequirement{{Stat: 16, Value: 10, Operator: 1}}, false}, + {"unequal pass", []gamedata.ItemRequirement{{Stat: 33, Value: 1, Operator: 24}}, true}, + {"unequal fail", []gamedata.ItemRequirement{{Stat: 33, Value: 0, Operator: 24}}, false}, + {"unproven getter mode", []gamedata.ItemRequirement{{Stat: 16, Value: 9, Operator: 24}}, false}, + {"OR pass", []gamedata.ItemRequirement{{Stat: 33, Value: 1, Operator: 0}, {Stat: 16, Value: 10, Operator: 0}, {Operator: 3}}, true}, + {"OR fail", []gamedata.ItemRequirement{{Stat: 33, Value: 1, Operator: 0}, {Stat: 16, Value: 11, Operator: 0}, {Operator: 3}}, false}, + {"AND pass", []gamedata.ItemRequirement{{Stat: 33, Value: 0, Operator: 0}, {Stat: 16, Value: 10, Operator: 0}, {Operator: 4}}, true}, + {"AND fail", []gamedata.ItemRequirement{{Stat: 33, Value: 1, Operator: 0}, {Stat: 16, Value: 10, Operator: 0}, {Operator: 4}}, false}, + {"NOT pass", []gamedata.ItemRequirement{{Stat: 33, Value: 1, Operator: 0}, {Operator: 42}}, true}, + {"NOT fail", []gamedata.ItemRequirement{{Stat: 33, Value: 0, Operator: 0}, {Operator: 42}}, false}, + {"no implicit AND", []gamedata.ItemRequirement{{Stat: 33, Value: 1, Operator: 0}, {Stat: 16, Value: 10, Operator: 0}}, true}, + {"AND underflow", []gamedata.ItemRequirement{{Operator: 4}}, false}, + {"OR underflow", []gamedata.ItemRequirement{{Stat: 16, Value: 10, Operator: 0}, {Operator: 3}}, false}, + {"NOT underflow", []gamedata.ItemRequirement{{Operator: 42}}, false}, + {"unknown stat inside NOT", []gamedata.ItemRequirement{{Stat: 9999, Value: 0, Operator: 0}, {Operator: 42}}, false}, + {"unknown stat after true", []gamedata.ItemRequirement{{Stat: 16, Value: 10, Operator: 0}, {Stat: 9999, Value: 0, Operator: 0}, {Operator: 3}}, false}, + {"unknown operator", []gamedata.ItemRequirement{{Stat: 16, Value: 10, Operator: 92}}, false}, + } { + t.Run(scenario.name, func(t *testing.T) { + world, owner := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + original := gamedata.ItemTemplates[121567] + definition := *original + actions := []gamedata.ItemAction{{Type: 8, Requirements: scenario.requirements}} + definition.Sections = []gamedata.ItemSection{{Actions: &actions}} + gamedata.ItemTemplates[121567] = &definition + t.Cleanup(func() { gamedata.ItemTemplates[121567] = original }) + player.inventory.Items[0].Template = 121567 + + err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]) + if client.equipment != nil { + world.advanceEquipment(client.equipment.readyAt) + } + + if err != nil || (player.inventory.Items[0].Slot == 6) != scenario.accepted || + !scenario.accepted && len(owner.packets) != 2 { + t.Fatal("postfix criteria produced an incorrect equipment outcome", err) + } + }) + } +} diff --git a/server/equipment_test.go b/server/equipment_test.go @@ -162,7 +162,7 @@ func TestEquipmentRequiresEachEffectiveSkillAtFive(t *testing.T) { func TestEquipmentUnsupportedWearSlotRestoresInventoryItem(t *testing.T) { world, conn := newEquipmentWorld(t) inventory := world.characters[1].inventory - inventory.Items[0].Type, inventory.Items[0].Template = 51022, 85535 + inventory.Items[0].Type, inventory.Items[0].Template = 51022, 29426 if err := world.saveInventory_locked(world.characters[1], inventory); err != nil { t.Fatal(err) } @@ -193,7 +193,7 @@ func TestEquipmentRejectedWearRestoresFullNativeInventory(t *testing.T) { t.Run(fmt.Sprint(source), func(t *testing.T) { world, conn := newEquipmentWorld(t) player := world.characters[1] - player.inventory.Items[0].Type, player.inventory.Items[0].Template = 51022, 85535 + player.inventory.Items[0].Type, player.inventory.Items[0].Template = 51022, 29426 player.inventory.Items[0].Slot = source if err := world.saveInventory_locked(player, player.inventory); err != nil { t.Fatal(err) diff --git a/server/starter_weapons_test.go b/server/starter_weapons_test.go @@ -104,7 +104,7 @@ func TestWeaponUnsupportedPredicatesAndMalformedDefinitionsRetainItem(t *testing requirement := gamedata.ItemRequirement{Stat: 9999, Value: 0, Operator: 0} switch scenario { case "unknown operator": - requirement = gamedata.ItemRequirement{Stat: 60, Value: 1, Operator: 3} + requirement = gamedata.ItemRequirement{Stat: 60, Value: 1, Operator: 92} case "wrong breed": requirement = gamedata.ItemRequirement{Stat: 4, Value: 4, Operator: 0} case "wrong side": diff --git a/server/weapon_stats.go b/server/weapon_stats.go @@ -37,32 +37,6 @@ func (character *character) effectiveStat(stat uint32) (int32, bool) { return 0, false } -func (character *character) weaponRequirementsMet(item ownedItem) bool { - // Evaluate supported action-8 predicates; unknown stats or operators cannot grant wear. - for _, section := range gamedata.ItemTemplates[item.Template].Sections { - if section.Actions == nil { - continue - } - for _, action := range *section.Actions { - if action.Type != 8 { - continue - } - for _, requirement := range action.Requirements { - if requirement.Operator == 4 { - continue - } - actual, known := character.effectiveStat(uint32(requirement.Stat)) - if !known || requirement.Operator != 0 && requirement.Operator != 2 || - requirement.Operator == 0 && actual != requirement.Value || - requirement.Operator == 2 && actual <= requirement.Value { - return false - } - } - } - } - return true -} - func (character *character) weaponOverequippingTier(weapon *gamedata.Item) uint32 { // kkr.dll 10090f10 scans every action-8 operator-2 predicate, including title. var tier uint32