|
|
@@ -144,7 +144,7 @@
|
|
|
FROM artifact
|
|
|
WHERE id = :id;
|
|
|
");
|
|
|
- $statement->bindValue(':id', $id, SQLITE3_INTEGER);
|
|
|
+ $statement->bindValue(':id', $id, SQLITE3_TEXT);
|
|
|
$r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
|
if ($r){
|
|
|
$this->id = $r["id"];
|
|
|
@@ -171,11 +171,28 @@
|
|
|
WHERE artifact = :artifact
|
|
|
ORDER BY slot;
|
|
|
");
|
|
|
- $statement->bindValue(':artifact', $this->id, SQLITE3_INTEGER);
|
|
|
+ $statement->bindValue(':artifact', $this->id, SQLITE3_TEXT);
|
|
|
$q = $statement->execute();
|
|
|
while ($r = $q->fetchArray(SQLITE3_ASSOC)){
|
|
|
array_push($this->effects, new Artifact_Effect($this->id, $r["slot"]));
|
|
|
}
|
|
|
+
|
|
|
+ // Get efficiencies, or calculate them if not yet set.
|
|
|
+ if ($this->efficiency == null || $this->efficiency == "" || intval($this->efficiency) == 0){
|
|
|
+ $this->efficiency = $this->calculate_efficiency();
|
|
|
+ $this->max_efficiency = $this->calculate_maximum_efficiency();
|
|
|
+ $statement = $db->prepare("
|
|
|
+ UPDATE artifact
|
|
|
+ SET
|
|
|
+ efficiency = :efficiency,
|
|
|
+ max_efficiency = :max_efficiency
|
|
|
+ WHERE id = :artifact
|
|
|
+ ");
|
|
|
+ $statement->bindValue(':efficiency', $this->efficiency, SQLITE3_FLOAT);
|
|
|
+ $statement->bindValue(':max_efficiency', $this->max_efficiency, SQLITE3_FLOAT);
|
|
|
+ $statement->bindValue(':artifact', $this->id, SQLITE3_INTEGER);
|
|
|
+ $q = $statement->execute();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -202,5 +219,76 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Calcuates the efficiency of the artifact.
|
|
|
+ *
|
|
|
+ * @return float Efficiency
|
|
|
+ */
|
|
|
+ private function calculate_efficiency(){
|
|
|
+ global $db;
|
|
|
+ $eff = [0.0, 0.0, 0.0, 0.0];
|
|
|
+
|
|
|
+ $query = "
|
|
|
+ SELECT
|
|
|
+ min,
|
|
|
+ max
|
|
|
+ FROM
|
|
|
+ k_artifact_roll_type,
|
|
|
+ k_artifact_stat_roll
|
|
|
+ WHERE
|
|
|
+ k_artifact_roll_type.id = k_artifact_stat_roll.type AND
|
|
|
+ k_artifact_roll_type.initial = :initial AND
|
|
|
+ k_artifact_roll_type.upgrade = :upgrade AND
|
|
|
+ k_artifact_stat_roll.effect = :effect
|
|
|
+ ";
|
|
|
+
|
|
|
+ for ($i = 0; $i <= 3; $i ++){
|
|
|
+ if (sizeof($this->effects) > $i && $this->effects[$i] != null && $this->effects[$i]->value > 0){
|
|
|
+ $value = $this->effects[$i]->value;
|
|
|
+ $value = $this->effects[$i]->value;
|
|
|
+ $statement = $db->prepare($query);
|
|
|
+ $statement->bindValue(':initial', 1, SQLITE3_TEXT);
|
|
|
+ $statement->bindValue(':upgrade', 1, SQLITE3_TEXT);
|
|
|
+ $statement->bindValue(':effect', $this->effects[$i]->effect, SQLITE3_TEXT);
|
|
|
+ $r_roll = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
|
|
+ if ($r_roll ){
|
|
|
+ $min_initial = 0;//$r_initial["min"];
|
|
|
+ $max_initial = $r_roll["max"];
|
|
|
+ $min_upgrade = 0;//$r_upgrade["min"];
|
|
|
+ $max_upgrade = $r_roll["max"];
|
|
|
+ $eff[$i] = ((5 * $value) - ( 4 * $min_upgrade + $min_initial)) / ( 8 * ($max_initial - $min_initial + (4 * ($max_upgrade + $min_upgrade))));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $efficiency = 0.0;
|
|
|
+ for ($i = 0; $i <= 3; $i ++){
|
|
|
+ $efficiency += $eff[$i];
|
|
|
+ }
|
|
|
+ $efficiency *= 100;
|
|
|
+ return $efficiency;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Calcuates the maximum efficiency of the artifact.
|
|
|
+ *
|
|
|
+ * @return float Efficiency
|
|
|
+ */
|
|
|
+ private function calculate_maximum_efficiency(){
|
|
|
+ $max_efficiency = $this->efficiency;
|
|
|
+ if ($this->level < 12){
|
|
|
+ $max_efficiency += (1/8);
|
|
|
+ }
|
|
|
+ if ($this->level < 9){
|
|
|
+ $max_efficiency += (1/8);
|
|
|
+ }
|
|
|
+ if ($this->level < 6){
|
|
|
+ $max_efficiency += (1/8);
|
|
|
+ }
|
|
|
+ if ($this->level < 3){
|
|
|
+ $max_efficiency += (1/8);
|
|
|
+ }
|
|
|
+ return $max_efficiency;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
?>
|