![]() |
Player Class ReferenceDatabase table Player.
More...
|
Public Member Functions | |
Player (Database &, const std::string &name) | |
~Player () | |
std::string | GetName () |
bool | IsWizard () |
std::string | GetPasswd () |
std::string | GetDisplayName () |
void | SetName (const std::string &) |
void | SetPasswd (const std::string &) |
void | SetWizard (bool) |
void | SetDisplayName (const std::string &) |
void | SetEmail (const std::string &) |
long | GetArea () |
long | GetChunk () |
long | GetChunkX () |
long | GetChunkY () |
void | SetChunkX (int) |
void | SetChunkY (int) |
void | SetArea (long) |
void | SetChunk (long) |
long | GetNum () |
Get integer primary key from object. | |
int | GetFacing () |
1-north, 2-south, 3-east, 4-west | |
void | SetFacing (int) |
1-north, 2-south, 3-east, 4-west | |
void | SetRace (long) |
long | GetRace () |
void | VerifyPos () |
void | Save () |
Save the object in database. | |
bool | Exists () |
Check if the object already exists in database. | |
void | SetWizView (bool=true) |
bool | IsWizView () |
long | GetCoordX (Area &, Chunk &) |
long | GetCoordY (Area &, Chunk &) |
bool | Seen (Area &, long xcoord, long ycoord, int ch_z) |
double | SightRange () |
void | LoadSteps () |
Static Public Member Functions | |
static db::Account * | GetAccount (Database &db, const std::string &name) |
Private Attributes | |
db::Account * | m_account |
Static Private Attributes | |
static accounts_t | m_accounts |
Definition at line 37 of file Player.h.
Player::Player | ( | Database & | , | |
const std::string & | name | |||
) |
Definition at line 36 of file Player.cpp.
00036 : Object(db) 00037 , m_account(Player::GetAccount(db, name)) 00038 { 00039 }
Player::~Player | ( | ) |
std::string Player::GetName | ( | ) |
Definition at line 80 of file Player.cpp.
References m_account.
Referenced by Setcmd::Execute(), and Login::OnLine().
bool Player::IsWizard | ( | ) |
Definition at line 86 of file Player.cpp.
References m_account.
Referenced by Command::CheckArgument(), Portal::Display(), FutureHandler::DoCommand(), Setcmd::Execute(), Create::Execute(), Look::LookMap(), Command::Match(), Move::move_to(), Login::OnLine(), FutureHandler::ShowHelp(), and Move::try_move().
std::string Player::GetPasswd | ( | ) |
Definition at line 92 of file Player.cpp.
References m_account.
Referenced by Login::OnLine().
00093 { 00094 return m_account -> passwd; 00095 }
std::string Player::GetDisplayName | ( | ) |
Definition at line 98 of file Player.cpp.
References m_account.
Referenced by Who::Execute(), Quit::Execute(), InSocket::OnDelete(), Login::OnLine(), and FutureHandler::Talk().
00099 { 00100 return m_account -> display_name + "&n"; 00101 }
void Player::SetName | ( | const std::string & | ) |
Definition at line 124 of file Player.cpp.
References m_account.
Referenced by Login::OnLine().
00125 { 00126 m_account -> name = x; 00127 }
void Player::SetPasswd | ( | const std::string & | ) |
Definition at line 130 of file Player.cpp.
References m_account.
Referenced by Login::OnLine().
00131 { 00132 m_account -> passwd = x; 00133 }
void Player::SetWizard | ( | bool | ) |
Definition at line 136 of file Player.cpp.
References m_account.
00137 { 00138 m_account -> wizard = x ? 1 : 0; 00139 }
void Player::SetDisplayName | ( | const std::string & | ) |
Definition at line 142 of file Player.cpp.
References m_account.
Referenced by Setcmd::Execute(), and Login::OnLine().
00143 { 00144 m_account -> display_name = x; 00145 }
void Player::SetEmail | ( | const std::string & | ) |
Definition at line 148 of file Player.cpp.
References m_account.
00149 { 00150 m_account -> email = x; 00151 }
long Player::GetArea | ( | ) |
Definition at line 154 of file Player.cpp.
References m_account.
Referenced by Setcmd::Execute(), Map::Execute(), List::Execute(), Fill::Execute(), Enter::Execute(), Edge::Execute(), Create::Execute(), Clear::Execute(), Editor::Init(), Move::move_to(), Look::NormalMap(), Create::OnLine(), Editor::Save(), Look::Show(), Move::try_create(), Move::try_move(), and Look::WizMap().
00155 { 00156 return m_account -> area; 00157 }
long Player::GetChunk | ( | ) |
Definition at line 160 of file Player.cpp.
References m_account.
Referenced by Setcmd::Execute(), Map::Execute(), Fill::Execute(), Enter::Execute(), Edge::Execute(), Clear::Execute(), Editor::Init(), Look::NormalMap(), Create::OnLine(), Editor::Save(), Look::Show(), Move::try_create(), Move::try_move(), and Look::WizMap().
00161 { 00162 return m_account -> chunk; 00163 }
long Player::GetChunkX | ( | ) |
Definition at line 166 of file Player.cpp.
References m_account.
Referenced by Setcmd::Execute(), Fill::Execute(), Enter::Execute(), Clear::Execute(), GetCoordX(), Editor::Init(), Look::NormalMap(), Create::OnLine(), Editor::Save(), Look::Show(), Chunk::Show(), Move::try_create(), Move::try_move(), and Look::WizMap().
00167 { 00168 return m_account -> chunkx; 00169 }
long Player::GetChunkY | ( | ) |
Definition at line 172 of file Player.cpp.
References m_account.
Referenced by Setcmd::Execute(), Fill::Execute(), Enter::Execute(), Clear::Execute(), GetCoordY(), Editor::Init(), Look::NormalMap(), Create::OnLine(), Editor::Save(), Look::Show(), Chunk::Show(), Move::try_create(), Move::try_move(), and Look::WizMap().
00173 { 00174 return m_account -> chunky; 00175 }
void Player::SetChunkX | ( | int | ) |
Definition at line 178 of file Player.cpp.
References m_account.
Referenced by Enter::Execute(), Move::move_to(), and Move::try_create().
00179 { 00180 m_account -> chunkx = x; 00181 }
void Player::SetChunkY | ( | int | ) |
Definition at line 184 of file Player.cpp.
References m_account.
Referenced by Enter::Execute(), Move::move_to(), and Move::try_create().
00185 { 00186 m_account -> chunky = y; 00187 }
void Player::SetArea | ( | long | ) |
Definition at line 190 of file Player.cpp.
References m_account.
Referenced by Enter::Execute().
00191 { 00192 m_account -> area = x; 00193 }
void Player::SetChunk | ( | long | ) |
Definition at line 196 of file Player.cpp.
References m_account.
Referenced by Enter::Execute(), Move::move_to(), and Move::try_create().
00197 { 00198 m_account -> chunk = x; 00199 }
long Player::GetNum | ( | ) | [virtual] |
Get integer primary key from object.
Implements Object.
Definition at line 202 of file Player.cpp.
References m_account.
Referenced by Steps::GetStep(), Steps::GetSteps(), Chunk::Init(), and LoadSteps().
00203 { 00204 return m_account -> num; 00205 }
int Player::GetFacing | ( | ) |
1-north, 2-south, 3-east, 4-west
Definition at line 208 of file Player.cpp.
References m_account.
Referenced by Right::Execute(), Left::Execute(), Forward::Execute(), and Look::NormalMap().
00209 { 00210 return m_account -> facing; 00211 }
void Player::SetFacing | ( | int | ) |
1-north, 2-south, 3-east, 4-west
Definition at line 214 of file Player.cpp.
References m_account.
Referenced by Right::Execute(), Left::Execute(), Forward::Execute(), and Move::move_to().
00215 { 00216 m_account -> facing = x; 00217 }
void Player::SetRace | ( | long | ) |
Definition at line 340 of file Player.cpp.
References m_account.
Referenced by Login::OnLine().
00341 { 00342 m_account -> race = x; 00343 }
long Player::GetRace | ( | ) |
Definition at line 346 of file Player.cpp.
References m_account.
Referenced by Login::OnLine().
00347 { 00348 return m_account -> race; 00349 }
void Player::VerifyPos | ( | ) |
Definition at line 104 of file Player.cpp.
References Area::GetHeight(), Chunk::GetNum(), Area::GetNum(), Area::GetWidth(), m_account, Object::m_db, and Save().
Referenced by Login::OnLine().
00105 { 00106 if (!m_account -> area) 00107 { 00108 Area area(m_db, "World"); 00109 Chunk chunk(m_db, area, 1000, 1000, 0); // default starting point 00110 m_account -> area = area.GetNum(); 00111 m_account -> chunk = chunk.GetNum(); 00112 m_account -> chunkx = area.GetWidth() / 2; 00113 m_account -> chunky = area.GetHeight() / 2; 00114 m_account -> save(); 00115 } 00116 if (!m_account -> facing) 00117 { 00118 m_account -> facing = 1; 00119 Save(); 00120 } 00121 }
void Player::Save | ( | ) | [virtual] |
Save the object in database.
Implements Object.
Definition at line 65 of file Player.cpp.
References m_account.
Referenced by Save::Execute(), Login::OnLine(), and VerifyPos().
bool Player::Exists | ( | ) | [virtual] |
Check if the object already exists in database.
Implements Object.
Definition at line 72 of file Player.cpp.
References m_account.
Referenced by InSocket::OnDelete().
db::Account * Player::GetAccount | ( | Database & | db, | |
const std::string & | name | |||
) | [static] |
Definition at line 47 of file Player.cpp.
References m_accounts.
00048 { 00049 db::Account *p = m_accounts[name]; 00050 if (p != NULL) 00051 return p; 00052 p = new db::Account(db, name); 00053 p -> name = name; 00054 if (!p -> num) 00055 { 00056 Query q(db); 00057 long nr = q.get_count("select count(*) from account"); 00058 p -> wizard = !nr; 00059 } 00060 m_accounts[name] = p; 00061 return p; 00062 }
void Player::SetWizView | ( | bool | = true |
) |
Definition at line 220 of file Player.cpp.
References m_account.
Referenced by Setcmd::Execute().
00221 { 00222 m_account -> wizview = x ? 1 : 0; 00223 }
bool Player::IsWizView | ( | ) |
Definition at line 232 of file Player.cpp.
References GetChunkX(), Area::GetWidth(), and Chunk::GetX().
Referenced by Look::NormalMap().
Definition at line 238 of file Player.cpp.
References GetChunkY(), Area::GetHeight(), and Chunk::GetY().
Referenced by Look::NormalMap().
bool Player::Seen | ( | Area & | , | |
long | xcoord, | |||
long | ycoord, | |||
int | ch_z | |||
) |
Definition at line 244 of file Player.cpp.
References Steps::GetStep(), and SightRange().
Referenced by Map::Execute().
00245 { 00246 for (int y = 0; y < SightRange() + 1; y++) 00247 { 00248 db::Steps *st; 00249 if (y) 00250 { 00251 st = Steps::GetStep(*this, area, ch_z, ycoord - y); 00252 if (st) 00253 { 00254 Parse pa(st -> xcoords, ":"); 00255 std::string tmp = pa.getword(); 00256 while (tmp.size()) 00257 { 00258 long x = atol(tmp.c_str()); 00259 long x0 = x - xcoord; 00260 long y0 = st -> ycoord - ycoord; 00261 long xtmp = 2 * x0 / 3; 00262 if (sqrt(xtmp * xtmp + y0 * y0) < SightRange()) 00263 { 00264 return true; 00265 } 00266 // 00267 tmp = pa.getword(); 00268 } 00269 } 00270 st = Steps::GetStep(*this, area, ch_z, ycoord + y); 00271 if (st) 00272 { 00273 Parse pa(st -> xcoords, ":"); 00274 std::string tmp = pa.getword(); 00275 while (tmp.size()) 00276 { 00277 long x = atol(tmp.c_str()); 00278 long x0 = x - xcoord; 00279 long y0 = st -> ycoord - ycoord; 00280 long xtmp = 2 * x0 / 3; 00281 if (sqrt(xtmp * xtmp + y0 * y0) < SightRange()) 00282 { 00283 return true; 00284 } 00285 // 00286 tmp = pa.getword(); 00287 } 00288 } 00289 } 00290 else 00291 { 00292 st = Steps::GetStep(*this, area, ch_z, ycoord); 00293 if (st) 00294 { 00295 Parse pa(st -> xcoords, ":"); 00296 std::string tmp = pa.getword(); 00297 while (tmp.size()) 00298 { 00299 long x = atol(tmp.c_str()); 00300 long x0 = x - xcoord; 00301 long y0 = st -> ycoord - ycoord; 00302 long xtmp = 2 * x0 / 3; 00303 if (sqrt(xtmp * xtmp + y0 * y0) < SightRange()) 00304 { 00305 return true; 00306 } 00307 // 00308 tmp = pa.getword(); 00309 } 00310 } 00311 } 00312 } 00313 return false; 00314 }
double Player::SightRange | ( | ) |
Definition at line 317 of file Player.cpp.
References Race::Exists(), Race::GetSightRange(), m_account, and Object::m_db.
Referenced by Look::NormalMap(), and Seen().
00318 { 00319 Race r(m_db, m_account -> race); 00320 if (r.Exists()) 00321 return r.GetSightRange(); 00322 return 3.5; 00323 }
void Player::LoadSteps | ( | ) |
Definition at line 326 of file Player.cpp.
References GetNum(), and Object::m_db.
Referenced by Login::OnLine().
00327 { 00328 Query q(m_db); 00329 q.get_result("select * from steps where player=" + Utility::l2string(GetNum())); 00330 while (q.fetch_row()) 00331 { 00332 db::Steps st(&m_db, &q); 00333 Area area(m_db, st.area); 00334 Steps s(m_db, *this, area, st.zcoord, st.ycoord); 00335 } 00336 q.free_result(); 00337 }
db::Account* Player::m_account [private] |
Definition at line 85 of file Player.h.
Referenced by Exists(), GetArea(), GetChunk(), GetChunkX(), GetChunkY(), GetDisplayName(), GetFacing(), GetName(), GetNum(), GetPasswd(), GetRace(), IsWizard(), IsWizView(), Save(), SetArea(), SetChunk(), SetChunkX(), SetChunkY(), SetDisplayName(), SetEmail(), SetFacing(), SetName(), SetPasswd(), SetRace(), SetWizard(), SetWizView(), SightRange(), and VerifyPos().
accounts_t Player::m_accounts [static, private] |