|
|
|
@ -19,6 +19,7 @@ $item = $database->get(
|
|
|
|
|
"[>]itemclasses" => ["classid" => "classid"]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
"items.itemid",
|
|
|
|
|
"inventory.itemjson",
|
|
|
|
|
"items.classid",
|
|
|
|
|
"itemclasses.classname",
|
|
|
|
@ -39,38 +40,48 @@ if (empty($item['itemjson']) || $item['itemjson'] == "[]") {
|
|
|
|
|
$itemjson = json_decode($item["itemjson"], true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$player = $database->get("players", ["energy", "maxenergy", "teamid"], ["accountid" => $user->getUID()]);
|
|
|
|
|
$player = new Player($user);
|
|
|
|
|
|
|
|
|
|
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 ($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"]) || !$database->has("locations", ["AND" => ["osmid" => $VARS["placeid"], "teamid" => $player["teamid"]]])) {
|
|
|
|
|
if (empty($VARS["placeid"])) {
|
|
|
|
|
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."));
|
|
|
|
|
|
|
|
|
|
$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));
|
|
|
|
|