-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathartifacts.php
More file actions
115 lines (94 loc) · 3.42 KB
/
artifacts.php
File metadata and controls
115 lines (94 loc) · 3.42 KB
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
<?php
/**
* artifacts.php
* Artifact actions
*
* @package roleplay
* @version 1.0
*
* Revision History
* ================
* 1.0 copyright (c) 2011 by Gorlum for http://supernova.ws
*
*/
use DBAL\db_mysql;
use Unit\DBStaticUnit;
global $lang, $user, $planetrow;
include('common.' . substr(strrchr(__FILE__, '.'), 1));
lng_include('infos');
lng_include('artifacts');
include('includes/includes/art_artifact.php');
$sn_group_artifacts = sn_get_groups('artifacts');
/**
* @param $user
* @param $unit_id
* @param $planetrow
* @param $lang
*
* @return string
*/
function art_buy($user, $unit_id, $planetrow, $lang) {
$Message = '';
db_mysql::db_transaction_start();
$user = db_user_by_id($user['id'], true);
$artifact_level = mrc_get_level($user, array(), $unit_id, true);
$build_data = eco_get_build_data($user, $planetrow, $unit_id, $artifact_level, true);
$darkmater_cost = $build_data[BUILD_CREATE][RES_DARK_MATTER];
// TODO: more correct check - with "FOR UPDATE"
if (mrc_get_level($user, null, RES_DARK_MATTER) >= $darkmater_cost) {
$unit_max_stack = get_unit_param($unit_id, P_MAX_STACK);
if (!isset($unit_max_stack) || $unit_max_stack > mrc_get_level($user, $planetrow, $unit_id)) {
if (!DBStaticUnit::dbUserAdd($user['id'], $unit_id, 1)) {
$Message = '{Ошибка записи в БД}';
} else {
rpg_points_change($user['id'], RPG_ARTIFACT, -($darkmater_cost), "Spent for artifact {$lang['tech'][$unit_id]} ID {$unit_id}");
db_mysql::db_transaction_commit();
sys_redirect("artifacts.php#{$unit_id}");
}
} else {
$Message = $lang['off_maxed_out'];
}
} else {
$Message = $lang['sys_no_points'];
}
db_mysql::db_transaction_rollback();
return $Message;
}
if (($action = sys_get_param_int('action')) && in_array($unit_id = sys_get_param_int('unit_id'), $sn_group_artifacts)) {
$Message = '';
switch ($action) {
case ACTION_BUY:
$Message = art_buy($user, $unit_id, $planetrow, $lang);
break;
case ACTION_USE:
art_use($user, $planetrow, $unit_id);
sys_redirect("artifacts.php#{$unit_id}");
break;
}
SnTemplate::messageBox($Message, $lang['tech'][UNIT_ARTIFACTS], 'artifacts.' . PHP_EX, 5);
}
$user = db_user_by_id($user['id'], true);
$template = SnTemplate::gettemplate('artifacts', true);
foreach ($sn_group_artifacts as $artifact_id) {
$artifact_level = mrc_get_level($user, [], $artifact_id, true);
$build_data = eco_get_build_data($user, $planetrow, $artifact_id, $artifact_level);
$artifact_data = get_unit_param($artifact_id);
$artifact_data_bonus = SnTemplate::tpl_render_unit_bonus_data($artifact_data);
$template->assign_block_vars('artifact', array(
'ID' => $artifact_id,
'NAME' => $lang['tech'][$artifact_id],
'DESCRIPTION' => $lang['info'][$artifact_id]['description'],
'EFFECT' => $lang['info'][$artifact_id]['effect'],
'COST' => $build_data[BUILD_CREATE][RES_DARK_MATTER],
'LEVEL' => intval($artifact_level),
'LEVEL_MAX' => intval($artifact_data['max']),
'BONUS' => $artifact_data_bonus,
'BONUS_TYPE' => $artifact_data[P_BONUS_TYPE],
'CAN_BUY' => $build_data['CAN'][BUILD_CREATE],
));
}
$template->assign_vars(array(
'PAGE_HEADER' => $lang['tech'][UNIT_ARTIFACTS],
'PAGE_HINT' => $lang['art_page_hint'],
));
SnTemplate::display($template, $lang['tech'][UNIT_ARTIFACTS]);