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;
|
if (!TryMessage(p, p.ColoredName + " %S" + action)) return;
|
||||||
p.NextEat = DateTime.UtcNow.AddSeconds(10);
|
p.NextEat = DateTime.UtcNow.AddSeconds(10);
|
||||||
if (Economy.Enabled) {
|
if (Economy.Enabled)
|
||||||
p.money -= 1; p.OnMoneyChanged();
|
p.SetMoney(p.money - 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static string[] defMessages = { "guzzled a grape", "chewed a cherry", "ate an avocado" };
|
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) {
|
public override void Help(Player p) {
|
||||||
Player.Message(p, "%T/buy [item] [value] <map name>");
|
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, "%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(", "));
|
Player.Message(p, "%H Available items: %f" + Economy.GetItemNames(", "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,7 @@ namespace MCGalaxy.Commands
|
|||||||
} else {
|
} else {
|
||||||
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.SetMoney(who.money + amount);
|
||||||
who.OnMoneyChanged();
|
|
||||||
ecos = Economy.RetrieveEcoStats(who.name);
|
ecos = Economy.RetrieveEcoStats(who.name);
|
||||||
Chat.MessageAll("{0} %Sgave {1} &f{2} &3{3}",
|
Chat.MessageAll("{0} %Sgave {1} &f{2} &3{3}",
|
||||||
giver, who.ColoredName, amount, Server.moneys);
|
giver, who.ColoredName, amount, Server.moneys);
|
||||||
|
@ -60,8 +60,7 @@ namespace MCGalaxy.Commands
|
|||||||
if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return;
|
if (!IsLegalPayment(p, payer.money, receiver.money, amount)) return;
|
||||||
|
|
||||||
receiver.money = who.money;
|
receiver.money = who.money;
|
||||||
who.money += amount;
|
who.SetMoney(who.money + amount);
|
||||||
who.OnMoneyChanged();
|
|
||||||
target = who.color + who.name;
|
target = who.color + who.name;
|
||||||
Chat.MessageAll("{0} %Spaid {1} &f{2} &3{3}",
|
Chat.MessageAll("{0} %Spaid {1} &f{2} &3{3}",
|
||||||
p.ColoredName, who.ColoredName, amount, Server.moneys);
|
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);
|
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.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.SetMoney(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);
|
||||||
|
@ -61,8 +61,7 @@ namespace MCGalaxy.Commands {
|
|||||||
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.SetMoney(ecos.money);
|
||||||
who.OnMoneyChanged();
|
|
||||||
Chat.MessageAll("{0} %Stook &f{2} &3{3} %Sfrom {1}",
|
Chat.MessageAll("{0} %Stook &f{2} &3{3} %Sfrom {1}",
|
||||||
p.ColoredName, who.ColoredName, amount, Server.moneys);
|
p.ColoredName, who.ColoredName, amount, Server.moneys);
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,7 @@ namespace MCGalaxy.Commands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.money -= 10;
|
p.SetMoney(p.money - 10);
|
||||||
p.OnMoneyChanged();
|
|
||||||
Server.zombie.Lottery.Add(p.name);
|
Server.zombie.Lottery.Add(p.name);
|
||||||
if (Server.zombie.CurLevel != null)
|
if (Server.zombie.CurLevel != null)
|
||||||
Server.zombie.CurLevel.ChatLevel(p.ColoredName + " %Sentered the lottery");
|
Server.zombie.CurLevel.ChatLevel(p.ColoredName + " %Sentered the lottery");
|
||||||
|
@ -158,14 +158,8 @@ PRIMARY KEY(player)
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static string GetItemNames(string separator) {
|
public static string GetItemNames(string separator) {
|
||||||
StringBuilder builder = new StringBuilder();
|
string items = Items.Join(x => x.Enabled ? x.ShopName : null, separator);
|
||||||
for (int i = 0; i < Items.Length; i++) {
|
return items.Length == 0 ? "(no enabled items)" : items;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleItem Color { get { return (SimpleItem)Items[0]; } }
|
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) {
|
public static void MakePurchase(Player p, int cost, string item) {
|
||||||
Economy.EcoStats ecos = RetrieveEcoStats(p.name);
|
Economy.EcoStats ecos = RetrieveEcoStats(p.name);
|
||||||
p.money -= cost;
|
p.SetMoney(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 +
|
||||||
|
@ -196,8 +196,7 @@ namespace MCGalaxy.Games {
|
|||||||
infectCombo++;
|
infectCombo++;
|
||||||
if (infectCombo >= 2) {
|
if (infectCombo >= 2) {
|
||||||
pKiller.SendMessage("You gained " + (2 + infectCombo) + " " + Server.moneys);
|
pKiller.SendMessage("You gained " + (2 + infectCombo) + " " + Server.moneys);
|
||||||
pKiller.money += 2 + infectCombo;
|
pKiller.SetMoney(pKiller.money + (2 + infectCombo));
|
||||||
pKiller.OnMoneyChanged();
|
|
||||||
CurLevel.ChatLevel(pKiller.ColoredName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!");
|
CurLevel.ChatLevel(pKiller.ColoredName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!");
|
||||||
}
|
}
|
||||||
if (infectCombo == 10)
|
if (infectCombo == 10)
|
||||||
@ -263,8 +262,7 @@ namespace MCGalaxy.Games {
|
|||||||
if (!pAlive.Game.PledgeSurvive) return;
|
if (!pAlive.Game.PledgeSurvive) return;
|
||||||
pAlive.Game.PledgeSurvive = false;
|
pAlive.Game.PledgeSurvive = false;
|
||||||
CurLevel.ChatLevel(pAlive.ColoredName + "%Sbroke their pledge of not being infected.");
|
CurLevel.ChatLevel(pAlive.ColoredName + "%Sbroke their pledge of not being infected.");
|
||||||
pAlive.money = Math.Max(pAlive.money - 2, 0);
|
pAlive.SetMoney(Math.Max(pAlive.money - 2, 0));
|
||||||
pAlive.OnMoneyChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBounty(Player pAlive, Player pKiller) {
|
void CheckBounty(Player pAlive, Player pKiller) {
|
||||||
@ -274,10 +272,8 @@ namespace MCGalaxy.Games {
|
|||||||
if (bounty != null) {
|
if (bounty != null) {
|
||||||
CurLevel.ChatLevel(pKiller.ColoredName + " %Scollected the bounty of &a" +
|
CurLevel.ChatLevel(pKiller.ColoredName + " %Scollected the bounty of &a" +
|
||||||
bounty.Amount + " %S" + Server.moneys + " on " + pAlive.ColoredName + "%S.");
|
bounty.Amount + " %S" + Server.moneys + " on " + pAlive.ColoredName + "%S.");
|
||||||
bounty.Origin.money = Math.Max(0, bounty.Origin.money - bounty.Amount);
|
bounty.Origin.SetMoney(Math.Max(0, bounty.Origin.money - bounty.Amount));
|
||||||
bounty.Origin.OnMoneyChanged();
|
pKiller.SetMoney(pKiller.money + bounty.Amount);
|
||||||
pKiller.money += bounty.Amount;
|
|
||||||
pKiller.OnMoneyChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,8 +341,7 @@ namespace MCGalaxy.Games {
|
|||||||
if (pl.Game.PledgeSurvive) {
|
if (pl.Game.PledgeSurvive) {
|
||||||
pl.SendMessage("You received &a5 %3" + Server.moneys +
|
pl.SendMessage("You received &a5 %3" + Server.moneys +
|
||||||
"%S for successfully pledging that you would survive.");
|
"%S for successfully pledging that you would survive.");
|
||||||
pl.money += 5;
|
pl.SetMoney(pl.money + 5);
|
||||||
pl.OnMoneyChanged();
|
|
||||||
}
|
}
|
||||||
if (winChance <= 10)
|
if (winChance <= 10)
|
||||||
ZombieAwards.Give(pl, ZombieAwards.lowWinChance, this);
|
ZombieAwards.Give(pl, ZombieAwards.lowWinChance, this);
|
||||||
@ -369,23 +364,22 @@ namespace MCGalaxy.Games {
|
|||||||
foreach (Player pl in online) {
|
foreach (Player pl in online) {
|
||||||
pl.Game.ResetInvisibility();
|
pl.Game.ResetInvisibility();
|
||||||
if (!pl.level.name.CaselessEq(CurLevelName)) continue;
|
if (!pl.level.name.CaselessEq(CurLevelName)) continue;
|
||||||
int money = GetMoney(pl, alive, rand);
|
int reward = GetReward(pl, alive, rand);
|
||||||
|
|
||||||
Entities.GlobalDespawn(pl, true);
|
Entities.GlobalDespawn(pl, true);
|
||||||
Entities.GlobalSpawn(pl, true);
|
Entities.GlobalSpawn(pl, true);
|
||||||
if (money == -1) {
|
if (reward == -1) {
|
||||||
pl.SendMessage("You may not hide inside a block! No " + Server.moneys + " for you."); money = 0;
|
pl.SendMessage("You may not hide inside a block! No " + Server.moneys + " for you."); reward = 0;
|
||||||
} else if (money > 0) {
|
} else if (reward > 0) {
|
||||||
pl.SendMessage( Colors.gold + "You gained " + money + " " + Server.moneys);
|
pl.SendMessage(Colors.gold + "You gained " + reward + " " + Server.moneys);
|
||||||
}
|
}
|
||||||
|
|
||||||
pl.money += money;
|
pl.SetMoney(pl.money + reward);
|
||||||
pl.Game.ResetZombieState();
|
pl.Game.ResetZombieState();
|
||||||
if (pl.Game.Referee) {
|
if (pl.Game.Referee) {
|
||||||
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.SetMoney(pl.money + 1);
|
||||||
}
|
}
|
||||||
pl.OnMoneyChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DoLottery();
|
DoLottery();
|
||||||
@ -420,13 +414,12 @@ namespace MCGalaxy.Games {
|
|||||||
+ amount + " " + Server.moneys);
|
+ amount + " " + Server.moneys);
|
||||||
}
|
}
|
||||||
Lottery.Clear();
|
Lottery.Clear();
|
||||||
winner.money += 10;
|
winner.SetMoney(winner.money + 10);
|
||||||
winner.OnMoneyChanged();
|
|
||||||
if (online.Count == 7)
|
if (online.Count == 7)
|
||||||
ZombieAwards.Give(winner, ZombieAwards.luckyNumber7, this);
|
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 (pl.CheckIfInsideBlock()) return -1;
|
||||||
|
|
||||||
if (alive.Length == 0) {
|
if (alive.Length == 0) {
|
||||||
|
@ -292,5 +292,10 @@ namespace MCGalaxy {
|
|||||||
public bool verifiedName;
|
public bool verifiedName;
|
||||||
|
|
||||||
public static bool IsSuper(Player p) { return p == null || p.ircNick != null; }
|
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