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.
88 lines
3.4 KiB
PHP
88 lines
3.4 KiB
PHP
<?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"]
|
|
],
|
|
[
|
|
"items.itemid",
|
|
"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 = new Player($user);
|
|
|
|
switch ($item["classname"]) {
|
|
case "healmagic":
|
|
if ($player->energy->getEnergy() < $player->energy->getMaxEnergy()) {
|
|
$diff = ($player->energy->getEnergy() + $item["itemcode"]["amount"]) < $player->energy->getMaxEnergy() ? $item["itemcode"]["amount"] : ($player->energy->getMaxEnergy() - $player->energy->getEnergy());
|
|
|
|
$player->changeEnergy($item["itemcode"]["amount"]);
|
|
|
|
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]);
|
|
}
|
|
$player->save();
|
|
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"])) {
|
|
sendJsonResp($Strings->get("You can't use that right now.", false));
|
|
}
|
|
|
|
$place = new Place($VARS["placeid"]);
|
|
if ($place->isClaimed() && $place->getTeamID() == $player->getTeamID()) {
|
|
$place->addArtifact(Artifact::create($player->getUID(), $place->getLocationID(), new Energy($item["itemcode"]["amount"], $item["itemcode"]["amount"]), $item["itemid"]));
|
|
$place->save();
|
|
$player->addExp();
|
|
$player->save();
|
|
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->get("Artifact activated.", false));
|
|
}
|
|
|
|
sendJsonResp($Strings->get("You can't use that right now.", false));
|
|
break;
|
|
default:
|
|
sendJsonResp($Strings->get("You can't use that right now.", false));
|
|
} |