Update the money figure in the CPE bottomright1 message when player's money changes.

This commit is contained in:
UnknownShadow200 2016-03-21 09:35:33 +11:00
parent 2e1aa7055d
commit cb85dab5d4
12 changed files with 102 additions and 83 deletions

View File

@ -56,6 +56,7 @@ namespace MCGalaxy.Commands
if (ReachedMax(p, who.money, amount)) return; if (ReachedMax(p, who.money, amount)) return;
ecos.money = who.money; ecos.money = who.money;
who.money += amount; who.money += amount;
who.OnMoneyChanged();
ecos = Economy.RetrieveEcoStats(who.name); ecos = Economy.RetrieveEcoStats(who.name);
Player.GlobalMessage(giver + " %Sgave " + who.FullName + " %f" + amount + " %3" + Server.moneys); Player.GlobalMessage(giver + " %Sgave " + who.FullName + " %f" + amount + " %3" + Server.moneys);
} }

View File

@ -60,6 +60,7 @@ namespace MCGalaxy.Commands
receiver.money = who.money; receiver.money = who.money;
who.money += amount; who.money += amount;
who.OnMoneyChanged();
target = who.color + who.name; target = who.color + who.name;
Player.GlobalMessage(p.FullName + " %Spaid " + who.FullName + " %f" + amount + " %3" + Server.moneys); 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.salary = "%f" + amount + " %3" + Server.moneys + " by " + p.color + p.name + "%3 on %f" + DateTime.Now.ToString(CultureInfo.InvariantCulture);
receiver.money += amount; receiver.money += amount;
p.money -= amount; p.money -= amount;
p.OnMoneyChanged();
payer.money = p.money; payer.money = p.money;
Economy.UpdateEcoStats(payer); Economy.UpdateEcoStats(payer);
Economy.UpdateEcoStats(receiver); Economy.UpdateEcoStats(receiver);

View File

