Monster.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "Monster_Base.php");
  4. /**
  5. * Monster.
  6. *
  7. * Represents an object from the table 'monster'.
  8. */
  9. class Monster extends Entity{
  10. /**
  11. * Project identifier.
  12. */
  13. public $id;
  14. /**
  15. * Monster name.
  16. */
  17. public $name;
  18. /**
  19. * Monster name (awakened).
  20. */
  21. public $name_aw;
  22. /**
  23. * Monster element.
  24. */
  25. public $element;
  26. /**
  27. * Default star level.
  28. */
  29. public $stars;
  30. /**
  31. * Base monster. {@see Monster_Base}
  32. */
  33. public $base;
  34. /**
  35. * Monster image.
  36. */
  37. public $image;
  38. /**
  39. * Monster image (awakened).
  40. */
  41. public $image_aw;
  42. /**
  43. * Constructor.
  44. *
  45. * Searches the database and retrieves the information about the
  46. * monster, populating it and it's items.
  47. *
  48. * @param MySQL_connection $db Connection to the database.
  49. * @param int $id Monster identifier.
  50. */
  51. public function __construct($db, $id){
  52. global $path;
  53. parent::__construct($db);
  54. $s =
  55. "SELECT " .
  56. " id, " .
  57. " name, " .
  58. " name_aw, " .
  59. " element, " .
  60. " stars, " .
  61. " base " .
  62. "FROM monster " .
  63. "WHERE id = $id; ";
  64. $q = mysqli_query($this->db, $s);
  65. if (mysqli_num_rows($q) > 0){
  66. $r = mysqli_fetch_array($q);
  67. $this->id = $r["id"];
  68. $this->name = $r["name"];
  69. $this->name_aw = $r["name_aw"];
  70. $this->element = $r["element"];
  71. $this->stars = $r["stars"];
  72. $this->base = new Monster_Base($this->db, $r["base"]);
  73. $this->image = $path["img"]["monster"] . str_pad($id, 4, '0', STR_PAD_LEFT) . ".png";
  74. $this->image_aw = $path["img"]["awaken"] . str_pad($id, 4, '0', STR_PAD_LEFT) . ".png";
  75. }
  76. }
  77. }
  78. ?>