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
///////////////////////////////////////////////////
/// <summary>
/// Performs script initialization
/// </summary>
public bool init(IEventObject invoker)
{ //Populate our variables
_arena = invoker as Arena;
_config = _arena._server._zoneConfig;
_minPlayers = 2;
return true;
}
/// <summary>
/// Allows the script to maintain itself
/// </summary>
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
/// <summary>
/// Called when a player enters the game
/// </summary>
[Scripts.Event("Player.Enter")]
public void playerEnter(Player player)
{
}
/// <summary>
/// Called when a player leaves the game
/// </summary>
[Scripts.Event("Player.Leave")]
public void playerLeave(Player player)
{
}
/// <summary>
/// Called when the game begins
/// </summary>
[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;
}
/// <summary>
/// Called when the game ends
/// </summary>
[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;
}
/// <summary>
/// Called when the statistical breakdown is displayed
/// </summary>
[Scripts.Event("Game.Breakdown")]
public bool breakdown()
{ //Allows additional "custom" breakdown information
//Always return true;
return true;
}
/// <summary>
/// Called to reset the game state
/// </summary>
[Scripts.Event("Game.Reset")]
public bool gameReset()
{ //Game reset, perhaps start a new one
_tickGameStart = 0;
_tickGameStarting = 0;
_victoryTeam = null;
return true;
}
/// <summary>
/// Handles the spawn of a player
/// </summary>
[Scripts.Event("Player.Spawn")]
public bool playerSpawn(Player player, bool bDeath)
{
return true;
}
/// <summary>
/// Triggered when a player wants to unspec and join the game
/// </summary>
[Scripts.Event("Player.JoinGame")]
public bool playerJoinGame(Player player)
{
return true;
}
/// <summary>
/// Triggered when a player wants to spec and leave the game
/// </summary>
[Scripts.Event("Player.LeaveGame")]
public bool playerLeaveGame(Player player)
{
return true;
}
/// <summary>
/// Triggered when a player has died, by any means
/// </summary>
/// <remarks>killer may be null if it wasn't a player kill</remarks>
[Scripts.Event("Player.Death")]
public bool playerDeath(Player victim, Player killer, Helpers.KillType killType, CS_VehicleDeath update)
{
return true;
}
/// <summary>
/// Triggered when one player has killed another
/// </summary>
[Scripts.Event("Player.PlayerKill")]
public bool playerPlayerKill(Player victim, Player killer)
{
victim._team._calculatedDeaths++;
killer._team._calculatedKills++;
return true;
}
#endregion
}
}