| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- <?php
- /**
- * Rune 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 . "K_Rune_Set.php");
- require_once(PATH::ENTITY . "Rune_Stat.php");
- /**
- * Owned rune.
- *
- * Represents an object from the table 'rune'.
- *
- * @category Entity
- */
- class Rune extends Entity{
- /**
- * @var int Owner identifier.
- */
- public $uid;
- /**
- * @var int Rune identifier.
- */
- public $id;
- /**
- * @var K_Rune_Set Rune set.
- */
- public $type;
- /**
- * @var int Position of the rune type (1-6).
- */
- public $slot;
- /**
- * @var int Rune stars.
- */
- public $stars;
- /**
- * @var bool Indicates if the rune is ancient.
- */
- public $ancient;
- /**
- * @var int Level of the rune.
- */
- public $level;
- /**
- * @var int Rune quality.
- *
- * @see QUALITY_ID
- */
- public $quality;
- /**
- * @var int Rune original quality.
- *
- * @see QUALITY_ID
- */
- public $original_quality;
- /**
- * @var string Rune quality name (uppercase).
- */
- public $quality_name;
- /**
- * @var string Rune original quality name (uppercase).
- */
- public $original_quality_name;
- /**
- * @var int Price of the rune.
- */
- public $value;
- /**
- * @var float Current efficiency of the rune.
- */
- public $efficiency;
- /**
- * @var float Maximum potential efficiency of the rune.
- */
- public $max_efficiency;
- /**
- * @var int Indicates if the rune is locked.
- */
- public $locked;
- /**
- * @var Rune_Stat Main stat of the rune.
- */
- public $main_stat;
- /**
- * @var Rune_Stat Extra stat of the rune.
- */
- public $innate_stat;
- /**
- * @var \Rune_Stat[] Substats of the rune.
- */
- public $substats = [];
- /**
- * @var \Rune_Stat[] All stats.
- *
- * Includes main, innate and substats
- */
- public $stats = [];
- /**
- * @var Unit Unit the rune is assigned to.
- */
- public $unit;
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * rune, populating it and it's items.
- *
- * @param int $id Rune id.
- * @global resource Database connection.
- */
- public function __construct($id){
- global $db;
- $statement = $db->prepare("
- SELECT
- id,
- type,
- slot,
- stars,
- level,
- ancient,
- quality,
- original_quality,
- value,
- efficiency,
- max_efficiency,
- locked
- FROM rune
- WHERE id = :id;
- ");
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->id = $r["id"];
- $this->type = new K_Rune_Set($r["type"]);
- $this->slot = $r["slot"];
- $this->stars = $r["stars"];
- $this->level = $r["level"];
- $this->ancient = $r["ancient"];
- $this->quality = $r["quality"];
- $this->original_quality = $r["original_quality"];
- $this->value = $r["value"];
- //$this->efficiency = $r["efficiency"];
- //$this->max_efficiency = $r["max_efficiency"];
- $this->locked = $r["locked"];
- // Get substats
- $statement = $db->prepare("
- SELECT slot
- FROM rune_stat
- WHERE rune = :rune
- ORDER BY slot;
- ");
- $statement->bindValue(':rune', $this->id, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- $stat = new Rune_Stat($this->id, $r["slot"]);
- array_push($this->stats, $stat);
- switch ($r["slot"]){
- case RUNE_STAT_SLOT_ID::MAIN:
- $this->main_stat = $stat;
- break;
- case RUNE_STAT_SLOT_ID::INNATE:
- $this->innate_stat = $stat;
- break;
- default:
- array_push($this->substats, $stat);
- break;
- }
- }
- $this->quality_name = $this->get_quality_name($this->quality);
- $this->original_quality_name = $this->get_quality_name($this->original_quality);
- $this->efficiency = $this->calculate_efficiency();
- $this->max_efficiency = $this->calculate_maximum_efficiency();
- }
- }
- /**
- * Gets the value of the main stat at an arbitrary level.
- *
- * @param int $level Desired level.
- * @return int Value of the main stat at the selected level.
- */
- public function get_main_stat_at_level($level){
- $level = intval($level);
- if ($level < 0 || $level > 15){
- return 0;
- }
- switch ($this->main_stat->stat){
- case RUNE_STAT_ID::HP:
- return RUNE_STAT_VALUES::HP[$this->stars][$level];
- case RUNE_STAT_ID::HP_P:
- return RUNE_STAT_VALUES::HP_P[$this->stars][$level];
- case RUNE_STAT_ID::ATK:
- return RUNE_STAT_VALUES::ATK[$this->stars][$level];
- case RUNE_STAT_ID::ATK_P:
- return RUNE_STAT_VALUES::ATK_P[$this->stars][$level];
- case RUNE_STAT_ID::DEF:
- return RUNE_STAT_VALUES::DEF[$this->stars][$level];
- case RUNE_STAT_ID::DEF_P:
- return RUNE_STAT_VALUES::DEF_P[$this->stars][$level];
- case RUNE_STAT_ID::SPD:
- return RUNE_STAT_VALUES::SPD[$this->stars][$level];
- case RUNE_STAT_ID::CRR:
- return RUNE_STAT_VALUES::CRR[$this->stars][$level];
- case RUNE_STAT_ID::CRD:
- return RUNE_STAT_VALUES::CRD[$this->stars][$level];
- case RUNE_STAT_ID::RES:
- return RUNE_STAT_VALUES::RES[$this->stars][$level];
- case RUNE_STAT_ID::ACC:
- return RUNE_STAT_VALUES::ACC[$this->stars][$level];
- default:
- return 0;
- }
- }
- /**
- * Gets a stat name frm the mappings.
- *
- * @param int $q Quality id.
- * @return string Quality (Uppercase)
- */
- private function get_quality_name($q){
- switch ($q){
- case QUALITY_ID::NORMAL:
- return "NORMAL";
- case QUALITY_ID::MAGIC:
- return "MAGIC";
- case QUALITY_ID::RARE:
- return "RARE";
- case QUALITY_ID::HERO:
- return "HERO";
- case QUALITY_ID::LEGEND:
- return "LEGEND";
- default:
- return "";
- }
- }
- /**
- * Calcuates the efficiency of the rune.
- *
- * @return float Efficiency
- */
- private function calculate_efficiency(){
- global $db;
- $eff = [0.0, 0.0, 0.0, 0.0, 0.0];
- $query = "
- SELECT
- min,
- max
- FROM
- k_rune_roll_type,
- k_rune_stat_roll
- WHERE
- k_rune_roll_type.id = k_rune_stat_roll.type AND
- k_rune_roll_type.ancient = :ancient AND
- k_rune_roll_type.initial = :initial AND
- k_rune_roll_type.upgrade = :upgrade AND
- k_rune_stat_roll.stars = :stars AND
- k_rune_stat_roll.stat = :stat
- ";
- // Fixed stat
- if ($this->innate_stat != null && $this->innate_stat->value > 0){
- $value = $this->innate_stat->value;
- $statement = $db->prepare($query);
- $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
- $statement->bindValue(':initial', 1, SQLITE3_TEXT);
- $statement->bindValue(':upgrade', 0, SQLITE3_TEXT);
- $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
- $statement->bindValue(':stat', $this->innate_stat->stat, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $min_initial = 0;//$r["min"];
- $max_initial = $r["max"];
- $eff[0] = ($value - $min_initial) / (9 * ($max_initial - $min_initial));
- }
- }
- for ($i = 1; $i <= 4; $i ++){
- if ($this->stats[$i] != null && $this->stats[$i]->value > 0){
- $value = $this->stats[$i]->value;
- $value = $this->stats[$i]->value;
- $statement = $db->prepare($query);
- $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
- $statement->bindValue(':initial', 1, SQLITE3_TEXT);
- $statement->bindValue(':upgrade', 0, SQLITE3_TEXT);
- $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
- $statement->bindValue(':stat', $this->stats[$i]->stat, SQLITE3_TEXT);
- $r_initial = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- $statement = $db->prepare($query);
- $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
- $statement->bindValue(':initial', 0, SQLITE3_TEXT);
- $statement->bindValue(':upgrade', 1, SQLITE3_TEXT);
- $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
- $statement->bindValue(':stat', $this->stats[$i]->stat, SQLITE3_TEXT);
- $r_upgrade = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r_initial && $r_upgrade){
- $min_initial = 0;//$r_initial["min"];
- $max_initial = $r_initial["max"];
- $min_upgrade = 0;//$r_upgrade["min"];
- $max_upgrade = $r_upgrade["max"];
- $eff[$i] = ((5 * $value) - ( 4 * $min_upgrade + $min_initial)) / ( 9 * ($max_initial - $min_initial + (4 * ($max_upgrade + $min_upgrade))));
- }
- }
- }
- $efficiency = 0.0;
- for ($i = 0; $i <= 4; $i ++){
- $efficiency += $eff[$i];
- }
- $efficiency *= 100;
- return $efficiency;
- }
- /**
- * Calcuates the maximum efficiency of the rune.
- *
- * @return float Efficiency
- */
- private function calculate_maximum_efficiency(){
- $max_efficiency = $this->efficiency;
- if ($this->level < 12){
- $max_efficiency += (1/9);
- }
- if ($this->level < 9){
- $max_efficiency += (1/9);
- }
- if ($this->level < 6){
- $max_efficiency += (1/9);
- }
- if ($this->level < 3){
- $max_efficiency += (1/9);
- }
- return $max_efficiency;
- }
- }
- ?>
|