-
Notifications
You must be signed in to change notification settings - Fork 3
/
adr_research.php
340 lines (293 loc) · 11 KB
/
adr_research.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
<?php
/***************************************************************************
* adr_research.php
* ------------------------
* begin : 01/07/2007
* copyright : egdcltd (http://games.directorygold.com)
*
*
***************************************************************************/
/***************************************************************************
*
* 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_LIBRARY', true);
define('IN_ADR_CHARACTER', true);
define('IN_ADR_SHOPS', true);
define('IN_ADR_CRAFTING', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$loc = 'skills';
$sub_loc = 'adr_research';
//
// Start session management
$userdata = session_pagestart($user_ip, PAGE_ADR);
init_userprefs($userdata);
// End session management
//
$user_id = $userdata['user_id'];
$points = $userdata['user_points'];
include($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx);
// Sorry , only logged users ...
if ( !$userdata['session_logged_in'] )
{
$redirect = "adr_research.$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_research_body.tpl');
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
// Get the general config
$adr_general = adr_get_general_config();
adr_enable_check();
adr_ban_check($user_id);
adr_character_created_check($user_id);
$adr_user = adr_get_user_infos($user_id);
$actual_zone = $adr_user['character_area'];
$sql = " SELECT * FROM " . ADR_ZONES_TABLE . "
WHERE zone_id = $actual_zone ";
if( !($result = $db->sql_query($sql)) )
message_die(GENERAL_ERROR, 'Could not query area list', '', __LINE__, __FILE__, $sql);
$info = $db->sql_fetchrow($result);
$access = $info['zone_research'];
if ( $access == '0' )
adr_previous( 'Adr_zone_building_noaccess' , 'adr_zones' , '' );
// Get Zone infos
$area_id = $adr_user['character_area'];
if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
{
$mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
$mode = htmlspecialchars($mode);
}
else
{
$mode = "";
}
if ( $mode != "" )
{
switch($mode)
{
case 'library_action' :
//Cost for using library
adr_substract_points($user_id, 100,'', 'adr_research');
//Research success calculation
$rand = rand(1,20);
//Critical failure
if($rand == '1')
{
$book_false = true;
}
else
{
$book_false = false;
$research = ($rand + adr_modifier_calc($adr_user['character_intelligence']));
if($research >= '150') $book_difficulty = '7';
elseif(($research >= '100') && ($research < '150'))$book_difficulty = '6';
elseif(($research >= '75') && ($research < '100'))$book_difficulty = '5';
elseif(($research >= '45') && ($research < '75'))$book_difficulty = '4';
elseif(($research >= '30') && ($research < '45'))$book_difficulty = '3';
elseif(($research >= '20') && ($research < '30'))$book_difficulty = '2';
elseif(($research >= '12') && ($research < '20'))$book_difficulty = '1';
elseif(($research >= '1') && ($research < '12'))$book_difficulty = '0';
}
if($book_false)
{
$sql = "SELECT *
FROM " . ADR_LIBRARY_TABLE ."
WHERE book_false = $book_false";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain book information', "", __LINE__, __FILE__, $sql);
}
$library = array();
while ( $row = $db->sql_fetchrow($result) )
{
// Loop through all rows:
if ( $row['book_zone'] != '0' )
{
// Check to see if the area id is in the book zone
$book_zone = explode(",", $row['book_zone']); // Create our array
$success = in_array($area_id, $book_zone); // Check our array
}
else
{
$success = true;
}
if ( $success )
{
// This row PASSES all checks so should be stored.
$library[] = $row;
}
}
}
else
{
$sql = "SELECT *
FROM " . ADR_LIBRARY_TABLE ."
WHERE book_difficulty <= $book_difficulty
AND book_false = '0'";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain book information', "", __LINE__, __FILE__, $sql);
}
$library = array();
while ( $row = $db->sql_fetchrow($result) )
{
// Loop through all rows:
if ( $row['book_zone'] != '0' )
{
// Check to see if the area id is in the book zone
$book_zone = explode(",", $row['book_zone']); // Create our array
$success = in_array($area_id, $book_zone); // Check our array
}
else
{
$success = true;
}
if ( $success )
{
// This row PASSES all checks so should be stored.
$library[] = $row;
}
}
}
if ( !$library )
{
adr_previous ( 'Adr_library_failure' , 'adr_research' , '' );
}
else
{
// Now roll for research
$rand_library = $library[array_rand($library, 1)];
$book_name = $rand_library['book_name'];
$book_details = $rand_library['book_details'];
$research_keep = intval($HTTP_POST_VARS['research_keep']);
$crafting_recipe = $rand_library['book_crafting'];
if($crafting_recipe)
{
//get now all info of the up-to-date recipe in the forums shop (id 1) (Admin might have changed or deleted it)
$sql_admin = "SELECT * FROM ". ADR_SHOPS_ITEMS_TABLE ."
WHERE item_owner_id = 1
AND item_id = " . $crafting_recipe;
$result_admin = $db->sql_query($sql_admin);
if( !($admin_recipe = $db->sql_fetchrow($result_admin)) )
{
//recipe deleted
}
else
{
//check if the user already has written the recipe into the recipebook
$sql_check_book = "SELECT * FROM ". ADR_RECIPEBOOK_TABLE ."
WHERE recipe_original_id = ".$admin_recipe['item_id']."
AND recipe_owner_id = $user_id
AND recipe_skill_id = ".$admin_recipe['item_recipe_skill_id']."
";
$result_check_book = $db->sql_query($sql_check_book);
if( $check_book = $db->sql_fetchrow($result_check_book) )
{
//recipe already known
}
else if (!($check_book = $db->sql_fetchrow($result_check_book)))
{
//get new recipe_id
$sql = "SELECT recipe_id FROM " . ADR_RECIPEBOOK_TABLE ."
WHERE recipe_skill_id = ".$admin_recipe['item_recipe_skill_id']."
ORDER BY recipe_id
DESC LIMIT 1";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, 'Could not obtain recipes total entrys', "", __LINE__, __FILE__, $sql);
}
$recipebook_data = $db->sql_fetchrow($result);
$new_recipe_id = $recipebook_data['recipe_id'] + 1;
//write recipe into the owners recipebook
$sql = "INSERT INTO " . ADR_RECIPEBOOK_TABLE . "
( recipe_id , recipe_owner_id , recipe_level , recipe_linked_item , recipe_items_req , recipe_effect , recipe_original_id, recipe_skill_id)
VALUES ( $new_recipe_id , $user_id , '".$admin_recipe['item_power']."' , '".$admin_recipe['item_recipe_linked_item']."' , '".$admin_recipe['item_brewing_items_req']."', '".$admin_recipe['item_effect']."', '".$admin_recipe['item_original_recipe_id']."', '".$admin_recipe['item_recipe_skill_id']."')";
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, "Couldn't insert new recipe into the recipebook", "", __LINE__, __FILE__, $sql);
}
}
}
}
else
{
if ( $research_keep != 0 )
{
// Extra cost for keeping learned information
adr_substract_points($user_id, 1000, '', adr_research);
// Get learned infomation
$sql = "SELECT book_id FROM " . ADR_LIBRARY_LEARN_TABLE . "
WHERE user_id = $user_id
AND book_id = ".$rand_library['book_id'];
if( !($result = $db->sql_query($sql)) ){
message_die(GENERAL_ERROR, "Couldn't get learned information", "", __LINE__, __FILE__, $sql);}
$row_learn = $db->sql_fetchrow($result);
// Check to see if you already know this information
if ( $row_learn == '' )
{
$sql_learn = "INSERT INTO " . ADR_LIBRARY_LEARN_TABLE . "
(user_id, book_id, book_name, book_details)
VALUES ($user_id, ".$rand_library['book_id'].", '".$rand_library['book_name']."', '".$rand_library['book_details']."')";
if( !($result_learn = $db->sql_query($sql_learn)) ){
message_die(GENERAL_ERROR, "Couldn't insert learned information", "", __LINE__, __FILE__, $sql_learn);}
}
else
{
$sql_learn = "UPDATE " . ADR_LIBRARY_LEARN_TABLE . "
SET book_name = '".$rand_library['book_name']."',
book_details = '".$rand_library['book_details']."'
WHERE user_id = $user_id
AND book_id = ".$rand_library['book_id'];
if( !($result_learn = $db->sql_query($sql_learn)) ){
message_die(GENERAL_ERROR, "Couldn't insert learned information", "", __LINE__, __FILE__, $sql_learn);}
}
}
}
$direction = append_sid("adr_research.$phpEx");
$message = $lang['Adr_library_success_top'];
$message .= '<b>'.$book_name.'</b><br /><br /><div align="center">' . $book_details. '</div>';
$message .= $lang['Adr_library_success_bottom'];
$message .= sprintf($lang['Adr_return'],"<a href=\"" . $direction . "\">", "</a>");
message_die ( GENERAL_MESSAGE , $message );
}
break;
}
}
else
{
$template->assign_block_vars('research',array());
$template->assign_vars(array(
'L_PERFORM_RESEARCH' => $lang['Adr_library_perform_research'],
'L_RESEARCH_EXPLAIN' => $lang['Adr_library_explain'],
));
}
$template->assign_vars(array(
'L_RESEARCH_TITLE' => $lang['Adr_library_title'],
'L_RESEARCH' => $lang['Adr_library_main'],
'L_RESEARCH_GO_TO' => $lang['Adr_library_go_to'],
'L_RESEARCH_EXPLAIN' => $lang['Adr_library_area_explain'],
'L_RESEARCH_HELPER' => $lang['Adr_library_helper'],
'L_RESEARCH_KEEP' => $lang['Adr_library_keep_info'],
'L_POINTS' => get_reward_name(),
'POINTS' => $points,
'U_RESEARCH' => append_sid("adr_research.$phpEx"),
'S_FORGE_ACTION'=> append_sid("adr_research.$phpEx"),
));
include($phpbb_root_path . 'adr/includes/adr_header.'.$phpEx);
$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>