| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- /**
- * Monster view page file.
- *
- * Provides a class with all the properties and methods to display the page.
- *
- * @category Page
- */
- /**
- * Require dependent files if not present.
- */
- require_once(PATH::PAGE . "Page.php");
- require_once(PATH::ENTITY . "Unit.php");
- /**
- * Monster view page model.
- *
- * @category Page
- */
- class Monster_Page extends Page{
- /**
- * @var Unit Selected Unit.
- */
- public $unit;
- /**
- * @var mixed[] Stats gained by building.
- */
- public $building_stats = [
- "atk" => 0,
- "def" => 0,
- "hp" => 0,
- "spd" => 0,
- "crd" => 0,
- "elm" => [
- 0 => 0,
- 1 => 0,
- 2 => 0,
- 3 => 0,
- 4 => 0
- ]
- ];
- /**
- * Constructor.
- *
- * Retrieves the data and initializes the variables.
- *
- * @param resource $db Connection to the database.
- * @param string $id Selected unit id
- */
- public function __construct($db, $id){
- parent::__construct($db);
- $this->view = PATH::VIEW . "monster.php";
- $this->calculate_buildings();
- $this->unit = new Unit($db, $id);
- $this->title = $this->unit->unit->name ." - SWDB";
- $this->description = "Owned " . $this->unit->unit->name;
- $this->canonical = URL::BASE . "monster/" . $id;
- }
- /**
- * Calculates the stats gained from bulding upgrades and populates the
- * $building_stats array.
- *
- * @gobal int User ID.
- */
- private function calculate_buildings(){
- global $UID;
- $s = "
- SELECT
- affected_stat,
- bonus,
- element
- FROM
- k_decoration,
- k_decoration_level,
- decoration
- WHERE
- decoration.uid = '$UID' AND
- k_decoration.id = decoration.decoration AND
- decoration.decoration = k_decoration_level.decoration AND
- decoration.level = k_decoration_level.level AND
- area = " . EFFECT_AREA_ID::GENERAL . " AND
- affected_stat IN (" . STAT_ID::ATK . ", " . STAT_ID::DEF . ", " . STAT_ID::HP . ", " . STAT_ID::SPD . ", " . STAT_ID::CRIT_DMG . ");
- ";
- $q = $this->db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- switch($r["affected_stat"]){
- case STAT_ID::DEF:
- $this->building_stats["def"] += $r["bonus"];
- break;
- case STAT_ID::HP:
- $this->building_stats["hp"] += $r["bonus"];
- break;
- case STAT_ID::SPD:
- $this->building_stats["spd"] += $r["bonus"];
- break;
- case STAT_ID::CRIT_DMG:
- $this->building_stats["crd"] += $r["bonus"];
- break;
- case STAT_ID::ATK:
- if(strlen($r["element"]) > 0){
- $this->building_stats["elm"][$r["element"]] += $r["bonus"];
- }
- else{
- $this->building_stats["atk"] += $r["bonus"];
- }
- break;
- }
- }
- }
- }
- ?>
|