You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
3.1 KiB
PHTML
77 lines
3.1 KiB
PHTML
5 years ago
|
<?php
|
||
|
|
||
|
/*
|
||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||
|
*/
|
||
|
|
||
|
$user = getRequestUser();
|
||
|
|
||
|
if (!$database->has("inventory", ["AND" => ["itemuuid" => $VARS["uuid"], "accountid" => $user->getUID()]])) {
|
||
|
sendJsonResp("That item doesn't exist.", "ERROR");
|
||
|
}
|
||
|
|
||
|
$item = $database->get(
|
||
|
"items",
|
||
|
[
|
||
|
"[>]inventory" => ["itemid" => "itemid"],
|
||
|
"[>]itemclasses" => ["classid" => "classid"]
|
||
|
],
|
||
|
[
|
||
|
"inventory.itemjson",
|
||
|
"items.classid",
|
||
|
"itemclasses.classname",
|
||
|
"items.itemcode"
|
||
|
],
|
||
|
[
|
||
|
"AND" => [
|
||
|
"inventory.itemuuid" => $VARS["uuid"],
|
||
|
"inventory.accountid" => $user->getUID()
|
||
|
]
|
||
|
]
|
||
|
);
|
||
|
$itemuuid = $VARS["uuid"];
|
||
|
$item['itemcode'] = json_decode($item['itemcode'], true);
|
||
|
if (empty($item['itemjson']) || $item['itemjson'] == "[]") {
|
||
|
$itemjson = json_encode(['uses' => $item['itemcode']['uses']]);
|
||
|
} else {
|
||
|
$itemjson = json_decode($item["itemjson"], true);
|
||
|
}
|
||
|
|
||
|
$player = $database->get("players", ["energy", "maxenergy", "teamid"], ["accountid" => $user->getUID()]);
|
||
|
|
||
|
switch ($item["classname"]) {
|
||
|
case "healmagic":
|
||
|
if ($player["energy"] < $player["maxenergy"]) {
|
||
|
$newhp = $player["energy"] + $item["itemcode"]["amount"];
|
||
|
if ($newhp > $player["maxenergy"]) {
|
||
|
$newhp = $player["maxenergy"];
|
||
|
}
|
||
|
$diff = $newhp - $player["energy"];
|
||
|
$database->update("players", ["energy" => $newhp], ["accountid" => $user->getUID()]);
|
||
|
if ($itemjson["uses"] <= 1) {
|
||
|
$database->delete("inventory", ["AND" => ["itemuuid" => $itemuuid, "accountid" => $user->getUID()]]);
|
||
|
} else if ($itemjson["uses"] > 1) {
|
||
|
$itemjson["uses"] -= 1;
|
||
|
$database->update("inventory", ["itemjson" => json_encode($itemjson)], ["itemuuid" => $itemuuid]);
|
||
|
}
|
||
|
sendJsonResp($Strings->build("Restored {x} energy points.", ["x" => $diff], false));
|
||
|
} else {
|
||
|
sendJsonResp($Strings->get("That would have no effect.", false));
|
||
|
}
|
||
|
break;
|
||
|
case "artifact":
|
||
|
if (empty($VARS["placeid"]) || !$database->has("locations", ["AND" => ["osmid" => $VARS["placeid"], "teamid" => $player["teamid"]]])) {
|
||
|
sendJsonResp($Strings->get("You can't use that right now.", false));
|
||
|
}
|
||
|
$place = $database->get("locations", ["locationid", "teamid", "ownerid", "currentlife", "maxlife"], ["locationid" => $VARS["placeid"]]);
|
||
|
$placelife = $place["currentlife"] + $item["itemcode"]["amount"];
|
||
|
$placemax = $place["maxlife"] + $item["itemcode"]["amount"];
|
||
|
$database->update("locations", ["currentlife" => $placelife, "maxlife" => $placemax], ["osmid" => $VARS["placeid"]]);
|
||
|
// TODO: give user some exp
|
||
|
sendJsonResp($Strings->get("Artifact activated."));
|
||
|
break;
|
||
|
default:
|
||
|
sendJsonResp($Strings->get("You can't use that right now.", false));
|
||
|
}
|