Monster_Page.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. require_once($path["page"] . "Page.php");
  3. require_once($path["entity"] . "Monster.php");
  4. /**
  5. * Monster view page.
  6. */
  7. class Monster_Page extends Page{
  8. /**
  9. * Selected @{see Monster}.
  10. */
  11. public $monsters;
  12. /**
  13. * Stats gained by building.
  14. */
  15. public $building_stats = [
  16. "atk" => 0,
  17. "def" => 0,
  18. "hp" => 0,
  19. "spd" => 0,
  20. "crd" => 0,
  21. "elm" => [
  22. "Fire" => 0,
  23. "Water" => 0,
  24. "Wind" => 0,
  25. "Light" => 0,
  26. "Dark" => 0
  27. ]
  28. ];
  29. /**
  30. * Constructor.
  31. *
  32. * Retrieves the data and initializes the variables.
  33. *
  34. * @param SQLite3 $db Connection to the database.
  35. * @param string $id Monster id
  36. */
  37. public function __construct($db, $id){
  38. global $path;
  39. global $root;
  40. parent::__construct($db);
  41. $this->view = $path["view"] . "monster.php";
  42. $this->calculate_buildings();
  43. $this->monster = new Monster($db, $id);
  44. $this->title = $this->monster->monster->name ." - SWDB";
  45. $this->description = "Owned " . $this->monster->monster->name;
  46. $this->canonical = $root . "monster/" . $id;
  47. }
  48. /**
  49. * Calculates the stats gained from bulding upgrades and populates the
  50. * $building_stats array.
  51. */
  52. private function calculate_buildings(){
  53. $s =
  54. "SELECT " .
  55. " affected_stat, " .
  56. " bonus, " .
  57. " element " .
  58. "FROM " .
  59. " k_building, " .
  60. " k_building_level, " .
  61. " building " .
  62. "WHERE " .
  63. " k_building.id = building.building AND " .
  64. " building.building = k_building_level.building AND " .
  65. " building.level = k_building_level.level AND " .
  66. " area = 'Everywhere' AND " .
  67. " affected_stat IN ('ATK', 'DEF', 'HP', 'SPD', 'CRI Dmg');";
  68. $q = $this->db->query($s);
  69. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  70. switch($r["affected_stat"]){
  71. case "DEF":
  72. $this->building_stats["def"] += $r["bonus"];
  73. break;
  74. case "HP":
  75. $this->building_stats["hp"] += $r["bonus"];
  76. break;
  77. case "SPD":
  78. $this->building_stats["spd"] += $r["bonus"];
  79. break;
  80. case "CRI Dmg":
  81. $this->building_stats["crd"] += $r["bonus"];
  82. break;
  83. case "ATK":
  84. if(strlen($r["element"]) > 0){
  85. $this->building_stats["elm"][$r["element"]] += $r["bonus"];
  86. }
  87. else{
  88. $this->building_stats["atk"] += $r["bonus"];
  89. }
  90. break;
  91. }
  92. }
  93. }
  94. }
  95. ?>