PageRenderTime 60ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/guide.php

https://github.com/minea94/DboorZ
PHP | 908 lines | 885 code | 16 blank | 7 comment | 262 complexity | fd1228920213ca69a23f537748258099 MD5 | raw file
  1. <?php
  2. /*********************/
  3. /* */
  4. /* Version : 5.1.0 */
  5. /* Author : RM */
  6. /* Comment : 071223 */
  7. /* */
  8. /*********************/
  9. require( ".".DIRECTORY_SEPARATOR."app".DIRECTORY_SEPARATOR."boot.php" );
  10. require_once( MODEL_PATH."guide.php" );
  11. class GPage extends villagepage
  12. {
  13. public $taskNumber = 0;
  14. public $taskState = 0;
  15. public $quiz = NULL;
  16. public $clientAction = NULL;
  17. public $guideData = array( );
  18. public function GPage( )
  19. {
  20. $this->customLogoutAction = TRUE;
  21. parent::villagepage( );
  22. if ( $this->player == NULL )
  23. {
  24. exit( 0 );
  25. }
  26. $this->layoutViewFile = NULL;
  27. $this->viewFile = "guide.phtml";
  28. $this->checkForGlobalMessage = FALSE;
  29. }
  30. public function load( )
  31. {
  32. parent::load( );
  33. $this->quiz = trim( $this->data['guide_quiz'] );
  34. if ( $this->quiz == GUIDE_QUIZ_COMPLETED )
  35. {
  36. exit( 0 );
  37. }
  38. else
  39. {
  40. $m = new GuideModel( );
  41. $this->taskState = 0;
  42. if ( $this->quiz == GUIDE_QUIZ_NOTSTARTED || $this->quiz == GUIDE_QUIZ_SUSPENDED )
  43. {
  44. $this->clientAction = 0 - 1;
  45. if ( isset( $_GET['v'] ) && $_GET['v'] == "f" )
  46. {
  47. if ( $this->quiz == GUIDE_QUIZ_NOTSTARTED )
  48. {
  49. $m->setGuideTask( $this->player->playerId, GUIDE_QUIZ_SUSPENDED );
  50. }
  51. $m->dispose( );
  52. exit( 0 );
  53. }
  54. else
  55. {
  56. if ( isset( $_GET['v'] ) && $_GET['v'] == "n" )
  57. {
  58. $this->quiz = "1,200";
  59. $this->clientAction = 1;
  60. $m->setGuideTask( $this->player->playerId, $this->quiz );
  61. }
  62. else
  63. {
  64. $this->taskNumber = isset( $_GET['v'] ) && $_GET['v'] == "s" ? 1 : 0;
  65. if ( $this->taskNumber == 1 )
  66. {
  67. $this->clientAction = 0;
  68. $this->quiz = "0,1";
  69. $m->setGuideTask( $this->player->playerId, $this->quiz );
  70. }
  71. }
  72. }
  73. }
  74. else
  75. {
  76. $quizArray = explode( ",", $this->quiz );
  77. $this->taskNumber = $quizArray[1];
  78. if ( $this->taskNumber == 200 && isset( $_GET['v'] ) )
  79. {
  80. if ( $_GET['v'] == "y" )
  81. {
  82. $this->taskNumber = 0;
  83. $this->clientAction = 1;
  84. $this->quiz = GUIDE_QUIZ_NOTSTARTED;
  85. $m->setGuideTask( $this->player->playerId, $this->quiz );
  86. }
  87. else if ( $_GET['v'] == "c" )
  88. {
  89. $this->quiz = "0,201,0";
  90. $quizArray = explode( ",", $this->quiz );
  91. $this->taskNumber = $quizArray[1];
  92. $m->setGuideTask( $this->player->playerId, $this->quiz );
  93. }
  94. }
  95. if ( $this->taskNumber == 201 )
  96. {
  97. $this->handleNoQuiz( $m, $quizArray[2] );
  98. }
  99. else if ( $quizArray[0] == 1 )
  100. {
  101. $this->clientAction = $quizArray[0] = 0;
  102. $m->setGuideTask( $this->player->playerId, implode( ",", $quizArray ) );
  103. $this->newReadQuiz( $this->taskNumber, $m, $quizArray );
  104. }
  105. else
  106. {
  107. $this->checkForQuiz( $this->taskNumber, $m, $quizArray );
  108. }
  109. $m->dispose( );
  110. }
  111. }
  112. }
  113. public function handleNoQuiz( $m, $quizStep )
  114. {
  115. $time = floor( 36000 / $this->gameMetadata['game_speed'] );
  116. $this->guideData['quiztime'] = WebHelper::secondstostring( $time );
  117. $result = 0;
  118. switch ( $quizStep )
  119. {
  120. case 0 :
  121. if ( isset( $_GET['v'] ) && trim( $_GET['v'] ) == "y" )
  122. {
  123. $result = 1;
  124. $newTask = new QueueTask( QS_PLUS1, $this->player->playerId, 86400 );
  125. $newTask->villageId = "";
  126. $newTask->tag = 0;
  127. $this->queueModel->addTask( $newTask );
  128. $m->increaseGoldNumber( $this->player->playerId, 15 );
  129. $newTask = new QueueTask( QS_GUIDENOQUIZ, $this->player->playerId, $time );
  130. $this->queueModel->addTask( $newTask );
  131. }
  132. break;
  133. case 1 :
  134. case 2 :
  135. case 3 :
  136. case 4 :
  137. case 5 :
  138. if ( !isset( $this->queueModel->tasksInQueue[QS_GUIDENOQUIZ] ) && isset( $_GET['v'] ) && trim( $_GET['v'] ) == "y" )
  139. {
  140. $result = 1;
  141. $m->addResourcesTo( $this->data['selected_village_id'], array( 217, 247, 177, 207 ) );
  142. $newTask = new QueueTask( QS_GUIDENOQUIZ, $this->player->playerId, $time );
  143. $this->queueModel->addTask( $newTask );
  144. }
  145. break;
  146. case 6 :
  147. if ( !isset( $this->queueModel->tasksInQueue[QS_GUIDENOQUIZ] ) && isset( $_GET['v'] ) && trim( $_GET['v'] ) == "y" )
  148. {
  149. break;
  150. }
  151. $this->clientAction = 100;
  152. $this->quiz = GUIDE_QUIZ_COMPLETED;
  153. $m->setGuideTask( $this->player->playerId, $this->quiz );
  154. $newTask = new QueueTask( QS_PLUS1, $this->player->playerId, 172800 );
  155. $newTask->villageId = "";
  156. $newTask->tag = 0;
  157. $this->queueModel->addTask( $newTask );
  158. $m->increaseGoldNumber( $this->player->playerId, 20 );
  159. }
  160. if ( $result == 1 && $quizStep < 6 )
  161. {
  162. ++$quizStep;
  163. $this->quiz = "0,201,".$quizStep;
  164. $m->setGuideTask( $this->player->playerId, $this->quiz );
  165. }
  166. $this->guideData['quizStep'] = $quizStep;
  167. $this->guideData['pended'] = isset( $this->queueModel->tasksInQueue[QS_GUIDENOQUIZ] );
  168. if ( $this->guideData['pended'] )
  169. {
  170. $this->guideData['re".__FILE__."ingSeconds'] = $this->queueModel->tasksInQueue[QS_GUIDENOQUIZ][0]['re".__FILE__."ingSeconds'];
  171. }
  172. }
  173. public function newReadQuiz( $quizNumber, $m, $quizArray )
  174. {
  175. switch ( $quizNumber )
  176. {
  177. case 6 :
  178. $this->clientAction = 2;
  179. require_once( MODEL_PATH."msg.php" );
  180. $mm = new MessageModel( );
  181. $messageId = $mm->sendMessage( 1, $this->appConfig['system']['adminName'], $this->player->playerId, $this->data['name'], guide_task_msg_subject, guide_task_msg_body );
  182. $quizArray[] = $messageId;
  183. $m->setGuideTask( $this->player->playerId, implode( ",", $quizArray ) );
  184. break;
  185. case 7 :
  186. $map_size = $this->setupMetadata['map_size'];
  187. $_x = $this->data['rel_x'];
  188. $_y = $this->data['rel_y'];
  189. $mapMatrix = implode( ",", $this->__getVillageMatrix( $map_size, $_x, $_y, 3 ) );
  190. $reader = $m->getVillagesMatrix( $mapMatrix );
  191. $availableVillages = array( );
  192. while ( $reader->next( ) )
  193. {
  194. if ( !$reader->row['is_oasis'] && 0 < intval( $reader->row['player_id'] ) && intval( $reader->row['player_id'] ) != $this->player->playerId )
  195. {
  196. $availableVillages[] = array(
  197. $reader->row['rel_x'],
  198. $reader->row['rel_y'],
  199. $reader->row['village_name']
  200. );
  201. }
  202. }
  203. if ( sizeof( $availableVillages ) == 0 )
  204. {
  205. $availableVillages[] = array(
  206. $this->data['rel_x'],
  207. $this->data['rel_y'],
  208. $this->data['village_name']
  209. );
  210. }
  211. $r_indx = mt_rand( 0, sizeof( $availableVillages ) - 1 );
  212. $this->guideData['vname'] = $availableVillages[$r_indx][2];
  213. $quizArray[] = implode( "|", $availableVillages[$r_indx] );
  214. $m->setGuideTask( $this->player->playerId, implode( ",", $quizArray ) );
  215. break;
  216. case 20 :
  217. case 21 :
  218. $this->taskState = $quizArray[sizeof( $quizArray ) - 1] == 1 ? 2 : 0;
  219. $this->guideData['troop_id'] = $this->getFirstTroopId( $this->data['tribe_id'] );
  220. $this->guideData['troop_name'] = constant( "troop_".$this->guideData['troop_id'] );
  221. }
  222. }
  223. public function checkForQuiz( $quizNumber, $m, $quizArray )
  224. {
  225. switch ( $quizNumber )
  226. {
  227. case 1 :
  228. foreach ( $this->buildings as $build )
  229. {
  230. if ( $build['item_id'] == 1 && 0 < $build['level'] )
  231. {
  232. $this->taskState = $this->clientAction = 1;
  233. $m->setGuideTask( $this->player->playerId, "1,2" );
  234. break;
  235. }
  236. }
  237. break;
  238. case 2 :
  239. foreach ( $this->buildings as $build )
  240. {
  241. if ( $build['item_id'] == 4 && 0 < $build['level'] )
  242. {
  243. $this->taskState = $this->clientAction = 1;
  244. $m->setGuideTask( $this->player->playerId, "1,3" );
  245. $newTask = new QueueTask( QS_PLUS1, $this->player->playerId, 86400 );
  246. $newTask->villageId = "";
  247. $newTask->tag = 0;
  248. $this->queueModel->addTask( $newTask );
  249. break;
  250. }
  251. }
  252. break;
  253. case 3 :
  254. if ( $this->data['village_name'] != new_village_name_prefix." ".$this->data['name'] )
  255. {
  256. $this->taskState = $this->clientAction = 1;
  257. $m->setGuideTask( $this->player->playerId, "1,4" );
  258. $m->addResourcesTo( $this->data['selected_village_id'], array( 30, 60, 30, 20 ) );
  259. }
  260. break;
  261. case 4 :
  262. do
  263. {
  264. do
  265. {
  266. do
  267. {
  268. if ( !isset( $_GET['v'] ) )
  269. {
  270. break;
  271. }
  272. else
  273. {
  274. $num = trim( $_GET['v'] );
  275. if ( !is_numeric( $num ) )
  276. {
  277. $this->taskState = 1;
  278. break;
  279. }
  280. else
  281. {
  282. $playerRank = $m->getPlayerRank( $this->player->playerId, $this->data['total_people_count'] * 10 + $this->data['villages_count'] );
  283. if ( $num == $playerRank )
  284. {
  285. $this->taskState = 4;
  286. break;
  287. }
  288. else if ( !( $num < $playerRank ) )
  289. {
  290. break;
  291. }
  292. else
  293. {
  294. }
  295. }
  296. }
  297. } while ( 0 );
  298. $this->taskState = 3;
  299. } while ( 0 );
  300. $this->clientAction = 1;
  301. $m->setGuideTask( $this->player->playerId, "1,5" );
  302. $m->addResourcesTo( $this->data['selected_village_id'], array( 40, 30, 20, 30 ) );
  303. } while ( 0 );
  304. break;
  305. case 5 :
  306. $count = 0;
  307. foreach ( $this->buildings as $build )
  308. {
  309. if ( $build['item_id'] == 2 && 0 < $build['level'] )
  310. {
  311. $count |= 1;
  312. }
  313. else if ( $build['item_id'] == 3 && 0 < $build['level'] )
  314. {
  315. $count |= 2;
  316. }
  317. }
  318. if ( 0 < ( $count & 1 ) && 0 < ( $count & 2 ) )
  319. {
  320. $this->taskState = $this->clientAction = 1;
  321. $m->setGuideTask( $this->player->playerId, "1,6" );
  322. $m->addResourcesTo( $this->data['selected_village_id'], array( 50, 60, 30, 30 ) );
  323. }
  324. break;
  325. case 6 :
  326. if ( $m->isOpenedMessage( $quizArray[2] ) )
  327. {
  328. $this->taskState = $this->clientAction = 1;
  329. $m->setGuideTask( $this->player->playerId, "1,7" );
  330. $m->increaseGoldNumber( $this->player->playerId, 20 );
  331. }
  332. break;
  333. case 7 :
  334. do
  335. {
  336. do
  337. {
  338. list( $x, $y, $vname ) = $x;//bugged
  339. $this->guideData['vname'] = $vname;
  340. if ( !isset( $_GET['v'] ) )
  341. {
  342. break;
  343. }
  344. else
  345. {
  346. $arr = explode( "|", trim( $_GET['v'] ) );
  347. if ( !( sizeof( $arr ) < 2 || $x != $arr[0] || $y != $arr[1] ) )
  348. {
  349. break;
  350. }
  351. else
  352. {
  353. $this->taskState = 1;
  354. }
  355. }
  356. return;
  357. } while ( 0 );
  358. $this->clientAction = 1;
  359. $this->taskState = 2;
  360. $m->setGuideTask( $this->player->playerId, "1,8" );
  361. $m->addResourcesTo( $this->data['selected_village_id'], array( 60, 30, 40, 90 ) );
  362. } while ( 0 );
  363. break;
  364. case 8 :
  365. do
  366. {
  367. do
  368. {
  369. if ( !( isset( $_GET['v'] ) && trim( $_GET['v'] ) == "send" ) )
  370. {
  371. break;
  372. }
  373. else
  374. {
  375. if ( !( $this->resources[4]['current_value'] < 200 ) )
  376. {
  377. break;
  378. }
  379. else
  380. {
  381. $this->taskState = 1;
  382. }
  383. }
  384. return;
  385. } while ( 0 );
  386. $this->clientAction = 1;
  387. $this->taskState = 2;
  388. $qid = $this->sendReinforcements( );
  389. $m->setGuideTask( $this->player->playerId, "1,9,".$qid );
  390. $m->addResourcesTo( $this->data['selected_village_id'], array(
  391. 0,
  392. 0,
  393. 0,
  394. 0 - 200
  395. ) );
  396. } while ( 0 );
  397. break;
  398. case 9 :
  399. $count = 0;
  400. foreach ( $this->buildings as $build )
  401. {
  402. if ( $build['item_id'] == 1 && 0 < $build['level'] )
  403. {
  404. $count |= 1;
  405. }
  406. else if ( $build['item_id'] == 2 && 0 < $build['level'] )
  407. {
  408. $count |= 2;
  409. }
  410. else if ( $build['item_id'] == 3 && 0 < $build['level'] )
  411. {
  412. $count |= 4;
  413. }
  414. else if ( $build['item_id'] == 4 && 0 < $build['level'] )
  415. {
  416. $count |= 8;
  417. }
  418. }
  419. if ( 0 < ( $count & 1 ) && 0 < ( $count & 2 ) && 0 < ( $count & 4 ) && 0 < ( $count & 8 ) )
  420. {
  421. $this->taskState = $this->clientAction = 1;
  422. $m->setGuideTask( $this->player->playerId, "1,10,".$quizArray[sizeof( $quizArray ) - 1] );
  423. $m->addResourcesTo( $this->data['selected_village_id'], array( 100, 80, 40, 40 ) );
  424. }
  425. break;
  426. case 10 :
  427. $qid = $quizArray[sizeof( $quizArray ) - 1];
  428. if ( $m->guideTroopsReached( $qid ) )
  429. {
  430. $this->taskState = $this->clientAction = 1;
  431. $m->setGuideTask( $this->player->playerId, "1,11" );
  432. $newTask = new QueueTask( QS_PLUS1, $this->player->playerId, 2 * 86400 );
  433. $newTask->villageId = "";
  434. $newTask->tag = 0;
  435. $this->queueModel->addTask( $newTask );
  436. }
  437. break;
  438. case 11 :
  439. if ( $m->isOpenedReport( $this->player->playerId ) )
  440. {
  441. $this->taskState = $this->clientAction = 1;
  442. $m->setGuideTask( $this->player->playerId, "1,12" );
  443. $m->addResourcesTo( $this->data['selected_village_id'], array( 75, 140, 40, 230 ) );
  444. }
  445. break;
  446. case 12 :
  447. $result = 1;
  448. foreach ( $this->buildings as $build )
  449. {
  450. if ( !( $build['item_id'] == 1 && $build['level'] < 1 || $build['item_id'] == 2 && $build['level'] < 1 || $build['item_id'] == 3 && $build['level'] < 1 || $build['item_id'] == 4 && $build['level'] < 1 ) )
  451. {
  452. continue;
  453. }
  454. $result = 0;
  455. break;
  456. break;
  457. }
  458. if ( $result == 1 )
  459. {
  460. $this->taskState = $this->clientAction = 1;
  461. $m->setGuideTask( $this->player->playerId, "1,13" );
  462. $m->addResourcesTo( $this->data['selected_village_id'], array( 75, 80, 30, 50 ) );
  463. }
  464. break;
  465. case 13 :
  466. if ( 0 < preg_match( "/\\[#0\\]/", $this->data['description1'] ) || 0 < preg_match( "/\\[#0\\]/", $this->data['description2'] ) )
  467. {
  468. $this->taskState = $this->clientAction = 1;
  469. $m->setGuideTask( $this->player->playerId, "1,14" );
  470. $m->addResourcesTo( $this->data['selected_village_id'], array( 120, 200, 140, 100 ) );
  471. }
  472. break;
  473. case 14 :
  474. $result = 0;
  475. foreach ( $this->buildings as $build )
  476. {
  477. if ( $build['item_id'] == 23 && 0 < $build['level'] )
  478. {
  479. $result = 1;
  480. break;
  481. }
  482. }
  483. if ( $result == 1 )
  484. {
  485. $this->taskState = $this->clientAction = 1;
  486. $m->setGuideTask( $this->player->playerId, "1,15" );
  487. $m->addResourcesTo( $this->data['selected_village_id'], array( 150, 180, 30, 130 ) );
  488. }
  489. break;
  490. case 15 :
  491. $count = 0;
  492. foreach ( $this->buildings as $build )
  493. {
  494. if ( $build['item_id'] == 1 && 1 < $build['level'] )
  495. {
  496. $count |= 1;
  497. }
  498. else if ( $build['item_id'] == 2 && 1 < $build['level'] )
  499. {
  500. $count |= 2;
  501. }
  502. else if ( $build['item_id'] == 3 && 1 < $build['level'] )
  503. {
  504. $count |= 4;
  505. }
  506. else if ( $build['item_id'] == 4 && 1 < $build['level'] )
  507. {
  508. $count |= 8;
  509. }
  510. }
  511. if ( 0 < ( $count & 1 ) && 0 < ( $count & 2 ) && 0 < ( $count & 4 ) && 0 < ( $count & 8 ) )
  512. {
  513. $this->taskState = $this->clientAction = 1;
  514. $m->setGuideTask( $this->player->playerId, "1,16" );
  515. $m->addResourcesTo( $this->data['selected_village_id'], array( 60, 50, 40, 30 ) );
  516. }
  517. break;
  518. case 16 :
  519. do
  520. {
  521. do
  522. {
  523. $this->guideData['wood'] = $this->gameMetadata['items'][19]['levels'][0]['resources'][1];
  524. if ( !( isset( $_GET['v'] ) && is_numeric( $_GET['v'] ) ) )
  525. {
  526. break;
  527. }
  528. else
  529. {
  530. if ( intval( $_GET['v'] ) == $this->guideData['wood'] )
  531. {
  532. $this->taskState = 3;
  533. $this->clientAction = 1;
  534. $m->setGuideTask( $this->player->playerId, "1,17" );
  535. $m->addResourcesTo( $this->data['selected_village_id'], array( 50, 30, 60, 20 ) );
  536. break;
  537. }
  538. else if ( !( $this->guideData['wood'] < intval( $_GET['v'] ) ) )
  539. {
  540. break;
  541. }
  542. else
  543. {
  544. $this->taskState = 1;
  545. }
  546. }
  547. break;
  548. } while ( 0 );
  549. $this->taskState = 2;
  550. } while ( 0 );
  551. break;
  552. case 17 :
  553. $result = 0;
  554. foreach ( $this->buildings as $build )
  555. {
  556. if ( $build['item_id'] == 15 && 2 < $build['level'] )
  557. {
  558. $result = 1;
  559. break;
  560. }
  561. }
  562. if ( $result == 1 )
  563. {
  564. $this->taskState = $this->clientAction = 1;
  565. $m->setGuideTask( $this->player->playerId, "1,18" );
  566. $m->addResourcesTo( $this->data['selected_village_id'], array( 75, 75, 40, 40 ) );
  567. }
  568. break;
  569. case 18 :
  570. do
  571. {
  572. do
  573. {
  574. if ( !isset( $_GET['v'] ) )
  575. {
  576. break;
  577. }
  578. else
  579. {
  580. $num = trim( $_GET['v'] );
  581. if ( !is_numeric( $num ) )
  582. {
  583. $this->taskState = 1;
  584. break;
  585. }
  586. else
  587. {
  588. $playerRank = $m->getPlayerRank( $this->player->playerId, $this->data['total_people_count'] * 10 + $this->data['villages_count'] );
  589. if ( $num == $playerRank )
  590. {
  591. $this->taskState = 4;
  592. $this->clientAction = 1;
  593. $m->setGuideTask( $this->player->playerId, "1,19" );
  594. $m->addResourcesTo( $this->data['selected_village_id'], array( 100, 90, 100, 60 ) );
  595. break;
  596. }
  597. else if ( !( $num < $playerRank ) )
  598. {
  599. break;
  600. }
  601. else
  602. {
  603. }
  604. }
  605. }
  606. } while ( 0 );
  607. $this->taskState = 3;
  608. } while ( 0 );
  609. break;
  610. case 19 :
  611. do
  612. {
  613. if ( sizeof( $quizArray ) == 2 )
  614. {
  615. if ( !isset( $_GET['v'] ) )
  616. {
  617. break;
  618. }
  619. $num = trim( $_GET['v'] );
  620. if ( !is_numeric( $num ) )
  621. {
  622. break;
  623. }
  624. $this->taskState = intval( $num ) == 1 ? 2 : 1;
  625. $m->setGuideTask( $this->player->playerId, "0,19,".$this->taskState );
  626. break;
  627. }
  628. else
  629. {
  630. $this->taskState = $quizArray[sizeof( $quizArray ) - 1];
  631. $result = 0;
  632. if ( $this->taskState == 1 )
  633. {
  634. foreach ( $this->buildings as $build )
  635. {
  636. if ( $build['item_id'] == 16 && 0 < $build['level'] )
  637. {
  638. $result = 1;
  639. break;
  640. }
  641. }
  642. }
  643. else if ( $this->taskState == 2 )
  644. {
  645. $result = 0;
  646. foreach ( $this->buildings as $build )
  647. {
  648. if ( $build['item_id'] == 11 && 0 < $build['level'] )
  649. {
  650. $result = 1;
  651. break;
  652. }
  653. }
  654. }
  655. if ( !( $result == 1 ) )
  656. {
  657. break;
  658. }
  659. $m->setGuideTask( $this->player->playerId, "1,20,".$this->taskState );
  660. }
  661. $this->taskState = $this->taskState == 1 ? 3 : 4;
  662. $this->clientAction = 1;
  663. $m->addResourcesTo( $this->data['selected_village_id'], array( 80, 90, 60, 40 ) );
  664. } while ( 0 );
  665. break;
  666. case 20 :
  667. do
  668. {
  669. $this->taskState = $quizArray[sizeof( $quizArray ) - 1] == 1 ? 2 : 0;
  670. $result = 0;
  671. if ( $this->taskState == 2 )
  672. {
  673. foreach ( $this->buildings as $build )
  674. {
  675. if ( $build['item_id'] == 19 && 0 < $build['level'] )
  676. {
  677. $result = 1;
  678. $m->addResourcesTo( $this->data['selected_village_id'], array( 70, 100, 90, 100 ) );
  679. break;
  680. }
  681. }
  682. }
  683. else if ( $this->taskState == 0 )
  684. {
  685. foreach ( $this->buildings as $build )
  686. {
  687. if ( $build['item_id'] == 10 && 0 < $build['level'] )
  688. {
  689. $result = 1;
  690. $m->addResourcesTo( $this->data['selected_village_id'], array( 70, 120, 90, 50 ) );
  691. break;
  692. }
  693. }
  694. }
  695. if ( !( $result == 1 ) )
  696. {
  697. break;
  698. }
  699. else
  700. {
  701. $m->setGuideTask( $this->player->playerId, "1,21,".( $this->taskState == 0 ? 2 : 1 ) );
  702. }
  703. $this->taskState = $this->taskState == 0 ? 1 : 3;
  704. $this->clientAction = 1;
  705. } while ( 0 );
  706. break;
  707. case 21 :
  708. do
  709. {
  710. $this->taskState = $quizArray[sizeof( $quizArray ) - 1] == 1 ? 2 : 0;
  711. $this->guideData['troop_id'] = $this->getFirstTroopId( $this->data['tribe_id'] );
  712. $this->guideData['troop_name'] = constant( "troop_".$this->guideData['troop_id'] );
  713. $result = 0;
  714. if ( $this->taskState == 2 )
  715. {
  716. $troops = $this->_getOnlyMyTroops( );
  717. if ( 2 <= $troops[$this->guideData['troop_id']] )
  718. {
  719. $result = 1;
  720. $m->addResourcesTo( $this->data['selected_village_id'], array( 300, 320, 360, 570 ) );
  721. }
  722. }
  723. else if ( $this->taskState == 0 )
  724. {
  725. foreach ( $this->buildings as $build )
  726. {
  727. if ( $build['item_id'] == 17 && 0 < $build['level'] )
  728. {
  729. $result = 1;
  730. $m->addResourcesTo( $this->data['selected_village_id'], array( 200, 200, 700, 450 ) );
  731. break;
  732. }
  733. }
  734. }
  735. if ( !( $result == 1 ) )
  736. {
  737. break;
  738. }
  739. else
  740. {
  741. $m->setGuideTask( $this->player->playerId, "1,22" );
  742. }
  743. $this->taskState = $this->taskState == 0 ? 1 : 3;
  744. $this->clientAction = 1;
  745. } while ( 0 );
  746. break;
  747. case 22 :
  748. $result = 1;
  749. foreach ( $this->buildings as $build )
  750. {
  751. if ( !( $build['item_id'] == 1 && $build['level'] < 2 || $build['item_id'] == 2 && $build['level'] < 2 || $build['item_id'] == 3 && $build['level'] < 2 || $build['item_id'] == 4 && $build['level'] < 2 ) )
  752. {
  753. continue;
  754. }
  755. $result = 0;
  756. break;
  757. break;
  758. }
  759. if ( $result == 1 )
  760. {
  761. $this->taskState = $this->clientAction = 1;
  762. $m->setGuideTask( $this->player->playerId, "1,23" );
  763. $m->increaseGoldNumber( $this->player->playerId, 15 );
  764. }
  765. break;
  766. case 23 :
  767. $result = 0;
  768. foreach ( $this->buildings as $build )
  769. {
  770. if ( $build['item_id'] == 18 && 0 < $build['level'] )
  771. {
  772. $result = 1;
  773. break;
  774. }
  775. }
  776. if ( $result == 1 )
  777. {
  778. $this->taskState = $this->clientAction = 1;
  779. $m->setGuideTask( $this->player->playerId, "1,24" );
  780. $m->addResourcesTo( $this->data['selected_village_id'], array( 100, 60, 90, 40 ) );
  781. }
  782. break;
  783. case 24 :
  784. if ( 0 < intval( $this->data['alliance_id'] ) )
  785. {
  786. break;
  787. }
  788. $this->taskState = 1;
  789. $this->clientAction = 100;
  790. $m->setGuideTask( $this->player->playerId, GUIDE_QUIZ_COMPLETED );
  791. $m->addResourcesTo( $this->data['selected_village_id'], array( 395, 315, 345, 230 ) );
  792. }
  793. }
  794. public function preRender( )
  795. {
  796. header( "gquiz:".$this->clientAction );
  797. }
  798. public function _getOnlyMyTroops( )
  799. {
  800. $troops = array( );
  801. $t_arr = explode( "|", $this->data['troops_num'] );
  802. foreach ( $t_arr as $t_str )
  803. {
  804. $t2_arr = explode( ":", $t_str );
  805. if ( $t2_arr[0] == 0 - 1 )
  806. {
  807. $t2_arr = explode( ",", $t2_arr[1] );
  808. foreach ( $t2_arr as $t2_str )
  809. {
  810. $t = explode( " ", $t2_str );
  811. if ( isset( $troops[$t[0]] ) )
  812. {
  813. $troops[$t[0]] += $t[1];
  814. }
  815. else
  816. {
  817. $troops[$t[0]] = $t[1];
  818. }
  819. }
  820. }
  821. }
  822. return $troops;
  823. }
  824. public function getFirstTroopId( $tribeId )
  825. {
  826. foreach ( $this->gameMetadata['troops'] as $tid => $troop )
  827. {
  828. if ( !( $troop['for_tribe_id'] == $tribeId ) )
  829. {
  830. continue;
  831. }
  832. return $tid;
  833. }
  834. return 0;
  835. }
  836. public function __getCoordInRange( $map_size, $x )
  837. {
  838. if ( $map_size <= $x )
  839. {
  840. $x -= $map_size;
  841. }
  842. else if ( $x < 0 )
  843. {
  844. $x = $map_size + $x;
  845. }
  846. return $x;
  847. }
  848. public function __getVillageId( $map_size, $x, $y )
  849. {
  850. return $x * $map_size + ( $y + 1 );
  851. }
  852. public function __getVillageMatrix( $map_size, $x, $y, $scale )
  853. {
  854. $matrix = array( );
  855. $i = 0 - $scale;
  856. while ( $i <= $scale )
  857. {
  858. $j = 0 - $scale;
  859. while ( $j <= $scale )
  860. {
  861. $nx = $this->__getCoordInRange( $map_size, $x + $i );
  862. $ny = $this->__getCoordInRange( $map_size, $y + $j );
  863. $matrix[] = $this->__getVillageId( $map_size, $nx, $ny );
  864. ++$j;
  865. }
  866. ++$i;
  867. }
  868. return $matrix;
  869. }
  870. public function sendReinforcements( )
  871. {
  872. $needed_time = floor( 18000 / $this->gameMetadata['game_speed'] );
  873. $troopsStr = "31 1,32 0,33 0,34 0,35 0,36 0,37 0,38 0,39 0,40 0";
  874. $catapultTargets = $carryResources = "";
  875. $spyAction = 0;
  876. $procParams = $troopsStr."|0|".$spyAction."|".$catapultTargets."|".$carryResources."|||0";
  877. $newTask = new QueueTask( QS_WAR_REINFORCE, 0, $needed_time );
  878. $newTask->villageId = 0;
  879. $newTask->toPlayerId = $this->player->playerId;
  880. $newTask->toVillageId = $this->data['selected_village_id'];
  881. $newTask->procParams = $procParams;
  882. $newTask->tag = array(
  883. "troops" => NULL,
  884. "hasHero" => FALSE,
  885. "resources" => NULL
  886. );
  887. return $this->queueModel->addTask( $newTask );
  888. }
  889. }
  890. $p = new GPage( );
  891. $p->run( );
  892. ?>