public static function getInstance() { if (!LevelsGrid::$instance) { LevelsGrid::$instance = new LevelsGrid(); } return LevelsGrid::$instance; }
public static function initForTeam(&$team) { $sponsorsStore = array(); $sponsorRate = 1; $sponsorsStore = RAM::getInstance()->getObjectsForTeam($team->getSocialUserId(), RAM::RAM_TYPE_SPONSOR); if (count($sponsorsStore) != $team->getSponsorsCount() || $team->getSponsorsCount() == 0) { //] || GlobalParameters::$IS_FAKE_ENTER // || GlobalParameters::MODER_ID == $team->getSocialUserId()){ $sponsorsStore = array(); $sql_template = "SELECT\n item_sponsors.id,\n item_sponsors.energy,\n item_sponsors.required_level\nFROM sponsors\nLEFT JOIN item_sponsors ON item_sponsors.id = sponsors.sponsor_id\nWHERE vk_id = '%s'"; $sql = sprintf($sql_template, $team->getSocialUserId()); $SQLresult = SQL::getInstance()->query($sql); if ($SQLresult instanceof ErrorPoint) { return $SQLresult; } $team->setSponsorsCount($SQLresult->num_rows, true); if ($SQLresult->num_rows) { $counter = 0; while ($sponsor = $SQLresult->fetch_object()) { $sponsorInstance = new Sponsor(); $sponsorInstance->initFromParameters($sponsor); $sponsorRate *= $sponsorInstance->getEnergy(); $sponsorsStore[$sponsorInstance->getId()] = $sponsorInstance; RAM::getInstance()->setSponsor($sponsorInstance, $team->getSocialUserId(), $counter); $counter++; } if (count($sponsorsStore) > GlobalParameters::SPONSORS_LIMIT) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Количество спонсоров превышет допустимого значения " . count($sponsorsStore) . " - " . $SQLresult->num_rows, ErrorPoint::TYPE_SYSTEM); } $team->setSponsorRate($sponsorRate); $team->setMaxEnergy($sponsorRate * LevelsGrid::getInstance()->getBaseEnergy($team->getLevel())); } } else { foreach ($sponsorsStore as $sponsorInstance) { $sponsorRate *= $sponsorInstance->getEnergy(); } } return $sponsorsStore; }
public function action() { SQL::getInstance()->autocommit(false); $actionResult = SponsorSatellite::erase(); /* $sponsorsStoreInRAM = RAM::getInstance()->getObjectsForTeam(UserParameters::getUserId(), RAM::RAM_TYPE_SPONSOR); foreach ($sponsorsStoreInRAM as $sponsorInstance){ RAM::getInstance()->deleteSponsor($sponsorInstance->getId(), UserParameters::getUserId()); } */ track_stats(); // Отслеживаем производительность $energyRate = 1; $sponsorsStore = array(); $actionResult = NULL; if (!is_object($this->parameters) && !is_array($this->parameters)) { $this->parameters = str_replace('\\\\"', '', $this->parameters); $this->parameters = str_replace(']\\"', ']', $this->parameters); $this->parameters = str_replace('\\"[', '[', $this->parameters); $this->parameters = json_decode($this->parameters); } track_stats(); // Отслеживаем производительность if (!Utils::isEmpty($this->parameters) && !$actionResult instanceof ErrorPoint) { $sponsorDBResult = SponsorSatellite::getFromStoreByIds($this->parameters); $sponsorCount = count($sponsorDBResult); track_stats(); // Отслеживаем производительность if ($sponsorDBResult instanceof ErrorPoint) { $actionResult = $sponsorDBResult; } elseif ($sponsorCount) { if ($sponsorCount > GlobalParameters::SPONSORS_LIMIT) { $actionResult = new ErrorPoint(ErrorPoint::CODE_LOGIC, "Количество спонсоров превышет допустимый предел. Получено " . $sponsorCount . " спонсоров ", ErrorPoint::TYPE_SYSTEM); } else { track_stats(); // Отслеживаем производительность foreach ($sponsorDBResult as $sponsor) { $sponsorInstance = new Sponsor(); $sponsorInstance->initFromParameters($sponsor); if ($sponsorInstance->getRequiredLevel() > $this->teamProfile->getLevel()) { $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Спонсор не доступен по уровню. Уровень спонсора: " . $sponsorInstance->getRequiredLevel() . ", а у вас " . intval($this->teamProfile->getLevel()), ErrorPoint::TYPE_USER); break; } $actionResult = $sponsorInstance->save(); if ($actionResult instanceof ErrorPoint) { break; } $energyRate *= $sponsorInstance->getEnergy(); $sponsorsStore[] = $sponsorInstance; } track_stats(); // Отслеживаем производительность } } } if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } if ($energyRate < 1) { $energyRate = 1; } track_stats(); // Отслеживаем производительность $this->teamProfile->setSponsorRate($energyRate); $this->teamProfile->setMaxEnergy($energyRate * LevelsGrid::getInstance()->getBaseEnergy($this->teamProfile->getLevel())); $this->teamProfile->bindSponsors($sponsorsStore); $actionResult = $this->teamProfile->save(); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); } else { SQL::getInstance()->commit(); } track_stats(); // Отслеживаем производительность return $actionResult; }
public function addExperience($xp) { $this->setExperience($this->getExperience() + $xp); $nextLevelXp = LevelsGrid::getInstance()->getNextLevelExp($this->getLevel()); if ($this->getExperience() >= $nextLevelXp) { if (LevelsGrid::getInstance()->levelExist($this->getLevel() + 1)) { $this->setLevel($this->getLevel() + 1); $this->setExperience($this->getExperience() - $nextLevelXp); $this->setStudyPoints(LevelsGrid::getInstance()->getStudyPoints($this->getLevel() - 1) + $this->getCoachMultiplay() + $this->getStudyPoints()); $this->setEnergyMax(floor(LevelsGrid::getInstance()->getBaseEnergy($this->getLevel()) * $this->getSponsorRage())); return true; } else { $this->setExperience($nextLevelXp); } } return false; }
// Home //define("SYSTEM_PATH", ".."); define("SYSTEM_PATH", "C:/srv/footboll/server"); break; } include_once SYSTEM_PATH . "/System/settings.php"; include_once SYSTEM_PATH . "/System/function.php"; register_shutdown_function('shutdown'); set_error_handler("handlerError"); $actionResult = null; if (SQL::getInstance()->connect_error) { $actionResult = new ErrorPoint(ErrorPoint::CODE_SQL, "Соединение провалено (" . SQL::getInstance()->connect_error . ")", ErrorPoint::TYPE_SYSTEM); die("No connection"); } $sql = "UPDATE teams set level = " . GlobalParameters::START_LEVEL . ", money = " . GlobalParameters::START_MONEY . ", money_real = " . GlobalParameters::START_REAL_MONEY . " " . " where level = 0 "; SQL::getInstance()->query($sql); echo "Fixed users: " . SQL::getInstance()->affected_rows . " " . PHP_EOL; $sql_template = "SELECT teams.level, teams.vk_id, (\nSELECT EXP(SUM(LOG(item_sponsors.energy))) FROM sponsors\nJOIN item_sponsors ON item_sponsors.id = sponsors.sponsor_id\nWHERE teams.vk_id = sponsors.vk_id\nGROUP BY sponsors.vk_id\n) AS sponsorIndex FROM teams WHERE teams.energy_max = 0"; $sql = sprintf($sql_template); $fixDBResult = SQL::getInstance()->query($sql); if ($fixDBResult->num_rows) { while ($team = $fixDBResult->fetch_object()) { if (empty($team->sponsorIndex)) { $team->sponsorIndex = 1; } $max = floor(floatval($team->sponsorIndex) * LevelsGrid::getInstance()->getBaseEnergy($team->level)); $sql = "UPDATE teams set energy_max = " . $max . " where vk_id = " . $team->vk_id; SQL::getInstance()->query($sql); } } echo str_repeat(" ", 27) . date("[Y-m-d H:i:s.m]") . ", updated users: " . $fixDBResult->num_rows . " " . PHP_EOL;