| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- <?php
- /**
- * Team entity file.
- *
- * Creates the entity and makes it available.
- *
- * @category Entity
- */
- /**
- * Require dependent entities if not present.
- */
- require_once(PATH::ENTITY . "Area.php");
- require_once(PATH::ENTITY . "Unit.php");
- /**
- * A Team.
- *
- * Represents an object from the table 'unit'.
- *
- * @category Entity
- */
- class Team extends Entity{
-
- /**
- * @var int Owner's player identifier.
- */
- private $player;
-
- /**
- * @var int Team identifier.
- */
- private $id;
-
- /**
- * @var string Team name.
- */
- private $name;
-
- /**
- * @var string Team description.
- */
- private $description;
-
- private $flag_units = false;
- /**
- * @var \Unit[] Units in the team.
- */
- private $unit = [];
-
- /**
- * @var int ID of the leader unit.
- */
- private $leader;
-
- /**
- * @var int[] List of IDs of the frontline units.
- */
- private $frontline = [];
-
- /**
- * @var Area Area the team is designed for.
- */
- private $area;
-
- /**
- * @var int Stage the team is designed for. It can be null.
- */
- private $stage;
-
- /**
- * @var int difficulty the team is designed for. It can be null.
- *
- * @see DIFFICULTY_ID
- */
- private $difficulty;
-
- /**
- * @var int Team score for the optmizer
- */
- private $score;
-
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * monster, populating it and it's items.
- *
- * @param int $id Monster identifier.
- * @param bool $complete If false, it won't load the units.
- */
- public function __construct($id){
-
- $statement = get_context()->get_db()->prepare("
- SELECT
- player,
- id,
- name,
- description,
- area_type,
- area,
- stage,
- difficulty,
- score
- FROM team
- WHERE id = :id;
- ");
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->player = $r["player"];
- $this->id = $r["id"];
- $this->name = HTML::e($r["name"]);
- $this->description = HTML::e($r["description"]);
- $this->area = new Area($r["area"], $r["area_type"]);
- $this->stage = $r["stage"];
- $this->score = $r["score"];
- }
- }
-
- private function load_units(){
- $statement = get_context()->get_db()->prepare("
- SELECT
- unit,
- leader,
- front
- FROM team_unit
- WHERE team = :team
- ORDER BY
- front DESC,
- leader DESC;
- ");
- $statement->bindValue(':team', $this->id, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->unit, new Unit($r["unit"], false));
- if ($r["leader"] == 1){
- $this->leader = $r["unit"];
- }
- if ($r["front"] == 1){
- array_push($this->frontline, $r["unit"]);
- }
- }
- $this->flag_units = true;
- }
- /**
- * Retrieves the account's player identifier.
- *
- * @return number Player ID.
- */
- public function get_player(){
- return $this->player;
- }
-
- /**
- * Retrieves the team identifier.
- *
- * @return number Team ID.
- */
- public function get_id(){
- return $this->id;
- }
-
- /**
- * Retrieves the team name.
- *
- * @return string Team name.
- */
- public function get_name(){
- return $this->name;
- }
-
- /**
- * Retrieves the team description.
- *
- * @return string Team description (can be an empty string).
- */
- public function get_description(){
- return $this->description;
- }
-
- /**
- * Retrieves the units in the team.
- *
- * @return Unit[] Units in the team.
- */
- public function get_units(){
- if (! $this->flag_units){
- $this->load_units();
- }
- return $this->unit;
- }
-
- /**
- * Retrieves the leader unit's identifier.
- *
- * @return number Leader unit ID.
- */
- public function get_leader(){
- return $this->leader;
- }
-
- /**
- * Retrieves the identifiers of the units in the frontline.
- *
- * @return number[] ID of units in the frontline.
- */
- public function get_frontline(){
- return $this->frontline;
- }
-
- /**
- * Retrieves the area the team is set for.
- *
- * @return Area Team area.
- */
- public function get_area(){
- return $this->area;
- }
-
- /**
- * Retrieves the stage the team is intended to.
- *
- * @return number Team stage, can be null.
- */
- public function get_stage(){
- return $this->stage;
- }
-
- /**
- * Retrieves the difficulty of the area the team is intended for.
- *
- * @see DIFFICULTY_ID
- *
- * @return number Difficulty ID, can be null.
- */
- public function get_difficulty(){
- return $this->difficulty;
- }
-
- /**
- * Retrieves the score of the team for the optimizer.
- *
- * @return number Team score.
- */
- public function get_score(){
- return $this->score;
- }
-
- }
- ?>
|