* @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 . "Skill_Level.php"); require_once(PATH::ENTITY . "Effect.php"); /** * Monster skill. * * Represents a monster skill. * * @category Entity */ class Skill extends Entity{ /** * @var int Skill identifier. */ private $id; /** * @var string Skill name. */ private $name; /** * @var string Skill description. */ private $description; /** * @var int Skill order. */ private $slot; /** * @var int Skill cooldown turns. */ private $cooltime; /** * @var int Number of hits. */ private $hits; /** * @var bool Wether the skill is passive or not. */ private $passive; /** * @var bool Wether the skill is AOE. */ private $aoe; /** * @var int Skill max level. */ private $max_level; /** * @var string Skill formula. */ private $multiplier_formula; /** * @var Skill The skill upgrading this one. */ private $upgrade; /** * @var bool Internal flag to check if the levels have been loaded into the entity. */ private $flag_levels = false; /** * @var Skill_Level[] Available skill levels. */ private $level = []; /** * @var bool Internal flag to check if the skill effects have been loaded into the entity. */ private $flag_effects = false; /** * @var Effect[] Associated eeffects. */ private $effect = []; /** * Constructor. * * Searches the database and retrieves the information about the * skill, populating it and it's items. * * @param int $id Skill identifier. */ public function __construct($id){ $statement = get_context()->get_db()->prepare(" SELECT id, name, description, slot, cooltime, hits, passive, aoe, max_level, multiplier_formula FROM skill WHERE id = :id; "); $statement->bindValue(':id', $id, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->id = $r["id"]; $this->name = HTML::e($r["name"]); $this->description = HTML::e($r["description"]); $this->slot = $r["slot"]; $this->cooltime = $r["cooltime"]; $this->hits = $r["hits"]; $this->passive = $r["passive"]; $this->aoe = $r["aoe"]; $this->max_level = $r["max_level"]; $this->multiplier_formula = HTML::e($r["multiplier_formula"]); } } /** * Loads the levels into the entity. * * Must be called only once before trying to access the levels. Sets the flag * {@link Skill:$flag_levels} to true. */ private function load_levels(){ $statement = get_context()->get_db()->prepare(" SELECT skill, level FROM skill_level WHERE skill = :skill ORDER BY level; "); $statement->bindValue(':skill', $this->id, SQLITE3_TEXT); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->level, new Skill_Level($r["skill"], $r["level"])); } $this->flag_levels = true; } /** * Loads the effects into the entity. * * Must be called only once before trying to access the effects. Sets the flag * {@link Skill:$flag_effects} to true. */ private function load_effects(){ $statement = get_context()->get_db()->prepare(" SELECT DISTINCT effect FROM skill_effect WHERE skill = :skill; "); $statement->bindValue(':skill', $this->id, SQLITE3_TEXT); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->effect, new Effect($r["effect"])); } $this->flag_effects = true; } /** * Retrieves the skill identifier. * * @return int Skill id. */ public function get_id(){ return $this->id; } /** * Retrieves the skill name. * * @return string Sill name. */ public function get_name(){ return $this->name; } /** * Retrieves the skill description. * * @return string Skill description. */ public function get_description(){ return $this->description; } /** * Retrieves the skill slot. * * @return int The skill slot (1-4); */ public function get_slot(){ return $this->slot; } /** * Retrieves the skill cooldown time * * @return int Skill cooltime. */ public function get_cooltime(){ return $this->cooltime; } /** * Retrieves the number of times the skill hist. * * @return int Number of hits. */ public function get_hits(){ return $this->hits; } /** * Checks if the skill is passive. * * @return bool True for passive skills, false for active. */ public function is_passive(){ return $this->passive; } /** * Checks if the skills affects a group instead of a unit. * * @return bool True for AOE skills, false for single-target skills. */ public function is_aoe(){ return $this->aoe; } /** * Retrieves the maximum level of the skill. * * @return int Skill max level. */ public function get_max_level(){ return $this->max_level; } /** * Retrieves the skills mathematical formula. * * @return string Skill formula. */ public function get_multiplier_formula(){ return $this->multiplier_formula; } /** * Retrieves the skill this one upgrades to (ie, on awakening). * * @return Skill Upgraded skill, null if not upgradeable. */ public function get_upgrade(){ return $this->upgrade; } /** * Retrieves information about the skill levels. * * @return Skill_Level[] Levels of the skill. */ public function get_levels(){ if (! $this->flag_levels){ $this->load_levels(); } return $this->level; } /** * Retrieves the effects caused by the skill. * * @return Effect[] Effects caused by the skill. */ public function get_effects(){ if (! $this->flag_effects){ $this->load_effects(); } return $this->effect; } /** * Gets the path to the skill image. * * @return string Image URL, or a fixed unknown image. */ public function get_image(){ return APPLICATION::img("SKILL", $this->id); } }