1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * artifacts.php |
||||
5 | * Artifact actions |
||||
6 | * |
||||
7 | * @package roleplay |
||||
8 | * @version 1.0 |
||||
9 | * |
||||
10 | * Revision History |
||||
11 | * ================ |
||||
12 | * 1.0 copyright (c) 2011 by Gorlum for http://supernova.ws |
||||
13 | * |
||||
14 | */ |
||||
15 | |||||
16 | |||||
17 | use Unit\DBStaticUnit; |
||||
18 | |||||
19 | global $lang, $user, $planetrow; |
||||
20 | |||||
21 | include('common.' . substr(strrchr(__FILE__, '.'), 1)); |
||||
22 | |||||
23 | lng_include('infos'); |
||||
24 | lng_include('artifacts'); |
||||
25 | |||||
26 | include('includes/includes/art_artifact.php'); |
||||
27 | |||||
28 | $sn_group_artifacts = sn_get_groups('artifacts'); |
||||
29 | |||||
30 | /** |
||||
31 | * @param $user |
||||
32 | * @param $unit_id |
||||
33 | * @param $planetrow |
||||
34 | * @param $lang |
||||
35 | * |
||||
36 | * @return string |
||||
37 | */ |
||||
38 | function art_buy($user, $unit_id, $planetrow, $lang) { |
||||
39 | $Message = ''; |
||||
40 | sn_db_transaction_start(); |
||||
41 | |||||
42 | $user = db_user_by_id($user['id'], true); |
||||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||||
43 | $artifact_level = mrc_get_level($user, array(), $unit_id, true); |
||||
44 | |||||
45 | $build_data = eco_get_build_data($user, $planetrow, $unit_id, $artifact_level, true); |
||||
46 | $darkmater_cost = $build_data[BUILD_CREATE][RES_DARK_MATTER]; |
||||
47 | |||||
48 | // TODO: more correct check - with "FOR UPDATE" |
||||
49 | if (mrc_get_level($user, null, RES_DARK_MATTER) >= $darkmater_cost) { |
||||
50 | $unit_max_stack = get_unit_param($unit_id, P_MAX_STACK); |
||||
51 | if (!isset($unit_max_stack) || $unit_max_stack > mrc_get_level($user, $planetrow, $unit_id)) { |
||||
52 | if (!DBStaticUnit::dbUserAdd($user['id'], $unit_id, 1)) { |
||||
53 | $Message = '{Ошибка записи в БД}'; |
||||
54 | } else { |
||||
55 | rpg_points_change($user['id'], RPG_ARTIFACT, -($darkmater_cost), "Spent for artifact {$lang['tech'][$unit_id]} ID {$unit_id}"); |
||||
56 | sn_db_transaction_commit(); |
||||
57 | sys_redirect("artifacts.php#{$unit_id}"); |
||||
58 | } |
||||
59 | } else { |
||||
60 | $Message = $lang['off_maxed_out']; |
||||
61 | } |
||||
62 | } else { |
||||
63 | $Message = $lang['sys_no_points']; |
||||
64 | } |
||||
65 | sn_db_transaction_rollback(); |
||||
66 | |||||
67 | return $Message; |
||||
68 | } |
||||
69 | |||||
70 | if (($action = sys_get_param_int('action')) && in_array($unit_id = sys_get_param_int('unit_id'), $sn_group_artifacts)) { |
||||
71 | $Message = ''; |
||||
72 | switch ($action) { |
||||
73 | case ACTION_BUY: |
||||
74 | $Message = art_buy($user, $unit_id, $planetrow, $lang); |
||||
75 | break; |
||||
76 | |||||
77 | case ACTION_USE: |
||||
78 | art_use($user, $planetrow, $unit_id); |
||||
79 | sys_redirect("artifacts.php#{$unit_id}"); |
||||
80 | break; |
||||
81 | } |
||||
82 | SnTemplate::messageBox($Message, $lang['tech'][UNIT_ARTIFACTS], 'artifacts.' . PHP_EX, 5); |
||||
83 | } |
||||
84 | |||||
85 | $user = db_user_by_id($user['id'], true); |
||||
0 ignored issues
–
show
The function
db_user_by_id() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
86 | |||||
87 | $template = SnTemplate::gettemplate('artifacts', true); |
||||
0 ignored issues
–
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
88 | |||||
89 | foreach ($sn_group_artifacts as $artifact_id) { |
||||
90 | $artifact_level = mrc_get_level($user, [], $artifact_id, true); |
||||
91 | $build_data = eco_get_build_data($user, $planetrow, $artifact_id, $artifact_level); |
||||
92 | $artifact_data = get_unit_param($artifact_id); |
||||
93 | $artifact_data_bonus = SnTemplate::tpl_render_unit_bonus_data($artifact_data); |
||||
94 | |||||
95 | $template->assign_block_vars('artifact', array( |
||||
96 | 'ID' => $artifact_id, |
||||
97 | 'NAME' => $lang['tech'][$artifact_id], |
||||
98 | 'DESCRIPTION' => $lang['info'][$artifact_id]['description'], |
||||
99 | 'EFFECT' => $lang['info'][$artifact_id]['effect'], |
||||
100 | 'COST' => $build_data[BUILD_CREATE][RES_DARK_MATTER], |
||||
101 | 'LEVEL' => intval($artifact_level), |
||||
102 | 'LEVEL_MAX' => intval($artifact_data['max']), |
||||
103 | 'BONUS' => $artifact_data_bonus, |
||||
104 | 'BONUS_TYPE' => $artifact_data[P_BONUS_TYPE], |
||||
105 | 'CAN_BUY' => $build_data['CAN'][BUILD_CREATE], |
||||
106 | )); |
||||
107 | } |
||||
108 | |||||
109 | $template->assign_vars(array( |
||||
110 | 'PAGE_HEADER' => $lang['tech'][UNIT_ARTIFACTS], |
||||
111 | 'PAGE_HINT' => $lang['art_page_hint'], |
||||
112 | )); |
||||
113 | |||||
114 | SnTemplate::display($template, $lang['tech'][UNIT_ARTIFACTS]); |
||||
115 |