Monster_Page.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 $STAT;
  54. global $EFFECT_AREA;
  55. global $UID;
  56. $s = "
  57. SELECT
  58. affected_stat,
  59. bonus,
  60. element
  61. FROM
  62. k_decoration,
  63. k_decoration_level,
  64. decoration
  65. WHERE
  66. decoration.uid = '$UID' AND
  67. k_decoration.id = decoration.decoration AND
  68. decoration.decoration = k_decoration_level.decoration AND
  69. decoration.level = k_decoration_level.level AND
  70. area = " . $EFFECT_AREA["GENERAL"] . " AND
  71. affected_stat IN (" . $STAT["ATK"] . ", " . $STAT["DEF"] . ", " . $STAT["HP"] . ", " . $STAT["SPD"] . ", " . $STAT["CRIT_DMG"] . ");
  72. ";
  73. $q = $this->db->query($s);
  74. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  75. switch($r["affected_stat"]){
  76. case $STAT["DEF"]:
  77. $this->building_stats["def"] += $r["bonus"];
  78. break;
  79. case $STAT["HP"]:
  80. $this->building_stats["hp"] += $r["bonus"];
  81. break;
  82. case $STAT["SPD"]:
  83. $this->building_stats["spd"] += $r["bonus"];
  84. break;
  85. case $STAT["CRIT_DMG"]:
  86. $this->building_stats["crd"] += $r["bonus"];
  87. break;
  88. case $STAT["ATK"]:
  89. if(strlen($r["element"]) > 0){
  90. $this->building_stats["elm"][$r["element"]] += $r["bonus"];
  91. }
  92. else{
  93. $this->building_stats["atk"] += $r["bonus"];
  94. }
  95. break;
  96. }
  97. }
  98. }
  99. }
  100. ?>