| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- <?php
- /**
- * Enchantments items entity file.
- *
- * Creates the entity and makes it available.
- *
- * @author Iñigo Valentin <i@inigovalentin.com>
- * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
- * @package SWDB
- */
- require_once(PATH::ENTITY . "Entity.php");
- require_once(PATH::ENTITY . "Rune_Set.php");
- /**
- * Owned enchantments.
- *
- * Represent an enchantment, both grindstones and gems.
- *
- * @category Entity
- */
- class Enchantment extends Entity{
- /**
- * @var int Owner's player ID.
- */
- private $player_id;
- /**
- * @var int Enchantment ID.
- */
- private $id;
- /**
- * @var int Quality ID ({@see QUALITY_ID}).
- */
- private $quality;
- /**
- * @var string Quality name.
- */
- private $quality_name;
- /**
- * @var int Rune set ID ({@see RUNE_SET_ID}).
- */
- private $rune_set;
- /**
- * @var int ID of the stat affeced by the enchantmentt ({@see RUNE_STAT_ID}).
- */
- private $stat;
- /**
- * @var string Name of the affected stat.
- */
- private $stat_name;
- /**
- * @var bool Indicates if the enchantment is a gem.
- */
- private $gem;
- /**
- * @var bool Indicates if the enchantment is ancient.
- */
- private $ancient;
- /**
- * @var bool Indicates if the enchantment is inmemorial.
- */
- private $inmemorial;
- /**
- * @var string Enchantment name.
- */
- private $name;
- /**
- * @var int Minimal effect of the enchantment.
- */
- private $min;
- /**
- * @var int Maximum effect of the enchantment.
- */
- private $max;
- /**
- * @var int Value of the enchantment in mana stones.
- */
- private $value;
- /**
- * @var int Owned amount of the same enchantment.
- */
- private $amount;
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * rune, populating it and it's items.
- *
- * @param int $id Enchantment id.
- */
- public function __construct($id){
- $statement = get_context()->get_db()->prepare("
- SELECT
- enchantment.player AS player,
- enchantment.id AS id,
- enchantment.quality As quality,
- enchantment.rune AS rune,
- enchantment.stat AS stat,
- enchantment.value AS value,
- enchantment.amount AS amount,
- enchantment_type.name AS name,
- enchantment_type.gem AS gem,
- enchantment_type.inmemorial AS inmemorial,
- enchantment_type.ancient AS ancient,
- enchantment_range.min AS min,
- enchantment_range.max AS max
- FROM
- enchantment,
- enchantment_type,
- enchantment_range
- WHERE
- enchantment.id = :id AND
- enchantment.type = enchantment_type.id AND
- enchantment_type.gem = enchantment_range.gem AND
- enchantment_type.gem = enchantment_range.gem AND
- enchantment_type.ancient = enchantment_range.ancient AND
- enchantment.quality = enchantment_range.quality AND
- enchantment.stat = enchantment_range.stat;
- ");
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->player_id = $r["player"];
- $this->id = $r["id"];
- if ($r["gem"] == 0){
- $this->gem = false;
- }
- else{
- $this->gem = true;
- }
- $this->quality = $r["quality"];
- $this->quality_name = $this->quality_name($r["quality"]);
- $this->stat = $r["stat"];
- $this->stat_name = $this->stat_name($r["stat"]);
- if ($r["ancient"] == 0){
- $this->ancient = false;
- }
- else{
- $this->ancient = true;
- }
- $this->inmemorial = $r["inmemorial"];
- if ($r["inmemorial"] == 0){
- $this->rune_set = new Rune_Set($r["rune"]);
- $this->name = $this->rune_set->get_name() . " " . $this->stat_name;
- $this->inmemorial = false;
- }
- else{
- $this->inmemorial = true;
- $this->name = "Inmemorial " . $this->stat_name;
- }
- $this->min = $r["min"];
- $this->max = $r["max"];
- $this->value = $r["value"];
- $this->amount = $r["amount"];
- }
- else{
- // Not found, maybe as a run drop?
- $statement = get_context()->get_db()->prepare("
- SELECT
- run_drop_enchantment.id AS id,
- type,
- run_drop_enchantment.quality AS quality,
- rune,
- run_drop_enchantment.stat AS stat,
- value,
- enchantment_type.inmemorial AS inmemorial,
- enchantment_type.ancient AS ancient,
- enchantment_range.min AS min,
- enchantment_range.max AS max
- FROM
- run_drop_enchantment,
- enchantment_type,
- enchantment_range
- WHERE
- run = :run AND
- run_drop_enchantment.type = enchantment_type.id AND
- enchantment_type.gem = enchantment_range.gem AND
- enchantment_type.gem = enchantment_range.gem AND
- enchantment_type.ancient = enchantment_range.ancient AND
- run_drop_enchantment.quality = enchantment_range.quality AND
- run_drop_enchantment.stat = enchantment_range.stat;
- ");
- $statement->bindValue(':id', $id, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->player_id = get_context()->get_player()->get_id();
- if ($r["type"] == ENCHANTMENT_TYPE_ID::ENCHANT_GEM || $r["type"] == ENCHANTMENT_TYPE_ID::INMEMORIAL_GEM){
- $this->gem = 1;
- }
- else{
- $this->gem = 0;
- }
- $this->quality = $r["quality"];
- $this->quality_name = $this->quality_name($r["quality"]);
- $this->value = 0;
- $this->stat = $r["stat"];
- $this->stat_name = $this->stat_name($r["stat"]);
- $this->ancient = filter_var($r["ancient"], FILTER_VALIDATE_BOOLEAN);
- $this->inmemorial = filter_var($r["inmemorial"], FILTER_VALIDATE_BOOLEAN);
- if ($r["inmemorial"] == 0){
- $this->rune_set = new Rune_Set($r["rune"]);
- $this->name = $this->rune_set->get_name() . " " . $this->stat_name;
- $this->inmemorial = false;
- }
- else{
- $this->inmemorial = true;
- $this->name = "Inmemorial " . $this->stat_name;
- }
- $this->min = $r["min"];
- $this->max = $r["max"];
- $this->value = $r["value"];
- $this->amount = 1;
- }
- }
- }
- /**
- * Gets a stat name from the maps.
- *
- * @param int $stat Stat id.
- * @return string Stat name (Uppercase)
- */
- private function stat_name($stat){
- switch ($stat){
- case RUNE_STAT_ID::HP:
- return "HP";
- case RUNE_STAT_ID::HP_P:
- return "HP%";
- case RUNE_STAT_ID::ATK:
- return "ATK";
- case RUNE_STAT_ID::ATK_P:
- return "ATK%";
- case RUNE_STAT_ID::DEF:
- return "DEF";
- case RUNE_STAT_ID::DEF_P:
- return "DEF%";
- case RUNE_STAT_ID::SPD:
- return "SPD";
- case RUNE_STAT_ID::CRR:
- return "CRR";
- case RUNE_STAT_ID::CRD:
- return "CRD";
- case RUNE_STAT_ID::RES:
- return "RES";
- case RUNE_STAT_ID::ACC:
- return "ACC";
- default:
- return "";
- }
- }
- /**
- * Gets a stat name from the maps.
- *
- * @param int $q Quality id.
- * @return string Quality (Uppercase)
- */
- private function 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 "";
- }
- }
- /**
- * Retrieves the owner's player identifier.
- *
- * @return int player identifier.
- */
- public function get_player_id(){
- return $this->player_id;
- }
- /**
- * Retrieves the enchantment identifier.
- *
- * @return string Enchantment ID.
- */
- public function get_id(){
- return $this->id;
- }
- /**
- * Retrieves the quality of the enchantment.
- *
- * @see QUALITY_ID
- *
- * @return int Quality.
- */
- public function get_quality(){
- return $this->quality;
- }
- /**
- * Retrieves the quality name of the enchantment.
- *
- * @return string Quality name.
- */
- public function get_quality_name(){
- return $this->quality_name;
- }
- /**
- * Retrieves the rune set the enchantment can be used on.
- *
- * @return Rune_Set The set the enchantment can be used on, null for inmemorials.
- */
- public function get_rune_set(){
- return $this->rune_set;
- }
- /**
- * Retrieves the stat affected by the enchantment.
- *
- * @see RUNE_STAT_ID
- *
- * @return int Stat ID.
- */
- public function get_stat(){
- return $this->stat;
- }
- /**
- * Retrieves the name of the affected stat.
- *
- * @return string Stat name
- */
- public function get_stat_name(){
- return $this->stat_name;
- }
- /**
- * Checks if the enchantment is a enchanted gem.
- *
- * @return bool true for enchanted gems, false for grindstones.
- */
- public function is_gem(){
- return $this->gem;
- }
- /**
- * Checks if the enchantment is a grindstone.
- *
- * @return bool true for grindstones, false enchanted gems.
- */
- public function is_grind(){
- return ! $this->gem;
- }
- /**
- * Checks if it's an ancient enchantment.
- *
- * @return bool True if ancient, false if normal.
- */
- public function is_ancient(){
- return $this->ancient;
- }
- /**
- * Checks if the enchantment is inmemorial.
- *
- * @return bool True for inmemorial, false otherwise.
- */
- public function is_inmemorial(){
- return $this->inmemorial;
- }
- /**
- * Retrieves the enchantment name.
- *
- * @return string Enchantment name.
- */
- public function get_name(){
- return $this->name;
- }
- /**
- * Retrieves the minumum value for the enchantment.
- *
- * @return int Minimum enchant outcome.
- */
- public function get_min(){
- return $this->min;
- }
- /**
- * Retrieves the maximum value for the enchantment.
- *
- * @return int Maximum enchant outcome.
- */
- public function get_max(){
- return $this->max;
- }
- /**
- * Retrieves the value of the enchantment in mana stones.
- *
- * @return int Value of the enchantment.
- */
- public function get_value(){
- return $this->value;
- }
- /**
- * Retrieves the amount of the same enchantment owned by the user.
- *
- * @return int Number of the enchantments owned.
- */
- public function get_amount(){
- return $this->amount;
- }
- }
|