| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <?php
- /**
- * Saved run 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 . "Unit.php");
- require_once(PATH::ENTITY . "K_Unit.php");
- require_once(PATH::ENTITY . "Rune.php");
- require_once(PATH::ENTITY . "Inventory.php");
- require_once(PATH::ENTITY . "K_Area.php");
- require_once(PATH::ENTITY . "K_Rune_Set.php");
- /**
- * A run.
- *
- * Represents an object from the table 'run'.
- *
- * @category Entity
- */
- class Run extends Entity{
- /**
- * @var int Player identifier.
- */
- public $uid;
- /**
- * @var int Run identifier.
- */
- public $id;
- /**
- * @var DateTime Run start datestamp.
- */
- public $dtime;
- /**
- * @var K_Area Area.
- */
- public $area;
- /**
- * @var int Stage.
- */
- public $stage;
- /**
- * @var int Difficulty (only scenario and dimension hole)
- */
- public $difficulty;
- /**
- * @var bool Win or lost run.
- */
- public $win;
- /**
- * @var int Clear time, milliseconds.
- */
- public $time;
- /**
- * @var int Reward mana.
- */
- public $mana;
- /**
- * @var int Reward energy.
- */
- public $energy;
- /**
- * @var int Reward crystal.
- */
- public $crystal;
- /**
- * @var bool Indicates if a frind/mentor helped.
- */
- public $helper;
- /**
- * @var int Score in battles that are rated (WB, rift dungeons...).
- */
- public $score;
- /**
- * @var String Rank in battles that are rated (WB, rift dungeons...).
- */
- public $rank;
- /**
- * @var \Unit[]|\K_Unit[] Uits used.
- * If the unit is still owned, it will be a instance of Unit.
- * If not, it will be a instance of K_Unit.
- */
- public $party = [];
- /**
- * @var int ID of the leader unit.
- */
- public $leader;
- /**
- * @var int[] List of IDs of the frontline units.
- */
- public $frontline = [];
- /**
- * @var \Inventory[] Dropped items.
- */
- public $item = [];
- /**
- * @var \K_Unit[] Units dropped.
- */
- public $unit = [];
- /**
- * @var int K_Unit[] Units whose secret dungeons were found on the run.
- */
- public $sd= [];
- /**
- * @var mixed[] List of dropped summon pieces.
- *
- * Formated as:
- * [@{see K_Unit}, amount]
- */
- public $unit_piece = [];
- /**
- * @var int Number of shapeshifting stones dropped;
- */
- public $shapeshifting = 0;
- /**
- * @var \Rune[] List of Runes dropped.
- */
- public $rune= [];
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * run, populating it and it's items.
- *
- * @param int $id Run identifier.
- * @global resource Database connection.
- */
- public function __construct($id){
- global $db;
- $s = "
- SELECT
- id,
- uid,
- dtime,
- area,
- stage,
- difficulty,
- win,
- time,
- mana,
- energy,
- crystal,
- helper,
- score,
- rank
- FROM run
- WHERE id = $id;
- ";
- $q = $db->query($s);
- $r = $q->fetchArray(SQLITE3_ASSOC);
- $this->id = $r["id"];
- $this->uid = $r["uid"];
- $this->dtime = $r["dtime"];
- $type = 0;
- if (APPLICATION::valid_id("RAID_RIFT_DUNGEON_ID", $r["area"]) && $r["stage"] < 1){
- $type = AREA_TYPE_ID::RIFT_RAID_DUNGEON;
- }
- elseif (APPLICATION::valid_id("SCENARIO_ID", $r["area"])){
- $type = AREA_TYPE_ID::SCENARIO;
- }
- elseif (APPLICATION::valid_id("ELEMENTAL_RIFT_DUNGEON_ID", $r["area"]) && $r["stage"] < 1){
- $type = AREA_TYPE_ID::RIFT_DUNGEON;
- }
- elseif (APPLICATION::valid_id("DUNGEON_ID", $r["area"])){
- $type = AREA_TYPE_ID::CAIROS_DUNGEON;
- }
- $this->area = new K_Area($r["area"], $type);
- $this->stage = $r["stage"];
- $this->difficulty = $r["difficulty"];
- $this->win = $r["win"];
- $this->time = $r["time"];
- $this->mana = $r["mana"];
- $this->energy = $r["energy"];
- $this->crystal = $r["crystal"];
- $this->helper = $r["helper"];
- $this->score = $r["score"];
- $this->rank = $r["rank"];
- $s = "
- SELECT
- unit,
- k_unit,
- (SELECT count(id) FROM unit WHERE unit.unit = k_unit) AS owned,
- leader,
- front
- FROM run_party
- WHERE run = $id
- ORDER BY
- front DESC,
- leader DESC;
- ";
- $q = $db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- if ($r["owned"] > 0){
- array_push($this->party, new Unit($r["unit"], false));
- }
- else{
- array_push($this->party, new K_Unit($r["k_unit"], false));
- }
- if ($r["leader"] == 1){
- $this->leader = $r["unit"];
- }
- if ($r["front"] == 1){
- array_push($this->frontline, $r["unit"]);
- }
- }
- $s = "
- SELECT
- item,
- amount
- FROM run_drop_item
- WHERE run = $this->id;
- ";
- $q = $db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- $i = new Inventory($r["item"]);
- $i->amount = $r["amount"];
- array_push($this->item, $i);
- }
- $s = "
- SELECT unit
- FROM run_drop_unit
- WHERE run = $this->id;
- ";
- $q = $db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->unit, new K_Unit($r["unit"]));
- }
- $s = "
- SELECT unit
- FROM run_drop_sd
- WHERE run = $this->id;
- ";
- $q = $db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->sd, new K_Unit($r["unit"]));
- }
- $s = "
- SELECT
- unit,
- amount
- FROM run_drop_unit_pieces
- WHERE run = $this->id;
- ";
- $q = $db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- $i = [
- "unit" => new K_Unit($r["unit"]),
- "amount" => $r["amount"]
- ];
- array_push($this->unit_piece, $i);
- }
- $s = "
- SELECT amount
- FROM run_drop_shapeshifting
- WHERE run = $this->id;
- ";
- $q = $db->query($s);
- $r = $q->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->shapeshifting = $r["amount"];
- }
- $s = "
- SELECT
- id,
- type,
- slot,
- stars,
- ancient,
- quality,
- value,
- efficiency,
- main_stat,
- main_stat_value,
- innate_stat,
- innate_stat_value,
- substat_1,
- substat_1_value,
- substat_2,
- substat_2_value,
- substat_3,
- substat_3_value,
- substat_4,
- substat_4_value
- FROM run_drop_rune
- WHERE run = $this->id;
- ";
- $q = $db->query($s);
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- $rune = new Rune($r["id"]);
- if (!isset($rune->id)){
- $rune->id = $r["id"];
- $rune->level = 0;
- $rune->assigned_to = null;
- $rune->type = new K_Rune_Set($r["type"]);
- $rune->slot = $r["slot"];
- $rune->stars = $r["stars"];
- $rune->ancient = $r["ancient"];
- $rune->quality = $r["quality"];
- $rune->original_quality = $r["quality"];
- $rune->value = $r["value"];
- $rune->value = 0;
- $rune->efficiency = $r["efficiency"];
- // TODO: Calculate?
- $rune->max_efficiency = $r["efficiency"];
- $rune->main_stat = $r["main_stat"];
- $rune->main_stat_value = $r["main_stat_value"];
- $rune->innate_stat = $r["innate_stat"];
- $rune->innate_stat_value = $r["innate_stat_value"];
- $rune->substat_1 = $r["substat_1"];
- $rune->substat_1_value = $r["substat_1_value"];
- $rune->substat_1_enchant = 0;
- $rune->substat_1_grind = 0;
- $rune->substat_2 = $r["substat_2"];
- $rune->substat_2_value = $r["substat_2_value"];
- $rune->substat_2_enchant = 0;
- $rune->substat_2_grind = 0;
- $rune->substat_3 = $r["substat_3"];
- $rune->substat_3_value = $r["substat_3_value"];
- $rune->substat_3_enchant = 0;
- $rune->substat_3_grind = 0;
- $rune->substat_4 = $r["substat_4"];
- $rune->substat_4_value = $r["substat_4_value"];
- $rune->substat_4_enchant = 0;
- $rune->substat_4_grind = 0;
- $rune->refresh_names();
- }
- array_push($this->rune, $rune);
- }
- }
- }
- ?>
|