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;
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);
}

View File

@ -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);

View File

@ -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] <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]");
}
}
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] <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;
}
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)

View File

@ -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);

View File

@ -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];

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);
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;
}

View File

@ -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));
}
}

View File

@ -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) { }
}
}

View File

@ -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();

View File

@ -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);
}
}
}

View File

@ -46,8 +46,6 @@ namespace MCGalaxy {
System.Timers.Timer muteTimer = new System.Timers.Timer(1000);
public static List<string> emoteList = 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; } }
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);