|
|
@@ -176,6 +176,136 @@
|
|
|
*/
|
|
|
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.
|
|
|
*/
|
|
|
@@ -301,8 +431,7 @@
|
|
|
$this->create_time = date_create($r["create_time"]);
|
|
|
$this->homunculus_name = $r["homunculus_name"];
|
|
|
if ($complete){
|
|
|
- $this->load_runes();
|
|
|
- $this->load_artifacts();
|
|
|
+ $this->load_stats();
|
|
|
$this->load_teams();
|
|
|
$this->check_storage();
|
|
|
$this->lock = $r["lock"];
|
|
|
@@ -370,42 +499,20 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * Loads the {@see teams} array, with the teams the unit is on.
|
|
|
+ * Calculates the stats gained from runes, artifacts and buildings.
|
|
|
+ * Calculates the totalls and the effective stats.
|
|
|
*
|
|
|
- * @global int Player ID.
|
|
|
+ * @gobal int User ID.
|
|
|
* @global resource Database connection.
|
|
|
*/
|
|
|
- public function load_teams(){
|
|
|
+ public function load_stats(){
|
|
|
+
|
|
|
global $UID;
|
|
|
global $db;
|
|
|
- $this->teams = [];
|
|
|
- $s = "
|
|
|
- SELECT DISTINCT team.id AS id
|
|
|
- FROM
|
|
|
- team,
|
|
|
- team_unit
|
|
|
- WHERE
|
|
|
- team.uid = '$UID' AND
|
|
|
- team.id = team_unit.team AND
|
|
|
- team_unit.unit = '" . $this->id . "';
|
|
|
- ";
|
|
|
- $q = $db->query($s);
|
|
|
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
- array_push($this->teams, new Team($r["id"], false));
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * Loads the information about the equiped runes.
|
|
|
- * It is autoatically called at construction time if the
|
|
|
- * $complete parameter is true (by default). No point in calling it
|
|
|
- * twice.
|
|
|
- *
|
|
|
- * @global resource Database connection.
|
|
|
- */
|
|
|
- public function load_runes(){
|
|
|
- global $db;
|
|
|
+ // Runes
|
|
|
$this->rune = [];
|
|
|
$s =
|
|
|
"SELECT id " .
|
|
|
@@ -426,18 +533,8 @@
|
|
|
$this->rune_attack = ceil($this->rune_attack);
|
|
|
$this->rune_defense = ceil($this->rune_defense);
|
|
|
$this->rune_hp = ceil($this->rune_hp);
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * Loads the information about the equiped artifacts.
|
|
|
- * It is autoatically called at construction time if the
|
|
|
- * $complete parameter is true (by default). No point in calling it
|
|
|
- * twice.
|
|
|
- *
|
|
|
- * @global resource Database connection.
|
|
|
- */
|
|
|
- public function load_artifacts(){
|
|
|
- global $db;
|
|
|
+ // Artifacts
|
|
|
$s =
|
|
|
"SELECT id " .
|
|
|
"FROM artifact " .
|
|
|
@@ -451,10 +548,127 @@
|
|
|
else{
|
|
|
$this->artifact_element = $artifact;
|
|
|
}
|
|
|
- $this->sum_rune_stat($artifact->main_stat, $artifact->main_stat_value);
|
|
|
+ switch($artifact->main_stat){
|
|
|
+ case ARTIFACT_STAT_ID::ATK:
|
|
|
+ $this->artifact_attack += $artifact->main_stat_value;
|
|
|
+ break;
|
|
|
+ case ARTIFACT_STAT_ID::DEF:
|
|
|
+ $this->artifact_defense += $artifact->main_stat_value;
|
|
|
+ break;
|
|
|
+ case ARTIFACT_STAT_ID::HP:
|
|
|
+ $this->artifact_hp += $artifact->main_stat_value;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Buildings
|
|
|
+ $s = "
|
|
|
+ SELECT
|
|
|
+ affected_stat,
|
|
|
+ bonus,
|
|
|
+ element
|
|
|
+ FROM
|
|
|
+ k_decoration,
|
|
|
+ k_decoration_level,
|
|
|
+ decoration
|
|
|
+ WHERE
|
|
|
+ decoration.uid = '$UID' AND
|
|
|
+ k_decoration.id = decoration.decoration AND
|
|
|
+ decoration.decoration = k_decoration_level.decoration AND
|
|
|
+ decoration.level = k_decoration_level.level AND
|
|
|
+ area = " . EFFECT_AREA_ID::GENERAL . " AND
|
|
|
+ affected_stat IN (" . STAT_ID::ATK . ", " . STAT_ID::DEF . ", " . STAT_ID::HP . ", " . STAT_ID::SPD . ", " . STAT_ID::CRIT_DMG . ");
|
|
|
+ ";
|
|
|
+ $q = $db->query($s);
|
|
|
+ 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->unit->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.
|
|
|
+ *
|
|
|
+ * @global int Player ID.
|
|
|
+ * @global resource Database connection.
|
|
|
+ */
|
|
|
+ public function load_teams(){
|
|
|
+ global $UID;
|
|
|
+ global $db;
|
|
|
+ $this->teams = [];
|
|
|
+ $s = "
|
|
|
+ SELECT DISTINCT team.id AS id
|
|
|
+ FROM
|
|
|
+ team,
|
|
|
+ team_unit
|
|
|
+ WHERE
|
|
|
+ team.uid = '$UID' AND
|
|
|
+ team.id = team_unit.team AND
|
|
|
+ team_unit.unit = '" . $this->id . "';
|
|
|
+ ";
|
|
|
+ $q = $db->query($s);
|
|
|
+ while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
+ array_push($this->teams, new Team($r["id"], false));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* Calculates the stat increase by a rune property.
|
|
|
*
|