Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
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
24
#include "
./itemmarketentrygcpokemon.h
"
25
#include <
pse-db/gamecornerdb.h
>
26
#include <
pse-db/entries/gamecornerdbentry.h
>
27
#include <
pse-savefile/expanded/storage.h
>
28
#include <
pse-savefile/expanded/player/playerbasics.h
>
29
#include <
pse-savefile/expanded/player/playerpokemon.h
>
30
#include <
pse-savefile/expanded/fragments/pokemonbox.h
>
31
#include <
pse-savefile/expanded/fragments/pokemonparty.h
>
32
#include <
pse-savefile/expanded/fragments/pokemonstorageset.h
>
33
#include <
pse-savefile/expanded/fragments/pokemonstoragebox.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
41
ItemMarketEntryGCPokemon::ItemMarketEntryGCPokemon
(
GameCornerDBEntry
*
toGameCorner
,
PlayerPokemon
*
party
,
Storage
*
storage
)
42
:
ItemMarketEntry
(
CompatNo
,
CompatYes
),
// Only Coins, Only Buying
43
toGameCorner
(
toGameCorner
),
44
party
(
party
),
45
storage
(
storage
)
46
{
47
finishConstruction
();
48
}
49
50
ItemMarketEntryGCPokemon::~ItemMarketEntryGCPokemon
() {}
51
52
QString
ItemMarketEntryGCPokemon::_name
()
53
{
54
if
(!
requestFilter
())
55
return
""
;
56
57
return
toGameCorner
->getName() +
" Lv."
+ QString::number(
toGameCorner
->getLevel());
58
}
59
60
int
ItemMarketEntryGCPokemon::_inStockCount
()
61
{
62
return
0;
63
}
64
65
bool
ItemMarketEntryGCPokemon::_canSell
()
66
{
67
return
true
;
68
}
69
70
int
ItemMarketEntryGCPokemon::_itemWorth
()
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
79
QString
ItemMarketEntryGCPokemon::_whichType
()
80
{
81
return
type
;
82
}
83
84
int
ItemMarketEntryGCPokemon::onCartLeft
()
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
131
int
ItemMarketEntryGCPokemon::stackCount
()
132
{
133
// Pokemon have a stack size of 1
134
return
onCart
;
135
}
136
137
void
ItemMarketEntryGCPokemon::checkout
() {
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
}
ItemMarketEntryGCPokemon::_name
virtual QString _name() override
Subtype: compute the display name.
Definition
itemmarketentrygcpokemon.cpp:52
ItemMarketEntryGCPokemon::checkout
virtual void checkout() override
Buy the prize mon (into party/storage).
Definition
itemmarketentrygcpokemon.cpp:137
ItemMarketEntryGCPokemon::_itemWorth
virtual int _itemWorth() override
Subtype: compute the unit value.
Definition
itemmarketentrygcpokemon.cpp:70
ItemMarketEntryGCPokemon::_inStockCount
virtual int _inStockCount() override
Subtype: compute the owned/sellable count.
Definition
itemmarketentrygcpokemon.cpp:60
ItemMarketEntryGCPokemon::party
PlayerPokemon * party
Destination party.
Definition
itemmarketentrygcpokemon.h:53
ItemMarketEntryGCPokemon::stackCount
virtual int stackCount() override
Subtype: new stack slots needed (see note above).
Definition
itemmarketentrygcpokemon.cpp:131
ItemMarketEntryGCPokemon::type
static constexpr const char * type
This row's type key.
Definition
itemmarketentrygcpokemon.h:51
ItemMarketEntryGCPokemon::_canSell
virtual bool _canSell() override
Subtype: compute sellability.
Definition
itemmarketentrygcpokemon.cpp:65
ItemMarketEntryGCPokemon::toGameCorner
GameCornerDBEntry * toGameCorner
The prize definition.
Definition
itemmarketentrygcpokemon.h:52
ItemMarketEntryGCPokemon::~ItemMarketEntryGCPokemon
virtual ~ItemMarketEntryGCPokemon()
Definition
itemmarketentrygcpokemon.cpp:50
ItemMarketEntryGCPokemon::ItemMarketEntryGCPokemon
ItemMarketEntryGCPokemon(GameCornerDBEntry *toGameCorner, PlayerPokemon *party, Storage *storage)
Definition
itemmarketentrygcpokemon.cpp:41
ItemMarketEntryGCPokemon::storage
Storage * storage
Overflow PC storage.
Definition
itemmarketentrygcpokemon.h:54
ItemMarketEntryGCPokemon::_whichType
virtual QString _whichType() override
Subtype: report the type label.
Definition
itemmarketentrygcpokemon.cpp:79
ItemMarketEntryGCPokemon::onCartLeft
virtual int onCartLeft() override
Subtype: how many more may be added.
Definition
itemmarketentrygcpokemon.cpp:84
ItemMarketEntry::ItemMarketEntry
ItemMarketEntry(int compatMoneyCurrency=CompatEither, int compatBuyMode=CompatEither)
Definition
itemmarketentry.cpp:28
ItemMarketEntry::totalStackCount
int totalStackCount()
Stacks across all rows of this type.
Definition
itemmarketentry.cpp:162
ItemMarketEntry::moneyLeftover
int moneyLeftover()
Money remaining if this checks out.
Definition
itemmarketentry.cpp:202
ItemMarketEntry::requestFilter
bool requestFilter()
Helper: does this row pass the current mode filter?
Definition
itemmarketentry.cpp:124
ItemMarketEntry::itemWorth
int itemWorth()
Cached unit value.
Definition
itemmarketentry.cpp:95
ItemMarketEntry::player
static PlayerBasics * player
Shared: player money/coins.
Definition
itemmarketentry.h:193
ItemMarketEntry::finishConstruction
void finishConstruction()
Finalise construction (register the instance).
Definition
itemmarketentry.cpp:58
ItemMarketEntry::onCart
int onCart
Backing cart quantity.
Definition
itemmarketentry.h:169
ItemMarketEntry::canCheckout
virtual bool canCheckout()
Can this row alone check out?
Definition
itemmarketentry.cpp:208
ItemMarketEntry::CompatNo
@ CompatNo
Definition
itemmarketentry.h:74
ItemMarketEntry::CompatYes
@ CompatYes
Definition
itemmarketentry.h:75
PlayerPokemon
The player's active party – a specialized PokemonStorageBox.
Definition
playerpokemon.h:42
PokemonBox::newPokemon
static PokemonBox * newPokemon(PokemonRandom::PokemonRandom_ list=PokemonRandom::Random_Starters, PlayerBasics *basics=nullptr)
Definition
pokemonbox.cpp:359
PokemonParty::convertToParty
static PokemonParty * convertToParty(PokemonBox *data)
New party mon from a box record (regenerates stats).
Definition
pokemonparty.cpp:191
Storage
The PC: the item storage box and all 12 Pokemon boxes.
Definition
storage.h:49
gamecornerdb.h
gamecornerdbentry.h
itemmarketentrygcpokemon.h
playerbasics.h
playerpokemon.h
pokemonbox.h
pokemonparty.h
pokemonstoragebox.h
boxMaxPokemon
constexpr var8 boxMaxPokemon
Capacity of a single PC box.
Definition
pokemonstoragebox.h:32
pokemonstorageset.h
storage.h
maxPokemonBoxes
constexpr var8 maxPokemonBoxes
Total PC boxes (12).
Definition
storage.h:35
GameCornerDBEntry
One Game Corner prize: a Pokemon or item, its coin price, and level.
Definition
gamecornerdbentry.h:37
projects
app
src
mvc
itemmarket
itemmarketentrygcpokemon.cpp
Generated by
1.17.0