From 2752a9e018e4ef28c94d67e926a938d043936c9a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 13 Mar 2016 10:27:08 +1100 Subject: [PATCH] Add /bounties, start work for /bounty. --- Commands/Fun/CmdBounties.cs | 51 ++++++++++++++++++++++++++ Commands/Fun/CmdBounty.cs | 58 ++++++++++++++++++++++++++++++ Games/ZombieSurvival/ZombieGame.cs | 14 ++++++-- MCGalaxy_.csproj | 2 ++ Player/Player.Handlers.cs | 4 +++ 5 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 Commands/Fun/CmdBounties.cs create mode 100644 Commands/Fun/CmdBounty.cs diff --git a/Commands/Fun/CmdBounties.cs b/Commands/Fun/CmdBounties.cs new file mode 100644 index 000000000..3218142a6 --- /dev/null +++ b/Commands/Fun/CmdBounties.cs @@ -0,0 +1,51 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + 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; + +namespace MCGalaxy.Commands { + + public sealed class CmdBounties : Command { + + public override string name { get { return "bounties"; } } + public override string shortcut { get { return ""; } } + 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 bool Enabled { get { return Server.ZombieModeOn; } } + public CmdBounties() { } + + public override void Use(Player p, string message) { + Dictionary bounties = Server.zombie.Bounties; + if (bounties.Count == 0) { + Player.SendMessage(p, "There are no active bounties."); + } else { + foreach (var pair in bounties) { + Player pl = PlayerInfo.FindExact(pair.Key); + if (pl == null) continue; + Player.SendMessage(p, "Bounty for " + pl.FullName + " %Sis &a" + + pair.Value.Amount + "%S" + Server.moneys + "."); + } + } + } + + public override void Help(Player p) { + Player.SendMessage(p, "%T/bounties"); + Player.SendMessage(p, "%HOutputs a list of all active bounties on players."); + } + } +} diff --git a/Commands/Fun/CmdBounty.cs b/Commands/Fun/CmdBounty.cs new file mode 100644 index 000000000..4a2d111dd --- /dev/null +++ b/Commands/Fun/CmdBounty.cs @@ -0,0 +1,58 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + 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. +*/ +namespace MCGalaxy.Commands { + + public sealed class CmdBounty : Command { + + public override string name { get { return "bounty"; } } + public override string shortcut { get { return ""; } } + 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 bool Enabled { get { return Server.ZombieModeOn; } } + public CmdBounty() { } + + public override void Use(Player p, string message) { + string[] args = message.Split(' '); + if (args.Length < 2) { Help(p); return; } + + Player who = PlayerInfo.FindOrShowMatches(p, args[0]); + if (who == null) return; + byte amount = 0; + if (!byte.TryParse(args[1], out amount)) { + Player.SendMessage(p, "The bounty amount must be an positive integer less than 256."); return; + } + if (p.money < amount) { + Player.SendMessage(p, "You do not have enough " + Server.moneys + " to place such a large bountry."); return; + } + + BountyData data; + if (Server.zombie.Bounties.TryGetValue(who.name, out data) && data.Amount >= amount) { + Player.SendMessage(p, "There is already a larger active bounty for " + who.name + "."); return; + } + // TODO here - actually announce the bounty and place it + // "Looks like someone wants the brain of ! An bounty for x was placed on them. + // " is popular! The bounty on them was increased from to money. + } + + public override void Help(Player p) { + Player.SendMessage(p, "%T/bounty [name] [amount]"); + Player.SendMessage(p, "%HSets a bounty on the given player."); + } + } +} diff --git a/Games/ZombieSurvival/ZombieGame.cs b/Games/ZombieSurvival/ZombieGame.cs index 5fa97e92f..f9fdf9d0a 100644 --- a/Games/ZombieSurvival/ZombieGame.cs +++ b/Games/ZombieSurvival/ZombieGame.cs @@ -24,8 +24,17 @@ using System.Linq; using System.Threading; using System.Timers; -namespace MCGalaxy -{ +namespace MCGalaxy { + + public class BountyData { + public Player Origin; + public int Amount; + + public BountyData(Player origin, int amount) { + Origin = origin; Amount = amount; + } + } + public sealed partial class ZombieGame { public int amountOfRounds = 0; @@ -55,6 +64,7 @@ namespace MCGalaxy string lastPlayerToInfect = ""; int infectCombo = 0; + public Dictionary Bounties = new Dictionary(); public void StartGame(int status, int amount) { diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index edead33e3..0bdd734c5 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -175,6 +175,8 @@ + + diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index 648105cde..6342e945e 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -1509,6 +1509,10 @@ return; if (!group.CanExecute(command)) { SendMessage("You are not allowed to use \"" + cmd + "\"."); return; } + if (!command.Enabled) { + SendMessage("The game associated with this game is not running, " + + "so this command is disabled."); return; + } if (cmd != "repeat") lastCMD = cmd + " " + message; if (level.IsMuseum && !command.museumUsable ) {