/build_decoded.php
PHP | 1682 lines | 1618 code | 42 blank | 22 comment | 510 complexity | e534ff882a0cea1154609995335272e0 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /*********************/
- /* */
- /* Dezend for PHP5 */
- /* NWS */
- /* Nulled.WS */
- /* */
- /*********************/
- require( ".".DIRECTORY_SEPARATOR."app".DIRECTORY_SEPARATOR."boot.php" );
- require_once( MODEL_PATH."build.php" );
- class GPage extends VillagePage
- {
- public $productionPane = TRUE;
- public $buildingView = "";
- public $buildingIndex = -1;
- public $buildProperties = NULL;
- public $newBuilds = NULL;
- public $troopsUpgrade;
- public $troopsUpgradeType;
- public $buildingTribeFactor;
- public $troops = array( );
- public $selectedTabIndex = 0;
- public $villageOases;
- public $childVillages;
- public $hasHero = FALSE;
- public $totalCpRate;
- public $totalCpValue;
- public $neededCpValue;
- public $childVillagesCount;
- public $showBuildingForm;
- public $embassyProperty;
- public $merchantProperty;
- public $rallyPointProperty;
- public $crannyProperty = array( 'buildingCount' => 0, 'totalSize' => 0 );
- public $warriorMessage = "";
- public $dataList;
- public $pageSize = 40;
- public $pageCount;
- public $pageIndex;
- public function GPage( )
- {
- parent::villagepage( );
- $this->viewFile = "build.phtml";
- $this->contentCssClass = "build";
- }
- public function onLoadBuildings( $building )
- {
- $GameMetadata = $GLOBALS['GameMetadata'];
- if ( $this->buildingIndex == 0 - 1 && isset( $_GET['bid'] ) && is_numeric( $_GET['bid'] ) && $_GET['bid'] == $building['item_id'] )
- {
- $this->buildingIndex = $building['index'];
- }
- if ( $building['item_id'] == 23 && 0 < $building['level'] )
- {
- ++$this->crannyProperty['buildingCount'];
- $this->crannyProperty['totalSize'] += $this->crannyProperty['buildingCount'];
- }
- }
- public function load( )
- {
- parent::load( );
- if ( $this->buildingIndex == 0 - 1 && isset( $_GET['id'] ) && is_numeric( $_GET['id'] ) && isset( $this->buildings[$_GET['id']] ) )
- {
- $this->buildingIndex = intval( $_GET['id'] );
- }
- $this->buildProperties = $this->getBuildingProperties( $this->buildingIndex );
- if ( $this->buildProperties == NULL )
- {
- $this->redirect( "village1.php" );
- }
- else if ( $this->buildProperties['emptyPlace'] )
- {
- $this->villagesLinkPostfix .= "&id=".$this->buildingIndex;
- $this->newBuilds = array(
- "available" => array( ),
- "soon" => array( )
- );
- foreach ( $this->gameMetadata['items'] as $item_id => $build )
- {
- if ( $item_id <= 4 || !isset( $build['for_tribe_id'][$this->tribeId] ) )
- {
- continue;
- }
- $canBuild = $this->canCreateNewBuild( $item_id );
- if ( $canBuild != 0 - 1 )
- {
- if ( $canBuild )
- {
- if ( !isset( $this->newBuilds['available'][$build['levels'][0]['time_consume']] ) )
- {
- $this->newBuilds['available'][$build['levels'][0]['time_consume']] = array( );
- }
- $this->newBuilds['available'][$build['levels'][0]['time_consume']][$item_id] = $build;
- }
- else
- {
- $dependencyCount = 0;
- foreach ( $build['pre_requests'] as $reqId => $reqValue )
- {
- if ( $reqValue != NULL )
- {
- $build['pre_requests_dependencyCount'][$reqId] = $reqValue - $this->_getMaxBuildingLevel( $reqId );
- $dependencyCount += $build['pre_requests_dependencyCount'][$reqId];
- }
- }
- if ( !isset( $this->newBuilds['soon'][$dependencyCount] ) )
- {
- $this->newBuilds['soon'][$dependencyCount] = array( );
- }
- $this->newBuilds['soon'][$dependencyCount][$item_id] = $build;
- }
- }
- }
- ksort( $this->newBuilds['available'], SORT_NUMERIC );
- ksort( $this->newBuilds['soon'], SORT_NUMERIC );
- }
- else
- {
- $bitemId = $this->buildProperties['building']['item_id'];
- $this->villagesLinkPostfix .= "&id=".$this->buildingIndex;
- if ( 4 < $bitemId )
- {
- $this->villagesLinkPostfix .= "&bid=".$bitemId;
- }
- $this->buildingTribeFactor = isset( $this->gameMetadata['items'][$bitemId]['for_tribe_id'][$this->data['tribe_id']] ) ? $this->gameMetadata['items'][$bitemId]['for_tribe_id'][$this->data['tribe_id']] : 1;
- if ( $this->buildings[$this->buildingIndex]['level'] == 0 )
- {
- return;
- }
- switch ( $bitemId )
- {
- case 12 :
- case 13 :
- $this->productionPane = FALSE;
- $this->buildingView = "Blacksmith_Armoury";
- $this->handleBlacksmithArmoury( );
- break;
- case 15 :
- if ( 10 <= $this->buildings[$this->buildingIndex]['level'] )
- {
- $this->buildingView = "MainBuilding";
- $this->handleMainBuilding( );
- }
- break;
- case 16 :
- $this->productionPane = FALSE;
- $this->buildingView = "RallyPoint";
- $this->handleRallyPoint( );
- break;
- case 17 :
- $this->productionPane = FALSE;
- $this->buildingView = "Marketplace";
- $this->handleMarketplace( );
- break;
- case 18 :
- $this->productionPane = FALSE;
- $this->buildingView = "Embassy";
- $this->handleEmbassy( );
- break;
- case 19 :
- case 20 :
- case 21 :
- case 29 :
- case 30 :
- case 36 :
- $this->_getOnlyMyTroops( );
- $this->productionPane = $bitemId == 36;
- $this->buildingView = "TroopBuilding";
- $this->handleTroopBuilding( );
- break;
- case 22 :
- $this->productionPane = FALSE;
- $this->buildingView = "Academy";
- $this->handleAcademy( );
- break;
- case 23 :
- $this->productionPane = TRUE;
- $this->buildingView = "Cranny";
- break;
- case 24 :
- $this->productionPane = FALSE;
- $this->buildingView = "TownHall";
- $this->handleTownHall( );
- break;
- case 25 :
- case 26 :
- $this->productionPane = FALSE;
- $this->buildingView = "Residence_Palace";
- $this->handleResidencePalace( );
- break;
- case 37 :
- $this->productionPane = FALSE;
- $this->buildingView = "HerosMansion";
- $this->handleHerosMansion( );
- break;
- case 40 :
- $this->productionPane = FALSE;
- break;
- case 42 :
- $this->_getOnlyMyTroops( );
- $this->productionPane = TRUE;
- $this->buildingView = "Warrior";
- $this->handleWarrior( );
- }
- }
- }
- public function handleBlacksmithArmoury( )
- {
- $this->troopsUpgradeType = $this->buildings[$this->buildingIndex]['item_id'] == 12 ? QS_TROOP_UPGRADE_ATTACK : QS_TROOP_UPGRADE_DEFENSE;
- $this->troopsUpgrade = array( );
- $_arr = explode( ",", $this->data['troops_training'] );
- $_c = 0;
- foreach ( $_arr as $troopStr )
- {
- ++$_c;
- $attack_level = explode( " ", $troopStr );
- $defense_level = explode( " ", $troopStr );
- $researches_done = explode( " ", $troopStr );
- $troopId = explode( " ", $troopStr );
- list( $troopId, $researches_done, $defense_level, $attack_level ) = $troopId;
- $tlevel = $this->troopsUpgradeType == QS_TROOP_UPGRADE_ATTACK ? $attack_level : $defense_level;
- if ( $troopId != 99 && $_c <= 8 && $tlevel < 20 && $researches_done == 1 )
- {
- $this->troopsUpgrade[$troopId] = $tlevel;
- }
- }
- if ( isset( $_GET['a'], $_GET['k'] ) && $_GET['k'] == $this->data['update_key'] && !isset( $this->queueModel->tasksInQueue[$this->troopsUpgradeType] ) && isset( $this->troopsUpgrade[intval( $_GET['a'] )] ) && !$this->isGameTransientStopped( ) && !$this->isGameOver( ) )
- {
- $troopId = intval( $_GET['a'] );
- $level = $this->troopsUpgrade[$troopId];
- $buildingMetadata = $this->gameMetadata['items'][$this->buildProperties['building']['item_id']]['troop_upgrades'][$troopId][$level];
- if ( !$this->isResourcesAvailable( $buildingMetadata['resources'] ) )
- {
- }
- else
- {
- $calcConsume = intval( $buildingMetadata['time_consume'] / $this->gameSpeed * ( 10 / ( $this->buildProperties['building']['level'] + 9 ) ) );
- $newTask = new QueueTask( $this->troopsUpgradeType, $this->player->playerId, $calcConsume );
- $newTask->villageId = $this->data['selected_village_id'];
- $newTask->procParams = $troopId." ".( $level + 1 );
- $newTask->tag = $buildingMetadata['resources'];
- $this->queueModel->addTask( $newTask );
- }
- }
- }
- public function handleMainBuilding( )
- {
- if ( $this->isPost( ) && isset( $_POST['drbid'] ) && 19 <= intval( $_POST['drbid'] ) && intval( $_POST['drbid'] ) <= sizeof( $this->buildings ) && isset( $this->buildings[$_POST['drbid']] ) && 0 < $this->buildings[$_POST['drbid']]['level'] && !isset( $this->queueModel->tasksInQueue[QS_BUILD_DROP] ) && !$this->isGameTransientStopped( ) && !$this->isGameOver( ) )
- {
- $item_id = $this->buildings[$_POST['drbid']]['item_id'];
- $calcConsume = intval( $this->gameMetadata['items'][$item_id]['levels'][$this->buildings[$_POST['drbid']]['level'] - 1]['time_consume'] / $this->gameSpeed * ( $this->data['time_consume_percent'] / 400 ) );
- $newTask = new QueueTask( QS_BUILD_DROP, $this->player->playerId, $calcConsume );
- $newTask->villageId = $this->data['selected_village_id'];
- $newTask->buildingId = $item_id;
- $newTask->procParams = $this->buildings[$_POST['drbid']]['index'];
- $this->queueModel->addTask( $newTask );
- }
- else if ( isset( $_GET['qid'] ) && is_numeric( $_GET['qid'] ) && isset( $_GET['k'] ) && $_GET['k'] == $this->data['update_key'] && isset( $_GET['d'] ) && isset( $this->queueModel->tasksInQueue[QS_BUILD_DROP] ) && !$this->isGameTransientStopped( ) && !$this->isGameOver( ) )
- {
- $this->queueModel->cancelTask( $this->player->playerId, intval( $_GET['qid'] ) );
- }
- }
- public function handleRallyPoint( )
- {
- if ( isset( $_GET['d'] ) )
- {
- $this->queueModel->cancelTask( $this->player->playerId, intval( $_GET['d'] ) );
- }
- $this->rallyPointProperty = array(
- "troops_in_village" => array(
- "troopsTable" => $this->_getTroopsList( "troops_num" ),
- "troopsIntrapTable" => $this->_getTroopsList( "troops_intrap_num" )
- ),
- "troops_out_village" => array(
- "troopsTable" => $this->_getTroopsList( "troops_out_num" ),
- "troopsIntrapTable" => $this->_getTroopsList( "troops_out_intrap_num" )
- ),
- "troops_in_oases" => array( ),
- "war_to_village" => $this->queueModel->tasksInQueue['war_troops']['to_village'],
- "war_from_village" => $this->queueModel->tasksInQueue['war_troops']['from_village'],
- "war_to_oasis" => $this->queueModel->tasksInQueue['war_troops']['to_oasis']
- );
- $village_oases_id = trim( $this->data['village_oases_id'] );
- if ( $village_oases_id != "" )
- {
- $m = new BuildModel( );
- $result = $m->getOasesDataById( $village_oases_id );
- while ( $result->next( ) )
- {
- $this->rallyPointProperty['troops_in_oases'][$result->row['id']] = array(
- "oasisRow" => $result->row,
- "troopsTable" => $this->_getOasisTroopsList( $result->row['troops_num'] ),
- "war_to" => isset( $this->rallyPointProperty['war_to_oasis'][$result->row['id']] ) ? $this->rallyPointProperty['war_to_oasis'][$result->row['id']] : NULL
- );
- }
- $m->dispose( );
- }
- }
- public function _canCancelWarTask( $taskType, $taskId )
- {
- if ( !QueueTask::iscancelabletask( $taskType ) )
- {
- return FALSE;
- }
- $timeout = QueueTask::getmaxcanceltimeout( $taskType );
- if ( 0 - 1 < $timeout )
- {
- $_task = NULL;
- foreach ( $this->queueModel->tasksInQueue[$taskType] as $t )
- {
- if ( !( $t['id'] == $taskId ) )
- {
- continue;
- }
- $_task = $t;
- break;
- break;
- }
- if ( $_task == NULL )
- {
- return FALSE;
- }
- $elapsedTime = $t['elapsedTime'];
- if ( $timeout < $elapsedTime )
- {
- return FALSE;
- }
- }
- return TRUE;
- }
- public function _getOasisTroopsList( $troops_num )
- {
- $GameMetadata = $GLOBALS['GameMetadata'];
- $m = new BuildModel( );
- $returnTroops = array( );
- if ( trim( $troops_num ) != "" )
- {
- $t_arr = explode( "|", $troops_num );
- foreach ( $t_arr as $t_str )
- {
- $t2_arr = explode( ":", $t_str );
- $vid = $t2_arr[0];
- $villageData = $m->getVillageData2ById( $vid );
- $returnTroops[$vid] = array( "villageData" => $villageData, "cropConsumption" => 0, "hasHero" => FALSE, "troops" => array( ) );
- $t2_arr = explode( ",", $t2_arr[1] );
- foreach ( $t2_arr as $t2_str )
- {
- $tnum = explode( " ", $t2_str );
- $tid = explode( " ", $t2_str );
- list( $tid, $tnum ) = $tid;
- if ( $tid == 99 )
- {
- continue;
- }
- if ( $tnum == 0 - 1 )
- {
- $tnum = 1;
- $returnTroops[$vid]['hasHero'] = TRUE;
- }
- else
- {
- $returnTroops[$vid]['troops'][$tid] = $tnum;
- }
- $returnTroops[$vid]['cropConsumption'] += $GameMetadata['troops'][$tid]['crop_consumption'] * $tnum;
-
- }
- }
- }
- $m->dispose( );
- return $returnTroops;
- }
- public function _getTroopsList( $key )
- {
- $GameMetadata = $GLOBALS['GameMetadata'];
- $m = new BuildModel( );
- $returnTroops = array( );
- if ( trim( $this->data[$key] ) != "" )
- {
- $t_arr = explode( "|", $this->data[$key] );
- foreach ( $t_arr as $t_str )
- {
- $t2_arr = explode( ":", $t_str );
- $vid = intval( $t2_arr[0] );
- $villageData = NULL;
- if ( $vid == 0 - 1 )
- {
- $vid = $this->data['selected_village_id'];
- $villageData = array( "id" => $vid, "village_name" => $this->data['village_name'], "player_id" => $this->player->playerId, "player_name" => buildings_p_thisvillage );
- }
- else
- {
- $villageData = $m->getVillageData2ById( $vid );
- }
- $returnTroops[$vid] = array( "villageData" => $villageData, "cropConsumption" => 0, "hasHero" => FALSE, "troops" => array( ) );
- if ( $vid == $this->data['selected_village_id'] )
- {
- $returnTroops[$vid]['hasHero'] = intval( $this->data['hero_in_village_id'] ) == intval( $this->data['selected_village_id'] );
- if ( $returnTroops[$vid]['hasHero'] )
- {
- $returnTroops[$vid]['cropConsumption'] += $GameMetadata['troops'][$this->data['hero_troop_id']]['crop_consumption'];
- }
- }
- $t2_arr = explode( ",", $t2_arr[1] );
- foreach ( $t2_arr as $t2_str )
- {
- $tnum = explode( " ", $t2_str );
- $tid = explode( " ", $t2_str );
- list( $tid, $tnum ) = $tid;
- if ( $tid == 99 )
- {
- continue;
- }
- if ( $tnum == 0 - 1 )
- {
- $tnum = 1;
- $returnTroops[$vid]['hasHero'] = TRUE;
- }
- else
- {
- $returnTroops[$vid]['troops'][$tid] = $tnum;
- }
- $returnTroops[$vid]['cropConsumption'] += $GameMetadata['troops'][$tid]['crop_consumption'] * $tnum;
- }
- }
- }
- $m->dispose( );
- return $returnTroops;
- }
- public function handleMarketplace( )
- {
- $this->selectedTabIndex = isset( $_GET['t'] ) && is_numeric( $_GET['t'] ) && 1 <= intval( $_GET['t'] ) && intval( $_GET['t'] ) <= 3 ? intval( $_GET['t'] ) : 0;
- $itemId = $this->buildings[$this->buildingIndex]['item_id'];
- $itemLevel = $this->buildings[$this->buildingIndex]['level'];
- $tribeMetadata = $this->gameMetadata['tribes'][$this->data['tribe_id']];
- $tradeOfficeLevel = $this->_getMaxBuildingLevel( 28 );
- $capacityFactor = $tradeOfficeLevel == 0 ? 1 : $this->gameMetadata['items'][28]['levels'][$tradeOfficeLevel - 1]['value'] / 100;
- $capacityFactor *= $this->gameMetadata['game_speed'];
- $total_merchants_num = $this->gameMetadata['items'][$itemId]['levels'][$itemLevel - 1]['value'];
- $exist_num = $total_merchants_num - $this->queueModel->tasksInQueue['out_merchants_num'] - $this->data['offer_merchants_count'];
- if ( $exist_num < 0 )
- {
- $exist_num = 0;
- }
- $this->merchantProperty = array( "speed" => $tribeMetadata['merchants_velocity'] * $this->gameMetadata['game_speed'], "capacity" => floor( $tribeMetadata['merchants_capacity'] * $capacityFactor ), "total_num" => $total_merchants_num, "exits_num" => $exist_num, "confirm_snd" => FALSE, "same_village" => FALSE, "vRow" => NULL );
- if ( $this->selectedTabIndex == 0 )
- {
- $m = new BuildModel( );
- if ( $this->isPost( ) || isset( $_GET['vid2'] ) )
- {
- $resources = array( "1" => isset( $_POST['r1'] ) ? intval( $_POST['r1'] ) : 0, "2" => isset( $_POST['r2'] ) ? intval( $_POST['r2'] ) : 0, "3" => isset( $_POST['r3'] ) ? intval( $_POST['r3'] ) : 0, "4" => isset( $_POST['r4'] ) ? intval( $_POST['r4'] ) : 0 );
- $this->merchantProperty['confirm_snd'] = $this->isPost( ) ? isset( $_POST['act'] ) && $_POST['act'] == 1 : isset( $_GET['vid2'] );
- $map_size = $this->setupMetadata['map_size'];
- $doSend = FALSE;
- if ( $this->merchantProperty['confirm_snd'] )
- {
- $vRow = NULL;
- if ( trim( $_POST['y'] ) != "" )
- {
- $vid = $this->__getVillageId( $map_size, $this->__getCoordInRange( $map_size, intval( $_POST['x'] ) ), $this->__getCoordInRange( $map_size, intval( $_POST['y'] ) ) );
- $vRow = $m->getVillageDataById( $vid );
- }
- else
- {
- if ( isset( $_POST['vname'] ) && trim( $_POST['vname'] ) != "" )
- {
- $vRow = $m->getVillageDataByName( trim( $_POST['vname'] ) );
- }
- else
- {
- if ( isset( $_GET['vid2'] ) )
- {
- $vRow = $m->getVillageDataById( intval( $_GET['vid2'] ) );
- if ( $vRow != NULL )
- {
- $_POST['x'] = $vRow['rel_x'];
- $_POST['y'] = $vRow['rel_y'];
- }
- }
- }
- }
- }
- else
- {
- $doSend = TRUE;
- $vRow = $m->getVillageDataById( intval( $_POST['vid2'] ) );
- $this->merchantProperty['showError'] = FALSE;
- $_POST['r1'] = $_POST['r2'] = $_POST['r3'] = $_POST['r4'] = "";
- }
- if ( 0 < intval( $vRow['player_id'] ) && $m->getPlayType( intval( $vRow['player_id'] ) ) == PLAYERTYPE_ADMIN )
- {
- $this->merchantProperty['showError'] = FALSE;
- $this->merchantProperty['confirm_snd'] = FALSE;
- }
- else
- {
- $this->merchantProperty['vRow'] = $vRow;
- $vid = $this->merchantProperty['to_vid'] = $vRow != NULL ? $vRow['id'] : 0;
- $rel_x = $vRow['rel_x'];
- $rel_y = $vRow['rel_y'];
- $this->merchantProperty['same_village'] = $vid == $this->data['selected_village_id'];
- $this->merchantProperty['available_res'] = $this->isResourcesAvailable( $resources );
- $this->merchantProperty['vRow_merchant_num'] = ceil( ( $resources[1] + $resources[2] + $resources[3] + $resources[4] ) / $this->merchantProperty['capacity'] );
- $this->merchantProperty['confirm_snd'] = 0 < $vid && $this->merchantProperty['available_res'] && 0 < $this->merchantProperty['vRow_merchant_num'] && $this->merchantProperty['vRow_merchant_num'] <= $this->merchantProperty['exits_num'] && !$this->merchantProperty['same_village'];
- $this->merchantProperty['showError'] = !$this->merchantProperty['confirm_snd'];
- $distance = WebHelper::getdistance( $this->data['rel_x'], $this->data['rel_y'], $rel_x, $rel_y, $this->setupMetadata['map_size'] / 2 );
- $this->merchantProperty['vRow_time'] = intval( $distance / $this->merchantProperty['speed'] * 3600 );
- if ( !$this->merchantProperty['showError'] && $doSend && !$this->isGameTransientStopped( ) && !$this->isGameOver( ) )
- {
- $this->merchantProperty['confirm_snd'] = FALSE;
- $this->merchantProperty -= "exits_num";
- $newTask = new QueueTask( QS_MERCHANT_GO, $this->player->playerId, $this->merchantProperty['vRow_time'] );
- $newTask->villageId = $this->data['selected_village_id'];
- $newTask->toPlayerId = $vRow['player_id'];
- $newTask->toVillageId = $vid;
- $newTask->procParams = $this->merchantProperty['vRow_merchant_num']."|".( $resources[1]." ".$resources[2]." ".$resources[3]." ".$resources[4] );
- $newTask->tag = $resources;
- $this->queueModel->addTask( $newTask );
- }
- }
- }
- $m->dispose( );
- }
- else if ( $this->selectedTabIndex == 1 )
- {
- $m = new BuildModel( );
- $showOfferList = TRUE;
- if ( isset( $_GET['oid'] ) && 0 < intval( $_GET['oid'] ) )
- {
- $oRow = $m->getOffer2( intval( $_GET['oid'] ), $this->data['rel_x'], $this->data['rel_y'], $this->setupMetadata['map_size'] / 2 );
- if ( $oRow != NULL )
- {
- $aid = 0;
- if ( $oRow['alliance_only'] && 0 < intval( $this->data['alliance_id'] ) )
- {
- $aid = $m->getPlayerAllianceId( $oRow['player_id'] );
- }
- $res2 = explode( "|", $oRow['offer'] );
- $res1 = explode( "|", $oRow['offer'] );
- list( $res1, $res2 ) = $res1;
- $resArr1 = explode( " ", $res1 );
- $needResources = array( "1" => $resArr1[0], "2" => $resArr1[1], "3" => $resArr1[2], "4" => $resArr1[3] );
- $res1_item_id = 0;
- $res1_value = 0;
- $i = 0;
- $_c = sizeof( $resArr1 );
- while ( $i < $_c )
- {
- if ( 0 < $resArr1[$i] )
- {
- $res1_item_id = $i + 1;
- $res1_value = $resArr1[$i];
- break;
- }
- ++$i;
- }
- $resArr1 = explode( " ", $res2 );
- $giveResources = array( "1" => $resArr1[0], "2" => $resArr1[1], "3" => $resArr1[2], "4" => $resArr1[3] );
- $res2_item_id = 0;
- $res2_value = 0;
- $i = 0;
- $_c = sizeof( $resArr1 );
- while ( $i < $_c )
- {
- if ( 0 < $resArr1[$i] )
- {
- $res2_item_id = $i + 1;
- $res2_value = $resArr1[$i];
- break;
- }
- ++$i;
- }
- $distance = $oRow['timeInSeconds'] / 3600 * $oRow['merchants_speed'];
- $acceptResult = $this->_canAcceptOffer( $needResources, $giveResources, $oRow['village_id'], $oRow['alliance_only'], $aid, $oRow['max_time'], $distance );
- if ( $acceptResult == 5 && !$this->isGameTransientStopped( ) && !$this->isGameOver( ) )
- {
- $showOfferList = FALSE;
- $this->merchantProperty['offerProperty'] = array( "player_id" => $oRow['player_id'], "player_name" => $oRow['player_name'], "res1_item_id" => $res1_item_id, "res1_value" => $res1_value, "res2_item_id" => $res2_item_id, "res2_value" => $res2_value );
- $merchantNum = ceil( ( $giveResources[1] + $giveResources[2] + $giveResources[3] + $giveResources[4] ) / $this->merchantProperty['capacity'] );
- $newTask = new QueueTask( QS_MERCHANT_GO, $this->player->playerId, $distance / ( $this->gameMetadata['tribes'][$this->data['tribe_id']]['merchants_velocity'] * $this->gameMetadata['game_speed'] ) * 3600 );
- $newTask->villageId = $this->data['selected_village_id'];
- $newTask->toPlayerId = $oRow['player_id'];
- $newTask->toVillageId = $oRow['village_id'];
- $newTask->procParams = $merchantNum."|".( $giveResources[1]." ".$giveResources[2]." ".$giveResources[3]." ".$giveResources[4] );
- $newTask->tag = $giveResources;
- $this->queueModel->addTask( $newTask );
- $newTask = new QueueTask( QS_MERCHANT_GO, $oRow['player_id'], $oRow['timeInSeconds'] );
- $newTask->villageId = $oRow['village_id'];
- $newTask->toPlayerId = $this->player->playerId;
- $newTask->toVillageId = $this->data['selected_village_id'];
- $newTask->procParams = $oRow['merchants_num']."|".( $needResources[1]." ".$needResources[2]." ".$needResources[3]." ".$needResources[4] );
- $newTask->tag = array( "1" => 0, "2" => 0, "3" => 0, "4" => 0 );
- $this->queueModel->addTask( $newTask );
- $m->removeMerchantOffer( intval( $_GET['oid'] ), $oRow['player_id'], $oRow['village_id'] );
- }
- }
- }
- $this->merchantProperty['showOfferList'] = $showOfferList;
- if ( $showOfferList )
- {
- $rowsCount = $m->getAllOffersCount( $this->data['selected_village_id'], $this->data['rel_x'], $this->data['rel_y'], $this->setupMetadata['map_size'] / 2, $this->gameMetadata['tribes'][$this->data['tribe_id']]['merchants_velocity'] * $this->gameMetadata['game_speed'] );
- $this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
- $this->pageIndex = isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) && intval( $_GET['p'] ) < $this->pageCount ? intval( $_GET['p'] ) : 0;
- $this->merchantProperty['all_offers'] = $m->getAllOffers( $this->data['selected_village_id'], $this->data['rel_x'], $this->data['rel_y'], $this->setupMetadata['map_size'] / 2, $this->gameMetadata['tribes'][$this->data['tribe_id']]['merchants_velocity'] * $this->gameMetadata['game_speed'], $this->pageIndex, $this->pageSize );
- }
- $m->dispose( );
- }
- else
- {
- if ( $this->selectedTabIndex == 2 )
- {
- $m = new BuildModel( );
- $this->merchantProperty['showError'] = FALSE;
- $this->merchantProperty['showError2'] = FALSE;
- $this->merchantProperty['showError3'] = FALSE;
- if ( $this->isPost( ) )
- {
- if ( isset( $_POST['m1'] ) && 0 < intval( $_POST['m1'] ) && isset( $_POST['m2'] ) && 0 < intval( $_POST['m2'] ) && isset( $_POST['rid1'] ) && 0 < intval( $_POST['rid1'] ) && isset( $_POST['rid2'] ) && 0 < intval( $_POST['rid2'] ) )
- {
- $resources1 = array( "1" => isset( $_POST['rid1'] ) && intval( $_POST['rid1'] ) == 1 ? intval( $_POST['m1'] ) : 0, "2" => isset( $_POST['rid1'] ) && intval( $_POST['rid1'] ) == 2 ? intval( $_POST['m1'] ) : 0, "3" => isset( $_POST['rid1'] ) && intval( $_POST['rid1'] ) == 3 ? intval( $_POST['m1'] ) : 0, "4" => isset( $_POST['rid1'] ) && intval( $_POST['rid1'] ) == 4 ? intval( $_POST['m1'] ) : 0 );
- $resources2 = array( "1" => isset( $_POST['rid2'] ) && intval( $_POST['rid2'] ) == 1 ? intval( $_POST['m2'] ) : 0, "2" => isset( $_POST['rid2'] ) && intval( $_POST['rid2'] ) == 2 ? intval( $_POST['m2'] ) : 0, "3" => isset( $_POST['rid2'] ) && intval( $_POST['rid2'] ) == 3 ? intval( $_POST['m2'] ) : 0, "4" => isset( $_POST['rid2'] ) && intval( $_POST['rid2'] ) == 4 ? intval( $_POST['m2'] ) : 0 );
- if ( intval( $_POST['rid1'] ) == intval( $_POST['rid2'] ) || intval( $resources1[1] + $resources1[2] + $resources1[3] + $resources1[4] ) <= 0 || intval( $resources2[1] + $resources2[2] + $resources2[3] + $resources2[4] ) <= 0 )
- {
- $this->merchantProperty['showError'] = TRUE;
- }
- else if ( 10 < ceil( ( $resources2[1] + $resources2[2] + $resources2[3] + $resources2[4] ) / ( $resources1[1] + $resources1[2] + $resources1[3] + $resources1[4] ) ) )
- {
- $this->merchantProperty['showError'] = TRUE;
- $this->merchantProperty['showError3'] = TRUE;
- }
- $this->merchantProperty['available_res'] = $this->isResourcesAvailable( $resources1 );
- if ( $this->merchantProperty['available_res'] && !$this->merchantProperty['showError'] )
- {
- $this->merchantProperty['vRow_merchant_num'] = ceil( ( $resources1[1] + $resources1[2] + $resources1[3] + $resources1[4] ) / $this->merchantProperty['capacity'] );
- if ( 0 < $this->merchantProperty['vRow_merchant_num'] && $this->merchantProperty['vRow_merchant_num'] <= $this->merchantProperty['exits_num'] )
- {
- $this->merchantProperty -= "exits_num";
- $this->data += "offer_merchants_count";
- $offer = $resources1[1]." ".$resources1[2]." ".$resources1[3]." ".$resources1[4]."|".( $resources2[1]." ".$resources2[2]." ".$resources2[3]." ".$resources2[4] );
- $m->addMerchantOffer( $this->player->playerId, $this->data['name'], $this->data['selected_village_id'], $this->data['rel_x'], $this->data['rel_y'], $this->merchantProperty['vRow_merchant_num'], $offer, isset( $_POST['ally'] ), 0 < intval( $_POST['d2'] ) ? intval( $_POST['d2'] ) : 0, $this->gameMetadata['tribes'][$this->data['tribe_id']]['merchants_velocity'] * $this->gameMetadata['game_speed'] );
- foreach ( $resources1 as $k => $v )
- {
- $this->resources[$k] -= "current_value";
- }
- $this->queueModel->_updateVillage( FALSE, FALSE );
- }
- else
- {
- $this->merchantProperty['showError'] = TRUE;
- }
- }
- else
- {
- $this->merchantProperty['showError'] = TRUE;
- }
- }
- else
- {
- $this->merchantProperty['showError'] = TRUE;
- $this->merchantProperty['showError2'] = TRUE;
- }
- }
- else if ( isset( $_GET['d'] ) && 0 < intval( $_GET['d'] ) )
- {
- $row = $m->getOffer( intval( $_GET['d'] ), $this->player->playerId, $this->data['selected_village_id'] );
- if ( $row != NULL )
- {
- $this->merchantProperty += "exits_num";
- $this->data -= "offer_merchants_count";
- $resources2 = explode( "|", $row['offer'] );
- $resources1 = explode( "|", $row['offer'] );
- list( $resources1, $resources2 ) = $resources1;
- $resourcesArray1 = explode( " ", $resources1 );
- $res = array( );
- $i = 0;
- $_c = sizeof( $resourcesArray1 );
- while ( $i < $_c )
- {
- $res[$i + 1] = $resourcesArray1[$i];
- ++$i;
- }
- foreach ( $res as $k => $v )
- {
- $this->resources[$k] += "current_value";
- }
- $this->queueModel->_updateVillage( FALSE, FALSE );
- $m->removeMerchantOffer( intval( $_GET['d'] ), $this->player->playerId, $this->data['selected_village_id'] );
- }
- }
- $this->merchantProperty['offers'] = $m->getOffers( $this->data['selected_village_id'] );
- $m->dispose( );
- }
- else
- {
- if ( $this->selectedTabIndex == 3 && $this->isPost( ) && isset( $_POST['m2'] ) && is_array( $_POST['m2'] ) && sizeof( $_POST['m2'] ) == 4 && $this->gameMetadata['plusTable'][6]['cost'] <= $this->data['gold_num'] )
- {
- $resources = array( "1" => intval( $_POST['m2'][0] ), "2" => intval( $_POST['m2'][1] ), "3" => intval( $_POST['m2'][2] ), "4" => intval( $_POST['m2'][3] ) );
- $oldSum = $this->resources[1]['current_value'] + $this->resources[2]['current_value'] + $this->resources[3]['current_value'] + $this->resources[4]['current_value'];
- $newSum = $resources[1] + $resources[2] + $resources[3] + $resources[4];
- if ( $newSum <= $oldSum )
- {
- foreach ( $resources as $k => $v )
- {
- $this->resources[$k]['current_value'] = $v;
- }
- $this->queueModel->_updateVillage( FALSE, FALSE );
- $m = new BuildModel( );
- $m->decreaseGoldNum( $this->player->playerId, $this->gameMetadata['plusTable'][6]['cost'] );
- $m->dispose( );
- }
- }
- }
- }
- }
- public function handleEmbassy( )
- {
- if ( 0 < intval( $this->data['alliance_id'] ) )
- {
- }
- else
- {
- $this->embassyProperty = array( "level" => $this->buildings[$this->buildingIndex]['level'], "invites" => NULL, "error" => 0, "ally1" => "", "ally2" => "" );
- $maxPlayers = $this->gameMetadata['items'][18]['levels'][$this->embassyProperty['level'] - 1]['value'];
- $this->embassyProperty['ally1'] = $ally1 = trim( $_POST['ally1'] );
- $this->embassyProperty['ally2'] = $ally2 = trim( $_POST['ally2'] );
- if ( $ally1 == "" || $ally2 == "" )
- {
- $this->embassyProperty['error'] = $ally1 == "" && $ally2 == "" ? 3 : $ally1 == "" ? 1 : 2;
- }
- else
- {
- $m = new BuildModel( );
- if ( !$m->allianceExists( $this->embassyProperty['ally1'] ) )
- {
- $this->data['alliance_name'] = $this->embassyProperty['ally1'];
- $this->data['alliance_id'] = $m->createAlliance( $this->player->playerId, $this->embassyProperty['ally1'], $this->embassyProperty['ally2'], $maxPlayers );
- $m->dispose( );
- }
- else
- {
- $this->embassyProperty['error'] = 4;
- $m->dispose( );
- }
- }
- $invites_alliance_ids = trim( $this->data['invites_alliance_ids'] );
- $this->embassyProperty['invites'] = array( );
- if ( $invites_alliance_ids != "" )
- {
- $_arr = explode( "\n", $invites_alliance_ids );
- foreach ( $_arr as $_s )
- {
- $allianceName = explode( " ", $_s, 2 );
- $allianceId = explode( " ", $_s, 2 );
- list ( $allianceId, $allianceName ) = $allianceId;
- $this->embassyProperty['invites'][$allianceId] = $allianceName;
- }
- }
- if ( !$this->isPost( ) )
- {
- if ( isset( $_GET['a'] ) && 0 < intval( $_GET['a'] ) )
- {
- $allianceId = intval( $_GET['a'] );
- if ( isset( $this->embassyProperty['invites'][$allianceId] ) )
- {
- $m = new BuildModel( );
- $acceptResult = $m->acceptAllianceJoining( $this->player->playerId, $allianceId );
- if ( $acceptResult == 2 )
- {
- $this->data['alliance_name'] = $this->embassyProperty['invites'][$allianceId];
- $this->data['alliance_id'] = $allianceId;
- unset( $Var_4320['invites'][$allianceId] );
- $m->removeAllianceInvites( $this->player->playerId, $allianceId );
- }
- else if ( $acceptResult == 1 )
- {
- $this->embassyProperty['error'] = 15;
- }
- $m->dispose( );
- }
- }
- else
- {
- if ( isset( $_GET['d'] ) && 0 < intval( $_GET['d'] ) )
- {
- $allianceId = intval( $_GET['d'] );
- if ( isset( $this->embassyProperty['invites'][$allianceId] ) )
- {
- unset( $Var_5112['invites'][$allianceId] );
- $m = new BuildModel( );
- $m->removeAllianceInvites( $this->player->playerId, $allianceId );
- $m->dispose( );
- }
- }
- }
- }
- }
- }
- public function handleWarrior( )
- {
- $itemId = $this->buildings[$this->buildingIndex]['item_id'];
- $this->troopsUpgrade = array( );
- $_arr = explode( ",", $this->data['troops_training'] );
- foreach ( $_arr as $troopStr )
- {
- $attack_level = explode( " ", $troopStr );
- $defense_level = explode( " ", $troopStr );
- $researches_done = explode( " ", $troopStr );
- $troopId = explode( " ", $troopStr );
- list( $troopId, $researches_done, $defense_level, $attack_level ) = $troopId;
- if ( $researches_done == 1 && 0 < $this->gameMetadata['troops'][$troopId]['gold_needed'] )
- {
- $this->troopsUpgrade[$troopId] = $troopId;
- }
- }
- $this->warriorMessage = "";
- if ( $this->isPost( ) && isset( $_POST['tf'] ) && !$this->isGameTransientStopped( ) && !$this->isGameOver( ) )
- {
- $cropConsume = 0;
- $totalGoldsNeeded = 0;
- foreach ( $_POST['tf'] as $troopId => $num )
- {
- $num = intval( $num );
- if ( $num <= 0 || !isset( $this->troopsUpgrade[$troopId] ) )
- {
- continue;
- }
- $totalGoldsNeeded += $this->gameMetadata['troops'][$troopId]['gold_needed'] * $num;
- $cropConsume += $this->gameMetadata['troops'][$troopId]['crop_consumption'] * $num;
- }
- if ( $totalGoldsNeeded <= 0 )
- {
- }
- else
- {
- $canProcess = $totalGoldsNeeded <= $this->data['gold_num'];
- $this->warriorMessage = $canProcess ? 1 : 2;
- if ( $canProcess )
- {
- $troopsString = "";
- foreach ( $this->troops as $tid => $num )
- {
- if ( $tid == 99 )
- {
- continue;
- }
- $neededNum = isset( $this->troopsUpgrade[$tid], $_POST['tf'][$tid] ) ? $_POST['tf'][$tid] : 0;
- if ( $troopsString != "" )
- {
- $troopsString .= ",";
- }
- $troopsString .= $tid." ".$neededNum;
- }
- $m = new BuildModel( );
- $m->decreaseGoldNum( $this->player->playerId, $totalGoldsNeeded );
- $m->dispose( );
- $this->data -= "gold_num";
- $procParams = $troopsString."|0||||||1";
- $buildingMetadata = $this->gameMetadata['items'][$this->buildProperties['building']['item_id']];
- $bLevel = $this->buildings[$this->buildingIndex]['level'];
- $needed_time = $buildingMetadata['levels'][$bLevel - 1]['value'] * 3600;
- $newTask = new QueueTask( QS_WAR_REINFORCE, 0, $needed_time );
- $newTask->villageId = 0;
- $newTask->toPlayerId = $this->player->playerId;
- $newTask->toVillageId = $this->data['selected_village_id'];
- $newTask->procParams = $procParams;
- $newTask->tag = array( "troops" => NULL, "hasHero" => FALSE, "resources" => NULL, "troopsCropConsume" => $cropConsume );
- $this->queueModel->addTask( $newTask );
- }
- }
- }
- }
- public function handleTroopBuilding( )
- {
- $itemId = $this->buildings[$this->buildingIndex]['item_id'];
- $this->troopsUpgradeType = QS_TROOP_TRAINING;
- $this->troopsUpgrade = array( );
- $_arr = explode( ",", $this->data['troops_training'] );
- foreach ( $_arr as $troopStr )
- {
- $attack_level = explode( " ", $troopStr );
- $defense_level = explode( " ", $troopStr );
- $researches_done = explode( " ", $troopStr );
- $troopId = explode( " ", $troopStr );
- list( $troopId, $researches_done, $defense_level, $attack_level ) = $troopId;
- if ( $researches_done == 1 && $this->_canTrainInBuilding( $troopId, $itemId ) )
- {
- $this->troopsUpgrade[$troopId] = $troopId;
- }
- }
- if ( $this->isPost( ) && isset( $_POST['tf'] ) && !$this->isGameTransientStopped( ) && !$this->isGameOver( ) )
- {
- foreach ( $_POST['tf'] as $troopId => $num )
- {
- $num = intval( $num );
- if ( $num <= 0 || !isset( $this->troopsUpgrade[$troopId] ) || $this->_getMaxTrainNumber( $troopId, $itemId ) < $num )
- {
- continue;
- }
- $timeFactor = 1;
- if ( $this->gameMetadata['troops'][$troopId]['is_cavalry'] == TRUE )
- {
- $flvl = $this->_getMaxBuildingLevel( 41 );
- if ( 0 < $flvl )
- {
- $timeFactor -= $this->gameMetadata['items'][41]['levels'][$flvl - 1]['value'] / 100;
- }
- }
- $troopMetadata = $this->gameMetadata['troops'][$troopId];
- $calcConsume = intval( $troopMetadata['training_time_consume'] / $this->gameSpeed * ( 10 / ( $this->buildProperties['building']['level'] + 9 ) ) * $timeFactor );
- $newTask = new QueueTask( $this->troopsUpgradeType, $this->player->playerId, $calcConsume );
- $newTask->threads = $num;
- $newTask->villageId = $this->data['selected_village_id'];
- $newTask->buildingId = $this->buildProperties['building']['item_id'];
- $newTask->procParams = $troopId;
- $newTask->tag = array( "1" => $troopMetadata['training_resources'][1] * $this->buildingTribeFactor * $num, "2" => $troopMetadata['training_resources'][2] * $this->buildingTribeFactor * $num, "3" => $troopMetadata['training_resources'][3] * $this->buildingTribeFactor * $num, "4" => $troopMetadata['training_resources'][4] * $this->buildingTribeFactor * $num );
- $this->queueModel->addTask( $newTask );
- }
- }
- }
- public function handleAcademy( )
- {
- $this->troopsUpgradeType = QS_TROOP_RESEARCH;
- $this->troopsUpgrade = array( "available" => array( ), "soon" => array( ) );
- $_arr = explode( ",", $this->data['troops_training'] );
- foreach ( $_arr as $troopStr )
- {
- $attack_level = explode( " ", $troopStr );
- $defense_level = explode( " ", $troopStr );
- $researches_done = explode( " ", $troopStr );
- $troopId = explode( " ", $troopStr );
- list( $troopId, $researches_done, $defense_level, $attack_level ) = $troopId;
- if ( $researches_done == 0 )
- {
- $this->troopsUpgrade[$this->_canDoResearches( $troopId ) ? "available" : "soon"][] = $troopId;
- }
- }
- if ( $_GET['k'] == $this->data['update_key'] && !isset( $this->queueModel->tasksInQueue[$this->troopsUpgradeType] ) && $this->_canDoResearches( intval( $_GET['a'] ) ) && !$this->isGameTransientStopped( ) && !$this->isGameOver( ) )
- {
- $troopId = intval( $_GET['a'] );
- $buildingMetadata = $this->gameMetadata['troops'][$troopId];
- return;
- $calcConsume = intval( $buildingMetadata['research_time_consume'] / $this->gameSpeed );
- $newTask = new QueueTask( $this->troopsUpgradeType, $this->player->playerId, $calcConsume );
- $newTask->villageId = $this->data['selected_village_id'];
- $newTask->procParams = $troopId;
- $newTask->tag = $buildingMetadata['research_resources'];
- $this->queueModel->addTask( $newTask );
- }
- }
- public function handleTownHall( )
- {
- $buildingMetadata = $this->gameMetadata['items'][$this->buildProperties['building']['item_id']];
- $bLevel = $this->buildings[$this->buildingIndex]['level'];
- if ( $_GET['k'] == $this->data['update_key'] && !isset( $this->queueModel->tasksInQueue[QS_TOWNHALL_CELEBRATION] ) && !$this->isGameTransientStopped( ) && !$this->isGameOver( ) )
- {
- if ( intval( $_GET…
Large files files are truncated, but you can click here to view the full file