Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
itemmarketentrygcpokemon.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Twilight
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16
21
22#include <QtDebug>
23
25#include <pse-db/gamecornerdb.h>
34
35// Pokemon cannot be bought with anything other than coins to keep
36// to keep compatibility with the games. They also cannot be sold back
37// for ethical reasons nor can they be bought in money, again, ethical
38// reasons. I don't want a PR nightmare and have this whole thing get
39// shutdown by GameFreak because of a PR nightmare.
40
49
51
53{
54 if(!requestFilter())
55 return "";
56
57 return toGameCorner->getName() + " Lv." + QString::number(toGameCorner->getLevel());
58}
59
61{
62 return 0;
63}
64
66{
67 return true;
68}
69
71{
72 if(!requestFilter())
73 return 0;
74
75 // We are only dealing with one currency and one mode
76 return toGameCorner->getPrice();
77}
78
80{
81 return type;
82}
83
85{
86 if(!requestFilter())
87 return 0;
88
89 // Calculate stacks this item takes up
90 auto stk = stackCount();
91
92 // Final value to return, a representation of items left that can go onto the
93 // cart
94 int ret = 0;
95
96 // Calculate stacks others take up
97 int totalStackFromOthers = totalStackCount() - stk;
98
99 // Calculate inventory space used and free combined from both bag and box
100 int combinedBoxSpace = party->pokemonMax() + (maxPokemonBoxes * boxMaxPokemon);
101 int combinedBoxUsed = party->pokemonCount();
102
103 if(storage->boxesFormatted) {
104 for(int i = 0; i < maxPokemonBoxes; i++) {
105 combinedBoxUsed += storage->boxAt(i)->pokemonCount();
106 }
107 }
108 else {
109 combinedBoxUsed += storage->boxAt(storage->curBox)->pokemonCount();
110 }
111
112 // Stack space left before requested transaction
113 int stackSpaceBefore = combinedBoxSpace - combinedBoxUsed;
114
115 // Stack space after requested transactions
116 int stackSpaceLeftAfter = stackSpaceBefore - totalStackFromOthers - stk;
117
118 // Calculate whole stack remaining. There is 1 pokemon max per stack
119 // This is the whole new stacks converted to pokemon count.
120 ret = stackSpaceLeftAfter * 1;
121
122 // Ret Now contains the maximum pokemon possible left but it doesn't take
123 // into consideration how much money is left. We do a quick calculation for
124 // that
125 int maxAmountFromMoney = moneyLeftover() / itemWorth();
126
127 // Return the smallest of the calculations
128 return qMin(ret, maxAmountFromMoney);
129}
130
132{
133 // Pokemon have a stack size of 1
134 return onCart;
135}
136
138 if(!requestFilter() ||
139 !canCheckout())
140 return;
141
142 // Add in requested Pokemon
143 for(int i = 0; i < onCart; i++) {
144 // Prepare Pokemon
145 auto mon = PokemonBox::newPokemon(toGameCorner->getToPokemon(), player);
146 mon->level = toGameCorner->getLevel();
147 mon->update(true, true, true, true);
148
149 // Find Free Storage in case needed
150 auto box = storage->freeSpace();
151
152 // Space in party ?
153 if(party->pokemonCount() < party->pokemonMax()) {
154 party->pokemon.append(PokemonParty::convertToParty(mon));
155 party->pokemonChanged();
156 }
157 else if(box != nullptr) {
158 box->pokemon.append(mon);
159 box->pokemonChanged();
160 }
161 else
162 qDebug() << "Mon was not able to be added?";
163 }
164
165 }
virtual QString _name() override
Subtype: compute the display name.
virtual void checkout() override
Buy the prize mon (into party/storage).
virtual int _itemWorth() override
Subtype: compute the unit value.
virtual int _inStockCount() override
Subtype: compute the owned/sellable count.
PlayerPokemon * party
Destination party.
virtual int stackCount() override
Subtype: new stack slots needed (see note above).
static constexpr const char * type
This row's type key.
virtual bool _canSell() override
Subtype: compute sellability.
GameCornerDBEntry * toGameCorner
The prize definition.
ItemMarketEntryGCPokemon(GameCornerDBEntry *toGameCorner, PlayerPokemon *party, Storage *storage)
Storage * storage
Overflow PC storage.
virtual QString _whichType() override
Subtype: report the type label.
virtual int onCartLeft() override
Subtype: how many more may be added.
ItemMarketEntry(int compatMoneyCurrency=CompatEither, int compatBuyMode=CompatEither)
int totalStackCount()
Stacks across all rows of this type.
int moneyLeftover()
Money remaining if this checks out.
bool requestFilter()
Helper: does this row pass the current mode filter?
int itemWorth()
Cached unit value.
static PlayerBasics * player
Shared: player money/coins.
void finishConstruction()
Finalise construction (register the instance).
int onCart
Backing cart quantity.
virtual bool canCheckout()
Can this row alone check out?
The player's active party – a specialized PokemonStorageBox.
static PokemonBox * newPokemon(PokemonRandom::PokemonRandom_ list=PokemonRandom::Random_Starters, PlayerBasics *basics=nullptr)
static PokemonParty * convertToParty(PokemonBox *data)
New party mon from a box record (regenerates stats).
The PC: the item storage box and all 12 Pokemon boxes.
Definition storage.h:49
constexpr var8 boxMaxPokemon
Capacity of a single PC box.
constexpr var8 maxPokemonBoxes
Total PC boxes (12).
Definition storage.h:35
One Game Corner prize: a Pokemon or item, its coin price, and level.