Advertisement
Guest User

Untitled

a guest
Apr 16th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.29 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by deZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 1.1.4.0
  8. * @ Author : DeZender
  9. * @ Release on : 30.03.2012
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. require( '.' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'boot.php' );
  15. require_once( MODEL_PATH . 'build.php' );
  16. class GPage extends VillagePage {
  17. var $productionPane = TRUE;
  18. var $buildingView = '';
  19. var $buildingIndex = -1;
  20. var $buildProperties = NULL;
  21. var $newBuilds = NULL;
  22. var $troopsUpgrade = null;
  23. var $troopsUpgradeType = null;
  24. var $buildingTribeFactor = null;
  25. var $troops = array( );
  26. var $selectedTabIndex = 0;
  27. var $villageOases = null;
  28. var $childVillages = null;
  29. var $hasHero = FALSE;
  30. var $totalCpRate = null;
  31. var $totalCpValue = null;
  32. var $neededCpValue = null;
  33. var $childVillagesCount = null;
  34. var $showBuildingForm = null;
  35. var $embassyProperty = null;
  36. var $merchantProperty = null;
  37. var $rallyPointProperty = null;
  38. var $crannyProperty = array( 'buildingCount' => 0, 'totalSize' => 0 );
  39. var $warriorMessage = '';
  40. var $dataList = null;
  41. var $pageSize = 40;
  42. var $pageCount = null;
  43. var $pageIndex = null;
  44.  
  45. function GPage() {
  46. parent::villagepage( );
  47. $this->viewFile = 'build.phtml';
  48. $this->contentCssClass = 'build';
  49. }
  50.  
  51. function onLoadBuildings($building) {
  52. $GameMetadata = $GLOBALS['GameMetadata'];
  53.  
  54. if (( ( ( $this->buildingIndex == 0 - 1 && isset( $_GET['bid'] ) ) && is_numeric( $_GET['bid'] ) ) && $_GET['bid'] == $building['item_id'] )) {
  55. $this->buildingIndex = $building['index'];
  56. }
  57.  
  58.  
  59. if (( $building['item_id'] == 23 && 0 < $building['level'] )) {
  60. ++$this->crannyProperty['buildingCount'];
  61. $this->crannyProperty += 'totalSize' = $GameMetadata['items'][$building['item_id']]['levels'][$building['level'] - 1]['value'] * $GameMetadata['items'][$building['item_id']]['for_tribe_id'][$this->tribeId];
  62. }
  63.  
  64. }
  65.  
  66. function load() {
  67. parent::load( );
  68.  
  69. if (( ( ( $this->buildingIndex == 0 - 1 && isset( $_GET['id'] ) ) && is_numeric( $_GET['id'] ) ) && isset( $this->buildings[$_GET['id']] ) )) {
  70. $this->buildingIndex = intval( $_GET['id'] );
  71. }
  72.  
  73. $this->buildProperties = $this->getBuildingProperties( $this->buildingIndex );
  74.  
  75. if ($this->buildProperties == NULL) {
  76. $this->redirect( 'village1.php' );
  77. return null;
  78. }
  79.  
  80.  
  81. if ($this->buildProperties['emptyPlace']) {
  82. $this->villagesLinkPostfix .= '&id=' . $this->buildingIndex;
  83. $this->newBuilds = array( 'available' => array( ), 'soon' => array( ) );
  84. foreach ($this->gameMetadata['items'] as $item_id => $build) {
  85. if (( $item_id <= 4 || !isset( $build['for_tribe_id'][$this->tribeId] ) )) {
  86. continue;
  87. }
  88.  
  89. $canBuild = $this->canCreateNewBuild( $item_id );
  90.  
  91. if ($canBuild != 0 - 1) {
  92. if ($canBuild) {
  93. if (!isset( $this->newBuilds['available'][$build['levels'][0]['time_consume']] )) {
  94. $this->newBuilds['available'][$build['levels'][0]['time_consume']] = array( );
  95. }
  96.  
  97. $this->newBuilds['available'][$build['levels'][0]['time_consume']][$item_id] = $build;
  98. continue;
  99. }
  100.  
  101. $dependencyCount = 0;
  102. foreach ($build['pre_requests'] as $reqId => $reqValue) {
  103. if ($reqValue != NULL) {
  104. $build['pre_requests_dependencyCount'][$reqId] = $reqValue - $this->_getMaxBuildingLevel( $reqId );
  105. $dependencyCount += $build['pre_requests_dependencyCount'][$reqId];
  106. continue;
  107. }
  108. }
  109.  
  110.  
  111. if (!isset( $this->newBuilds['soon'][$dependencyCount] )) {
  112. $this->newBuilds['soon'][$dependencyCount] = array( );
  113. }
  114.  
  115. $this->newBuilds['soon'][$dependencyCount][$item_id] = $build;
  116. continue;
  117. }
  118. }
  119.  
  120. ksort( $this->newBuilds['available'], SORT_NUMERIC );
  121. ksort( $this->newBuilds['soon'], SORT_NUMERIC );
  122. return null;
  123. }
  124.  
  125. $bitemId = $this->buildProperties['building']['item_id'];
  126. $this->villagesLinkPostfix .= '&id=' . $this->buildingIndex;
  127.  
  128. if (4 < $bitemId) {
  129. $this->villagesLinkPostfix .= '&bid=' . $bitemId;
  130. }
  131.  
  132. $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);
  133.  
  134. if ($this->buildings[$this->buildingIndex]['level'] == 0) {
  135. return null;
  136. }
  137.  
  138. switch ($bitemId) {
  139. case 12: {
  140. }
  141.  
  142. case 13: {
  143. $this->productionPane = FALSE;
  144. $this->buildingView = 'Blacksmith_Armoury';
  145. $this->handleBlacksmithArmoury( );
  146. break;
  147. }
  148.  
  149. case 15: {
  150. if (10 <= $this->buildings[$this->buildingIndex]['level']) {
  151. $this->buildingView = 'MainBuilding';
  152. $this->handleMainBuilding( );
  153. }
  154.  
  155. break;
  156. }
  157.  
  158. case 16: {
  159. $this->productionPane = FALSE;
  160. $this->buildingView = 'RallyPoint';
  161. $this->handleRallyPoint( );
  162. break;
  163. }
  164.  
  165. case 17: {
  166. $this->productionPane = FALSE;
  167. $this->buildingView = 'Marketplace';
  168. $this->handleMarketplace( );
  169. break;
  170. }
  171.  
  172. case 18: {
  173. $this->productionPane = FALSE;
  174. $this->buildingView = 'Embassy';
  175. $this->handleEmbassy( );
  176. break;
  177. }
  178.  
  179. case 19: {
  180. }
  181.  
  182. case 20: {
  183. }
  184.  
  185. case 21: {
  186. }
  187.  
  188. case 29: {
  189. }
  190.  
  191. case 30: {
  192. }
  193.  
  194. case 36: {
  195. $this->_getOnlyMyTroops( );
  196. $this->productionPane = $bitemId == 36;
  197. $this->buildingView = 'TroopBuilding';
  198. $this->handleTroopBuilding( );
  199. break;
  200. }
  201.  
  202. case 22: {
  203. $this->productionPane = FALSE;
  204. $this->buildingView = 'Academy';
  205. $this->handleAcademy( );
  206. break;
  207. }
  208.  
  209. case 23: {
  210. $this->productionPane = TRUE;
  211. $this->buildingView = 'Cranny';
  212. break;
  213. }
  214.  
  215. case 24: {
  216. $this->productionPane = FALSE;
  217. $this->buildingView = 'TownHall';
  218. $this->handleTownHall( );
  219. break;
  220. }
  221.  
  222. case 25: {
  223. }
  224.  
  225. case 26: {
  226. $this->productionPane = FALSE;
  227. $this->buildingView = 'Residence_Palace';
  228. $this->handleResidencePalace( );
  229. break;
  230. }
  231.  
  232. case 37: {
  233. $this->productionPane = FALSE;
  234. $this->buildingView = 'HerosMansion';
  235. $this->handleHerosMansion( );
  236. break;
  237. }
  238.  
  239. case 40: {
  240. $this->productionPane = FALSE;
  241. break;
  242. }
  243.  
  244. case 42: {
  245. $this->_getOnlyMyTroops( );
  246. $this->productionPane = TRUE;
  247. $this->buildingView = 'Warrior';
  248. $this->handleWarrior( );
  249. }
  250. }
  251.  
  252. }
  253.  
  254. function handleBlacksmithArmoury() {
  255. $this->troopsUpgradeType = ($this->buildings[$this->buildingIndex]['item_id'] == 12 ? QS_TROOP_UPGRADE_ATTACK : QS_TROOP_UPGRADE_DEFENSE);
  256. $this->troopsUpgrade = array( );
  257. $_arr = explode( ',', $this->data['troops_training'] );
  258. $_c = 0;
  259. foreach ($_arr as $troopStr) {
  260. ++$_c;
  261. list( $troopId, $researches_done, $defense_level, $attack_level ) = explode( ' ', $troopStr );
  262. $tlevel = ($this->troopsUpgradeType == QS_TROOP_UPGRADE_ATTACK ? $attack_level : $defense_level);
  263.  
  264. if (( ( ( $troopId != 99 && $_c <= 8 ) && $tlevel < 20 ) && $researches_done == 1 )) {
  265. $this->troopsUpgrade[$troopId] = $tlevel;
  266. continue;
  267. }
  268. }
  269.  
  270.  
  271. if (( ( ( ( ( ( isset( $_GET['a'] ) && isset( $_GET['k'] ) ) && $_GET['k'] == $this->data['update_key'] ) && !isset( $this->queueModel->tasksInQueue[$this->troopsUpgradeType] ) ) && isset( $this->troopsUpgrade[intval( $_GET['a'] )] ) ) && !$this->isGameTransientStopped( ) ) && !$this->isGameOver( ) )) {
  272. $troopId = intval( $_GET['a'] );
  273. $level = $this->troopsUpgrade[$troopId];
  274. $buildingMetadata = $this->gameMetadata['items'][$this->buildProperties['building']['item_id']]['troop_upgrades'][$troopId][$level];
  275.  
  276. if (!$this->isResourcesAvailable( $buildingMetadata['resources'] )) {
  277. return null;
  278. }
  279.  
  280. $calcConsume = intval( $buildingMetadata['time_consume'] / $this->gameSpeed * ( 10 / ( $this->buildProperties['building']['level'] + 9 ) ) );
  281. $newTask = new QueueTask( $this->troopsUpgradeType, $this->player->playerId, $calcConsume );
  282. $newTask->villageId = $this->data['selected_village_id'];
  283. $newTask->procParams = $troopId . ' ' . ( $level + 1 );
  284. $newTask->tag = $buildingMetadata['resources'];
  285. $this->queueModel->addTask( $newTask );
  286. }
  287.  
  288. }
  289.  
  290. function handleMainBuilding() {
  291. 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( ) )) {
  292. $item_id = $this->buildings[$_POST['drbid']]['item_id'];
  293. $calcConsume = intval( $this->gameMetadata['items'][$item_id]['levels'][$this->buildings[$_POST['drbid']]['level'] - 1]['time_consume'] / $this->gameSpeed * ( $this->data['time_consume_percent'] / 400 ) );
  294. $newTask = new QueueTask( QS_BUILD_DROP, $this->player->playerId, $calcConsume );
  295. $newTask->villageId = $this->data['selected_village_id'];
  296. $newTask->buildingId = $item_id;
  297. $newTask->procParams = $this->buildings[$_POST['drbid']]['index'];
  298. $this->queueModel->addTask( $newTask );
  299. return null;
  300. }
  301.  
  302.  
  303. 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( ) )) {
  304. $this->queueModel->cancelTask( $this->player->playerId, intval( $_GET['qid'] ) );
  305. }
  306.  
  307. }
  308.  
  309. function handleRallyPoint() {
  310. if (isset( $_GET['d'] )) {
  311. $this->queueModel->cancelTask( $this->player->playerId, intval( $_GET['d'] ) );
  312. }
  313.  
  314. $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'] );
  315. $village_oases_id = trim( $this->data['village_oases_id'] );
  316.  
  317. if ($village_oases_id != '') {
  318. $m = new BuildModel( );
  319. $result = $m->getOasesDataById( $village_oases_id );
  320.  
  321. while ($result->next( )) {
  322. $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) );
  323. }
  324.  
  325. $m->dispose( );
  326. }
  327.  
  328. }
  329.  
  330. function _canCancelWarTask($taskType, $taskId) {
  331. if (!QueueTask::iscancelabletask( $taskType )) {
  332. return FALSE;
  333. }
  334.  
  335. $timeout = QueueTask::getmaxcanceltimeout( $taskType );
  336.  
  337. if (0 - 1 < $timeout) {
  338. $_task = NULL;
  339. foreach ($this->queueModel->tasksInQueue[$taskType] as $t) {
  340. if ($t['id'] == $taskId) {
  341. $_task = $t;
  342. break;
  343. }
  344. }
  345.  
  346.  
  347. if ($_task == NULL) {
  348. return FALSE;
  349. }
  350.  
  351. $elapsedTime = $t['elapsedTime'];
  352.  
  353. if ($timeout < $elapsedTime) {
  354. return FALSE;
  355. }
  356. }
  357.  
  358. return TRUE;
  359. }
  360.  
  361. function _getOasisTroopsList(&$troops_num) {
  362. $GameMetadata = $GLOBALS['GameMetadata'];
  363. $m = new BuildModel( );
  364. $returnTroops = array( );
  365.  
  366. if (trim( $troops_num ) != '') {
  367. $t_arr = explode( '|', $troops_num );
  368. foreach ($t_arr as $t_str) {
  369. $t2_arr = explode( ':', $t_str );
  370. $vid = $t2_arr[0];
  371. $villageData = $m->getVillageData2ById( $vid );
  372. $returnTroops[$vid] = array( 'villageData' => $villageData, 'cropConsumption' => 0, 'hasHero' => FALSE, 'troops' => array( ) );
  373. $t2_arr = explode( ',', $t2_arr[1] );
  374. foreach ($t2_arr as $t2_str) {
  375. list( $tid, $tnum ) = explode( ' ', $t2_str );
  376.  
  377. if ($tid == 99) {
  378. continue;
  379. }
  380.  
  381.  
  382. if ($tnum == 0 - 1) {
  383. $tnum = 1;
  384. $returnTroops[$vid]['hasHero'] = TRUE;
  385. } else {
  386. $returnTroops[$vid]['troops'][$tid] = $tnum;
  387. }
  388.  
  389. $returnTroops[$vid] += 'cropConsumption' = $GameMetadata['troops'][$tid]['crop_consumption'] * $tnum;
  390. }
  391. }
  392. }
  393.  
  394. $m->dispose( );
  395. return $returnTroops;
  396. }
  397.  
  398. function _getTroopsList(&$key) {
  399. $GameMetadata = $GLOBALS['GameMetadata'];
  400. $m = new BuildModel( );
  401. $returnTroops = array( );
  402.  
  403. if (trim( $this->data[$key] ) != '') {
  404. $t_arr = explode( '|', $this->data[$key] );
  405. foreach ($t_arr as $t_str) {
  406. $t2_arr = explode( ':', $t_str );
  407. $vid = intval( $t2_arr[0] );
  408. $villageData = NULL;
  409.  
  410. if ($vid == 0 - 1) {
  411. $vid = $this->data['selected_village_id'];
  412. $villageData = array( 'id' => $vid, 'village_name' => $this->data['village_name'], 'player_id' => $this->player->playerId, 'player_name' => buildings_p_thisvillage );
  413. } else {
  414. $villageData = $m->getVillageData2ById( $vid );
  415. }
  416.  
  417. $returnTroops[$vid] = array( 'villageData' => $villageData, 'cropConsumption' => 0, 'hasHero' => FALSE, 'troops' => array( ) );
  418.  
  419. if ($vid == $this->data['selected_village_id']) {
  420. $returnTroops[$vid]['hasHero'] = intval( $this->data['hero_in_village_id'] ) == intval( $this->data['selected_village_id'] );
  421.  
  422. if ($returnTroops[$vid]['hasHero']) {
  423. $returnTroops[$vid] += 'cropConsumption' = $GameMetadata['troops'][$this->data['hero_troop_id']]['crop_consumption'];
  424. }
  425. }
  426.  
  427. $t2_arr = explode( ',', $t2_arr[1] );
  428. foreach ($t2_arr as $t2_str) {
  429. list( $tid, $tnum ) = explode( ' ', $t2_str );
  430.  
  431. if ($tid == 99) {
  432. continue;
  433. }
  434.  
  435.  
  436. if ($tnum == 0 - 1) {
  437. $tnum = 1;
  438. $returnTroops[$vid]['hasHero'] = TRUE;
  439. } else {
  440. $returnTroops[$vid]['troops'][$tid] = $tnum;
  441. }
  442.  
  443. $returnTroops[$vid] += 'cropConsumption' = $GameMetadata['troops'][$tid]['crop_consumption'] * $tnum;
  444. }
  445. }
  446. }
  447.  
  448. $m->dispose( );
  449. return $returnTroops;
  450. }
  451.  
  452. function handleMarketplace() {
  453. $this->selectedTabIndex = (( ( ( isset( $_GET['t'] ) && is_numeric( $_GET['t'] ) ) && 1 <= intval( $_GET['t'] ) ) && intval( $_GET['t'] ) <= 3 ) ? intval( $_GET['t'] ) : 0);
  454. $itemId = $this->buildings[$this->buildingIndex]['item_id'];
  455. $itemLevel = $this->buildings[$this->buildingIndex]['level'];
  456. $tribeMetadata = $this->gameMetadata['tribes'][$this->data['tribe_id']];
  457. $tradeOfficeLevel = $this->_getMaxBuildingLevel( 28 );
  458. $capacityFactor = ($tradeOfficeLevel == 0 ? 1 : $this->gameMetadata['items'][28]['levels'][$tradeOfficeLevel - 1]['value'] / 100);
  459. $capacityFactor *= $this->gameMetadata['game_speed'];
  460. $total_merchants_num = $this->gameMetadata['items'][$itemId]['levels'][$itemLevel - 1]['value'];
  461. $exist_num = $total_merchants_num - $this->queueModel->tasksInQueue['out_merchants_num'] - $this->data['offer_merchants_count'];
  462.  
  463. if ($exist_num < 0) {
  464. $exist_num = 0;
  465. }
  466.  
  467. $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 );
  468.  
  469. if ($this->selectedTabIndex == 0) {
  470. $m = new BuildModel( );
  471.  
  472. if (( $this->isPost( ) || isset( $_GET['vid2'] ) )) {
  473. $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) );
  474. $this->merchantProperty['confirm_snd'] = ($this->isPost( ) ? ( isset( $_POST['act'] ) && $_POST['act'] == 1 ) : isset( $_GET['vid2'] ));
  475. $map_size = $this->setupMetadata['map_size'];
  476. $doSend = FALSE;
  477.  
  478. if ($this->merchantProperty['confirm_snd']) {
  479. $vRow = NULL;
  480.  
  481. if (( ( ( isset( $_POST['x'] ) && isset( $_POST['y'] ) ) && trim( $_POST['x'] ) != '' ) && trim( $_POST['y'] ) != '' )) {
  482. $vid = $this->__getVillageId( $map_size, $this->__getCoordInRange( $map_size, intval( $_POST['x'] ) ), $this->__getCoordInRange( $map_size, intval( $_POST['y'] ) ) );
  483. $vRow = $m->getVillageDataById( $vid );
  484. } else {
  485. if (( isset( $_POST['vname'] ) && trim( $_POST['vname'] ) != '' )) {
  486. $vRow = $m->getVillageDataByName( trim( $_POST['vname'] ) );
  487. } else {
  488. if (isset( $_GET['vid2'] )) {
  489. $vRow = $m->getVillageDataById( intval( $_GET['vid2'] ) );
  490.  
  491. if ($vRow != NULL) {
  492. $_POST['x'] = $vRow['rel_x'];
  493. $_POST['y'] = $vRow['rel_y'];
  494. }
  495. }
  496. }
  497. }
  498. } else {
  499. $doSend = TRUE;
  500. $vRow = $m->getVillageDataById( intval( $_POST['vid2'] ) );
  501. $this->merchantProperty['showError'] = FALSE;
  502. $_POST['r4'] = '';
  503. $_POST['r3'] = ;
  504. $_POST['r2'] = ;
  505. $_POST['r1'] = ;
  506. }
  507.  
  508.  
  509. if (( 0 < intval( $vRow['player_id'] ) && $m->getPlayType( intval( $vRow['player_id'] ) ) == PLAYERTYPE_ADMIN )) {
  510. $this->merchantProperty['showError'] = FALSE;
  511. $this->merchantProperty['confirm_snd'] = FALSE;
  512. return null;
  513. }
  514.  
  515. $this->merchantProperty['vRow'] = $vRow;
  516. $this->merchantProperty['to_vid'] = ($vRow != NULL ? $vRow['id'] : 0);
  517. $vid = ;
  518. $rel_x = $vRow['rel_x'];
  519. $rel_y = $vRow['rel_y'];
  520. $this->merchantProperty['same_village'] = $vid == $this->data['selected_village_id'];
  521. $this->merchantProperty['available_res'] = $this->isResourcesAvailable( $resources );
  522. $this->merchantProperty['vRow_merchant_num'] = ceil( ( $resources[1] + $resources[2] + $resources[3] + $resources[4] ) / $this->merchantProperty['capacity'] );
  523. $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'] );
  524. $this->merchantProperty['showError'] = !$this->merchantProperty['confirm_snd'];
  525. $distance = WebHelper::getdistance( $this->data['rel_x'], $this->data['rel_y'], $rel_x, $rel_y, $this->setupMetadata['map_size'] / 2 );
  526. $this->merchantProperty['vRow_time'] = intval( $distance / $this->merchantProperty['speed'] * 3600 );
  527.  
  528. if (( ( ( !$this->merchantProperty['showError'] && $doSend ) && !$this->isGameTransientStopped( ) ) && !$this->isGameOver( ) )) {
  529. $this->merchantProperty['confirm_snd'] = FALSE;
  530. $this->merchantProperty -= 'exits_num' = $this->merchantProperty['vRow_merchant_num'];
  531. $newTask = new QueueTask( QS_MERCHANT_GO, $this->player->playerId, $this->merchantProperty['vRow_time'] );
  532. $newTask->villageId = $this->data['selected_village_id'];
  533. $newTask->toPlayerId = $vRow['player_id'];
  534. $newTask->toVillageId = $vid;
  535. $newTask->procParams = $this->merchantProperty['vRow_merchant_num'] . '|' . ( $resources[1] . ' ' . $resources[2] . ' ' . $resources[3] . ' ' . $resources[4] );
  536. $newTask->tag = $resources;
  537. $this->queueModel->addTask( $newTask );
  538. }
  539. }
  540.  
  541. $m->dispose( );
  542. return null;
  543. }
  544.  
  545.  
  546. if ($this->selectedTabIndex == 1) {
  547. $m = new BuildModel( );
  548. $showOfferList = TRUE;
  549.  
  550. if (( isset( $_GET['oid'] ) && 0 < intval( $_GET['oid'] ) )) {
  551. $oRow = $m->getOffer2( intval( $_GET['oid'] ), $this->data['rel_x'], $this->data['rel_y'], $this->setupMetadata['map_size'] / 2 );
  552.  
  553. if ($oRow != NULL) {
  554. $aid = 0;
  555.  
  556. if ($oRow['alliance_only']) {
  557. if (0 < intval( $this->data['alliance_id'] )) {
  558. $aid = $m->getPlayerAllianceId( $oRow['player_id'] );
  559. }
  560. }
  561.  
  562. list( $res1, $res2 ) = explode( '|', $oRow['offer'] );
  563. $resArr1 = explode( ' ', $res1 );
  564. $needResources = array( '1' => $resArr1[0], '2' => $resArr1[1], '3' => $resArr1[2], '4' => $resArr1[3] );
  565. $res1_item_id = 0;
  566. $res1_value = 0;
  567. $i = 0;
  568. $_c = sizeof( $resArr1 );
  569.  
  570. while ($i < $_c) {
  571. if (0 < $resArr1[$i]) {
  572. $res1_item_id = $i + 1;
  573. $res1_value = $resArr1[$i];
  574. break;
  575. }
  576.  
  577. ++$i;
  578. }
  579.  
  580. $resArr1 = explode( ' ', $res2 );
  581. $giveResources = array( '1' => $resArr1[0], '2' => $resArr1[1], '3' => $resArr1[2], '4' => $resArr1[3] );
  582. $res2_item_id = 0;
  583. $res2_value = 0;
  584. $i = 0;
  585. $_c = sizeof( $resArr1 );
  586.  
  587. while ($i < $_c) {
  588. if (0 < $resArr1[$i]) {
  589. $res2_item_id = $i + 1;
  590. $res2_value = $resArr1[$i];
  591. break;
  592. }
  593.  
  594. ++$i;
  595. }
  596.  
  597. $distance = $oRow['timeInSeconds'] / 3600 * $oRow['merchants_speed'];
  598. $acceptResult = $this->_canAcceptOffer( $needResources, $giveResources, $oRow['village_id'], $oRow['alliance_only'], $aid, $oRow['max_time'], $distance );
  599.  
  600. if (( ( $acceptResult == 5 && !$this->isGameTransientStopped( ) ) && !$this->isGameOver( ) )) {
  601. $showOfferList = FALSE;
  602. $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 );
  603. $merchantNum = ceil( ( $giveResources[1] + $giveResources[2] + $giveResources[3] + $giveResources[4] ) / $this->merchantProperty['capacity'] );
  604. $newTask = new QueueTask( QS_MERCHANT_GO, $this->player->playerId, $distance / ( $this->gameMetadata['tribes'][$this->data['tribe_id']]['merchants_velocity'] * $this->gameMetadata['game_speed'] ) * 3600 );
  605. $newTask->villageId = $this->data['selected_village_id'];
  606. $newTask->toPlayerId = $oRow['player_id'];
  607. $newTask->toVillageId = $oRow['village_id'];
  608. $newTask->procParams = $merchantNum . '|' . ( $giveResources[1] . ' ' . $giveResources[2] . ' ' . $giveResources[3] . ' ' . $giveResources[4] );
  609. $newTask->tag = $giveResources;
  610. $this->queueModel->addTask( $newTask );
  611. $newTask = new QueueTask( QS_MERCHANT_GO, $oRow['player_id'], $oRow['timeInSeconds'] );
  612. $newTask->villageId = $oRow['village_id'];
  613. $newTask->toPlayerId = $this->player->playerId;
  614. $newTask->toVillageId = $this->data['selected_village_id'];
  615. $newTask->procParams = $oRow['merchants_num'] . '|' . ( $needResources[1] . ' ' . $needResources[2] . ' ' . $needResources[3] . ' ' . $needResources[4] );
  616. $newTask->tag = array( '1' => 0, '2' => 0, '3' => 0, '4' => 0 );
  617. $this->queueModel->addTask( $newTask );
  618. $m->removeMerchantOffer( intval( $_GET['oid'] ), $oRow['player_id'], $oRow['village_id'] );
  619. }
  620. }
  621. }
  622.  
  623. $this->merchantProperty['showOfferList'] = $showOfferList;
  624.  
  625. if ($showOfferList) {
  626. $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'] );
  627. $this->pageCount = (0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1);
  628. $this->pageIndex = (( ( isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) ) && intval( $_GET['p'] ) < $this->pageCount ) ? intval( $_GET['p'] ) : 0);
  629. $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 );
  630. }
  631.  
  632. $m->dispose( );
  633. return null;
  634. }
  635. .................................
  636. ......................
  637. .............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement