forked from supernova-ws/SuperNova
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartifacts.php
118 lines (100 loc) · 3.54 KB
/
artifacts.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
<?php
/**
* artifacts.php
* Artifact actions
*
* @package roleplay
* @version 1.0
*
* Revision History
* ================
* 1.0 copyright (c) 2011 by Gorlum for http://supernova.ws
*
*/
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');
if(($action = sys_get_param_int('action')) && in_array($unit_id = sys_get_param_int('unit_id'), $sn_group_artifacts))
{
switch($action)
{
case ACTION_BUY:
sn_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))
{
$db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, 1, $user);
OldDbChangeSet::db_changeset_apply($db_changeset);
rpg_points_change($user['id'], RPG_ARTIFACT, -($darkmater_cost), "Spent for artifact {$lang['tech'][$unit_id]} ID {$unit_id}");
sn_db_transaction_commit();
sys_redirect("artifacts.php#{$unit_id}");
}
else
{
$Message = $lang['off_maxed_out'];
}
}
else
{
$Message = $lang['sys_no_points'];
}
sn_db_transaction_rollback();
break;
case ACTION_USE:
art_use($user, $planetrow, $unit_id);
sys_redirect("artifacts.php#{$unit_id}");
break;
}
messageBox($Message, $lang['tech'][UNIT_ARTIFACTS], 'artifacts.' . PHP_EX, 5);
}
$template = gettemplate('artifacts', true);
foreach($sn_group_artifacts as $artifact_id)
{
$artifact_level = mrc_get_level($user, array(), $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 = $artifact_data['bonus'];
$artifact_data_bonus = $artifact_data_bonus >= 0 ? "+{$artifact_data_bonus}" : "{$artifact_data_bonus}";
switch($artifact_data['bonus_type'])
{
case BONUS_PERCENT:
$artifact_data_bonus = "{$artifact_data_bonus}% ";
break;
case BONUS_ADD:
break;
case BONUS_ABILITY:
$artifact_data_bonus = '';
break;
default:
break;
}
$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],
'COST_TEXT' => pretty_number($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['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'],
));
display($template, $lang['tech'][UNIT_ARTIFACTS]);