Monster_Page.php 3.4 KB

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