45 load(saveFile, offset);
50 for(
auto item :
items)
63 for(
auto el :
items) {
84 if(dest->items.size() >= dest->itemsMax())
92 if(ind >=
items.size())
104 for(
var8 i = 0; i < count; i++) {
138 if(giveSuperPotion) {
139 items.append(
new Item(
"SUPER POTION", 1));
153 for(
var8 i = 0; i < count; i++) {
160 if(
items.size() <= 0 ||
162 from >=
items.size() ||
164 to >=
items.size() ||
169 auto eFrom =
items.at(from);
170 items.removeAt(from);
173 items.insert(to, eFrom);
183 if(
items.size() <= 0 ||
188 items.at(ind)->deleteLater();
196 for(
auto el :
items) {
210 for(
auto el :
items) {
226 for(
auto el :
items) {
228 room += (99 - el->amount);
239 if(ind < 0 || amount <= 0)
245 for(
auto el :
items) {
250 const int put = qMin(99 - el->amount, amount - added);
253 el->setAmount(el->amount + put);
259 const int put = qMin(99, amount - added);
273 if(ind < 0 || amount <= 0)
280 for(
int i =
items.size() - 1; i >= 0 && removed < amount; --i) {
285 const int take = qMin(el->
amount, amount - removed);
309 if(entry->getGlitch() || entry->getOnce())
315 pool.append(entry->getInd());
322 return pool.at(
Random::inst()->rangeExclusive(0, pool.size()));
348 while(
items.size() > 0 && dest->items.size() < dest->itemsMax()) {
360 if(
items.size() <= 0 ||
362 ind >=
items.size() ||
363 dest->items.size() >= dest->itemsMax())
366 auto el =
items.at(ind);
367 beforeItemRelocate(el);
373 dest->items.append(el);
374 dest->itemInsertChange();
375 dest->itemsChanged();
382 if(
items.size() <= 0)
387 collator.setNumericMode(
true);
388 collator.setIgnorePunctuation(
true);
393 [&collator](
Item* item1,
Item* item2)
395 if(item1->toItem() == nullptr || item2->toItem() == nullptr)
396 return collator.compare(
"",
"") < 0;
398 return collator.compare(item1->toItem()->getReadable(), item2->toItem()->getReadable()) < 0;
409 this->
file = saveFile;
411 if(saveFile ==
nullptr)
414 auto toolset = saveFile->
toolset;
418 for (
var8 i = 0; i < toolset->getByte(offset) && i <
maxSize; i++) {
419 auto item =
new Item(it);
437 it->setByte(
items.at(i)->ind);
438 it->setByte(
items.at(i)->amount);
447 ?
file->dataExpanded->storage->items
448 :
file->dataExpanded->player->items;
455 for(
auto el :
items) {
456 ret += el->buyPriceAllMoney();
466 for(
auto el :
items) {
467 ret += el->buyPriceAllCoins();
477 for(
auto el :
items) {
478 ret += el->sellPriceAllMoney();
488 for(
auto el :
items) {
489 ret += el->sellPriceAllCoins();
497 for(
auto item :
items) {
void sort()
Sort the box contents.
QVector< Item * > items
The stored items.
void save(SaveFile *saveFile, int offset)
Flatten the box to the save.
void reset()
Empty the box.
bool getIsBag()
Is this the bag?
void itemsResetChange()
The box was reset.
void randomizeBag()
Randomizer path for the bag.
bool isBag
Bag vs PC (set at construction; treat as read-only).
void load(SaveFile *saveFile=nullptr, int offset=0)
Expand the box from the save.
ItemStorageBox * destBox()
The paired box for relocation.
virtual ~ItemStorageBox()
int maxSize
Capacity (set at construction; treat as read-only).
void itemNew()
Add a fresh random item (never a duplicate of one already here).
ItemStorageBox(bool isBag, int maxSize, SaveFile *saveFile=nullptr, int offset=0)
How many items are there.
int itemsCountBulk()
Item count including stack amounts.
void itemInsertChange()
An item was inserted.
void itemMoveChange(int from, int to)
An item moved slot.
bool relocateAll()
Move every item to the paired box.
int randomUniqueInd()
A random non-glitch/non-once item index absent from this box, or -1 if none remain.
bool itemMove(int from, int to)
Reorder an item.
bool relocateOne(int ind)
Move one item to the paired box.
void randomizeStorage()
Randomizer path for a PC item box.
bool relocateFull()
Is relocation blocked because the paired box is full?
int capacityForInd(int ind)
Room to add more of item ind: the unused space in existing matching rows (up to 99 each) plus 99 for ...
Item * itemAt(int ind)
Item slot ind (GC-protected return).
bool hasItemInd(int ind)
Does this box already contain an item with index ind? (Q_INVOKABLE: the SelectItem dropdown greys out...
void randomize()
Randomize (dispatches to bag/storage path); sorts afterward.
int removeAmount(int ind, int amount)
Remove amount of item ind from this box (drains matching rows from the last, deleting emptied rows).
SaveFile * file
Owning save.
int amountOfInd(int ind)
Total amount of item ind across all rows in this box (Q_INVOKABLE: the SelectItem dropdown shows the ...
int itemsCount()
Distinct item count.
void itemRemoveChange(int ind)
An item was removed.
void itemsChanged()
Box contents changed.
void itemRemove(int ind)
Remove item ind.
int addAmount(int ind, int amount)
Add amount of item ind: top up existing matching rows to 99 first, then add new rows (up to maxSize).
One inventory slot: an item index and an amount, with live pricing.
int ind
Item index (backs property).
int amount
Item amount (max 99 in Gen 1; backs property).
void setAmount(int val)
Set amount (backs property WRITE; clamped to the Gen 1 max).
static ItemsDB * inst()
< Number of items.
bool chanceSuccess(const int percent) const
Did a percent chance succeed?
int rangeInclusive(const int start, const int end) const
Random integer in the closed interval [start, end].
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
void setByte(var8 val, var16 padding=0)
Write a byte at the cursor; advances.
SaveFileIterator * offsetTo(var16 val)
Move the cursor to an absolute offset. Returns this for chaining.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
SaveFileToolset * toolset
Tools to operate directly on the raw sav file data.
SaveFileIterator * iterator()
Returns a unique iterator that's setup to iterate over the raw sav file data.
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
qmlCppOwned() – protect Q_INVOKABLE QObject returns from QML's GC.
static T * qmlCppOwned(T *obj)
Hand QML CppOwnership of a C++-owned QObject returned from a Q_INVOKABLE.