Monster_Page.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. require_once($path["page"] . "Page.php");
  3. require_once($path["entity"] . "Unit.php");
  4. /**
  5. * Monster view page.
  6. */
  7. class Monster_Page extends Page{
  8. /**
  9. * Selected @{see Unit}.
  10. */
  11. public $unit;
  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. 0 => 0,
  23. 1 => 0,
  24. 2 => 0,
  25. 3 => 0,
  26. 4 => 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->unit = new Unit($db, $id);
  44. $this->title = $this->unit->unit->name ." - SWDB";
  45. $this->description = "Owned " . $this->unit->unit->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. global $EFFECT_AREA;
  54. $s =
  55. "SELECT " .
  56. " affected_stat, " .
  57. " bonus, " .
  58. " element " .
  59. "FROM " .
  60. " k_decoration, " .
  61. " k_decoration_level, " .
  62. " decoration " .
  63. "WHERE " .
  64. " k_decoration.id = decoration.decoration AND " .
  65. " decoration.decoration = k_decoration_level.decoration AND " .
  66. " decoration.level = k_decoration_level.level AND " .
  67. " area = " . $EFFECT_AREA["GENERAL"] . " AND " .
  68. " affected_stat IS NOT NULL;";
  69. $q = $this->db->query($s);
  70. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  71. switch($r["affected_stat"]){
  72. case "DEF":
  73. $this->building_stats["def"] += $r["bonus"];
  74. break;
  75. case "HP":
  76. $this->building_stats["hp"] += $r["bonus"];
  77. break;
  78. case "SPD":
  79. $this->building_stats["spd"] += $r["bonus"];
  80. break;
  81. case "CRI Dmg":
  82. $this->building_stats["crd"] += $r["bonus"];
  83. break;
  84. case "ATK":
  85. if(strlen($r["element"]) > 0){
  86. $this->building_stats["elm"][$r["element"]] += $r["bonus"];
  87. }
  88. else{
  89. $this->building_stats["atk"] += $r["bonus"];
  90. }
  91. break;
  92. }
  93. }
  94. }
  95. }
  96. ?>