YAPOG  0.0.1
Yet Another Pokemon Online Game
PokemonSelectRequest.cpp
Go to the documentation of this file.
5 
8 #include "Pokemon/PokemonTeam.hpp"
9 
10 namespace yse
11 {
13  : databaseManager_ (dm)
14  {
15  }
16 
17  /*
18  bool PokemonSelectRequest::Select (PokemonTable& pokemonTable)
19  {
20  yap::String queryString =
21  "SELECT "
22  "account_id, "
23  "pokemon_static_id, "
24  "pokemon_experience, "
25  "pokemon_gender, "
26  "pokemon_nickname, "
27  "pokemon_shiny, "
28  "pokemon_loyalty, "
29  "pokemon_nature, "
30  "pokemon_trading_number, "
31  "pokemon_trader_account_id, "
32  "pokemon_box_number, "
33  "pokemon_box_index, "
34  "pokemon_catch_date "
35  "FROM pokemon "
36  "WHERE pokemon_id = :pokemonID";
37 
38  yap::DatabaseStream select (
39  queryString,
40  databaseManager_.GetConnection ());
41 
42  select.Write (pokemonTable.id_);
43 
44  if (select.EndOfStream ())
45  throw yap::DatabaseException ("This pokemon doesn't exist !");
46 
47  pokemonTable.accountID_ = select.ReadID ();
48  pokemonTable.staticID_ = select.ReadID ();
49  pokemonTable.experience_ = select.ReadUInt ();
50  pokemonTable.gender_ = (yap::Gender) select.ReadUInt ();
51  pokemonTable.nickname_ = select.ReadString ();
52  pokemonTable.shiny_ = select.ReadBool ();
53  pokemonTable.loyalty_ = select.ReadInt ();
54  pokemonTable.nature_ = select.ReadID ();
55  pokemonTable.tradingNumber_ = select.ReadUInt ();
56  pokemonTable.traderAccountID_ = select.ReadID ();
57  pokemonTable.boxNumber_ = select.ReadUInt ();
58  pokemonTable.boxIndex_ = select.ReadID ();
59  pokemonTable.catchDate_ = select.ReadString ();
60 
61  if (!select.EndOfStream ())
62  throw yap::DatabaseException ("Pokemon information loading error !");
63  }
64 
65  PokemonTable* PokemonSelectRequest::SelectPokemon (const yap::ID& pokemonID)
66  {
67  PokemonTable* pokemonTable = new PokemonTable ();
68 
69  yap::String queryString =
70  "SELECT "
71  "account_id, "
72  "pokemon_static_id, "
73  "pokemon_experience, "
74  "pokemon_gender, "
75  "pokemon_nickname, "
76  "pokemon_shiny, "
77  "pokemon_loyalty, "
78  "pokemon_nature, "
79  "pokemon_trading_number, "
80  "pokemon_trader_account_id, "
81  "pokemon_box_number, "
82  "pokemon_box_index, "
83  "pokemon_catch_date "
84  "FROM pokemon "
85  "WHERE pokemon_id = :pokemonID";
86 
87  yap::DatabaseStream select (
88  queryString,
89  databaseManager_.GetConnection ());
90 
91  select.Write (pokemonID);
92 
93  if (select.EndOfStream ())
94  throw yap::DatabaseException ("This pokemon doesn't exist !");
95 
96  pokemonTable->id_ = pokemonID;
97 
98  pokemonTable->accountID_ = select.ReadID ();
99  pokemonTable->staticID_ = select.ReadID ();
100  pokemonTable->experience_ = select.ReadUInt ();
101  pokemonTable->gender_ = (yap::Gender) select.ReadUInt ();
102  pokemonTable->nickname_ = select.ReadString ();
103  pokemonTable->shiny_ = select.ReadBool ();
104  pokemonTable->loyalty_ = select.ReadInt ();
105  pokemonTable->nature_ = select.ReadID ();
106  pokemonTable->tradingNumber_ = select.ReadUInt ();
107  pokemonTable->traderAccountID_ = select.ReadID ();
108  pokemonTable->boxNumber_ = select.ReadUInt ();
109  pokemonTable->boxIndex_ = select.ReadID ();
110  pokemonTable->catchDate_ = select.ReadString ();
111 
112  if (!select.EndOfStream ())
113  throw yap::DatabaseException ("Pokemon information loading error !");
114 
115  return pokemonTable;
116  }
117  */
118 
120  const yap::String& trainerName,
121  const yap::ID& accountID)
122  {
123  yap::String queryString =
124  "SELECT "
125  "pokemon.pokemon_id, "
126  "pokemon.pokemon_static_id, "
127  "pokemon.pokemon_experience, "
128  "pokemon.pokemon_hp, "
129  "pokemon.pokemon_gender, "
130  "pokemon.pokemon_nickname, "
131  "pokemon.pokemon_shiny, "
132  "pokemon.pokemon_loyalty, "
133  "pokemon.pokemon_nature, "
134  "pokemon.pokemon_trading_number, "
135  "pokemon.pokemon_trader_account_id, "
136  "pokemon.pokemon_box_number, "
137  "pokemon.pokemon_box_index, "
138  "pokemon.pokemon_catch_date, "
139  "pokemon.pokemon_status, "
140 
141  "pokemon_ev.pokemon_ev_hp, "
142  "pokemon_ev.pokemon_ev_attack, "
143  "pokemon_ev.pokemon_ev_defense, "
144  "pokemon_ev.pokemon_ev_special_attack, "
145  "pokemon_ev.pokemon_ev_special_defense, "
146  "pokemon_ev.pokemon_ev_speed, "
147 
148  "pokemon_iv.pokemon_iv_hp, "
149  "pokemon_iv.pokemon_iv_attack, "
150  "pokemon_iv.pokemon_iv_defense, "
151  "pokemon_iv.pokemon_iv_special_attack, "
152  "pokemon_iv.pokemon_iv_special_defense, "
153  "pokemon_iv.pokemon_iv_speed "
154 
155  "FROM pokemon "
156  "INNER JOIN pokemon_ev ON "
157  "pokemon_ev.pokemon_id = pokemon.pokemon_id "
158  "INNER JOIN pokemon_iv ON "
159  "pokemon_iv.pokemon_id = pokemon.pokemon_id "
160  "WHERE account_id = :accountID AND pokemon_box_number = 0";
161 
162  yap::DatabaseStream select (
163  queryString,
165 
166  select.Write (accountID);
167 
168  if (select.EndOfStream ())
169  throw yap::DatabaseException ("This pokemon doesn't exist !");
170 
171  // Read data from database
172  int counter = 0;
173  PokemonTeam* pokemonTeam = new PokemonTeam ();
174 
175  while (!select.EndOfStream ())
176  {
177  PokemonTable* pokemonTable = new PokemonTable ();
178 
179  // Get the Pokemon's basic data
180  pokemonTable->accountID_ = accountID;
181  pokemonTable->id_ = select.ReadID ();
182  pokemonTable->staticID_ = select.ReadID ();
183  pokemonTable->experience_ = select.ReadUInt ();
184  pokemonTable->hp_ = select.ReadUInt16 ();
185  pokemonTable->gender_ = static_cast<yap::Gender>(select.ReadUInt ());
186  pokemonTable->nickname_ = select.ReadString ();
187  pokemonTable->shiny_ = select.ReadBool ();
188  pokemonTable->loyalty_ = select.ReadInt ();
189  pokemonTable->nature_ = select.ReadID ();
190  pokemonTable->tradingNumber_ = select.ReadUInt ();
191  pokemonTable->traderAccountID_ = select.ReadID ();
192  pokemonTable->boxNumber_ = select.ReadUInt ();
193  pokemonTable->boxIndex_ = select.ReadID ();
194  pokemonTable->catchDate_ = select.ReadString ();
195  pokemonTable->status_ = static_cast<yap::PokemonStatus>(select.ReadUInt ());
196 
197  // Get the Pokemon's EV value
198  yap::UInt16 hpEV = select.ReadUInt16 ();
199  yap::UInt16 attackEV = select.ReadUInt16 ();
200  yap::UInt16 defenseEV = select.ReadUInt16 ();
201  yap::UInt16 specialAttackEV = select.ReadUInt16 ();
202  yap::UInt16 specialDefenseEV = select.ReadUInt16 ();
203  yap::UInt16 speedEV = select.ReadUInt16 ();
204 
205  // Get the Pokemon's IV value
206  yap::UInt16 hpIV = select.ReadUInt16 ();
207  yap::UInt16 attackIV = select.ReadUInt16 ();
208  yap::UInt16 defenseIV = select.ReadUInt16 ();
209  yap::UInt16 specialAttackIV = select.ReadUInt16 ();
210  yap::UInt16 specialDefenseIV = select.ReadUInt16 ();
211  yap::UInt16 speedIV = select.ReadUInt16 ();
212 
213  // Set the stats with EV and IV
214  yap::HitPoint hp (pokemonTable->hp_, hpEV, hpIV);
215  yap::Attack attack (attackEV, attackIV);
216  yap::Defense defense (defenseEV, defenseIV);
217  yap::SpecialAttack specialAttack (specialAttackEV, specialAttackIV);
218  yap::SpecialDefense specialDefense (specialDefenseEV, specialDefenseIV);
219  yap::Speed speed (speedEV, speedIV);
220 
221  yap::PokemonStat stats (
222  hp,
223  attack,
224  defense,
225  specialAttack,
226  specialDefense,
227  speed);
228 
229  // Get the Pokemon's moves from PokemonMoveSelectRequest
230  PokemonMoveSelectRequest selectPokemonMoves (databaseManager_);
231  const yap::PokemonMoveSet& moveSet =
232  *selectPokemonMoves.SelectPokemonMoves (pokemonTable->id_);
233 
234  pokemonTeam->AddPokemon (pokemonTable->CreatePokemon (
235  trainerName, stats, moveSet));
236 
237  counter++;
238 
239  if (counter > 6)
240  throw yap::DatabaseException ("This team have more of 6 Pokemon !");
241  }
242 
243  return pokemonTeam;
244  }
245 
246 } // namespace yse