Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.17 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Runtime.InteropServices;
  6. using System.Threading;
  7.  
  8. using InfServer.Logic;
  9. using InfServer.Game;
  10. using InfServer.Scripting;
  11. using InfServer.Bots;
  12. using InfServer.Protocol;
  13.  
  14. using Assets;
  15.  
  16. namespace InfServer.Script.GameType_CR_Chaos
  17. {   // Script Class
  18.     /// Provides the interface between the script and arena
  19.     ///////////////////////////////////////////////////////
  20.     class Script_CR_Chaos : Scripts.IScript
  21.     {   ///////////////////////////////////////////////////
  22.         // Member Variables
  23.         ///////////////////////////////////////////////////
  24.         private Arena _arena;                   //Pointer to our arena class
  25.         private CfgInfo _config;                //The zone config
  26.  
  27.         private Team _victoryTeam;              //The team currently winning!
  28.         private int _tickGameLastTickerUpdate; 
  29.         private int _lastGameCheck;             //The tick at which we last checked for game viability
  30.         private int _tickGameStarting;          //The tick at which the game began starting (0 == not initiated)
  31.         private int _tickGameStart;             //The tick at which the game started (0 == stopped)
  32.         //Settings
  33.         private int _minPlayers;                //The minimum amount of players
  34.  
  35.  
  36.         ///////////////////////////////////////////////////
  37.         // Member Functions
  38.         ///////////////////////////////////////////////////
  39.         /// <summary>
  40.         /// Performs script initialization
  41.         /// </summary>
  42.         public bool init(IEventObject invoker)
  43.         {   //Populate our variables
  44.             _arena = invoker as Arena;
  45.             _config = _arena._server._zoneConfig;
  46.  
  47.             _minPlayers = 1;
  48.  
  49.             return true;
  50.         }
  51.  
  52.         /// <summary>
  53.         /// Allows the script to maintain itself
  54.         /// </summary>
  55.         public bool poll()
  56.         {   //Should we check game state yet?
  57.             int now = Environment.TickCount;
  58.  
  59.             if (now - _lastGameCheck <= Arena.gameCheckInterval)
  60.                 return true;
  61.             _lastGameCheck = now;
  62.  
  63.             //Do we have enough players ingame?
  64.             int playing = _arena.PlayerCount;
  65.  
  66.             if ((_tickGameStart == 0 || _tickGameStarting == 0) && playing < _minPlayers)
  67.             {   //Stop the game!
  68.                 _arena.setTicker(1, 1, 0, "");
  69.                 _arena.gameReset();
  70.             }
  71.  
  72.             //Do we have enough players to start a game?
  73.             else if (_tickGameStart == 0 && _tickGameStarting == 0 && playing >= _minPlayers)
  74.             {   //Trigger the game start
  75.                 _arena.gameStart();
  76.                    
  77.             }
  78.             return true;
  79.         }
  80.  
  81.         #region Events
  82.    
  83.  
  84.         /// <summary>
  85.         /// Called when a player enters the game
  86.         /// </summary>
  87.         [Scripts.Event("Player.Enter")]
  88.         public void playerEnter(Player player)
  89.         {
  90.         }
  91.  
  92.         /// <summary>
  93.         /// Called when a player leaves the game
  94.         /// </summary>
  95.         [Scripts.Event("Player.Leave")]
  96.         public void playerLeave(Player player)
  97.         {
  98.         }
  99.  
  100.         /// <summary>
  101.         /// Called when the game begins
  102.         /// </summary>
  103.         [Scripts.Event("Game.Start")]
  104.         public bool gameStart()
  105.         {   //We've started!
  106.             _tickGameStart = Environment.TickCount;
  107.             _tickGameStarting = 0;
  108.  
  109.             return true;
  110.         }
  111.  
  112.  
  113.         /// <summary>
  114.         /// Called when the game ends
  115.         /// </summary>
  116.         [Scripts.Event("Game.End")]
  117.         public bool gameEnd()
  118.         {   //Game finished, perhaps start a new one
  119.  
  120.             _arena.sendArenaMessage("Game Over");
  121.  
  122.             _arena.breakdown(false);
  123.  
  124.             _tickGameStart = 0;
  125.             _tickGameStarting = 0;
  126.             _victoryTeam = null;
  127.  
  128.             return true;
  129.         }
  130.  
  131.  
  132.         /// <summary>
  133.         /// Handles the spawn of a player
  134.         /// </summary>
  135.         [Scripts.Event("Player.Spawn")]
  136.         public bool playerSpawn(Player player, bool bDeath)
  137.         {
  138.             return true;
  139.         }
  140.  
  141.         /// <summary>
  142.         /// Triggered when a player wants to unspec and join the game
  143.         /// </summary>
  144.         [Scripts.Event("Player.JoinGame")]
  145.         public bool playerJoinGame(Player player)
  146.         {
  147.             return true;
  148.         }
  149.  
  150.         /// <summary>
  151.         /// Triggered when a player wants to spec and leave the game
  152.         /// </summary>
  153.         [Scripts.Event("Player.LeaveGame")]
  154.         public bool playerLeaveGame(Player player)
  155.         {
  156.             return true;
  157.         }
  158.  
  159.         #endregion
  160.     }
  161. }
Add Comment
Please, Sign In to add comment