@ -1,80 +1,81 @@
/* /*
Copyright 2011 MCForge Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.Globalization; using System.Globalization;
namespace MCGalaxy.Commands namespace MCGalaxy.Commands
{ {
public sealed class CmdTake : Command public sealed class CmdTake : Command
{ {
public override string name { get { return "take"; } } public override string name { get { return "take"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } } public override string type { get { return CommandTypes.Other; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdTake() { } public CmdTake() { }
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
string[] args = message.Split(' '); string[] args = message.Split(' ');
if (args.Length != 2) { Help(p); return; } if (args.Length != 2) { Help(p); return; }
string taker = null, takerRaw = null; string taker = null, takerRaw = null;
if (p == null) { takerRaw = "(console)"; taker = "(console)"; } if (p == null) { takerRaw = "(console)"; taker = "(console)"; }
else { takerRaw = p.color + p.name; taker = p.FullName; } else { takerRaw = p.color + p.name; taker = p.FullName; }
int amount = 0; int amount = 0;
bool all = args[1].CaselessEq("all"); bool all = args[1].CaselessEq("all");
if (!all && !int.TryParse(args[1], out amount)) { if (!all && !int.TryParse(args[1], out amount)) {
Player.SendMessage(p, "Amount must be an integer."); return; Player.SendMessage(p, "Amount must be an integer."); return;
} }
if (amount < 0) { Player.SendMessage(p, "%cYou can't take negative %3" + Server.moneys); return; } if (amount < 0) { Player.SendMessage(p, "%cYou can't take negative %3" + Server.moneys); return; }
Player who = PlayerInfo.Find(args[0]); 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; } if (p != null && p == who) { Player.SendMessage(p, "%cYou can't take %3" + Server.moneys + "%c from yourself"); return; }
Economy.EcoStats ecos; Economy.EcoStats ecos;
if (who == null) { if (who == null) {
OfflinePlayer off = PlayerInfo.FindOffline(args[0]); OfflinePlayer off = PlayerInfo.FindOffline(args[0]);
if (off == null) { Player.SendMessage(p, "The player \"&a" + args[0] + "%S\" was not found at all."); return; } if (off == null) { Player.SendMessage(p, "The player \"&a" + args[0] + "%S\" was not found at all."); return; }
ecos = Economy.RetrieveEcoStats(args[0]); ecos = Economy.RetrieveEcoStats(args[0]);
Take(all, ref ecos, ref amount); Take(all, ref ecos, ref amount);
Player.GlobalMessage(taker + " %Stook %f" + amount + " %3" + Server.moneys + " %Sfrom " + off.color + off.name + "%f(offline)"); Player.GlobalMessage(taker + " %Stook %f" + amount + " %3" + Server.moneys + " %Sfrom " + off.color + off.name + "%f(offline)");
} else { } else {
ecos = Economy.RetrieveEcoStats(who.name); ecos = Economy.RetrieveEcoStats(who.name);
ecos.money = who.money; ecos.money = who.money;
Take(all, ref ecos, ref amount); Take(all, ref ecos, ref amount);
who.money = ecos.money; who.money = ecos.money;
Player.GlobalMessage(taker + " %Stook %f" + amount + " %3" + Server.moneys + " %Sfrom " + who.prefix + who.name); 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); 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) { static void Take(bool all, ref Economy.EcoStats ecos, ref int amount) {
amount = ecos.money; if (all || ecos.money < amount) {
ecos.money = 0; amount = ecos.money;
} else { ecos.money = 0;
ecos.money -= amount; } else {
} ecos.money -= amount;
} }
}
public override void Help(Player p){
Player.SendMessage(p, "&f/take [player] <amount> " + Server.DefaultColor + "- Takes <amount> of " + Server.moneys + " from [player]"); public override void Help(Player p){
Player.SendMessage(p, "&f/take [player] all " + Server.DefaultColor + "- Takes all the " + Server.moneys + " from [player]"); Player.SendMessage(p, "&f/take [player] <amount> " + Server.DefaultColor + "- Takes <amount> of " + Server.moneys + " from [player]");
} Player.SendMessage(p, "&f/take [player] all " + Server.DefaultColor + "- Takes all the " + Server.moneys + " from [player]");
} }
}
} }

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Commands
Player.SendMessage(p, "Cannot use this on someone of equal or greater rank."); return; Player.SendMessage(p, "Cannot use this on someone of equal or greater rank."); return;
} }
Command.all.Find("hide").Use(who, ""); 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) public override void Help(Player p)

View File

@ -50,6 +50,7 @@ namespace MCGalaxy.Eco {
protected static void MakePurchase(Player p, int cost, string item) { protected static void MakePurchase(Player p, int cost, string item) {
Economy.EcoStats ecos = Economy.RetrieveEcoStats(p.name); Economy.EcoStats ecos = Economy.RetrieveEcoStats(p.name);
p.money -= cost; p.money -= cost;
p.OnMoneyChanged();
ecos.money = p.money; ecos.money = p.money;
ecos.totalSpent += cost; ecos.totalSpent += cost;
ecos.purchase = item + "%3 - Price: %f" + cost + " %3" + Server.moneys + ecos.purchase = item + "%3 - Price: %f" + cost + " %3" + Server.moneys +
@ -88,7 +89,7 @@ namespace MCGalaxy.Eco {
} }
// Must always provide an argument. // Must always provide an argument.
if (args.Length < 2) { cmd.Help(p); return; } 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; Player.SendMessage(p, "%cYou don't have enough %3" + Server.moneys + "%c to buy a " + Name + "."); return;
} }
OnBuyCommand(p, message, args); OnBuyCommand(p, message, args);

View File

@ -85,7 +85,7 @@ namespace MCGalaxy.Eco {
LevelPreset preset = FindPreset(args[1]); LevelPreset preset = FindPreset(args[1]);
if (preset == null) { Player.SendMessage(p, "%cThat isn't a level preset"); return; } 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; Player.SendMessage(p, "%cYou don't have enough %3" + Server.moneys + "%c to buy that map"); return;
} }
string name = p.name + "_" + args[2]; string name = p.name + "_" + args[2];

View File

@ -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); Player.SendMessage(p, "%cYou cannot buy anymore ranks, because you passed the max buyable rank: " + maxrank.color + maxrank.name);
return; 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; Player.SendMessage(p, "%cYou don't have enough %3" + Server.moneys + "%c to buy the next rank"); return;
} }

View File

@ -33,13 +33,13 @@ namespace MCGalaxy.Eco {
if (args.Length >= 3 && !byte.TryParse(args[2], out count) || count == 0 || count > 10) { 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; 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 + Player.SendMessage(p, "%cYou don't have enough %3" + Server.moneys +
"%c to buy " + (count * 10) + " " + Name + "."); return; "%c to buy " + (count * 10) + " " + Name + "."); return;
} }
p.blocksStacked += 10 * count; p.blocksStacked += 10 * count;
MakePurchase(p, Price, "%3Blocks: " + (10 * count)); MakePurchase(p, Price * count, "%3Blocks: " + (10 * count));
} }
} }

View File

@ -44,5 +44,7 @@ namespace MCGalaxy.Games {
public virtual void PlayerLeftGame(Player p) { } public virtual void PlayerLeftGame(Player p) { }
public virtual void PlayerJoinedLevel(Player p, Level oldLvl) { } public virtual void PlayerJoinedLevel(Player p, Level oldLvl) { }
public virtual void PlayerMoneyChanged(Player p) { }
} }
} }

View File

@ -166,8 +166,9 @@ namespace MCGalaxy.Games {
if (lastPlayerToInfect == pKiller.name) { if (lastPlayerToInfect == pKiller.name) {
infectCombo++; infectCombo++;
if (infectCombo >= 2) { if (infectCombo >= 2) {
pKiller.SendMessage("You gained " + (4 - infectCombo) + " " + Server.moneys); pKiller.SendMessage("You gained " + (4 + infectCombo) + " " + Server.moneys);
pKiller.money += 4 - infectCombo; pKiller.money += 4 + infectCombo;
pKiller.OnMoneyChanged();
CurrentLevel.ChatLevel(pKiller.FullName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!"); CurrentLevel.ChatLevel(pKiller.FullName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!");
} }
} else { } else {
@ -188,7 +189,9 @@ namespace MCGalaxy.Games {
CurrentLevel.ChatLevel(pKiller.FullName + " %Scollected the bounty of &a" + CurrentLevel.ChatLevel(pKiller.FullName + " %Scollected the bounty of &a" +
bounty.Amount + " %S" + Server.moneys + " on " + pAlive.FullName + "%S."); bounty.Amount + " %S" + Server.moneys + " on " + pAlive.FullName + "%S.");
bounty.Origin.money = Math.Max(0, bounty.Origin.money - bounty.Amount); bounty.Origin.money = Math.Max(0, bounty.Origin.money - bounty.Amount);
bounty.Origin.OnMoneyChanged();
pKiller.money += bounty.Amount; pKiller.money += bounty.Amount;
pKiller.OnMoneyChanged();
} }
UpdatePlayerColor(pAlive, Colors.red); 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.SendMessage("You gained one " + Server.moneys + " because you're a ref. Would you like a medal as well?");
pl.money++; pl.money++;
} }
pl.OnMoneyChanged();
} }
Alive.Clear(); Alive.Clear();
Infected.Clear(); Infected.Clear();

View File

@ -123,5 +123,11 @@ namespace MCGalaxy.Games {
Alive.Remove(p); Alive.Remove(p);
Infected.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);
}
} }
} }

View File

@ -46,8 +46,6 @@ namespace MCGalaxy {
System.Timers.Timer muteTimer = new System.Timers.Timer(1000); System.Timers.Timer muteTimer = new System.Timers.Timer(1000);
public static List<string> emoteList = new List<string>(); public static List<string> emoteList = new List<string>();
public List<string> listignored = new List<string>(); public List<string> listignored = new List<string>();
public List<string> mapgroups = new List<string>();
public static int totalMySQLFailed = 0;
public static byte number { get { return (byte)PlayerInfo.Online.Count; } } public static byte number { get { return (byte)PlayerInfo.Online.Count; } }
static System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); static System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
static MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); static MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
@ -866,10 +864,14 @@ Next: continue;
} }
public bool EnoughMoney(int amount) { public bool EnoughMoney(int amount) {
if (this.money >= amount) return money >= amount;
return true;
return false;
} }
public void OnMoneyChanged() {
if (Server.ZombieModeOn) Server.zombie.PlayerMoneyChanged(this);
if (Server.lava.active) Server.lava.PlayerMoneyChanged(this);
}
public void ReviewTimer() { public void ReviewTimer() {
this.canusereview = false; this.canusereview = false;
System.Timers.Timer Clock = new System.Timers.Timer(1000 * Server.reviewcooldown); System.Timers.Timer Clock = new System.Timers.Timer(1000 * Server.reviewcooldown);