PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/MCG76 HG v2/src/mcg76/hungergames/task/HungerGamesScoreBoardTask.php

https://gitlab.com/Skull3x/WorkingInProgress-Plugins-Sourcecode-For-Dev
PHP | 318 lines | 284 code | 7 blank | 27 comment | 76 complexity | d20dd8c2bfc0d038d7e0a3a91457b8f3 MD5 | raw file
  1. <?php
  2. namespace mcg76\hungergames\task;
  3. use mcg76\hungergames\arena\MapArenaModel;
  4. use mcg76\hungergames\main\HungerGamesPlugIn;
  5. use mcg76\hungergames\level\GameLevelModel;
  6. use mcg76\hungergames\statue\StatueBuilder;
  7. use mcg76\hungergames\statue\StatueModel;
  8. use mcg76\hungergames\utils\MagicUtil;
  9. use mcg76\hungergames\utils\TextUtil;
  10. use pocketmine\level\Level;
  11. use pocketmine\level\Position;
  12. use pocketmine\scheduler\PluginTask;
  13. use pocketmine\utils\TextFormat;
  14. use mcg76\hungergames\level\GameLevelManager;
  15. use mcg76\hungergames\main\HungerGameKit;
  16. use pocketmine\tile\Tile;
  17. use pocketmine\tile\Sign;
  18. use pocketmine\tile\Chest;
  19. use pocketmine\math\Vector3;
  20. /**
  21. * HungerGamesScoreBoardTask
  22. *
  23. * Copyright (C) 2015 minecraftgenius76
  24. * YouTube Channel: http://www.youtube.com/user/minecraftgenius76
  25. *
  26. * @author MCG76
  27. *
  28. */
  29. class HungerGamesScoreBoardTask extends PluginTask {
  30. private $plugin;
  31. public function __construct(HungerGamesPlugIn $plugin) {
  32. $this->plugin = $plugin;
  33. parent::__construct ( $plugin );
  34. }
  35. private function showHelpFloatingText() {
  36. if ((mt_rand ( 1, 12 )) > 10) {
  37. if ($this->plugin->showLobbyHelp) {
  38. MagicUtil::addFloatingText ( $this->plugin->hubLevel, $this->plugin->hubLobbyHelpText, TextFormat::BOLD . TextFormat::AQUA . $this->plugin->hubLobbyHelpTitle, $this->plugin->hubLobbyHelpPos );
  39. }
  40. }
  41. }
  42. private function showHallOfFrameWinners() {
  43. if ((mt_rand ( 1, 20 )) > 15) {
  44. $builder = new StatueBuilder ( $this->plugin );
  45. $builder->updateHallOfFrameWinners ();
  46. unset($builder);
  47. }
  48. }
  49. private function showPortalParticles(GameLevelModel $lv) {
  50. if ((mt_rand ( 1, 12 )) > 9) {
  51. $px = round ( ($lv->gatePos2->x + $lv->gatePos1->x) / 2 );
  52. $py = ($lv->gatePos2->y);
  53. $pz = round ( ($lv->gatePos2->z + $lv->gatePos1->z) / 2 ) + 1;
  54. $pos = new Position ( $px, $py, $pz );
  55. if ($lv->particles != null) {
  56. MagicUtil::addParticles ( $lv->level, $lv->particles, $pos, 100 );
  57. }
  58. }
  59. }
  60. private function moveStatues(GameLevelModel $lv) {
  61. $i = mt_rand ( 1, 16 );
  62. if ($i < 5) {
  63. foreach ( $this->plugin->statueManager->npcs as $npc ) {
  64. $i = mt_rand ( 1, 12 );
  65. if ($i === 2 || $i === 3 || $i === 5) {
  66. if ($npc->type === "npc") {
  67. StatueBuilder::moveStatue ( $npc );
  68. StatueBuilder::animateStatue ( $npc );
  69. }
  70. } elseif ($i === 2 || $i === 5 || $i === 7) {
  71. if ($npc instanceof StatueModel) {
  72. if ($npc->type === "npc") {
  73. if ($npc->particles != null) {
  74. MagicUtil::addParticles ( $lv->level, $npc->particles, new Position ( $npc->position->x, $npc->position->y + 1, $npc->position->z ), 200 );
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. private function displayGameStats(GameLevelModel $lv) {
  83. if (is_null ( $lv ) || is_null ( $lv->currentMap ) || (count ( $lv->currentMap->livePlayers ) === 0)) {
  84. $this->plugin->log ( "HungerGamesScoreBoardTask: error NULL parameters" );
  85. return;
  86. }
  87. foreach ( $lv->currentMap->livePlayers as $gamer ) {
  88. if (isset ( $lv->currentMap->playerscores [$gamer->player->getName ()] )) {
  89. $scores = $lv->currentMap->playerscores [$gamer->player->getName ()];
  90. if (! is_null ( $scores ) && ! is_null ( $lv->currentStep )) {
  91. $message = $gamer->player->isOp () ? TextFormat::RED . "OP-" : "";
  92. $message .= TextFormat::GRAY . "HG-" . $lv->type . ": " . TextFormat::GREEN . $lv->currentStep;
  93. $message .= TextFormat::GRAY . " alive: " . TextFormat::WHITE . count ( $lv->currentMap->livePlayers );
  94. $message .= TextFormat::GRAY . " | ";
  95. $message .= TextFormat::GRAY . "shots " . TextFormat::WHITE . $scores ["shots"] . " ";
  96. $message .= TextFormat::GRAY . "points " . TextFormat::WHITE . $scores ["hits"] . " ";
  97. $diff = 0;
  98. if ($lv->currentStep === GameLevelModel::STEP_HUNTING) {
  99. $diff = round ( $lv->currentMap->huntingFinishTime ) - (microtime ( true ));
  100. $message .= TextFormat::GRAY . "| " . TextFormat::AQUA . round ( $diff, 2 );
  101. } elseif ($lv->currentStep === GameLevelModel::STEP_DEATH_MATCH) {
  102. $diff = round ( $lv->currentMap->deathMatchFinishTime - (microtime ( true )) );
  103. $message .= TextFormat::GRAY . "| " . TextFormat::AQUA . round ( $diff, 2 );
  104. }
  105. for($i = 0; $i < 15; $i ++) {
  106. TextUtil::sendPopUpText ( $gamer->player, $message );
  107. }
  108. }
  109. }
  110. }
  111. }
  112. public function updateHallOfFrameSigns() {
  113. if (! empty ( $this->plugin->hubHallOfFrameSignExitPos ) && ! empty ( $this->plugin->hubLevel )) {
  114. $sign = $this->plugin->hubLevel->getTile ( $this->plugin->hubHallOfFrameSignTitlePos );
  115. if (! is_null ( $sign ) and $sign instanceof Sign) {
  116. $sign->setText ( TextFormat::DARK_GREEN . "HG", TextFormat::GOLD . "Hall Of Frame", TextFormat::RED . "[EXIT]", TextFormat::WHITE . "LOBBY" );
  117. }
  118. unset ( $sign );
  119. }
  120. if (! empty ( $this->plugin->hubHallOfFrameSignTitlePos ) && ! empty ( $this->plugin->hubLevel )) {
  121. $sign = $this->plugin->hubLevel->getTile ( $this->plugin->hubHallOfFrameSignTitlePos );
  122. if (! is_null ( $sign ) and $sign instanceof Sign) {
  123. $sign->setText ( TextFormat::DARK_GREEN . "HG", TextFormat::GOLD . "Hall Of Frame", TextFormat::RED . "", TextFormat::WHITE . "BEST OF BEST" );
  124. }
  125. unset ( $sign );
  126. }
  127. }
  128. public function updateVIPSigns() {
  129. if (! empty ( $this->plugin->vipSignPos ) and ! empty ( $this->plugin->hubLevel )) {
  130. $sign = $this->plugin->hubLevel->getTile ( new Vector3 ( $this->plugin->vipSignPos->x, $this->plugin->vipSignPos->y, $this->plugin->vipSignPos->z ) );
  131. if (! is_null ( $sign ) and $sign instanceof Sign) {
  132. $sign->setText ( TextFormat::GOLD . "-VIP members-", TextFormat::GREEN . "Enter", TextFormat::BOLD . TextFormat::WHITE . "[ " . TextFormat::RED . "VIP+ " . TextFormat::AQUA . "Lodge" . TextFormat::WHITE . " ]", TextFormat::WHITE . "---" );
  133. MagicUtil::addParticles ( $this->plugin->hubLevel, "reddust", $this->plugin->vipSignPos, 8 );
  134. }
  135. unset ( $sign );
  136. }
  137. if (! empty ( $this->plugin->vipExitSignPos ) and ! empty ( $this->plugin->vipLevel )) {
  138. $sign = $this->plugin->vipLevel->getTile ( new Vector3 ( $this->plugin->vipExitSignPos->x, $this->plugin->vipExitSignPos->y, $this->plugin->vipExitSignPos->z ) );
  139. if (! is_null ( $sign ) and $sign instanceof Sign) {
  140. $sign->setText ( TextFormat::GOLD . "---", TextFormat::RED . "EXIT", TextFormat::BOLD . TextFormat::WHITE . "[ " . TextFormat::AQUA . "HG " . TextFormat::AQUA . "Lobby" . TextFormat::WHITE . " ]", TextFormat::WHITE . "---" );
  141. MagicUtil::addParticles ( $this->plugin->hubLevel, "reddust", $this->plugin->vipSignPos, 8 );
  142. }
  143. unset ( $sign );
  144. }
  145. }
  146. /**
  147. *
  148. * @param
  149. * $ticks
  150. */
  151. public function onRun($ticks) {
  152. try {
  153. $start_time = microtime ( true );
  154. $this->showHelpFloatingText ();
  155. $this->showHallOfFrameWinners ();
  156. $this->updateVIPSigns ();
  157. foreach ( $this->plugin->getAvailableLevels () as &$lv ) {
  158. if ($lv instanceof GameLevelModel) {
  159. if ($lv->forceSignUpdate) {
  160. $this->updateLevelSigns ( $lv->level, $lv );
  161. $this->updateHallOfFrameSigns ();
  162. $lv->forceSignUpdate = false;
  163. }
  164. $this->showPortalParticles ( $lv );
  165. $this->moveStatues ( $lv );
  166. $this->updateLevelSigns ( $lv->level, $lv );
  167. if (count ( $lv->joinedPlayers ) === 0) {
  168. continue;
  169. }
  170. if ($lv->currentStep === GameLevelModel::STEP_WAITING || $lv->currentStep === GameLevelModel::STEP_INVISIBLE) {
  171. $this->displayGameStats ( $lv );
  172. }
  173. if ($lv->currentStep === GameLevelModel::STEP_HUNTING || $lv->currentStep === GameLevelModel::STEP_DEATH_MATCH) {
  174. $this->displayGameStats ( $lv );
  175. }
  176. if ($lv->currentStep === GameLevelModel::STEP_GAME_OVER) {
  177. $this->showHallOfFrameWinners ();
  178. }
  179. }
  180. }
  181. // $this->plugin->log ( "[HungerGamesScoreBoardTask->onRun took " . (microtime ( true ) - $start_time) );
  182. } catch ( \Exception $e ) {
  183. $this->plugin->printError ( $e );
  184. }
  185. }
  186. /**
  187. * Update Level Signs
  188. *
  189. * @param Level $level
  190. * @param GameLevelModel $lv
  191. * @internal param MapArenaModel $arena
  192. */
  193. private function updateLevelSigns(Level $level, GameLevelModel &$lv) {
  194. try {
  195. if (is_null ( $level )) {
  196. $this->plugin->log ( "[HG] game sign level is null " );
  197. return;
  198. }
  199. if (! empty ( $lv->signJoin )) {
  200. $sign = $level->getTile ( $lv->signJoin );
  201. if (! is_null ( $sign ) and $sign instanceof Sign) {
  202. if ($lv->type === 1) {
  203. $sign->setText ( TextFormat::AQUA . "Welcome ", TextFormat::GREEN . $lv->name, TextFormat::WHITE . "join " . count ( $lv->joinedPlayers ) . " |min " . $lv->minPlayers, TextFormat::GOLD . "[" . $lv->currentStep . "]" );
  204. }
  205. if ($lv->type === 2) {
  206. $sign->setText ( TextFormat::AQUA . "Welcome ", TextFormat::YELLOW . $lv->name, TextFormat::WHITE . "join " . count ( $lv->joinedPlayers ) . " |min " . $lv->minPlayers, TextFormat::GOLD . "[" . $lv->currentStep . "]" );
  207. }
  208. if ($lv->type === 3) {
  209. $sign->setText ( TextFormat::AQUA . "Welcome ", TextFormat::BLUE . $lv->name, TextFormat::WHITE . "join " . count ( $lv->joinedPlayers ) . " |min " . $lv->minPlayers, TextFormat::GOLD . "[" . $lv->currentStep . "]" );
  210. }
  211. if ($lv->type === 4) {
  212. $sign->setText ( TextFormat::AQUA . "Welcome ", TextFormat::RED . $lv->name, TextFormat::WHITE . "join " . count ( $lv->joinedPlayers ) . " |min " . $lv->minPlayers, TextFormat::GOLD . "[" . $lv->currentStep . "]" );
  213. }
  214. }
  215. unset ( $sign );
  216. }
  217. if (! empty ( $lv->signJoin2 )) {
  218. $sign = $level->getTile ( $lv->signJoin2 );
  219. if (! is_null ( $sign ) and $sign instanceof Sign) {
  220. if ($lv->type === 1) {
  221. $sign->setText ( TextFormat::AQUA . "Welcome ", TextFormat::GREEN . $lv->name, TextFormat::WHITE . "join " . count ( $lv->joinedPlayers ) . " |min " . $lv->minPlayers, TextFormat::GOLD . "[" . $lv->currentStep . "]" );
  222. }
  223. if ($lv->type === 2) {
  224. $sign->setText ( TextFormat::AQUA . "Welcome ", TextFormat::YELLOW . $lv->name, TextFormat::WHITE . "join " . count ( $lv->joinedPlayers ) . " |min " . $lv->minPlayers, TextFormat::GOLD . "[" . $lv->currentStep . "]" );
  225. }
  226. if ($lv->type === 3) {
  227. $sign->setText ( TextFormat::AQUA . "Welcome ", TextFormat::BLUE . $lv->name, TextFormat::WHITE . "join " . count ( $lv->joinedPlayers ) . " |min " . $lv->minPlayers, TextFormat::GOLD . "[" . $lv->currentStep . "]" );
  228. }
  229. if ($lv->type === 4) {
  230. $sign->setText ( TextFormat::AQUA . "Welcome ", TextFormat::RED . $lv->name, TextFormat::WHITE . "join " . count ( $lv->joinedPlayers ) . " |min " . $lv->minPlayers, TextFormat::GOLD . "[" . $lv->currentStep . "]" );
  231. }
  232. }
  233. unset ( $sign );
  234. }
  235. if (! empty ( $lv->signStats )) {
  236. $sign = $level->getTile ( $lv->signStats );
  237. if (! is_null ( $sign ) && $sign instanceof Sign) {
  238. try {
  239. $livePlayers = count ( $lv->joinedPlayers );
  240. $sign->setText ( TextFormat::RED . $lv->name, TextFormat::WHITE . "=" . $lv->status . "=", TextFormat::GRAY . "join " . TextFormat::GREEN . count ( $lv->joinedPlayers ) . TextFormat::GRAY . " |min." . TextFormat::BLUE . $lv->minPlayers, TextFormat::GOLD . "[" . $lv->currentStep . "]" );
  241. } catch ( \Exception $e ) {
  242. $this->plugin->printError ( $e );
  243. $sign->setText ( TextFormat::RED . $lv->name, TextFormat::WHITE . "=" . $lv->status . "=", TextFormat::GRAY . "join " . count ( $lv->joinedPlayers ), TextFormat::GOLD . "[" . $lv->currentStep . "]" );
  244. }
  245. }
  246. unset ( $sign );
  247. }
  248. if (! empty ( $lv->signExit )) {
  249. $sign = $level->getTile ( $lv->signExit );
  250. if (! is_null ( $sign ) and $sign instanceof Sign) {
  251. $sign->setText ( TextFormat::GREEN . $lv->name, " ", TextFormat::RED . "[ EXIT ]", TextFormat::WHITE . "LOBBY" );
  252. }
  253. unset ( $sign );
  254. }
  255. $this->updateArenaSigns ( $lv );
  256. } catch ( \Exception $e ) {
  257. $this->plugin->printError ( $e );
  258. }
  259. }
  260. /**
  261. *
  262. * @param GameLevelModel $lv
  263. * @param MapArenaModel $arena
  264. */
  265. private function updateArenaSigns(GameLevelModel &$lv) {
  266. try {
  267. foreach ( $this->plugin->getAvailableArenas () as &$arena ) {
  268. if ($arena instanceof MapArenaModel) {
  269. if (is_null ( $arena->exitLevel )) {
  270. return;
  271. }
  272. if (! empty ( $lv->currentStep )) {
  273. if ($lv->currentStep === GameLevelModel::STEP_WAITING || $lv->currentStep === GameLevelModel::STEP_GAME_OVER) {
  274. $arena->vote = 0;
  275. }
  276. }
  277. if (! empty ( $arena->signVote )) {
  278. if ($lv->type === GameLevelModel::LEVEL_VIP) {
  279. $sign = $lv->level->getTile ( new Vector3($arena->signVote->x,$arena->signVote->y,$arena->signVote->z));
  280. } else {
  281. $sign = $arena->exitLevel->getTile ( $arena->signVote );
  282. }
  283. if (! is_null ( $sign ) and $sign instanceof Sign) {
  284. if ($arena->published) {
  285. $sign->setText ( TextFormat::WHITE . "tap to vote", TextFormat::DARK_GREEN . "map", TextFormat::GOLD . $arena->displayName, TextFormat::WHITE . "votes: [ " . TextFormat::BOLD . TextFormat::GOLD . $arena->vote . TextFormat::WHITE . " ]" );
  286. } else {
  287. $sign->setText ( TextFormat::DARK_GRAY . "Not Available", TextFormat::DARK_GRAY . "map", TextFormat::DARK_GRAY . $arena->displayName, TextFormat::DARK_GRAY . "Not Available" );
  288. }
  289. }
  290. unset ( $sign );
  291. }
  292. if (! empty ( $arena->signJoin )) {
  293. $sign = $arena->exitLevel->getTile ( $arena->signJoin );
  294. if (! is_null ( $sign ) and $sign instanceof Sign) {
  295. if ($arena->published) {
  296. $sign->setText ( TextFormat::WHITE . "Admin Map TP", TextFormat::GOLD . $arena->displayName, TextFormat::DARK_GREEN . "Joined:" . count ( $arena->joinedPlayers ), TextFormat::WHITE . "Live: " . count ( $arena->livePlayers ) );
  297. } else {
  298. $sign->setText ( TextFormat::DARK_GRAY . "Not Available", TextFormat::DARK_GRAY . "map", TextFormat::DARK_GRAY . $arena->displayName, TextFormat::DARK_GRAY . "Not Available" );
  299. }
  300. }
  301. unset ( $sign );
  302. }
  303. }
  304. }
  305. } catch ( \Exception $e ) {
  306. $this->plugin->printError ( $e );
  307. }
  308. }
  309. public function onCancel() {
  310. }
  311. }