* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package SWDB */ require_once(PATH::ENTITY . "Entity.php"); require_once(PATH::ENTITY . "Rune_Set.php"); /** * Owned enchantments. * * Represent an enchantment, both grindstones and gems. * * @category Entity */ class Enchantment extends Entity{ /** * @var int Owner's player ID. */ private $player_id; /** * @var int Enchantment ID. */ private $id; /** * @var int Quality ID ({@see QUALITY_ID}). */ private $quality; /** * @var string Quality name. */ private $quality_name; /** * @var int Rune set ID ({@see RUNE_SET_ID}). */ private $rune_set; /** * @var int ID of the stat affeced by the enchantmentt ({@see RUNE_STAT_ID}). */ private $stat; /** * @var string Name of the affected stat. */ private $stat_name; /** * @var bool Indicates if the enchantment is a gem. */ private $gem; /** * @var bool Indicates if the enchantment is ancient. */ private $ancient; /** * @var bool Indicates if the enchantment is inmemorial. */ private $inmemorial; /** * @var string Enchantment name. */ private $name; /** * @var int Minimal effect of the enchantment. */ private $min; /** * @var int Maximum effect of the enchantment. */ private $max; /** * @var int Value of the enchantment in mana stones. */ private $value; /** * @var int Owned amount of the same enchantment. */ private $amount; /** * Constructor. * * Searches the database and retrieves the information about the * rune, populating it and it's items. * * @param int $id Enchantment id. */ public function __construct($id){ $statement = get_context()->get_db()->prepare(" SELECT enchantment.player AS player, enchantment.id AS id, enchantment.quality As quality, enchantment.rune AS rune, enchantment.stat AS stat, enchantment.value AS value, enchantment.amount AS amount, enchantment_type.name AS name, enchantment_type.gem AS gem, enchantment_type.inmemorial AS inmemorial, enchantment_type.ancient AS ancient, enchantment_range.min AS min, enchantment_range.max AS max FROM enchantment, enchantment_type, enchantment_range WHERE enchantment.id = :id AND enchantment.type = enchantment_type.id AND enchantment_type.gem = enchantment_range.gem AND enchantment_type.gem = enchantment_range.gem AND enchantment_type.ancient = enchantment_range.ancient AND enchantment.quality = enchantment_range.quality AND enchantment.stat = enchantment_range.stat; "); $statement->bindValue(':id', $id, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->player_id = $r["player"]; $this->id = $r["id"]; if ($r["gem"] == 0){ $this->gem = false; } else{ $this->gem = true; } $this->quality = $r["quality"]; $this->quality_name = $this->quality_name($r["quality"]); $this->stat = $r["stat"]; $this->stat_name = $this->stat_name($r["stat"]); if ($r["ancient"] == 0){ $this->ancient = false; } else{ $this->ancient = true; } $this->inmemorial = $r["inmemorial"]; if ($r["inmemorial"] == 0){ $this->rune_set = new Rune_Set($r["rune"]); $this->name = $this->rune_set->get_name() . " " . $this->stat_name; $this->inmemorial = false; } else{ $this->inmemorial = true; $this->name = "Inmemorial " . $this->stat_name; } $this->min = $r["min"]; $this->max = $r["max"]; $this->value = $r["value"]; $this->amount = $r["amount"]; } else{ // Not found, maybe as a run drop? $statement = get_context()->get_db()->prepare(" SELECT run_drop_enchantment.id AS id, type, run_drop_enchantment.quality AS quality, rune, run_drop_enchantment.stat AS stat, value, enchantment_type.inmemorial AS inmemorial, enchantment_type.ancient AS ancient, enchantment_range.min AS min, enchantment_range.max AS max FROM run_drop_enchantment, enchantment_type, enchantment_range WHERE run = :run AND run_drop_enchantment.type = enchantment_type.id AND enchantment_type.gem = enchantment_range.gem AND enchantment_type.gem = enchantment_range.gem AND enchantment_type.ancient = enchantment_range.ancient AND run_drop_enchantment.quality = enchantment_range.quality AND run_drop_enchantment.stat = enchantment_range.stat; "); $statement->bindValue(':id', $id, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->player_id = get_context()->get_player()->get_id(); if ($r["type"] == ENCHANTMENT_TYPE_ID::ENCHANT_GEM || $r["type"] == ENCHANTMENT_TYPE_ID::INMEMORIAL_GEM){ $this->gem = 1; } else{ $this->gem = 0; } $this->quality = $r["quality"]; $this->quality_name = $this->quality_name($r["quality"]); $this->value = 0; $this->stat = $r["stat"]; $this->stat_name = $this->stat_name($r["stat"]); $this->ancient = filter_var($r["ancient"], FILTER_VALIDATE_BOOLEAN); $this->inmemorial = filter_var($r["inmemorial"], FILTER_VALIDATE_BOOLEAN); if ($r["inmemorial"] == 0){ $this->rune_set = new Rune_Set($r["rune"]); $this->name = $this->rune_set->get_name() . " " . $this->stat_name; $this->inmemorial = false; } else{ $this->inmemorial = true; $this->name = "Inmemorial " . $this->stat_name; } $this->min = $r["min"]; $this->max = $r["max"]; $this->value = $r["value"]; $this->amount = 1; } } } /** * Gets a stat name from the maps. * * @param int $stat Stat id. * @return string Stat name (Uppercase) */ private function stat_name($stat){ switch ($stat){ case RUNE_STAT_ID::HP: return "HP"; case RUNE_STAT_ID::HP_P: return "HP%"; case RUNE_STAT_ID::ATK: return "ATK"; case RUNE_STAT_ID::ATK_P: return "ATK%"; case RUNE_STAT_ID::DEF: return "DEF"; case RUNE_STAT_ID::DEF_P: return "DEF%"; case RUNE_STAT_ID::SPD: return "SPD"; case RUNE_STAT_ID::CRR: return "CRR"; case RUNE_STAT_ID::CRD: return "CRD"; case RUNE_STAT_ID::RES: return "RES"; case RUNE_STAT_ID::ACC: return "ACC"; default: return ""; } } /** * Gets a stat name from the maps. * * @param int $q Quality id. * @return string Quality (Uppercase) */ private function quality_name($q){ switch ($q){ case QUALITY_ID::NORMAL: return "NORMAL"; case QUALITY_ID::MAGIC: return "MAGIC"; case QUALITY_ID::RARE: return "RARE"; case QUALITY_ID::HERO: return "HERO"; case QUALITY_ID::LEGEND: return "LEGEND"; default: return ""; } } /** * Retrieves the owner's player identifier. * * @return int player identifier. */ public function get_player_id(){ return $this->player_id; } /** * Retrieves the enchantment identifier. * * @return string Enchantment ID. */ public function get_id(){ return $this->id; } /** * Retrieves the quality of the enchantment. * * @see QUALITY_ID * * @return int Quality. */ public function get_quality(){ return $this->quality; } /** * Retrieves the quality name of the enchantment. * * @return string Quality name. */ public function get_quality_name(){ return $this->quality_name; } /** * Retrieves the rune set the enchantment can be used on. * * @return Rune_Set The set the enchantment can be used on, null for inmemorials. */ public function get_rune_set(){ return $this->rune_set; } /** * Retrieves the stat affected by the enchantment. * * @see RUNE_STAT_ID * * @return int Stat ID. */ public function get_stat(){ return $this->stat; } /** * Retrieves the name of the affected stat. * * @return string Stat name */ public function get_stat_name(){ return $this->stat_name; } /** * Checks if the enchantment is a enchanted gem. * * @return bool true for enchanted gems, false for grindstones. */ public function is_gem(){ return $this->gem; } /** * Checks if the enchantment is a grindstone. * * @return bool true for grindstones, false enchanted gems. */ public function is_grind(){ return ! $this->gem; } /** * Checks if it's an ancient enchantment. * * @return bool True if ancient, false if normal. */ public function is_ancient(){ return $this->ancient; } /** * Checks if the enchantment is inmemorial. * * @return bool True for inmemorial, false otherwise. */ public function is_inmemorial(){ return $this->inmemorial; } /** * Retrieves the enchantment name. * * @return string Enchantment name. */ public function get_name(){ return $this->name; } /** * Retrieves the minumum value for the enchantment. * * @return int Minimum enchant outcome. */ public function get_min(){ return $this->min; } /** * Retrieves the maximum value for the enchantment. * * @return int Maximum enchant outcome. */ public function get_max(){ return $this->max; } /** * Retrieves the value of the enchantment in mana stones. * * @return int Value of the enchantment. */ public function get_value(){ return $this->value; } /** * Retrieves the amount of the same enchantment owned by the user. * * @return int Number of the enchantments owned. */ public function get_amount(){ return $this->amount; } }