Skip to content

fix(trade): warn only for the Jewel of Guardian and the Cape of Lord, not every item after them - #946

Merged
Mosch0512 merged 4 commits into
Mutizens:mainfrom
leqatoavgust-dot:fix/trade-warning-tracked-items
Dec 4, 2026
Merged

Mosch0512 merged 4 commits into
Mutizens:mainfrom
leqatoavgust-dot:fix/trade-warning-tracked-items

Conversation

@leqatoavgust-dot

@leqatoavgust-dot leqatoavgust-dot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #671.

CTrade::BackUpYourInven decides which of the trade partner's items are remembered, so the trade window can warn when the partner swaps one for a worse copy. Two lines of its list used >= where their original comments name a single item (Jewel of Guardian, Cape of Lord):

|| (pYourItemObj->Type >= ITEM_JEWEL_OF_GUARDIAN)
|| (pYourItemObj->Type >= ITEM_CAPE_OF_LORD)

With >=, every item from (13,30) to the end of the item table was tracked: potions, Box of Luck variants, tickets, scrolls and the rest of groups 13 to 15. Taking such an item out of the trade window and putting in a smaller stack or a lower-level box drew the red "Warning" over it and the confirmation box on accept, although it is not a worse copy of the same item.

Both lines now compare with ==. The Horn of Fenrir, which the old >= also covered, stays on the list: a lower durability is a real downgrade for it, as for the Uniria and Dinorant.

The rule is now an item rule, GameLogic::Items::IsTrackedForTradeChangeWarning (GameLogic/Items/TradeChangeWarning.cpp), with named fields and its own packed jewel check. BackUpYourInven returns early for a missing item. docs/item-data.md describes the warning.

Testing

Before / After

No screenshots: the in-game checks above were made through the control socket.

Coding rules

I read docs/CODING_RULES.md and docs/PULL_REQUESTS.md and followed them for this change.

🤖 Generated with Claude Code

@ezequielzacca

Copy link
Copy Markdown
Contributor

Please add test coverage to protect this against future regressions! :)

@leqatoavgust-dot

leqatoavgust-dot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I added tests in 4546fc5: the rule of CTrade::BackUpYourInven moved into UI::Inventory::IsTrackedForChangeWarning (UI/Inventory/TradeChangeWarning.cpp) so it can be tested on its own, and tests/ui/test_trade_change_warning.cpp (target trade_change_warning_tests) checks that

3 test cases, 28 assertions, all passing. With the old >= put back, 8 of them fail, so they'd catch the regression. The client builds with the change (Windows x64, editor preset).

@Mosch0512 Mosch0512 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: changes requested for the one item below; the rest is non-blocking or a follow-up. The two == lines match what the original comments name: 수호의 보석 (Jewel of Guardian) and 군주의 망토 (Cape of Lord) in ee2c7a3. The extracted rule is the old condition with only those two lines changed. Reading the third test case, all eight of its CHECK_FALSE lines would fail with the old >= put back, so the tests guard the fix. Thanks for adding them.

Required

  • Keep the warning for the Horn of Fenrir, which the narrower list drops (inline, TradeChangeWarning.cpp:10).

Non-blocking

  • The function the PR touches has no null check (inline, Trade.cpp:757).
  • The header comment promises more items than the rule tracks (inline, TradeChangeWarning.h:5).
  • The packed-jewel check passes for any item, and the compiledGem parameter can be derived from the type (inline, test_trade_change_warning.cpp:33).
  • The rule sits in the UI layer (coding rule 5) (inline, TradeChangeWarning.cpp:6).
  • Outside the diff, no inline comment: coding rule 11 asks for docs when a trade-flow rule changes, and nothing in docs/ describes the trade warning yet. A few lines in the trade section of docs/item-data.md would cover it: which items are remembered, what counts as worse (CompareItem compares level, then skill, excellent options, special options, the additional option, then durability), and that the original client's >= tracked everything from (13,30) on.
  • Outside the diff, PR text: the "Not changed here" paragraph says the same >= ITEM_CAPE_OF_LORD is still in RenderRepairInfo. It isn't any more. 949b87a (item names from the item data) removed it, and no >= ITEM_CAPE_OF_LORD is left in src/source. The paragraph can go.

