Add ability to add artifacts to places in useitem
This commit is contained in:
parent
2dcaaed09b
commit
4cea9d1098
@ -19,6 +19,7 @@ $item = $database->get(
|
|||||||
"[>]itemclasses" => ["classid" => "classid"]
|
"[>]itemclasses" => ["classid" => "classid"]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
"items.itemid",
|
||||||
"inventory.itemjson",
|
"inventory.itemjson",
|
||||||
"items.classid",
|
"items.classid",
|
||||||
"itemclasses.classname",
|
"itemclasses.classname",
|
||||||
@ -39,38 +40,48 @@ if (empty($item['itemjson']) || $item['itemjson'] == "[]") {
|
|||||||
$itemjson = json_decode($item["itemjson"], true);
|
$itemjson = json_decode($item["itemjson"], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$player = $database->get("players", ["energy", "maxenergy", "teamid"], ["accountid" => $user->getUID()]);
|
$player = new Player($user);
|
||||||
|
|
||||||
switch ($item["classname"]) {
|
switch ($item["classname"]) {
|
||||||
case "healmagic":
|
case "healmagic":
|
||||||
if ($player["energy"] < $player["maxenergy"]) {
|
if ($player->energy->getEnergy() < $player->energy->getMaxEnergy()) {
|
||||||
$newhp = $player["energy"] + $item["itemcode"]["amount"];
|
$diff = ($player->energy->getEnergy() + $item["itemcode"]["amount"]) < $player->energy->getMaxEnergy() ? $item["itemcode"]["amount"] : ($player->energy->getMaxEnergy() - $player->energy->getEnergy());
|
||||||
if ($newhp > $player["maxenergy"]) {
|
|
||||||
$newhp = $player["maxenergy"];
|
$player->changeEnergy($item["itemcode"]["amount"]);
|
||||||
}
|
|
||||||
$diff = $newhp - $player["energy"];
|
|
||||||
$database->update("players", ["energy" => $newhp], ["accountid" => $user->getUID()]);
|
|
||||||
if ($itemjson["uses"] <= 1) {
|
if ($itemjson["uses"] <= 1) {
|
||||||
$database->delete("inventory", ["AND" => ["itemuuid" => $itemuuid, "accountid" => $user->getUID()]]);
|
$database->delete("inventory", ["AND" => ["itemuuid" => $itemuuid, "accountid" => $user->getUID()]]);
|
||||||
} else if ($itemjson["uses"] > 1) {
|
} else if ($itemjson["uses"] > 1) {
|
||||||
$itemjson["uses"] -= 1;
|
$itemjson["uses"] -= 1;
|
||||||
$database->update("inventory", ["itemjson" => json_encode($itemjson)], ["itemuuid" => $itemuuid]);
|
$database->update("inventory", ["itemjson" => json_encode($itemjson)], ["itemuuid" => $itemuuid]);
|
||||||
}
|
}
|
||||||
|
$player->save();
|
||||||
sendJsonResp($Strings->build("Restored {x} energy points.", ["x" => $diff], false));
|
sendJsonResp($Strings->build("Restored {x} energy points.", ["x" => $diff], false));
|
||||||
} else {
|
} else {
|
||||||
sendJsonResp($Strings->get("That would have no effect.", false));
|
sendJsonResp($Strings->get("That would have no effect.", false));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "artifact":
|
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));
|
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"];
|
$place = new Place($VARS["placeid"]);
|
||||||
$placemax = $place["maxlife"] + $item["itemcode"]["amount"];
|
if ($place->isClaimed() && $place->getTeamID() == $player->getTeamID()) {
|
||||||
$database->update("locations", ["currentlife" => $placelife, "maxlife" => $placemax], ["osmid" => $VARS["placeid"]]);
|
$place->addArtifact(Artifact::create($player->getUID(), $place->getLocationID(), new Energy($item["itemcode"]["amount"], $item["itemcode"]["amount"]), $item["itemid"]));
|
||||||
// TODO: give user some exp
|
$place->save();
|
||||||
sendJsonResp($Strings->get("Artifact activated."));
|
$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;
|
break;
|
||||||
default:
|
default:
|
||||||
sendJsonResp($Strings->get("You can't use that right now.", false));
|
sendJsonResp($Strings->get("You can't use that right now.", false));
|
||||||
|
@ -20,6 +20,7 @@ class Place {
|
|||||||
* @var bool If this place exists in the game DB
|
* @var bool If this place exists in the game DB
|
||||||
*/
|
*/
|
||||||
private $gameexists = false;
|
private $gameexists = false;
|
||||||
|
private $locationid = null;
|
||||||
private $teamid = null;
|
private $teamid = null;
|
||||||
private $ownerid = null;
|
private $ownerid = null;
|
||||||
private $osmid = null;
|
private $osmid = null;
|
||||||
@ -41,6 +42,7 @@ class Place {
|
|||||||
if ($database->has("locations", ["osmid" => $osmid])) {
|
if ($database->has("locations", ["osmid" => $osmid])) {
|
||||||
$game = $database->get("locations", ["locationid", "teamid", "ownerid", "osmid", "currentlife", "maxlife", "data", "lastactivity"], ["osmid" => $osmid]);
|
$game = $database->get("locations", ["locationid", "teamid", "ownerid", "osmid", "currentlife", "maxlife", "data", "lastactivity"], ["osmid" => $osmid]);
|
||||||
|
|
||||||
|
$this->locationid = $game["locationid"];
|
||||||
$this->teamid = $game["teamid"];
|
$this->teamid = $game["teamid"];
|
||||||
$this->ownerid = $game["ownerid"];
|
$this->ownerid = $game["ownerid"];
|
||||||
$this->energy->setMaxEnergy($game["maxlife"]);
|
$this->energy->setMaxEnergy($game["maxlife"]);
|
||||||
@ -87,6 +89,10 @@ class Place {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function exists(): bool {
|
||||||
|
return $this->gameexists;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this place is claimed by a player/team.
|
* Check if this place is claimed by a player/team.
|
||||||
* @return bool
|
* @return bool
|
||||||
@ -118,6 +124,10 @@ class Place {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLocationID(): int {
|
||||||
|
return $this->locationid;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTeamID(): int {
|
public function getTeamID(): int {
|
||||||
return $this->teamid;
|
return $this->teamid;
|
||||||
}
|
}
|
||||||
@ -157,6 +167,10 @@ class Place {
|
|||||||
return $this->artifacts;
|
return $this->artifacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addArtifact(\Artifact $artifact) {
|
||||||
|
$this->artifacts[] = $artifact;
|
||||||
|
}
|
||||||
|
|
||||||
public function doAttack(int $damage) {
|
public function doAttack(int $damage) {
|
||||||
$artifact = false;
|
$artifact = false;
|
||||||
foreach ($this->artifacts as $art) {
|
foreach ($this->artifacts as $art) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user