Esempio n. 1
0
 function processSetup($map_size, $adminEmail)
 {
     $this->_createTables();
     $this->_createMap($map_size);
     if ($this->_createAdminPlayer($map_size, $adminEmail)) {
         $raiseTime = 10 / $GLOBALS['GameMetadata']['game_speed'];
         $raiseTime *= 2592000;
         $raiseTime = intval($raiseTime);
         if ($raiseTime < 2592000) {
             $raiseTime = 2592000;
         }
         $queueModel = new QueueModel();
         new QueueTask($queueModel->addTask(QS_TATAR_RAISE, 0, $raiseTime));
         GameLicense::set(WebHelper::getdomain());
     }
 }
Esempio n. 2
0
 /**
  * Updates `where` part of query to exclude queueUsers
  * @param $exclude bool
  * @param RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter
  * @param $where
  */
 protected static function excludeQueueUsers($exclude, RedBeanModelJoinTablesQueryAdapter &$joinTablesAdapter, &$where)
 {
     if ($exclude) {
         $queueModelTableName = QueueModel::getTableName();
         $excludeQueueUsersWhere = "(_user.id not in (select queueuser__user_id from {$queueModelTableName}";
         $excludeQueueUsersWhere .= " where queueuser__user_id is not null)) and {$where}";
         $where = $excludeQueueUsersWhere;
     }
 }
