-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadr_character.php
1149 lines (1033 loc) · 42.4 KB
/
adr_character.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
/***************************************************************************
* adr_character.php
* ------------------------
* begin : 31/01/2004
* copyright : Malicious Rabbit / Dr DLP
*
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
***************************************************************************/
define('IN_PHPBB', true);
define('IN_ADR_CHARACTER', true);
define('IN_ADR_BATTLE', true);
define('IN_ADR_SHOPS', true);
define('IN_ADR_VAULT', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$loc = 'character';
$sub_loc = 'adr_character';
//
// Start session management
$userdata = session_pagestart($user_ip, PAGE_ADR);
init_userprefs($userdata);
// End session management
//
include($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx);
// Sorry , only logged users ...
if ( !$userdata['session_logged_in'] )
{
$redirect = "adr_character.$phpEx";
$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}
// Includes the tpl and the header
adr_template_file('adr_character_body.tpl');
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
// Who is looking at this page ?
$user_id = $userdata['user_id'];
if ( (!( isset($_POST[POST_USERS_URL]) || isset($_GET[POST_USERS_URL]))) || ( empty($_POST[POST_USERS_URL]) && empty($_GET[POST_USERS_URL])))
{
$view_userdata = $userdata;
}
else
{
$view_userdata = get_userdata(intval($_GET[POST_USERS_URL]));
}
$searchid = $view_userdata['user_id'];
$points = $userdata['user_points'];
$posts = $userdata['user_posts'];
// Let's define some actions
$Level_up = isset($_POST['level_up']);
$carac_up = intval($_POST['carac_up']);
$Step2 = isset($_POST['Step2']);
$Step4 = isset($_POST['Step4']);
$bio_edit = isset($_POST['bio_edit']);
$upgrade_bio = isset($_POST['upgrade_bio']);
$delete = isset($_POST['delete']);
$monsters = isset($_POST['battle_monsters']);
$players = isset($_POST['battle_players']);
$delete_confirm = isset($_POST['delete_confirm']);
if ( intval($_GET['list']))
{
if ( intval($_GET['list']) == '2' )
{
$players = TRUE;
}
else
{
$monsters = TRUE;
}
}
// Get the general settings
$adr_general = adr_get_general_config();
adr_enable_check();
adr_ban_check($user_id);
// See if the user has ever created a character or no
$row = adr_get_user_infos($searchid);
$current_name = $row['character_name'];
// If someone is looking at a character's user that doesn't exist , let's display an error message
if ( !( $row['character_class'] ) && ($searchid != $user_id) )
{
message_die(GENERAL_MESSAGE, $lang['Adr_character_lack']);
}
// Sounds strange , but this prevents characters without class if the user leaves the page while creating a character
if ( is_numeric($row['character_race']) && !$row['character_class'] && $searchid == $user_id )
{
$Step3 = TRUE;
}
// The user has no character yet
if ( (!(is_numeric($row['character_race'])) && $searchid == $user_id ) || $Step3 )
{
// Does character meet minimum post count for character creation
if ( $adr_general['posts_enable'] && $posts < $adr_general['posts_min'] )
{
adr_previous ( Adr_posts , 'index' , '' );
}
if ($Step2)
{
$sql = "SELECT character_id FROM " . ADR_CHARACTERS_TABLE ."
WHERE character_id = $user_id";
if(!$result = $db->sql_query($sql)){
message_die(GENERAL_MESSAGE, 'Error getting character info', '', __LINE__, __FILE__, $sql);}
$character_twice = $db->sql_fetchrow($result);
if ( $character_twice != ''){
adr_previous( Adr_character_twice , adr_character, '');
}else{
$bio = trim($_POST['bio']);
$name = $_POST['name'];
$race = intval($_POST['race']);
$element = intval($_POST['element']);
$alignment = intval($_POST['alignment']);
$reuse_char = unexploit_user_characteristics($userdata['user_id']);
$details = explode('%SPLIT%', $reuse_char);
$power = $details[0];
$agility = $details[1];
$endurance = $details[2];
$intelligence = $details[3];
$willpower = $details[4];
$charm = $details[5];
$magic_attack = $details[6];
$magic_resistance = $details[7];
delete_unexploited_characteristics($userdata['user_id']);
##=== START character checks
// Empty name check
if(!$name){
adr_previous(Fields_empty, adr_character, '');}
// Same name character check
$sql = "SELECT character_id FROM " . ADR_CHARACTERS_TABLE ."
WHERE character_name = '" . str_replace("\'", "''", $name) . "'";
if(!$result = $db->sql_query($sql)){
message_die(CRITICAL_ERROR, 'Error checking for duplicate character name');}
$name_check = $db->sql_fetchrow($result);
if(is_numeric($name_check['character_id'])){
adr_previous(Adr_character_same_name_creation, adr_character, '');}
// Same username. It can be there own but no one elses
$sql = "SELECT user_id FROM " . USERS_TABLE . "
WHERE username = '" . str_replace("\'", "''", $name) . "'
AND user_id != '$user_id'";
if(!$result = $db->sql_query($sql)){
message_die(CRITICAL_ERROR, 'Error checking for duplicate user names');}
$username_check = $db->sql_fetchrow($result);
if(is_numeric($username_check['user_id'])){
adr_previous(Adr_user_same_name_creation, adr_character, '');}
##=== END character checks
$sql = "SELECT * FROM " . ADR_RACES_TABLE ." r , " . ADR_ELEMENTS_TABLE ." e , " . ADR_ALIGNMENTS_TABLE ." a
WHERE r.race_id = $race
AND e.element_id = $element
AND a.alignment_id = $alignment ";
if (!$result = $db->sql_query($sql))
{
message_die(CRITICAL_ERROR, 'Error Getting ADR Config!');
}
$infos = $db->sql_fetchrow($result);
$power = $power + ( $infos['race_might_bonus'] - $infos['race_might_malus'] );
$agility = $agility + ( $infos['race_dexterity_bonus'] - $infos['race_dexterity_malus'] );
$endurance = $endurance + ( $infos['race_constitution_bonus'] - $infos['race_constitution_malus'] );
$intelligence = $intelligence + ( $infos['race_intelligence_bonus'] - $infos['race_intelligence_malus'] );
$willpower = $willpower + ( $infos['race_wisdom_bonus'] - $infos['race_wisdom_malus'] );
$charm = $charm + ( $infos['race_charisma_bonus'] - $infos['race_charisma_malus'] );
$magic_attack = $magic_attack + ( $infos['race_magic_attack_bonus'] - $infos['race_magic_attack_malus'] );
$magic_resistance = $magic_resistance + ( $infos['race_magic_resistance_bonus'] - $infos['race_magic_resistance_malus'] );
$mining = 1 + ( $infos['race_skill_mining_bonus'] + $infos['element_skill_mining_bonus'] );
$stone = 1 + ( $infos['race_skill_stone_bonus'] + $infos['element_skill_stone_bonus'] );
$forge = 1 + ( $infos['race_skill_forge_bonus'] + $infos['element_skill_forge_bonus'] );
$enchantment = 1 + ( $infos['race_skill_enchantment_bonus'] + $infos['element_skill_enchantment_bonus'] );
$trading = 1 + ( $infos['race_skill_trading_bonus'] + $infos['element_skill_trading_bonus'] );
$thief = 1 + ( $infos['race_skill_thief_bonus'] + $infos['element_skill_thief_bonus'] );
$current_time = time();
$sql = "INSERT INTO " . ADR_CHARACTERS_TABLE ."
( character_id , character_name , character_desc , character_race , character_element , character_alignment , character_might , character_dexterity , character_constitution , character_intelligence , character_wisdom ,character_charisma, character_skill_mining , character_skill_stone , character_skill_forge , character_skill_enchantment , character_skill_trading , character_skill_thief , character_birth, character_battle_limit, character_skill_limit, character_trading_limit, character_thief_limit )
VALUES ( $user_id , '" . str_replace("\'", "''", $name ) . "' , '" . str_replace("\'", "''", $bio) . "' , $race , $element , $alignment , $power , $agility , $endurance , $intelligence , $willpower , $charm, $mining , $stone , $forge , $enchantment , $trading , $thief , $current_time, ".$adr_general['Adr_character_battle_limit'].", ".$adr_general['Adr_character_skill_limit'].", ".$adr_general['Adr_character_trading_limit'].", ".$adr_general['Adr_character_thief_limit']." ) ";
if (!$result = $db->sql_query($sql)) {
message_die(GENERAL_ERROR, 'Could not insert new character into database', '', __LINE__, __FILE__, $sql);}
adr_update_posters_infos();
}
$Step3 = TRUE ;
}
else if ($Step4)
{
$class_id = intval($_POST['class']);
if ( !$class_id )
{
adr_previous( Adr_character_must_select_class , adr_character , '' );
}
$sql = "SELECT * FROM " . ADR_CLASSES_TABLE ."
WHERE class_id = $class_id ";
if (!$result = $db->sql_query($sql))
{
message_die(CRITICAL_ERROR, 'Error Getting ADR Config!');
}
$class = $db->sql_fetchrow($result);
$sql = "UPDATE " . ADR_CHARACTERS_TABLE ."
SET character_class = $class_id ,
character_hp = ".$class['class_base_hp'].",
character_hp_max = ".$class['class_base_hp'].",
character_mp = ".$class['class_base_mp'].",
character_mp_max = ".$class['class_base_mp'].",
character_ac = ".$class['class_base_ac']."
WHERE character_id = $user_id ";
if (!$result = $db->sql_query($sql))
{
message_die(CRITICAL_ERROR, 'Error Getting ADR Config!');
}
adr_update_posters_infos();
adr_previous( Adr_character_success , adr_character , '' );
}
if ($Step3)
{
$template->assign_block_vars( 'nocharacterclass' , array());
if ( $userdata['user_level'] == ADMIN )
{
$sql_level = '';
}
else if ( $userdata['user_level'] == MOD )
{
$sql_level = ' AND c.class_level <> 1';
}
else
{
$sql_level = 'AND c.class_level = 0';
}
$sql = "SELECT c.* FROM " . ADR_CLASSES_TABLE ." c , " . ADR_CHARACTERS_TABLE ." u
WHERE c.class_might_req < u.character_might
$sql_level
AND c.class_dexterity_req <= u.character_dexterity
AND c.class_constitution_req <= u.character_constitution
AND c.class_intelligence_req <= u.character_intelligence
AND c.class_wisdom_req <= u.character_wisdom
AND c.class_charisma_req <= u.character_charisma
AND c.class_selectable = 1
AND u.character_id = $user_id ";
if (!$result = $db->sql_query($sql))
{
message_die(CRITICAL_ERROR, 'Error Getting ADR Config!');
}
$class = $db->sql_fetchrowset($result);
if ( !count($class) )
{
$sql = "DELETE FROM " . ADR_CHARACTERS_TABLE . "
WHERE character_id = $user_id";
if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not delete user from user pets table', '', __LINE__, __FILE__, $sql);
}
adr_previous( Adr_character_impossible , adr_character , '' );
}
for ( $i = 0 ; $i < count($class) ; $i ++)
{
$template->assign_block_vars('nocharacterclass.classes' , array(
"CLASS_NAME" => adr_get_lang($class[$i]['class_name']),
"CLASS_DESC" => adr_get_lang($class[$i]['class_desc']),
"CLASS_IMG" => $class[$i]['class_img'],
"CLASS_ID" => $class[$i]['class_id'],
"BASE_HP" => $class[$i]['class_base_hp'],
"BASE_MP" => $class[$i]['class_base_mp'],
"BASE_AC" => $class[$i]['class_base_ac'],
"UPDATE_XP_REQ" => $class[$i]['class_update_xp_req'],
"UPDATE_HP" => $class[$i]['class_update_hp'],
"UPDATE_MP" => $class[$i]['class_update_mp'],
"UPDATE_AC" => $class[$i]['class_update_ac'],
));
}
$template->assign_vars(array(
"L_BASE_HP" => $lang['Adr_classes_base_hp'],
"L_BASE_MP" => $lang['Adr_classes_base_mp'],
"L_BASE_AC" => $lang['Adr_classes_base_ac'],
"L_UPDATE_HP" => $lang['Adr_classes_update_hp'],
"L_UPDATE_MP" => $lang['Adr_classes_update_mp'],
"L_UPDATE_AC" => $lang['Adr_classes_update_ac'],
"L_NEW_CHARACTER_CLASS_DESC" => $lang['Adr_races_desc'],
"L_NEW_CHARACTER_CLASS_CHOOSE" => $lang['Select'],
));
}
else
{
$template->assign_block_vars( 'nocharacter' , array());
if ( $adr_general['allow_reroll'] )
{
$template->assign_block_vars( 'nocharacter.reroll' , array());
}
// Prepare the level check for races , elements and alignments
if ( $userdata['user_level'] == ADMIN )
{
$sql_race_level = '';
$sql_element_level = '';
$sql_alignment_level = '';
}
else if ( $userdata['user_level'] == MOD )
{
$sql_race_level = 'WHERE race_level <> 1';
$sql_element_level = 'WHERE element_level <> 1';
$sql_alignment_level = 'WHERE alignment_level <> 1';
}
else
{
$sql_race_level = 'WHERE race_level = 0';
$sql_element_level = 'WHERE element_level = 0';
$sql_alignment_level = 'WHERE alignment_level = 0';
}
// Build the lists
$sql = "SELECT * FROM " . ADR_RACES_TABLE . "
$sql_race_level ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain races information', "", __LINE__, __FILE__, $sql);
}
$races = $db->sql_fetchrowset($result);
$races_list = '<select name="race" tabindex="4">';
for($i = 0; $i < count($races); $i++)
{
$races[$i]['race_name'] = adr_get_lang($races[$i]['race_name']);
$previous_race = ( isset($_POST['race']) ) ? intval($_POST['race']) : 1;
$race_selected = ( $previous_race == $races[$i]['race_id'] ) ? 'selected' : '';
$races_list .= '<option value = "'.$races[$i]['race_id'].'" '.$race_selected.' >' . $races[$i]['race_name'] . '</option>';
}
$races_list .= '</select>';
$sql = "SELECT * FROM " . ADR_ELEMENTS_TABLE . "
$sql_element_level ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain elements information', "", __LINE__, __FILE__, $sql);
}
$elements = $db->sql_fetchrowset($result);
$elements_list = '<select name="element" tabindex="5">';
for($i = 0; $i < count($elements); $i++)
{
$elements[$i]['element_name'] = adr_get_lang($elements[$i]['element_name']);
$previous_element = ( isset($_POST['element']) ) ? intval($_POST['element']) : 1;
$element_selected = ( $previous_element == $elements[$i]['element_id'] ) ? 'selected' : '';
$elements_list .= '<option value = "'.$elements[$i]['element_id'].'" '.$element_selected.' >' . $elements[$i]['element_name'] . '</option>';
}
$elements_list .= '</select>';
$sql = "SELECT * FROM " . ADR_ALIGNMENTS_TABLE . "
$sql_alignment_level ";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain alignments information', "", __LINE__, __FILE__, $sql);
}
$alignments = $db->sql_fetchrowset($result);
$alignments_list = '<select name="alignment" tabindex="6">';
for($i = 0; $i < count($alignments); $i++)
{
$alignments[$i]['alignment_name'] = adr_get_lang($alignments[$i]['alignment_name']);
$previous_alignment = ( isset($_POST['alignment']) ) ? intval($_POST['alignment']) : 1;
$alignment_selected = ( $previous_alignment == $alignments[$i]['alignment_id'] ) ? 'selected' : '';
$alignments_list .= '<option value = "'.$alignments[$i]['alignment_id'].'" '.$alignment_selected.' >' . $alignments[$i]['alignment_name'] . '</option>';
}
$alignments_list .= '</select>';
if ( $_POST['power'] && !$adr_general['allow_reroll'] )
{
$reuse_char = unexploit_user_characteristics($userdata['user_id']);
$details = explode('%SPLIT%', $reuse_char);
$power = $details[0];
$agility = $details[1];
$endurance = $details[2];
$intelligence = $details[3];
$willpower = $details[4];
$charm = $details[5];
$magic_attack = $details[6];
$magic_resistance = $details[7];
}
else
{
if ($adr_general['allow_reroll'])
{
$allow = 1;
}
else
{
$allow = '';
}
set_unexploited_characteristics($userdata['user_id'], $adr_general['min_characteristic'], $adr_general['max_characteristic'], $allow);
$reuse_char = unexploit_user_characteristics($userdata['user_id']);
$details = explode('%SPLIT%', $reuse_char);
$power = $details[0];
$agility = $details[1];
$endurance = $details[2];
$intelligence = $details[3];
$willpower = $details[4];
$charm = $details[5];
$magic_attack = $details[6];
$magic_resistance = $details[7];
}
$s_hidden_fields .= '<input type="hidden" name="race" value="' . $race . '" />';
$s_hidden_fields .= '<input type="hidden" name="element" value="' . $element . '" />';
$s_hidden_fields .= '<input type="hidden" name="alignment" value="' . $alignment . '" />';
$s_hidden_fields .= '<input type="hidden" name="name" value="' . $name . '" />';
$s_hidden_fields .= '<input type="hidden" name="bio" value="' . $bio . '" />';
$template->assign_vars(array(
'L_NEW_CHARACTER' => $lang['Adr_character_new'],
'L_NEW_CHARACTER_NAME' => $lang['Adr_character_new_name'],
'L_CHARACTERISTICS' => $lang['Adr_character_characteristics'],
'L_POWER' => $lang['Adr_character_power'],
'L_AGILITY' => $lang['Adr_character_agility'],
'L_ENDURANCE' => $lang['Adr_character_endurance'],
'L_INTELLIGENCE' => $lang['Adr_character_intelligence'],
'L_WILLPOWER' => $lang['Adr_character_willpower'],
'L_CHARM' => $lang['Adr_character_charm'],
'L_MA' => $lang['Adr_character_ma'],
'L_MD' => $lang['Adr_character_md'],
'L_REROLL' => $lang['Adr_character_reroll'],
'L_RACES_SELECT' => $lang['Adr_character_races_select'],
'L_ELEMENTS_SELECT' => $lang['Adr_character_elements_select'],
'L_ALIGNMENTS_SELECT' => $lang['Adr_character_alignments_select'],
'L_RACES_MINI_FAQ' => $lang['Adr_character_races_mini_faq'],
'L_ELEMENTS_MINI_FAQ' => $lang['Adr_character_elements_mini_faq'],
'L_ALIGNMENTS_MINI_FAQ' => $lang['Adr_character_alignments_mini_faq'],
'L_NEW_CHARACTER_BIOGRAPHY' => $lang['Adr_character_new_bio'],
'L_NEW_CHARACTER_BIOGRAPHY_EXPLAIN' => $lang['Adr_character_new_bio_explain'],
'BIO' => ( !empty($_POST['bio']) ) ? htmlspecialchars(stripslashes(trim(str_replace('<br />', "\n", $_POST['bio'] ) ))) : '',
'NAME' => ( !empty($_POST['name']) ) ? htmlspecialchars(stripslashes($_POST['name'])) : '',
'RACES_LIST' => $races_list,
'ELEMENTS_LIST' => $elements_list,
'ALIGNMENTS_LIST' => $alignments_list,
'POWER' => $power,
'AGILITY' => $agility,
'ENDURANCE' => $endurance,
'INTELLIGENCE' => $intelligence,
'WILLPOWER' => $willpower,
'CHARM' => $charm,
'MA' => $magic_attack,
'MD' => $magic_resistance,
'MAX' => $adr_general['max_characteristic'],
'S_HIDDEN_FIELDS' => $s_hidden_fields,
));
}
}
// He even has a character
else
{
if ( $players )
{
adr_template_file('adr_character_battle_body.tpl');
$start = ( isset($_GET['start']) ) ? intval($_GET['start']) : 0;
if ( isset($_GET['mode2']) || isset($_POST['mode2']) )
{
$mode2 = ( isset($_POST['mode2']) ) ? htmlspecialchars($_POST['mode2']) : htmlspecialchars($_GET['mode2']);
}
else
{
$mode2 = 'default';
}
if(isset($_POST['order']))
{
$sort_order = ($_POST['order'] == 'ASC') ? 'ASC' : 'DESC';
}
else if(isset($_GET['order']))
{
$sort_order = ($_GET['order'] == 'ASC') ? 'ASC' : 'DESC';
}
else
{
$sort_order = 'ASC';
}
$mode_types_text = array( $lang['Adr_pvp_result'] , $lang['Adr_pvp_player_name'] , $lang['Adr_pvp_player_level'] );
$mode_types = array( 'result' , 'name', 'level' );
$select_sort_mode = '<select name="mode2">';
for($i = 0; $i < count($mode_types_text); $i++)
{
$selected = ( $mode2 == $mode_types[$i] ) ? ' selected="selected"' : '';
$select_sort_mode .= '<option value="' . $mode_types[$i] . '"' . $selected . '>' . $mode_types_text[$i] . '</option>';
}
$select_sort_mode .= '</select>';
$select_sort_order = '<select name="order">';
if($sort_order == 'ASC')
{
$select_sort_order .= '<option value="ASC" selected="selected">' . $lang['Sort_Ascending'] . '</option><option value="DESC">' . $lang['Sort_Descending'] . '</option>';
}
else
{
$select_sort_order .= '<option value="ASC">' . $lang['Sort_Ascending'] . '</option><option value="DESC" selected="selected">' . $lang['Sort_Descending'] . '</option>';
}
$select_sort_order .= '</select>';
switch( $mode2 )
{
case 'result':
$order_by = "b.battle_result $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
case 'name':
$order_by = "c.character_name $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
case 'level':
$order_by = "c.character_level $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
default:
$order_by = "b.battle_id $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
}
// Strange request isn't it ?
$sql = "SELECT b.* , c.character_name , c.character_level FROM " . ADR_BATTLE_PVP_TABLE . " b
LEFT JOIN " . ADR_CHARACTERS_TABLE . " c ON ( ( b.battle_challenger_id = c.character_id AND b.battle_challenger_id <> $searchid ) OR ( b.battle_opponent_id = c.character_id AND b.battle_opponent_id <> $searchid ) )
WHERE b.battle_result <> 0
AND b.battle_result <> 3
AND ( b.battle_opponent_id = $searchid OR b.battle_challenger_id = $searchid )
ORDER BY $order_by ";
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Error Getting Adr Users!');
}
if ( $row = $db->sql_fetchrow($result) )
{
$i = 0;
do
{
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
if ( ( ($row['battle_result'] == 1) && ($row['battle_challenger_id'] == $searchid) ) || ( ($row['battle_result'] == 2) && ($row['battle_opponent_id'] == $searchid) ) )
{
$battle_result = sprintf( $lang['Adr_pvp_victory_current'] , $current_name);
}
else if ( ( ($row['battle_result'] == 1) && ($row['battle_opponent_id'] == $searchid) ) || ( ($row['battle_result'] == 2) && ($row['battle_challenger_id'] == $searchid) ) )
{
$battle_result = sprintf( $lang['Adr_pvp_victory_current'] , $row['character_name']);
}
else if ( ( ($row['battle_result'] == 5) && ($row['battle_challenger_id'] == $searchid) ) || ( ($row['battle_result'] == 6) && ($row['battle_opponent_id'] == $searchid) ) )
{
$battle_result = sprintf( $lang['Adr_pvp_stopped_current'] , $row['character_name']);
}
else if ( ( ($row['battle_result'] == 5) && ($row['battle_opponent_id'] == $searchid) ) || ( ($row['battle_result'] == 6) && ($row['battle_challenger_id'] == $searchid) ) )
{
$battle_result = sprintf( $lang['Adr_pvp_stopped_current'] , $current_name);
}
else if ( ( ($row['battle_result'] == 8) && ($row['battle_challenger_id'] == $searchid) ) || ( ($row['battle_result'] == 9) && ($row['battle_opponent_id'] == $searchid) ) )
{
$battle_result = sprintf( $lang['Adr_pvp_flee_current'] , $current_name);
}
else if ( ( ($row['battle_result'] == 8) && ($row['battle_opponent_id'] == $searchid) ) || ( ($row['battle_result'] == 9) && ($row['battle_challenger_id'] == $searchid) ) )
{
$battle_result = sprintf( $lang['Adr_pvp_flee_current'] , $row['character_name']);
}
$template->assign_block_vars('battle', array(
"ROW_CLASS" => $row_class,
"RESULT" => $battle_result ,
"MONSTER_NAME" => adr_get_lang($row['character_name']),
"MONSTER_LEVEL" => $row['character_level'],
));
$i++;
}
while ( $row = $db->sql_fetchrow($result) );
}
$sql = "SELECT count(*) AS total FROM " . ADR_BATTLE_PVP_TABLE . "
WHERE battle_result <> 0
AND battle_result <> 3
AND ( battle_opponent_id = $searchid OR battle_challenger_id = $searchid )";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error getting total users', '', __LINE__, __FILE__, $sql);
}
if ( $total = $db->sql_fetchrow($result) )
{
$total_battle = $total['total'];
$pagination = generate_pagination("adr_character.$phpEx?".POST_USERS_URL."=$searchid&mode2=$mode2&order=$sort_order&list=2", $total_battle , $board_config['topics_per_page'], $start). ' ';
}
$template->assign_vars(array(
'L_MONSTER_NAME' => $lang['Adr_pvp_player_name'],
'L_MONSTER_LEVEL' => $lang['Adr_pvp_player_level'],
'L_RESULT' => $lang['Adr_battle_result'],
'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
'L_ORDER' => $lang['Order'],
'L_SORT' => $lang['Sort'],
'L_SUBMIT' => $lang['Sort'],
'S_MODE_SELECT' => $select_sort_mode,
'S_ORDER_SELECT' => $select_sort_order,
'PAGINATION' => $pagination,
'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $total_battle / $board_config['topics_per_page'] )),
'L_GOTO_PAGE' => $lang['Goto_page'],
"S_BATTLE_ACTION" => append_sid("adr_character.$phpEx?".POST_USERS_URL."=$searchid&mode2=$mode2&order=$sort_order&list=2"),
));
}
if ( $monsters )
{
adr_template_file('adr_character_battle_body.tpl');
$start = ( isset($_GET['start']) ) ? intval($_GET['start']) : 0;
if ( isset($_GET['mode2']) || isset($_POST['mode2']) )
{
$mode2 = ( isset($_POST['mode2']) ) ? htmlspecialchars($_POST['mode2']) : htmlspecialchars($_GET['mode2']);
}
else
{
$mode2 = 'default';
}
if(isset($_POST['order']))
{
$sort_order = ($_POST['order'] == 'ASC') ? 'ASC' : 'DESC';
}
else if(isset($_GET['order']))
{
$sort_order = ($_GET['order'] == 'ASC') ? 'ASC' : 'DESC';
}
else
{
$sort_order = 'ASC';
}
$mode_types_text = array( $lang['Adr_battle_result'] , $lang['Adr_battle_monster_name'] , $lang['Adr_battle_monster_level'] );
$mode_types = array( 'result' , 'name', 'level' );
$select_sort_mode = '<select name="mode2">';
for($i = 0; $i < count($mode_types_text); $i++)
{
$selected = ( $mode2 == $mode_types[$i] ) ? ' selected="selected"' : '';
$select_sort_mode .= '<option value="' . $mode_types[$i] . '"' . $selected . '>' . $mode_types_text[$i] . '</option>';
}
$select_sort_mode .= '</select>';
$select_sort_order = '<select name="order">';
if($sort_order == 'ASC')
{
$select_sort_order .= '<option value="ASC" selected="selected">' . $lang['Sort_Ascending'] . '</option><option value="DESC">' . $lang['Sort_Descending'] . '</option>';
}
else
{
$select_sort_order .= '<option value="ASC">' . $lang['Sort_Ascending'] . '</option><option value="DESC" selected="selected">' . $lang['Sort_Descending'] . '</option>';
}
$select_sort_order .= '</select>';
switch( $mode2 )
{
case 'result':
$order_by = "b.battle_result $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
case 'name':
$order_by = "m.monster_name $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
case 'level':
$order_by = "m.monster_level $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
default:
$order_by = "b.battle_id $sort_order LIMIT $start, " . $board_config['topics_per_page'];
break;
}
$sql = "SELECT b.battle_result , m.monster_name , m.monster_level FROM " . ADR_BATTLE_LIST_TABLE . " b
LEFT JOIN " . ADR_BATTLE_MONSTERS_TABLE . " m ON ( b.battle_opponent_id = m.monster_id )
WHERE b.battle_type = 1
AND b.battle_challenger_id = $searchid
ORDER BY $order_by ";
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Error Getting Adr Users!');
}
if ( $row = $db->sql_fetchrow($result) )
{
$i = 0;
do
{
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
if ( $row['battle_result'] == 1 )
{
$battle_result = $lang['Adr_battle_result_victory'];
}
else if ( $row['battle_result'] == 2 )
{
$battle_result = $lang['Adr_battle_result_defeat'];
}
elseif ( $row['battle_result'] == 3 )
{
$battle_result = $lang['Adr_battle_result_flee'];
}
else
{
$battle_result = $lang['Adr_battle_result_double_ko'];
}
$template->assign_block_vars('battle', array(
"ROW_CLASS" => $row_class,
"RESULT" => $battle_result ,
"MONSTER_NAME" => adr_get_lang($row['monster_name']),
"MONSTER_LEVEL" => $row['monster_level'],
));
$i++;
}
while ( $row = $db->sql_fetchrow($result) );
}
$sql = "SELECT count(*) AS total FROM " . ADR_BATTLE_LIST_TABLE . "
WHERE battle_challenger_id = $searchid
AND battle_type = 1 ";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error getting total users', '', __LINE__, __FILE__, $sql);
}
if ( $total = $db->sql_fetchrow($result) )
{
$total_battle = $total['total'];
$pagination = generate_pagination("adr_character.$phpEx?".POST_USERS_URL."=$searchid&mode2=$mode2&order=$sort_order&list=1", $total_battle , $board_config['topics_per_page'], $start). ' ';
}
$template->assign_vars(array(
'L_MONSTER_NAME' => $lang['Adr_battle_monster_name'],
'L_MONSTER_LEVEL' => $lang['Adr_battle_monster_level'],
'L_RESULT' => $lang['Adr_battle_result'],
'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
'L_ORDER' => $lang['Order'],
'L_SORT' => $lang['Sort'],
'L_SUBMIT' => $lang['Sort'],
'S_MODE_SELECT' => $select_sort_mode,
'S_ORDER_SELECT' => $select_sort_order,
'PAGINATION' => $pagination,
'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $total_battle / $board_config['topics_per_page'] )),
'L_GOTO_PAGE' => $lang['Goto_page'],
"S_BATTLE_ACTION" => append_sid("adr_character.$phpEx?".POST_USERS_URL."=$searchid&mode2=$mode2&order=$sort_order&list=1"),
));
}
$template->assign_block_vars( 'character' , array());
if ( $user_id == $searchid )
{
$template->assign_block_vars( 'character.owner' , array());
// Check if the user can gain a level
if ( adr_seek_levelup($user_id) )
{
$template->assign_block_vars( 'character_level_up' , array());
if ( $Level_up )
{
$carac[1]='character_might';
$carac[2]='character_dexterity';
$carac[3]='character_constitution';
$carac[4]='character_intelligence';
$carac[5]='character_wisdom';
$carac[6]='character_charisma';
$sql = "UPDATE " . ADR_CHARACTERS_TABLE . "
SET $carac[$carac_up] = $carac[$carac_up] + 1
WHERE character_id = $user_id ";
if (!($result = $db->sql_query($sql) ))
{
message_die(GENERAL_ERROR, 'Could not update user experience',"", __LINE__, __FILE__, $sql);
}
adr_level_up($user_id , character_page );
}
}
// Check if the user can delete his character
if ( $adr_general['allow_character_delete'] )
{
$template->assign_block_vars( 'character.owner.delete' , array());
}
if ( $delete )
{
adr_template_file('adr_confirm_body.tpl');
$template->assign_block_vars('delete_character' , array());
$template->assign_vars(array(
'MESSAGE_TITLE' => $lang['Adr_items_sell_confirm'],
'MESSAGE_TEXT' => $lang['Adr_character_delete_confirm'],
'L_YES' => $lang['Yes'],
'L_NO' => $lang['No'],
));
}
else if ( $delete_confirm )
{
// Active loan check
$sql = "SELECT loan_time FROM " . ADR_VAULT_USERS_TABLE . "
WHERE owner_id = $user_id ";
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Error Getting Vault Users!');
}
$loan_check = $db->sql_fetchrow($result);
if ( $loan_check['loan_time'] <= 0 )
{
$sql = " DELETE FROM " . ADR_CHARACTERS_TABLE . "
WHERE character_id = $user_id ";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Cannot delete this user', '', __LINE__, __FILE__, $sql);
}
$sql = " DELETE FROM " . ADR_BATTLE_LIST_TABLE . "
WHERE battle_challenger_id = $user_id
AND battle_type = 1 ";
if (!$db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Cannot delete this user', '', __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . ADR_SHOPS_TABLE ."
WHERE shop_owner_id = $user_id ";
if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not delete shop', "", __LINE__, __FILE__, $sql);
}
adr_update_posters_infos();
adr_previous( Adr_character_successful_deleted , adr_character , '' );
}
else
{
adr_previous( Adr_character_active_loan , adr_character , '' );
}
}
else if ( $bio_edit )
{
adr_template_file('adr_character_edit_body.tpl');
$message = $row['character_desc'];
$message = str_replace('<', '<', $message);
$message = str_replace('>', '>', $message);
$message = str_replace('<br />', "\n", $message);
$template->assign_vars(array(
'L_SUBMIT' => $lang['Submit'],
'L_NEW_CHARACTER_BIOGRAPHY' => $lang['Adr_character_new_bio'],
'L_NEW_CHARACTER_BIOGRAPHY_EXPLAIN' => $lang['Adr_character_new_bio_explain'],
'NEW_BIO' => $message,
));
}
else if ( $upgrade_bio )
{
$bio = $_POST['new_bio'];
$sql = "UPDATE " . ADR_CHARACTERS_TABLE . "
SET character_desc = '" . str_replace("\'", "''", $bio) . "'
WHERE character_id = $user_id ";
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Error updating bio informations !');
}
adr_previous( Adr_character_bio_updated , adr_character , '' );
}
// Check if quota limits are enabled
if ( $adr_general['Adr_character_limit_enable'] == 1 )
{
$template->assign_block_vars( 'character.limit' , array());
}
}
$avatar_img = '';
if ( $view_userdata['user_avatar_type'] && $view_userdata['user_allowavatar'] )
{
switch( $view_userdata['user_avatar_type'] )
{
case USER_AVATAR_UPLOAD:
$avatar_img = ( $board_config['allow_avatar_upload'] ) ? '<img src="' . $board_config['avatar_path'] . '/' . $view_userdata['user_avatar'] . '" alt="" border="0" />' : '';
break;
case USER_AVATAR_REMOTE:
$avatar_img = ( $board_config['allow_avatar_remote'] ) ? '<img src="' . $view_userdata['user_avatar'] . '" alt="" border="0" />' : '';
break;
case USER_AVATAR_GALLERY:
$avatar_img = ( $board_config['allow_avatar_local'] ) ? '<img src="' . $board_config['avatar_gallery_path'] . '/' . $view_userdata['user_avatar'] . '" alt="" border="0" />' : '';
break;
}
}
$sql = "SELECT c.* , r.race_name , r.race_weight , r.race_weight_per_level , r.race_img , e.element_name , e.element_img , a.alignment_name , a.alignment_img , cl.class_name , cl.class_img , cl.class_update_xp_req
FROM " . ADR_CHARACTERS_TABLE . " c , " . ADR_RACES_TABLE . " r , " . ADR_ELEMENTS_TABLE . " e , " . ADR_ALIGNMENTS_TABLE . " a , " . ADR_CLASSES_TABLE . " cl
WHERE c.character_id= $searchid
AND cl.class_id = c.character_class
AND r.race_id = c.character_race
AND e.element_id = c.character_element
AND a.alignment_id = c.character_alignment ";
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Error Getting Adr Users!');
}
$row = $db->sql_fetchrow($result);
if ( $row['character_desc'] )
{
$template->assign_block_vars( 'character.bio' , array());
}
$class = adr_get_lang($row['class_name']);
$race = adr_get_lang($row['race_name']);
$element = adr_get_lang($row['element_name']);
$alignment = adr_get_lang($row['alignment_name']);
// Work out weight stats
$max_weight = adr_weight_stats($row['character_level'], $row['race_weight'], $row['race_weight_per_level'], $row['character_might']);
// Count up characters current weight
$sql = "SELECT SUM(item_weight) AS total FROM " . ADR_SHOPS_ITEMS_TABLE . "
WHERE item_owner_id = $searchid
AND item_in_warehouse = 0
AND item_duration > 0
AND item_in_shop = 0";
if ( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, 'Error Getting Adr Users!');
}
$weight = $db->sql_fetchrow($result);
if ( $weight[total] != '' )
{
$current_weight = $weight[total];
}
else
{
$current_weight = 0;
}
//changed from max_hp to max_xp
$max_xp = $row['class_update_xp_req'];
for ( $p = 1 ; $p < $row['character_level'] ; $p ++ )
{
$max_xp = floor($max_xp * (( $adr_general['next_level_penalty'] + 100 ) / 100 ));
}
##=== Create bar widths ===##
list($hp_percent_width, $hp_percent_empty) = adr_make_bars($row['character_hp'], $row['character_hp_max'], '318');
list($mp_percent_width, $mp_percent_empty) = adr_make_bars($row['character_mp'], $row['character_mp_max'], '318');
list($exp_percent_width, $exp_percent_empty) = adr_make_bars($row['character_xp'], $max_xp, '318');
list($weight_percent_width, $weight_percent_empty) = adr_make_bars($current_weight, $max_weight, '318');
##=== Create bar widths ===##