mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Avoid hardcoding OnMoneyChanged() everywhere, just use p.SetMoney().
This commit is contained in:
parent
c3ac1ea8b9
commit
f2f1889c60
@ -47,9 +47,8 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
if (!TryMessage(p, p.ColoredName + " %S" + action)) return;
|
||||
p.NextEat = DateTime.UtcNow.AddSeconds(10);
|
||||
if (Economy.Enabled) {
|
||||
p.money -= 1; p.OnMoneyChanged();
|
||||
}
|
||||
if (Economy.Enabled)
|
||||
p.SetMoney(p.money - 1);
|
||||
}
|
||||
|
||||
static string[] defMessages = { "guzzled a grape", "chewed a cherry", "ate an avocado" };
|
||||
|
@ -51,7 +51,7 @@ namespace MCGalaxy.Commands {
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/buy [item] [value] <map name>");
|
||||
Player.Message(p, "%Hmap name is only used for %T/buy map%H.");
|
||||
Player.Message(p, "%HUse %T/store <type> %Hto see the information for an item.");
|
||||
Player.Message(p, "%HUse %T/store [item] %Hto see more information for an item.");
|
||||
Player.Message(p, "%H Available items: %f" + Economy.GetItemNames(", "));
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +59,7 @@ namespace MCGalaxy.Commands
|
||||
} else {
|
||||
if (ReachedMax(p, who.money, amount)) return;
|
||||
ecos.money = who.money;
|
||||
who.money += amount;
|
||||
who.OnMoneyChanged();
|
||||
who.SetMoney(who.money + amount);
|
||||
ecos = Economy.RetrieveEcoStats(who.name);
|
||||
Chat.MessageAll("{0} %Sgave {1} &f{2} &3{3}",
|
||||
giver, who.ColoredName, amount, Server.moneys);
|
||||
|
@ -60,8 +60,7 @@ namespace MCGalaxy.Commands
|
||||
if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return;
|
||||
|
||||
receiver.money = who.money;
|
||||
who.money += amount;
|
||||
who.OnMoneyChanged();
|
||||
who.SetMoney(who.money + amount);
|
||||
target = who.color + who.name;
|
||||
Chat.MessageAll("{0} %Spaid {1} &f{2} &3{3}",
|
||||
p.ColoredName, who.ColoredName, amount, Server.moneys);
|
||||
@ -70,8 +69,7 @@ namespace MCGalaxy.Commands
|
||||
payer.payment = "%f" + amount + " %3" + Server.moneys + " to " + target + "%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;
|
||||
p.money -= amount;
|
||||
p.OnMoneyChanged();
|
||||
p.SetMoney(p.money - amount);
|
||||
payer.money = p.money;
|
||||
Economy.UpdateEcoStats(payer);
|
||||
Economy.UpdateEcoStats(receiver);
|
||||
|
@ -61,8 +61,7 @@ namespace MCGalaxy.Commands {
|
||||
ecos = Economy.RetrieveEcoStats(who.name);
|
||||
ecos.money = who.money;
|
||||
Take(all, ref ecos, ref amount);
|
||||
who.money = ecos.money;
|
||||
who.OnMoneyChanged();
|
||||
who.SetMoney(ecos.money);
|
||||
Chat.MessageAll("{0} %Stook &f{2} &3{3} %Sfrom {1}",
|
||||
p.ColoredName, who.ColoredName, amount, Server.moneys);
|
||||
}
|
||||
|
@ -44,8 +44,7 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
}
|
||||
|
||||
p.money -= 10;
|
||||
p.OnMoneyChanged();
|
||||
p.SetMoney(p.money - 10);
|
||||
Server.zombie.Lottery.Add(p.name);
|
||||
if (Server.zombie.CurLevel != null)
|
||||
Server.zombie.CurLevel.ChatLevel(p.ColoredName + " %Sentered the lottery");
|
||||
|
@ -158,14 +158,8 @@ PRIMARY KEY(player)
|
||||
}
|
||||
|
||||
public static string GetItemNames(string separator) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < Items.Length; i++) {
|
||||
if (!Items[i].Enabled) continue;
|
||||
builder.Append(Items[i].ShopName);
|
||||
if (i < Items.Length - 1)
|
||||
builder.Append(separator);
|
||||
}
|
||||
return builder.Length == 0 ? "(no enabled items)" : builder.ToString();
|
||||
string items = Items.Join(x => x.Enabled ? x.ShopName : null, separator);
|
||||
return items.Length == 0 ? "(no enabled items)" : items;
|
||||
}
|
||||
|
||||
public static SimpleItem Color { get { return (SimpleItem)Items[0]; } }
|
||||
@ -176,8 +170,7 @@ PRIMARY KEY(player)
|
||||
|
||||
public static void MakePurchase(Player p, int cost, string item) {
|
||||
Economy.EcoStats ecos = RetrieveEcoStats(p.name);
|
||||
p.money -= cost;
|
||||
p.OnMoneyChanged();
|
||||
p.SetMoney(p.money - cost);
|
||||
ecos.money = p.money;
|
||||
ecos.totalSpent += cost;
|
||||
ecos.purchase = item + "%3 - Price: %f" + cost + " %3" + Server.moneys +
|
||||
|
@ -196,8 +196,7 @@ namespace MCGalaxy.Games {
|
||||
infectCombo++;
|
||||
if (infectCombo >= 2) {
|
||||
pKiller.SendMessage("You gained " + (2 + infectCombo) + " " + Server.moneys);
|
||||
pKiller.money += 2 + infectCombo;
|
||||
pKiller.OnMoneyChanged();
|
||||
pKiller.SetMoney(pKiller.money + (2 + infectCombo));
|
||||
CurLevel.ChatLevel(pKiller.ColoredName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!");
|
||||
}
|
||||
if (infectCombo == 10)
|
||||
@ -263,8 +262,7 @@ namespace MCGalaxy.Games {
|
||||
if (!pAlive.Game.PledgeSurvive) return;
|
||||
pAlive.Game.PledgeSurvive = false;
|
||||
CurLevel.ChatLevel(pAlive.ColoredName + "%Sbroke their pledge of not being infected.");
|
||||
pAlive.money = Math.Max(pAlive.money - 2, 0);
|
||||
pAlive.OnMoneyChanged();
|
||||
pAlive.SetMoney(Math.Max(pAlive.money - 2, 0));
|
||||
}
|
||||
|
||||
void CheckBounty(Player pAlive, Player pKiller) {
|
||||
@ -274,10 +272,8 @@ namespace MCGalaxy.Games {
|
||||
if (bounty != null) {
|
||||
CurLevel.ChatLevel(pKiller.ColoredName + " %Scollected the bounty of &a" +
|
||||
bounty.Amount + " %S" + Server.moneys + " on " + pAlive.ColoredName + "%S.");
|
||||
bounty.Origin.money = Math.Max(0, bounty.Origin.money - bounty.Amount);
|
||||
bounty.Origin.OnMoneyChanged();
|
||||
pKiller.money += bounty.Amount;
|
||||
pKiller.OnMoneyChanged();
|
||||
bounty.Origin.SetMoney(Math.Max(0, bounty.Origin.money - bounty.Amount));
|
||||
pKiller.SetMoney(pKiller.money + bounty.Amount);
|
||||
}
|
||||
}
|
||||
|
||||
@ -345,8 +341,7 @@ namespace MCGalaxy.Games {
|
||||
if (pl.Game.PledgeSurvive) {
|
||||
pl.SendMessage("You received &a5 %3" + Server.moneys +
|
||||
"%S for successfully pledging that you would survive.");
|
||||
pl.money += 5;
|
||||
pl.OnMoneyChanged();
|
||||
pl.SetMoney(pl.money + 5);
|
||||
}
|
||||
if (winChance <= 10)
|
||||
ZombieAwards.Give(pl, ZombieAwards.lowWinChance, this);
|
||||
@ -369,23 +364,22 @@ namespace MCGalaxy.Games {
|
||||
foreach (Player pl in online) {
|
||||
pl.Game.ResetInvisibility();
|
||||
if (!pl.level.name.CaselessEq(CurLevelName)) continue;
|
||||
int money = GetMoney(pl, alive, rand);
|
||||
int reward = GetReward(pl, alive, rand);
|
||||
|
||||
Entities.GlobalDespawn(pl, true);
|
||||
Entities.GlobalSpawn(pl, true);
|
||||
if (money == -1) {
|
||||
pl.SendMessage("You may not hide inside a block! No " + Server.moneys + " for you."); money = 0;
|
||||
} else if (money > 0) {
|
||||
pl.SendMessage( Colors.gold + "You gained " + money + " " + Server.moneys);
|
||||
if (reward == -1) {
|
||||
pl.SendMessage("You may not hide inside a block! No " + Server.moneys + " for you."); reward = 0;
|
||||
} else if (reward > 0) {
|
||||
pl.SendMessage(Colors.gold + "You gained " + reward + " " + Server.moneys);
|
||||
}
|
||||
|
||||
pl.money += money;
|
||||
pl.SetMoney(pl.money + reward);
|
||||
pl.Game.ResetZombieState();
|
||||
if (pl.Game.Referee) {
|
||||
pl.SendMessage("You gained one " + Server.moneys + " because you're a ref. Would you like a medal as well?");
|
||||
pl.money++;
|
||||
pl.SetMoney(pl.money + 1);
|
||||
}
|
||||
pl.OnMoneyChanged();
|
||||
}
|
||||
|
||||
DoLottery();
|
||||
@ -420,13 +414,12 @@ namespace MCGalaxy.Games {
|
||||
+ amount + " " + Server.moneys);
|
||||
}
|
||||
Lottery.Clear();
|
||||
winner.money += 10;
|
||||
winner.OnMoneyChanged();
|
||||
winner.SetMoney(winner.money + 10);
|
||||
if (online.Count == 7)
|
||||
ZombieAwards.Give(winner, ZombieAwards.luckyNumber7, this);
|
||||
}
|
||||
|
||||
int GetMoney(Player pl, Player[] alive, Random rand) {
|
||||
int GetReward(Player pl, Player[] alive, Random rand) {
|
||||
if (pl.CheckIfInsideBlock()) return -1;
|
||||
|
||||
if (alive.Length == 0) {
|
||||
|
@ -292,5 +292,10 @@ namespace MCGalaxy {
|
||||
public bool verifiedName;
|
||||
|
||||
public static bool IsSuper(Player p) { return p == null || p.ircNick != null; }
|
||||
|
||||
public void SetMoney(int amount) {
|
||||
money = amount;
|
||||
OnMoneyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user