Esempio n. 3
0
 public function upgradeBuilding($villageId, $bid, $itemId, $drop = FALSE)
 {
     $customAction = FALSE;
     $GameMetadata = $GLOBALS['GameMetadata'];
     $villageRow = $this->provider->fetchRow("SELECT\r\n\t\t\t\tv.player_id,\r\n\t\t\t\tv.alliance_id,\r\n\t\t\t\tv.buildings,\r\n\t\t\t\tv.resources,\r\n\t\t\t\tv.cp,\r\n\t\t\t\tv.crop_consumption,\r\n\t\t\t\tv.time_consume_percent,\r\n\t\t\t\tTIME_TO_SEC(TIMEDIFF(NOW(), v.last_update_date)) elapsedTimeInSeconds \r\n\t\t\tFROM p_villages v\r\n\t\t\tWHERE v.id=%s", array(intval($villageId)));
     if (intval($villageRow['player_id']) == 0) {
         return $customAction;
     }
     $buildings = $this->_getBuildingsArray($villageRow['buildings']);
     $build = $buildings[$bid];
     $buildingMetadata = $GameMetadata['items'][$itemId];
     if ($build['item_id'] != $itemId) {
         return $customAction;
     }
     if ($drop && $build['level'] <= 0) {
         return $customAction;
     }
     $LevelOffset = $drop ? 0 - 1 : 1;
     $_resFactor = $itemId <= 4 ? $GameMetadata['game_speed'] : 1;
     $buildingLevel = $build['level'];
     $oldValue = ($buildingLevel == 0 ? $itemId <= 4 ? 2 : 0 : $buildingMetadata['levels'][$buildingLevel - 1]['value']) * $_resFactor;
     $oldCP = $buildingLevel == 0 ? 0 : $buildingMetadata['levels'][$buildingLevel - 1]['cp'];
     $newBuildingLevel = $buildingLevel + $LevelOffset;
     $newValue = ($newBuildingLevel == 0 ? $itemId <= 4 ? 2 : 0 : $buildingMetadata['levels'][$newBuildingLevel - 1]['value']) * $_resFactor;
     $newCP = $newBuildingLevel == 0 ? 0 : $buildingMetadata['levels'][$newBuildingLevel - 1]['cp'];
     $value_inc = $newValue - $oldValue;
     $people_inc = $drop ? 0 - 1 * $buildingMetadata['levels'][$buildingLevel - 1]['people_inc'] : $buildingMetadata['levels'][$newBuildingLevel - 1]['people_inc'];
     $resultArr = $this->_getResourcesArray($villageRow['resources'], $villageRow['elapsedTimeInSeconds'], $villageRow['crop_consumption'], $villageRow['cp']);
     $resultArr['cp']['cpRate'] += $newCP - $oldCP;
     $allegiance_percent_inc = 0;
     switch ($itemId) {
         case 1:
         case 2:
         case 3:
         case 4:
             $resultArr['resources'][$itemId]['prod_rate'] += $value_inc;
             break;
         case 5:
         case 6:
         case 7:
         case 8:
             $resultArr['resources'][$itemId - 4]['prod_rate_percentage'] += $value_inc;
             break;
         case 9:
             $resultArr['resources'][4]['prod_rate_percentage'] += $value_inc;
             break;
         case 10:
         case 38:
             $newStorage = $resultArr['resources'][1]['store_max_limit'] == $resultArr['resources'][1]['store_init_limit'] ? 0 : $resultArr['resources'][1]['store_max_limit'];
             $newStorage = $newStorage + $value_inc;
             if ($newStorage < $resultArr['resources'][1]['store_init_limit']) {
                 $newStorage = $resultArr['resources'][1]['store_init_limit'];
             }
             $resultArr['resources'][1]['store_max_limit'] = $resultArr['resources'][2]['store_max_limit'] = $resultArr['resources'][3]['store_max_limit'] = $newStorage;
             break;
         case 11:
         case 39:
             $newStorage = $resultArr['resources'][4]['store_max_limit'] == $resultArr['resources'][4]['store_init_limit'] ? 0 : $resultArr['resources'][4]['store_max_limit'];
             $newStorage = $newStorage + $value_inc;
             if ($newStorage < $resultArr['resources'][4]['store_init_limit']) {
                 $newStorage = $resultArr['resources'][4]['store_init_limit'];
             }
             $resultArr['resources'][4]['store_max_limit'] = $newStorage;
             break;
         case 15:
             $villageRow['time_consume_percent'] = $newValue == 0 ? 300 : $newValue;
             break;
         case 18:
             if (0 < intval($villageRow['alliance_id']) && !$drop) {
                 $this->provider->executeQuery("UPDATE p_alliances a\r\n\t\t\t\t\t\tSET\r\n\t\t\t\t\t\t\ta.max_player_count=%s\r\n\t\t\t\t\t\tWHERE a.id=%s AND a.creator_player_id=%s AND a.max_player_count<%s", array($newValue, intval($villageRow['alliance_id']), intval($villageRow['player_id']), $newValue));
             }
             break;
         case 25:
         case 26:
             if (!$drop) {
                 $allegiance_percent_inc = 10;
             }
             break;
         case 40:
             if ($newBuildingLevel == sizeof($buildingMetadata['levels'])) {
                 break;
             }
             $customAction = TRUE;
             $this->provider->executeQuery("DELETE FROM p_queue");
             require_once MODEL_PATH . "queue.php";
             $resetTime = 259200;
             $queueModel = new QueueModel();
             $queueModel->addTask(new QueueTask(QS_SITE_RESET, 0, $resetTime));
             $this->provider->executeQuery("UPDATE g_settings gs SET gs.game_over=1, gs.win_pid=%s", array(intval($villageRow['player_id'])));
     }
     $buildings[$bid]['level'] += $LevelOffset;
     if (!$drop) {
         --$buildings[$bid]['update_state'];
     } else {
         if ($buildings[$bid]['level'] <= 0 && $buildings[$bid]['update_state'] == 0 && 4 < $buildings[$bid]['item_id']) {
             $buildings[$bid]['item_id'] = 0;
         }
     }
     if ($buildings[$bid]['update_state'] < 0) {
         $buildings[$bid]['update_state'] = 0;
     }
     $buildingsString = $this->_getBuildingString($buildings);
     $this->provider->executeQuery("UPDATE p_villages v \r\n\t\t\tSET\r\n\t\t\t\tv.buildings='%s',\r\n\t\t\t\tv.resources='%s',\r\n\t\t\t\tv.cp='%s',\r\n\t\t\t\tv.crop_consumption=v.crop_consumption+%s,\r\n\t\t\t\tv.people_count=v.people_count+%s,\r\n\t\t\t\tv.time_consume_percent=%s,\r\n\t\t\t\tv.allegiance_percent=IF(v.allegiance_percent+%s>=100, 100, v.allegiance_percent+%s),\r\n\t\t\t\tv.last_update_date=NOW()\r\n\t\t\tWHERE v.id=%s", array($buildingsString, $this->_getResourcesString($resultArr['resources']), $resultArr['cp']['cpValue'] . " " . $resultArr['cp']['cpRate'], $people_inc, $people_inc, $villageRow['time_consume_percent'], $allegiance_percent_inc, $allegiance_percent_inc, intval($villageId)));
     $devPoint = $people_inc;
     $this->provider->executeQuery("UPDATE p_players p\r\n\t\t\tSET\r\n\t\t\t\tp.total_people_count=p.total_people_count+%s,\r\n\t\t\t\tp.week_dev_points=p.week_dev_points+%s\r\n\t\t\tWHERE p.id=%s", array($people_inc, $devPoint, intval($villageRow['player_id'])));
     if (0 < intval($villageRow['alliance_id'])) {
         $this->provider->executeQuery("UPDATE p_alliances a\r\n\t\t\t\tSET\r\n\t\t\t\t\ta.week_dev_points=a.week_dev_points+%s\r\n\t\t\t\tWHERE a.id=%s", array($devPoint, intval($villageRow['alliance_id'])));
     }
     return $customAction;
 }