|
Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
|
Item<->item exchange for the Market's Exchange tab (Healing + Custom). More...
#include <itemexchangemodel.h>
Public Member Functions | |
| ItemExchangeModel (ItemStorageBox *bag, ItemStorageBox *storage, PlayerBasics *basics) | |
| int | itemAInd () const |
| int | itemBInd () const |
| void | setItemAInd (int v) |
| void | setItemBInd (int v) |
| int | net () const |
| int | revision () const |
| bool | valid () const |
| QString | aName () const |
| QString | bName () const |
| int | aBuy () const |
| int | bBuy () const |
| int | aStart () const |
| int | bStart () const |
| int | moneyStart () const |
| int | aAfter () const |
| int | bAfter () const |
| int | moneyAfter () const |
| int | giveFor (int dir, int steps) const |
How many of the OTHER item steps of this direction consume, priced as ONE whole trade rather than steps separate ones: dir > 0 gains A (consuming B), dir < 0 gains B (consuming A). | |
| int | refundFor (int dir, int steps) const |
The leftover value of steps in direction dir, refunded as money – i.e. | |
| bool | canAddA () const |
| bool | canAddB () const |
| QVariantList | sourceItems (bool healingOnly, int excludeInd) const |
LEFT list – what you can GIVE: items you actually own (amount > 0) and that are exchangeable (buy price > 0), optionally healing-only, excluding excludeInd. | |
| QVariantList | targetItems (bool healingOnly, int excludeInd) const |
RIGHT list – what you can GET: EVERY exchangeable item (owned or not), optionally healing-only, excluding excludeInd. | |
| bool | canGainTarget (int bInd) const |
Can we gain at least one of item bInd right now, paying with the selected source? | |
| void | pickDefaults (bool healingOnly) |
| Choose a sensible starting pair. | |
| void | adjust (int dir) |
| +1 = one gained-A step, -1 = one gained-B step (gated). | |
| void | reset () |
| Clear the net axis. | |
| void | refresh () |
| Re-read counts/money + re-emit (tab open / external edit). | |
| void | checkout () |
| Apply the previewed trade to the save. | |
| protected::void | selectionChanged () |
| A or B selection changed. | |
| void | changed () |
| Any derived value changed. | |
Static Public Attributes | |
| static constexpr int | MoneyCap = 999999 |
| < Both picked, distinct, both have a buy price. | |
| static constexpr int | StackCap = 99 |
| Gen 1 per-stack cap. | |
Item<->item exchange for the Market's Exchange tab (Healing + Custom).
Powers the two item-trading sub-tabs. Two items are selected (A and B); a single net axis (net) drives the trade the same way the money<->coins converter drives one coin axis. Each "+A" step gains one more of item A; the WHOLE trade is then priced as one transaction – the minimum whole number of item B whose BUY value covers the total value being bought, with only the single leftover refunded as money (money only ever goes up). "+B" is the mirror. Rounding up the TOTAL, not each step, is the point: 3 Fresh Water (₽600) is paid for by exactly 2 Potions (₽600) with NO refund, where pricing each Fresh Water on its own would have wasted 3 Potions and handed back ₽300. Everything is previewed (the after counts + money) and only written on checkout(). Values come from each item's money buy price; the traded items are counted across the bag + PC storage combined.
The two dropdowns are asymmetric: the LEFT one is what you GIVE, so it lists the items you actually own (sourceItems); the RIGHT one is what you GET, so it lists EVERY exchangeable item (targetItems) with the ones your stock can't cover flagged unaffordable and greyed. That greying is what keeps a selected pair always tradeable in at least one direction – the two "+" buttons are never both disabled. Healing filters both lists to healing/drink items and starts on Potion <=> Fresh Water (pickDefaults). Exposed as brg.itemExchangeModel.
Definition at line 50 of file itemexchangemodel.h.
| ItemExchangeModel::ItemExchangeModel | ( | ItemStorageBox * | bag, |
| ItemStorageBox * | storage, | ||
| PlayerBasics * | basics ) |
Definition at line 80 of file itemexchangemodel.cpp.
References PlayerBasics::coinsChanged(), ItemsDB::inst(), ItemStorageBox::itemsChanged(), PlayerBasics::moneyChanged(), and refresh().
|
inline |
Definition at line 104 of file itemexchangemodel.h.
|
inline |
Definition at line 98 of file itemexchangemodel.h.
Referenced by giveFor(), refundFor(), and valid().
| void ItemExchangeModel::adjust | ( | int | dir | ) |
+1 = one gained-A step, -1 = one gained-B step (gated).
Definition at line 276 of file itemexchangemodel.cpp.
|
inline |
Definition at line 96 of file itemexchangemodel.h.
|
inline |
Definition at line 101 of file itemexchangemodel.h.
|
inline |
Definition at line 105 of file itemexchangemodel.h.
|
inline |
Definition at line 99 of file itemexchangemodel.h.
Referenced by giveFor(), refundFor(), and valid().
|
inline |
Definition at line 97 of file itemexchangemodel.h.
|
inline |
Definition at line 102 of file itemexchangemodel.h.
|
inline |
|
inline |
| bool ItemExchangeModel::canGainTarget | ( | int | bInd | ) | const |
Can we gain at least one of item bInd right now, paying with the selected source?
Definition at line 358 of file itemexchangemodel.cpp.
References MoneyCap, and moneyStart().
Referenced by pickDefaults(), and targetItems().
| void ItemExchangeModel::changed | ( | ) |
Any derived value changed.
| void ItemExchangeModel::checkout | ( | ) |
Apply the previewed trade to the save.
Definition at line 433 of file itemexchangemodel.cpp.
References giveFor(), MoneyCap, refundFor(), and valid().
| int ItemExchangeModel::giveFor | ( | int | dir, |
| int | steps ) const |
How many of the OTHER item steps of this direction consume, priced as ONE whole trade rather than steps separate ones: dir > 0 gains A (consuming B), dir < 0 gains B (consuming A).
Because the total is what's rounded up, a trade that divides evenly costs nothing extra – 3 Fresh Water (₽600) is exactly 2 Potions (₽600), not 3 Potions with three separate leftovers.
Definition at line 186 of file itemexchangemodel.cpp.
References aBuy(), bBuy(), and valid().
Referenced by checkout(), and refundFor().
|
inline |
Definition at line 87 of file itemexchangemodel.h.
|
inline |
Definition at line 88 of file itemexchangemodel.h.
|
inline |
Definition at line 106 of file itemexchangemodel.h.
| int ItemExchangeModel::moneyStart | ( | ) | const |
Definition at line 169 of file itemexchangemodel.cpp.
Referenced by canGainTarget().
|
inline |
Definition at line 92 of file itemexchangemodel.h.
| void ItemExchangeModel::pickDefaults | ( | bool | healingOnly | ) |
Choose a sensible starting pair.
Healing prefers a potion-family source the player owns (Potion > Super > Hyper > Max > Full Restore, then any healing item) and Fresh Water as the target – i.e. Potion <=> Fresh Water by default. Always lands on a pair with a usable "+" when one exists.
Definition at line 377 of file itemexchangemodel.cpp.
References canGainTarget(), selectionChanged(), sourceItems(), and targetItems().
| void ItemExchangeModel::refresh | ( | ) |
Re-read counts/money + re-emit (tab open / external edit).
Definition at line 295 of file itemexchangemodel.cpp.
Referenced by ItemExchangeModel().
| int ItemExchangeModel::refundFor | ( | int | dir, |
| int | steps ) const |
The leftover value of steps in direction dir, refunded as money – i.e.
giveFor() * (given item's buy price) minus the value actually being bought. Zero when the trade divides evenly (nothing to refund).
Definition at line 194 of file itemexchangemodel.cpp.
References aBuy(), bBuy(), giveFor(), and valid().
Referenced by checkout().
| void ItemExchangeModel::reset | ( | ) |
Clear the net axis.
Definition at line 287 of file itemexchangemodel.cpp.
|
inline |
Definition at line 93 of file itemexchangemodel.h.
| protected::void ItemExchangeModel::selectionChanged | ( | ) |
A or B selection changed.
Referenced by pickDefaults(), setItemAInd(), and setItemBInd().
| void ItemExchangeModel::setItemAInd | ( | int | v | ) |
Definition at line 256 of file itemexchangemodel.cpp.
References selectionChanged().
| void ItemExchangeModel::setItemBInd | ( | int | v | ) |
Definition at line 266 of file itemexchangemodel.cpp.
References selectionChanged().
| QVariantList ItemExchangeModel::sourceItems | ( | bool | healingOnly, |
| int | excludeInd ) const |
LEFT list – what you can GIVE: items you actually own (amount > 0) and that are exchangeable (buy price > 0), optionally healing-only, excluding excludeInd.
Returns [{name, ind}] sorted by display name.
Definition at line 306 of file itemexchangemodel.cpp.
Referenced by pickDefaults().
| QVariantList ItemExchangeModel::targetItems | ( | bool | healingOnly, |
| int | excludeInd ) const |
RIGHT list – what you can GET: EVERY exchangeable item (owned or not), optionally healing-only, excluding excludeInd.
Each entry carries an affordable flag – false when your current source stock can't cover even one of it (or there's no room / money would overflow). The dropdown greys those, which is what guarantees the selected pair always has at least one usable "+" (never both disabled). Returns [{name, ind, affordable}] sorted by display name.
Definition at line 334 of file itemexchangemodel.cpp.
References canGainTarget().
Referenced by pickDefaults().
| bool ItemExchangeModel::valid | ( | ) | const |
Definition at line 176 of file itemexchangemodel.cpp.
References aBuy(), and bBuy().
Referenced by canAddA(), canAddB(), checkout(), giveFor(), and refundFor().
|
staticconstexpr |
< Both picked, distinct, both have a buy price.
Net axis (+N = N gained-A steps, -N = gained-B). < Item A display name. Item B display name. Item A buy price (money). Item B buy price (money). < Item A owned (bag+storage) before. Item A owned after the previewed trade. Item B owned before. Item B owned after. Money before. Money after (refunds only). < "+A" enabled (one more gained-A step is legal). "+B" enabled. Bumped on every change. sourceItems()/targetItems() are Q_INVOKABLE calls, so a QML model: binding on them has no dependency to re-run on – read this in the binding and the lists (and their affordable flags) rebuild whenever the state moves. Gen 1 money cap.
Definition at line 82 of file itemexchangemodel.h.
Referenced by canGainTarget(), and checkout().
|
staticconstexpr |
Gen 1 per-stack cap.
Definition at line 83 of file itemexchangemodel.h.