| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- /**
- * Transformation entity file.
- *
- * Creates the entity and makes it available.
- *
- * @author Iñigo Valentin <i@inigovalentin.com>
- * @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.php");
- require_once(PATH::ENTITY . "Leader_Skill.php");
- require_once(PATH::ENTITY . "Source.php");
- /**
- * Monster transformation.
- *
- * Represents a transformation that a monster can achive in battle.
- *
- * @category Entity
- */
- class Monster_Transformation extends Entity{
- /**
- * @var int Transformed monster identifier.
- */
- private $id;
- /**
- * @var int Transformed monster family id.
- */
- private $family;
- /**
- * @var int ID of the monster that transformes into this.
- */
- private $monster;
- /**
- * @var bool Internal flag to check if the skills have been loaded into the entity.
- */
- private $flag_skills = false;
- /**
- * @var Skill[] Skills in the transformed form.
- */
- private $skill = [];
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * trnsformed monster, populating it and it's items.
- *
- * @param int $id Transformed monster identifier.
- */
- public function __construct($id){
- $statement = get_context()->get_db()->prepare("
- SELECT
- id,
- family,
- monster
- FROM monster_transformation
- WHERE id = :id;
- ");
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->id = $r["id"];
- $this->family = $r["family"];
- $this->monster = $r["monster"];
- }
- }
- /**
- * Loads the information about the monster skills in the transformed form.
- *
- * Must be called only once before trying to get the skills. Sets the flag
- * {@link Monster_Transformation:$flag_skills} to true.
- */
- private function load_skills(){
- $this->skill = [];
- $statement = get_context()->get_db()->prepare("
- SELECT skill
- FROM
- skill,
- monster_skill
- WHERE
- id = skill AND
- monster = :id
- ORDER BY slot;
- ");
- $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->skill, new Skill($r["skill"]));
- }
- $this->flag_skills = true;
- }
- /**
- * Retrieves the identifier of the transformed monster.
- *
- * @return string Trasnformed monster ID.
- */
- public function get_id(){
- return $this->id;
- }
- /**
- * Retrieves the transofmred monster family identifier.
- *
- * @return int Family ID.
- */
- public function get_family(){
- return $this->family;
- }
- /**
- * Retrieves the identifier of the monster that transforms into this one.
- *
- * @return int Base monster ID.
- */
- public function get_base_id(){
- return $this->monster;
- }
- /**
- * Retrieves the skills of the transformed monster.
- *
- * @return Skill[] Array of skills.
- */
- public function get_skills(){
- if (! $this->flag_skills){
- $this->load_skills();
- }
- return $this->skill;
- }
- /**
- * Gets the path to the monster image.
- *
- * @return string Image URL, or a fixed unknown image.
- */
- public function get_image(){
- return APPLICATION::img("UNIT", $this->id);
- }
- }
|