Monster_Page.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. 1 => 0,
  35. 2 => 0,
  36. 3 => 0,
  37. 4 => 0,
  38. 5 => 0
  39. ]
  40. ];
  41. /**
  42. * Constructor.
  43. *
  44. * Retrieves the data and initializes the variables.
  45. *
  46. * @param string $id Selected unit id
  47. * @global resource Database connection.
  48. */
  49. public function __construct($id){
  50. global $db;
  51. $this->view = PATH::VIEW . "monster.php";
  52. $this->calculate_buildings();
  53. $this->unit = new Unit($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. * @global resource Database connection.
  64. */
  65. private function calculate_buildings(){
  66. global $UID;
  67. global $db;
  68. $s = "
  69. SELECT
  70. affected_stat,
  71. bonus,
  72. element
  73. FROM
  74. k_decoration,
  75. k_decoration_level,
  76. decoration
  77. WHERE
  78. decoration.uid = '$UID' AND
  79. k_decoration.id = decoration.decoration AND
  80. decoration.decoration = k_decoration_level.decoration AND
  81. decoration.level = k_decoration_level.level AND
  82. area = " . EFFECT_AREA_ID::GENERAL . " AND
  83. affected_stat IN (" . STAT_ID::ATK . ", " . STAT_ID::DEF . ", " . STAT_ID::HP . ", " . STAT_ID::SPD . ", " . STAT_ID::CRIT_DMG . ");
  84. ";
  85. $q = $db->query($s);
  86. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  87. switch($r["affected_stat"]){
  88. case STAT_ID::DEF:
  89. $this->building_stats["def"] += $r["bonus"];
  90. break;
  91. case STAT_ID::HP:
  92. $this->building_stats["hp"] += $r["bonus"];
  93. break;
  94. case STAT_ID::SPD:
  95. $this->building_stats["spd"] += $r["bonus"];
  96. break;
  97. case STAT_ID::CRIT_DMG:
  98. $this->building_stats["crd"] += $r["bonus"];
  99. break;
  100. case STAT_ID::ATK:
  101. if(strlen($r["element"]) > 0){
  102. $this->building_stats["elm"][$r["element"]] += $r["bonus"];
  103. }
  104. else{
  105. $this->building_stats["atk"] += $r["bonus"];
  106. }
  107. break;
  108. }
  109. }
  110. }
  111. }
  112. ?>