supernova-ws /
SuperNova
| 1 | <?php |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * Created by Gorlum 08.01.2018 13:23 |
||||
| 5 | */ |
||||
| 6 | |||||
| 7 | namespace Unit; |
||||
| 8 | |||||
| 9 | use DBAL\db_mysql; |
||||
| 10 | use \SN; |
||||
|
0 ignored issues
–
show
|
|||||
| 11 | use Planet\Planet; |
||||
| 12 | |||||
| 13 | class Governor extends Unit { |
||||
| 14 | // protected $type = UNIT_GOVERNOR_PRIMARY; |
||||
| 15 | // protected $typeIdField = 'PLANET_GOVERNOR_ID'; |
||||
| 16 | // protected $typeLevelField = 'PLANET_GOVERNOR_LEVEL'; |
||||
| 17 | |||||
| 18 | protected $snId = 0; |
||||
| 19 | protected $level = 0; |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * @var RecordUnit $unit |
||||
| 23 | */ |
||||
| 24 | protected $unit; |
||||
| 25 | |||||
| 26 | /** |
||||
| 27 | * @var Planet $planet |
||||
| 28 | */ |
||||
| 29 | protected $planet; |
||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * Governor constructor. |
||||
| 33 | */ |
||||
| 34 | public function __construct() { |
||||
| 35 | $this->reset(); |
||||
| 36 | } |
||||
| 37 | |||||
| 38 | /** |
||||
| 39 | * @param Planet $planet |
||||
| 40 | */ |
||||
| 41 | public function setPlanet($planet) { |
||||
| 42 | $this->reset(); |
||||
| 43 | |||||
| 44 | $this->planet = $planet; |
||||
| 45 | $this->getExternalData(); |
||||
| 46 | } |
||||
| 47 | |||||
| 48 | /** |
||||
| 49 | * @param int $hireId - Hire unit SN ID |
||||
| 50 | */ |
||||
| 51 | public function hire($hireId) { |
||||
| 52 | if (!in_array($hireId, sn_get_groups('governors'))) { |
||||
| 53 | return; |
||||
| 54 | } |
||||
| 55 | |||||
| 56 | if ($hireId == $this->getSnId() && $this->getMaxLevel() && $this->getMaxLevel() >= $this->getLevel()) { |
||||
| 57 | return; |
||||
| 58 | } |
||||
| 59 | |||||
| 60 | db_mysql::db_transaction_start(); |
||||
| 61 | $user = db_user_by_id($this->planet->id_owner, true); |
||||
|
0 ignored issues
–
show
The function
db_user_by_id() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 62 | // $this->planetRow = Planet\DBStaticPlanet::db_planet_by_id($this->planet->id, true); |
||||
| 63 | // $build_data = eco_get_build_data($user, $this->planetRow, $hireId, $this->getId() == $hireId ? $this->getLevel() : 0); |
||||
| 64 | $this->planet->dbLoadRecord($this->planet->id); |
||||
| 65 | |||||
| 66 | $build_data = eco_get_build_data($user, $this->planet->asArray(), $hireId, $this->getSnId() == $hireId ? $this->getLevel() : 0); |
||||
| 67 | if ( |
||||
| 68 | $build_data['CAN'][BUILD_CREATE] |
||||
| 69 | && |
||||
| 70 | mrc_get_level($user, [], RES_DARK_MATTER) >= $build_data[BUILD_CREATE][RES_DARK_MATTER] |
||||
| 71 | && |
||||
| 72 | rpg_points_change( |
||||
| 73 | $user['id'], |
||||
| 74 | RPG_GOVERNOR, |
||||
| 75 | -$build_data[BUILD_CREATE][RES_DARK_MATTER], |
||||
| 76 | sprintf(SN::$lang['ov_governor_purchase'], |
||||
| 77 | SN::$lang['tech'][$hireId], |
||||
| 78 | $hireId, |
||||
| 79 | $this->level, |
||||
| 80 | uni_render_planet_object_full($this->planet, false, true) |
||||
| 81 | ) |
||||
| 82 | ) |
||||
| 83 | ) { |
||||
| 84 | $this->addLevel($hireId); |
||||
| 85 | $this->planet->update(); |
||||
| 86 | } |
||||
| 87 | db_mysql::db_transaction_commit(); |
||||
| 88 | } |
||||
| 89 | |||||
| 90 | |||||
| 91 | /** |
||||
| 92 | * @return int |
||||
| 93 | */ |
||||
| 94 | public function getSnId() { |
||||
| 95 | return $this->snId; |
||||
| 96 | } |
||||
| 97 | |||||
| 98 | /** |
||||
| 99 | * @return int |
||||
| 100 | */ |
||||
| 101 | public function getLevel() { |
||||
| 102 | return $this->level; |
||||
| 103 | } |
||||
| 104 | |||||
| 105 | /** |
||||
| 106 | * @return int |
||||
| 107 | */ |
||||
| 108 | public function getMaxLevel() { |
||||
| 109 | $snId = $this->getSnId(); |
||||
| 110 | return !empty($snId) ? get_unit_param($snId, P_MAX_STACK) : 0; |
||||
| 111 | } |
||||
| 112 | |||||
| 113 | /** |
||||
| 114 | * @param $hireId |
||||
| 115 | */ |
||||
| 116 | protected function addLevel($hireId) { |
||||
| 117 | if ($this->getSnId() == $hireId) { |
||||
| 118 | $this->level++; |
||||
| 119 | } else { |
||||
| 120 | $this->level = 1; |
||||
| 121 | } |
||||
| 122 | |||||
| 123 | $this->snId = $hireId; |
||||
| 124 | |||||
| 125 | $this->setExternalData(); |
||||
| 126 | } |
||||
| 127 | |||||
| 128 | |||||
| 129 | protected function reset() { |
||||
| 130 | unset($this->unit); |
||||
| 131 | $this->planet = null; |
||||
| 132 | |||||
| 133 | $this->snId = 0; |
||||
| 134 | $this->level = 0; |
||||
| 135 | } |
||||
| 136 | |||||
| 137 | /** |
||||
| 138 | * Sets data on external sources from internal properties |
||||
| 139 | */ |
||||
| 140 | protected function setExternalData() { |
||||
| 141 | $this->planet->PLANET_GOVERNOR_ID = $this->getSnId(); |
||||
| 142 | $this->planet->PLANET_GOVERNOR_LEVEL = $this->level; |
||||
| 143 | } |
||||
| 144 | |||||
| 145 | /** |
||||
| 146 | * Loads some data from external sources |
||||
| 147 | */ |
||||
| 148 | protected function getExternalData() { |
||||
| 149 | $this->snId = !empty($this->planet->PLANET_GOVERNOR_ID) ? intval($this->planet->PLANET_GOVERNOR_ID) : 0; |
||||
| 150 | $this->level = !empty($this->planet->PLANET_GOVERNOR_LEVEL) ? intval($this->planet->PLANET_GOVERNOR_LEVEL) : 0; |
||||
| 151 | } |
||||
| 152 | |||||
| 153 | } |
||||
| 154 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths