Monster_Page.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Monster view page file.
  4. *
  5. * Provides a class with all the properties and methods to display the page.
  6. *
  7. * @category Page
  8. */
  9. /**
  10. * Require dependent files if not present.
  11. */
  12. require_once(PATH::PAGE . "Page.php");
  13. require_once(PATH::ENTITY . "Unit.php");
  14. /**
  15. * Monster view page model.
  16. *
  17. * @category Page
  18. */
  19. class Monster_Page extends Page{
  20. /**
  21. * @var Unit Selected Unit.
  22. */
  23. public $unit;
  24. /**
  25. * @var mixed[] Stats gained by building.
  26. */
  27. public $building_stats = [
  28. "atk" => 0,
  29. "def" => 0,
  30. "hp" => 0,
  31. "spd" => 0,
  32. "crd" => 0,
  33. "elm" => [
  34. 0 => 0,
  35. 1 => 0,
  36. 2 => 0,
  37. 3 => 0,
  38. 4 => 0
  39. ]
  40. ];
  41. /**
  42. * Constructor.
  43. *
  44. * Retrieves the data and initializes the variables.
  45. *
  46. * @param resource $db Connection to the database.
  47. * @param string $id Selected unit id
  48. */
  49. public function __construct($db, $id){
  50. parent::__construct($db);
  51. $this->view = PATH::VIEW . "monster.php";
  52. $this->calculate_buildings();
  53. $this->unit = new Unit($db, $id);
  54. $this->title = $this->unit->unit->name ." - SWDB";
  55. $this->description = "Owned " . $this->unit->unit->name;
  56. $this->canonical = URL::BASE . "monster/" . $id;
  57. }
  58. /**
  59. * Calculates the stats gained from bulding upgrades and populates the
  60. * $building_stats array.
  61. *
  62. * @gobal int User ID.
  63. */
  64. private function calculate_buildings(){
  65. global $UID;
  66. $s = "
  67. SELECT
  68. affected_stat,
  69. bonus,
  70. element
  71. FROM
  72. k_decoration,
  73. k_decoration_level,
  74. decoration
  75. WHERE
  76. decoration.uid = '$UID' AND
  77. k_decoration.id = decoration.decoration AND
  78. decoration.decoration = k_decoration_level.decoration AND
  79. decoration.level = k_decoration_level.level AND
  80. area = " . EFFECT_AREA_ID::GENERAL . " AND
  81. affected_stat IN (" . STAT_ID::ATK . ", " . STAT_ID::DEF . ", " . STAT_ID::HP . ", " . STAT_ID::SPD . ", " . STAT_ID::CRIT_DMG . ");
  82. ";
  83. $q = $this->db->query($s);
  84. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  85. switch($r["affected_stat"]){
  86. case STAT_ID::DEF:
  87. $this->building_stats["def"] += $r["bonus"];
  88. break;
  89. case STAT_ID::HP:
  90. $this->building_stats["hp"] += $r["bonus"];
  91. break;
  92. case STAT_ID::SPD:
  93. $this->building_stats["spd"] += $r["bonus"];
  94. break;
  95. case STAT_ID::CRIT_DMG:
  96. $this->building_stats["crd"] += $r["bonus"];
  97. break;
  98. case STAT_ID::ATK:
  99. if(strlen($r["element"]) > 0){
  100. $this->building_stats["elm"][$r["element"]] += $r["bonus"];
  101. }
  102. else{
  103. $this->building_stats["atk"] += $r["bonus"];
  104. }
  105. break;
  106. }
  107. }
  108. }
  109. }
  110. ?>