-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
OTS_Player.php
3629 lines (3189 loc) · 103 KB
/
OTS_Player.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
$__load = array();
/*
'loss_experience' => NULL,
'loss_items' => NULL,
'guild_info' => NULL,
'skull_type' => NULL,
'skull_time' => NULL,
'blessings' => NULL,
'direction' => NULL,
'stamina' => NULL,
'world_id' => NULL,
'online' => NULL,
'deletion' => NULL,
'promotion' => NULL,
'marriage' => NULL
);*/
/**#@+
* @version 0.0.1
*/
/**
* @package POT
* @version 0.1.5
* @author Wrzasq <wrzasq@gmail.com>
* @copyright 2007 - 2008 (C) by Wrzasq
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
*/
/**
* OTServ character abstraction.
*
* @package POT
* @version 0.1.5
* @property string $name Character name.
* @property OTS_Account $account Account to which character belongs.
* @property OTS_Group $group Group of which character is member.
* @property int $sex Gender.
* @property int $vocation Vocation.
* @property int $experience Experience points.
* @property int $level Experience level.
* @property int $magLevel Magic level.
* @property int $health Hit points.
* @property int $healthMax Maximum hit points.
* @property int $mana Mana.
* @property int $manaMax Maximum mana.
* @property int $manaSpent Spent mana.
* @property int $soul Soul points.
* @property int $direction Looking direction.
* @property int $lookBody Body color.
* @property int $lookFeet Feet color.
* @property int $lookHead Hairs color.
* @property int $lookLegs Legs color.
* @property int $lookType Outfit type.
* @property int $lookAddons Addons.
* @property int $posX Spawn X coord.
* @property int $posY Spawn Y coord.
* @property int $posZ Spawn Z coord.
* @property int $cap Capacity.
* @property int $lastLogin Last login timestamp.
* @property int $lastIP Last login IP number.
* @property string $conditions Binary conditions.
* @property int $redSkullTime Timestamp for which red skull will last.
* @property string $guildNick
* @property OTS_GuildRank $rank
* @property int $townId
* @property int $lossExperience
* @property int $lossMana
* @property int $lossSkills
* @property int $lossItems
* @property int $balance Bank balance.
* @property bool $save Player save flag.
* @property bool $redSkull Player red skull flag.
* @property bool $banned Player banned state.
* @property-read int $id Player ID.
* @property-read bool $loaded Loaded state.
* @property-read string $townName Name of town in which player residents.
* @property-read OTS_House $house House which player rents.
* @property-read OTS_Players_List $vipsList List of VIPs of player.
* @property-read string $vocationName String vocation representation.
* @property-read array $spellsList List of known spells.
* @tutorial POT/Players.pkg
*/
class OTS_Player extends OTS_Row_DAO
{
/**
* Player data.
*
* @version 0.1.2
* @var array
*/
private $data = array('sex' => 0, 'vocation' => 0, 'experience' => 0, 'level' => 1, 'maglevel' => 0, 'health' => 100, 'healthmax' => 100, 'mana' => 100, 'manamax' => 100, 'manaspent' => 0, 'soul' => 0, '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, 'skulltime' => 0, 'skull' => 0, 'balance' => 0, 'lastlogout' => 0, 'blessings' => 0, 'stamina' => 0, 'online' => 0, 'comment' => '', 'created' => 0, 'hidden' => 0);
/**
* Player skills.
*
* @version 0.0.2
* @since 0.0.2
* @var array
*/
private $skills = array(
POT::SKILL_FIST => array('value' => 0, 'tries' => 0),
POT::SKILL_CLUB => array('value' => 0, 'tries' => 0),
POT::SKILL_SWORD => array('value' => 0, 'tries' => 0),
POT::SKILL_AXE => array('value' => 0, 'tries' => 0),
POT::SKILL_DIST => array('value' => 0, 'tries' => 0),
POT::SKILL_SHIELD => array('value' => 0, 'tries' => 0),
POT::SKILL_FISH => array('value' => 0, 'tries' => 0)
);
/**
* Magic PHP5 method.
*
* Allows object serialisation.
*
* @return array List of properties that should be saved.
* @version 0.0.4
* @since 0.0.4
*/
public function __sleep()
{
return array('data', 'skills');
}
/**
* Loads player with given id.
*
* @version 0.1.2
* @param int $id Player's ID.
* @throws PDOException On PDO operation error.
*/
public function load($id, $fields = null, $load_skills = true)
{
global $__load;
if(!isset($__load['loss_experience']))
{
$loss = '';
if($this->db->hasColumn('players', 'loss_experience')) {
$loss = ', `loss_experience`, `loss_mana`, `loss_skills`';
}
$__load['loss_experience'] = $loss;
}
if(!isset($__load['loss_items']))
{
$loss_items = '';
if($this->db->hasColumn('players', 'loss_items')) {
$loss_items = ', `loss_items`, `loss_containers`';
}
$__load['loss_items'] = $loss_items;
}
if(!isset($__load['guild_info']))
{
$guild_info = '';
if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
$guild_info = ', `guildnick`, `rank_id`';
}
$__load['guild_info'] = $guild_info;
}
if(!isset($__load['skull_type']))
{
$skull_type = 'skull';
if($this->db->hasColumn('players', 'skull_type')) {
$skull_type = 'skull_type';
}
$__load['skull_type'] = $skull_type;
}
if(!isset($__load['skull_time']))
{
$skull_time = 'skulltime';
if($this->db->hasColumn('players', 'skull_time')) {
$skull_time = 'skull_time';
}
$__load['skull_time'] = $skull_time;
}
if(!isset($__load['blessings'])) {
$__load['blessings'] = $this->db->hasColumn('players', 'blessings');
}
if(!isset($__load['direction'])) {
$__load['direction'] = $this->db->hasColumn('players', 'direction');
}
if(!isset($__load['stamina'])) {
$__load['stamina'] = $this->db->hasColumn('players', 'stamina');
}
if(!isset($__load['world_id'])) {
$__load['world_id'] = $this->db->hasColumn('players', 'world_id');
}
if(!isset($__load['online'])) {
$__load['online'] = $this->db->hasColumn('players', 'online');
}
if(!isset($__load['deletion'])) {
$__load['deletion'] = $this->db->hasColumn('players', 'deletion');
}
if(!isset($__load['promotion'])) {
$__load['promotion'] = $this->db->hasColumn('players', 'promotion');
}
if(!isset($__load['marriage'])) {
$__load['marriage'] = $this->db->hasColumn('players', 'marriage');
}
if(isset($fields)) { // load only what we wish
if(in_array('promotion', $fields)) {
if(!$this->db->hasColumn('players', 'promotion')) {
unset($fields[array_search('promotion', $fields)]);
}
}
if(in_array('deleted', $fields)) {
if($this->db->hasColumn('players', 'deletion')) {
unset($fields[array_search('deleted', $fields)]);
$fields[] = 'deletion';
}
}
if(in_array('online', $fields)) {
if(!$this->db->hasColumn('players', 'online')) {
unset($fields[array_search('online', $fields)]);
}
}
$this->data = $this->db->query('SELECT ' . implode(', ', $fields) . ' FROM `players` WHERE `id` = ' . (int)$id)->fetch();
}
else {
// SELECT query on database
$this->data = $this->db->query('SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . ($this->db->hasColumn('players', 'lookaddons') ? ', `lookaddons`' : '') . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $__load['skull_time'] . '` as `skulltime`, `' . $__load['skull_type'] . '` as `skull`' . $__load['guild_info'] . ', `town_id`' . $__load['loss_experience'] . $__load['loss_items'] . ', `balance`' . ($__load['blessings'] ? ', `blessings`' : '') . ($__load['direction'] ? ', `direction`' : '') . ($__load['stamina'] ? ', `stamina`' : '') . ($__load['world_id'] ? ', `world_id`' : '') . ($__load['online'] ? ', `online`' : '') . ', `' . ($__load['deletion'] ? 'deletion' : 'deleted') . '`' . ($__load['promotion'] ? ', `promotion`' : '') . ($__load['marriage'] ? ', `marriage`' : '') . ', `comment`, `created`, `hidden` FROM `players` WHERE `id` = ' . (int)$id)->fetch();
}
// loads skills
if( $this->isLoaded() && $load_skills)
{
if($this->db->hasColumn('players', 'skill_fist')) {
$skill_ids = array(
'skill_fist' => POT::SKILL_FIST,
'skill_club' => POT::SKILL_CLUB,
'skill_sword' => POT::SKILL_SWORD,
'skill_axe' => POT::SKILL_AXE,
'skill_dist' => POT::SKILL_DIST,
'skill_shielding' => POT::SKILL_SHIELD,
'skill_fishing' => POT::SKILL_FISH
);
$select = '';
$i = count($skill_ids);
foreach($skill_ids as $name => $id) {
$select .= '`' . $name . '`,';
$select .= '`' . $name . '_tries`';
if($id != $i - 1)
$select .= ',';
}
//echo $select;
$skills = $this->db->query('SELECT ' . $select . ' FROM `players` WHERE `id` = ' . $this->data['id'])->fetch();
foreach($skill_ids as $name => $id) {
$this->skills[$id] = array('value' => $skills[$name], 'tries' => $skills[$name . '_tries']);
}
}
else if($this->db->hasTable('player_skills')) {
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)
{
$this->skills[ $skill['skillid'] ] = array('value' => $skill['value'], 'tries' => $skill['count']);
}
}
}
}
/**
* Loads player by it's name.
*
* @version 0.0.5
* @since 0.0.2
* @param string $name Player's name.
* @throws PDOException On PDO operation error.
*/
public function find($name)
{
// finds player's ID
$id = $this->db->query('SELECT `id` FROM `players` WHERE `name` = ' . $this->db->quote($name) )->fetch();
// if anything was found
if( isset($id['id']) )
{
$this->load($id['id']);
}
}
/**
* Checks if object is loaded.
*
* @return bool Load state.
*/
public function isLoaded()
{
return isset($this->data['id']);
}
/**
* Saves player in database.
*
* <p>
* If player is not loaded to represent any existing group it will create new row for it.
* </p>
*
* @version 0.1.2
* @throws PDOException On PDO operation error.
*/
public function save()
{
$skull_type = 'skull';
if($this->db->hasColumn('players', 'skull_type')) {
$skull_type = 'skull_type';
}
$skull_time = 'skulltime';
if($this->db->hasColumn('players', 'skull_time')) {
$skull_time = 'skull_time';
}
if(!isset($this->data['loss_experience']))
$this->data['loss_experience'] = 100;
if(!isset($this->data['loss_mana']))
$this->data['loss_mana'] = 100;
if(!isset($this->data['loss_skills']))
$this->data['loss_skills'] = 100;
if(!isset($this->data['loss_items']))
$this->data['loss_items'] = 10;
if(!isset($this->data['loss_containers']))
$this->data['loss_containers'] = 100;
if(!isset($this->data['guildnick']))
$this->data['guildnick'] = '';
if(!isset($this->data['rank_id']))
$this->data['rank_id'] = 0;
if(!isset($this->data['promotion']))
$this->data['promotion'] = 0;
if(!isset($this->data['direction']))
$this->data['direction'] = 0;
if(!isset($this->data['conditions']))
$this->data['conditions'] = '';
if(!isset($this->data['town_id']))
$this->data['town_id'] = 1;
// updates existing player
if( isset($this->data['id']) )
{
$loss = '';
if($this->db->hasColumn('players', 'loss_experience')) {
$loss = ', `loss_experience` = ' . $this->data['loss_experience'] . ', `loss_mana` = ' . $this->data['loss_mana'] . ', `loss_skills` = ' . $this->data['loss_skills'];
}
$loss_items = '';
if($this->db->hasColumn('players', 'loss_items')) {
$loss_items = ', `loss_items` = ' . $this->data['loss_items'] . ', `loss_containers` = ' . $this->data['loss_containers'];
}
$guild_info = '';
if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
$guild_info = ', `guildnick` = ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->db->fieldName('rank_id') . ' = ' . $this->data['rank_id'];
}
$direction = '';
if($this->db->hasColumn('players', 'direction')) {
$direction = ', `direction` = ' . $this->db->quote($this->data['direction']);
}
$blessings = '';
if($this->db->hasColumn('players', 'blessings')) {
$blessings = ', `blessings` = ' . $this->db->quote($this->data['blessings']);
}
$stamina = '';
if($this->db->hasColumn('players', 'stamina')) {
$stamina = ', `stamina` = ' . $this->db->quote($this->data['stamina']);
}
$lookaddons = '';
if($this->db->hasColumn('players', 'lookaddons')) {
$lookaddons = ', `lookaddons` = ' . $this->db->quote($this->data['lookaddons']);
}
// UPDATE query on database
$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('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('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'] . $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('lastlogout') . ' = ' . $this->data['lastlogout'] . ', ' . $this->db->fieldName('lastip') . ' = ' . $this->db->quote($this->data['lastip']) . ', ' . $this->db->fieldName('save') . ' = ' . (int) $this->data['save'] . ', ' . $this->db->fieldName('conditions') . ' = ' . $this->db->quote($this->data['conditions']) . ', `' . $skull_time . '` = ' . $this->data['skulltime'] . ', `' . $skull_type . '` = ' . (int) $this->data['skull'] . $guild_info . ', ' . $this->db->fieldName('town_id') . ' = ' . $this->data['town_id'] . $loss . $loss_items . ', ' . $this->db->fieldName('balance') . ' = ' . $this->data['balance'] . $blessings . $stamina . $direction . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
}
// creates new player
else
{
$loss = '';
$loss_data = '';
if($this->db->hasColumn('players', 'loss_experience')) {
$loss = ', `loss_experience`, `loss_mana`, `loss_skills`';
$loss_data = ', ' . $this->data['loss_experience'] . ', ' . $this->data['loss_mana'] . ', ' . $this->data['loss_skills'];
}
$loss_items = '';
$loss_items_data = '';
if($this->db->hasColumn('players', 'loss_items')) {
$loss_items = ', `loss_items`, `loss_containers`';
$loss_items_data = ', ' . $this->data['loss_items'] . ', ' . $this->data['loss_containers'];
}
$guild_info = '';
$guild_info_data = '';
if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
$guild_info = ', `guildnick`, `rank_id`';
$guild_info_data = ', ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->data['rank_id'];
}
$promotion = '';
$promotion_data = '';
if($this->db->hasColumn('players', 'promotion')) {
$promotion = ', `promotion`';
$promotion_data = ', ' . $this->data['promotion'];
}
$direction = '';
$direction_data = '';
if($this->db->hasColumn('players', 'direction')) {
$direction = ', `direction`';
$direction_data = ', ' . $this->data['direction'];
}
$blessings = '';
$blessings_data = '';
if($this->db->hasColumn('players', 'blessings')) {
$blessings = ', `blessings`';
$blessings_data = ', ' . $this->data['blessings'];
}
$stamina = '';
$stamina_data = '';
if($this->db->hasColumn('players', 'stamina')) {
$stamina = ', `stamina`';
$stamina_data = ', ' . $this->data['stamina'];
}
$lookaddons = '';
$lookaddons_data = '';
if($this->db->hasColumn('players', 'lookaddons')) {
$lookaddons = ', `lookaddons`';
$lookaddons_data = ', ' . $this->data['lookaddons'];
}
// INSERT query on database
$this->db->query('INSERT INTO `players` (`name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . $lookaddons . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $skull_time . '`, `' . $skull_type . '`' . $guild_info . ', `town_id`' . $loss . $loss_items . ', `balance`' . $blessings . $stamina . $direction . ', `created`' . $promotion . ', `comment`) VALUES (' . $this->db->quote($this->data['name']) . ', ' . $this->data['account_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['lookbody'] . ', ' . $this->data['lookfeet'] . ', ' . $this->data['lookhead'] . ', ' . $this->data['looklegs'] . ', ' . $this->data['looktype'] . $lookaddons_data . ', ' . $this->data['posx'] . ', ' . $this->data['posy'] . ', ' . $this->data['posz'] . ', ' . $this->data['cap'] . ', ' . $this->data['lastlogin'] . ', ' . $this->data['lastlogout'] . ', ' . $this->data['lastip'] . ', ' . (int) $this->data['save'] . ', ' . $this->db->quote($this->data['conditions']) . ', ' . $this->data['skulltime'] . ', ' . (int) $this->data['skull'] . $guild_info_data . ', ' . $this->data['town_id'] . $loss_data . $loss_items_data . ', ' . $this->data['balance'] . $blessings_data . $stamina_data . $direction_data . ', ' . time() . $promotion_data . ', "")');
// ID of new group
$this->data['id'] = $this->db->lastInsertId();
}
// updates skills - doesn't matter if we have just created character - trigger inserts new skills
if($this->db->hasColumn('players', 'skill_fist')) { // tfs 1.0
$set = '';
$skill_ids = array(
'skill_fist' => POT::SKILL_FIST,
'skill_club' => POT::SKILL_CLUB,
'skill_sword' => POT::SKILL_SWORD,
'skill_axe' => POT::SKILL_AXE,
'skill_dist' => POT::SKILL_DIST,
'skill_shielding' => POT::SKILL_SHIELD,
'skill_fishing' => POT::SKILL_FISH
);
$i = count($skill_ids);
foreach($skill_ids as $name => $id) {
$set .= '`' . $name . '` = ' . $this->skills[$id]['value'] . ',';
$set .= '`' . $name . '_tries` = ' . $this->skills[$id]['tries'];
if($id != $i - 1)
$set .= ',';
}
$skills = $this->db->query('UPDATE `players` SET ' . $set . ' WHERE `id` = ' . $this->data['id']);
}
else if($this->db->hasTable('player_skills')) {
foreach($this->skills as $id => $skill)
{
$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);
}
}
}
/**
* Player ID.
*
* <p>
* Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
* </p>
*
* @version 0.0.3
* @return int Player ID.
* @throws E_OTS_NotLoaded If player is not loaded.
*/
public function getId()
{
if( !isset($this->data['id']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['id'];
}
public function isHidden()
{
if( !isset($this->data['hidden']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['hidden'] == 1;
}
public function setHidden($hidden)
{
$this->data['hidden'] = (int) $hidden;
}
public function getMarriage()
{
if(!$this->db->hasColumn('players', 'marriage'))
return '';
if( !isset($this->data['marriage']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['marriage'];
}
/**
* Player name.
*
* <p>
* Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
* </p>
*
* @version 0.0.3
* @return string Player's name.
* @throws E_OTS_NotLoaded If player is not loaded.
*/
public function getName()
{
if( !isset($this->data['name']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['name'];
}
/**
* Sets players's name.
*
* <p>
* 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.
* </p>
*
* @param string $name Name.
*/
public function setName($name)
{
$this->data['name'] = (string) $name;
}
/**
* Returns account of this player.
*
* <p>
* Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
* </p>
*
* @version 0.1.0
* @return OTS_Account Owning account.
* @throws E_OTS_NotLoaded If player is not loaded.
* @throws PDOException On PDO operation error.
*/
public function getAccount()
{
if( !isset($this->data['account_id']) )
{
throw new E_OTS_NotLoaded();
}
$account = new OTS_Account();
$account->load($this->data['account_id']);
return $account;
}
public function getAccountId()
{
if( !isset($this->data['account_id']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['account_id'];
}
/**
* Assigns character to account.
*
* <p>
* 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.
* </p>
*
* @param OTS_Account $account Owning account.
* @throws E_OTS_NotLoaded If passed <var>$account</var> parameter is not loaded.
*/
public function setAccount(OTS_Account $account)
{
$this->data['account_id'] = $account->getId();
}
public function setAccountId($account_id)
{
$this->data['account_id'] = (int)$account_id;
}
/**
* Returns group of this player.
*
* <p>
* Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
* </p>
*
* @version 0.1.0
* @return OTS_Group Group of which current character is member.
* @throws E_OTS_NotLoaded If player is not loaded.
* @throws PDOException On PDO operation error.
*/
public function getGroup()
{
//global $config;
//if($path == '')
// $path = $config['data_path'].'XML/groups.xml';
if( !isset($this->data['group_id']) )
{
throw new E_OTS_NotLoaded();
}
//$groups = new DOMDocument();
//$groups->load($path);
global $groups;
$tmp = $groups->getGroup($this->data['group_id']);
if($tmp)
return $tmp;
return new OTS_Group();
// echo 'error while loading group..';
/*
$_id = $this->data['group_id'];
$tmpGroup = new OTS_Group;
foreach($groups->getElementsByTagName('group') as $group)
{
if($group->getAttribute('id') == $_id)
{
$tmpGroup->load($group);
return $tmpGroup;
}
}*/
// $group = new OTS_Group();
// $group->load($this->data['group_id']);
// return $group;
}
/**
* Assigns character to group.
*
* <p>
* 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.
* </p>
*
* @param OTS_Group $group Group to be a member.
* @throws E_OTS_NotLoaded If passed <var>$group</var> parameter is not loaded.
*/
public function setGroup(OTS_Group $group)
{
$this->data['group_id'] = $group->getId();
}
public function setGroupId($group_id)
{
$this->data['group_id'] = $group_id;
}
/**
* Player's Premium Account expiration timestamp.
*
* @version 0.1.5
* @since 0.0.3
* @return int Player PACC expiration timestamp.
* @throws E_OTS_NotLoaded If player is not loaded.
* @deprecated 0.1.5 Use OTS_Account->getPremiumEnd().
*/
public function getPremiumEnd()
{
if( !isset($this->data['id']) )
{
throw new E_OTS_NotLoaded();
}
return $this->getAccount()->getPremiumEnd();
}
/**
* Player gender.
*
* <p>
* Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
* </p>
*
* @version 0.0.3
* @return int Player gender.
* @throws E_OTS_NotLoaded If player is not loaded.
*/
public function getSex()
{
if( !isset($this->data['sex']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['sex'];
}
public function isDeleted()
{
$field = 'deleted';
if($this->db->hasColumn('players', 'deletion'))
$field = 'deletion';
if( !isset($this->data[$field]) )
{
throw new E_OTS_NotLoaded();
}
return $this->data[$field] > 0;
}
public function setDeleted($deleted)
{
$this->data['deleted'] = (int) $deleted;
}
public function isOnline()
{
if($this->db->hasTable('players_online')) // tfs 1.0
{
$query = $this->db->query('SELECT `player_id` FROM `players_online` WHERE `player_id` = ' . $this->data['id']);
return $query->rowCount() > 0;
}
if( !isset($this->data['online']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['online'] == 1;
}
public function getCreated()
{
if( !isset($this->data['created']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['created'];
}
public function setCreated($created)
{
$this->data['created'] = (bool) $created;
}
public function getComment()
{
if( !isset($this->data['comment']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['comment'];
}
public function setComment($comment)
{
$this->data['comment'] = (string) $comment;
}
/**
* Sets player gender.
*
* <p>
* 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.
* </p>
*
* @param int $sex Player gender.
*/
public function setSex($sex)
{
$this->data['sex'] = (int) $sex;
}
/**
* Player proffesion.
*
* <p>
* Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
* </p>
*
* @version 0.0.3
* @return int Player proffesion.
* @throws E_OTS_NotLoaded If player is not loaded.
*/
public function getVocation()
{
if( !isset($this->data['vocation']) )
{
throw new E_OTS_NotLoaded();
}
if(isset($this->data['promotion'])) {
global $config;
if((int)$this->data['promotion'] > 0)
return ($this->data['vocation'] + ($this->data['promotion'] * $config['vocations_amount']));
}
return $this->data['vocation'];
}
public function getPromotion()
{
if( !isset($this->data['promotion']) )
{
return false;
}
return $this->data['promotion'];
}
/**
* Sets player proffesion.
*
* <p>
* 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.
* </p>
*
* @param int $vocation Player proffesion.
*/
public function setVocation($vocation)
{
$this->data['vocation'] = (int) $vocation;
}
public function setPromotion($promotion)
{
$this->data['promotion'] = (int) $promotion;
}
/**
* Experience points.
*
* <p>
* Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
* </p>
*
* @version 0.0.3
* @return int Experience points.
* @throws E_OTS_NotLoaded If player is not loaded.
*/
public function getExperience()
{
if( !isset($this->data['experience']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['experience'];
}
/**
* Sets experience points.
*
* <p>
* 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.
* </p>
*
* @param int $experience Experience points.
*/
public function setExperience($experience)
{
$this->data['experience'] = (int) $experience;
}
/**
* Experience level.
*
* <p>
* Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
* </p>
*
* @version 0.0.3
* @return int Experience level.
* @throws E_OTS_NotLoaded If player is not loaded.
*/
public function getLevel()
{
if( !isset($this->data['level']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['level'];
}
/**
* Sets experience level.
*
* <p>
* 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.
* </p>
*
* @param int $level Experience level.
*/
public function setLevel($level)
{
$this->data['level'] = (int) $level;
}
/**
* Magic level.
*
* <p>
* Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
* </p>
*
* @version 0.0.3
* @return int Magic level.
* @throws E_OTS_NotLoaded If player is not loaded.
*/
public function getMagLevel()
{
if( !isset($this->data['maglevel']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['maglevel'];
}
/**
* Sets magic level.
*
* <p>
* 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.
* </p>
*
* @param int $maglevel Magic level.
*/
public function setMagLevel($maglevel)
{
$this->data['maglevel'] = (int) $maglevel;
}
/**
* Current HP.
*
* <p>
* Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
* </p>
*
* @version 0.0.3
* @return int Current HP.
* @throws E_OTS_NotLoaded If player is not loaded.
*/
public function getHealth()
{
if( !isset($this->data['health']) )