insert("artifacts", ["currentlife" => $energy->getEnergy(), "maxlife" => $energy->getMaxEnergy(), "locationid" => $locationid, "accountid" => $ownerid, "itemid" => $itemid]); return (new Artifact($database->id())); } public function __construct($uuid) { global $database; $data = $database->get("artifacts", ["artuuid", "currentlife", "maxlife", "locationid"], ["artuuid" => $uuid]); $this->uuid = $data["artuuid"]; $this->energy = new Energy($data["currentlife"], $data["maxlife"]); $this->locationid = $data["locationid"]; } public function changeEnergy(int $diff) { $this->energy->setEnergy($this->energy->getEnergy() + $diff); } public function getEnergy(): \Energy { return $this->energy; } /** * Check if the artifact will be deleted on save. * @return bool */ public function deleted(): bool { if ($this->energy->getEnergy() == 0 || $this->delete) { return true; } return false; } /** * Mark for deletion on save. */ public function delete() { $this->delete = true; } public function save() { global $database; if ($this->deleted()) { $database->delete("artifacts", ["artuuid" => $this->uuid]); } else { $database->update("artifacts", ["currentlife" => $this->energy->getEnergy(), "maxlife" => $this->energy->getMaxEnergy()], ["artuuid" => $this->uuid]); } } }