-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathitemuse.php
113 lines (112 loc) · 3.68 KB
/
itemuse.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
<?php
declare(strict_types=1);
/**
* MCCodes v2 by Dabomstew & ColdBlooded
*
* Repository: https://github.com/davemacaulay/mccodesv2
* License: MIT License
*/
global $db, $ir, $userid, $h;
require_once('globals.php');
$_GET['ID'] =
(isset($_GET['ID']) && is_numeric($_GET['ID']))
? abs(intval($_GET['ID'])) : '';
if (!$_GET['ID'])
{
echo 'Invalid use of file';
}
else
{
$i =
$db->query(
"SELECT `effect1`, `effect2`, `effect3`,
`effect1_on`, `effect2_on`, `effect3_on`,
`itmname`, `inv_itemid`
FROM `inventory` AS `iv`
INNER JOIN `items` AS `i`
ON `iv`.`inv_itemid` = `i`.`itmid`
WHERE `iv`.`inv_id` = {$_GET['ID']}
AND `iv`.`inv_userid` = $userid");
if ($db->num_rows($i) == 0)
{
$db->free_result($i);
echo 'Invalid item ID';
}
else
{
$r = $db->fetch_row($i);
$db->free_result($i);
if (!$r['effect1_on'] && !$r['effect2_on'] && !$r['effect3_on'])
{
echo 'Sorry, this item cannot be used as it has no effect.';
$h->endpage();
exit;
}
for ($enum = 1; $enum <= 3; $enum++)
{
if ($r["effect{$enum}_on"])
{
$einfo = unserialize($r["effect{$enum}"]);
if ($einfo['inc_type'] == 'percent')
{
if (in_array($einfo['stat'],
['energy', 'will', 'brave', 'hp']))
{
$inc =
round(
$ir['max' . $einfo['stat']] / 100
* $einfo['inc_amount']);
}
else
{
$inc =
round(
$ir[$einfo['stat']] / 100
* $einfo['inc_amount']);
}
}
else
{
$inc = $einfo['inc_amount'];
}
if ($einfo['dir'] == 'pos')
{
if (in_array($einfo['stat'],
['energy', 'will', 'brave', 'hp']))
{
$ir[$einfo['stat']] =
min($ir[$einfo['stat']] + $inc,
$ir['max' . $einfo['stat']]);
}
else
{
$ir[$einfo['stat']] += $inc;
}
}
else
{
$ir[$einfo['stat']] = max($ir[$einfo['stat']] - $inc, 0);
}
$upd = $ir[$einfo['stat']];
if (in_array($einfo['stat'],
['strength', 'agility', 'guard', 'labour', 'IQ']))
{
$db->query(
"UPDATE `userstats`
SET `{$einfo['stat']}` = '{$upd}'
WHERE `userid` = {$userid}");
}
else
{
$db->query(
"UPDATE `users`
SET `{$einfo['stat']}` = '{$upd}'
WHERE `userid` = {$userid}");
}
}
}
echo $r['itmname'] . ' used successfully!';
item_remove($userid, (int)$r['inv_itemid'], 1);
}
}
$h->endpage();