Code: Select all
public const int MAXTIME = 20; //max time allowed to choose a class
public enum CharType { Scout, Soldier, Pyro, Demo, Heavy, Engineer, Medic, Sniper, Spy, NONE };
public class PlayerData
{
public IPlayer player { get; private set; }
public IUser user { get; private set; }
public PlayerTeam team { get; private set; }
public CharType characterClass { get; set; }
public PlayerData (IPlayer in_player)
{
this.player = in_player;
this.team = in_player.GetTeam ();
this.user = in_player.GetUser ();
this.characterClass = CharType.NONE;
}
public void GiveWeapon ()
{
WeaponItem[] weps = { };
switch (this.characterClass)
{
case CharType.Scout:
IProfile ScoutProfile = new IProfile ();
ScoutProfile.Accesory = new IProfileClothingItem ("DogTag", "ClothingGray");
ScoutProfile.Head = new IProfileClothingItem ("Cap", "ClothingGray");
ScoutProfile.ChestOver = new IProfileClothingItem ("None", "ClothingGray");
ScoutProfile.ChestUnder = new IProfileClothingItem ("TShirt", "ClothingRed");
ScoutProfile.Hands = new IProfileClothingItem ("FingerlessGloves", "ClothingLightGray");
ScoutProfile.Legs = new IProfileClothingItem ("Pants", "ClothingGray");
ScoutProfile.Feet = new IProfileClothingItem ("ShoesBlack", "ClothingLightGray");
weps = new WeaponItem[] { WeaponItem.SAWED_OFF, WeaponItem.PISTOL, WeaponItem.BAT };
break;
case CharType.Soldier:
IProfile SoldierProfile = new IProfile ();
SoldierProfile.Accesory = new IProfileClothingItem ("Cigar", "ClothingDarkGray");
SoldierProfile.Head = new IProfileClothingItem ("Helmet2", "ClothingGray");
SoldierProfile.ChestOver = new IProfileClothingItem ("GrenadeBelt", "ClothingGray");
SoldierProfile.ChestUnder = new IProfileClothingItem ("Shirt", "ClothingRed");
SoldierProfile.Hands = new IProfileClothingItem ("None", "ClothingLightGray");
SoldierProfile.Legs = new IProfileClothingItem ("PantsBlack", "ClothingDarkGray");
SoldierProfile.Feet = new IProfileClothingItem ("BootsBlack", "ClothingDarkGray");
weps = new WeaponItem[] { WeaponItem.BAZOOKA };
break;
case CharType.Pyro:
IProfile PyroProfile = new IProfile ();
PyroProfile.Accesory = new IProfileClothingItem ("GasMask2", "ClothingDarkGray", "ClothingLightGray");
PyroProfile.Head = new IProfileClothingItem ("None", "ClothingGray");
PyroProfile.ChestOver = new IProfileClothingItem ("GrenadeBelt", "ClothingGray");
PyroProfile.ChestUnder = new IProfileClothingItem ("Shirt", "ClothingRed");
PyroProfile.Hands = new IProfileClothingItem ("Gloves", "ClothingDarkGray");
PyroProfile.Legs = new IProfileClothingItem ("Pants", "ClothingDarkRed");
PyroProfile.Feet = new IProfileClothingItem ("BootsBlack", "ClothingDarkGray");
weps = new WeaponItem[] { WeaponItem.FLAMETHROWER, WeaponItem.FLAREGUN, WeaponItem.AXE };
break;
case CharType.Demo:
IProfile DemoProfile = new IProfile ();
DemoProfile.Accesory = new IProfileClothingItem ("None", "ClothingDarkGray");
DemoProfile.Head = new IProfileClothingItem ("Beret", "ClothingGray", "ClothingGray");
DemoProfile.ChestOver = new IProfileClothingItem ("GrenadeBelt", "ClothingGray");
DemoProfile.ChestUnder = new IProfileClothingItem ("Shirt", "ClothingRed");
DemoProfile.Hands = new IProfileClothingItem ("None", "ClothingLightGray");
DemoProfile.Legs = new IProfileClothingItem ("Pants", "ClothingDarkRed");
DemoProfile.Feet = new IProfileClothingItem ("BootsBlack", "ClothingDarkGray");
weps = new WeaponItem[] { WeaponItem.GRENADE_LAUNCHER, WeaponItem.BOTTLE, WeaponItem.MINES };
break;
case CharType.Heavy:
IProfile HeavyProfile = new IProfile ();
HeavyProfile.Accesory = new IProfileClothingItem ("None", "ClothingDarkGray");
HeavyProfile.Head = new IProfileClothingItem ("None", "ClothingGray");
HeavyProfile.ChestOver = new IProfileClothingItem ("AmmoBelt", "ClothingDarkGray");
HeavyProfile.ChestUnder = new IProfileClothingItem ("TShirt", "ClothingRed");
HeavyProfile.Hands = new IProfileClothingItem ("FingerlessGloves", "ClothingDarkGray");
HeavyProfile.Legs = new IProfileClothingItem ("Pants", "ClothingGray");
HeavyProfile.Feet = new IProfileClothingItem ("BootsBlack", "ClothingDarkGray");
weps = new WeaponItem[] { WeaponItem.M60 };
break;
case CharType.Engineer:
IProfile EngineerProfile = new IProfile ();
EngineerProfile.Accesory = new IProfileClothingItem ("Goggles", "ClothingDarkGray", "ClothingLightGray");
EngineerProfile.Head = new IProfileClothingItem ("Helmet", "ClothingYellow");
EngineerProfile.ChestOver = new IProfileClothingItem ("Vest", "ClothingLightBrown", "ClothingLightGray");
EngineerProfile.ChestUnder = new IProfileClothingItem ("TShirt", "ClothingRed");
EngineerProfile.Hands = new IProfileClothingItem ("Gloves", "ClothingYellow");
EngineerProfile.Legs = new IProfileClothingItem ("Pants", "ClothingLightBrown");
EngineerProfile.Feet = new IProfileClothingItem ("Boots", "ClothingDarkBrown");
weps = new WeaponItem[] { WeaponItem.SHOTGUN, WeaponItem.PISTOL, WeaponItem.PIPE };
break;
case CharType.Medic:
IProfile MedicProfile = new IProfile ();
MedicProfile.Accesory = new IProfileClothingItem ("Glasses", "ClothingLightGray", "ClothingLightGray");
MedicProfile.Head = new IProfileClothingItem ("BucketHat", "ClothingDarkRed", "ClothingYellow");
MedicProfile.ChestOver = new IProfileClothingItem ("Coat", "ClothingLightGray", "ClothingDarkRed");
MedicProfile.ChestUnder = new IProfileClothingItem ("ShirtWithBowtie", "ClothingLightGray", "ClothingRed");
MedicProfile.Hands = new IProfileClothingItem ("Gloves", "ClothingRed");
MedicProfile.Legs = new IProfileClothingItem ("Pants", "ClothingBrown");
MedicProfile.Feet = new IProfileClothingItem ("BootsBlack", "ClothingDarkGray");
weps = new WeaponItem[] { WeaponItem.TEAPOT };
break;
case CharType.Sniper:
IProfile SniperProfile = new IProfile ();
SniperProfile.Accesory = new IProfileClothingItem ("Glasses", "ClothingOrange", "ClothingLightGray");
SniperProfile.Head = new IProfileClothingItem ("CowboyHat", "ClothingBrown", "ClothingDarkGray");
SniperProfile.ChestOver = new IProfileClothingItem ("Vest", "ClothingBrown", "ClothingLightBrown");
SniperProfile.ChestUnder = new IProfileClothingItem ("TShirt", "ClothingLightPurple");
SniperProfile.Hands = new IProfileClothingItem ("FingerlessGloves", "ClothingLightBrown");
SniperProfile.Legs = new IProfileClothingItem ("Pants", "ClothingDarkPurple");
SniperProfile.Feet = new IProfileClothingItem ("Shoes", "ClothingDarkBrown");
weps = new WeaponItem[] { WeaponItem.SNIPER, WeaponItem.MACHETE, WeaponItem.UZI };
break;
case CharType.Spy:
IProfile SpyProfile = new IProfile ();
SpyProfile.Accesory = new IProfileClothingItem ("Balaclava", "ClothingDarkRed");
SpyProfile.Head = new IProfileClothingItem ("None", "ClothingBrown");
SpyProfile.ChestOver = new IProfileClothingItem ("StripedSuitJacket", "ClothingDarkRed");
SpyProfile.ChestUnder = new IProfileClothingItem ("ShirtWithTie", "ClothingLightGray", "ClothingDarkRed");
SpyProfile.Hands = new IProfileClothingItem ("GlovesBlack", "ClothingDarkGray");
SpyProfile.Legs = new IProfileClothingItem ("StripedPants", "ClothingDarkRed");
SpyProfile.Feet = new IProfileClothingItem ("ShoesBlack", "ClothingDarkGray");
weps = new WeaponItem[] { WeaponItem.KNIFE, WeaponItem.REVOLVER };
break;
}
foreach (WeaponItem w in weps)
{
this.player.GiveWeaponItem (w);
}
}
}
public const float PI = 3.141592f;
public int time = MAXTIME;
public Dictionary<IPlayer, PlayerData> dataList = new Dictionary<IPlayer, PlayerData> ();
public List<Vector2> startingPositions = new List<Vector2> ();
public Random rnd = new Random ();
public Area mapCameraArea;
public Area mapBorderArea;
public void OnStartup ()
{
foreach (IObject obj in Game.GetObjectsByName ("SpawnPlayer"))
{
startingPositions.Add (obj.GetWorldPosition ());
}
Game.SetMapType (MapType.Custom);
InitializeMap ();
}
public void InitializeMap ()
{
float f = Game.GetCameraMaxArea ().Top;
Vector2 tempVec = new Vector2 (Game.GetCameraMaxArea ().Right + 500f, Game.GetCameraMaxArea ().Top + 500f);
InitializeCamera (tempVec);
CreateMap (tempVec);
InitializePlayers (tempVec);
}
public void InitializeCamera (Vector2 tempVec)
{
mapCameraArea = Game.GetCameraArea ();
mapBorderArea = Game.GetCameraMaxArea ();
Area tempArea = new Area (tempVec, new Vector2 (200f, 200f) + tempVec);
Game.SetCameraArea (tempArea);
Game.SetCameraArea (tempArea);
Game.SetCurrentCameraMode (CameraMode.Dynamic);
Game.SetCurrentCameraMode (CameraMode.Static);
}
public void CreateMap (Vector2 tempVec)
{
Game.CreateObject ("Concrete01A", tempVec + new Vector2 (25f, 46f)).SetSizeFactor (new Point (29, 1));
Game.CreateObject ("Concrete01A", tempVec + new Vector2 (25f, 146f)).SetSizeFactor (new Point (29, 1));
Game.CreateObject ("Concrete02B", tempVec + new Vector2 (20f, 150f)).SetSizeFactor (new Point (1, 14));
Game.CreateObject ("Concrete02C", tempVec + new Vector2 (20f, 42f));
Game.CreateObject ("Concrete02A", tempVec + new Vector2 (20f, 152f));
Game.CreateObject ("Concrete02B", tempVec + new Vector2 (252f, 150f)).SetSizeFactor (new Point (1, 14));
Game.CreateObject ("Concrete02C", tempVec + new Vector2 (252f, 42f));
Game.CreateObject ("Concrete02A", tempVec + new Vector2 (252f, 152f));
CreateButtons (tempVec);
CreateTimer (1000, 0, "TickTime", "ClassScriptClock");
}
public void CreateButtons (Vector2 tempVec)
{
int i = 0;
foreach (string name in Enum.GetNames (typeof (CharType)))
{
string str = name;
if (name != "NONE")
{
Vector2 pos = tempVec + new Vector2 (40f + i * 24f, 70f);
IObjectTrigger button = ((IObjectTrigger) Game.CreateObject ("Button00", pos));
button.SetScriptMethod ("ChooseClass");
button.CustomId = str;
IObjectText label = (IObjectText) Game.CreateObject ("Text", pos + new Vector2 (-8f, 8f), PI / 4);
label.SetText (str);
i++;
}
}
}
public void InitializePlayers (Vector2 tempVec)
{
foreach (IPlayer ply in Game.GetPlayers ())
{
ply.SetWorldPosition (tempVec + new Vector2 (100f, 100f));
dataList.Add (ply, new PlayerData (ply));
}
}
public void ChooseClass (TriggerArgs args)
{
IPlayer ply = (IPlayer) args.Sender;
PlayerData data = dataList[ply];
data.characterClass = (CharType) Enum.Parse (typeof (CharType), ((IObject) args.Caller).CustomId);
CheckStartGame ();
}
public void TickTime (TriggerArgs args)
{
time--;
Game.ShowPopupMessage ("Choose a class ! Time remaining : " + time + "s");
CheckStartGame ();
}
public void CheckStartGame ()
{
bool start = true;
foreach (PlayerData data in dataList.Values)
{
if (data.characterClass == CharType.NONE && !data.player.IsDead) start = false;
}
if (time < 0) start = true;
if (start) StartGame ();
}
public void StartGame ()
{
Game.GetSingleObjectByCustomId ("ClassScriptClock").Remove ();
Game.ShowPopupMessage ("Let the fight begins !");
CreateTimer (5000, 1, "HidePopupMessage", "");
EquipPlayers ();
SetBackCamera ();
Game.SetMapType (MapType.Versus);
}
public void EquipPlayers ()
{
//Wether or not spawns are present on the map
bool nostart = false;
if (startingPositions.Count <= 0)
{
nostart = true;
}
foreach (IPlayer ply in Game.GetPlayers ())
{
if (!ply.IsDead)
{
PlayerData data = dataList[ply];
data.GiveWeapon ();
Vector2 v;
if (nostart)
{
v = new Vector2 ();
}
else
{
// === all spawn as already been used ===
if (startingPositions.Count <= 0)
{
foreach (IObject obj in Game.GetObjectsByName ("SpawnPlayer"))
{
startingPositions.Add (obj.GetWorldPosition ());
}
}
v = startingPositions[rnd.Next (startingPositions.Count)];
}
ply.SetWorldPosition (v);
startingPositions.Remove (v);
}
}
}
public void SetBackCamera ()
{
Game.SetCameraArea (mapCameraArea);
Game.SetCameraArea (mapBorderArea);
Game.SetCurrentCameraMode (CameraMode.Dynamic);
Game.SetCurrentCameraMode (CameraMode.Static);
}
private void CreateTimer (int interval, int count, string method, string id)
{
IObjectTimerTrigger timerTrigger = (IObjectTimerTrigger) Game.CreateObject ("TimerTrigger");
timerTrigger.SetIntervalTime (interval);
timerTrigger.SetRepeatCount (count);
timerTrigger.SetScriptMethod (method);
timerTrigger.CustomId = id;
timerTrigger.Trigger ();
}
public void HidePopupMessage (TriggerArgs args)
{
Game.HidePopupMessage ();
}