· 8 years ago · Jun 06, 2018, 06:24 PM
1<?php
2
3/**#@+
4 * @version 0.0.1
5 */
6
7/**
8 * @package POT
9 * @version 0.1.5
10 * @author Wrzasq <wrzasq@gmail.com>
11 * @copyright 2007 - 2008 (C) by Wrzasq
12 * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
13 */
14
15/**
16 * OTServ character abstraction.
17 *
18 * @package POT
19 * @version 0.1.5
20 * @property string $name Character name.
21 * @property OTS_Account $account Account to which character belongs.
22 * @property OTS_Group $group Group of which character is member.
23 * @property int $sex Gender.
24 * @property int $vocation Vocation.
25 * @property int $experience Experience points.
26 * @property int $level Experience level.
27 * @property int $magLevel Magic level.
28 * @property int $health Hit points.
29 * @property int $healthMax Maximum hit points.
30 * @property int $mana Mana.
31 * @property int $manaMax Maximum mana.
32 * @property int $manaSpent Spent mana.
33 * @property int $soul Soul points.
34 * @property int $direction Looking direction.
35 * @property int $lookBody Body color.
36 * @property int $lookFeet Feet color.
37 * @property int $lookHead Hairs color.
38 * @property int $lookLegs Legs color.
39 * @property int $lookType Outfit type.
40 * @property int $lookAddons Addons.
41 * @property int $posX Spawn X coord.
42 * @property int $posY Spawn Y coord.
43 * @property int $posZ Spawn Z coord.
44 * @property int $cap Capacity.
45 * @property int $lastLogin Last login timestamp.
46 * @property int $lastIP Last login IP number.
47 * @property string $conditions Binary conditions.
48 * @property int $redSkullTime Timestamp for which red skull will last.
49 * @property string $guildNick
50 * @property OTS_GuildRank $rank
51 * @property int $townId
52 * @property int $lossExperience
53 * @property int $lossMana
54 * @property int $lossSkills
55 * @property int $lossItems
56 * @property int $balance Bank balance.
57 * @property bool $save Player save flag.
58 * @property bool $redSkull Player red skull flag.
59 * @property bool $banned Player banned state.
60 * @property-read int $id Player ID.
61 * @property-read bool $loaded Loaded state.
62 * @property-read string $townName Name of town in which player residents.
63 * @property-read OTS_House $house House which player rents.
64 * @property-read OTS_Players_List $vipsList List of VIPs of player.
65 * @property-read string $vocationName String vocation representation.
66 * @property-read array $spellsList List of known spells.
67 * @tutorial POT/Players.pkg
68 */
69class OTS_Player extends OTS_Row_DAO
70{
71/**
72 * Player data.
73 *
74 * @version 0.1.2
75 * @var array
76 */
77 private $data = array('sex' => POT::SEX_FEMALE, 'vocation' => 0, 'access' => 0, 'exp' => 0, 'level' => 1, 'maglevel' => 0, 'health' => 100, 'healthmax' => 100, 'mana' => 100, 'manamax' => 100, 'manaspent' => 0, 'lookdir' => POT::DIRECTION_NORTH, 'lookbody' => 10, 'lookfeet' => 10, 'lookhead' => 10, 'looklegs' => 10, 'looktype' => 136, 'posx' => 631, 'posy' => 124, 'posz' => 7, 'cap' => 6000, 'lastlogin' => 1, 'save' => true, 'skulltype' => 0, 'guildnick' => '', 'deleted' => 0, 'premticks' => 0, 'promoted' => 0, 'online' => 0, 'komentarz' => '', 'created' => 0, 'hide_char' => 0, 'old_name' => '');
78
79/**
80 * Player skills.
81 *
82 * @version 0.0.2
83 * @since 0.0.2
84 * @var array
85 */
86 private $skills = array();
87
88/**
89 * Magic PHP5 method.
90 *
91 * Allows object serialisation.
92 *
93 * @return array List of properties that should be saved.
94 * @version 0.0.4
95 * @since 0.0.4
96 */
97 public function __sleep()
98 {
99 return array('data', 'skills');
100 }
101
102/**
103 * Loads player with given id.
104 *
105 * @version 0.1.2
106 * @param int $id Player's ID.
107 * @throws PDOException On PDO operation error.
108 */
109 public function load($id)
110 {
111 // SELECT query on database
112 $this->data = $this->db->query('SELECT ' . $this->db->fieldName('id') . ', ' . $this->db->fieldName('name') . ', ' . $this->db->fieldName('account_id') . ', ' . $this->db->fieldName('access') . ', ' . $this->db->fieldName('sex') . ', ' . $this->db->fieldName('vocation') . ', ' . $this->db->fieldName('exp') . ', ' . $this->db->fieldName('level') . ', ' . $this->db->fieldName('maglevel') . ', ' . $this->db->fieldName('health') . ', ' . $this->db->fieldName('healthmax') . ', ' . $this->db->fieldName('mana') . ', ' . $this->db->fieldName('manamax') . ', ' . $this->db->fieldName('manaspent') . ', ' . $this->db->fieldName('lookdir') . ', ' . $this->db->fieldName('lookbody') . ', ' . $this->db->fieldName('lookfeet') . ', ' . $this->db->fieldName('lookhead') . ', ' . $this->db->fieldName('looklegs') . ', ' . $this->db->fieldName('looktype') . ', '. $this->db->fieldName('posx') . ', ' . $this->db->fieldName('posy') . ', ' . $this->db->fieldName('posz') . ', ' . $this->db->fieldName('cap') . ', ' . $this->db->fieldName('lastlogin') . ', ' . $this->db->fieldName('save') . ', ' . $this->db->fieldName('skulltype') . ', ' . $this->db->fieldName('guildnick') . ', ' . $this->db->fieldName('rank_id') . ', ' . $this->db->fieldName('online') . ', ' . $this->db->fieldName('deleted') . ', ' . $this->db->fieldName('premticks') . ', ' . $this->db->fieldName('promoted') . ', ' . $this->db->fieldName('komentarz') . ', ' . $this->db->fieldName('created') . ', ' . $this->db->fieldName('hide_char') . ', ' . $this->db->fieldName('old_name') . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . (int) $id)->fetch();
113
114 // loads skills
115 if( $this->isLoaded() )
116 {
117 foreach( $this->db->query('SELECT ' . $this->db->fieldName('skillid') . ', ' . $this->db->fieldName('value') . ', ' . $this->db->fieldName('count') . ' FROM ' . $this->db->tableName('player_skills') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetchAll() as $skill)
118 {
119 $this->skills[ $skill['skillid'] ] = array('value' => $skill['value'], 'tries' => $skill['count']);
120 }
121 }
122 }
123
124/**
125 * Loads player by it's name.
126 *
127 * @version 0.0.5
128 * @since 0.0.2
129 * @param string $name Player's name.
130 * @throws PDOException On PDO operation error.
131 */
132 public function find($name)
133 {
134 // finds player's ID
135 $id = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('name') . ' = ' . $this->db->quote($name) )->fetch();
136
137 // if anything was found
138 if( isset($id['id']) )
139 {
140 $this->load($id['id']);
141 }
142 else
143 {
144 // finds player's ID
145 $id = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('old_name') . ' = ' . $this->db->quote($name) . ' AND ' . $this->db->fieldName('nick_verify') .' = 1')->fetch();
146
147 // if anything was found
148 if( isset($id['id']) )
149 {
150 $this->load($id['id']);
151 }
152 }
153 }
154
155/**
156 * Checks if object is loaded.
157 *
158 * @return bool Load state.
159 */
160 public function isLoaded()
161 {
162 return isset($this->data['id']);
163 }
164
165/**
166 * Saves player in database.
167 *
168 * <p>
169 * If player is not loaded to represent any existing group it will create new row for it.
170 * </p>
171 *
172 * @version 0.1.2
173 * @throws PDOException On PDO operation error.
174 */
175 public function save()
176 {
177 // updates existing player
178 if( isset($this->data['id']) )
179 {
180 // UPDATE query on database
181 $this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName('name') . ' = ' . $this->db->quote($this->data['name']) . ', ' . $this->db->fieldName('account_id') . ' = ' . $this->data['account_id'] . ', ' . $this->db->fieldName('access') . ' = ' . $this->data['access'] . ', ' . $this->db->fieldName('sex') . ' = ' . $this->data['sex'] . ', ' . $this->db->fieldName('vocation') . ' = ' . $this->data['vocation'] . ', ' . $this->db->fieldName('exp') . ' = ' . $this->data['exp'] . ', ' . $this->db->fieldName('level') . ' = ' . $this->data['level'] . ', ' . $this->db->fieldName('maglevel') . ' = ' . $this->data['maglevel'] . ', ' . $this->db->fieldName('health') . ' = ' . $this->data['health'] . ', ' . $this->db->fieldName('healthmax') . ' = ' . $this->data['healthmax'] . ', ' . $this->db->fieldName('mana') . ' = ' . $this->data['mana'] . ', ' . $this->db->fieldName('manamax') . ' = ' . $this->data['manamax'] . ', ' . $this->db->fieldName('manaspent') . ' = ' . $this->data['manaspent'] . ', ' . $this->db->fieldName('lookdir') . ' = ' . $this->data['lookdir'] . ', ' . $this->db->fieldName('lookbody') . ' = ' . $this->data['lookbody'] . ', ' . $this->db->fieldName('lookfeet') . ' = ' . $this->data['lookfeet'] . ', ' . $this->db->fieldName('lookhead') . ' = ' . $this->data['lookhead'] . ', ' . $this->db->fieldName('looklegs') . ' = ' . $this->data['looklegs'] . ', ' . $this->db->fieldName('looktype') . ' = ' . $this->data['looktype'] .', ' . $this->db->fieldName('posx') . ' = ' . $this->data['posx'] . ', ' . $this->db->fieldName('posy') . ' = ' . $this->data['posy'] . ', ' . $this->db->fieldName('posz') . ' = ' . $this->data['posz'] . ', ' . $this->db->fieldName('cap') . ' = ' . $this->data['cap'] . ', ' . $this->db->fieldName('lastlogin') . ' = ' . $this->data['lastlogin'] . ', ' . $this->db->fieldName('save') . ' = ' . (int) $this->data['save'] . ', ' . $this->db->fieldName('skulltype') . ' = ' . $this->data['skulltype'] . ', ' . $this->db->fieldName('guildnick') . ' = ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->db->fieldName('rank_id') . ' = ' . $this->data['rank_id'] . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
182 }
183 // creates new player
184 else
185 {
186 // INSERT query on database
187 $this->db->query('INSERT INTO ' . $this->db->tableName('players') . ' (' . $this->db->fieldName('name') . ', ' . $this->db->fieldName('account_id') . ', ' . $this->db->fieldName('access') . ', ' . $this->db->fieldName('sex') . ', ' . $this->db->fieldName('vocation') . ', ' . $this->db->fieldName('exp') . ', ' . $this->db->fieldName('level') . ', ' . $this->db->fieldName('maglevel') . ', ' . $this->db->fieldName('health') . ', ' . $this->db->fieldName('healthmax') . ', ' . $this->db->fieldName('mana') . ', ' . $this->db->fieldName('manamax') . ', ' . $this->db->fieldName('manaspent') . ', ' . $this->db->fieldName('lookdir') . ', ' . $this->db->fieldName('lookbody') . ', ' . $this->db->fieldName('lookfeet') . ', ' . $this->db->fieldName('lookhead') . ', ' . $this->db->fieldName('looklegs') . ', ' . $this->db->fieldName('looktype') . ', ' . $this->db->fieldName('posx') . ', ' . $this->db->fieldName('posy') . ', ' . $this->db->fieldName('posz') . ', ' . $this->db->fieldName('cap') . ', ' . $this->db->fieldName('lastlogin') . ', ' . $this->db->fieldName('save') . ', ' . $this->db->fieldName('skulltype') . ', ' . $this->db->fieldName('guildnick') . ', ' . $this->db->fieldName('rank_id') . ', ' . $this->db->fieldName('created') . ', ' . $this->db->fieldName('premticks') . ', ' . $this->db->fieldName('promoted') . ') VALUES (' . $this->db->quote($this->data['name']) . ', ' . $this->data['account_id'] . ', ' . $this->data['access'] . ', ' . $this->data['sex'] . ', ' . $this->data['vocation'] . ', ' . $this->data['exp'] . ', ' . $this->data['level'] . ', ' . $this->data['maglevel'] . ', ' . $this->data['health'] . ', ' . $this->data['healthmax'] . ', ' . $this->data['mana'] . ', ' . $this->data['manamax'] . ', ' . $this->data['manaspent'] . ', ' . $this->data['lookdir'] . ', ' . $this->data['lookbody'] . ', ' . $this->data['lookfeet'] . ', ' . $this->data['lookhead'] . ', ' . $this->data['looklegs'] . ', ' . $this->data['looktype'] . ', ' . $this->data['posx'] . ', ' . $this->data['posy'] . ', ' . $this->data['posz'] . ', ' . $this->data['cap'] . ', ' . $this->data['lastlogin'] . ', ' . (int) $this->data['save'] . ', ' . $this->data['skulltype'] . ', ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->data['rank_id'] . ', ' . time() . ', ' . $this->data['premticks'] . ', ' . $this->data['promoted'] . ')');
188 // ID of new group
189 $this->data['id'] = $this->db->lastInsertId();
190 }
191
192 // updates skills - doesn't matter if we have just created character - trigger inserts new skills
193 foreach($this->skills as $id => $skill)
194 {
195 $this->db->query('UPDATE ' . $this->db->tableName('player_skills') . ' SET ' . $this->db->fieldName('value') . ' = ' . $skill['value'] . ', ' . $this->db->fieldName('count') . ' = ' . $skill['tries'] . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('skillid') . ' = ' . $id);
196 }
197 }
198
199/**
200 * Player ID.
201 *
202 * <p>
203 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
204 * </p>
205 *
206 * @version 0.0.3
207 * @return int Player ID.
208 * @throws E_OTS_NotLoaded If player is not loaded.
209 */
210 public function getId()
211 {
212 if( !isset($this->data['id']) )
213 {
214 throw new E_OTS_NotLoaded();
215 }
216
217 return $this->data['id'];
218 }
219
220 public function getHideChar()
221 {
222 if( !isset($this->data['hide_char']) )
223 {
224 throw new E_OTS_NotLoaded();
225 }
226
227 return $this->data['hide_char'];
228 }
229
230/**
231 * Player name.
232 *
233 * <p>
234 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
235 * </p>
236 *
237 * @version 0.0.3
238 * @return string Player's name.
239 * @throws E_OTS_NotLoaded If player is not loaded.
240 */
241 public function getName()
242 {
243 if( !isset($this->data['name']) )
244 {
245 throw new E_OTS_NotLoaded();
246 }
247
248 return $this->data['name'];
249 }
250
251 public function getOldName()
252 {
253 if( !isset($this->data['old_name']) )
254 {
255 throw new E_OTS_NotLoaded();
256 }
257
258 return $this->data['old_name'];
259 }
260/**
261 * Sets players's name.
262 *
263 * <p>
264 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
265 * </p>
266 *
267 * @param string $name Name.
268 */
269 public function setName($name)
270 {
271 $this->data['name'] = (string) $name;
272 }
273
274/**
275 * Returns account of this player.
276 *
277 * <p>
278 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
279 * </p>
280 *
281 * @version 0.1.0
282 * @return OTS_Account Owning account.
283 * @throws E_OTS_NotLoaded If player is not loaded.
284 * @throws PDOException On PDO operation error.
285 */
286 public function getAccount()
287 {
288 if( !isset($this->data['account_id']) )
289 {
290 throw new E_OTS_NotLoaded();
291 }
292
293 $account = new OTS_Account();
294 $account->load($this->data['account_id']);
295 return $account;
296 }
297
298/**
299 * Assigns character to account.
300 *
301 * <p>
302 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
303 * </p>
304 *
305 * @param OTS_Account $account Owning account.
306 * @throws E_OTS_NotLoaded If passed <var>$account</var> parameter is not loaded.
307 */
308 public function setAccount(OTS_Account $account)
309 {
310 $this->data['account_id'] = $account->getId();
311 }
312
313/**
314 * Returns group of this player.
315 *
316 * <p>
317 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
318 * </p>
319 *
320 * @version 0.1.0
321 * @return OTS_Group Group of which current character is member.
322 * @throws E_OTS_NotLoaded If player is not loaded.
323 * @throws PDOException On PDO operation error.
324 */
325 public function getGroup()
326 {
327 if( !isset($this->data['access']) )
328 {
329 throw new E_OTS_NotLoaded();
330 }
331
332 return $this->data['access'];
333 }
334
335/**
336 * Assigns character to group.
337 *
338 * <p>
339 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
340 * </p>
341 *
342 * @param OTS_Group $group Group to be a member.
343 * @throws E_OTS_NotLoaded If passed <var>$group</var> parameter is not loaded.
344 */
345 public function setGroup($group)
346 {
347 $this->data['access'] = $group;
348 }
349
350/**
351 * Player's Premium Account expiration timestamp.
352 *
353 * @version 0.1.5
354 * @since 0.0.3
355 * @return int Player PACC expiration timestamp.
356 * @throws E_OTS_NotLoaded If player is not loaded.
357 * @deprecated 0.1.5 Use OTS_Account->getPremiumEnd().
358 */
359 public function isPremium()
360 {
361 if( !isset($this->data['premticks']) )
362 {
363 throw new E_OTS_NotLoaded();
364 }
365 if($this->data['premticks'] > 0)
366 return true;
367 else
368 return false;
369 }
370
371 public function setPremium($hours)
372 {
373 $this->data['premticks'] = 1000*60*60*$hours;
374 }
375
376/**
377 * Player gender.
378 *
379 * <p>
380 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
381 * </p>
382 *
383 * @version 0.0.3
384 * @return int Player gender.
385 * @throws E_OTS_NotLoaded If player is not loaded.
386 */
387 public function getSex()
388 {
389 if( !isset($this->data['sex']) )
390 {
391 throw new E_OTS_NotLoaded();
392 }
393
394 return $this->data['sex'];
395 }
396
397 public function isDeleted()
398 {
399 if( !isset($this->data['deleted']) )
400 {
401 throw new E_OTS_NotLoaded();
402 }
403
404 return $this->data['deleted'] > 0;
405 }
406
407 public function isOnline()
408 {
409 if( !isset($this->data['online']) )
410 {
411 throw new E_OTS_NotLoaded();
412 }
413
414 return $this->data['online'] == 1;
415 }
416
417 public function getCreated()
418 {
419 if( !isset($this->data['created']) )
420 {
421 throw new E_OTS_NotLoaded();
422 }
423
424 return $this->data['created'];
425 }
426
427 public function getComment()
428 {
429 if( !isset($this->data['komentarz']) )
430 {
431 throw new E_OTS_NotLoaded();
432 }
433
434 return $this->data['komentarz'];
435 }
436
437/**
438 * Sets player gender.
439 *
440 * <p>
441 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
442 * </p>
443 *
444 * @param int $sex Player gender.
445 */
446 public function setSex($sex)
447 {
448 $this->data['sex'] = (int) $sex;
449 }
450
451/**
452 * Player proffesion.
453 *
454 * <p>
455 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
456 * </p>
457 *
458 * @version 0.0.3
459 * @return int Player proffesion.
460 * @throws E_OTS_NotLoaded If player is not loaded.
461 */
462 public function getVocation()
463 {
464 if( !isset($this->data['vocation']) )
465 {
466 throw new E_OTS_NotLoaded();
467 }
468
469 return $this->data['vocation'];
470 }
471
472
473 public function getPromotion()
474 {
475 if( !isset($this->data['promoted']) )
476 {
477 throw new E_OTS_NotLoaded();
478 }
479
480 return $this->data['promoted'];
481 }
482/**
483 * Sets player proffesion.
484 *
485 * <p>
486 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
487 * </p>
488 *
489 * @param int $vocation Player proffesion.
490 */
491 public function setVocation($vocation)
492 {
493 $this->data['vocation'] = (int) $vocation;
494 }
495
496 public function setPromotion($promotion)
497 {
498 $this->data['promoted'] = (int) $promotion;
499 }
500/**
501 * Experience points.
502 *
503 * <p>
504 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
505 * </p>
506 *
507 * @version 0.0.3
508 * @return int Experience points.
509 * @throws E_OTS_NotLoaded If player is not loaded.
510 */
511 public function getExperience()
512 {
513 if( !isset($this->data['exp']) )
514 {
515 throw new E_OTS_NotLoaded();
516 }
517
518 return $this->data['exp'];
519 }
520
521/**
522 * Sets experience points.
523 *
524 * <p>
525 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
526 * </p>
527 *
528 * @param int $experience Experience points.
529 */
530 public function setExperience($experience)
531 {
532 $this->data['exp'] = (int) $experience;
533 }
534
535/**
536 * Experience level.
537 *
538 * <p>
539 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
540 * </p>
541 *
542 * @version 0.0.3
543 * @return int Experience level.
544 * @throws E_OTS_NotLoaded If player is not loaded.
545 */
546 public function getLevel()
547 {
548 if( !isset($this->data['level']) )
549 {
550 throw new E_OTS_NotLoaded();
551 }
552
553 return $this->data['level'];
554 }
555
556/**
557 * Sets experience level.
558 *
559 * <p>
560 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
561 * </p>
562 *
563 * @param int $level Experience level.
564 */
565 public function setLevel($level)
566 {
567 $this->data['level'] = (int) $level;
568 }
569
570/**
571 * Magic level.
572 *
573 * <p>
574 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
575 * </p>
576 *
577 * @version 0.0.3
578 * @return int Magic level.
579 * @throws E_OTS_NotLoaded If player is not loaded.
580 */
581 public function getMagLevel()
582 {
583 if( !isset($this->data['maglevel']) )
584 {
585 throw new E_OTS_NotLoaded();
586 }
587
588 return $this->data['maglevel'];
589 }
590
591/**
592 * Sets magic level.
593 *
594 * <p>
595 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
596 * </p>
597 *
598 * @param int $maglevel Magic level.
599 */
600 public function setMagLevel($maglevel)
601 {
602 $this->data['maglevel'] = (int) $maglevel;
603 }
604
605/**
606 * Current HP.
607 *
608 * <p>
609 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
610 * </p>
611 *
612 * @version 0.0.3
613 * @return int Current HP.
614 * @throws E_OTS_NotLoaded If player is not loaded.
615 */
616 public function getHealth()
617 {
618 if( !isset($this->data['health']) )
619 {
620 throw new E_OTS_NotLoaded();
621 }
622
623 return $this->data['health'];
624 }
625
626/**
627 * Sets current HP.
628 *
629 * <p>
630 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
631 * </p>
632 *
633 * @param int $health Current HP.
634 */
635 public function setHealth($health)
636 {
637 $this->data['health'] = (int) $health;
638 }
639
640/**
641 * Maximum HP.
642 *
643 * <p>
644 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
645 * </p>
646 *
647 * @version 0.0.3
648 * @return int Maximum HP.
649 * @throws E_OTS_NotLoaded If player is not loaded.
650 */
651 public function getHealthMax()
652 {
653 if( !isset($this->data['healthmax']) )
654 {
655 throw new E_OTS_NotLoaded();
656 }
657
658 return $this->data['healthmax'];
659 }
660
661/**
662 * Sets maximum HP.
663 *
664 * <p>
665 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
666 * </p>
667 *
668 * @param int $healthmax Maximum HP.
669 */
670 public function setHealthMax($healthmax)
671 {
672 $this->data['healthmax'] = (int) $healthmax;
673 }
674
675/**
676 * Current mana.
677 *
678 * <p>
679 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
680 * </p>
681 *
682 * @version 0.0.3
683 * @return int Current mana.
684 * @throws E_OTS_NotLoaded If player is not loaded.
685 */
686 public function getMana()
687 {
688 if( !isset($this->data['mana']) )
689 {
690 throw new E_OTS_NotLoaded();
691 }
692
693 return $this->data['mana'];
694 }
695
696/**
697 * Sets current mana.
698 *
699 * <p>
700 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
701 * </p>
702 *
703 * @param int $mana Current mana.
704 */
705 public function setMana($mana)
706 {
707 $this->data['mana'] = (int) $mana;
708 }
709
710/**
711 * Maximum mana.
712 *
713 * <p>
714 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
715 * </p>
716 *
717 * @version 0.0.3
718 * @return int Maximum mana.
719 * @throws E_OTS_NotLoaded If player is not loaded.
720 */
721 public function getManaMax()
722 {
723 if( !isset($this->data['manamax']) )
724 {
725 throw new E_OTS_NotLoaded();
726 }
727
728 return $this->data['manamax'];
729 }
730
731/**
732 * Sets maximum mana.
733 *
734 * <p>
735 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
736 * </p>
737 *
738 * @param int $manamax Maximum mana.
739 */
740 public function setManaMax($manamax)
741 {
742 $this->data['manamax'] = (int) $manamax;
743 }
744
745/**
746 * Mana spent.
747 *
748 * <p>
749 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
750 * </p>
751 *
752 * @version 0.0.3
753 * @return int Mana spent.
754 * @throws E_OTS_NotLoaded If player is not loaded.
755 */
756 public function getManaSpent()
757 {
758 if( !isset($this->data['manaspent']) )
759 {
760 throw new E_OTS_NotLoaded();
761 }
762
763 return $this->data['manaspent'];
764 }
765
766/**
767 * Sets mana spent.
768 *
769 * <p>
770 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
771 * </p>
772 *
773 * @param int $manaspent Mana spent.
774 */
775 public function setManaSpent($manaspent)
776 {
777 $this->data['manaspent'] = (int) $manaspent;
778 }
779
780/**
781 * Looking direction.
782 *
783 * <p>
784 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
785 * </p>
786 *
787 * @version 0.0.3
788 * @return int Looking direction.
789 * @throws E_OTS_NotLoaded If player is not loaded.
790 */
791 public function getDirection()
792 {
793 if( !isset($this->data['lookdir']) )
794 {
795 throw new E_OTS_NotLoaded();
796 }
797
798 return $this->data['lookdir'];
799 }
800
801/**
802 * Sets looking direction.
803 *
804 * <p>
805 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
806 * </p>
807 *
808 * @param int $direction Looking direction.
809 */
810 public function setDirection($direction)
811 {
812 $this->data['lookdir'] = (int) $direction;
813 }
814
815/**
816 * Body color.
817 *
818 * <p>
819 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
820 * </p>
821 *
822 * @version 0.0.3
823 * @return int Body color.
824 * @throws E_OTS_NotLoaded If player is not loaded.
825 */
826 public function getLookBody()
827 {
828 if( !isset($this->data['lookbody']) )
829 {
830 throw new E_OTS_NotLoaded();
831 }
832
833 return $this->data['lookbody'];
834 }
835
836/**
837 * Sets body color.
838 *
839 * <p>
840 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
841 * </p>
842 *
843 * @param int $lookbody Body color.
844 */
845 public function setLookBody($lookbody)
846 {
847 $this->data['lookbody'] = (int) $lookbody;
848 }
849
850/**
851 * Boots color.
852 *
853 * <p>
854 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
855 * </p>
856 *
857 * @version 0.0.3
858 * @return int Boots color.
859 * @throws E_OTS_NotLoaded If player is not loaded.
860 */
861 public function getLookFeet()
862 {
863 if( !isset($this->data['lookfeet']) )
864 {
865 throw new E_OTS_NotLoaded();
866 }
867
868 return $this->data['lookfeet'];
869 }
870
871/**
872 * Sets boots color.
873 *
874 * <p>
875 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
876 * </p>
877 *
878 * @param int $lookfeet Boots color.
879 */
880 public function setLookFeet($lookfeet)
881 {
882 $this->data['lookfeet'] = (int) $lookfeet;
883 }
884
885/**
886 * Hair color.
887 *
888 * <p>
889 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
890 * </p>
891 *
892 * @version 0.0.3
893 * @return int Hair color.
894 * @throws E_OTS_NotLoaded If player is not loaded.
895 */
896 public function getLookHead()
897 {
898 if( !isset($this->data['lookhead']) )
899 {
900 throw new E_OTS_NotLoaded();
901 }
902
903 return $this->data['lookhead'];
904 }
905
906/**
907 * Sets hair color.
908 *
909 * <p>
910 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
911 * </p>
912 *
913 * @param int $lookhead Hair color.
914 */
915 public function setLookHead($lookhead)
916 {
917 $this->data['lookhead'] = (int) $lookhead;
918 }
919
920/**
921 * Legs color.
922 *
923 * <p>
924 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
925 * </p>
926 *
927 * @version 0.0.3
928 * @return int Legs color.
929 * @throws E_OTS_NotLoaded If player is not loaded.
930 */
931 public function getLookLegs()
932 {
933 if( !isset($this->data['looklegs']) )
934 {
935 throw new E_OTS_NotLoaded();
936 }
937
938 return $this->data['looklegs'];
939 }
940
941/**
942 * Sets legs color.
943 *
944 * <p>
945 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
946 * </p>
947 *
948 * @param int $looklegs Legs color.
949 */
950 public function setLookLegs($looklegs)
951 {
952 $this->data['looklegs'] = (int) $looklegs;
953 }
954
955/**
956 * Outfit.
957 *
958 * <p>
959 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
960 * </p>
961 *
962 * @version 0.0.3
963 * @return int Outfit.
964 * @throws E_OTS_NotLoaded If player is not loaded.
965 */
966 public function getLookType()
967 {
968 if( !isset($this->data['looktype']) )
969 {
970 throw new E_OTS_NotLoaded();
971 }
972
973 return $this->data['looktype'];
974 }
975
976/**
977 * Sets outfit.
978 *
979 * <p>
980 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
981 * </p>
982 *
983 * @param int $looktype Outfit.
984 */
985 public function setLookType($looktype)
986 {
987 $this->data['looktype'] = (int) $looktype;
988 }
989
990/**
991 * X map coordinate.
992 *
993 * <p>
994 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
995 * </p>
996 *
997 * @version 0.0.3
998 * @return int X map coordinate.
999 * @throws E_OTS_NotLoaded If player is not loaded.
1000 */
1001 public function getPosX()
1002 {
1003 if( !isset($this->data['posx']) )
1004 {
1005 throw new E_OTS_NotLoaded();
1006 }
1007
1008 return $this->data['posx'];
1009 }
1010
1011/**
1012 * Sets X map coordinate.
1013 *
1014 * <p>
1015 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
1016 * </p>
1017 *
1018 * @param int $posx X map coordinate.
1019 */
1020 public function setPosX($posx)
1021 {
1022 $this->data['posx'] = (int) $posx;
1023 }
1024
1025/**
1026 * Y map coordinate.
1027 *
1028 * <p>
1029 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1030 * </p>
1031 *
1032 * @version 0.0.3
1033 * @return int Y map coordinate.
1034 * @throws E_OTS_NotLoaded If player is not loaded.
1035 */
1036 public function getPosY()
1037 {
1038 if( !isset($this->data['posy']) )
1039 {
1040 throw new E_OTS_NotLoaded();
1041 }
1042
1043 return $this->data['posy'];
1044 }
1045
1046/**
1047 * Sets Y map coordinate.
1048 *
1049 * <p>
1050 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
1051 * </p>
1052 *
1053 * @param int $posy Y map coordinate.
1054 */
1055 public function setPosY($posy)
1056 {
1057 $this->data['posy'] = (int) $posy;
1058 }
1059
1060/**
1061 * Z map coordinate.
1062 *
1063 * <p>
1064 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1065 * </p>
1066 *
1067 * @version 0.0.3
1068 * @return int Z map coordinate.
1069 * @throws E_OTS_NotLoaded If player is not loaded.
1070 */
1071 public function getPosZ()
1072 {
1073 if( !isset($this->data['posz']) )
1074 {
1075 throw new E_OTS_NotLoaded();
1076 }
1077
1078 return $this->data['posz'];
1079 }
1080
1081/**
1082 * Sets Z map coordinate.
1083 *
1084 * <p>
1085 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
1086 * </p>
1087 *
1088 * @param int $posz Z map coordinate.
1089 */
1090 public function setPosZ($posz)
1091 {
1092 $this->data['posz'] = (int) $posz;
1093 }
1094
1095/**
1096 * Capacity.
1097 *
1098 * <p>
1099 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1100 * </p>
1101 *
1102 * @version 0.0.3
1103 * @return int Capacity.
1104 * @throws E_OTS_NotLoaded If player is not loaded.
1105 */
1106 public function getCap()
1107 {
1108 if( !isset($this->data['cap']) )
1109 {
1110 throw new E_OTS_NotLoaded();
1111 }
1112
1113 return $this->data['cap'];
1114 }
1115
1116/**
1117 * Sets capacity.
1118 *
1119 * <p>
1120 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
1121 * </p>
1122 *
1123 * @param int $cap Capacity.
1124 */
1125 public function setCap($cap)
1126 {
1127 $this->data['cap'] = (int) $cap;
1128 }
1129
1130/**
1131 * Last login timestamp.
1132 *
1133 * <p>
1134 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1135 * </p>
1136 *
1137 * @version 0.0.3
1138 * @return int Last login timestamp.
1139 * @throws E_OTS_NotLoaded If player is not loaded.
1140 */
1141 public function getLastLogin()
1142 {
1143 if( !isset($this->data['lastlogin']) )
1144 {
1145 throw new E_OTS_NotLoaded();
1146 }
1147
1148 return $this->data['lastlogin'];
1149 }
1150
1151/**
1152 * Sets last login timestamp.
1153 *
1154 * <p>
1155 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
1156 * </p>
1157 *
1158 * @param int $lastlogin Last login timestamp.
1159 */
1160 public function setLastLogin($lastlogin)
1161 {
1162 $this->data['lastlogin'] = (int) $lastlogin;
1163 }
1164
1165
1166/**
1167 * Checks if save flag is set.
1168 *
1169 * <p>
1170 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1171 * </p>
1172 *
1173 * @version 0.0.7
1174 * @return bool PACC days.
1175 * @throws E_OTS_NotLoaded If player is not loaded.
1176 */
1177 public function isSaveSet()
1178 {
1179 if( !isset($this->data['save']) )
1180 {
1181 throw new E_OTS_NotLoaded();
1182 }
1183
1184 return $this->data['save'];
1185 }
1186
1187/**
1188 * Unsets save flag.
1189 *
1190 * <p>
1191 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
1192 * </p>
1193 *
1194 * @version 0.0.7
1195 */
1196 public function unsetSave()
1197 {
1198 $this->data['save'] = false;
1199 }
1200
1201/**
1202 * @version 0.0.7
1203 * @since 0.0.6
1204 * @return int Save counter.
1205 * @throws E_OTS_NotLoaded If player is not loaded.
1206 * @deprecated 0.0.7 Save field is back as flag not a counter.
1207 */
1208 public function getSave()
1209 {
1210 if( !isset($this->data['save']) )
1211 {
1212 throw new E_OTS_NotLoaded();
1213 }
1214
1215 return $this->data['save'];
1216 }
1217
1218/**
1219 * Sets save flag.
1220 *
1221 * <p>
1222 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
1223 * </p>
1224 *
1225 * @version 0.0.7
1226 * @param int $save Deprecated, unused, optional.
1227 */
1228 public function setSave($save = 1)
1229 {
1230 $this->data['save'] = true;
1231 }
1232
1233/**
1234 * Guild nick.
1235 *
1236 * <p>
1237 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1238 * </p>
1239 *
1240 * @version 0.0.3
1241 * @return string Guild title.
1242 * @throws E_OTS_NotLoaded If player is not loaded.
1243 */
1244 public function getGuildNick()
1245 {
1246 if( !isset($this->data['guildnick']) )
1247 {
1248 throw new E_OTS_NotLoaded();
1249 }
1250
1251 return $this->data['guildnick'];
1252 }
1253
1254/**
1255 * Sets guild nick.
1256 *
1257 * <p>
1258 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
1259 * </p>
1260 *
1261 * @param string $guildnick Name.
1262 */
1263 public function setGuildNick($guildnick)
1264 {
1265 $this->data['guildnick'] = (string) $guildnick;
1266 }
1267
1268/**
1269 * @version 0.0.3
1270 * @return int Guild rank ID.
1271 * @throws E_OTS_NotLoaded If player is not loaded.
1272 * @deprecated 0.0.4 Use getRank().
1273 */
1274 public function getRankId()
1275 {
1276 if( !isset($this->data['rank_id']) )
1277 {
1278 throw new E_OTS_NotLoaded();
1279 }
1280
1281 return $this->data['rank_id'];
1282 }
1283
1284/**
1285 * Assigned guild rank.
1286 *
1287 * <p>
1288 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1289 * </p>
1290 *
1291 * @version 0.1.0
1292 * @return OTS_GuildRank|null Guild rank (null if not member of any).
1293 * @throws E_OTS_NotLoaded If player is not loaded.
1294 * @throws PDOException On PDO operation error.
1295 */
1296 public function getRank()
1297 {
1298 if( !isset($this->data['rank_id']) )
1299 {
1300 throw new E_OTS_NotLoaded();
1301 }
1302
1303 if($this->data['rank_id'] == 0)
1304 {
1305 return null;
1306 }
1307
1308 $guildRank = new OTS_GuildRank();
1309 $guildRank->load($this->data['rank_id']);
1310 return $guildRank;
1311 }
1312
1313/**
1314 * @param int $rank_id Guild rank ID.
1315 * @deprecated 0.0.4 Use setRank().
1316 */
1317 public function setRankId($rank_id)
1318 {
1319 $this->data['rank_id'] = (int) $rank_id;
1320 }
1321
1322/**
1323 * Assigns guild rank.
1324 *
1325 * <p>
1326 * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database.
1327 * </p>
1328 *
1329 * @param OTS_GuildRank|null Guild rank (null to clear assign).
1330 * @throws E_OTS_NotLoaded If passed <var>$guildRank</var> parameter is not loaded.
1331 */
1332 public function setRank(OTS_GuildRank $guildRank = null)
1333 {
1334 if( isset($guildRank) )
1335 {
1336 $this->data['rank_id'] = $guildRank->getId();
1337 }
1338 else
1339 {
1340 $this->data['rank_id'] = 0;
1341 }
1342 }
1343
1344/**
1345 * Reads custom field.
1346 *
1347 * <p>
1348 * Reads field by it's name. Can read any field of given record that exists in database.
1349 * </p>
1350 *
1351 * <p>
1352 * Note: You should use this method only for fields that are not provided in standard setters/getters (SVN fields). This method runs SQL query each time you call it so it highly overloads used resources.
1353 * </p>
1354 *
1355 * @version 0.0.5
1356 * @since 0.0.3
1357 * @param string $field Field name.
1358 * @return string Field value.
1359 * @throws E_OTS_NotLoaded If player is not loaded.
1360 * @throws PDOException On PDO operation error.
1361 */
1362 public function getCustomField($field)
1363 {
1364 if( !isset($this->data['id']) )
1365 {
1366 throw new E_OTS_NotLoaded();
1367 }
1368
1369 $value = $this->db->query('SELECT ' . $this->db->fieldName($field) . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id'])->fetch();
1370 return $value[$field];
1371 }
1372
1373/**
1374 * Writes custom field.
1375 *
1376 * <p>
1377 * Write field by it's name. Can write any field of given record that exists in database.
1378 * </p>
1379 *
1380 * <p>
1381 * Note: You should use this method only for fields that are not provided in standard setters/getters (SVN fields). This method runs SQL query each time you call it so it highly overloads used resources.
1382 * </p>
1383 *
1384 * <p>
1385 * Note: Make sure that you pass $value argument of correct type. This method determinates whether to quote field value. It is safe - it makes you sure that no unproper queries that could lead to SQL injection will be executed, but it can make your code working wrong way. For example: $object->setCustomField('foo', '1'); will quote 1 as as string ('1') instead of passing it as a integer.
1386 * </p>
1387 *
1388 * @version 0.0.5
1389 * @since 0.0.3
1390 * @param string $field Field name.
1391 * @param mixed $value Field value.
1392 * @throws E_OTS_NotLoaded If player is not loaded.
1393 * @throws PDOException On PDO operation error.
1394 */
1395 public function setCustomField($field, $value)
1396 {
1397 if( !isset($this->data['id']) )
1398 {
1399 throw new E_OTS_NotLoaded();
1400 }
1401
1402 // quotes value for SQL query
1403 if(!( is_int($value) || is_float($value) ))
1404 {
1405 $value = $this->db->quote($value);
1406 }
1407
1408 $this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName($field) . ' = ' . $value . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
1409 }
1410
1411/**
1412 * Returns player's skill.
1413 *
1414 * @version 0.0.2
1415 * @since 0.0.2
1416 * @param int $skill Skill ID.
1417 * @return int Skill value.
1418 * @throws E_OTS_NotLoaded If player is not loaded.
1419 */
1420 public function getSkill($skill)
1421 {
1422 if( !isset($this->skills[$skill]) )
1423 {
1424 throw new E_OTS_NotLoaded();
1425 }
1426
1427 return $this->skills[$skill]['value'];
1428 }
1429
1430/**
1431 * Sets skill value.
1432 *
1433 * @version 0.0.2
1434 * @since 0.0.2
1435 * @param int $skill Skill ID.
1436 * @param int $value Skill value.
1437 */
1438 public function setSkill($skill, $value)
1439 {
1440 $this->skills[ (int) $skill]['value'] = (int) $value;
1441 }
1442
1443/**
1444 * Returns player's skill's tries for next level.
1445 *
1446 * @version 0.0.2
1447 * @since 0.0.2
1448 * @param int $skill Skill ID.
1449 * @return int Skill tries.
1450 * @throws E_OTS_NotLoaded If player is not loaded.
1451 */
1452 public function getSkillTries($skill)
1453 {
1454 if( !isset($this->skills[$skill]) )
1455 {
1456 throw new E_OTS_NotLoaded();
1457 }
1458
1459 return $this->skills[$skill]['count'];
1460 }
1461
1462/**
1463 * Sets skill's tries for next level.
1464 *
1465 * @version 0.0.2
1466 * @since 0.0.2
1467 * @param int $skill Skill ID.
1468 * @param int $tries Skill tries.
1469 */
1470 public function setSkillTries($skill, $tries)
1471 {
1472 $this->skills[ (int) $skill]['count'] = (int) $tries;
1473 }
1474
1475/**
1476 * Returns value of storage record.
1477 *
1478 * @version 0.1.3
1479 * @since 0.1.2
1480 * @param int $key Storage key.
1481 * @return int|null Stored value (null if not set).
1482 * @throws E_OTS_NotLoaded If player is not loaded.
1483 * @throws PDOException On PDO operation error.
1484 */
1485 public function getStorage($key)
1486 {
1487 if( !isset($this->data['id']) )
1488 {
1489 throw new E_OTS_NotLoaded();
1490 }
1491
1492 $value = $this->db->query('SELECT ' . $this->db->fieldName('value') . ' FROM ' . $this->db->tableName('player_storage') . ' WHERE ' . $this->db->fieldName('key') . ' = ' . (int) $key . ' AND ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetch();
1493
1494 if($value !== false)
1495 {
1496 return null;
1497 }
1498
1499 return $value['value'];
1500 }
1501
1502/**
1503 * Sets value of storage record.
1504 *
1505 * @version 0.1.2
1506 * @since 0.1.2
1507 * @param int $key Storage key.
1508 * @param int $value Stored value.
1509 * @throws E_OTS_NotLoaded If player is not loaded.
1510 * @throws PDOException On PDO operation error.
1511 */
1512 public function setStorage($key, $value)
1513 {
1514 if( !isset($this->data['id']) )
1515 {
1516 throw new E_OTS_NotLoaded();
1517 }
1518
1519 $current = $this->getStorage($key);
1520
1521 // checks if there is any row to be updates
1522 if( isset($current) )
1523 {
1524 $this->db->query('UPDATE ' . $this->db->tableName('player_storage') . ' SET ' . $this->db->fieldName('value') . ' = ' . (int) $value . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('key') . ' = ' . (int) $key);
1525 }
1526 // inserts new storage record
1527 else
1528 {
1529 $this->db->query('INSERT INTO ' . $this->db->tableName('player_storage') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('key') . ', ' . $this->db->fieldName('value') . ') VALUES (' . $this->data['id'] . ', ' . (int) $key . ', ' . (int) $value . ')');
1530 }
1531 }
1532
1533
1534/**
1535 * Deletes player.
1536 *
1537 * @version 0.0.5
1538 * @since 0.0.5
1539 * @throws E_OTS_NotLoaded If player is not loaded.
1540 * @throws PDOException On PDO operation error.
1541 */
1542 public function delete()
1543 {
1544 if( !isset($this->data['id']) )
1545 {
1546 throw new E_OTS_NotLoaded();
1547 }
1548
1549 // deletes row from database
1550 $this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName('deleted') . ' = 1 WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
1551
1552 // resets object handle
1553 unset($this->data['id']);
1554 }
1555
1556/**
1557 * Returns list of VIPs.
1558 *
1559 * <p>
1560 * It means list of players which this player have on his/her list.
1561 * </p>
1562 *
1563 * @version 0.1.3
1564 * @since 0.1.3
1565 * @return OTS_Players_List List of VIPs.
1566 * @throws E_OTS_NotLoaded If player is not loaded.
1567 * @throws PDOException On PDO operation error.
1568 */
1569 public function getVIPsList()
1570 {
1571 if( !isset($this->data['id']) )
1572 {
1573 throw new E_OTS_NotLoaded();
1574 }
1575
1576 $list = new OTS_Players_List();
1577
1578 // foreign table fields identifiers
1579 $field1 = new OTS_SQLField('player_id', 'player_viplist');
1580 $field2 = new OTS_SQLField('vip_id', 'player_viplist');
1581
1582 // creates filter
1583 $filter = new OTS_SQLFilter();
1584 $filter->addFilter($field1, $this->data['id']);
1585 $filter->compareField('id', $field2);
1586
1587 // puts filter onto list
1588 $list->setFilter($filter);
1589
1590 return $list;
1591 }
1592
1593/**
1594 * Adds player to VIP list.
1595 *
1596 * @version 0.1.4
1597 * @since 0.1.3
1598 * @param OTS_Player $player Player to be added.
1599 * @throws E_OTS_NotLoaded If player is not loaded.
1600 * @throws PDOException On PDO operation error.
1601 */
1602 public function addVIP(OTS_Player $player)
1603 {
1604 if( !isset($this->data['id']) )
1605 {
1606 throw new E_OTS_NotLoaded();
1607 }
1608
1609 $this->db->query('INSERT INTO ' . $this->db->tableName('player_viplist') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('vip_id') . ') VALUES (' . $this->data['id'] . ', ' . $player->getId() . ')');
1610 }
1611
1612/**
1613 * Checks if given player is a VIP for current one.
1614 *
1615 * @version 0.1.5
1616 * @since 0.1.3
1617 * @param OTS_Player $player Player to check.
1618 * @return bool True, if given player is on VIP list.
1619 * @throws E_OTS_NotLoaded If player is not loaded.
1620 * @throws PDOException On PDO operation error.
1621 */
1622 public function isVIP(OTS_Player $player)
1623 {
1624 if( !isset($this->data['id']) )
1625 {
1626 throw new E_OTS_NotLoaded();
1627 }
1628
1629 return $this->db->query('SELECT COUNT(' . $this->db->fieldName('vip_id') . ') FROM ' . $this->db->tableName('player_viplist') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('vip_id') . ' = ' . $player->getId() )->fetchColumn() > 0;
1630 }
1631
1632/**
1633 * Deletes player from VIP list.
1634 *
1635 * @version 0.1.4
1636 * @since 0.1.3
1637 * @param OTS_Player $player Player to be deleted.
1638 * @throws E_OTS_NotLoaded If player is not loaded.
1639 * @throws PDOException On PDO operation error.
1640 */
1641 public function deleteVIP(OTS_Player $player)
1642 {
1643 if( !isset($this->data['id']) )
1644 {
1645 throw new E_OTS_NotLoaded();
1646 }
1647
1648 $this->db->query('DELETE FROM ' . $this->db->tableName('player_viplist') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('vip_id') . ' = ' . $player->getId() );
1649 }
1650
1651
1652/**
1653 * Magic PHP5 method.
1654 *
1655 * @version 0.1.5
1656 * @since 0.1.0
1657 * @param string $name Property name.
1658 * @return mixed Property value.
1659 * @throws E_OTS_NotLoaded When player is not loaded.
1660 * @throws OutOfBoundsException For non-supported properties.
1661 * @throws PDOException On PDO operation error.
1662 */
1663 public function __get($name)
1664 {
1665 switch($name)
1666 {
1667 case 'id':
1668 return $this->getId();
1669
1670 case 'name':
1671 return $this->getName();
1672
1673 case 'account':
1674 return $this->getAccount();
1675
1676 case 'group':
1677 return $this->getGroup();
1678
1679 case 'sex':
1680 return $this->getSex();
1681
1682 case 'vocation':
1683 return $this->getVocation();
1684
1685 case 'exp':
1686 return $this->getExperience();
1687
1688 case 'level':
1689 return $this->getLevel();
1690
1691 case 'magLevel':
1692 return $this->getMagLevel();
1693
1694 case 'health':
1695 return $this->getHealth();
1696
1697 case 'healthMax':
1698 return $this->getHealthMax();
1699
1700 case 'mana':
1701 return $this->getMana();
1702
1703 case 'manaMax':
1704 return $this->getManaMax();
1705
1706 case 'manaSpent':
1707 return $this->getManaSpent();
1708
1709 case 'lookdir':
1710 return $this->getDirection();
1711
1712 case 'lookBody':
1713 return $this->getLookBody();
1714
1715 case 'lookFeet':
1716 return $this->getLookFeet();
1717
1718 case 'lookHead':
1719 return $this->getLookHead();
1720
1721 case 'lookLegs':
1722 return $this->getLookLegs();
1723
1724 case 'lookType':
1725 return $this->getLookType();
1726
1727 case 'posX':
1728 return $this->getPosX();
1729
1730 case 'posY':
1731 return $this->getPosY();
1732
1733 case 'posZ':
1734 return $this->getPosZ();
1735
1736 case 'cap':
1737 return $this->getCap();
1738
1739 case 'lastLogin':
1740 return $this->getLastLogin();
1741
1742 case 'save':
1743 return $this->isSaveSet();
1744
1745 case 'guildNick':
1746 return $this->getGuildNick();
1747
1748 case 'rank':
1749 return $this->getRank();
1750
1751 case 'loaded':
1752 return $this->isLoaded();
1753
1754 case 'vipsList':
1755 return $this->getVIPsList();
1756
1757 default:
1758 throw new OutOfBoundsException();
1759 }
1760 }
1761
1762/**
1763 * Magic PHP5 method.
1764 *
1765 * @version 0.1.5
1766 * @since 0.1.0
1767 * @param string $name Property name.
1768 * @param mixed $value Property value.
1769 * @throws E_OTS_NotLoaded When passing object value which represents not-initialised instance.
1770 * @throws OutOfBoundsException For non-supported properties.
1771 */
1772 public function __set($name, $value)
1773 {
1774 switch($name)
1775 {
1776 case 'name':
1777 $this->setName($value);
1778 break;
1779
1780 case 'account':
1781 $this->setAccount($value);
1782 break;
1783
1784 case 'group':
1785 $this->setGroup($value);
1786 break;
1787
1788 case 'sex':
1789 $this->setSex($value);
1790 break;
1791
1792 case 'vocation':
1793 $this->setVocation($value);
1794 break;
1795
1796 case 'exp':
1797 $this->setExperience($value);
1798 break;
1799
1800 case 'level':
1801 $this->setLevel($value);
1802 break;
1803
1804 case 'magLevel':
1805 $this->setMagLevel($value);
1806 break;
1807
1808 case 'health':
1809 $this->setHealth($value);
1810 break;
1811
1812 case 'healthMax':
1813 $this->setHealthMax($value);
1814 break;
1815
1816 case 'mana':
1817 $this->setMana($value);
1818 break;
1819
1820 case 'manaMax':
1821 $this->setManaMax($value);
1822 break;
1823
1824 case 'manaSpent':
1825 $this->setManaSpent($value);
1826 break;
1827
1828 case 'direction':
1829 $this->setDirection($value);
1830 break;
1831
1832 case 'lookBody':
1833 $this->setLookBody($value);
1834 break;
1835
1836 case 'lookFeet':
1837 $this->setLookFeet($value);
1838 break;
1839
1840 case 'lookHead':
1841 $this->setLookHead($value);
1842 break;
1843
1844 case 'lookLegs':
1845 $this->setLookLegs($value);
1846 break;
1847
1848 case 'lookType':
1849 $this->setLookType($value);
1850 break;
1851
1852 case 'posX':
1853 $this->setPosX($value);
1854 break;
1855
1856 case 'posY':
1857 $this->setPosY($value);
1858 break;
1859
1860 case 'posZ':
1861 $this->setPosZ($value);
1862 break;
1863
1864 case 'cap':
1865 $this->setCap($value);
1866 break;
1867
1868 case 'lastLogin':
1869 $this->setLastLogin($value);
1870 break;
1871
1872 case 'guildNick':
1873 $this->setGuildNick($value);
1874 break;
1875
1876 case 'rank':
1877 $this->setRank($value);
1878 break;
1879
1880 case 'save':
1881 if($value)
1882 {
1883 $this->setSave();
1884 }
1885 else
1886 {
1887 $this->unsetSave();
1888 }
1889 break;
1890
1891 default:
1892 throw new OutOfBoundsException();
1893 }
1894 }
1895
1896/**
1897 * Returns string representation of object.
1898 *
1899 * <p>
1900 * If any display driver is currently loaded then it uses it's method. Else it returns character name.
1901 * </p>
1902 *
1903 * @version 0.1.3
1904 * @since 0.1.0
1905 * @return string String representation of object.
1906 */
1907 public function __toString()
1908 {
1909 $ots = POT::getInstance();
1910
1911 // checks if display driver is loaded
1912 if( $ots->isDisplayDriverLoaded() )
1913 {
1914 return $ots->getDisplayDriver()->displayPlayer($this);
1915 }
1916
1917 return $this->getName();
1918 }
1919}
1920
1921/**#@-*/
1922
1923?>