These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | global $user, $planetrow; |
||
17 | |||
18 | use DBStatic\DBStaticUnit; |
||
19 | use DBStatic\DBStaticUser; |
||
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 | $Message = ''; |
||
31 | if (($action = sys_get_param_int('action')) && in_array($unit_id = sys_get_param_int('unit_id'), $sn_group_artifacts)) { |
||
32 | switch ($action) { |
||
33 | case ACTION_BUY: |
||
34 | sn_db_transaction_start(); |
||
35 | |||
36 | $user = DBStaticUser::db_user_by_id($user['id'], true); |
||
37 | $artifact_level = mrc_get_level($user, null, $unit_id, true); |
||
38 | |||
39 | $build_data = eco_get_build_data($user, $planetrow, $unit_id, $artifact_level, true); |
||
40 | $darkmater_cost = $build_data[BUILD_CREATE][RES_DARK_MATTER]; |
||
41 | |||
42 | // TODO: more correct check - with "FOR UPDATE" |
||
43 | if (mrc_get_level($user, null, RES_DARK_MATTER) >= $darkmater_cost) { |
||
44 | $unit_max_stack = get_unit_param($unit_id, P_MAX_STACK); |
||
45 | if (!isset($unit_max_stack) || $unit_max_stack > mrc_get_level($user, $planetrow, $unit_id)) { |
||
46 | |||
47 | $db_changeset['unit'][] = DBStaticUnit::dbUpdateOrInsertUnit($unit_id, 1, $user); |
||
48 | |||
49 | rpg_points_change($user['id'], RPG_ARTIFACT, -($darkmater_cost), |
||
50 | sprintf('Spent for artifact %1$s ID %2$d', classLocale::$lang['tech'][$unit_id], $unit_id) |
||
51 | ); |
||
52 | sn_db_transaction_commit(); |
||
53 | header("Location: artifacts.php#{$unit_id}"); |
||
54 | ob_end_flush(); |
||
55 | die(); |
||
56 | } else { |
||
57 | $Message = classLocale::$lang['off_maxed_out']; |
||
58 | } |
||
59 | } else { |
||
60 | $Message = classLocale::$lang['sys_no_points']; |
||
61 | } |
||
62 | sn_db_transaction_rollback(); |
||
63 | break; |
||
64 | |||
65 | case ACTION_USE: |
||
66 | art_use($user, $planetrow, $unit_id); |
||
67 | header("Location: artifacts.php#{$unit_id}"); |
||
68 | ob_end_flush(); |
||
69 | die(); |
||
70 | break; |
||
71 | } |
||
72 | message($Message, classLocale::$lang['tech'][UNIT_ARTIFACTS], 'artifacts' . DOT_PHP_EX, 5); |
||
73 | } |
||
74 | |||
75 | $template = gettemplate('artifacts', true); |
||
76 | |||
77 | foreach ($sn_group_artifacts as $artifact_id) { |
||
78 | $artifact_level = mrc_get_level($user, null, $artifact_id, true); |
||
79 | $build_data = eco_get_build_data($user, $planetrow, $artifact_id, $artifact_level); |
||
80 | { |
||
81 | $artifact_data = get_unit_param($artifact_id); |
||
82 | $artifact_data_bonus = $artifact_data['bonus']; |
||
83 | $artifact_data_bonus = $artifact_data_bonus >= 0 ? "+{$artifact_data_bonus}" : "{$artifact_data_bonus}"; |
||
84 | View Code Duplication | switch ($artifact_data['bonus_type']) { |
|
0 ignored issues
–
show
|
|||
85 | case BONUS_PERCENT: |
||
86 | $artifact_data_bonus = "{$artifact_data_bonus}% "; |
||
87 | break; |
||
88 | |||
89 | case BONUS_ADD: |
||
90 | break; |
||
91 | |||
92 | case BONUS_ABILITY: |
||
93 | $artifact_data_bonus = ''; |
||
94 | break; |
||
95 | |||
96 | default: |
||
97 | break; |
||
98 | } |
||
99 | |||
100 | $template->assign_block_vars('artifact', array( |
||
101 | 'ID' => $artifact_id, |
||
102 | 'NAME' => classLocale::$lang['tech'][$artifact_id], |
||
103 | 'DESCRIPTION' => classLocale::$lang['info'][$artifact_id]['description'], |
||
104 | 'EFFECT' => classLocale::$lang['info'][$artifact_id]['effect'], |
||
105 | 'COST' => $build_data[BUILD_CREATE][RES_DARK_MATTER], |
||
106 | 'COST_TEXT' => pretty_number($build_data[BUILD_CREATE][RES_DARK_MATTER]), |
||
107 | 'LEVEL' => intval($artifact_level), |
||
108 | 'LEVEL_MAX' => intval($artifact_data['max']), |
||
109 | 'BONUS' => $artifact_data_bonus, |
||
110 | 'BONUS_TYPE' => $artifact_data['bonus_type'], |
||
111 | 'CAN_BUY' => $build_data['CAN'][BUILD_CREATE], |
||
112 | )); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | $template->assign_vars(array( |
||
117 | 'PAGE_HEADER' => classLocale::$lang['tech'][UNIT_ARTIFACTS], |
||
118 | 'PAGE_HINT' => classLocale::$lang['art_page_hint'], |
||
119 | )); |
||
120 | |||
121 | display(parsetemplate($template), classLocale::$lang['tech'][UNIT_ARTIFACTS]); |
||
122 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.