using System; using System.Linq; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Threading; using InfServer.Logic; using InfServer.Game; using InfServer.Scripting; using InfServer.Bots; using InfServer.Protocol; using Assets; namespace InfServer.Script.GameType_TDM { // Script Class /// Provides the interface between the script and arena /////////////////////////////////////////////////////// class Script_TDM : Scripts.IScript { /////////////////////////////////////////////////// // Member Variables /////////////////////////////////////////////////// private Arena _arena; //Pointer to our arena class private CfgInfo _config; //The zone config private Team _victoryTeam; //The team currently winning! private int _lastGameCheck; //The tick at which we last checked for game viability private int _tickGameStarting; //The tick at which the game began starting (0 == not initiated) private int _tickGameStart; //The tick at which the game started (0 == stopped) //Settings private int _minPlayers; //The minimum amount of players /////////////////////////////////////////////////// // Member Functions /////////////////////////////////////////////////// /// /// Performs script initialization /// public bool init(IEventObject invoker) { //Populate our variables _arena = invoker as Arena; _config = _arena._server._zoneConfig; _minPlayers = 2; return true; } /// /// Allows the script to maintain itself /// public bool poll() { //Should we check game state yet? int now = Environment.TickCount; if (now - _lastGameCheck <= Arena.gameCheckInterval) return true; _lastGameCheck = now; //Do we have enough players ingame? int playing = _arena.PlayerCount; if ((_tickGameStart == 0 || _tickGameStarting == 0) && playing < _minPlayers) { //Stop the game! _arena.setTicker(1, 1, 0, "Not Enough Players"); _arena.gameReset(); } //Do we have enough players to start a game? else if (_tickGameStart == 0 && _tickGameStarting == 0 && playing >= _minPlayers) { //Great! Get going _tickGameStarting = now; _arena.setTicker(1, 1, _config.deathMatch.startDelay * 100, "Next game: ", delegate() { //Trigger the game start _arena.gameStart(); } ); } return true; } #region Events /// /// Called when a player enters the game /// [Scripts.Event("Player.Enter")] public void playerEnter(Player player) { } /// /// Called when a player leaves the game /// [Scripts.Event("Player.Leave")] public void playerLeave(Player player) { } /// /// Called when the game begins /// [Scripts.Event("Game.Start")] public bool gameStart() { //We've started! _tickGameStart = Environment.TickCount; _tickGameStarting = 0; //Let everyone know _arena.sendArenaMessage("Game has started!", _config.flag.resetBong); _arena.setTicker(1, 1, _config.deathMatch.timer * 100, "Time Left: ", delegate() { //Trigger game end. _arena.gameEnd(); } ); return true; } /// /// Called when the game ends /// [Scripts.Event("Game.End")] public bool gameEnd() { //Game finished, perhaps start a new one _arena.sendArenaMessage("Game Over"); foreach (Team t in _arena.ActiveTeams) { _arena.sendArenaMessage(String.Format("!{0} - (K={1} D={2})", t._name, t._calculatedKills, t._calculatedDeaths)); } _tickGameStart = 0; _tickGameStarting = 0; _victoryTeam = null; return true; } /// /// Called when the statistical breakdown is displayed /// [Scripts.Event("Game.Breakdown")] public bool breakdown() { //Allows additional "custom" breakdown information //Always return true; return true; } /// /// Called to reset the game state /// [Scripts.Event("Game.Reset")] public bool gameReset() { //Game reset, perhaps start a new one _tickGameStart = 0; _tickGameStarting = 0; _victoryTeam = null; return true; } /// /// Handles the spawn of a player /// [Scripts.Event("Player.Spawn")] public bool playerSpawn(Player player, bool bDeath) { return true; } /// /// Triggered when a player wants to unspec and join the game /// [Scripts.Event("Player.JoinGame")] public bool playerJoinGame(Player player) { return true; } /// /// Triggered when a player wants to spec and leave the game /// [Scripts.Event("Player.LeaveGame")] public bool playerLeaveGame(Player player) { return true; } /// /// Triggered when a player has died, by any means /// /// killer may be null if it wasn't a player kill [Scripts.Event("Player.Death")] public bool playerDeath(Player victim, Player killer, Helpers.KillType killType, CS_VehicleDeath update) { return true; } /// /// Triggered when one player has killed another /// [Scripts.Event("Player.PlayerKill")] public bool playerPlayerKill(Player victim, Player killer) { victim._team._calculatedDeaths++; killer._team._calculatedKills++; return true; } #endregion } }