<?php

    require_once($path["entity"] . "Entity.php");

    /**
     * Skill effect.
     *
     * Represents an object from the table 'k_effect'.
     */
    class K_Effect extends Entity{

        /**
         * Effect identifier.
         */
        public $id;

        /**
         * Effect name.
         */
        public $name;

        /**
         * Indicates if the effect is a buff.
         */
        public $is_buff;

        /**
         * Effect description.
         */
        public $description;

        /**
         * Constructor.
         *
         * Searches the database and retrieves the information about the
         * skill level, populating it and it's items.
         *
         * @param SQLite3 $db Connection to the database.
         * @param int $skill Effect identifier.
         */
        public function __construct($db, $id){
            global $path;
            parent::__construct($db);
            $s =
              "SELECT " .
              "  id, " .
              "  name, " .
              "  is_buff, " .
              "  description " .
              "FROM k_effect " .
              "WHERE id = $id;";
            $q = $this->db->query($s);
            $r = $q->fetchArray(SQLITE3_ASSOC);
            if ($r){
                $this->id = $r["id"];
                $this->name = $r["name"];
                $this->is_buff = $r["is_buff"];
                $this->description = $r["description"];
            }
        }

        /**
         * Gets the pathto the monster image. The image must be in the
         * img/effect/ directory, and its name must be the effect id,
         * padded with '0' to 4 digits, and the extension must be '.png'.
         *
         * @return path to the image, or a path to a fixed unknown image if it
         *         doesn't exist.
         */
        public function get_image(){
            global $base_dir;
            global $path;
            if (file_exists($base_dir . "img/effect/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
                return $path["img"]["effect"] . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
            }
            else{
                return $path["img"]["root"] . "unknown.png";
            }
        }
    }
?>
