From 509fa5d1d77d76a7819b62ec5e41889e2e003917 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 21 Sep 2016 09:35:18 +1000 Subject: [PATCH] ZS: Bounties now persist between rounds, or until either the target or setter leaves the server. --- .../Fun/ZombieSurvival/CmdBounties.cs | 24 ++++++++--------- .../Commands/Fun/ZombieSurvival/CmdBounty.cs | 11 ++++---- .../Games/ZombieSurvival/ZombieGame.Core.cs | 26 +++++++++++-------- .../Games/ZombieSurvival/ZombieGame.Game.cs | 13 ++++++++++ .../Games/ZombieSurvival/ZombieGame.Props.cs | 9 ++++--- MCGalaxy/Games/ZombieSurvival/ZombieGame.cs | 9 +++++++ 6 files changed, 60 insertions(+), 32 deletions(-) diff --git a/MCGalaxy/Commands/Fun/ZombieSurvival/CmdBounties.cs b/MCGalaxy/Commands/Fun/ZombieSurvival/CmdBounties.cs index 2a9e9f20c..2e59fab25 100644 --- a/MCGalaxy/Commands/Fun/ZombieSurvival/CmdBounties.cs +++ b/MCGalaxy/Commands/Fun/ZombieSurvival/CmdBounties.cs @@ -14,7 +14,7 @@ BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licenses for the specific language governing permissions and limitations under the Licenses. -*/ + */ using System.Collections.Generic; using MCGalaxy.Games; @@ -27,20 +27,20 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Games; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } - public override CommandEnable Enabled { get { return CommandEnable.Zombie; } } + public override CommandEnable Enabled { get { return CommandEnable.Zombie; } } public CmdBounties() { } public override void Use(Player p, string message) { - Dictionary bounties = Server.zombie.Bounties; - if (bounties.Count == 0) { - Player.Message(p, "There are no active bounties."); - } else { - foreach (var pair in bounties) { - Player pl = PlayerInfo.FindExact(pair.Key); - if (pl == null) continue; - Player.Message(p, "Bounty for " + pl.ColoredName + " %Sis &a" - + pair.Value.Amount + "%S" + Server.moneys + "."); - } + BountyData[] bounties = Server.zombie.Bounties.Items; + if (bounties.Length == 0) { + Player.Message(p, "There are no active bounties."); return; + } + + foreach (BountyData bounty in bounties) { + Player pl = PlayerInfo.FindExact(bounty.Target); + if (pl == null) continue; + Player.Message(p, "Bounty for {0} %Sis &a{1} %S{2}.", + pl.ColoredName, bounty.Amount, Server.moneys); } } diff --git a/MCGalaxy/Commands/Fun/ZombieSurvival/CmdBounty.cs b/MCGalaxy/Commands/Fun/ZombieSurvival/CmdBounty.cs index 2689c21cb..001d8ecc2 100644 --- a/MCGalaxy/Commands/Fun/ZombieSurvival/CmdBounty.cs +++ b/MCGalaxy/Commands/Fun/ZombieSurvival/CmdBounty.cs @@ -42,19 +42,20 @@ namespace MCGalaxy.Commands { Player.Message(p, "You do not have enough " + Server.moneys + " to place such a large bountry."); return; } - BountyData old; - if (Server.zombie.Bounties.TryGetValue(who.name, out old) && old.Amount >= amount) { + BountyData old = Server.zombie.FindBounty(who.name); + if (old != null && old.Amount >= amount) { Player.Message(p, "There is already a larger active bounty for " + who.name + "."); return; } if (old == null) { Chat.MessageAll("Looks like someone really wants the brains of {0}%S! A bounty of &a{1} %S{2} was placed on them.", - who.ColoredName, amount, Server.moneys); + who.ColoredName, amount, Server.moneys); } else { Chat.MessageAll("{0} %Sis popular! The bounty on them was increased from &a{3} %Sto &a{1} %S{2}.", - who.ColoredName, amount, Server.moneys, old.Amount); + who.ColoredName, amount, Server.moneys, old.Amount); + Server.zombie.Bounties.Remove(old); } - Server.zombie.Bounties[who.name] = new BountyData(p, amount); + Server.zombie.Bounties.Add(new BountyData(p.name, who.name, amount)); } public override void Help(Player p) { diff --git a/MCGalaxy/Games/ZombieSurvival/ZombieGame.Core.cs b/MCGalaxy/Games/ZombieSurvival/ZombieGame.Core.cs index f16af87a1..2230e4cc6 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZombieGame.Core.cs @@ -52,7 +52,7 @@ namespace MCGalaxy.Games { return; } else if (Status == ZombieGameStatus.InfiniteRounds) { DoRound(); - if (ZombieGameProps.ChangeLevels) + if (ZombieGameProps.ChangeLevels) LevelPicker.ChooseNextLevel(this); } else if (Status == ZombieGameStatus.SingleRound) { DoRound(); @@ -62,7 +62,7 @@ namespace MCGalaxy.Games { ResetState(); return; } else { DoRound(); - if (ZombieGameProps.ChangeLevels) + if (ZombieGameProps.ChangeLevels) LevelPicker.ChooseNextLevel(this); } } else if (Status == ZombieGameStatus.LastRound) { @@ -94,7 +94,7 @@ namespace MCGalaxy.Games { CurLevel.ChatLevel(first.ColoredName + " %Sstarted the infection!"); InfectPlayer(first); - DoCoreGame(random); + DoCoreGame(random); if (!Running) { Status = ZombieGameStatus.LastRound; return; } else { @@ -186,7 +186,7 @@ namespace MCGalaxy.Games { UpdatePlayerColor(pAlive, pAlive.color); int dx = Math.Abs(pAlive.pos[0] - pKiller.pos[0]); int dy = Math.Abs(pAlive.pos[1] - pKiller.pos[1]); - int dz = Math.Abs(pAlive.pos[2] - pKiller.pos[2]); + int dz = Math.Abs(pAlive.pos[2] - pKiller.pos[2]); if (dx > dist || dy > dist || dz > dist) continue; if (!pAlive.Game.Infected && pKiller.Game.Infected && !pAlive.Game.Referee @@ -245,7 +245,7 @@ namespace MCGalaxy.Games { Player[] players = PlayerInfo.Online.Items; foreach (Player p in players) { if (!p.Game.Invisible || p.level != CurLevel) continue; - DateTime end = p.Game.InvisibilityEnd; + DateTime end = p.Game.InvisibilityEnd; if (now >= end) { ResetInvisibility(p); continue; } int left = (int)Math.Ceiling((end - now).TotalSeconds); @@ -268,13 +268,18 @@ namespace MCGalaxy.Games { } void CheckBounty(Player pAlive, Player pKiller) { - BountyData bounty; - if (Bounties.TryGetValue(pAlive.name, out bounty)) - Bounties.Remove(pAlive.name); - if (bounty != null) { + BountyData bounty = FindBounty(pAlive.name); + if (bounty == null) return; + Bounties.Remove(bounty); + + Player origin = PlayerInfo.FindExact(bounty.Origin); + if (origin == null) { + Player.Message(pKiller, "Cannot collect the bounty, as the player who set it is offline."); + } else { CurLevel.ChatLevel(pKiller.ColoredName + " %Scollected the bounty of &a" + bounty.Amount + " %S" + Server.moneys + " on " + pAlive.ColoredName + "%S."); - bounty.Origin.SetMoney(Math.Max(0, bounty.Origin.money - bounty.Amount)); + + origin.SetMoney(Math.Max(0, origin.money - bounty.Amount)); pKiller.SetMoney(pKiller.money + bounty.Amount); } } @@ -304,7 +309,6 @@ namespace MCGalaxy.Games { RoundInProgress = false; RoundStart = DateTime.MinValue; RoundEnd = DateTime.MinValue; - Bounties.Clear(); if (!Running) return; Rewards.HandOut(this); diff --git a/MCGalaxy/Games/ZombieSurvival/ZombieGame.Game.cs b/MCGalaxy/Games/ZombieSurvival/ZombieGame.Game.cs index c4d84a6fe..9f5d358de 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZombieGame.Game.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZombieGame.Game.cs @@ -97,10 +97,23 @@ namespace MCGalaxy.Games { Alive.Remove(p); Infected.Remove(p); p.Game.Infected = false; + RemoveBounties(p); + AssignFirstZombie(); UpdateAllPlayerStatus(); } + 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); + } + } + public override void PlayerJoinedServer(Player p) { if (!Running || ZombieGameProps.SetMainLevel) return; Player.Message(p, "Zombie Survival is running! Type %T/g " + CurLevelName + " %Sto join."); diff --git a/MCGalaxy/Games/ZombieSurvival/ZombieGame.Props.cs b/MCGalaxy/Games/ZombieSurvival/ZombieGame.Props.cs index 3974bc2b9..2f51dc841 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZombieGame.Props.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZombieGame.Props.cs @@ -24,11 +24,11 @@ using MCGalaxy.Config; namespace MCGalaxy.Games { public class BountyData { - public Player Origin; + public string Origin, Target; public int Amount; - public BountyData(Player origin, int amount) { - Origin = origin; Amount = amount; + public BountyData(string origin, string target, int amount) { + Origin = origin; Target = target; Amount = amount; } } @@ -90,7 +90,8 @@ namespace MCGalaxy.Games { string lastPlayerToInfect = ""; int infectCombo = 0; - public Dictionary Bounties = new Dictionary(); + /// List of players who have a bounty on them. + public VolatileArray Bounties = new VolatileArray(false); /// List of players who are in the lottery. public VolatileArray Lottery = new VolatileArray(false); diff --git a/MCGalaxy/Games/ZombieSurvival/ZombieGame.cs b/MCGalaxy/Games/ZombieSurvival/ZombieGame.cs index b50ed9f53..a76ac2f0b 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZombieGame.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZombieGame.cs @@ -186,6 +186,15 @@ namespace MCGalaxy.Games { CurLevel = null; } + public BountyData FindBounty(string target) { + BountyData[] bounties = Bounties.Items; + foreach (BountyData bounty in bounties) { + if (bounty.Target.CaselessEq(target)) return bounty; + } + return null; + } + + void UpdatePlayerStatus(Player p) { int seconds = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds; string status = GetStatusMessage(GetTimespan(seconds));