* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package SWDB */ require_once(PATH::ENTITY . "Entity.php"); /** * Artifact effect. * * Represents each of the up to 4 artifact effects (not the main stat). * * @category Entity */ class Artifact_Effect extends Entity{ /** * @var int The effect slot ({@see ARTIFACT_EFFECT_SLOT_ID}). */ private $slot; /** * @var int The effect ID. */ private $effect; /** * @var string The effect name. */ private $name; /** * @var float The value of the effect. */ private $value; /** * @var float The grinded value of the effect. */ private $grind; /** * @var bool Indicates if the effect has been enchanted. */ private $enchant; /** * Constructor. * * Retrieves the artifact effect information from the database. * * @param int $artifact Artifact id. * @param int $slot Artifact effect slot id. */ public function __construct($artifact, $slot){ $statement = get_context()->get_db()->prepare(" SELECT slot, effect, value, enchant, grind FROM artifact_effect WHERE artifact = :artifact AND slot = :slot; "); $statement->bindValue(':artifact', $artifact, SQLITE3_TEXT); $statement->bindValue(':slot', $slot, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->effect = $r["effect"]; $this->value = $r["value"]; $this->enchant = $r["enchant"]; $this->grind = $r["grind"]; $statement = get_context()->get_db()->prepare(" SELECT name FROM effect_artifact WHERE id = :id; "); $statement->bindValue(':id', $this->effect, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->name = str_replace("{}", $this->value, $r["name"]); } } else{ // Not found. Maybe as a run drop? $select = "effect_1 AS effect, effect_1_value AS value"; switch ($slot){ case ARTIFACT_EFFECT_SLOT_ID::EFFECT_1: $select = "effect_1 AS effect, effect_1_value AS value"; break; case ARTIFACT_EFFECT_SLOT_ID::EFFECT_2: $select = "effect_2 AS effect, effect_2_value AS value"; break; case ARTIFACT_EFFECT_SLOT_ID::EFFECT_3: $select = "effect_3 AS effect, effect_3_value AS value"; break; case ARTIFACT_EFFECT_SLOT_ID::EFFECT_4: $select = "effect_4 AS effect, effect_4_value AS value"; break; } $statement = get_context()->get_db()->prepare(" SELECT $select FROM run_drop_artifact WHERE id = :id "); $statement->bindValue(':id', $artifact, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->slot = $slot; $this->effect = $r["effect"]; $this->value = $r["value"]; $this->enchant = false; $this->grind = 0; $statement = get_context()->get_db()->prepare(" SELECT name FROM effect_artifact WHERE id = :id; "); $statement->bindValue(':id', $this->effect, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->name = str_replace("{}", $this->value, $r["name"]); } } } } /** * Retrieves the artifact effect's slot identifier. * * @see ARTIFACT_EFFECT_SLOT_ID * @return int Effect slot ID. */ public function get_slot(){ return $this->slot; } /** * Artifact effect identifier. * * @return int Effect ID. */ public function get_effect(){ return $this->effect; } /** * Retrieves the artifact effect name. * * @return string The effect name. */ public function get_name(){ return $this->name; } /** * Retrieves the value of the artifact effect, excluding grinds. * * @return float Effect value. */ public function get_value(){ return $this->value; } /** * Retrieves the grinded value on the effect. * * @return float Effect grinded value. */ public function get_grind(){ return $this->grind; } /** * Checks if the effect has been enchanted. * * @return bool True if the effect was enchanted, false otherwise */ public function is_enchanted(){ return filter_var($this->enchant, FILTER_VALIDATE_BOOLEAN); } }