|
|
@@ -1,378 +1,464 @@
|
|
|
<?php
|
|
|
+/**
|
|
|
+ * Unit entity file.
|
|
|
+ *
|
|
|
+ * Creates the entity and makes it available.
|
|
|
+ *
|
|
|
+ * @category Entity
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * Require dependent entities if not present.
|
|
|
+ */
|
|
|
+require_once(PATH::ENTITY . "Entity.php");
|
|
|
+require_once(PATH::ENTITY . "Monster.php");
|
|
|
+require_once(PATH::ENTITY . "Team.php");
|
|
|
+require_once(PATH::ENTITY . "Rune.php");
|
|
|
+require_once(PATH::ENTITY . "Artifact.php");
|
|
|
+require_once(PATH::ENTITY . "Building.php");
|
|
|
+
|
|
|
+/**
|
|
|
+ * A Unit.
|
|
|
+ *
|
|
|
+ * Represents an object from the table 'unit'.
|
|
|
+ *
|
|
|
+ * @category Entity
|
|
|
+ */
|
|
|
+class Unit extends Entity{
|
|
|
+
|
|
|
+ private $player;
|
|
|
+ private $id;
|
|
|
+ private $building;
|
|
|
+ private $monster;
|
|
|
+ private $stars;
|
|
|
+ private $level;
|
|
|
+ private $experience;
|
|
|
+ private $exp_gained;
|
|
|
+ private $exp_gain_rate;
|
|
|
+ private $flag_experience = false;
|
|
|
+ private $experience_level = 0;
|
|
|
+ private $experience_level_up = 0;
|
|
|
+ private $flag_storage = false;
|
|
|
+ private $in_storage = false;
|
|
|
+ private $title;
|
|
|
+ private $costume;
|
|
|
+ private $flag_source = false;
|
|
|
+ private $source_id;
|
|
|
+ private $source;
|
|
|
+ private $create_time;
|
|
|
+ private $homunculus_name;
|
|
|
+ private $lock;
|
|
|
+ private $base_stats = array(
|
|
|
+ "hp" => 0,
|
|
|
+ "atk" => 0,
|
|
|
+ "def" => 0,
|
|
|
+ "spd" => 0,
|
|
|
+ "crr" => 0,
|
|
|
+ "crd" => 0,
|
|
|
+ "acc" => 0,
|
|
|
+ "res" => 0,
|
|
|
+ "ehp" => 0,
|
|
|
+ "dmg" => 0,
|
|
|
+ );
|
|
|
+ private $rune_stats = array(
|
|
|
+ "hp" => 0,
|
|
|
+ "atk" => 0,
|
|
|
+ "def" => 0,
|
|
|
+ "spd" => 0,
|
|
|
+ "crr" => 0,
|
|
|
+ "crd" => 0,
|
|
|
+ "acc" => 0,
|
|
|
+ "res" => 0,
|
|
|
+ "ehp" => 0,
|
|
|
+ "dmg" => 0,
|
|
|
+ );
|
|
|
+ private $artifact_stats = array(
|
|
|
+ "hp" => 0,
|
|
|
+ "atk" => 0,
|
|
|
+ "def" => 0,
|
|
|
+ "spd" => 0,
|
|
|
+ "crr" => 0,
|
|
|
+ "crd" => 0,
|
|
|
+ "acc" => 0,
|
|
|
+ "res" => 0,
|
|
|
+ "ehp" => 0,
|
|
|
+ "dmg" => 0,
|
|
|
+ );
|
|
|
+ private $flag_buildings = false;
|
|
|
+ private $building_stats = array(
|
|
|
+ "hp" => 0,
|
|
|
+ "atk" => 0,
|
|
|
+ "def" => 0,
|
|
|
+ "spd" => 0,
|
|
|
+ "crr" => 0,
|
|
|
+ "crd" => 0,
|
|
|
+ "acc" => 0,
|
|
|
+ "res" => 0,
|
|
|
+ "ehp" => 0,
|
|
|
+ "dmg" => 0,
|
|
|
+ );
|
|
|
+ private $flag_stats = false;
|
|
|
+ private $stats = array(
|
|
|
+ "hp" => 0,
|
|
|
+ "atk" => 0,
|
|
|
+ "def" => 0,
|
|
|
+ "spd" => 0,
|
|
|
+ "crr" => 0,
|
|
|
+ "crd" => 0,
|
|
|
+ "acc" => 0,
|
|
|
+ "res" => 0,
|
|
|
+ "ehp" => 0,
|
|
|
+ "dmg" => 0,
|
|
|
+ );
|
|
|
+ private $flag_runes = false;
|
|
|
+ private $avg_rune_efficiency = 0.0;
|
|
|
+ private $rune = [];
|
|
|
+ private $artifact_type;
|
|
|
+ private $artifact_element;
|
|
|
+ private $flag_teams = false;
|
|
|
+ private $teams = [];
|
|
|
+ private $flag_skills = false;
|
|
|
+ private $skill_levels = [];
|
|
|
+
|
|
|
/**
|
|
|
- * Unit entity file.
|
|
|
+ * Retrieves the owner's player identifier.
|
|
|
*
|
|
|
- * Creates the entity and makes it available.
|
|
|
+ * @return int Player ID.
|
|
|
+ */
|
|
|
+ public function get_player(){
|
|
|
+ return $this->player;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the unit identifier.
|
|
|
*
|
|
|
- * @category Entity
|
|
|
+ * @return int Unit ID.
|
|
|
*/
|
|
|
-
|
|
|
+ public function get_id(){
|
|
|
+ return $this->id;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * Require dependent entities if not present.
|
|
|
+ * Retrieves the identifier of the building the unit is in, if any.
|
|
|
+ *
|
|
|
+ * @return int Building ID, null if unit not in building.
|
|
|
*/
|
|
|
- require_once(PATH::ENTITY . "Entity.php");
|
|
|
- require_once(PATH::ENTITY . "Monster.php");
|
|
|
- require_once(PATH::ENTITY . "Team.php");
|
|
|
- require_once(PATH::ENTITY . "Rune.php");
|
|
|
- require_once(PATH::ENTITY . "Artifact.php");
|
|
|
- require_once(PATH::ENTITY . "Building.php");
|
|
|
-
|
|
|
+ public function get_building_id(){
|
|
|
+ return $this->building;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * A Unit.
|
|
|
+ * Retrieves the base monster.
|
|
|
*
|
|
|
- * Represents an object from the table 'unit'.
|
|
|
+ * @return Monster The base monster.
|
|
|
+ */
|
|
|
+ public function get_monster(){
|
|
|
+ return $this->monster;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the unit stars (grade).
|
|
|
*
|
|
|
- * @category Entity
|
|
|
+ * @return int Unit stars (1-6).
|
|
|
*/
|
|
|
- class Unit extends Entity{
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Player ID.
|
|
|
- */
|
|
|
- public $player;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit ID.
|
|
|
- */
|
|
|
- public $id;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var Building Building the unit is on.
|
|
|
- */
|
|
|
- public $building;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var Monster Base monster.
|
|
|
- */
|
|
|
- public $monster;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit stars.
|
|
|
- */
|
|
|
- public $stars;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit level.
|
|
|
- */
|
|
|
- public $level;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit base HP stat.
|
|
|
- */
|
|
|
- public $hp;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit base ATK stat.
|
|
|
- */
|
|
|
- public $attack;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit base DEF stat.
|
|
|
- */
|
|
|
- public $defense;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit base SPD stat.
|
|
|
- */
|
|
|
- public $speed;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit base CRR stat.
|
|
|
- */
|
|
|
- public $crit_rate;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit base CRD stat.
|
|
|
- */
|
|
|
- public $crit_damage;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit base RES stat.
|
|
|
- */
|
|
|
- public $resistance;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit base ACC stat.
|
|
|
- */
|
|
|
- public $accuracy;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Total gained experience.
|
|
|
- */
|
|
|
- public $experience;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Total gained experience in its current level.
|
|
|
- */
|
|
|
- public $exp_gained;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Experience / hour in the current building.
|
|
|
- */
|
|
|
- public $exp_gain_rate;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Equipped transmogification.
|
|
|
- */
|
|
|
- public $costume;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var Source Source the unit was aquired from.
|
|
|
- */
|
|
|
- public $source;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var Datetime Time the unit was obtained.
|
|
|
- */
|
|
|
- public $create_time;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var string Indicates the Homunculus name
|
|
|
- */
|
|
|
- public $homunculus_name;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var bool Indicates if the monster is locked.
|
|
|
- */
|
|
|
- public $lock;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit rune HP stat.
|
|
|
- */
|
|
|
- public $rune_hp = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit rune ATK stat.
|
|
|
- */
|
|
|
- public $rune_attack = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit rune DEF stat.
|
|
|
- */
|
|
|
- public $rune_defense = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit rune SPD stat.
|
|
|
- */
|
|
|
- public $rune_speed = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit rune CRR stat.
|
|
|
- */
|
|
|
- public $rune_crit_rate = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit rune CRD stat.
|
|
|
- */
|
|
|
- public $rune_crit_damage = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit rune RES stat.
|
|
|
- */
|
|
|
- public $rune_resistance = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit rune ACC stat.
|
|
|
- */
|
|
|
- public $rune_accuracy = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit artifact HP stat.
|
|
|
- */
|
|
|
- public $artifact_hp = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit artifact ATK stat.
|
|
|
- */
|
|
|
- public $artifact_attack = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit artifact DEF stat.
|
|
|
- */
|
|
|
- public $artifact_defense = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit artifact SPD stat.
|
|
|
- */
|
|
|
- public $artifact_speed = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit artifact CRR stat.
|
|
|
- */
|
|
|
- public $artifact_crit_rate = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit artifact CRD stat.
|
|
|
- */
|
|
|
- public $artifact_crit_damage = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit artifact RES stat.
|
|
|
- */
|
|
|
- public $artifact_resistance = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit artifact ACC stat.
|
|
|
- */
|
|
|
- public $artifact_accuracy = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit building HP stat.
|
|
|
- */
|
|
|
- public $building_hp = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit building ATK stat.
|
|
|
- */
|
|
|
- public $building_attack = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit building DEF stat.
|
|
|
- */
|
|
|
- public $building_defense = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit building SPD stat.
|
|
|
- */
|
|
|
- public $building_speed = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit building CRR stat.
|
|
|
- */
|
|
|
- public $building_crit_rate = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit building CRD stat.
|
|
|
- */
|
|
|
- public $building_crit_damage = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit building RES stat.
|
|
|
- */
|
|
|
- public $building_resistance = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit building ACC stat.
|
|
|
- */
|
|
|
- public $building_accuracy = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit total HP stat.
|
|
|
- */
|
|
|
- public $total_hp = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit total ATK stat.
|
|
|
- */
|
|
|
- public $total_attack = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit total DEF stat.
|
|
|
- */
|
|
|
- public $total_defense = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit total SPD stat.
|
|
|
- */
|
|
|
- public $total_speed = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit total CRR stat.
|
|
|
- */
|
|
|
- public $total_crit_rate = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit total CRD stat.
|
|
|
- */
|
|
|
- public $total_crit_damage = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit total RES stat.
|
|
|
- */
|
|
|
- public $total_resistance = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit total ACC stat.
|
|
|
- */
|
|
|
- public $total_accuracy = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit effective HP
|
|
|
- */
|
|
|
- public $effective_hp = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Unit effective damage
|
|
|
- */
|
|
|
- public $effective_dmg = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var float Average rune efficiency.
|
|
|
- */
|
|
|
- public $avg_rune_efficiency = 0.0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var \Rune[] Equiped Runes.
|
|
|
- */
|
|
|
- public $rune = [];
|
|
|
-
|
|
|
- /**
|
|
|
- * @var Artifact Type artifact equipped.
|
|
|
- */
|
|
|
- public $artifact_type;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var Artifact Elemental artifact equipped.
|
|
|
- */
|
|
|
- public $artifact_element;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var \Team[] The Teamss the unit is on.
|
|
|
- */
|
|
|
- public $teams = [];
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int[] Array with the levels of the skills, in orer.
|
|
|
- */
|
|
|
- public $skill_levels = [];
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Total experience required for the current level.
|
|
|
- */
|
|
|
- public $experience_level = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var int Experience required to level up.
|
|
|
- */
|
|
|
- public $experience_level_up = 0;
|
|
|
+ public function get_stars(){
|
|
|
+ return $this->stars;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the unit current level.
|
|
|
+ *
|
|
|
+ * @return int Unit level.
|
|
|
+ */
|
|
|
+ public function get_level(){
|
|
|
+ return $this->level;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the unit's base stats.
|
|
|
+ *
|
|
|
+ * It's an associative array with the following keys:
|
|
|
+ * atk, def, hp, spd, crr, crd, acc, res, ehp, dmg
|
|
|
+ *
|
|
|
+ * @return int[] Unit stats.
|
|
|
+ */
|
|
|
+ public function get_base_stats(){
|
|
|
+ return $this->base_stats;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * @var int Indcates if the unit is in storage.
|
|
|
- */
|
|
|
- public $in_storage = false;
|
|
|
+ /**
|
|
|
+ * Retrieves the unit's stats provided by runes.
|
|
|
+ *
|
|
|
+ * It's an associative array with the following keys:
|
|
|
+ * atk, def, hp, spd, crr, crd, acc, res, ehp, dmg
|
|
|
+ *
|
|
|
+ * @return int[] Rune stats.
|
|
|
+ */
|
|
|
+ public function get_rune_stats(){
|
|
|
+ if (! $this->flag_runes){
|
|
|
+ $this->load_runes();
|
|
|
+ }
|
|
|
+ return $this->rune_stats;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the unit's stats provided by artifacts.
|
|
|
+ *
|
|
|
+ * It's an associative array with the following keys:
|
|
|
+ * atk, def, hp, spd, crr, crd, acc, res, ehp, dmg
|
|
|
+ * Note that only "atk", "def", "hp", "dmg" and "ehp" can me non-zero.
|
|
|
+ *
|
|
|
+ * @return int[] Artifact stats.
|
|
|
+ */
|
|
|
+ public function get_artifact_stats(){
|
|
|
+ if (! $this->flag_runes){
|
|
|
+ $this->load_runes();
|
|
|
+ }
|
|
|
+ return $this->artifact_stats;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * @var string Unit title.
|
|
|
- * If Homunculus,it will be it's name.
|
|
|
- * If awakened, it will be the awakened from name.
|
|
|
- * If unawakened, it will be <element> <name>.
|
|
|
- */
|
|
|
- public $title;
|
|
|
+ /**
|
|
|
+ * Retrieves the unit's stat bonus provided by buildings.
|
|
|
+ * Only building bonuses are considered.
|
|
|
+ *
|
|
|
+ * It's an associative array with the following keys:
|
|
|
+ * atk, def, hp, spd, crr, crd, acc, res, ehp, dmg
|
|
|
+ *
|
|
|
+ * @return int[] Building stats.
|
|
|
+ */
|
|
|
+ public function get_building_stats(){
|
|
|
+ if (! $this->flag_buildings){
|
|
|
+ $this->load_buildings();
|
|
|
+ }
|
|
|
+ return $this->building_stats;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 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, query only unit and monster.
|
|
|
- */
|
|
|
- public function __construct($id, $complete = true, $player = -1){
|
|
|
- if ($player == -1 && null != get_context()->get_player()){
|
|
|
- $player = get_context()->get_player()->get_id();
|
|
|
- }
|
|
|
- $statement = get_context()->get_db()->prepare("
|
|
|
+ /**
|
|
|
+ * Retrieves the unit's stats.
|
|
|
+ *
|
|
|
+ * It's an associative array with the following keys:
|
|
|
+ * atk, def, hp, spd, crr, crd, acc, res, ehp, dmg
|
|
|
+ *
|
|
|
+ * Includes the unit base stats, the runes and artifact increases and the building bonuses.
|
|
|
+ *
|
|
|
+ * @return int[] Unit stats.
|
|
|
+ */
|
|
|
+ public function get_stats(){
|
|
|
+ if (! $this->flag_stats){
|
|
|
+ $this->load_stats();
|
|
|
+ }
|
|
|
+ return $this->stats;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the total experience earned by the unit.
|
|
|
+ *
|
|
|
+ * @return int Total experience.
|
|
|
+ */
|
|
|
+ public function get_experience(){
|
|
|
+ return $this->experience;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the total experience earned by the unit since it's level is the current one..
|
|
|
+ *
|
|
|
+ * @return int Current level experience.
|
|
|
+ */
|
|
|
+ public function get_current_level_experience(){
|
|
|
+ return $this->exp_gained;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the experience being gained by the hour from a building.
|
|
|
+ *
|
|
|
+ * @return int Experience by the hour, 0 if not in an exp building.
|
|
|
+ */
|
|
|
+ public function get_exp_gain_rate(){
|
|
|
+ return $this->exp_gain_rate;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the current transmogrification identifier.
|
|
|
+ *
|
|
|
+ * @return int Transmogification ID, null if none.
|
|
|
+ */
|
|
|
+ public function get_costume(){
|
|
|
+ return $this->costume;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the $source the unit was obtained from.
|
|
|
+ *
|
|
|
+ * @return Source Unit source.
|
|
|
+ */
|
|
|
+ public function get_source(){
|
|
|
+ if (! $this->flag_source){
|
|
|
+ $this->load_source();
|
|
|
+ }
|
|
|
+ return $this->source;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Gets the date the unit was obtained.
|
|
|
+ *
|
|
|
+ * If $format is supplied, a string in the desired format will be returned. If not, the raw
|
|
|
+ * DateTime object will e returned.
|
|
|
+ *
|
|
|
+ * @param string $format A date format (optional).
|
|
|
+ * @return DateTime | string The raw date, or a formatted version.
|
|
|
+ */
|
|
|
+ public function get_creation_time($format = null){
|
|
|
+ if (null == $format){
|
|
|
+ return $this->create_time;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return $this->create_time->format($format);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the name if the unit is an homunculus.
|
|
|
+ *
|
|
|
+ * @return string Homunculus name, null if not Homunculus.
|
|
|
+ */
|
|
|
+ public function get_homunculus_name(){
|
|
|
+ return $this->homunculus_name;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Checks if the unit is locked.
|
|
|
+ *
|
|
|
+ * @return boolean True if locked, false if unlocked.
|
|
|
+ */
|
|
|
+ public function is_locked(){
|
|
|
+ return $this->lock;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the average rune efficiency.
|
|
|
+ *
|
|
|
+ * @return number Average efficiency of the runes.
|
|
|
+ */
|
|
|
+ public function get_avg_rune_efficiency(){
|
|
|
+ if (! $this->flag_runes){
|
|
|
+ $this->load_runes();
|
|
|
+ }
|
|
|
+ return $this->avg_rune_efficiency;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the currently equipped runes.
|
|
|
+ *
|
|
|
+ * @return Rune[]
|
|
|
+ */
|
|
|
+ public function get_runes(){
|
|
|
+ if (! $this->flag_runes){
|
|
|
+ $this->load_runes();
|
|
|
+ }
|
|
|
+ return $this->rune;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves equipped artifacts.
|
|
|
+ * Can be read with the indexes ARTIFACT_TYPE:ELEMENT and ARTIFACT_TYPE:ARCHETYPE.
|
|
|
+ *
|
|
|
+ * @see ARTIFACT_TYPE
|
|
|
+ *
|
|
|
+ * @return Artifact[] Equiped artifact array. Null positions if not equipped.
|
|
|
+ */
|
|
|
+ public function get_artifacts(){
|
|
|
+ if (! $this->flag_runes){
|
|
|
+ $this->load_runes();
|
|
|
+ }
|
|
|
+ return [$this->artifact_element, $this->artifact_type];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves $teams
|
|
|
+ *
|
|
|
+ * @return multitype:Team
|
|
|
+ */
|
|
|
+ public function get_teams(){
|
|
|
+ if (! $this->flag_teams){
|
|
|
+ $this->load_teams();
|
|
|
+ }
|
|
|
+ return $this->teams;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves $skill_levels
|
|
|
+ *
|
|
|
+ * @return multitype:number
|
|
|
+ */
|
|
|
+ public function get_skill_levels(){
|
|
|
+ if (! $this->flag_skills){
|
|
|
+ $this->load_skill();
|
|
|
+ }
|
|
|
+ return $this->skill_levels;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the total experience required for the current level.
|
|
|
+ *
|
|
|
+ * @return int Level experience.
|
|
|
+ */
|
|
|
+ public function get_experience_level(){
|
|
|
+ if (! $this->flag_experience){
|
|
|
+ $this->load_experience();
|
|
|
+ }
|
|
|
+ return $this->experience_level;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the experience required to level-up.
|
|
|
+ *
|
|
|
+ * @return int Experience to level-up.
|
|
|
+ */
|
|
|
+ public function get_experience_level_up(){
|
|
|
+ if (! $this->flag_experience){
|
|
|
+ $this->load_experience();
|
|
|
+ }
|
|
|
+ return $this->experience_level_up;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Checks if the unit is in storage.
|
|
|
+ *
|
|
|
+ * @return boolean True if in storage, false otherwise.
|
|
|
+ */
|
|
|
+ public function is_in_storage(){
|
|
|
+ if (! $this->flag_storage){
|
|
|
+ $this->load_storage();
|
|
|
+ }
|
|
|
+ return $this->in_storage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieves the unit's title.
|
|
|
+ * If Homunculus,it will be it's name.
|
|
|
+ * If awakened, it will be the awakened from name.
|
|
|
+ * If unawakened, it will be <element> <name>.
|
|
|
+ *
|
|
|
+ * @return string The unit's title.
|
|
|
+ */
|
|
|
+ public function get_title(){
|
|
|
+ return $this->title;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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, query only unit and monster.
|
|
|
+ */
|
|
|
+ public function __construct($id, $complete = true, $player = -1){
|
|
|
+ if ($player == -1 && null != get_context()->get_player()){
|
|
|
+ $player = get_context()->get_player()->get_id();
|
|
|
+ }
|
|
|
+ $statement = get_context()->get_db()->prepare("
|
|
|
SELECT
|
|
|
player,
|
|
|
id,
|
|
|
@@ -400,85 +486,95 @@
|
|
|
WHERE
|
|
|
id = :id;
|
|
|
");
|
|
|
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
|
|
|
- $statement->bindValue(':player', $player, SQLITE3_TEXT);
|
|
|
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
|
- if ($r){
|
|
|
- $this->player = $r["player"];
|
|
|
- $this->id = $r["id"];
|
|
|
- if ($r["building"] != null && $r["building"] > 0){
|
|
|
- $this->building = new Building($r["building"]);
|
|
|
- }
|
|
|
- if (strlen($r["monster"]) > 0){
|
|
|
- $this->monster = new Monster($r["monster"], $complete);
|
|
|
- }
|
|
|
- $this->stars = $r["stars"];
|
|
|
- $this->level = $r["level"];
|
|
|
- $this->hp = $r["hp"];
|
|
|
- $this->attack = $r["attack"];
|
|
|
- $this->defense = $r["defense"];
|
|
|
- $this->speed = $r["speed"];
|
|
|
- $this->crit_rate = $r["crit_rate"];
|
|
|
- $this->crit_damage = $r["crit_damage"];
|
|
|
- $this->resistance = $r["resistance"];
|
|
|
- $this->accuracy = $r["accuracy"];
|
|
|
- $this->experience = $r["experience"];
|
|
|
- $this->exp_gained = $r["exp_gained"];
|
|
|
- $this->exp_gain_rate = $r["exp_gain_rate"];
|
|
|
- $this->costume = $r["costume"];
|
|
|
- $this->source = new Source($r["source"]);
|
|
|
- $this->create_time = date_create($r["create_time"]);
|
|
|
- $this->homunculus_name = $r["homunculus_name"];
|
|
|
- if ($complete){
|
|
|
- $this->load_stats();
|
|
|
- $this->load_teams();
|
|
|
- $this->check_storage();
|
|
|
- $this->lock = $r["lock"];
|
|
|
- $statement = get_context()->get_db()->prepare("
|
|
|
- SELECT level
|
|
|
- FROM
|
|
|
- unit_skill,
|
|
|
- skill
|
|
|
- WHERE
|
|
|
- skill.id = unit_skill.skill AND
|
|
|
- unit_skill.unit = :unit
|
|
|
- ORDER BY slot;
|
|
|
- ");
|
|
|
- $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
|
|
|
- $q = $statement->execute();
|
|
|
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
- array_push($this->skill_levels, $r["level"]);
|
|
|
- }
|
|
|
- $statement = get_context()->get_db()->prepare("
|
|
|
- SELECT exp
|
|
|
- FROM experience
|
|
|
- WHERE
|
|
|
- stars = :stars AND
|
|
|
- level = :level;
|
|
|
- ");
|
|
|
- $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
|
|
|
- $statement->bindValue(':level', $this->level, SQLITE3_TEXT);
|
|
|
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
|
- if ($r){
|
|
|
- $this->experience_level = $r["exp"];
|
|
|
- $this->experience_level_up = $r["exp"] - $this->exp_gained;
|
|
|
- }
|
|
|
- }
|
|
|
- if ($this->monster->homunculus){
|
|
|
- $this->title = $this->homunculus_name;
|
|
|
- }
|
|
|
- else{
|
|
|
- $this->title = $this->monster->title;
|
|
|
- }
|
|
|
+ $statement->bindValue(':id', $id, SQLITE3_TEXT);
|
|
|
+ $statement->bindValue(':player', $player, SQLITE3_TEXT);
|
|
|
+ $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
|
+ if ($r){
|
|
|
+ $this->player = $r["player"];
|
|
|
+ $this->id = $r["id"];
|
|
|
+ if ($r["building"] != null && $r["building"] > 0){
|
|
|
+ $this->building = $r["building"];
|
|
|
+ }
|
|
|
+ if (strlen($r["monster"]) > 0){
|
|
|
+ $this->monster = new Monster($r["monster"]);
|
|
|
+ }
|
|
|
+ $this->stars = $r["stars"];
|
|
|
+ $this->level = $r["level"];
|
|
|
+ $this->base_stats["hp"] = $r["hp"];
|
|
|
+ $this->base_stats["atk"] = $r["attack"];
|
|
|
+ $this->base_stats["def"] = $r["defense"];
|
|
|
+ $this->base_stats["spd"] = $r["speed"];
|
|
|
+ $this->base_stats["crr"] = $r["crit_rate"];
|
|
|
+ $this->base_stats["crd"] = $r["crit_damage"];
|
|
|
+ $this->base_stats["res"] = $r["resistance"];
|
|
|
+ $this->base_stats["acc"] = $r["accuracy"];
|
|
|
+ $this->base_stats["ehp"] = APPLICATION::calculate_ehp($r["hp"], $r["defense"]);
|
|
|
+ $this->base_stats["dmg"] = APPLICATION::calculate_dmg($r["attack"], $r["crit_rate"], $r["crit_damage"]);
|
|
|
+
|
|
|
+ $this->experience = $r["experience"];
|
|
|
+ $this->exp_gained = $r["exp_gained"];
|
|
|
+ $this->exp_gain_rate = $r["exp_gain_rate"];
|
|
|
+ $this->costume = $r["costume"];
|
|
|
+ if ($r["source"]){
|
|
|
+ $this->source_id = $r["source"];
|
|
|
+ }
|
|
|
+ $this->create_time = new Datetime();
|
|
|
+ $this->create_time->setTimestamp($r["create_time"]);
|
|
|
+ $this->homunculus_name = $r["homunculus_name"];
|
|
|
+ if ($this->monster->is_homunculus()){
|
|
|
+ $this->title = $this->homunculus_name;
|
|
|
}
|
|
|
+ else{
|
|
|
+ $this->title = $this->monster->get_title();
|
|
|
+ }
|
|
|
+ $this->lock = $r["lock"];
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Checks if the monster is in storage and sets {@see $in_storage} to
|
|
|
- * true or false.
|
|
|
- */
|
|
|
- public function check_storage(){
|
|
|
- $statement = get_context()->get_db()->prepare("
|
|
|
+ }
|
|
|
+
|
|
|
+ private function load_skills(){
|
|
|
+ $statement = get_context()->get_db()->prepare("
|
|
|
+ SELECT level
|
|
|
+ FROM
|
|
|
+ unit_skill,
|
|
|
+ skill
|
|
|
+ WHERE
|
|
|
+ skill.id = unit_skill.skill AND
|
|
|
+ unit_skill.unit = :unit
|
|
|
+ ORDER BY slot;
|
|
|
+ ");
|
|
|
+ $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
|
|
|
+ $q = $statement->execute();
|
|
|
+ while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
+ array_push($this->skill_levels, $r["level"]);
|
|
|
+ }
|
|
|
+ $this->flag_skills = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function load_experience(){
|
|
|
+ $statement = get_context()->get_db()->prepare("
|
|
|
+ SELECT exp
|
|
|
+ FROM experience
|
|
|
+ WHERE
|
|
|
+ stars = :stars AND
|
|
|
+ level = :level;
|
|
|
+ ");
|
|
|
+ $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
|
|
|
+ $statement->bindValue(':level', $this->level, SQLITE3_TEXT);
|
|
|
+ $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
|
+ if ($r){
|
|
|
+ $this->experience_level = $r["exp"];
|
|
|
+ $this->experience_level_up = $r["exp"] - $this->exp_gained;
|
|
|
+ }
|
|
|
+ $this->flag_experience = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Checks if the monster is in storage and sets {@see $in_storage} to
|
|
|
+ * true or false.
|
|
|
+ */
|
|
|
+ private function load_storage(){
|
|
|
+ $statement = get_context()->get_db()->prepare("
|
|
|
SELECT 1
|
|
|
FROM
|
|
|
unit,
|
|
|
@@ -490,255 +586,266 @@
|
|
|
unit.building = building.id AND
|
|
|
building.buildable = :buildable;
|
|
|
");
|
|
|
- $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
|
|
|
- $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
|
|
|
- $statement->bindValue(':buildable', BUILDING_ID::MONSTER_STORAGE, SQLITE3_TEXT);
|
|
|
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
|
- if ($r){
|
|
|
- $this->in_storage = true;
|
|
|
- }
|
|
|
- else{
|
|
|
- $this->in_storage = false;
|
|
|
- }
|
|
|
+ $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
|
|
|
+ $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
|
|
|
+ $statement->bindValue(':buildable', BUILDING_ID::MONSTER_STORAGE, SQLITE3_TEXT);
|
|
|
+ $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
|
+ if ($r){
|
|
|
+ $this->in_storage = true;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * Calculates the stats gained from runes, artifacts and buildings.
|
|
|
- * Calculates the totalls and the effective stats.
|
|
|
- *
|
|
|
- * @gobal Player Currently selected player.
|
|
|
- * @gobal int Game mode (Normal/RTA).
|
|
|
- */
|
|
|
- public function load_stats(){
|
|
|
-
|
|
|
- // Runes
|
|
|
- $this->rune = [];
|
|
|
- $statement = get_context()->get_db()->prepare("
|
|
|
- SELECT rune
|
|
|
- FROM unit_rune
|
|
|
- WHERE
|
|
|
- unit = :unit AND
|
|
|
- rta = :rta;
|
|
|
- ");
|
|
|
- $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
|
|
|
- $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
|
|
|
- $q = $statement->execute();
|
|
|
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
- array_push($this->rune, new Rune($r["rune"]));
|
|
|
- }
|
|
|
- foreach ($this->rune as $rune){
|
|
|
- foreach ($rune->stats as $stat){
|
|
|
- $this->sum_rune_stat($stat->stat, $stat->value + $stat->grind);
|
|
|
- }
|
|
|
- }
|
|
|
- $this->rune_attack = ceil($this->rune_attack);
|
|
|
- $this->rune_defense = ceil($this->rune_defense);
|
|
|
- $this->rune_hp = ceil($this->rune_hp);
|
|
|
-
|
|
|
- // Artifacts
|
|
|
- $this->artifact = [];
|
|
|
- $statement = get_context()->get_db()->prepare("
|
|
|
- SELECT artifact
|
|
|
- FROM unit_artifact
|
|
|
- WHERE
|
|
|
- unit = :unit AND
|
|
|
- rta = :rta;
|
|
|
- ");
|
|
|
- $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
|
|
|
- $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
|
|
|
- $q = $statement->execute();
|
|
|
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
- $artifact = new Artifact($r["artifact"]);
|
|
|
- if ($artifact->type == ARTIFACT_TYPE::ARCHETYPE){
|
|
|
- $this->artifact_type = $artifact;
|
|
|
- }
|
|
|
- else{
|
|
|
- $this->artifact_element = $artifact;
|
|
|
- }
|
|
|
- switch($artifact->stat->getStat()){
|
|
|
- case ARTIFACT_STAT_ID::ATK:
|
|
|
- $this->artifact_attack += $artifact->stat->getValue();
|
|
|
- break;
|
|
|
- case ARTIFACT_STAT_ID::DEF:
|
|
|
- $this->artifact_defense += $artifact->stat->getValue();
|
|
|
- break;
|
|
|
- case ARTIFACT_STAT_ID::HP:
|
|
|
- $this->artifact_hp += $artifact->stat->getValue();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Buildings
|
|
|
- $statement = get_context()->get_db()->prepare("
|
|
|
- SELECT
|
|
|
- affected_stat,
|
|
|
- bonus,
|
|
|
- element
|
|
|
- FROM
|
|
|
- decorative,
|
|
|
- decorative_level,
|
|
|
- decoration
|
|
|
- WHERE
|
|
|
- decoration.player = :player AND
|
|
|
- decorative.id = decoration.decorative AND
|
|
|
- decoration.decorative = decorative_level.decorative AND
|
|
|
- decoration.level = decorative_level.level AND
|
|
|
- area = :area AND
|
|
|
- affected_stat IN (:stat_atk, :stat_def, :stat_hp, :stat_spd, :stat_crd);
|
|
|
- ");
|
|
|
- $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
|
|
|
- $statement->bindValue(':area', EFFECT_AREA_ID::GENERAL, SQLITE3_INTEGER);
|
|
|
- $statement->bindValue(':stat_atk', STAT_ID::ATK, SQLITE3_INTEGER);
|
|
|
- $statement->bindValue(':stat_def', STAT_ID::DEF, SQLITE3_INTEGER);
|
|
|
- $statement->bindValue(':stat_hp', STAT_ID::HP, SQLITE3_INTEGER);
|
|
|
- $statement->bindValue(':stat_spd', STAT_ID::SPD, SQLITE3_INTEGER);
|
|
|
- $statement->bindValue(':stat_crd', STAT_ID::CRIT_DMG, SQLITE3_INTEGER);
|
|
|
- $q = $statement->execute();
|
|
|
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
- switch($r["affected_stat"]){
|
|
|
- case STAT_ID::DEF:
|
|
|
- $this->building_defense += ($this->defense * $r["bonus"] / 100);
|
|
|
- break;
|
|
|
- case STAT_ID::HP:
|
|
|
- $this->building_hp += ($this->hp * $r["bonus"] / 100);
|
|
|
- break;
|
|
|
- case STAT_ID::SPD:
|
|
|
- $this->building_speed += ($this->speed * $r["bonus"] / 100);
|
|
|
- break;
|
|
|
- case STAT_ID::CRIT_DMG:
|
|
|
- $this->building_crit_damage += $r["bonus"];
|
|
|
- break;
|
|
|
- case STAT_ID::ATK:
|
|
|
- if(strlen($r["element"]) > 0 && $r["element"] == $this->monster->element){
|
|
|
- $this->building_attack += ($this->attack * $r["bonus"] / 100);
|
|
|
- }
|
|
|
- else{
|
|
|
- $this->building_attack += ($this->attack * $r["bonus"] / 100);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- $this->building_attack = ceil($this->building_attack);
|
|
|
- $this->building_defense = ceil($this->building_defense);
|
|
|
- $this->building_hp = ceil($this->building_hp);
|
|
|
- $this->building_speed = ceil($this->building_speed);
|
|
|
- $this->building_crit_damage = ceil($this->building_crit_damage);
|
|
|
-
|
|
|
- // Totals
|
|
|
- $this->total_hp = $this->hp + $this->rune_hp + $this->building_hp + $this->artifact_hp;
|
|
|
- $this->total_attack = $this->attack + $this->rune_attack + $this->building_attack + $this->artifact_attack;
|
|
|
- $this->total_defense = $this->defense + $this->rune_defense + $this->building_defense + $this->artifact_defense;
|
|
|
- $this->total_speed = $this->speed + $this->rune_speed + $this->building_speed;
|
|
|
- $this->total_crit_rate = $this->crit_rate + $this->rune_crit_rate + $this->building_crit_rate;
|
|
|
- $this->total_crit_damage = $this->crit_damage + $this->rune_crit_damage + $this->building_crit_damage;
|
|
|
- $this->total_accuracy = $this->accuracy + $this->rune_accuracy + $this->building_accuracy;
|
|
|
- $this->total_resistance = $this->resistance + $this->rune_resistance + $this->building_resistance;
|
|
|
-
|
|
|
- // Effective stats
|
|
|
- $ehp = 0;
|
|
|
- $edmg = 0;
|
|
|
-
|
|
|
- // Calculate effective_hp
|
|
|
- $hp = $this->total_hp;
|
|
|
- $def = $this->total_defense;
|
|
|
- $ehp = ceil(((($def * 3.5) + 1140) * $hp) / 1000);
|
|
|
- $this->effective_hp = $ehp;
|
|
|
-
|
|
|
- // Calculate effective_dmg
|
|
|
- $atk = $this->total_attack;
|
|
|
- $crr = $this->total_crit_rate;
|
|
|
- if ($crr > 100){
|
|
|
- $crr = 100;
|
|
|
- }
|
|
|
- $crd = $this->total_crit_damage;
|
|
|
- $edmg = ceil(($atk * (100 - $crr) / 100) + (($atk + ($atk * $crd / 100)) * $crr / 100));
|
|
|
- $this->effective_dmg = $edmg;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * Loads the {@see teams} array, with the teams the unit is on.
|
|
|
- */
|
|
|
- public function load_teams(){
|
|
|
- $this->teams = [];
|
|
|
- $statement = get_context()->get_db()->prepare("
|
|
|
- SELECT DISTINCT team.id AS id
|
|
|
- FROM
|
|
|
- team,
|
|
|
- team_unit
|
|
|
- WHERE
|
|
|
- team.player = :player AND
|
|
|
- team.id = team_unit.team AND
|
|
|
- team_unit.unit = :unit;
|
|
|
- ");
|
|
|
- $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
|
|
|
- $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
|
|
|
- $q = $statement->execute();
|
|
|
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
- array_push($this->teams, new Team($r["id"], false));
|
|
|
- }
|
|
|
+ else{
|
|
|
+ $this->in_storage = false;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * Calculates the stat increase by a rune property.
|
|
|
- *
|
|
|
- * @param string $stat Stat type.
|
|
|
- * @param int $value Stat increase value.
|
|
|
- */
|
|
|
- private function sum_rune_stat($stat, $value){
|
|
|
- switch ($stat){
|
|
|
- case RUNE_STAT_ID::ATK:
|
|
|
- $this->rune_attack += $value;
|
|
|
- break;
|
|
|
- case RUNE_STAT_ID::DEF:
|
|
|
- $this->rune_defense += $value;
|
|
|
- break;
|
|
|
- case RUNE_STAT_ID::HP:
|
|
|
- $this->rune_hp += $value;
|
|
|
- break;
|
|
|
- case RUNE_STAT_ID::SPD:
|
|
|
- $this->rune_speed += $value;
|
|
|
+ $this->flag_storage = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function load_buildings(){
|
|
|
+ $statement = get_context()->get_db()->prepare("
|
|
|
+ SELECT
|
|
|
+ affected_stat,
|
|
|
+ bonus,
|
|
|
+ element
|
|
|
+ FROM
|
|
|
+ decorative,
|
|
|
+ decorative_level,
|
|
|
+ decoration
|
|
|
+ WHERE
|
|
|
+ decoration.player = :player AND
|
|
|
+ decorative.id = decoration.decorative AND
|
|
|
+ decoration.decorative = decorative_level.decorative AND
|
|
|
+ decoration.level = decorative_level.level AND
|
|
|
+ area = :area AND
|
|
|
+ affected_stat IN (:stat_atk, :stat_def, :stat_hp, :stat_spd, :stat_crd);
|
|
|
+ ");
|
|
|
+ $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
|
|
|
+ $statement->bindValue(':area', EFFECT_AREA_ID::GENERAL, SQLITE3_INTEGER);
|
|
|
+ $statement->bindValue(':stat_atk', STAT_ID::ATK, SQLITE3_INTEGER);
|
|
|
+ $statement->bindValue(':stat_def', STAT_ID::DEF, SQLITE3_INTEGER);
|
|
|
+ $statement->bindValue(':stat_hp', STAT_ID::HP, SQLITE3_INTEGER);
|
|
|
+ $statement->bindValue(':stat_spd', STAT_ID::SPD, SQLITE3_INTEGER);
|
|
|
+ $statement->bindValue(':stat_crd', STAT_ID::CRIT_DMG, SQLITE3_INTEGER);
|
|
|
+ $q = $statement->execute();
|
|
|
+ while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
+ switch($r["affected_stat"]){
|
|
|
+ case STAT_ID::DEF:
|
|
|
+ $this->building_stats["def"] += ($this->base_stats["def"]* $r["bonus"] / 100);
|
|
|
break;
|
|
|
- case RUNE_STAT_ID::CRR:
|
|
|
- $this->rune_crit_rate += $value;
|
|
|
+ case STAT_ID::HP:
|
|
|
+ $this->building_stats["hp"] += ($this->base_stats["hp"]* $r["bonus"] / 100);
|
|
|
break;
|
|
|
- case RUNE_STAT_ID::CRD:
|
|
|
- $this->rune_crit_damage += $value;
|
|
|
+ case STAT_ID::SPD:
|
|
|
+ $this->building_stats["spd"] += ($this->base_stats["spd"]* $r["bonus"] / 100);
|
|
|
break;
|
|
|
- case RUNE_STAT_ID::ACC:
|
|
|
- $this->rune_accuracy += $value;
|
|
|
+ case STAT_ID::CRIT_DMG:
|
|
|
+ $this->building_stats["crd"] += $r["bonus"];
|
|
|
break;
|
|
|
- case RUNE_STAT_ID::RES:
|
|
|
- $this->rune_resistance += $value;
|
|
|
+ case STAT_ID::ATK:
|
|
|
+ if(strlen($r["element"]) > 0 && $r["element"] == $this->monster->get_element()){
|
|
|
+ $this->building_stats["atk"] += ($this->base_stats["atk"]* $r["bonus"] / 100);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ $this->building_stats["atk"] += ($this->base_stats["atk"]* $r["bonus"] / 100);
|
|
|
+ }
|
|
|
break;
|
|
|
- case RUNE_STAT_ID::ATK_P:
|
|
|
- $this->rune_attack += ($this->attack * $value / 100);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->building_stats["hp"] = ceil($this->building_stats["hp"]);
|
|
|
+ $this->building_stats["atk"] = ceil($this->building_stats["atk"]);
|
|
|
+ $this->building_stats["def"] = ceil($this->building_stats["def"]);
|
|
|
+ $this->building_stats["spd"] = ceil($this->building_stats["spd"]);
|
|
|
+ $this->building_stats["ehp"] = APPLICATION::calculate_ehp($this->building_stats["hp"], $this->building_stats["def"]);
|
|
|
+ $this->building_stats["dmg"] = APPLICATION::calculate_dmg($this->building_stats["atk"], $this->building_stats["crr"], $this->building_stats["crd"]);
|
|
|
+ $this->flag_buildings = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function load_source(){
|
|
|
+ if ($this->source_id != null){
|
|
|
+ $this->source = new Source($this->source_id);
|
|
|
+ }
|
|
|
+ $this->flag_source = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function load_runes(){
|
|
|
+ // Runes
|
|
|
+ $statement = get_context()->get_db()->prepare("
|
|
|
+ SELECT rune
|
|
|
+ FROM unit_rune
|
|
|
+ WHERE
|
|
|
+ unit = :unit AND
|
|
|
+ rta = :rta;
|
|
|
+ ");
|
|
|
+ $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
|
|
|
+ $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
|
|
|
+ $q = $statement->execute();
|
|
|
+ while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
+ array_push($this->rune, new Rune($r["rune"]));
|
|
|
+ }
|
|
|
+ foreach ($this->rune as $rune){
|
|
|
+ foreach ($rune->stats as $stat){
|
|
|
+ $this->sum_rune_stat($stat->stat, $stat->value + $stat->grind);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->rune_stats["atk"] = ceil($this->rune_stats["atk"]);
|
|
|
+ $this->rune_stats["def"] = ceil($this->rune_stats["def"]);
|
|
|
+ $this->rune_stats["hp"] = ceil($this->rune_stats["hp"]);
|
|
|
+ $this->rune_stats["ehp"] = APPLICATION::calculate_ehp($this->rune_stats["hp"], $this->rune_stats["def"]);
|
|
|
+ $this->rune_stats["dmg"] = APPLICATION::calculate_dmg($this->rune_stats["atk"], $this->rune_stats["crr"], $this->rune_stats["crd"]);
|
|
|
+
|
|
|
+ // Artifacts
|
|
|
+ $this->artifact = [];
|
|
|
+ $statement = get_context()->get_db()->prepare("
|
|
|
+ SELECT artifact
|
|
|
+ FROM unit_artifact
|
|
|
+ WHERE
|
|
|
+ unit = :unit AND
|
|
|
+ rta = :rta;
|
|
|
+ ");
|
|
|
+ $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
|
|
|
+ $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
|
|
|
+ $q = $statement->execute();
|
|
|
+ while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
+ $artifact = new Artifact($r["artifact"]);
|
|
|
+ if ($artifact->is_archetypal()){
|
|
|
+ $this->artifact_type = $artifact;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ $this->artifact_element = $artifact;
|
|
|
+ }
|
|
|
+ switch($artifact->get_stat()->get_stat()){
|
|
|
+ case ARTIFACT_STAT_ID::ATK:
|
|
|
+ $this->artifact_stats["atk"] += $artifact->get_stat()->get_value();
|
|
|
break;
|
|
|
- case RUNE_STAT_ID::DEF_P:
|
|
|
- $this->rune_defense += ($this->defense * $value / 100);
|
|
|
+ case ARTIFACT_STAT_ID::DEF:
|
|
|
+ $this->artifact_stats["def"] += $artifact->get_stat()->get_value();
|
|
|
break;
|
|
|
- case RUNE_STAT_ID::HP_P:
|
|
|
- $this->rune_hp += ($this->hp * $value / 100);
|
|
|
+ case ARTIFACT_STAT_ID::HP:
|
|
|
+ $this->artifact_stats["hp"] += $artifact->get_stat()->get_value();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Checks if the unit skills are completly maxed.
|
|
|
- *
|
|
|
- * @return bool True if all skills maxed, false otherwise.
|
|
|
- */
|
|
|
- public function are_skills_maxed(){
|
|
|
- $maxed = true;
|
|
|
- for ($i = 0; $i < sizeof($this->monster->skill); $i ++){
|
|
|
- if ($this->monster->skill[$i]->max_level > $this->skill_levels[$i]){
|
|
|
- $maxed = false;
|
|
|
- break;
|
|
|
- }
|
|
|
+ $this->artifact_stats["ehp"] = APPLICATION::calculate_ehp($this->artifact_stats["hp"], $this->artifact_stats["def"]);
|
|
|
+ $this->artifact_stats["dmg"] = APPLICATION::calculate_dmg($this->artifact_stats["atk"], $this->artifact_stats["crr"], $this->artifact_stats["crd"]);
|
|
|
+
|
|
|
+ $this->flag_runes = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: Other loaders??
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Calculates the stats gained from runes, artifacts and buildings.
|
|
|
+ * Calculates the totalls and the effective stats.
|
|
|
+ *
|
|
|
+ * @gobal Player Currently selected player.
|
|
|
+ * @gobal int Game mode (Normal/RTA).
|
|
|
+ */
|
|
|
+ private function load_stats(){
|
|
|
+
|
|
|
+ if (! $this->flag_buildings){
|
|
|
+ $this->load_buildings();
|
|
|
+ }
|
|
|
+ if (! $this->flag_runes){
|
|
|
+ $this->load_runes();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $keys = ["atk", "def", "hp", "spd", "crr", "crd", "res", "acc", "ehp", "dmg"];
|
|
|
+
|
|
|
+ foreach ($keys as $key){
|
|
|
+ $this->stats[$key] = $this->base_stats[$key] + $this->rune_stats[$key] + $this->artifact_stats[$key] + $this->building_stats[$key];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->flag_stats = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Loads the {@see teams} array, with the teams the unit is on.
|
|
|
+ */
|
|
|
+ private function load_teams(){
|
|
|
+ $statement = get_context()->get_db()->prepare("
|
|
|
+ SELECT DISTINCT team.id AS id
|
|
|
+ FROM
|
|
|
+ team,
|
|
|
+ team_unit
|
|
|
+ WHERE
|
|
|
+ team.player = :player AND
|
|
|
+ team.id = team_unit.team AND
|
|
|
+ team_unit.unit = :unit;
|
|
|
+ ");
|
|
|
+ $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
|
|
|
+ $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
|
|
|
+ $q = $statement->execute();
|
|
|
+ while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
+ array_push($this->teams, new Team($r["id"], false));
|
|
|
+ }
|
|
|
+ $this->flag_teams = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Calculates the stat increase by a rune property.
|
|
|
+ *
|
|
|
+ * @param string $stat Stat type.
|
|
|
+ * @param int $value Stat increase value.
|
|
|
+ */
|
|
|
+ private function sum_rune_stat($stat, $value){
|
|
|
+ switch ($stat){
|
|
|
+ case RUNE_STAT_ID::ATK:
|
|
|
+ $this->rune_stats["atk"] += $value;
|
|
|
+ break;
|
|
|
+ case RUNE_STAT_ID::DEF:
|
|
|
+ $this->rune_stats["def"] += $value;
|
|
|
+ break;
|
|
|
+ case RUNE_STAT_ID::HP:
|
|
|
+ $this->rune_stats["hp"] += $value;
|
|
|
+ break;
|
|
|
+ case RUNE_STAT_ID::SPD:
|
|
|
+ $this->rune_stats["spd"] += $value;
|
|
|
+ break;
|
|
|
+ case RUNE_STAT_ID::CRR:
|
|
|
+ $this->rune_stats["crr"] += $value;
|
|
|
+ break;
|
|
|
+ case RUNE_STAT_ID::CRD:
|
|
|
+ $this->rune_stats["crd"] += $value;
|
|
|
+ break;
|
|
|
+ case RUNE_STAT_ID::ACC:
|
|
|
+ $this->rune_stats["acc"] += $value;
|
|
|
+ break;
|
|
|
+ case RUNE_STAT_ID::RES:
|
|
|
+ $this->rune_stats["res"] += $value;
|
|
|
+ break;
|
|
|
+ case RUNE_STAT_ID::ATK_P:
|
|
|
+ $this->rune_stats["atk"] += ($this->base_stats["atk"] * $value / 100);
|
|
|
+ break;
|
|
|
+ case RUNE_STAT_ID::DEF_P:
|
|
|
+ $this->rune_stats["def"] += ($this->base_stats["def"] * $value / 100);
|
|
|
+ break;
|
|
|
+ case RUNE_STAT_ID::HP_P:
|
|
|
+ $this->rune_stats["hp"] += ($this->base_stats["hp"] * $value / 100);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Checks if the unit skills are completly maxed.
|
|
|
+ *
|
|
|
+ * @return bool True if all skills maxed, false otherwise.
|
|
|
+ */
|
|
|
+ public function is_fully_skilled(){
|
|
|
+ if (! $this->flag_skills){
|
|
|
+ $this->load_skills();
|
|
|
+ }
|
|
|
+ $maxed = true;
|
|
|
+ $skills = $this->monster->get_skills();
|
|
|
+ for ($i = 0; $i < sizeof($skills); $i ++){
|
|
|
+ if ($skills[$i]->max_level > $this->skill_levels[$i]){
|
|
|
+ $maxed = false;
|
|
|
+ break;
|
|
|
}
|
|
|
- return $maxed;
|
|
|
}
|
|
|
+ return $maxed;
|
|
|
}
|
|
|
+}
|
|
|
?>
|