· 10 years ago · Sep 04, 2016, 06:18 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 $lossContainers
57 * @property int $balance Bank balance.
58 * @property bool $save Player save flag.
59 * @property bool $redSkull Player red skull flag.
60 * @property bool $banned Player banned state.
61 * @property-read int $id Player ID.
62 * @property-read bool $loaded Loaded state.
63 * @property-read string $townName Name of town in which player residents.
64 * @property-read OTS_House $house House which player rents.
65 * @property-read OTS_Players_List $vipsList List of VIPs of player.
66 * @property-read string $vocationName String vocation representation.
67 * @property-read array $spellsList List of known spells.
68 * @tutorial POT/Players.pkg
69 */
70class OTS_Player extends OTS_Row_DAO
71{
72/**
73 * Player data.
74 *
75 * @version 0.1.2
76 * @var array
77 */
78 private $data = array('sex' => POT::SEX_FEMALE, 'vocation' => 0, 'experience' => 0, 'level' => 1, 'maglevel' => 0, 'health' => 100, 'healthmax' => 100, 'mana' => 100, 'manamax' => 100, 'manaspent' => 0, 'soul' => 0, 'direction' => POT::DIRECTION_NORTH, 'lookbody' => 10, 'lookfeet' => 10, 'lookhead' => 10, 'looklegs' => 10, 'looktype' => 136, 'lookaddons' => 0, 'posx' => 0, 'posy' => 0, 'posz' => 0, 'cap' => 0, 'lastlogin' => 0, 'lastip' => 0, 'save' => true, 'skull' => 0, 'guildnick' => '', 'loss_experience' => 10, 'loss_mana' => 10, 'loss_skills' => 10, 'loss_items' => 10, 'loss_containers' => 10, 'balance' => 0, 'deleted' => 0, 'promotion' => 0, 'online' => 0, 'marriage' => 0, 'comment' => '', 'created' => 0, 'hide_char' => 0, 'old_name' => '', 'world_id' => 0);
79
80/**
81 * Player skills.
82 *
83 * @version 0.0.2
84 * @since 0.0.2
85 * @var array
86 */
87 private $skills = array();
88
89/**
90 * Magic PHP5 method.
91 *
92 * Allows object serialisation.
93 *
94 * @return array List of properties that should be saved.
95 * @version 0.0.4
96 * @since 0.0.4
97 */
98 public function __sleep()
99 {
100 return array('data', 'skills');
101 }
102
103/**
104 * Loads player with given id.
105 *
106 * @version 0.1.2
107 * @param int $id Player's ID.
108 * @throws PDOException On PDO operation error.
109 */
110 public function load($id)
111 {
112 // SELECT query on database
113 $this->data = $this->db->query('SELECT ' . $this->db->fieldName('id') . ', ' . $this->db->fieldName('name') . ', ' . $this->db->fieldName('account_id') . ', ' . $this->db->fieldName('group_id') . ', ' . $this->db->fieldName('sex') . ', ' . $this->db->fieldName('vocation') . ', ' . $this->db->fieldName('experience') . ', ' . $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('soul') . ', ' . $this->db->fieldName('direction') . ', ' . $this->db->fieldName('lookbody') . ', ' . $this->db->fieldName('lookfeet') . ', ' . $this->db->fieldName('lookhead') . ', ' . $this->db->fieldName('looklegs') . ', ' . $this->db->fieldName('looktype') . ', ' . $this->db->fieldName('lookaddons') . ', ' . $this->db->fieldName('posx') . ', ' . $this->db->fieldName('posy') . ', ' . $this->db->fieldName('posz') . ', ' . $this->db->fieldName('cap') . ', ' . $this->db->fieldName('lastlogin') . ', ' . $this->db->fieldName('lastip') . ', ' . $this->db->fieldName('save') . ', ' . $this->db->fieldName('conditions') . ', ' . $this->db->fieldName('skull') . ', ' . $this->db->fieldName('guildnick') . ', ' . $this->db->fieldName('rank_id') . ', ' . $this->db->fieldName('town_id') . ', ' . $this->db->fieldName('loss_experience') . ', ' . $this->db->fieldName('loss_mana') . ', ' . $this->db->fieldName('loss_skills') . ', ' . $this->db->fieldName('loss_items') . ', ' . $this->db->fieldName('loss_containers') . ', ' . $this->db->fieldName('balance') . ', ' . $this->db->fieldName('online') . ', ' . $this->db->fieldName('deleted') . ', ' . $this->db->fieldName('promotion') . ', ' . $this->db->fieldName('marriage') . ', ' . $this->db->fieldName('comment') . ', ' . $this->db->fieldName('created') . ', ' . $this->db->fieldName('hide_char') . ', ' . $this->db->fieldName('old_name') . ', ' . $this->db->fieldName('world_id') . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . (int) $id)->fetch();
114
115 // loads skills
116 if( $this->isLoaded() )
117 {
118 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)
119 {
120 $this->skills[ $skill['skillid'] ] = array('value' => $skill['value'], 'tries' => $skill['count']);
121 }
122 }
123 }
124
125/**
126 * Loads player by it's name.
127 *
128 * @version 0.0.5
129 * @since 0.0.2
130 * @param string $name Player's name.
131 * @throws PDOException On PDO operation error.
132 */
133 public function find($name)
134 {
135 // finds player's ID
136 $id = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('name') . ' = ' . $this->db->quote($name) )->fetch();
137
138 // if anything was found
139 if( isset($id['id']) )
140 {
141 $this->load($id['id']);
142 }
143 else
144 {
145 // finds player's ID
146 $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();
147
148 // if anything was found
149 if( isset($id['id']) )
150 {
151 $this->load($id['id']);
152 }
153 }
154 }
155
156/**
157 * Checks if object is loaded.
158 *
159 * @return bool Load state.
160 */
161 public function isLoaded()
162 {
163 return isset($this->data['id']);
164 }
165
166/**
167 * Saves player in database.
168 *
169 * <p>
170 * If player is not loaded to represent any existing group it will create new row for it.
171 * </p>
172 *
173 * @version 0.1.2
174 * @throws PDOException On PDO operation error.
175 */
176 public function save()
177 {
178 // updates existing player
179 if( isset($this->data['id']) )
180 {
181 // UPDATE query on database
182 $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('world_id') . ' = ' . $this->data['world_id'] . ', ' . $this->db->fieldName('group_id') . ' = ' . $this->data['group_id'] . ', ' . $this->db->fieldName('sex') . ' = ' . $this->data['sex'] . ', ' . $this->db->fieldName('vocation') . ' = ' . $this->data['vocation'] . ', ' . $this->db->fieldName('experience') . ' = ' . $this->data['experience'] . ', ' . $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('soul') . ' = ' . $this->data['soul'] . ', ' . $this->db->fieldName('direction') . ' = ' . $this->data['direction'] . ', ' . $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('lookaddons') . ' = ' . $this->data['lookaddons'] . ', ' . $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('lastip') . ' = ' . $this->data['lastip'] . ', ' . $this->db->fieldName('save') . ' = ' . (int) $this->data['save'] . ', ' . $this->db->fieldName('conditions') . ' = ' . $this->db->quote($this->data['conditions']) . ', ' . $this->db->fieldName('skull') . ' = ' . $this->data['skull'] . ', ' . $this->db->fieldName('guildnick') . ' = ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->db->fieldName('rank_id') . ' = ' . $this->data['rank_id'] . ', ' . $this->db->fieldName('town_id') . ' = ' . $this->data['town_id'] . ', ' . $this->db->fieldName('loss_experience') . ' = ' . $this->data['loss_experience'] . ', ' . $this->db->fieldName('loss_mana') . ' = ' . $this->data['loss_mana'] . ', ' . $this->db->fieldName('loss_skills') . ' = ' . $this->data['loss_skills'] . ', ' . $this->db->fieldName('loss_items') . ' = ' . $this->data['loss_items'] . ', ' . $this->db->fieldName('loss_containers') . ' = ' . $this->data['loss_containers'] . ', ' . $this->db->fieldName('balance') . ' = ' . $this->data['balance'] . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
183 }
184 // creates new player
185 else
186 {
187 // INSERT query on database
188 $this->db->query('INSERT INTO ' . $this->db->tableName('players') . ' (' . $this->db->fieldName('name') . ', ' . $this->db->fieldName('account_id') . ', ' . $this->db->fieldName('world_id') . ', ' . $this->db->fieldName('group_id') . ', ' . $this->db->fieldName('sex') . ', ' . $this->db->fieldName('vocation') . ', ' . $this->db->fieldName('experience') . ', ' . $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('soul') . ', ' . $this->db->fieldName('direction') . ', ' . $this->db->fieldName('lookbody') . ', ' . $this->db->fieldName('lookfeet') . ', ' . $this->db->fieldName('lookhead') . ', ' . $this->db->fieldName('looklegs') . ', ' . $this->db->fieldName('looktype') . ', ' . $this->db->fieldName('lookaddons') . ', ' . $this->db->fieldName('posx') . ', ' . $this->db->fieldName('posy') . ', ' . $this->db->fieldName('posz') . ', ' . $this->db->fieldName('cap') . ', ' . $this->db->fieldName('lastlogin') . ', ' . $this->db->fieldName('lastip') . ', ' . $this->db->fieldName('save') . ', ' . $this->db->fieldName('conditions') . ', ' . $this->db->fieldName('skull') . ', ' . $this->db->fieldName('guildnick') . ', ' . $this->db->fieldName('rank_id') . ', ' . $this->db->fieldName('town_id') . ', ' . $this->db->fieldName('loss_experience') . ', ' . $this->db->fieldName('loss_mana') . ', ' . $this->db->fieldName('loss_skills') . ', ' . $this->db->fieldName('loss_items') . ', ' . $this->db->fieldName('loss_containers') . ', ' . $this->db->fieldName('balance') . ', ' . $this->db->fieldName('created') . ', ' . $this->db->fieldName('promotion') . ') VALUES (' . $this->db->quote($this->data['name']) . ', ' . $this->data['account_id'] . ', ' . $this->data['world_id'] . ', ' . $this->data['group_id'] . ', ' . $this->data['sex'] . ', ' . $this->data['vocation'] . ', ' . $this->data['experience'] . ', ' . $this->data['level'] . ', ' . $this->data['maglevel'] . ', ' . $this->data['health'] . ', ' . $this->data['healthmax'] . ', ' . $this->data['mana'] . ', ' . $this->data['manamax'] . ', ' . $this->data['manaspent'] . ', ' . $this->data['soul'] . ', ' . $this->data['direction'] . ', ' . $this->data['lookbody'] . ', ' . $this->data['lookfeet'] . ', ' . $this->data['lookhead'] . ', ' . $this->data['looklegs'] . ', ' . $this->data['looktype'] . ', ' . $this->data['lookaddons'] . ', ' . $this->data['posx'] . ', ' . $this->data['posy'] . ', ' . $this->data['posz'] . ', ' . $this->data['cap'] . ', ' . $this->data['lastlogin'] . ', ' . $this->data['lastip'] . ', ' . (int) $this->data['save'] . ', ' . $this->db->quote($this->data['conditions']) . ', ' . $this->data['skull'] . ', ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->data['rank_id'] . ', ' . $this->data['town_id'] . ', ' . $this->data['loss_experience'] . ', ' . $this->data['loss_mana'] . ', ' . $this->data['loss_skills'] . ', ' . $this->data['loss_items'] . ', ' . $this->data['loss_containers'] . ', ' . $this->data['balance'] . ', ' . time() . ', ' . $this->data['promotion'] . ')');
189 // ID of new group
190 $this->data['id'] = $this->db->lastInsertId();
191 }
192
193 // updates skills - doesn't matter if we have just created character - trigger inserts new skills
194 foreach($this->skills as $id => $skill)
195 {
196 $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);
197 }
198 }
199
200/**
201 * Player ID.
202 *
203 * <p>
204 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
205 * </p>
206 *
207 * @version 0.0.3
208 * @return int Player ID.
209 * @throws E_OTS_NotLoaded If player is not loaded.
210 */
211 public function getId()
212 {
213 if( !isset($this->data['id']) )
214 {
215 throw new E_OTS_NotLoaded();
216 }
217
218 return $this->data['id'];
219 }
220
221 public function getWorld()
222 {
223 if( !isset($this->data['world_id']) )
224 {
225 throw new E_OTS_NotLoaded();
226 }
227
228 return $this->data['world_id'];
229 }
230
231 public function getHideChar()
232 {
233 if( !isset($this->data['hide_char']) )
234 {
235 throw new E_OTS_NotLoaded();
236 }
237
238 return $this->data['hide_char'];
239 }
240
241 public function getMarriage()
242 {
243 if( !isset($this->data['marriage']) )
244 {
245 throw new E_OTS_NotLoaded();
246 }
247
248 return $this->data['marriage'];
249 }
250
251/**
252 * Player name.
253 *
254 * <p>
255 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
256 * </p>
257 *
258 * @version 0.0.3
259 * @return string Player's name.
260 * @throws E_OTS_NotLoaded If player is not loaded.
261 */
262 public function getName()
263 {
264 if( !isset($this->data['name']) )
265 {
266 throw new E_OTS_NotLoaded();
267 }
268
269 return $this->data['name'];
270 }
271
272
273 public function getOldName()
274 {
275 if( !isset($this->data['old_name']) )
276 {
277 throw new E_OTS_NotLoaded();
278 }
279
280 return $this->data['old_name'];
281 }
282/**
283 * Sets players's name.
284 *
285 * <p>
286 * 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.
287 * </p>
288 *
289 * @param string $name Name.
290 */
291 public function setName($name)
292 {
293 $this->data['name'] = (string) $name;
294 }
295
296
297 public function setWorld($id)
298 {
299 $this->data['world_id'] = (int) $id;
300 }
301/**
302 * Returns account of this player.
303 *
304 * <p>
305 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
306 * </p>
307 *
308 * @version 0.1.0
309 * @return OTS_Account Owning account.
310 * @throws E_OTS_NotLoaded If player is not loaded.
311 * @throws PDOException On PDO operation error.
312 */
313 public function getAccount()
314 {
315 if( !isset($this->data['account_id']) )
316 {
317 throw new E_OTS_NotLoaded();
318 }
319
320 $account = new OTS_Account();
321 $account->load($this->data['account_id']);
322 return $account;
323 }
324
325/**
326 * Assigns character to account.
327 *
328 * <p>
329 * 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.
330 * </p>
331 *
332 * @param OTS_Account $account Owning account.
333 * @throws E_OTS_NotLoaded If passed <var>$account</var> parameter is not loaded.
334 */
335 public function setAccount(OTS_Account $account)
336 {
337 $this->data['account_id'] = $account->getId();
338 }
339
340/**
341 * Returns group of this player.
342 *
343 * <p>
344 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
345 * </p>
346 *
347 * @version 0.1.0
348 * @return OTS_Group Group of which current character is member.
349 * @throws E_OTS_NotLoaded If player is not loaded.
350 * @throws PDOException On PDO operation error.
351 */
352 public function getGroup()
353 {
354 if( !isset($this->data['group_id']) )
355 {
356 throw new E_OTS_NotLoaded();
357 }
358
359 return $this->data['group_id'];
360 }
361
362/**
363 * Assigns character to group.
364 *
365 * <p>
366 * 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.
367 * </p>
368 *
369 * @param OTS_Group $group Group to be a member.
370 * @throws E_OTS_NotLoaded If passed <var>$group</var> parameter is not loaded.
371 */
372 public function setGroup($group)
373 {
374 $this->data['group_id'] = $group;
375 }
376
377/**
378 * Player's Premium Account expiration timestamp.
379 *
380 * @version 0.1.5
381 * @since 0.0.3
382 * @return int Player PACC expiration timestamp.
383 * @throws E_OTS_NotLoaded If player is not loaded.
384 * @deprecated 0.1.5 Use OTS_Account->getPremiumEnd().
385 */
386 public function getPremiumEnd()
387 {
388 if( !isset($this->data['id']) )
389 {
390 throw new E_OTS_NotLoaded();
391 }
392
393 return $this->getAccount()->getPremiumEnd();
394 }
395
396/**
397 * Player gender.
398 *
399 * <p>
400 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
401 * </p>
402 *
403 * @version 0.0.3
404 * @return int Player gender.
405 * @throws E_OTS_NotLoaded If player is not loaded.
406 */
407 public function getSex()
408 {
409 if( !isset($this->data['sex']) )
410 {
411 throw new E_OTS_NotLoaded();
412 }
413
414 return $this->data['sex'];
415 }
416
417 public function isDeleted()
418 {
419 if( !isset($this->data['deleted']) )
420 {
421 throw new E_OTS_NotLoaded();
422 }
423
424 return $this->data['deleted'] > 0;
425 }
426
427 public function isOnline()
428 {
429 if( !isset($this->data['online']) )
430 {
431 throw new E_OTS_NotLoaded();
432 }
433
434 return $this->data['online'] == 1;
435 }
436
437 public function getCreated()
438 {
439 if( !isset($this->data['created']) )
440 {
441 throw new E_OTS_NotLoaded();
442 }
443
444 return $this->data['created'];
445 }
446
447 public function getComment()
448 {
449 if( !isset($this->data['comment']) )
450 {
451 throw new E_OTS_NotLoaded();
452 }
453
454 return $this->data['comment'];
455 }
456
457/**
458 * Sets player gender.
459 *
460 * <p>
461 * 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.
462 * </p>
463 *
464 * @param int $sex Player gender.
465 */
466 public function setSex($sex)
467 {
468 $this->data['sex'] = (int) $sex;
469 }
470
471/**
472 * Player proffesion.
473 *
474 * <p>
475 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
476 * </p>
477 *
478 * @version 0.0.3
479 * @return int Player proffesion.
480 * @throws E_OTS_NotLoaded If player is not loaded.
481 */
482 public function getVocation()
483 {
484 if( !isset($this->data['vocation']) )
485 {
486 throw new E_OTS_NotLoaded();
487 }
488
489 return $this->data['vocation'];
490 }
491
492
493 public function getPromotion()
494 {
495 if( !isset($this->data['promotion']) )
496 {
497 throw new E_OTS_NotLoaded();
498 }
499
500 return $this->data['promotion'];
501 }
502/**
503 * Sets player proffesion.
504 *
505 * <p>
506 * 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.
507 * </p>
508 *
509 * @param int $vocation Player proffesion.
510 */
511 public function setVocation($vocation)
512 {
513 $this->data['vocation'] = (int) $vocation;
514 }
515
516 public function setPromotion($promotion)
517 {
518 $this->data['promotion'] = (int) $promotion;
519 }
520/**
521 * Experience points.
522 *
523 * <p>
524 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
525 * </p>
526 *
527 * @version 0.0.3
528 * @return int Experience points.
529 * @throws E_OTS_NotLoaded If player is not loaded.
530 */
531 public function getExperience()
532 {
533 if( !isset($this->data['experience']) )
534 {
535 throw new E_OTS_NotLoaded();
536 }
537
538 return $this->data['experience'];
539 }
540
541/**
542 * Sets experience points.
543 *
544 * <p>
545 * 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.
546 * </p>
547 *
548 * @param int $experience Experience points.
549 */
550 public function setExperience($experience)
551 {
552 $this->data['experience'] = (int) $experience;
553 }
554
555/**
556 * Experience level.
557 *
558 * <p>
559 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
560 * </p>
561 *
562 * @version 0.0.3
563 * @return int Experience level.
564 * @throws E_OTS_NotLoaded If player is not loaded.
565 */
566 public function getLevel()
567 {
568 if( !isset($this->data['level']) )
569 {
570 throw new E_OTS_NotLoaded();
571 }
572
573 return $this->data['level'];
574 }
575
576/**
577 * Sets experience level.
578 *
579 * <p>
580 * 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.
581 * </p>
582 *
583 * @param int $level Experience level.
584 */
585 public function setLevel($level)
586 {
587 $this->data['level'] = (int) $level;
588 }
589
590/**
591 * Magic level.
592 *
593 * <p>
594 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
595 * </p>
596 *
597 * @version 0.0.3
598 * @return int Magic level.
599 * @throws E_OTS_NotLoaded If player is not loaded.
600 */
601 public function getMagLevel()
602 {
603 if( !isset($this->data['maglevel']) )
604 {
605 throw new E_OTS_NotLoaded();
606 }
607
608 return $this->data['maglevel'];
609 }
610
611/**
612 * Sets magic level.
613 *
614 * <p>
615 * 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.
616 * </p>
617 *
618 * @param int $maglevel Magic level.
619 */
620 public function setMagLevel($maglevel)
621 {
622 $this->data['maglevel'] = (int) $maglevel;
623 }
624
625/**
626 * Current HP.
627 *
628 * <p>
629 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
630 * </p>
631 *
632 * @version 0.0.3
633 * @return int Current HP.
634 * @throws E_OTS_NotLoaded If player is not loaded.
635 */
636 public function getHealth()
637 {
638 if( !isset($this->data['health']) )
639 {
640 throw new E_OTS_NotLoaded();
641 }
642
643 return $this->data['health'];
644 }
645
646/**
647 * Sets current HP.
648 *
649 * <p>
650 * 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.
651 * </p>
652 *
653 * @param int $health Current HP.
654 */
655 public function setHealth($health)
656 {
657 $this->data['health'] = (int) $health;
658 }
659
660/**
661 * Maximum HP.
662 *
663 * <p>
664 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
665 * </p>
666 *
667 * @version 0.0.3
668 * @return int Maximum HP.
669 * @throws E_OTS_NotLoaded If player is not loaded.
670 */
671 public function getHealthMax()
672 {
673 if( !isset($this->data['healthmax']) )
674 {
675 throw new E_OTS_NotLoaded();
676 }
677
678 return $this->data['healthmax'];
679 }
680
681/**
682 * Sets maximum HP.
683 *
684 * <p>
685 * 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.
686 * </p>
687 *
688 * @param int $healthmax Maximum HP.
689 */
690 public function setHealthMax($healthmax)
691 {
692 $this->data['healthmax'] = (int) $healthmax;
693 }
694
695/**
696 * Current mana.
697 *
698 * <p>
699 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
700 * </p>
701 *
702 * @version 0.0.3
703 * @return int Current mana.
704 * @throws E_OTS_NotLoaded If player is not loaded.
705 */
706 public function getMana()
707 {
708 if( !isset($this->data['mana']) )
709 {
710 throw new E_OTS_NotLoaded();
711 }
712
713 return $this->data['mana'];
714 }
715
716/**
717 * Sets current mana.
718 *
719 * <p>
720 * 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.
721 * </p>
722 *
723 * @param int $mana Current mana.
724 */
725 public function setMana($mana)
726 {
727 $this->data['mana'] = (int) $mana;
728 }
729
730/**
731 * Maximum mana.
732 *
733 * <p>
734 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
735 * </p>
736 *
737 * @version 0.0.3
738 * @return int Maximum mana.
739 * @throws E_OTS_NotLoaded If player is not loaded.
740 */
741 public function getManaMax()
742 {
743 if( !isset($this->data['manamax']) )
744 {
745 throw new E_OTS_NotLoaded();
746 }
747
748 return $this->data['manamax'];
749 }
750
751/**
752 * Sets maximum mana.
753 *
754 * <p>
755 * 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.
756 * </p>
757 *
758 * @param int $manamax Maximum mana.
759 */
760 public function setManaMax($manamax)
761 {
762 $this->data['manamax'] = (int) $manamax;
763 }
764
765/**
766 * Mana spent.
767 *
768 * <p>
769 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
770 * </p>
771 *
772 * @version 0.0.3
773 * @return int Mana spent.
774 * @throws E_OTS_NotLoaded If player is not loaded.
775 */
776 public function getManaSpent()
777 {
778 if( !isset($this->data['manaspent']) )
779 {
780 throw new E_OTS_NotLoaded();
781 }
782
783 return $this->data['manaspent'];
784 }
785
786/**
787 * Sets mana spent.
788 *
789 * <p>
790 * 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.
791 * </p>
792 *
793 * @param int $manaspent Mana spent.
794 */
795 public function setManaSpent($manaspent)
796 {
797 $this->data['manaspent'] = (int) $manaspent;
798 }
799
800/**
801 * Soul points.
802 *
803 * <p>
804 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
805 * </p>
806 *
807 * @version 0.0.3
808 * @return int Soul points.
809 * @throws E_OTS_NotLoaded If player is not loaded.
810 */
811 public function getSoul()
812 {
813 if( !isset($this->data['soul']) )
814 {
815 throw new E_OTS_NotLoaded();
816 }
817
818 return $this->data['soul'];
819 }
820
821/**
822 * Sets soul points.
823 *
824 * <p>
825 * 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.
826 * </p>
827 *
828 * @param int $soul Soul points.
829 */
830 public function setSoul($soul)
831 {
832 $this->data['soul'] = (int) $soul;
833 }
834
835/**
836 * Looking direction.
837 *
838 * <p>
839 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
840 * </p>
841 *
842 * @version 0.0.3
843 * @return int Looking direction.
844 * @throws E_OTS_NotLoaded If player is not loaded.
845 */
846 public function getDirection()
847 {
848 if( !isset($this->data['direction']) )
849 {
850 throw new E_OTS_NotLoaded();
851 }
852
853 return $this->data['direction'];
854 }
855
856/**
857 * Sets looking direction.
858 *
859 * <p>
860 * 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.
861 * </p>
862 *
863 * @param int $direction Looking direction.
864 */
865 public function setDirection($direction)
866 {
867 $this->data['direction'] = (int) $direction;
868 }
869
870/**
871 * Body color.
872 *
873 * <p>
874 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
875 * </p>
876 *
877 * @version 0.0.3
878 * @return int Body color.
879 * @throws E_OTS_NotLoaded If player is not loaded.
880 */
881 public function getLookBody()
882 {
883 if( !isset($this->data['lookbody']) )
884 {
885 throw new E_OTS_NotLoaded();
886 }
887
888 return $this->data['lookbody'];
889 }
890
891/**
892 * Sets body color.
893 *
894 * <p>
895 * 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.
896 * </p>
897 *
898 * @param int $lookbody Body color.
899 */
900 public function setLookBody($lookbody)
901 {
902 $this->data['lookbody'] = (int) $lookbody;
903 }
904
905/**
906 * Boots color.
907 *
908 * <p>
909 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
910 * </p>
911 *
912 * @version 0.0.3
913 * @return int Boots color.
914 * @throws E_OTS_NotLoaded If player is not loaded.
915 */
916 public function getLookFeet()
917 {
918 if( !isset($this->data['lookfeet']) )
919 {
920 throw new E_OTS_NotLoaded();
921 }
922
923 return $this->data['lookfeet'];
924 }
925
926/**
927 * Sets boots color.
928 *
929 * <p>
930 * 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.
931 * </p>
932 *
933 * @param int $lookfeet Boots color.
934 */
935 public function setLookFeet($lookfeet)
936 {
937 $this->data['lookfeet'] = (int) $lookfeet;
938 }
939
940/**
941 * Hair color.
942 *
943 * <p>
944 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
945 * </p>
946 *
947 * @version 0.0.3
948 * @return int Hair color.
949 * @throws E_OTS_NotLoaded If player is not loaded.
950 */
951 public function getLookHead()
952 {
953 if( !isset($this->data['lookhead']) )
954 {
955 throw new E_OTS_NotLoaded();
956 }
957
958 return $this->data['lookhead'];
959 }
960
961/**
962 * Sets hair color.
963 *
964 * <p>
965 * 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.
966 * </p>
967 *
968 * @param int $lookhead Hair color.
969 */
970 public function setLookHead($lookhead)
971 {
972 $this->data['lookhead'] = (int) $lookhead;
973 }
974
975/**
976 * Legs color.
977 *
978 * <p>
979 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
980 * </p>
981 *
982 * @version 0.0.3
983 * @return int Legs color.
984 * @throws E_OTS_NotLoaded If player is not loaded.
985 */
986 public function getLookLegs()
987 {
988 if( !isset($this->data['looklegs']) )
989 {
990 throw new E_OTS_NotLoaded();
991 }
992
993 return $this->data['looklegs'];
994 }
995
996/**
997 * Sets legs color.
998 *
999 * <p>
1000 * 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.
1001 * </p>
1002 *
1003 * @param int $looklegs Legs color.
1004 */
1005 public function setLookLegs($looklegs)
1006 {
1007 $this->data['looklegs'] = (int) $looklegs;
1008 }
1009
1010/**
1011 * Outfit.
1012 *
1013 * <p>
1014 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1015 * </p>
1016 *
1017 * @version 0.0.3
1018 * @return int Outfit.
1019 * @throws E_OTS_NotLoaded If player is not loaded.
1020 */
1021 public function getLookType()
1022 {
1023 if( !isset($this->data['looktype']) )
1024 {
1025 throw new E_OTS_NotLoaded();
1026 }
1027
1028 return $this->data['looktype'];
1029 }
1030
1031/**
1032 * Sets outfit.
1033 *
1034 * <p>
1035 * 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.
1036 * </p>
1037 *
1038 * @param int $looktype Outfit.
1039 */
1040 public function setLookType($looktype)
1041 {
1042 $this->data['looktype'] = (int) $looktype;
1043 }
1044
1045/**
1046 * Addons.
1047 *
1048 * <p>
1049 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1050 * </p>
1051 *
1052 * @version 0.0.3
1053 * @return int Addons.
1054 * @throws E_OTS_NotLoaded If player is not loaded.
1055 */
1056 public function getLookAddons()
1057 {
1058 if( !isset($this->data['lookaddons']) )
1059 {
1060 throw new E_OTS_NotLoaded();
1061 }
1062
1063 return $this->data['lookaddons'];
1064 }
1065
1066/**
1067 * Sets addons.
1068 *
1069 * <p>
1070 * 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.
1071 * </p>
1072 *
1073 * @param int $lookaddons Addons.
1074 */
1075 public function setLookAddons($lookaddons)
1076 {
1077 $this->data['lookaddons'] = (int) $lookaddons;
1078 }
1079
1080/**
1081 * X map coordinate.
1082 *
1083 * <p>
1084 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1085 * </p>
1086 *
1087 * @version 0.0.3
1088 * @return int X map coordinate.
1089 * @throws E_OTS_NotLoaded If player is not loaded.
1090 */
1091 public function getPosX()
1092 {
1093 if( !isset($this->data['posx']) )
1094 {
1095 throw new E_OTS_NotLoaded();
1096 }
1097
1098 return $this->data['posx'];
1099 }
1100
1101/**
1102 * Sets X map coordinate.
1103 *
1104 * <p>
1105 * 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.
1106 * </p>
1107 *
1108 * @param int $posx X map coordinate.
1109 */
1110 public function setPosX($posx)
1111 {
1112 $this->data['posx'] = (int) $posx;
1113 }
1114
1115/**
1116 * Y map coordinate.
1117 *
1118 * <p>
1119 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1120 * </p>
1121 *
1122 * @version 0.0.3
1123 * @return int Y map coordinate.
1124 * @throws E_OTS_NotLoaded If player is not loaded.
1125 */
1126 public function getPosY()
1127 {
1128 if( !isset($this->data['posy']) )
1129 {
1130 throw new E_OTS_NotLoaded();
1131 }
1132
1133 return $this->data['posy'];
1134 }
1135
1136/**
1137 * Sets Y map coordinate.
1138 *
1139 * <p>
1140 * 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.
1141 * </p>
1142 *
1143 * @param int $posy Y map coordinate.
1144 */
1145 public function setPosY($posy)
1146 {
1147 $this->data['posy'] = (int) $posy;
1148 }
1149
1150/**
1151 * Z map coordinate.
1152 *
1153 * <p>
1154 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1155 * </p>
1156 *
1157 * @version 0.0.3
1158 * @return int Z map coordinate.
1159 * @throws E_OTS_NotLoaded If player is not loaded.
1160 */
1161 public function getPosZ()
1162 {
1163 if( !isset($this->data['posz']) )
1164 {
1165 throw new E_OTS_NotLoaded();
1166 }
1167
1168 return $this->data['posz'];
1169 }
1170
1171/**
1172 * Sets Z map coordinate.
1173 *
1174 * <p>
1175 * 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.
1176 * </p>
1177 *
1178 * @param int $posz Z map coordinate.
1179 */
1180 public function setPosZ($posz)
1181 {
1182 $this->data['posz'] = (int) $posz;
1183 }
1184
1185/**
1186 * Capacity.
1187 *
1188 * <p>
1189 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1190 * </p>
1191 *
1192 * @version 0.0.3
1193 * @return int Capacity.
1194 * @throws E_OTS_NotLoaded If player is not loaded.
1195 */
1196 public function getCap()
1197 {
1198 if( !isset($this->data['cap']) )
1199 {
1200 throw new E_OTS_NotLoaded();
1201 }
1202
1203 return $this->data['cap'];
1204 }
1205
1206/**
1207 * Sets capacity.
1208 *
1209 * <p>
1210 * 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.
1211 * </p>
1212 *
1213 * @param int $cap Capacity.
1214 */
1215 public function setCap($cap)
1216 {
1217 $this->data['cap'] = (int) $cap;
1218 }
1219
1220/**
1221 * Last login timestamp.
1222 *
1223 * <p>
1224 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1225 * </p>
1226 *
1227 * @version 0.0.3
1228 * @return int Last login timestamp.
1229 * @throws E_OTS_NotLoaded If player is not loaded.
1230 */
1231 public function getLastLogin()
1232 {
1233 if( !isset($this->data['lastlogin']) )
1234 {
1235 throw new E_OTS_NotLoaded();
1236 }
1237
1238 return $this->data['lastlogin'];
1239 }
1240
1241/**
1242 * Sets last login timestamp.
1243 *
1244 * <p>
1245 * 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.
1246 * </p>
1247 *
1248 * @param int $lastlogin Last login timestamp.
1249 */
1250 public function setLastLogin($lastlogin)
1251 {
1252 $this->data['lastlogin'] = (int) $lastlogin;
1253 }
1254
1255/**
1256 * Last login IP.
1257 *
1258 * <p>
1259 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1260 * </p>
1261 *
1262 * @version 0.0.3
1263 * @return int Last login IP.
1264 * @throws E_OTS_NotLoaded If player is not loaded.
1265 */
1266 public function getLastIP()
1267 {
1268 if( !isset($this->data['lastip']) )
1269 {
1270 throw new E_OTS_NotLoaded();
1271 }
1272
1273 return $this->data['lastip'];
1274 }
1275
1276/**
1277 * Sets last login IP.
1278 *
1279 * <p>
1280 * 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.
1281 * </p>
1282 *
1283 * @param int $lastip Last login IP.
1284 */
1285 public function setLastIP($lastip)
1286 {
1287 $this->data['lastip'] = (int) $lastip;
1288 }
1289
1290/**
1291 * Checks if save flag is set.
1292 *
1293 * <p>
1294 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1295 * </p>
1296 *
1297 * @version 0.0.7
1298 * @return bool PACC days.
1299 * @throws E_OTS_NotLoaded If player is not loaded.
1300 */
1301 public function isSaveSet()
1302 {
1303 if( !isset($this->data['save']) )
1304 {
1305 throw new E_OTS_NotLoaded();
1306 }
1307
1308 return $this->data['save'];
1309 }
1310
1311/**
1312 * Unsets save flag.
1313 *
1314 * <p>
1315 * 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.
1316 * </p>
1317 *
1318 * @version 0.0.7
1319 */
1320 public function unsetSave()
1321 {
1322 $this->data['save'] = false;
1323 }
1324
1325/**
1326 * @version 0.0.7
1327 * @since 0.0.6
1328 * @return int Save counter.
1329 * @throws E_OTS_NotLoaded If player is not loaded.
1330 * @deprecated 0.0.7 Save field is back as flag not a counter.
1331 */
1332 public function getSave()
1333 {
1334 if( !isset($this->data['save']) )
1335 {
1336 throw new E_OTS_NotLoaded();
1337 }
1338
1339 return $this->data['save'];
1340 }
1341
1342/**
1343 * Sets save flag.
1344 *
1345 * <p>
1346 * 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.
1347 * </p>
1348 *
1349 * @version 0.0.7
1350 * @param int $save Deprecated, unused, optional.
1351 */
1352 public function setSave($save = 1)
1353 {
1354 $this->data['save'] = true;
1355 }
1356
1357/**
1358 * Conditions.
1359 *
1360 * <p>
1361 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1362 * </p>
1363 *
1364 * @version 0.0.3
1365 * @return string Conditions binary string.
1366 * @throws E_OTS_NotLoaded If player is not loaded.
1367 */
1368 public function getConditions()
1369 {
1370 if( !isset($this->data['conditions']) )
1371 {
1372 throw new E_OTS_NotLoaded();
1373 }
1374
1375 return $this->data['conditions'];
1376 }
1377
1378/**
1379 * Sets conditions.
1380 *
1381 * <p>
1382 * 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.
1383 * </p>
1384 *
1385 * @param string $conditions Condition binary string.
1386 */
1387 public function setConditions($conditions)
1388 {
1389 $this->data['conditions'] = $conditions;
1390 }
1391
1392/**
1393 * Red skulled time remained.
1394 *
1395 * <p>
1396 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1397 * </p>
1398 *
1399 * @version 0.0.3
1400 * @return int Red skulled time remained.
1401 * @throws E_OTS_NotLoaded If player is not loaded.
1402 */
1403 public function getRedSkullTime()
1404 {
1405 if( !isset($this->data['redskulltime']) )
1406 {
1407 throw new E_OTS_NotLoaded();
1408 }
1409
1410 return $this->data['redskulltime'];
1411 }
1412
1413/**
1414 * Sets red skulled time remained.
1415 *
1416 * <p>
1417 * 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.
1418 * </p>
1419 *
1420 * @param int $redskulltime Red skulled time remained.
1421 */
1422 public function setRedSkullTime($redskulltime)
1423 {
1424 $this->data['redskulltime'] = (int) $redskulltime;
1425 }
1426
1427/**
1428 * Checks if player has red skull.
1429 *
1430 * <p>
1431 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1432 * </p>
1433 *
1434 * @version 0.0.3
1435 * @return bool Red skull state.
1436 * @throws E_OTS_NotLoaded If player is not loaded.
1437 */
1438 public function hasRedSkull()
1439 {
1440 if( !isset($this->data['redskull']) )
1441 {
1442 throw new E_OTS_NotLoaded();
1443 }
1444
1445 return $this->data['redskull'];
1446 }
1447
1448/**
1449 * Unsets red skull flag.
1450 *
1451 * <p>
1452 * 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.
1453 * </p>
1454 */
1455 public function unsetRedSkull()
1456 {
1457 $this->data['redskull'] = false;
1458 }
1459
1460/**
1461 * Sets red skull flag.
1462 *
1463 * <p>
1464 * 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.
1465 * </p>
1466 */
1467 public function setRedSkull()
1468 {
1469 $this->data['redskull'] = true;
1470 }
1471
1472/**
1473 * Guild nick.
1474 *
1475 * <p>
1476 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1477 * </p>
1478 *
1479 * @version 0.0.3
1480 * @return string Guild title.
1481 * @throws E_OTS_NotLoaded If player is not loaded.
1482 */
1483 public function getGuildNick()
1484 {
1485 if( !isset($this->data['guildnick']) )
1486 {
1487 throw new E_OTS_NotLoaded();
1488 }
1489
1490 return $this->data['guildnick'];
1491 }
1492
1493/**
1494 * Sets guild nick.
1495 *
1496 * <p>
1497 * 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.
1498 * </p>
1499 *
1500 * @param string $guildnick Name.
1501 */
1502 public function setGuildNick($guildnick)
1503 {
1504 $this->data['guildnick'] = (string) $guildnick;
1505 }
1506
1507/**
1508 * @version 0.0.3
1509 * @return int Guild rank ID.
1510 * @throws E_OTS_NotLoaded If player is not loaded.
1511 * @deprecated 0.0.4 Use getRank().
1512 */
1513 public function getRankId()
1514 {
1515 if( !isset($this->data['rank_id']) )
1516 {
1517 throw new E_OTS_NotLoaded();
1518 }
1519
1520 return $this->data['rank_id'];
1521 }
1522
1523/**
1524 * Assigned guild rank.
1525 *
1526 * <p>
1527 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1528 * </p>
1529 *
1530 * @version 0.1.0
1531 * @return OTS_GuildRank|null Guild rank (null if not member of any).
1532 * @throws E_OTS_NotLoaded If player is not loaded.
1533 * @throws PDOException On PDO operation error.
1534 */
1535 public function getRank()
1536 {
1537 if( !isset($this->data['rank_id']) )
1538 {
1539 throw new E_OTS_NotLoaded();
1540 }
1541
1542 if($this->data['rank_id'] == 0)
1543 {
1544 return null;
1545 }
1546
1547 $guildRank = new OTS_GuildRank();
1548 $guildRank->load($this->data['rank_id']);
1549 return $guildRank;
1550 }
1551
1552/**
1553 * @param int $rank_id Guild rank ID.
1554 * @deprecated 0.0.4 Use setRank().
1555 */
1556 public function setRankId($rank_id)
1557 {
1558 $this->data['rank_id'] = (int) $rank_id;
1559 }
1560
1561/**
1562 * Assigns guild rank.
1563 *
1564 * <p>
1565 * 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.
1566 * </p>
1567 *
1568 * @param OTS_GuildRank|null Guild rank (null to clear assign).
1569 * @throws E_OTS_NotLoaded If passed <var>$guildRank</var> parameter is not loaded.
1570 */
1571 public function setRank(OTS_GuildRank $guildRank = null)
1572 {
1573 if( isset($guildRank) )
1574 {
1575 $this->data['rank_id'] = $guildRank->getId();
1576 }
1577 else
1578 {
1579 $this->data['rank_id'] = 0;
1580 }
1581 }
1582
1583/**
1584 * Residence town's ID.
1585 *
1586 * <p>
1587 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1588 * </p>
1589 *
1590 * @version 0.0.3
1591 * @return int Residence town's ID.
1592 * @throws E_OTS_NotLoaded If player is not loaded.
1593 */
1594 public function getTownId()
1595 {
1596 if( !isset($this->data['town_id']) )
1597 {
1598 throw new E_OTS_NotLoaded();
1599 }
1600
1601 return $this->data['town_id'];
1602 }
1603
1604/**
1605 * Sets residence town's ID.
1606 *
1607 * <p>
1608 * 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.
1609 * </p>
1610 *
1611 * @param int $town_id Residence town's ID.
1612 */
1613 public function setTownId($town_id)
1614 {
1615 $this->data['town_id'] = (int) $town_id;
1616 }
1617
1618/**
1619 * Percentage of experience lost after dead.
1620 *
1621 * <p>
1622 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1623 * </p>
1624 *
1625 * @version 0.0.3
1626 * @return int Percentage of experience lost after dead.
1627 * @throws E_OTS_NotLoaded If player is not loaded.
1628 */
1629 public function getLossExperience()
1630 {
1631 if( !isset($this->data['loss_experience']) )
1632 {
1633 throw new E_OTS_NotLoaded();
1634 }
1635
1636 return $this->data['loss_experience'];
1637 }
1638
1639/**
1640 * Sets percentage of experience lost after dead.
1641 *
1642 * <p>
1643 * 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.
1644 * </p>
1645 *
1646 * @param int $loss_experience Percentage of experience lost after dead.
1647 */
1648 public function setLossExperience($loss_experience)
1649 {
1650 $this->data['loss_experience'] = (int) $loss_experience;
1651 }
1652
1653/**
1654 * Percentage of used mana lost after dead.
1655 *
1656 * <p>
1657 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1658 * </p>
1659 *
1660 * @version 0.0.3
1661 * @return int Percentage of used mana lost after dead.
1662 * @throws E_OTS_NotLoaded If player is not loaded.
1663 */
1664 public function getLossMana()
1665 {
1666 if( !isset($this->data['loss_mana']) )
1667 {
1668 throw new E_OTS_NotLoaded();
1669 }
1670
1671 return $this->data['loss_mana'];
1672 }
1673
1674/**
1675 * Sets percentage of used mana lost after dead.
1676 *
1677 * <p>
1678 * 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.
1679 * </p>
1680 *
1681 * @param int $loss_mana Percentage of used mana lost after dead.
1682 */
1683 public function setLossMana($loss_mana)
1684 {
1685 $this->data['loss_mana'] = (int) $loss_mana;
1686 }
1687
1688/**
1689 * Percentage of skills lost after dead.
1690 *
1691 * <p>
1692 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
1693 * </p>
1694 *
1695 * @version 0.0.3
1696 * @return int Percentage of skills lost after dead.
1697 * @throws E_OTS_NotLoaded If player is not loaded.
1698 */
1699 public function getLossSkills()
1700 {
1701 if( !isset($this->data['loss_skills']) )
1702 {
1703 throw new E_OTS_NotLoaded();
1704 }
1705
1706 return $this->data['loss_skills'];
1707 }
1708
1709/**
1710 * Sets percentage of skills lost after dead.
1711 *
1712 * <p>
1713 * 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.
1714 * </p>
1715 *
1716 * @param int $loss_skills Percentage of skills lost after dead.
1717 */
1718 public function setLossSkills($loss_skills)
1719 {
1720 $this->data['loss_skills'] = (int) $loss_skills;
1721 }
1722
1723/**
1724 * Percentage of items lost after dead.
1725 *
1726 * @version 0.1.4
1727 * @since 0.1.4
1728 * @return int Percentage of items lost after dead.
1729 * @throws E_OTS_NotLoaded If player is not loaded.
1730 */
1731 public function getLossItems()
1732 {
1733 if( !isset($this->data['loss_items']) )
1734 {
1735 throw new E_OTS_NotLoaded();
1736 }
1737
1738 return $this->data['loss_items'];
1739 }
1740
1741/**
1742 * Sets percentage of items lost after dead.
1743 *
1744 * @version 0.1.4
1745 * @since 0.1.4
1746 * @param int $loss_items Percentage of items lost after dead.
1747 */
1748 public function setLossItems($loss_items)
1749 {
1750 $this->data['loss_items'] = (int) $loss_items;
1751 }
1752
1753/**
1754 * Sets percentage of containers lost after dead. (Equipments).
1755 * === Sample character compatibility fix by Znote at otland!
1756 * @version 0.1.4
1757 * @since 0.1.4
1758 * @param int $loss_containers Percentage to loose equipments after dead.
1759 */
1760
1761 public function getLossContainers()
1762 {
1763 if( !isset($this->data['loss_containers']) )
1764 {
1765 throw new E_OTS_NotLoaded();
1766 }
1767
1768 return $this->data['loss_containers'];
1769 }
1770
1771/**
1772 * Sets percentage of containers lost after dead. (Equipments).
1773 * === Sample character compatibility fix by Znote at otland!
1774 * @version 0.1.4
1775 * @since 0.1.4
1776 * @param int $loss_containers Percentage to loose equipments after dead.
1777 */
1778
1779 public function setLossContainers($loss_containers)
1780 {
1781 $this->data['loss_containers'] = (int) $loss_containers;
1782 }
1783
1784/**
1785 * Bank balance.
1786 *
1787 * @version 0.1.2
1788 * @since 0.1.2
1789 * @return int Amount of money stored in bank.
1790 * @throws E_OTS_NotLoaded If player is not loaded.
1791 */
1792 public function getBalance()
1793 {
1794 if( !isset($this->data['balance']) )
1795 {
1796 throw new E_OTS_NotLoaded();
1797 }
1798
1799 return $this->data['balance'];
1800 }
1801
1802/**
1803 * Sets bank balance value.
1804 *
1805 * <p>
1806 * 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.
1807 * </p>
1808 *
1809 * @version 0.1.2
1810 * @since 0.1.2
1811 * @param int $balance Amount of money to be set in bank.
1812 */
1813 public function setBalance($balance)
1814 {
1815 $this->data['balance'] = (int) $balance;
1816 }
1817
1818/**
1819 * Reads custom field.
1820 *
1821 * <p>
1822 * Reads field by it's name. Can read any field of given record that exists in database.
1823 * </p>
1824 *
1825 * <p>
1826 * 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.
1827 * </p>
1828 *
1829 * @version 0.0.5
1830 * @since 0.0.3
1831 * @param string $field Field name.
1832 * @return string Field value.
1833 * @throws E_OTS_NotLoaded If player is not loaded.
1834 * @throws PDOException On PDO operation error.
1835 */
1836 public function getCustomField($field)
1837 {
1838 if( !isset($this->data['id']) )
1839 {
1840 throw new E_OTS_NotLoaded();
1841 }
1842
1843 $value = $this->db->query('SELECT ' . $this->db->fieldName($field) . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id'])->fetch();
1844 return $value[$field];
1845 }
1846
1847/**
1848 * Writes custom field.
1849 *
1850 * <p>
1851 * Write field by it's name. Can write any field of given record that exists in database.
1852 * </p>
1853 *
1854 * <p>
1855 * 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.
1856 * </p>
1857 *
1858 * <p>
1859 * 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.
1860 * </p>
1861 *
1862 * @version 0.0.5
1863 * @since 0.0.3
1864 * @param string $field Field name.
1865 * @param mixed $value Field value.
1866 * @throws E_OTS_NotLoaded If player is not loaded.
1867 * @throws PDOException On PDO operation error.
1868 */
1869 public function setCustomField($field, $value)
1870 {
1871 if( !isset($this->data['id']) )
1872 {
1873 throw new E_OTS_NotLoaded();
1874 }
1875
1876 // quotes value for SQL query
1877 if(!( is_int($value) || is_float($value) ))
1878 {
1879 $value = $this->db->quote($value);
1880 }
1881
1882 $this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName($field) . ' = ' . $value . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
1883 }
1884
1885/**
1886 * Returns player's skill.
1887 *
1888 * @version 0.0.2
1889 * @since 0.0.2
1890 * @param int $skill Skill ID.
1891 * @return int Skill value.
1892 * @throws E_OTS_NotLoaded If player is not loaded.
1893 */
1894 public function getSkill($skill)
1895 {
1896 if( !isset($this->skills[$skill]) )
1897 {
1898 throw new E_OTS_NotLoaded();
1899 }
1900
1901 return $this->skills[$skill]['value'];
1902 }
1903
1904/**
1905 * Sets skill value.
1906 *
1907 * @version 0.0.2
1908 * @since 0.0.2
1909 * @param int $skill Skill ID.
1910 * @param int $value Skill value.
1911 */
1912 public function setSkill($skill, $value)
1913 {
1914 $this->skills[ (int) $skill]['value'] = (int) $value;
1915 }
1916
1917/**
1918 * Returns player's skill's tries for next level.
1919 *
1920 * @version 0.0.2
1921 * @since 0.0.2
1922 * @param int $skill Skill ID.
1923 * @return int Skill tries.
1924 * @throws E_OTS_NotLoaded If player is not loaded.
1925 */
1926 public function getSkillTries($skill)
1927 {
1928 if( !isset($this->skills[$skill]) )
1929 {
1930 throw new E_OTS_NotLoaded();
1931 }
1932
1933 return $this->skills[$skill]['tries'];
1934 }
1935
1936/**
1937 * Sets skill's tries for next level.
1938 *
1939 * @version 0.0.2
1940 * @since 0.0.2
1941 * @param int $skill Skill ID.
1942 * @param int $tries Skill tries.
1943 */
1944 public function setSkillTries($skill, $tries)
1945 {
1946 $this->skills[ (int) $skill]['tries'] = (int) $tries;
1947 }
1948
1949/**
1950 * Returns value of storage record.
1951 *
1952 * @version 0.1.3
1953 * @since 0.1.2
1954 * @param int $key Storage key.
1955 * @return int|null Stored value (null if not set).
1956 * @throws E_OTS_NotLoaded If player is not loaded.
1957 * @throws PDOException On PDO operation error.
1958 */
1959 public function getStorage($key)
1960 {
1961 if( !isset($this->data['id']) )
1962 {
1963 throw new E_OTS_NotLoaded();
1964 }
1965
1966 $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();
1967
1968 if($value !== false)
1969 {
1970 return null;
1971 }
1972
1973 return $value['value'];
1974 }
1975
1976/**
1977 * Sets value of storage record.
1978 *
1979 * @version 0.1.2
1980 * @since 0.1.2
1981 * @param int $key Storage key.
1982 * @param int $value Stored value.
1983 * @throws E_OTS_NotLoaded If player is not loaded.
1984 * @throws PDOException On PDO operation error.
1985 */
1986 public function setStorage($key, $value)
1987 {
1988 if( !isset($this->data['id']) )
1989 {
1990 throw new E_OTS_NotLoaded();
1991 }
1992
1993 $current = $this->getStorage($key);
1994
1995 // checks if there is any row to be updates
1996 if( isset($current) )
1997 {
1998 $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);
1999 }
2000 // inserts new storage record
2001 else
2002 {
2003 $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 . ')');
2004 }
2005 }
2006
2007/**
2008 * Deletes item with contained items.
2009 *
2010 * @version 0.0.5
2011 * @since 0.0.3
2012 * @param int $sid Item unique player's ID.
2013 * @throws PDOException On PDO operation error.
2014 */
2015 private function deleteItem($sid)
2016 {
2017 // deletes all sub-items
2018 foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $sid)->fetchAll() as $item)
2019 {
2020 $this->deleteItem($item['sid']);
2021 }
2022
2023 // deletes item
2024 $this->db->query('DELETE FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('sid') . ' = ' . $sid);
2025 }
2026
2027/**
2028 * Returns items tree from given slot.
2029 *
2030 * <p>
2031 * You need global items list resources loaded in order to use this method.
2032 * </p>
2033 *
2034 * @version 0.1.2
2035 * @since 0.0.3
2036 * @param int $slot Slot to get items.
2037 * @return OTS_Item|null Item in given slot (items tree if in given slot there is a container). If there is no item in slot then null value will be returned.
2038 * @throws E_OTS_NotLoaded If player is not loaded or there is no global items list resource loaded.
2039 * @throws E_OTS_NotAContainer If item which is not of type container contains sub items.
2040 * @throws PDOException On PDO operation error.
2041 */
2042 public function getSlot($slot)
2043 {
2044 if( !isset($this->data['id']) )
2045 {
2046 throw new E_OTS_NotLoaded();
2047 }
2048
2049 // loads current item
2050 $item = $this->db->query('SELECT ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName($slot > POT::SLOT_AMMO ? 'sid' : 'pid') . ' = ' . (int) $slot)->fetch();
2051
2052 if( empty($item) )
2053 {
2054 return null;
2055 }
2056
2057 // checks if there are any items under current one
2058 $items = array();
2059 foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $item['sid'])->fetchAll() as $sub)
2060 {
2061 $items[] = $this->getSlot($sub['sid']);
2062 }
2063
2064 // item type
2065 $slot = POT::getInstance()->getItemsList()->getItemType($item['itemtype'])->createItem();
2066 $slot->setCount($item['count']);
2067 $slot->setAttributes($item['attributes']);
2068
2069 // checks if current item has any contained items
2070 if( !empty($items) )
2071 {
2072 // checks if item is realy a container
2073 if(!$slot instanceof OTS_Container)
2074 {
2075 throw new E_OTS_NotAContainer();
2076 }
2077
2078 // puts items into container
2079 foreach($items as $sub)
2080 {
2081 $slot->addItem($sub);
2082 }
2083 }
2084
2085 return $slot;
2086 }
2087
2088/**
2089 * Sets slot content.
2090 *
2091 * @version 0.1.2
2092 * @since 0.0.3
2093 * @param int $slot Slot to save items.
2094 * @param OTS_Item $item Item (can be a container with content) for given slot. Leave this parameter blank to clear slot.
2095 * @param int $pid Deprecated, not used anymore.
2096 * @throws E_OTS_NotLoaded If player is not loaded.
2097 * @throws PDOException On PDO operation error.
2098 */
2099 public function setSlot($slot, OTS_Item $item = null, $pid = 0)
2100 {
2101 static $sid;
2102
2103 if( !isset($this->data['id']) )
2104 {
2105 throw new E_OTS_NotLoaded();
2106 }
2107
2108 // clears current slot
2109 if($slot <= POT::SLOT_AMMO)
2110 {
2111 $id = $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . (int) $slot)->fetch();
2112 $this->deleteItem( (int) $id['sid']);
2113 }
2114
2115 // checks if there is any item to insert
2116 if( isset($item) )
2117 {
2118 // current maximum sid (over slot sids)
2119 if( !isset($sid) )
2120 {
2121 $sid = $this->db->query('SELECT MAX(' . $this->db->fieldName('sid') . ') AS `sid` FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetch();
2122 $sid = $sid['sid'] > POT::SLOT_AMMO ? $sid['sid'] : POT::SLOT_AMMO;
2123 }
2124
2125 $sid++;
2126
2127 // inserts given item
2128 $this->db->query('INSERT INTO ' . $this->db->tableName('player_items') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('pid') . ', ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ') VALUES (' . $this->data['id'] . ', ' . $sid . ', ' . (int) $slot . ', ' . $item->getId() . ', ' . $item->getCount() . ', ' . $this->db->quote( $item->getAttributes() ) . ')');
2129
2130 // checks if this is container
2131 if($item instanceof OTS_Container)
2132 {
2133 $pid = $sid;
2134
2135 // inserts all contained items
2136 foreach($item as $sub)
2137 {
2138 $this->setSlot($pid, $sub);
2139 }
2140 }
2141 }
2142
2143 // clears $sid for next public call
2144 if($slot <= POT::SLOT_AMMO)
2145 {
2146 $sid = null;
2147 }
2148 }
2149
2150/**
2151 * Deletes depot item with contained items.
2152 *
2153 * @version 0.0.5
2154 * @since 0.0.3
2155 * @param int $sid Depot item unique player's ID.
2156 * @throws PDOException On PDO operation error.
2157 */
2158 private function deleteDepot($sid)
2159 {
2160 // deletes all sub-items
2161 foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $sid)->fetchAll() as $item)
2162 {
2163 $this->deleteDepot($item['sid']);
2164 }
2165
2166 // deletes item
2167 $this->db->query('DELETE FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('sid') . ' = ' . $sid);
2168 }
2169
2170/**
2171 * Returns items tree from given depot.
2172 *
2173 * <p>
2174 * You need global items list resources loaded in order to use this method.
2175 * </p>
2176 *
2177 * @version 0.1.2
2178 * @since 0.0.3
2179 * @param int $depot Depot ID to get items.
2180 * @return OTS_Item|null Item in given depot (items tree if in given depot there is a container). If there is no item in depot then null value will be returned.
2181 * @throws E_OTS_NotLoaded If player is not loaded or there is no global items list resource loaded.
2182 * @throws E_OTS_NotAContainer If item which is not of type container contains sub items.
2183 * @throws PDOException On PDO operation error.
2184 */
2185 public function getDepot($depot)
2186 {
2187 if( !isset($this->data['id']) )
2188 {
2189 throw new E_OTS_NotLoaded();
2190 }
2191
2192 // loads current item
2193 $item = $this->db->query('SELECT ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName($depot > POT::DEPOT_SID_FIRST ? 'sid' : 'pid') . ' = ' . (int) $depot)->fetch();
2194
2195 if( empty($item) )
2196 {
2197 return null;
2198 }
2199
2200 // checks if there are any items under current one
2201 $items = array();
2202 foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $item['sid'])->fetchAll() as $sub)
2203 {
2204 $items[] = $this->getDepot($sub['sid']);
2205 }
2206
2207 // item type
2208 $depot = POT::getInstance()->getItemsList()->getItemType($item['itemtype'])->createItem();
2209 $depot->setCount($item['count']);
2210 $depot->setAttributes($item['attributes']);
2211
2212 // checks if current item has any contained items
2213 if( !empty($items) )
2214 {
2215 // checks if item is realy a container
2216 if(!$depot instanceof OTS_Container)
2217 {
2218 throw new E_OTS_NotAContainer();
2219 }
2220
2221 // puts items into container
2222 foreach($items as $sub)
2223 {
2224 $depot->addItem($sub);
2225 }
2226 }
2227
2228 return $depot;
2229 }
2230
2231/**
2232 * Sets depot content.
2233 *
2234 * @version 0.1.2
2235 * @since 0.0.3
2236 * @param int $depot Depot ID to save items.
2237 * @param OTS_Item $item Item (can be a container with content) for given depot. Leave this parameter blank to clear depot.
2238 * @param int $pid Deprecated, not used anymore.
2239 * @param int $depot_id Internal, for further use.
2240 * @throws E_OTS_NotLoaded If player is not loaded.
2241 * @throws PDOException On PDO operation error.
2242 */
2243 public function setDepot($depot, OTS_Item $item = null, $pid = 0, $depot_id = 0)
2244 {
2245 static $sid;
2246
2247 // if no depot_id is specified then it is same as depot slot
2248 if($depot_id == 0)
2249 {
2250 $depot_id = $depot;
2251 }
2252
2253 if( !isset($this->data['id']) )
2254 {
2255 throw new E_OTS_NotLoaded();
2256 }
2257
2258 // clears current depot
2259 if($depot <= POT::DEPOT_SID_FIRST)
2260 {
2261 $id = $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . (int) $depot)->fetch();
2262 $this->deleteDepot( (int) $id['sid']);
2263 }
2264
2265 // checks if there is any item to insert
2266 if( isset($item) )
2267 {
2268 // current maximum sid (over depot sids)
2269 if( !isset($sid) )
2270 {
2271 $sid = $this->db->query('SELECT MAX(' . $this->db->fieldName('sid') . ') AS `sid` FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetch();
2272 $sid = $sid['sid'] > POT::DEPOT_SID_FIRST ? $sid['sid'] : POT::DEPOT_SID_FIRST;
2273 }
2274
2275 $sid++;
2276
2277 // inserts given item
2278 $this->db->query('INSERT INTO ' . $this->db->tableName('player_depotitems') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('depot_id') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('pid') . ', ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ') VALUES (' . $this->data['id'] . ', ' . $depot_id . ', ' . $sid . ', ' . (int) $depot . ', ' . $item->getId() . ', ' . $item->getCount() . ', ' . $this->db->quote( $item->getAttributes() ) . ')');
2279
2280 // checks if this is container
2281 if($item instanceof OTS_Container)
2282 {
2283 $pid = $sid;
2284
2285 // inserts all contained items
2286 foreach($item as $sub)
2287 {
2288 $this->setDepot($pid, $sub, 0, $depot_id);
2289 }
2290 }
2291 }
2292
2293 // clears $sid for next public call
2294 if($depot <= POT::DEPOT_SID_FIRST)
2295 {
2296 $sid = null;
2297 }
2298 }
2299
2300/**
2301 * @version 0.1.5
2302 * @since 0.0.5
2303 * @param int $time Time for time until expires (0 - forever).
2304 * @throws PDOException On PDO operation error.
2305 * @deprecated 0.1.5 Use OTS_PlayerBan class.
2306 */
2307 public function ban($time = 0)
2308 {
2309 // can't ban nothing
2310 if( !$this->isLoaded() )
2311 {
2312 throw new E_OTS_NotLoaded();
2313 }
2314
2315 // creates ban entry
2316 $ban = new OTS_PlayerBan();
2317 $ban->setValue($this->data['id']);
2318 $ban->setExpires($time);
2319 $ban->setAdded( time() );
2320 $ban->activate();
2321 $ban->save();
2322 }
2323
2324/**
2325 * @version 0.1.5
2326 * @since 0.0.5
2327 * @throws PDOException On PDO operation error.
2328 * @deprecated 0.1.5 Use OTS_PlayerBan class.
2329 */
2330 public function unban()
2331 {
2332 // can't unban nothing
2333 if( !$this->isLoaded() )
2334 {
2335 throw new E_OTS_NotLoaded();
2336 }
2337
2338 // deletes ban entry
2339 $ban = new OTS_PlayerBan();
2340 $ban->find($this->data['id']);
2341 $ban->delete();
2342 }
2343
2344/**
2345 * @version 0.1.5
2346 * @since 0.0.5
2347 * @return bool True if player is banned, false otherwise.
2348 * @throws PDOException On PDO operation error.
2349 * @deprecated 0.1.5 Use OTS_PlayerBan class.
2350 */
2351 public function isBanned()
2352 {
2353 // nothing can't be banned
2354 if( !$this->isLoaded() )
2355 {
2356 throw new E_OTS_NotLoaded();
2357 }
2358 if( !isset($this->data['banned']) )
2359 $this->loadBan();
2360 return ($this->data['banned'] == 1);
2361 }
2362
2363 public function getBanTime()
2364 {
2365 // nothing can't be banned
2366 if( !$this->isLoaded() )
2367 {
2368 throw new E_OTS_NotLoaded();
2369 }
2370 if( !isset($this->data['banned_time']) )
2371 $this->loadBan();
2372 return $this->data['banned_time'];
2373 }
2374
2375 public function loadBan()
2376 {
2377 // nothing can't be banned
2378 if( !$this->isLoaded() )
2379 {
2380 throw new E_OTS_NotLoaded();
2381 }
2382 $ban = $this->db->query('SELECT ' . $this->db->fieldName('active') . ', ' . $this->db->fieldName('expires') . ' FROM ' . $this->db->tableName('bans') . ' WHERE (' . $this->db->fieldName('type') . ' = 3 OR ' . $this->db->fieldName('type') . ' = 5) AND ' . $this->db->fieldName('active') . ' = 1 AND ' . $this->db->fieldName('value') . ' = ' . $this->data['account_id'] . ' AND (' . $this->db->fieldName('expires') . ' > ' . time() .' OR ' . $this->db->fieldName('expires') . ' = -1)')->fetch();
2383 $this->data['banned'] = $ban['active'];
2384 $this->data['banned_time'] = $ban['expires'];
2385 }
2386
2387 public function loadNameLock()
2388 {
2389 // nothing can't be namelocked
2390 if( !$this->isLoaded() )
2391 {
2392 throw new E_OTS_NotLoaded();
2393 }
2394 $ban = $this->db->query('SELECT ' . $this->db->fieldName('active') . ' FROM ' . $this->db->tableName('bans') . ' WHERE ' . $this->db->fieldName('type') . ' = 2 AND ' . $this->db->fieldName('active') . ' = 1 AND ' . $this->db->fieldName('value') . ' = ' . $this->data['id'])->fetch();
2395 $this->data['namelock'] = $ban['active'];
2396 }
2397 public function addNameLock()
2398 {
2399 //nothing can't be namelocked
2400 if( !$this->isLoaded() )
2401 {
2402 throw new E_OTS_NotLoaded();
2403 }
2404 $this->db->query('INSERT INTO ' . $this->db->tableName('bans') . ' (' . $this->db->fieldName('type') . ', ' . $this->db->fieldName('value') . ', ' . $this->db->fieldName('param') . ', ' . $this->db->fieldName('active') . ', ' . $this->db->fieldName('expires') . ', ' . $this->db->fieldName('added') . ', ' . $this->db->fieldName('admin_id') . ', ' . $this->db->fieldName('comment') . ', ' . $this->db->fieldName('') . ', ' . $this->db->fieldName('reason') . ', ' . $this->db->fieldName('action') . ') VALUES (2, ' . (int) $this->data['id']. ', 4294967295, 1, -1, ' . time() . ', 0, ' . $this->db->quote('Name lock from site') . ', 1, 1)');
2405 }
2406
2407 public function removeNameLock()
2408 {
2409 //nothing can't be namelocked
2410 if( !$this->isLoaded() )
2411 {
2412 throw new E_OTS_NotLoaded();
2413 }
2414 $this->db->query('UPDATE ' . $this->db->tableName('bans') . ' SET ' . $this->db->fieldName('active') .' = 0 WHERE ' . $this->db->fieldName('value') . ' = ' . (int) $this->data['id'] . ' AND ' . $this->db->fieldName('type') . ' = 2');
2415 }
2416
2417 public function isNameLocked()
2418 {
2419 //nothing can't be namelocked
2420 if( !$this->isLoaded() )
2421 {
2422 throw new E_OTS_NotLoaded();
2423 }
2424 if( !isset($this->data['namelock']) )
2425 $this->loadNameLock();
2426 return ($this->data['namelock'] == 1);
2427 }
2428/**
2429 * Deletes player.
2430 *
2431 * @version 0.0.5
2432 * @since 0.0.5
2433 * @throws E_OTS_NotLoaded If player is not loaded.
2434 * @throws PDOException On PDO operation error.
2435 */
2436 public function delete()
2437 {
2438 if( !isset($this->data['id']) )
2439 {
2440 throw new E_OTS_NotLoaded();
2441 }
2442
2443 // deletes row from database
2444 $this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName('deleted') . ' = 1 WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
2445
2446 // resets object handle
2447 unset($this->data['id']);
2448 }
2449
2450/**
2451 * Player proffesion name.
2452 *
2453 * <p>
2454 * You need global vocations list resource loaded in order to use this method.
2455 * </p>
2456 *
2457 * @version 0.1.0
2458 * @since 0.0.6
2459 * @return string Player proffesion name.
2460 * @throws E_OTS_NotLoaded If player is not loaded or global vocations list is not loaded.
2461 */
2462 public function getVocationName()
2463 {
2464 if( !isset($this->data['vocation']) )
2465 {
2466 throw new E_OTS_NotLoaded();
2467 }
2468
2469 return POT::getInstance()->getVocationsList()->getVocationName($this->data['vocation']);
2470 }
2471
2472/**
2473 * Player residence town name.
2474 *
2475 * <p>
2476 * You need global map resource loaded in order to use this method.
2477 * </p>
2478 *
2479 * @version 0.1.0
2480 * @since 0.1.0
2481 * @return string Player town name.
2482 * @throws E_OTS_NotLoaded If player is not loaded or global map is not loaded.
2483 */
2484 public function getTownName()
2485 {
2486 if( !isset($this->data['town_id']) )
2487 {
2488 throw new E_OTS_NotLoaded();
2489 }
2490
2491 return POT::getInstance()->getMap()->getTownName($this->data['town_id']);
2492 }
2493
2494/**
2495 * Returns house rented by this player.
2496 *
2497 * <p>
2498 * You need global houses list resource loaded in order to use this method.
2499 * </p>
2500 *
2501 * @version 0.1.0
2502 * @since 0.1.0
2503 * @return OTS_House|null House rented by player.
2504 * @throws E_OTS_NotLoaded If player is not loaded or global houses list is not loaded.
2505 * @throws PDOException On PDO operation error.
2506 */
2507 public function getHouse()
2508 {
2509 if( !isset($this->data['id']) )
2510 {
2511 throw new E_OTS_NotLoaded();
2512 }
2513
2514 // SELECT query on database
2515 $house = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('houses') . ' WHERE ' . $this->db->fieldName('owner') . ' = ' . $this->data['id'])->fetch();
2516
2517 if( !empty($house) )
2518 {
2519 return POT::getInstance()->getHousesList()->getHouse($house['id']);
2520 }
2521
2522 return null;
2523 }
2524
2525/**
2526 * Returns list of VIPs.
2527 *
2528 * <p>
2529 * It means list of players which this player have on his/her list.
2530 * </p>
2531 *
2532 * @version 0.1.3
2533 * @since 0.1.3
2534 * @return OTS_Players_List List of VIPs.
2535 * @throws E_OTS_NotLoaded If player is not loaded.
2536 * @throws PDOException On PDO operation error.
2537 */
2538 public function getVIPsList()
2539 {
2540 if( !isset($this->data['id']) )
2541 {
2542 throw new E_OTS_NotLoaded();
2543 }
2544
2545 $list = new OTS_Players_List();
2546
2547 // foreign table fields identifiers
2548 $field1 = new OTS_SQLField('player_id', 'player_viplist');
2549 $field2 = new OTS_SQLField('vip_id', 'player_viplist');
2550
2551 // creates filter
2552 $filter = new OTS_SQLFilter();
2553 $filter->addFilter($field1, $this->data['id']);
2554 $filter->compareField('id', $field2);
2555
2556 // puts filter onto list
2557 $list->setFilter($filter);
2558
2559 return $list;
2560 }
2561
2562/**
2563 * Adds player to VIP list.
2564 *
2565 * @version 0.1.4
2566 * @since 0.1.3
2567 * @param OTS_Player $player Player to be added.
2568 * @throws E_OTS_NotLoaded If player is not loaded.
2569 * @throws PDOException On PDO operation error.
2570 */
2571 public function addVIP(OTS_Player $player)
2572 {
2573 if( !isset($this->data['id']) )
2574 {
2575 throw new E_OTS_NotLoaded();
2576 }
2577
2578 $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() . ')');
2579 }
2580
2581/**
2582 * Checks if given player is a VIP for current one.
2583 *
2584 * @version 0.1.5
2585 * @since 0.1.3
2586 * @param OTS_Player $player Player to check.
2587 * @return bool True, if given player is on VIP list.
2588 * @throws E_OTS_NotLoaded If player is not loaded.
2589 * @throws PDOException On PDO operation error.
2590 */
2591 public function isVIP(OTS_Player $player)
2592 {
2593 if( !isset($this->data['id']) )
2594 {
2595 throw new E_OTS_NotLoaded();
2596 }
2597
2598 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;
2599 }
2600
2601/**
2602 * Deletes player from VIP list.
2603 *
2604 * @version 0.1.4
2605 * @since 0.1.3
2606 * @param OTS_Player $player Player to be deleted.
2607 * @throws E_OTS_NotLoaded If player is not loaded.
2608 * @throws PDOException On PDO operation error.
2609 */
2610 public function deleteVIP(OTS_Player $player)
2611 {
2612 if( !isset($this->data['id']) )
2613 {
2614 throw new E_OTS_NotLoaded();
2615 }
2616
2617 $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() );
2618 }
2619
2620/**
2621 * Returns list of known spells.
2622 *
2623 * <p>
2624 * You need global spells list resource loaded in order to use this method.
2625 * </p>
2626 *
2627 * @version 0.1.4
2628 * @since 0.1.4
2629 * @return array List of known spells.
2630 * @throws E_OTS_NotLoaded If player is not loaded.
2631 * @throws PDOException On PDO operation error.
2632 */
2633 public function getSpellsList()
2634 {
2635 if( !isset($this->data['id']) )
2636 {
2637 throw new E_OTS_NotLoaded();
2638 }
2639
2640 $spells = array();
2641 $list = POT::getInstance()->getSpellsList();
2642
2643 // reads all known spells
2644 foreach( $this->db->query('SELECT ' . $this->db->fieldName('name') . ' FROM ' . $this->db->tableName('player_spells') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id']) as $spell)
2645 {
2646 // checks if there is rune, instant or conjure spell with given name
2647
2648 if( $list->hasRune($spell['name']) )
2649 {
2650 $spells[] = $list->getRune($spell['name']);
2651 }
2652
2653 if( $list->hasInstance($spell['name']) )
2654 {
2655 $spells[] = $list->getInstance($spell['name']);
2656 }
2657
2658 if( $list->hasConjure($spell['name']) )
2659 {
2660 $spells[] = $list->getConjure($spell['name']);
2661 }
2662 }
2663
2664 return $spells;
2665 }
2666
2667/**
2668 * Checks if player knows given spell.
2669 *
2670 * @version 0.1.5
2671 * @since 0.1.4
2672 * @param OTS_Spell $spell Spell to be checked.
2673 * @return bool True if player knows given spell, false otherwise.
2674 * @throws E_OTS_NotLoaded If player is not loaded.
2675 * @throws PDOException On PDO operation error.
2676 */
2677 public function hasSpell(OTS_Spell $spell)
2678 {
2679 if( !isset($this->data['id']) )
2680 {
2681 throw new E_OTS_NotLoaded();
2682 }
2683
2684 return $this->db->query('SELECT COUNT(' . $this->db->fieldName('name') . ') FROM ' . $this->db->tableName('player_spells') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('name') . ' = ' . $this->db->quote( $spell->getName() ) )->fetchColumn() > 0;
2685 }
2686
2687/**
2688 * Adds given spell to player's spell book (makes him knowing it).
2689 *
2690 * @version 0.1.4
2691 * @since 0.1.4
2692 * @param OTS_Spell $spell Spell to be learned.
2693 * @throws E_OTS_NotLoaded If player is not loaded.
2694 * @throws PDOException On PDO operation error.
2695 */
2696 public function addSpell(OTS_Spell $spell)
2697 {
2698 if( !isset($this->data['id']) )
2699 {
2700 throw new E_OTS_NotLoaded();
2701 }
2702
2703 $this->db->query('INSERT INTO ' . $this->db->tableName('player_spells') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('name') . ') VALUES (' . $this->data['id'] . ', ' . $this->db->quote( $spell->getName() ) . ')');
2704 }
2705
2706/**
2707 * Removes given spell from player's spell book.
2708 *
2709 * @version 0.1.4
2710 * @since 0.1.4
2711 * @param OTS_Spell $spell Spell to be removed.
2712 * @throws E_OTS_NotLoaded If player is not loaded.
2713 * @throws PDOException On PDO operation error.
2714 */
2715 public function deleteSpell(OTS_Spell $spell)
2716 {
2717 if( !isset($this->data['id']) )
2718 {
2719 throw new E_OTS_NotLoaded();
2720 }
2721
2722 $this->db->query('DELETE FROM ' . $this->db->tableName('player_spells') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('name') . ' = ' . $this->db->quote( $spell->getName() ) );
2723 }
2724
2725/**
2726 * Magic PHP5 method.
2727 *
2728 * @version 0.1.5
2729 * @since 0.1.0
2730 * @param string $name Property name.
2731 * @return mixed Property value.
2732 * @throws E_OTS_NotLoaded When player is not loaded.
2733 * @throws OutOfBoundsException For non-supported properties.
2734 * @throws PDOException On PDO operation error.
2735 */
2736 public function __get($name)
2737 {
2738 switch($name)
2739 {
2740 case 'id':
2741 return $this->getId();
2742
2743 case 'name':
2744 return $this->getName();
2745
2746 case 'account':
2747 return $this->getAccount();
2748
2749 case 'group':
2750 return $this->getGroup();
2751
2752 case 'sex':
2753 return $this->getSex();
2754
2755 case 'vocation':
2756 return $this->getVocation();
2757
2758 case 'experience':
2759 return $this->getExperience();
2760
2761 case 'level':
2762 return $this->getLevel();
2763
2764 case 'magLevel':
2765 return $this->getMagLevel();
2766
2767 case 'health':
2768 return $this->getHealth();
2769
2770 case 'healthMax':
2771 return $this->getHealthMax();
2772
2773 case 'mana':
2774 return $this->getMana();
2775
2776 case 'manaMax':
2777 return $this->getManaMax();
2778
2779 case 'manaSpent':
2780 return $this->getManaSpent();
2781
2782 case 'soul':
2783 return $this->getSoul();
2784
2785 case 'direction':
2786 return $this->getDirection();
2787
2788 case 'lookBody':
2789 return $this->getLookBody();
2790
2791 case 'lookFeet':
2792 return $this->getLookFeet();
2793
2794 case 'lookHead':
2795 return $this->getLookHead();
2796
2797 case 'lookLegs':
2798 return $this->getLookLegs();
2799
2800 case 'lookType':
2801 return $this->getLookType();
2802
2803 case 'lookAddons':
2804 return $this->getLookAddons();
2805
2806 case 'posX':
2807 return $this->getPosX();
2808
2809 case 'posY':
2810 return $this->getPosY();
2811
2812 case 'posZ':
2813 return $this->getPosZ();
2814
2815 case 'cap':
2816 return $this->getCap();
2817
2818 case 'lastLogin':
2819 return $this->getLastLogin();
2820
2821 case 'lastIP':
2822 return $this->getLastIP();
2823
2824 case 'save':
2825 return $this->isSaveSet();
2826
2827 case 'conditions':
2828 return $this->getConditions();
2829
2830 case 'redSkullTime':
2831 return $this->getRedSkullTime();
2832
2833 case 'redSkull':
2834 return $this->hasRedSkull();
2835
2836 case 'guildNick':
2837 return $this->getGuildNick();
2838
2839 case 'rank':
2840 return $this->getRank();
2841
2842 case 'townId':
2843 return $this->getTownId();
2844
2845 case 'townName':
2846 return $this->getTownName();
2847
2848 case 'house':
2849 return $this->getHouse();
2850
2851 case 'lossExperience':
2852 return $this->getLossExperience();
2853
2854 case 'lossMana':
2855 return $this->getLossMana();
2856
2857 case 'lossSkills':
2858 return $this->getLossSkills();
2859
2860 case 'lossItems':
2861 return $this->getLossItems();
2862
2863 case 'lossContainers':
2864 return $this->getLossContainers();
2865
2866 case 'balance':
2867 return $this->getBalance();
2868
2869 case 'loaded':
2870 return $this->isLoaded();
2871
2872 case 'banned':
2873 return $this->isBanned();
2874
2875 case 'vipsList':
2876 return $this->getVIPsList();
2877
2878 case 'vocationName':
2879 return $this->getVocationName();
2880
2881 case 'spellsList':
2882 return $this->getSpellsList();
2883
2884 default:
2885 throw new OutOfBoundsException();
2886 }
2887 }
2888
2889/**
2890 * Magic PHP5 method.
2891 *
2892 * @version 0.1.5
2893 * @since 0.1.0
2894 * @param string $name Property name.
2895 * @param mixed $value Property value.
2896 * @throws E_OTS_NotLoaded When passing object value which represents not-initialised instance.
2897 * @throws OutOfBoundsException For non-supported properties.
2898 */
2899 public function __set($name, $value)
2900 {
2901 switch($name)
2902 {
2903 case 'name':
2904 $this->setName($value);
2905 break;
2906
2907 case 'account':
2908 $this->setAccount($value);
2909 break;
2910
2911 case 'group':
2912 $this->setGroup($value);
2913 break;
2914
2915 case 'sex':
2916 $this->setSex($value);
2917 break;
2918
2919 case 'vocation':
2920 $this->setVocation($value);
2921 break;
2922
2923 case 'experience':
2924 $this->setExperience($value);
2925 break;
2926
2927 case 'level':
2928 $this->setLevel($value);
2929 break;
2930
2931 case 'magLevel':
2932 $this->setMagLevel($value);
2933 break;
2934
2935 case 'health':
2936 $this->setHealth($value);
2937 break;
2938
2939 case 'healthMax':
2940 $this->setHealthMax($value);
2941 break;
2942
2943 case 'mana':
2944 $this->setMana($value);
2945 break;
2946
2947 case 'manaMax':
2948 $this->setManaMax($value);
2949 break;
2950
2951 case 'manaSpent':
2952 $this->setManaSpent($value);
2953 break;
2954
2955 case 'soul':
2956 $this->setSoul($value);
2957 break;
2958
2959 case 'direction':
2960 $this->setDirection($value);
2961 break;
2962
2963 case 'lookBody':
2964 $this->setLookBody($value);
2965 break;
2966
2967 case 'lookFeet':
2968 $this->setLookFeet($value);
2969 break;
2970
2971 case 'lookHead':
2972 $this->setLookHead($value);
2973 break;
2974
2975 case 'lookLegs':
2976 $this->setLookLegs($value);
2977 break;
2978
2979 case 'lookType':
2980 $this->setLookType($value);
2981 break;
2982
2983 case 'lookAddons':
2984 $this->setLookAddons($value);
2985 break;
2986
2987 case 'posX':
2988 $this->setPosX($value);
2989 break;
2990
2991 case 'posY':
2992 $this->setPosY($value);
2993 break;
2994
2995 case 'posZ':
2996 $this->setPosZ($value);
2997 break;
2998
2999 case 'cap':
3000 $this->setCap($value);
3001 break;
3002
3003 case 'lastLogin':
3004 $this->setLastLogin($value);
3005 break;
3006
3007 case 'lastIP':
3008 $this->setLastIP($value);
3009 break;
3010
3011 case 'conditions':
3012 $this->setConditions($value);
3013 break;
3014
3015 case 'redSkullTime':
3016 $this->setRedSkullTime($value);
3017 break;
3018
3019 case 'guildNick':
3020 $this->setGuildNick($value);
3021 break;
3022
3023 case 'rank':
3024 $this->setRank($value);
3025 break;
3026
3027 case 'townId':
3028 $this->setTownId($value);
3029 break;
3030
3031 case 'lossExperience':
3032 $this->setLossExperience($value);
3033 break;
3034
3035 case 'lossMana':
3036 $this->setLossMana($value);
3037 break;
3038
3039 case 'lossSkills':
3040 $this->setLossSkills($value);
3041 break;
3042
3043 case 'lossItems':
3044 $this->setLossItems($value);
3045 break;
3046
3047 case 'lossContainers':
3048 $this->setLossContainers($value);
3049 break;
3050
3051 case 'balance':
3052 $this->setBalance($value);
3053 break;
3054
3055 case 'redSkull':
3056 if($value)
3057 {
3058 $this->setRedSkull();
3059 }
3060 else
3061 {
3062 $this->unsetRedSkull();
3063 }
3064 break;
3065
3066 case 'save':
3067 if($value)
3068 {
3069 $this->setSave();
3070 }
3071 else
3072 {
3073 $this->unsetSave();
3074 }
3075 break;
3076
3077 case 'banned':
3078 if($value)
3079 {
3080 $this->ban();
3081 }
3082 else
3083 {
3084 $this->unban();
3085 }
3086 break;
3087
3088 default:
3089 throw new OutOfBoundsException();
3090 }
3091 }
3092
3093/**
3094 * Returns string representation of object.
3095 *
3096 * <p>
3097 * If any display driver is currently loaded then it uses it's method. Else it returns character name.
3098 * </p>
3099 *
3100 * @version 0.1.3
3101 * @since 0.1.0
3102 * @return string String representation of object.
3103 */
3104 public function __toString()
3105 {
3106 $ots = POT::getInstance();
3107
3108 // checks if display driver is loaded
3109 if( $ots->isDisplayDriverLoaded() )
3110 {
3111 return $ots->getDisplayDriver()->displayPlayer($this);
3112 }
3113
3114 return $this->getName();
3115 }
3116}
3117
3118/**#@-*/
3119
3120?>