Follow-up, older than this PR (both outside the diff, details below)

  • AlertYourTradeInven can write past the end of nCompareItemType[10].
  • One partner item that matches its backup exactly clears the alert for the whole trade.

Follow-up: nCompareItemType[10] overflow (Trade.cpp:810, :834)

AlertYourTradeInven adds one entry for each partner item that equals its backup, and nothing checks the bound:

int nCompareItemType[10];
...
if (0 == nCompareValue)
    nCompareItemType[nCount++] = m_aYourInvenBackUp[j].Type;

The trade grid has 32 one-cell slots. A partner who puts in 12 Jewels of Bless and takes one out makes ProcessToReceiveYourItemDelete back up a Jewel of Bless. The next AlertYourTradeInven call then finds 11 equal jewels and writes 11 entries into the 10-entry array, overwriting the stack. Reopening a cancelled trade with 11 or more identical tracked items does the same. This PR makes it rarer, since potions no longer count, but jewels, wings and pets are still tracked. Each partner item adds at most one entry, so int nCompareItemType[MAX_TRADE_INVEN]; is enough.

Follow-up: an exact match clears the alert (Trade.cpp:845)

if (nCount > 0)
{
    m_bTradeAlert = false;

The backups hold Wings of Elf +3 and a Jewel of Bless. The partner offers Wings of Elf +1 and the same Jewel of Bless. The wings compare worse, so they are tinted red and m_bTradeAlert is set. The jewel compares equal, so nCount becomes 1 and m_bTradeAlert goes back to false. The wings keep the red tint and the "Warning" label, but the confirm button (line 183) skips the "levels and options of some items have been changed" box. After the loop that clears the matched types, setting m_bTradeAlert from whether any item still has ITEM_COLOR_TRADE_WARNING would keep the box for the wings.

I found both by reading the code and haven't reproduced them in game. Neither needs to block this PR. They should get their own issue, as #671 already says for the first one.

What I checked: I read the diff against a7e8d9a and compared the two lines with the original source and its Korean comments (ee2c7a3). I traced both callers of BackUpYourInven (the partner's delete and the cancelled trade), CompareItem, AlertYourTradeInven, the confirm button, and COMGEM::Check_Jewel for the packed jewels. The branch merges into the current main (e6ce259) without conflicts. I didn't build or run the branch. Both CI runs on 4546fc5 are waiting for a maintainer's approval, so no job has built or run it yet.

{
bool IsTrackedForChangeWarning(int itemType, int level, int excellentFlags, bool compiledGem)
{
return (itemType >= ITEM_HELPER && itemType <= ITEM_DARK_HORSE_ITEM)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required. The narrower list also drops the Horn of Fenrir (13,37). The old >= ITEM_CAPE_OF_LORD covered it. For a Fenrir a lower durability is a real downgrade, as it is for the Uniria and Dinorant this line keeps, and its life is restored with Jewels of Bless (InventoryCtrl.cpp:1073). So if a partner offers a red Fenrir at 255, takes it back and offers one at 5, the warning used to show and now doesn't. The gold, black and blue Fenrirs still warn through excellentFlags, but a plain red one has none. The "Expected" list in #671 left it out; that's on the issue, not on you. Please add || itemType == ITEM_HORN_OF_FENRIR here and turn line 54 of the test into a CHECK, so the test keeps it tracked.

The later pets after (13,30) lost tracking too (Demon, Spirit of Guardian, Rudolf, Panda, Unicorn, Skeleton). Whether their durability matters as much is less clear, so I'm only asking for Fenrir.

Comment thread src/source/UI/Inventory/Trade.cpp Outdated
|| (pYourItemObj->Type == ITEM_JEWEL_OF_CHAOS)
|| (pYourItemObj->Type >= ITEM_CAPE_OF_FIGHTER && pYourItemObj->Type <= ITEM_CAPE_OF_OVERRULE)
|| ((pYourItemObj->Level > 4 && pYourItemObj->Type < ITEM_WING) || pYourItemObj->ExcellentFlags > 0))
if (UI::Inventory::IsTrackedForChangeWarning(pYourItemObj->Type, pYourItemObj->Level, pYourItemObj->ExcellentFlags,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, older than this PR. BackUpYourInven(int) passes FindItem's result straight here. FindItemFromSlotIndex returns nullptr for an empty slot or for an index outside the 32 slots, and the server sends the index as a BYTE. The rule call then reads Type, Level and ExcellentFlags through a null pointer. Since you're touching the function, an early if (pYourItemObj == nullptr) return; (coding rule 2) would close that.


namespace UI::Inventory
{
// Whether the trade window remembers an item the partner offers, so that it can warn when the partner takes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking. The comment promises more than the rule does. Single Jewels of Creation and Harmony, Gemstones and refine stones aren't remembered (the test checks that for Creation, line 55), although their packed bundles are, through isCompiledGem. The small wings (12,130 to 12,135) and the Dark Raven (13,5) aren't remembered either. Naming what the list holds would save the next reader a surprise: pets (13,0) to (13,4) and, with the change above, the Horn of Fenrir; Jewels of Bless, Soul, Life, Guardian and Chaos; packed jewels; wings 0-6 and 36-43 and capes 49-50 of group 12; the Cape of Lord; weapons and armor from +5; anything with excellent options.

Comment thread tests/ui/test_trade_change_warning.cpp Outdated
CHECK(Tracked(ITEM_CAPE_OF_LORD));
CHECK(Tracked(ITEM_CAPE_OF_FIGHTER));
CHECK(Tracked(ITEM_CAPE_OF_OVERRULE));
CHECK(Tracked(INDEX_COMPILED_SOUL, 0, 0, true)); // a packed jewel

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking. This check passes compiledGem = true, and with that flag the rule returns true for any type, so Tracked(ITEM_LARGE_HEALING_POTION, 0, 0, true) would pass too. Which items count as packed jewels is decided by the caller (COMGEM::isCompiledGem in Trade.cpp), which no test reaches. isCompiledGem only reads the type, so the rule could check the packed types itself (ITEM_PACKED_JEWEL_OF_BLESS and the others come from _enum.h, which the file already includes) and drop the bool. Then this check tests something, and a caller can't pass a flag that doesn't fit the type. If you'd rather keep the bool, a comment here saying the packed-jewel check is the caller's would do.

Related: level and excellentFlags are neighbouring ints, so swapping them still compiles. A Box of Luck +3 passed as (type, 0, 3) is then tracked through excellentFlags, which is the warning #671 is about.

#include "Core/Platform/WinCompat.h" // the Win32 scalar types _enum.h and _define.h use
#include "Core/Globals/_enum.h"

namespace UI::Inventory

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking. Coding rule 5: "UI must not contain game logic." Which items the warning remembers is an item rule, like GameLogic::Items::IsTradeBan (GameLogic/Items/TradeRestrictions.h) and IsHighValueItem (ItemCategories.h). It would fit in GameLogic::Items, for example as IsTrackedForTradeChangeWarning next to the trade restrictions, and the test needs no UI sources either way. If it stays in UI, the trade code in this folder uses UI::Trade (TradeUpdates.h), not UI::Inventory.

Later the list could come from the item data, which already has most of these categories: IsWingItem (slot wings), IsJewelItem (the jewel tag), COMGEM::Check_Jewel for single and packed jewels, and the mount, darkLordPet and guardianPet tags. That changes which items are tracked (small wings, Fenrir, the single Jewel of Creation), so it's a follow-up, not something for this PR.

@Mosch0512 Mosch0512 self-assigned this Nov 6, 2026
icheat2win added a commit to icheat2win/MuMain that referenced this pull request Nov 16, 2026
Which items are remembered (all items from the Cape of Lord on, Mutizens#946),
jewel bundles instead of sockets, +4 only for weapons and armour, the full
CompareItem order with the bit-flag excellent options and durability, every
way of cancelling, and the question closing with the window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
leqatoavgust-dot and others added 4 commits November 30, 2026 21:53
… not every item after them

Two lines of CTrade::BackUpYourInven used >= where their original comments name one
item each, so every item from (13,30) to the end of the item table was tracked:
potions, boxes, tickets and the rest of groups 13 to 15. Taking one out of the trade
window and putting in a smaller stack or a lower-level box drew the change warning
over it, although it is not a worse copy of the same item.

Fixes Mutizens#671

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rule of CTrade::BackUpYourInven moves into UI::Inventory::IsTrackedForChangeWarning
so that it can be tested on its own. The tests check that the items the list names
are remembered (pets up to the Dark Horse, jewels, packed jewels, wings and capes,
+5 or excellent equipment) and that potions, boxes of luck, tickets and the items
after the Cape of Lord aren't (Mutizens#671).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The narrower list dropped the Horn of Fenrir (13,37), which the old >= ITEM_CAPE_OF_LORD covered. Its
durability is a real downgrade, as for the Uniria and Dinorant, so a partner could swap a red Fenrir at
255 for one at 5 without the warning. It's tracked again, and the test checks it.
…gic::Items

Review of Mutizens#946: the rule moves to GameLogic/Items/TradeChangeWarning (coding rule 5) as
IsTrackedForTradeChangeWarning. It takes named fields, so the level and the excellent flags
can't be swapped, and checks the packed jewel types itself instead of a caller's flag.
BackUpYourInven returns early for a missing item. The header comment names what the list
holds, and docs/item-data.md describes the warning.
@leqatoavgust-dot
leqatoavgust-dot force-pushed the fix/trade-warning-tracked-items branch from 2fc94ee to e0d2f21 Compare November 30, 2026 18:05
@leqatoavgust-dot

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review, and sorry for the slow answer. I rebased onto current main (only tests/ui/CMakeLists.txt conflicted, next to trade_worse_offers_tests) and pushed e0d2f21.

Required

  • Horn of Fenrir: tracked again (a02c6d3), and the test checks it.

Non-blocking, also done (e0d2f21)

  • The rule moved to GameLogic/Items/TradeChangeWarning as GameLogic::Items::IsTrackedForTradeChangeWarning (coding rule 5).
  • It takes a TradeWarningItem with named fields ({.type, .level, .excellentFlags}), so the level and the excellent flags can't be swapped at the call.
  • The compiledGem flag is gone: the rule checks the ten packed jewel and stone types itself. The test checks each of them, and that the single Creation, Harmony, Gemstone and refine stones aren't tracked.
  • BackUpYourInven returns early when FindItem gives nullptr.
  • The header comment names what the list holds and what it leaves out.
  • docs/item-data.md has a short "trade change warning" section: what is remembered, what counts as worse (CompareItem's order) and the old >=.
  • The PR text no longer has the "Not changed here" paragraph.

Not in this PR

  • The nCompareItemType[10] overflow and the exact-match reset: since the rebase, AlertYourTradeInven goes through UI::Trade::MarkWorseOffers from main, so I left them out. I can look at what is left of them in a follow-up if you like.
  • Taking the list from the item data (tags): a follow-up, as you wrote.

Tests: trade_change_warning_tests (4 cases, 42 checks) and trade_worse_offers_tests (18 cases) pass, Trade.cpp builds (Windows x64, editor preset), and scripts/check_format.sh passes.

@nitoygo
nitoygo requested a review from Mosch0512 December 4, 2026 07:32
@Mosch0512
Mosch0512 merged commit f2ccba9 into Mutizens:main Dec 4, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trade change warning tracks every item from (13,30) up: >= used for Jewel of Guardian and Cape of Lord

4 participants