void CheckBounty(Player p, Player pKiller) { BountyData bounty = FindBounty(p.name); if (bounty == null) { return; } Bounties.Remove(bounty); Player setter = PlayerInfo.FindExact(bounty.Origin); if (pKiller == null) { CurLevel.ChatLevel("Bounty on " + p.ColoredName + " %Sis no longer active."); if (setter != null) { setter.SetMoney(setter.money + bounty.Amount); } } else if (setter == null) { Player.Message(pKiller, "Cannot collect the bounty, as the player who set it is offline."); } else { CurLevel.ChatLevel("&c" + pKiller.DisplayName + " %Scollected the bounty of &a" + bounty.Amount + " %S" + Server.moneys + " on " + p.ColoredName + "%S."); pKiller.SetMoney(pKiller.money + bounty.Amount); } }
void DoRound() { if (!Running) { return; } List <Player> players = DoRoundCountdown(); if (players == null) { return; } RoundInProgress = true; Random random = new Random(); Player first = PickFirstZombie(random, players); CurLevel.ChatLevel(first.color + first.name + " %Sstarted the infection!"); first.Game.Infected = true; PlayerMoneyChanged(first); UpdatePlayerColor(first, InfectCol); RoundInProgress = true; int roundMins = random.Next(CurLevel.MinRoundTime, CurLevel.MaxRoundTime); string suffix = roundMins == 1 ? " %Sminute!" : " %Sminutes!"; CurLevel.ChatLevel("The round will last for &a" + roundMins + suffix); RoundEnd = DateTime.UtcNow.AddMinutes(roundMins); timer = new System.Timers.Timer(roundMins * 60 * 1000); timer.Elapsed += new ElapsedEventHandler(EndRound); timer.Enabled = true; Player[] online = PlayerInfo.Online.Items; foreach (Player p in online) { if (p.level == null || p.level != CurLevel || p.Game.Referee) { continue; } if (p != first) { Alive.Add(p); } } Infected.Clear(); Infected.Add(first); UpdateAllPlayerStatus(); DoCoreGame(random); if (!Running) { Status = ZombieGameStatus.LastRound; return; } else { HandOutRewards(); } }
void DoCollisions(Player[] aliveList, Player[] deadList, Random random) { int dist = ZombieGameProps.HitboxPrecision; foreach (Player killer in deadList) { killer.Game.Infected = true; UpdatePlayerColor(killer, InfectCol); aliveList = Alive.Items; foreach (Player alive in aliveList) { if (alive == killer) { continue; } UpdatePlayerColor(alive, alive.color); if (!MovementCheck.InRange(alive, killer, dist)) { continue; } if (killer.Game.Infected && !alive.Game.Infected && !alive.Game.Referee && !killer.Game.Referee && killer.level.name.CaselessEq(CurLevelName) && alive.level.name.CaselessEq(CurLevelName)) { InfectPlayer(alive, killer); alive.Game.LastInfecter = killer.name; if (lastPlayerToInfect == killer.name) { infectCombo++; if (infectCombo >= 2) { killer.SendMessage("You gained " + (2 + infectCombo) + " " + Server.moneys); killer.SetMoney(killer.money + (2 + infectCombo)); CurLevel.ChatLevel("&c" + killer.DisplayName + " %Sis on a rampage! " + (infectCombo + 1) + " infections in a row!"); } } else { infectCombo = 0; } lastPlayerToInfect = killer.name; killer.Game.CurrentInfected++; killer.Game.TotalInfected++; killer.Game.MaxInfected = Math.Max(killer.Game.CurrentInfected, killer.Game.MaxInfected); ShowInfectMessage(random, alive, killer); UpdatePlayerColor(alive, InfectCol); Thread.Sleep(50); } } } }
void CheckHumanPledge(Player pAlive) { if (!pAlive.Game.PledgeSurvive) { return; } pAlive.Game.PledgeSurvive = false; CurLevel.ChatLevel(pAlive.ColoredName + "%Sbroke their pledge of not being infected."); pAlive.money = Math.Max(pAlive.money - 2, 0); pAlive.OnMoneyChanged(); }
void EndRound(object sender, ElapsedEventArgs e) { if (!Running) { return; } CurLevel.ChatLevel("%4Round End:%f 5"); Thread.Sleep(1000); CurLevel.ChatLevel("%4Round End:%f 4"); Thread.Sleep(1000); CurLevel.ChatLevel("%4Round End:%f 3"); Thread.Sleep(1000); CurLevel.ChatLevel("%4Round End:%f 2"); Thread.Sleep(1000); CurLevel.ChatLevel("%4Round End:%f 1"); Thread.Sleep(1000); HandOutRewards(); }
void DoRound() { if (!Running) { return; } List <Player> players = DoRoundCountdown(); if (players == null) { return; } Random random = new Random(); RoundInProgress = true; int roundMins = random.Next(CurLevel.MinRoundTime, CurLevel.MaxRoundTime); string suffix = roundMins == 1 ? " %Sminute!" : " %Sminutes!"; CurLevel.ChatLevel("This round will last for &a" + roundMins + suffix); RoundEnd = DateTime.UtcNow.AddMinutes(roundMins); Player[] online = PlayerInfo.Online.Items; foreach (Player p in online) { if (p.level == null || p.level != CurLevel || p.Game.Referee) { continue; } Alive.Add(p); } Infected.Clear(); Player first = PickFirstZombie(random, players); CurLevel.ChatLevel("&c" + first.DisplayName + " %Sstarted the infection!"); InfectPlayer(first, null); DoCoreGame(random); if (!Running) { Status = ZombieGameStatus.LastRound; return; } EndRound(); if (RecentMaps.Count > 20) { RecentMaps.RemoveAt(0); } RecentMaps.Add(CurLevelName); }
void ChangeLevel(string next) { Player[] online = PlayerInfo.Online.Items; if (CurLevel != null) { bool saveSettings = false; foreach (Player pl in online) { saveSettings |= pl.Game.RatedMap; } if (saveSettings) { Level.SaveSettings(CurLevel); } CurLevel.ChatLevel("The next map has been chosen - " + Colors.red + next.ToLower()); CurLevel.ChatLevel("Please wait while you are transfered."); } CurLevelName = next; QueuedLevel = null; Command.all.Find("load").Use(null, next.ToLower() + " 0"); CurLevel = LevelInfo.Find(next); if (ZombieGame.SetMainLevel) { Server.mainLevel = CurLevel; } online = PlayerInfo.Online.Items; foreach (Player pl in online) { pl.Game.RatedMap = false; pl.Game.PledgeSurvive = false; if (!pl.level.name.CaselessEq(next) && pl.level.name.CaselessEq(LastLevelName)) { pl.SendMessage("Going to the next map - &a" + next); Command.all.Find("goto").Use(pl, next); } } if (LastLevelName != "") { Command.all.Find("unload").Use(null, LastLevelName); } LastLevelName = next; }
void CheckBounty(Player pAlive, Player pKiller) { BountyData bounty; if (Bounties.TryGetValue(pAlive.name, out bounty)) { Bounties.Remove(pAlive.name); } if (bounty != null) { CurLevel.ChatLevel(pKiller.ColoredName + " %Scollected the bounty of &a" + bounty.Amount + " %S" + Server.moneys + " on " + pAlive.ColoredName + "%S."); bounty.Origin.money = Math.Max(0, bounty.Origin.money - bounty.Amount); bounty.Origin.OnMoneyChanged(); pKiller.money += bounty.Amount; pKiller.OnMoneyChanged(); } }
void ShowInfectMessage(Random random, Player pAlive, Player pKiller) { string text = null; List <string> infectMsgs = pKiller.Game.InfectMessages; if (infectMsgs != null && infectMsgs.Count > 0 && random.Next(0, 10) < 5) { text = infectMsgs[random.Next(infectMsgs.Count)]; } else { text = infectMessages[random.Next(infectMessages.Count)]; } CurLevel.ChatLevel(String.Format(text, "&c" + pKiller.DisplayName + "%S", pAlive.ColoredName + "%S")); }
void ShowInfectMessage(Random random, Player pAlive, Player pKiller) { string text = null; List <string> infectMsgs = pKiller.Game.InfectMessages; if (infectMsgs != null && random.Next(0, 10) < 5) { text = infectMsgs[random.Next(infectMsgs.Count)]; } else { text = messages[random.Next(messages.Length)]; } CurLevel.ChatLevel(String.Format(text, Colors.red + pKiller.DisplayName + Colors.yellow, Colors.red + pAlive.DisplayName + Colors.yellow)); }
void CheckHumanPledge(Player p, Player killer) { if (!p.Game.PledgeSurvive) { return; } p.Game.PledgeSurvive = false; CurLevel.ChatLevel("&c" + p.DisplayName + " %Sbroke their pledge of not being infected."); if (killer == null) { Player.Message(p, "As this was an automatic infection, you have not lost any &3" + Server.moneys); } else { p.SetMoney(Math.Max(p.money - 2, 0)); } }
void RemoveBounties(Player p) { BountyData[] bounties = Bounties.Items; foreach (BountyData b in bounties) { if (!(b.Origin.CaselessEq(p.name) || b.Target.CaselessEq(p.name))) { continue; } string target = PlayerInfo.GetColoredName(p, b.Target); CurLevel.ChatLevel("Bounty on " + target + " %Sis no longer active."); Bounties.Remove(b); Player setter = PlayerInfo.FindExact(b.Origin); if (setter != null) { setter.SetMoney(setter.money + b.Amount); } } }
internal void ChangeLevel(string next) { Player[] online = PlayerInfo.Online.Items; if (CurLevel != null) { Level.SaveSettings(CurLevel); CurLevel.ChatLevel("The next map has been chosen - " + Colors.red + next.ToLower()); CurLevel.ChatLevel("Please wait while you are transfered."); } string lastLevel = CurLevelName; CurLevelName = next; QueuedLevel = null; CmdLoad.LoadLevel(null, next); CurLevel = LevelInfo.Find(next); if (ZombieGameProps.SetMainLevel) { Server.mainLevel = CurLevel; } online = PlayerInfo.Online.Items; List <Player> players = new List <Player>(online.Length); foreach (Player pl in online) { pl.Game.RatedMap = false; pl.Game.PledgeSurvive = false; if (!pl.level.name.CaselessEq(next) && pl.level.name.CaselessEq(lastLevel)) { players.Add(pl); } } JoinInRandomOrder(players, next); if (LastLevelName != "") { Command.all.Find("unload").Use(null, LastLevelName); } LastLevelName = next; }
/// <summary> If there are no infected players left, randomly selected one of the alive players to continue the infection. </summary> public void AssignFirstZombie() { if (!Running || !RoundInProgress || Infected.Count > 0) { return; } Random random = new Random(); Player[] alive = Alive.Items; if (alive.Length == 0) { return; } int index = random.Next(alive.Length); while (alive[index].Game.Referee || !alive[index].level.name.CaselessEq(CurLevelName)) { if (index >= alive.Length - 1) { index = 0; alive = Alive.Items; if (alive.Length == 0) { return; } } else { index++; } } Player zombie = alive[index]; CurLevel.ChatLevel("&c" + zombie.DisplayName + " %Scontinued the infection!"); InfectPlayer(zombie, null); }
public void HandOutRewards() { if (!RoundInProgress) { return; } RoundInProgress = false; RoundStart = DateTime.MinValue; RoundEnd = DateTime.MinValue; Bounties.Clear(); if (!Running) { return; } Player[] alive = Alive.Items; CurLevel.ChatLevel(Colors.lime + "The game has ended!"); if (alive.Length == 0) { CurLevel.ChatLevel(Colors.maroon + "Zombies have won this round."); } else if (alive.Length == 1) { CurLevel.ChatLevel(Colors.green + "Congratulations to the sole survivor:"); } else { CurLevel.ChatLevel(Colors.green + "Congratulations to the survivors:"); } timer.Enabled = false; string playersString = ""; Player[] online = null; if (alive.Length == 0) { online = PlayerInfo.Online.Items; foreach (Player pl in online) { ResetPlayer(pl, ref playersString); } } else { foreach (Player pl in alive) { if (pl.Game.PledgeSurvive) { pl.SendMessage("You received &a5 %3" + Server.moneys + "%s for successfully pledging that you would survive."); pl.money += 5; pl.OnMoneyChanged(); } pl.Game.CurrentRoundsSurvived++; pl.Game.TotalRoundsSurvived++; pl.Game.MaxRoundsSurvived = Math.Max(pl.Game.CurrentRoundsSurvived, pl.Game.MaxRoundsSurvived); ResetPlayer(pl, ref playersString); } } CurLevel.ChatLevel(playersString); online = PlayerInfo.Online.Items; Random rand = new Random(); foreach (Player pl in online) { if (!pl.level.name.CaselessEq(CurLevelName)) { continue; } int money = GetMoney(pl, alive, rand); Player.GlobalDespawn(pl, true); Player.GlobalSpawn(pl, true); if (money == -1) { pl.SendMessage("You may not hide inside a block! No " + Server.moneys + " for you."); money = 0; } else if (money > 0) { pl.SendMessage(Colors.gold + "You gained " + money + " " + Server.moneys); } pl.Game.BlocksLeft = 50; pl.Game.CurrentInfected = 0; pl.money += money; pl.Game.Infected = false; if (pl.Game.Referee) { pl.SendMessage("You gained one " + Server.moneys + " because you're a ref. Would you like a medal as well?"); pl.money++; } pl.OnMoneyChanged(); } UpdateAllPlayerStatus(); Alive.Clear(); Infected.Clear(); }
void DoCoreGame(Random random) { Player[] alive = null; string lastTimespan = null; while ((alive = Alive.Items).Length > 0) { Player[] infected = Infected.Items; // Update the round time left shown in the top right int seconds = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds; string timespan = GetTimespan(seconds); if (lastTimespan != timespan) { UpdateAllPlayerStatus(timespan); lastTimespan = timespan; } foreach (Player pKiller in infected) { pKiller.Game.Infected = true; UpdatePlayerColor(pKiller, InfectCol); bool aliveChanged = false; foreach (Player pAlive in alive) { UpdatePlayerColor(pAlive, pAlive.color); if (Math.Abs(pAlive.pos[0] - pKiller.pos[0]) > HitboxPrecision || Math.Abs(pAlive.pos[1] - pKiller.pos[1]) > HitboxPrecision || Math.Abs(pAlive.pos[2] - pKiller.pos[2]) > HitboxPrecision) { continue; } if (!pAlive.Game.Infected && pKiller.Game.Infected && !pAlive.Game.Referee && !pKiller.Game.Referee && pKiller != pAlive && pKiller.level.name.CaselessEq(CurLevelName) && pAlive.level.name.CaselessEq(CurLevelName)) { InfectPlayer(pAlive); aliveChanged = true; pAlive.Game.BlocksLeft = 25; if (lastPlayerToInfect == pKiller.name) { infectCombo++; if (infectCombo >= 2) { pKiller.SendMessage("You gained " + (2 + infectCombo) + " " + Server.moneys); pKiller.money += 2 + infectCombo; pKiller.OnMoneyChanged(); CurLevel.ChatLevel(pKiller.ColoredName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!"); } } else { infectCombo = 0; } lastPlayerToInfect = pKiller.name; pKiller.Game.CurrentInfected++; pKiller.Game.TotalInfected++; pKiller.Game.MaxInfected = Math.Max(pKiller.Game.CurrentInfected, pKiller.Game.MaxInfected); ShowInfectMessage(random, pAlive, pKiller); CheckHumanPledge(pAlive); CheckBounty(pAlive, pKiller); UpdatePlayerColor(pAlive, InfectCol); } } if (aliveChanged) { alive = Alive.Items; } } Thread.Sleep(25); } }
List <Player> DoRoundCountdown() { while (true) { RoundStart = DateTime.UtcNow.AddSeconds(30); if (!Running) { return(null); } CurLevel.ChatLevel("&4Round Start:&f 30..."); Thread.Sleep(20000); if (!Running) { return(null); } CurLevel.ChatLevel("&4Round Start:&f 10..."); Thread.Sleep(5000); if (!Running) { return(null); } CurLevel.ChatLevel("&4Round Start:&f 5..."); Thread.Sleep(1000); if (!Running) { return(null); } CurLevel.ChatLevel("&4Round Start:&f 4..."); Thread.Sleep(1000); if (!Running) { return(null); } CurLevel.ChatLevel("&4Round Start:&f 3..."); Thread.Sleep(1000); if (!Running) { return(null); } CurLevel.ChatLevel("&4Round Start:&f 2..."); Thread.Sleep(1000); if (!Running) { return(null); } CurLevel.ChatLevel("&4Round Start:&f 1..."); Thread.Sleep(1000); if (!Running) { return(null); } int nonRefPlayers = 0; List <Player> players = new List <Player>(); Player[] online = PlayerInfo.Online.Items; foreach (Player p in online) { if (!p.Game.Referee && p.level.name.CaselessEq(CurLevelName)) { players.Add(p); nonRefPlayers++; } } if (!Running) { return(null); } if (nonRefPlayers >= 2) { return(players); } CurLevel.ChatLevel("&cNeed 2 or more non-ref players to start a round."); } }