* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package SWDB */ require_once(PATH::ENTITY . "Entity.php"); /** * Rune_stat. * * Represents any of the stats of a rune. * * @category Entity */ class Rune_Stat extends Entity{ /** * @var int Stat slot. * @see RUNE_STAT_SLOT_ID */ private $slot; /** * @var int Substat type. * @see RUNE_STAT_ID */ private $stat; /** * @var string Substat name (uppercase). */ private $stat_name = ""; /** * @var int Substat value. */ private $value; /** * @var int Grinded value of the stat. */ private $grind; /** * @var bool Indicates if a gem has been used. */ private $enchant; /** * Constructor. * * Searches the database and retrieves the information about the * rune stat, populating it and it's items. * * @param int $id Rune id. */ public function __construct($rune, $slot){ $statement = get_context()->get_db()->prepare(" SELECT slot, stat, value, enchant, grind FROM rune_stat WHERE rune = :rune AND slot = :slot; "); $statement->bindValue(':rune', $rune, SQLITE3_TEXT); $statement->bindValue(':slot', $slot, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->slot = $r["slot"]; $this->stat = $r["stat"]; $this->value = $r["value"]; if ($r["enchant"] == 1){ $this->enchant = true; } else{ $this->enchant = false; } $this->grind = $r["grind"]; switch ($this->stat){ case RUNE_STAT_ID::HP: $this->stat_name = "HP"; break; case RUNE_STAT_ID::HP_P: $this->stat_name = "HP%"; break; case RUNE_STAT_ID::ATK: $this->stat_name = "ATK"; break; case RUNE_STAT_ID::ATK_P: $this->stat_name = "ATK%"; break; case RUNE_STAT_ID::DEF: $this->stat_name = "DEF"; break; case RUNE_STAT_ID::DEF_P: $this->stat_name = "DEF%"; break; case RUNE_STAT_ID::SPD: $this->stat_name = "SPD"; break; case RUNE_STAT_ID::CRR: $this->stat_name = "CRR"; break; case RUNE_STAT_ID::CRD: $this->stat_name = "CRD"; break; case RUNE_STAT_ID::RES: $this->stat_name = "RES"; break; case RUNE_STAT_ID::ACC: $this->stat_name = "ACC"; break; } } else{ // Not found, maybe in run_drop_rune? $select = "main_stat AS stat, main_stat_value AS value"; switch ($slot){ case RUNE_STAT_SLOT_ID::MAIN: $select = "main_stat AS stat, main_stat_value AS value"; break; case RUNE_STAT_SLOT_ID::INNATE: $select = "innate_stat AS stat, innate_stat_value AS value"; break; case RUNE_STAT_SLOT_ID::SUBSTAT_1: $select = "substat_1 AS stat, substat_1_value AS value"; break; case RUNE_STAT_SLOT_ID::SUBSTAT_2: $select = "substat_2 AS stat, substat_2_value AS value"; break; case RUNE_STAT_SLOT_ID::SUBSTAT_3: $select = "substat_3 AS stat, substat_3_value AS value"; break; case RUNE_STAT_SLOT_ID::SUBSTAT_4: $select = "substat_4 AS stat, substat_4_value AS value"; break; } $statement = get_context()->get_db()->prepare(" SELECT $select FROM run_drop_rune WHERE id = :rune; "); $statement->bindValue(':rune', $rune, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->slot = $slot; $this->stat = $r["stat"]; $this->value = $r["value"]; $this->enchant = false; $this->grind = 0; switch ($this->stat){ case RUNE_STAT_ID::HP: $this->stat_name = "HP"; break; case RUNE_STAT_ID::HP_P: $this->stat_name = "HP%"; break; case RUNE_STAT_ID::ATK: $this->stat_name = "ATK"; break; case RUNE_STAT_ID::ATK_P: $this->stat_name = "ATK%"; break; case RUNE_STAT_ID::DEF: $this->stat_name = "DEF"; break; case RUNE_STAT_ID::DEF_P: $this->stat_name = "DEF%"; break; case RUNE_STAT_ID::SPD: $this->stat_name = "SPD"; break; case RUNE_STAT_ID::CRR: $this->stat_name = "CRR"; break; case RUNE_STAT_ID::CRD: $this->stat_name = "CRD"; break; case RUNE_STAT_ID::RES: $this->stat_name = "RES"; break; case RUNE_STAT_ID::ACC: $this->stat_name = "ACC"; break; } } } } /** * Retrieves the slot of the stat. * * @see RUNE_STAT_SLOT_ID * @return int Slot number. */ public function get_slot(){ return $this->slot; } /** * Retrieves the stat identifier. * * @see RUNE_STAT_ID * @return int Stat ID. */ public function get_stat(){ return $this->stat; } /** * Retrieves the stat name. * * @return string Stat name. */ public function get_stat_name(){ return $this->stat_name; } /** * Retrieves the stat value, without grinds. * * @return int Stat value. */ public function get_value(){ return $this->value; } /** * Retrieves the grinded value of the stat. * * @return int Grinded value. */ public function get_grind(){ return $this->grind; } /** * Checks if the stat has been changed by gems. * * @return bool True if the stat was enchanted, false otherwise. */ public function is_enchanted(){ return $this->enchant; } } ?>