diff --git a/Commands/Economy/CmdGive.cs b/Commands/Economy/CmdGive.cs index 5da2aba19..78a8c68a2 100644 --- a/Commands/Economy/CmdGive.cs +++ b/Commands/Economy/CmdGive.cs @@ -56,6 +56,7 @@ namespace MCGalaxy.Commands if (ReachedMax(p, who.money, amount)) return; ecos.money = who.money; who.money += amount; + who.OnMoneyChanged(); ecos = Economy.RetrieveEcoStats(who.name); Player.GlobalMessage(giver + " %Sgave " + who.FullName + " %f" + amount + " %3" + Server.moneys); } diff --git a/Commands/Economy/CmdPay.cs b/Commands/Economy/CmdPay.cs index 6e2a7bc07..64932dfa5 100644 --- a/Commands/Economy/CmdPay.cs +++ b/Commands/Economy/CmdPay.cs @@ -60,6 +60,7 @@ namespace MCGalaxy.Commands receiver.money = who.money; who.money += amount; + who.OnMoneyChanged(); target = who.color + who.name; Player.GlobalMessage(p.FullName + " %Spaid " + who.FullName + " %f" + amount + " %3" + Server.moneys); } @@ -68,6 +69,7 @@ namespace MCGalaxy.Commands receiver.salary = "%f" + amount + " %3" + Server.moneys + " by " + p.color + p.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture); receiver.money += amount; p.money -= amount; + p.OnMoneyChanged(); payer.money = p.money; Economy.UpdateEcoStats(payer); Economy.UpdateEcoStats(receiver); diff --git a/Commands/Economy/CmdTake.cs b/Commands/Economy/CmdTake.cs index 43a404bf6..fd9e5e253 100644 --- a/Commands/Economy/CmdTake.cs +++ b/Commands/Economy/CmdTake.cs @@ -1,80 +1,81 @@ /* - Copyright 2011 MCForge - - 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. + Copyright 2011 MCForge + + 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; using System.Globalization; namespace MCGalaxy.Commands { - public sealed class CmdTake : Command - { - public override string name { get { return "take"; } } - public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Other; } } - public override bool museumUsable { get { return true; } } - public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } - public CmdTake() { } + public sealed class CmdTake : Command + { + public override string name { get { return "take"; } } + public override string shortcut { get { return ""; } } + public override string type { get { return CommandTypes.Other; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } + public CmdTake() { } - public override void Use(Player p, string message) { - string[] args = message.Split(' '); - if (args.Length != 2) { Help(p); return; } + public override void Use(Player p, string message) { + string[] args = message.Split(' '); + if (args.Length != 2) { Help(p); return; } - string taker = null, takerRaw = null; - if (p == null) { takerRaw = "(console)"; taker = "(console)"; } - else { takerRaw = p.color + p.name; taker = p.FullName; } + string taker = null, takerRaw = null; + if (p == null) { takerRaw = "(console)"; taker = "(console)"; } + else { takerRaw = p.color + p.name; taker = p.FullName; } - int amount = 0; - bool all = args[1].CaselessEq("all"); - if (!all && !int.TryParse(args[1], out amount)) { - Player.SendMessage(p, "Amount must be an integer."); return; - } - if (amount < 0) { Player.SendMessage(p, "%cYou can't take negative %3" + Server.moneys); return; } - Player who = PlayerInfo.Find(args[0]); - if (p != null && p == who) { Player.SendMessage(p, "%cYou can't take %3" + Server.moneys + "%c from yourself"); return; } - - Economy.EcoStats ecos; - if (who == null) { - OfflinePlayer off = PlayerInfo.FindOffline(args[0]); - if (off == null) { Player.SendMessage(p, "The player \"&a" + args[0] + "%S\" was not found at all."); return; } - ecos = Economy.RetrieveEcoStats(args[0]); - Take(all, ref ecos, ref amount); - Player.GlobalMessage(taker + " %Stook %f" + amount + " %3" + Server.moneys + " %Sfrom " + off.color + off.name + "%f(offline)"); - } else { - ecos = Economy.RetrieveEcoStats(who.name); - ecos.money = who.money; - Take(all, ref ecos, ref amount); - who.money = ecos.money; - Player.GlobalMessage(taker + " %Stook %f" + amount + " %3" + Server.moneys + " %Sfrom " + who.prefix + who.name); - } - ecos.fine = "%f" + amount + " %3" + Server.moneys + " by " + takerRaw + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture); - Economy.UpdateEcoStats(ecos); - } - - static void Take(bool all, ref Economy.EcoStats ecos, ref int amount) { - if (all || ecos.money < amount) { - amount = ecos.money; - ecos.money = 0; - } else { - ecos.money -= amount; - } - } - - public override void Help(Player p){ - Player.SendMessage(p, "&f/take [player] " + Server.DefaultColor + "- Takes of " + Server.moneys + " from [player]"); - Player.SendMessage(p, "&f/take [player] all " + Server.DefaultColor + "- Takes all the " + Server.moneys + " from [player]"); - } - } + int amount = 0; + bool all = args[1].CaselessEq("all"); + if (!all && !int.TryParse(args[1], out amount)) { + Player.SendMessage(p, "Amount must be an integer."); return; + } + if (amount < 0) { Player.SendMessage(p, "%cYou can't take negative %3" + Server.moneys); return; } + Player who = PlayerInfo.Find(args[0]); + if (p != null && p == who) { Player.SendMessage(p, "%cYou can't take %3" + Server.moneys + "%c from yourself"); return; } + + Economy.EcoStats ecos; + if (who == null) { + OfflinePlayer off = PlayerInfo.FindOffline(args[0]); + if (off == null) { Player.SendMessage(p, "The player \"&a" + args[0] + "%S\" was not found at all."); return; } + ecos = Economy.RetrieveEcoStats(args[0]); + Take(all, ref ecos, ref amount); + Player.GlobalMessage(taker + " %Stook %f" + amount + " %3" + Server.moneys + " %Sfrom " + off.color + off.name + "%f(offline)"); + } else { + ecos = Economy.RetrieveEcoStats(who.name); + ecos.money = who.money; + Take(all, ref ecos, ref amount); + who.money = ecos.money; + who.OnMoneyChanged(); + Player.GlobalMessage(taker + " %Stook %f" + amount + " %3" + Server.moneys + " %Sfrom " + who.prefix + who.name); + } + ecos.fine = "%f" + amount + " %3" + Server.moneys + " by " + takerRaw + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture); + Economy.UpdateEcoStats(ecos); + } + + static void Take(bool all, ref Economy.EcoStats ecos, ref int amount) { + if (all || ecos.money < amount) { + amount = ecos.money; + ecos.money = 0; + } else { + ecos.money -= amount; + } + } + + public override void Help(Player p){ + Player.SendMessage(p, "&f/take [player] " + Server.DefaultColor + "- Takes of " + Server.moneys + " from [player]"); + Player.SendMessage(p, "&f/take [player] all " + Server.DefaultColor + "- Takes all the " + Server.moneys + " from [player]"); + } + } } diff --git a/Commands/Moderation/CmdOhide.cs b/Commands/Moderation/CmdOhide.cs index 3b84c072c..9abc37141 100644 --- a/Commands/Moderation/CmdOhide.cs +++ b/Commands/Moderation/CmdOhide.cs @@ -42,7 +42,7 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "Cannot use this on someone of equal or greater rank."); return; } Command.all.Find("hide").Use(who, ""); - Player.SendMessage(p, "Used /hide on " + who.color + who.name + Server.DefaultColor + "%S."); + Player.SendMessage(p, "Used /hide on " + who.color + who.name + "%S."); } public override void Help(Player p) diff --git a/Economy/Item.cs b/Economy/Item.cs index 6675ee3ec..88b24a85d 100644 --- a/Economy/Item.cs +++ b/Economy/Item.cs @@ -50,6 +50,7 @@ namespace MCGalaxy.Eco { protected static void MakePurchase(Player p, int cost, string item) { Economy.EcoStats ecos = Economy.RetrieveEcoStats(p.name); p.money -= cost; + p.OnMoneyChanged(); ecos.money = p.money; ecos.totalSpent += cost; ecos.purchase = item + "%3 - Price: %f" + cost + " %3" + Server.moneys + @@ -88,7 +89,7 @@ namespace MCGalaxy.Eco { } // Must always provide an argument. if (args.Length < 2) { cmd.Help(p); return; } - if (!p.EnoughMoney(Price)) { + if (p.money < Price) { Player.SendMessage(p, "%cYou don't have enough %3" + Server.moneys + "%c to buy a " + Name + "."); return; } OnBuyCommand(p, message, args); diff --git a/Economy/LevelItem.cs b/Economy/LevelItem.cs index cd8c87bc1..a6486f50b 100644 --- a/Economy/LevelItem.cs +++ b/Economy/LevelItem.cs @@ -85,7 +85,7 @@ namespace MCGalaxy.Eco { LevelPreset preset = FindPreset(args[1]); if (preset == null) { Player.SendMessage(p, "%cThat isn't a level preset"); return; } - if (!p.EnoughMoney(preset.price)) { + if (p.money < preset.price) { Player.SendMessage(p, "%cYou don't have enough %3" + Server.moneys + "%c to buy that map"); return; } string name = p.name + "_" + args[2]; diff --git a/Economy/RankItem.cs b/Economy/RankItem.cs index 7f6f6208a..9a5163fe2 100644 --- a/Economy/RankItem.cs +++ b/Economy/RankItem.cs @@ -75,7 +75,7 @@ namespace MCGalaxy.Eco { Player.SendMessage(p, "%cYou cannot buy anymore ranks, because you passed the max buyable rank: " + maxrank.color + maxrank.name); return; } - if (!p.EnoughMoney(NextRank(p).price)) { + if (p.money < NextRank(p).price) { Player.SendMessage(p, "%cYou don't have enough %3" + Server.moneys + "%c to buy the next rank"); return; } diff --git a/Economy/ZombieItems.cs b/Economy/ZombieItems.cs index a94648c37..a64dc9d3f 100644 --- a/Economy/ZombieItems.cs +++ b/Economy/ZombieItems.cs @@ -33,13 +33,13 @@ namespace MCGalaxy.Eco { if (args.Length >= 3 && !byte.TryParse(args[2], out count) || count == 0 || count > 10) { Player.SendMessage(p, "Number of groups of 10 blocks to buy must be an integer between 1 and 10."); return; } - if (!p.EnoughMoney(Price * count)) { + if (p.money < Price * count) { Player.SendMessage(p, "%cYou don't have enough %3" + Server.moneys + "%c to buy " + (count * 10) + " " + Name + "."); return; } p.blocksStacked += 10 * count; - MakePurchase(p, Price, "%3Blocks: " + (10 * count)); + MakePurchase(p, Price * count, "%3Blocks: " + (10 * count)); } } diff --git a/Games/IGame.cs b/Games/IGame.cs index e6a8ccac9..c994e2498 100644 --- a/Games/IGame.cs +++ b/Games/IGame.cs @@ -44,5 +44,7 @@ namespace MCGalaxy.Games { public virtual void PlayerLeftGame(Player p) { } public virtual void PlayerJoinedLevel(Player p, Level oldLvl) { } + + public virtual void PlayerMoneyChanged(Player p) { } } } diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index 54b96eb9a..f3872bed8 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -166,8 +166,9 @@ namespace MCGalaxy.Games { if (lastPlayerToInfect == pKiller.name) { infectCombo++; if (infectCombo >= 2) { - pKiller.SendMessage("You gained " + (4 - infectCombo) + " " + Server.moneys); - pKiller.money += 4 - infectCombo; + pKiller.SendMessage("You gained " + (4 + infectCombo) + " " + Server.moneys); + pKiller.money += 4 + infectCombo; + pKiller.OnMoneyChanged(); CurrentLevel.ChatLevel(pKiller.FullName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!"); } } else { @@ -188,7 +189,9 @@ namespace MCGalaxy.Games { CurrentLevel.ChatLevel(pKiller.FullName + " %Scollected the bounty of &a" + bounty.Amount + " %S" + Server.moneys + " on " + pAlive.FullName + "%S."); bounty.Origin.money = Math.Max(0, bounty.Origin.money - bounty.Amount); + bounty.Origin.OnMoneyChanged(); pKiller.money += bounty.Amount; + pKiller.OnMoneyChanged(); } UpdatePlayerColor(pAlive, Colors.red); } @@ -274,6 +277,7 @@ namespace MCGalaxy.Games { pl.SendMessage("You gained one " + Server.moneys + " because you're a ref. Would you like a medal as well?"); pl.money++; } + pl.OnMoneyChanged(); } Alive.Clear(); Infected.Clear(); diff --git a/Games/ZombieSurvival/ZombieGame.Game.cs b/Games/ZombieSurvival/ZombieGame.Game.cs index 87ca994bb..72bf6b393 100644 --- a/Games/ZombieSurvival/ZombieGame.Game.cs +++ b/Games/ZombieSurvival/ZombieGame.Game.cs @@ -123,5 +123,11 @@ namespace MCGalaxy.Games { Alive.Remove(p); Infected.Remove(p); } + + public override void PlayerMoneyChanged(Player p) { + if (Status == ZombieGameStatus.NotStarted + || !p.level.name.CaselessEq(CurrentLevelName)) return; + p.SendCpeMessage(CpeMessageType.BottomRight1, "%SYou have &a" + p.money + " %S" + Server.moneys); + } } } diff --git a/Player/Player.cs b/Player/Player.cs index 9393b15c3..54c269c00 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -46,8 +46,6 @@ namespace MCGalaxy { System.Timers.Timer muteTimer = new System.Timers.Timer(1000); public static List emoteList = new List(); public List listignored = new List(); - public List mapgroups = new List(); - public static int totalMySQLFailed = 0; public static byte number { get { return (byte)PlayerInfo.Online.Count; } } static System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); static MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); @@ -866,10 +864,14 @@ Next: continue; } public bool EnoughMoney(int amount) { - if (this.money >= amount) - return true; - return false; + return money >= amount; } + + public void OnMoneyChanged() { + if (Server.ZombieModeOn) Server.zombie.PlayerMoneyChanged(this); + if (Server.lava.active) Server.lava.PlayerMoneyChanged(this); + } + public void ReviewTimer() { this.canusereview = false; System.Timers.Timer Clock = new System.Timers.Timer(1000 * Server.reviewcooldown);