Advertisement
vertrex

Battle Mania - main.php

Feb 28th, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.61 KB | None | 0 0
  1. <?php
  2. ###################################################################
  3. ######                     Battle Mania                      ######
  4. ###################################################################
  5. ######  Script by: LOVER$BOY                                 ######
  6. ######  Description: Please leave this header. Thanks!       ######
  7. ######  Contact: zodiacsohma1@gmail.com                      ######
  8. ###################################################################
  9.  
  10. //!<  Reads the STDIN (input) from feed provided by the stream
  11. function ReadStdin()
  12. {
  13.     //  Normally use rtrim but trim is better for this.
  14.     //  Extended read line length from 1024 to 2048 for long lines.
  15.     Base::$base->line = trim(fgets(STDIN, 2048));
  16. }
  17.  
  18. //!< Put the pieces together
  19. function BridgePieces($start, $break = " ", $finish = -1)
  20. {
  21.     $str = "";
  22.  
  23.     if ($finish == -1)
  24.         $finish = count(Base::$base->pieces);
  25.  
  26.     for($i = $start; $i < $finish; $i++)
  27.     {
  28.         if (($i + 1) == count(Base::$base->pieces))
  29.             $str .= Base::$base->pieces[$i];
  30.         else
  31.             $str .= Base::$base->pieces[$i].$break;
  32.     }
  33.  
  34.     return $str;
  35. }
  36.  
  37. //!< MAIN ENGINE >!\\
  38. function main()
  39. {
  40.     //  parse lines read
  41.     if (Filter(Base::$base->line) !== "")
  42.     {
  43.         //  split and store strings by the break character (" ")
  44.         Base::$base->pieces = explode(" ", Base::$base->line);
  45.  
  46.         try
  47.         {
  48.             //<! When a player has entered the server; grid/spectator
  49.             if (startswith(Base::$base->line, "PLAYER_ENTERED"))
  50.             {
  51.                 PlayerEntered();
  52.             }
  53.             //!< When a AI has entered the server
  54.             elseif (startswith(Base::$base->line, "PLAYER_AI_ENTERED"))
  55.             {
  56.                 PlayerAIEntered();
  57.             }
  58.             //!< When a player has been renamed
  59.             elseif (startswith(Base::$base->line, "PLAYER_RENAMED"))
  60.             {
  61.                 PlayerRenamed();
  62.             }
  63.             //!< Setting the colored display name of the player
  64.             elseif (startswith(Base::$base->line, "PLAYER_COLORED_NAME"))
  65.             {
  66.                 PlayerColoredName();
  67.             }
  68.             //!< Online players stats
  69.             elseif (startswith(Base::$base->line, "ONLINE_PLAYERS"))
  70.             {
  71.                 OnlineSyncDetails();
  72.             }
  73.             //!< The data of the online player
  74.             elseif (startswith(Base::$base->line, "ONLINE_PLAYER"))
  75.             {
  76.                 OnlinePlayer();
  77.             }
  78.             //!< When a AI or player leave the server
  79.             elseif ((startswith(Base::$base->line, "PLAYER_LEFT")) || (startswith(Base::$base->line, "PLAYER_AI_LEFT")))
  80.             {
  81.                 PlayerLeft();
  82.             }
  83.             //!< When a team is created
  84.             elseif (startswith(Base::$base->line, "TEAM_CREATED"))
  85.             {
  86.                 TeamCreated();
  87.             }
  88.             //!< When a team is renamed
  89.             elseif (startswith(Base::$base->line, "TEAM_RENAMED"))
  90.             {
  91.                 TeamRenamed();
  92.             }
  93.             //!< When players leave the team and it gets destroyed
  94.             elseif (startswith(Base::$base->line, "TEAM_DESTROYED"))
  95.             {
  96.                 TeamDestroyed();
  97.             }
  98.             //!< When a player is added to a certain team
  99.             elseif (startswith(Base::$base->line, "TEAM_PLAYER_ADDED"))
  100.             {
  101.                 TeamAddedPlayer();
  102.             }
  103.             //!< The currntly played map and the size factor for it
  104.             elseif (startswith(Base::$base->line, "CURRENT_MAP"))
  105.             {
  106.                 CurrentMap();
  107.             }
  108.             //!< When player (s) have died
  109.             elseif (startswith(Base::$base->line, "DEATH_"))
  110.             {
  111.                 deaths();
  112.             }
  113.             //!< When a cycle is created on the grid
  114.             elseif (startswith(Base::$base->line, "CYCLE_CREATED"))
  115.             {
  116.                 CycleCreated();
  117.             }
  118.             //!< When a cycle is destroyed on the grid
  119.             elseif (startswith(Base::$base->line, "CYCLE_DESTROYED"))
  120.             {
  121.                 CycleDestroyed();
  122.             }
  123.             //!< The gridpos of the player and their cycle
  124.             elseif (startswith(Base::$base->line, "PLAYER_GRIDPOS"))
  125.             {
  126.                 //  No need to process the positions of players during zombie challenge.
  127.                 //  This will save time and process energy for the spawned zombie zones.
  128.                 if (Base::$base->game_mode == 1) return;
  129.  
  130.                 $player = getPlayerByLog(Base::$base->pieces[1]);
  131.                 if (isset($player) && !is_null($player) && $player instanceof Player)
  132.                 {
  133.                     $cycle = $player->cycle;
  134.                     if (isset($cycle) && !is_null($cycle) && $cycle instanceof Cycle)
  135.                     {
  136.                         $pos = new Coord(Base::$base->pieces[2] / Base::$base->ARENA->sizeMultiplier, Base::$base->pieces[3] / Base::$base->ARENA->sizeMultiplier);
  137.                         $dir = new Coord(Base::$base->pieces[4], Base::$base->pieces[5]);
  138.  
  139.                         player_gridpos($cycle, $pos, $dir, Base::$base->pieces[6], Base::$base->pieces[7], Base::$base->pieces[8]);
  140.                     }
  141.                 }
  142.             }
  143.             //!< When the round has just started
  144.             elseif (startswith(Base::$base->line, "ROUND_STARTED"))
  145.             {
  146.                 onRoundStart();
  147.             }
  148.             //!< When the round has just finished (declaring winner or no one alive)
  149.             elseif (startswith(Base::$base->line, "ROUND_FINISHED"))
  150.             {
  151.                 onRoundFinish();
  152.             }
  153.             //!< When a new round is about to commence
  154.             elseif (startswith(Base::$base->line, "ROUND_COMMENCING"))
  155.             {
  156.                 onRoundCommencing();
  157.             }
  158.             //!< When the round has just ended (clearing out all grid and data of cycles)
  159.             elseif (startswith(Base::$base->line, "ROUND_ENDED"))
  160.             {
  161.                 onRoundEnd();
  162.             }
  163.             //!< When an unknown chat command is called
  164.             elseif (startswith(Base::$base->line, "INVALID_COMMAND"))
  165.             {
  166.                 parseNormalChat();
  167.             }
  168.             //!< When an custom unknown chat command is called
  169.             elseif (startswith(Base::$base->line, "CUSTOM_INVALID_COMMAND"))
  170.             {
  171.                 parseUnknownChat();
  172.             }
  173.             //!< When the deathzone is activated
  174.             elseif (startswith(Base::$base->line, "DEATHZONE_ACTIVATED"))
  175.             {
  176.                 //  turn off respawning since it's time to close the round
  177.                 Base::$base->respawn = false;
  178.  
  179.                 con("0xffaaffDeathzone Activated, respawn is now switched off!");
  180.             }
  181.             //!< When a zone is spawned or created
  182.             elseif (startswith(Base::$base->line, "ZONE_CREATED") || startswith(Base::$base->line, "ZONE_SPAWNED"))
  183.             {
  184.                 ZoneCreated();
  185.             }
  186.             //!< When an objectzone is created
  187.             elseif (startswith(Base::$base->line, "OBJECTZONE_SPAWNED"))
  188.             {
  189.                 ObjectZoneCreated();
  190.             }
  191.             //!< When a player entered an object zone
  192.             elseif (startswith(Base::$base->line, "OBJECTZONE_PLAYER_ENTER"))
  193.             {
  194.                 ObjectZonePlayerEntered();
  195.             }
  196.             //!< When a zone entered an object zone
  197.             elseif (startswith(Base::$base->line, "OBJECTZONE_ZONE_ENTERED"))
  198.             {
  199.                 ObjectZoneZoneEntered();
  200.             }
  201.             //!< When a zone has collapsed/destroyed
  202.             elseif (startswith(Base::$base->line, "ZONE_COLLAPSED"))
  203.             {
  204.                 ZoneCollapsed();
  205.             }
  206.             //!< When a round winner (team) is declared
  207.             elseif (startswith(Base::$base->line, "ROUND_WINNER"))
  208.             {
  209.                 onRoundWinnerDeclared();
  210.             }
  211.             //!< When all players leave the server
  212.             elseif (startswith(Base::$base->line, "GAME_END"))
  213.             {
  214.                 on_game_end();
  215.             }
  216.             //!< When the server has been shutdown, do the shutdown of the script
  217.             elseif (startswith(Base::$base->line, "SHUTDOWN"))
  218.             {
  219.                 on_server_exist();
  220.             }
  221.         }
  222.         catch (ErrorException $ex)
  223.         {
  224.             errorExecute($ex);
  225.             errorLog($ex);
  226.         }
  227.     }
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement