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 DBAL\db_mysql; |
||||
18 | use Unit\DBStaticUnit; |
||||
19 | |||||
20 | global $lang, $user, $planetrow; |
||||
21 | |||||
22 | include('common.' . substr(strrchr(__FILE__, '.'), 1)); |
||||
23 | |||||
24 | lng_include('infos'); |
||||
25 | lng_include('artifacts'); |
||||
26 | |||||
27 | include('includes/includes/art_artifact.php'); |
||||
28 | |||||
29 | $sn_group_artifacts = sn_get_groups('artifacts'); |
||||
30 | |||||
31 | /** |
||||
32 | * @param $user |
||||
33 | * @param $unit_id |
||||
34 | * @param $planetrow |
||||
35 | * @param $lang |
||||
36 | * |
||||
37 | * @return string |
||||
38 | */ |
||||
39 | function art_buy($user, $unit_id, $planetrow, $lang) { |
||||
40 | $Message = ''; |
||||
41 | db_mysql::db_transaction_start(); |
||||
42 | |||||
43 | $user = db_user_by_id($user['id'], true); |
||||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||||
44 | $artifact_level = mrc_get_level($user, array(), $unit_id, true); |
||||
45 | |||||
46 | $build_data = eco_get_build_data($user, $planetrow, $unit_id, $artifact_level, true); |
||||
47 | $darkmater_cost = $build_data[BUILD_CREATE][RES_DARK_MATTER]; |
||||
48 | |||||
49 | // TODO: more correct check - with "FOR UPDATE" |
||||
50 | if (mrc_get_level($user, null, RES_DARK_MATTER) >= $darkmater_cost) { |
||||
51 | $unit_max_stack = get_unit_param($unit_id, P_MAX_STACK); |
||||
52 | if (!isset($unit_max_stack) || $unit_max_stack > mrc_get_level($user, $planetrow, $unit_id)) { |
||||
53 | if (!DBStaticUnit::dbUserAdd($user['id'], $unit_id, 1)) { |
||||
54 | $Message = '{Ошибка записи в БД}'; |
||||
55 | } else { |
||||
56 | rpg_points_change($user['id'], RPG_ARTIFACT, -($darkmater_cost), "Spent for artifact {$lang['tech'][$unit_id]} ID {$unit_id}"); |
||||
57 | db_mysql::db_transaction_commit(); |
||||
58 | sys_redirect("artifacts.php#{$unit_id}"); |
||||
59 | } |
||||
60 | } else { |
||||
61 | $Message = $lang['off_maxed_out']; |
||||
62 | } |
||||
63 | } else { |
||||
64 | $Message = $lang['sys_no_points']; |
||||
65 | } |
||||
66 | db_mysql::db_transaction_rollback(); |
||||
67 | |||||
68 | return $Message; |
||||
69 | } |
||||
70 | |||||
71 | if (($action = sys_get_param_int('action')) && in_array($unit_id = sys_get_param_int('unit_id'), $sn_group_artifacts)) { |
||||
72 | $Message = ''; |
||||
73 | switch ($action) { |
||||
74 | case ACTION_BUY: |
||||
75 | $Message = art_buy($user, $unit_id, $planetrow, $lang); |
||||
76 | break; |
||||
77 | |||||
78 | case ACTION_USE: |
||||
79 | art_use($user, $planetrow, $unit_id); |
||||
80 | sys_redirect("artifacts.php#{$unit_id}"); |
||||
81 | break; |
||||
82 | } |
||||
83 | SnTemplate::messageBox($Message, $lang['tech'][UNIT_ARTIFACTS], 'artifacts.' . PHP_EX, 5); |
||||
84 | } |
||||
85 | |||||
86 | $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
![]() |
|||||
87 | |||||
88 | $template = SnTemplate::gettemplate('artifacts', true); |
||||
89 | |||||
90 | foreach ($sn_group_artifacts as $artifact_id) { |
||||
91 | $artifact_level = mrc_get_level($user, [], $artifact_id, true); |
||||
92 | $build_data = eco_get_build_data($user, $planetrow, $artifact_id, $artifact_level); |
||||
93 | $artifact_data = get_unit_param($artifact_id); |
||||
94 | $artifact_data_bonus = SnTemplate::tpl_render_unit_bonus_data($artifact_data); |
||||
95 | |||||
96 | $template->assign_block_vars('artifact', array( |
||||
97 | 'ID' => $artifact_id, |
||||
98 | 'NAME' => $lang['tech'][$artifact_id], |
||||
99 | 'DESCRIPTION' => $lang['info'][$artifact_id]['description'], |
||||
100 | 'EFFECT' => $lang['info'][$artifact_id]['effect'], |
||||
101 | 'COST' => $build_data[BUILD_CREATE][RES_DARK_MATTER], |
||||
102 | 'LEVEL' => intval($artifact_level), |
||||
103 | 'LEVEL_MAX' => intval($artifact_data['max']), |
||||
104 | 'BONUS' => $artifact_data_bonus, |
||||
105 | 'BONUS_TYPE' => $artifact_data[P_BONUS_TYPE], |
||||
106 | 'CAN_BUY' => $build_data['CAN'][BUILD_CREATE], |
||||
107 | )); |
||||
108 | } |
||||
109 | |||||
110 | $template->assign_vars(array( |
||||
111 | 'PAGE_HEADER' => $lang['tech'][UNIT_ARTIFACTS], |
||||
112 | 'PAGE_HINT' => $lang['art_page_hint'], |
||||
113 | )); |
||||
114 | |||||
115 | SnTemplate::display($template, $lang['tech'][UNIT_ARTIFACTS]); |
||||
116 |