Repository navigation
fix(trade): warn only for the Jewel of Guardian and the Cape of Lord, not every item after them - #946
Conversation
|
Please add test coverage to protect this against future regressions! :) |
|
Thanks for the review! I added tests in 4546fc5: the rule of
3 test cases, 28 assertions, all passing. With the old |
Mosch0512
left a comment
There was a problem hiding this comment.
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
compiledGemparameter 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 ofdocs/item-data.mdwould cover it: which items are remembered, what counts as worse (CompareItemcompares 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_LORDis still inRenderRepairInfo. It isn't any more. 949b87a (item names from the item data) removed it, and no>= ITEM_CAPE_OF_LORDis left insrc/source. The paragraph can go.
Follow-up, older than this PR (both outside the diff, details below)
AlertYourTradeInvencan write past the end ofnCompareItemType[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) |
There was a problem hiding this comment.
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.
| || (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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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
… 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.
2fc94ee to
e0d2f21
Compare
|
Thanks for the careful review, and sorry for the slow answer. I rebased onto current Required
Non-blocking, also done (e0d2f21)
Not in this PR
Tests: |
Fixes #671.
CTrade::BackUpYourInvendecides 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):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.BackUpYourInvenreturns early for a missing item.docs/item-data.mddescribes the warning.Testing
Trade.cpp,trade_change_warning_tests,trade_worse_offers_tests.trade_change_warning_testspasses (4 cases, 42 checks);trade_worse_offers_testspasses (18 cases).>=used for Jewel of Guardian and Cape of Lord #671 describes as warned before. The same through a cancelled and reopened trade: no warning. Control: Wings of Elf +3 offered, trade cancelled and reopened, Wings of Elf +1 offered: the red tint and the "Warning!" label still show.>=used for Jewel of Guardian and Cape of Lord #671 describes it.scripts/check_format.shpasses (clang-format 21.1.8).Before / After
No screenshots: the in-game checks above were made through the control socket.
Coding rules
I read
docs/CODING_RULES.mdanddocs/PULL_REQUESTS.mdand followed them for this change.🤖 Generated with Claude Code