forked from vendethiel/ezarena
/
adr_spell_cast.php
287 lines (236 loc) · 9.01 KB
/
adr_spell_cast.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
<?php
/***************************************************************************
*
* -------------------
* begin : 21/09/2004
* copyright :
*
*
***************************************************************************/
/***************************************************************************
*
* 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.
*
***************************************************************************/
// The following check must be at the start of all scripts to stop direct
// access to the script
//if ( !defined('IN_PHPBB') )
//{
// die("Hacking attempt");
//}
define('IN_PHPBB', true);
define('IN_ADR_SHOPS', true);
define('IN_ADR_CHARACTER', true);
define('IN_ADR_BATTLE', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
//
// Start session management
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
// End session management
//
include($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx);
include($phpbb_root_path . 'adr/includes/adr_constants.'.$phpEx);
$user_id = $userdata['user_id'];
// Includes the tpl and the header
adr_template_file('adr_spell_cast_body.tpl');
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
// General script config options
$adr_general = adr_get_general_config();
$adr_user = adr_get_user_infos($user_id);
adr_battle_cell_check($user_id, $userdata);
// Fix values
$cast_spell = $_POST['cast_upon'];
$to_member_id = $_POST['cast'];
$spell_id = $_GET['spell_id'];
// Check to see if spell can be cast on others
//$sql = "SELECT * FROM " . ADR_SHOPS_SPELLS_TABLE . "
// WHERE spell_owner_id = $user_id
// AND spell_id = $spell_id
// LIMIT 1";
//if( !($result = $db->sql_query($sql)) )
//{
// adr_previous( Adr_shop_items_failure_deleted , adr_spellbook , '');
//}
// Show user list
$sql = "SELECT u.user_id , u.username , c.* FROM " . USERS_TABLE . " u , " . ADR_CHARACTERS_TABLE . " c
WHERE u.user_id = c.character_id
AND c.character_hp < c.character_hp_max
AND c.character_hp > 0
ORDER by u.username ";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain user list', '', __LINE__, __FILE__, $sql);
}
$users = $db->sql_fetchrowset($result);
$chars_list = '<select name="cast">';
$chars_list .= '<option value = "0" >Select member:</option>';
for ( $i = 0 ; $i < count($users) ; $i ++)
{
$chars_list .= '<option value = "'.$users[$i]['user_id'].'" >' . $users[$i]['character_name'] . ' ( HP: ' . $users[$i]['character_hp'] . '/' . $users[$i]['character_hp_max'] . ' - MP: ' . $users[$i]['character_mp'] . '/' . $users[$i]['character_mp_max'] . ' - ' . $lang['Adr_character_level'] . ': ' . $users[$i]['character_level'] . ' ) </option>';
}
$chars_list .= '</select>';
if ( $cast_spell )
{
// Get other char info
$other_member = adr_get_user_infos($to_member_id);
// Get spell info
$sql = "SELECT * FROM " . ADR_SHOPS_SPELLS_TABLE . "
WHERE spell_owner_id = $user_id
AND spell_original_id = $spell_id
LIMIT 1";
if( !($result = $db->sql_query($sql)) )
{
adr_previous( Adr_shop_items_failure_deleted , adr_spellbook , '');
}
$item = $db->sql_fetchrow($result);
$spell_skill = $item['item_type_use'];
$power = 0;
// Spell components check
if (($item['spell_items_req'] !='') && ($item['spell_items_req'] !='0'))
{
adr_spell_check_components($spell_id, $user_id, 'adr_spellbook');
}
// MP check
if ( $adr_user['character_mp'] < ($item['spell_mp_use'] + $item['spell_power']) || $adr_user['character_mp'] < 0 )
{
adr_previous ( Adr_battle_check_two , 'adr_spellbook' , '' );
}
$power = (($item['spell_power'] * 1.2) + $item['spell_add_power']);
$mp_usage = ($item['spell_mp_use'] + $item['spell_power']);
if ( $mp_usage == '' )
{
adr_previous ( Adr_battle_check , 'adr_spellbook' , '' );
}
// Check if target is in combat
$sql = " SELECT * FROM " . ADR_BATTLE_LIST_TABLE . "
WHERE battle_challenger_id = $to_member_id
AND battle_result = 0
AND battle_type = 1 ";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
}
$bat = $db->sql_fetchrow($result);
if ( is_numeric($bat['battle_id']) )
{
adr_previous( Adr_spells_target_battle , adr_spellbook , '' );
}
// Check if other person is alive
if ( $other_member['character_hp'] < 1 )
{
adr_previous( Adr_spells_target_dead , adr_spellbook , '' );
}
// Check if target is in the same zone
// if($adr_user['character_area'] != $other_member['character_area'])
// {
// adr_previous( Adr_spells_wrong_place, adr_spellbook , '');
// }
// Subtract the magic points
spell_remove_mp( $user_id , $mp_usage , 0 );
// Use the item
adr_use_item($spell_id , $user_id);
// Healing spell
if($spell_skill == '108')
{
$attbonus = 0;
$attbonus = adr_weapon_skill_check($user_id);
$power = ceil($power * $attbonus);
if($code = $item['spell_xtreme'])
{
eval($code);
message_die ( GENERAL_MESSAGE , $message );
}
else
{
// Check if other person is already at full health
if ( $other_member['character_hp'] >= $other_member['character_hp_max'] )
{
adr_previous( Adr_spells_target_health_full , adr_spellbook , '' );
}
// Check if other user goes over max_hp with spell
$hp_heal = (( $power + $other_member['character_hp']) > $other_member['character_hp_max']) ? $other_member['character_hp_max'] - $other_member['character_hp'] : $power ;
// Restore HP
spell_add_hp_to_member( $to_member_id , $hp_heal , 0 );
if ($adr_general['spell_enable_pm'] == '1')
{
// Notify other user of heal
$subject = $lang['Adr_spells_heal_pm_title'];
$message = sprintf($lang['Adr_spells_heal_pm_text'] , $adr_user['character_name'] , $hp_heal);
if($to_member_id != $user_id)
{
adr_send_pm ( $to_member_id , $subject , $message );
}
}
$direction = append_sid("adr_spellbook.$phpEx");
$message = sprintf($lang['Adr_spells_heal_cast'], $item['spell_name'], $other_member['character_name'], $hp_heal);
$message .= '<br /><br />'.sprintf($lang['Adr_return'],"<a href=\"" . $direction . "\">", "</a>") ;
message_die ( GENERAL_MESSAGE , $message );
}
}
// Defensive spell
else if($spell_skill == '109')
{
$attbonus = 0;
$attbonus = adr_weapon_skill_check($user_id);
$power = ceil($power * $attbonus);
if($code = $item['spell_xtreme'])
{
eval($code);
message_die (GENERAL_MESSAGE, $message);
}
else
{
if ($other_member['character_spell_pre_effects'] == '' || $other_member['character_spell_pre_effects'] == NULL || $other_member['character_spell_pre_effects'] == '0')
{
// Define standard effects
$effects ="ATT:$power:DEF:$power";
$sql = "UPDATE " . ADR_CHARACTERS_TABLE ."
SET character_spell_pre_effects = '$effects'
WHERE character_id = $to_member_id ";
if (!$result = $db->sql_query($sql))
message_die(CRITICAL_ERROR, 'Error updating ADR character spell pre-effects!');
if ($adr_general['spell_enable_pm'] == '1')
{
// Notify other user
$subject = $lang['Adr_lang_cast_boost_pm_title'];
$message = sprintf($lang['Adr_lang_cast_boost_pm_text'], $adr_user['character_name'], $item['spell_name']);
if($to_member_id != $user_id)
{
adr_send_pm ( $to_member_id , $subject , $message );
}
}
$direction = append_sid("adr_spellbook.$phpEx");
$message = sprintf($lang['Adr_spells_cast_boost_success'], $item['spell_name'], $other_member['character_name']);
$message .= '<br /><br />'.sprintf($lang['Adr_return'],"<a href=\"" . $direction . "\">", "</a>") ;
message_die ( GENERAL_MESSAGE , $message );
}
else
{
$direction = append_sid("adr_spellbook.$phpEx");
$message = sprintf($lang['Adr_spells_cast_already'], $other_member['character_name']);
$message .= '<br /><br />'.sprintf($lang['Adr_return'],"<a href=\"" . $direction . "\">", "</a>") ;
message_die ( GENERAL_MESSAGE , $message );
}
}
}
}
else
{
$template->assign_vars(array(
'SELECT_CHARACTER' => $chars_list,
'L_SPELLS_MP' => sprintf($lang['Adr_spells_cast_mp'], $adr_user['character_mp']),
'L_SCRIPT_TITLE' => $lang['Adr_spells_target_select'],
'L_CAST_TYPE' => $lang['Adr_spells_cast'],
'S_CHARACTER_ACTION' => append_sid("adr_spell_cast.$phpEx?spell_id=$spell_id"),
));
}
include($phpbb_root_path . 'adr/includes/adr_header.'.$phpEx);
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>