Add a zombie invisibility item, also make it so custom command aliases override core command aliases.

This commit is contained in:
UnknownShadow200 2016-08-28 23:15:01 +10:00
parent 57abf03099
commit e705ef6d50
8 changed files with 98 additions and 59 deletions

View File

@ -148,7 +148,8 @@ PRIMARY KEY(player)
public static Item[] Items = { new ColorItem(), new TitleColorItem(), public static Item[] Items = { new ColorItem(), new TitleColorItem(),
new TitleItem(), new RankItem(), new LevelItem(), new LoginMessageItem(), new TitleItem(), new RankItem(), new LevelItem(), new LoginMessageItem(),
new LogoutMessageItem(), new BlocksItem(), new QueueLevelItem(), new LogoutMessageItem(), new BlocksItem(), new QueueLevelItem(),
new InfectMessageItem(), new NickItem(), new InvisibilityItem(), new ReviveItem() }; new InfectMessageItem(), new NickItem(), new ReviveItem(),
new HumanInvisibilityItem(), new ZombieInvisibilityItem() };
public static Item GetItem(string name) { public static Item GetItem(string name) {
foreach (Item item in Items) { foreach (Item item in Items) {

View File

@ -36,8 +36,8 @@ namespace MCGalaxy.Eco {
Player.Message(p, "Number of groups of 10 blocks to buy must be an integer between 1 and 10."); return; Player.Message(p, "Number of groups of 10 blocks to buy must be an integer between 1 and 10."); return;
} }
if (p.money < Price * count) { if (p.money < Price * count) {
Player.Message(p, "&cYou don't have enough &3{2} &cto buy {1} {0}.", Player.Message(p, "&cYou don't have enough &3{2} &cto buy {1} {0}.",
Name, count * 10, Server.moneys); return; Name, count * 10, Server.moneys); return;
} }
p.Game.BlocksLeft += 10 * count; p.Game.BlocksLeft += 10 * count;
@ -48,7 +48,7 @@ namespace MCGalaxy.Eco {
Player.Message(p, "Syntax: %T/buy 10blocks [num]"); Player.Message(p, "Syntax: %T/buy 10blocks [num]");
Player.Message(p, "Increases the blocks you are able to place by 10 * [num]."); Player.Message(p, "Increases the blocks you are able to place by 10 * [num].");
Player.Message(p, "Costs &f{0} * [num] &3{1}", Price, Server.moneys); Player.Message(p, "Costs &f{0} * [num] &3{1}", Price, Server.moneys);
} }
} }
public sealed class QueueLevelItem : SimpleItem { public sealed class QueueLevelItem : SimpleItem {
@ -86,13 +86,13 @@ namespace MCGalaxy.Eco {
string text = message.SplitSpaces(2)[1]; // keep spaces this way string text = message.SplitSpaces(2)[1]; // keep spaces this way
bool hasAToken = false; bool hasAToken = false;
for (int i = 0; i < text.Length; i++) { for (int i = 0; i < text.Length; i++) {
if (!CheckEscape(text, i, ref hasAToken)) { if (!CheckEscape(text, i, ref hasAToken)) {
Player.Message(p, "You can only use {0} and {1} for tokens in infect messages."); return; Player.Message(p, "You can only use {0} and {1} for tokens in infect messages."); return;
} }
} }
if (!hasAToken) { if (!hasAToken) {
Player.Message(p, "You need to include a \"{0}\" (placeholder for zombie player) " + Player.Message(p, "You need to include a \"{0}\" (placeholder for zombie player) " +
"and/or a \"{1}\" (placeholder for human player) in the infect message."); return; "and/or a \"{1}\" (placeholder for human player) in the infect message."); return;
} }
PlayerDB.AppendInfectMessage(p.name, text); PlayerDB.AppendInfectMessage(p.name, text);
@ -111,54 +111,80 @@ namespace MCGalaxy.Eco {
} }
} }
public sealed class InvisibilityItem : SimpleItem { public abstract class InvisibilityItem : SimpleItem {
public InvisibilityItem() { protected abstract int MaxPotions { get; }
Aliases = new[] { "invisibility", "invisible", "invis" }; protected abstract int Duration { get; }
Price = 3; protected abstract bool ForHumans { get; }
}
public override string Name { get { return "Invisibility"; } } protected internal override void OnBuyCommand(Command cmd, Player p,
string message, string[] args) {
protected internal override void OnBuyCommand(Command cmd, Player p,
string message, string[] args) {
if (p.money < Price) { if (p.money < Price) {
Player.Message(p, "%cYou don't have enough &3{1} &c to buy a {0}.", Name, Server.moneys); return; Player.Message(p, "%cYou don't have enough &3{1} &c to buy a {0}.", Name, Server.moneys); return;
} }
if (p.Game.Invisible) { if (p.Game.Invisible) { Player.Message(p, "You are already invisible."); return; }
Player.Message(p, "You are already invisible."); return; if (p.Game.InvisibilityPotions >= MaxPotions) {
Player.Message(p, "You cannot buy any more invisibility potions this round."); return;
} }
if (p.Game.InvisibilityPotions >= ZombieGame.InvisibilityPotions) { if (ForHumans && p.Game.Infected) {
Player.Message(p, "You cannot buy any more invisibility potions this round."); return; Player.Message(p, "Use %T/buy zinvisibility %Sfor buying invisibility when you are a zombie."); return;
} }
if (!ForHumans && !p.Game.Infected) {
Player.Message(p, "Use %T/buy invisibility %Sfor buying invisibility when you are a human."); return;
}
if (!Server.zombie.Running || !Server.zombie.RoundInProgress) { if (!Server.zombie.Running || !Server.zombie.RoundInProgress) {
Player.Message(p, "You can only buy an invisiblity potion " + Player.Message(p, "You can only buy an invisiblity potion " +
"when a round of zombie survival is in progress."); return; "when a round of zombie survival is in progress."); return;
} }
DateTime end = Server.zombie.RoundEnd; DateTime end = Server.zombie.RoundEnd;
if (DateTime.UtcNow.AddSeconds(60) > end) { if (DateTime.UtcNow.AddSeconds(60) > end) {
Player.Message(p, "You cannot buy an invisibility potion " + Player.Message(p, "You cannot buy an invisibility potion " +
"during the last minute of a round."); return; "during the last minute of a round."); return;
} }
int duration = ZombieGame.InvisibilityDuration;
p.Game.Invisible = true; p.Game.Invisible = true;
p.Game.InvisibilityEnd = DateTime.UtcNow.AddSeconds(duration); p.Game.InvisibilityEnd = DateTime.UtcNow.AddSeconds(Duration);
p.Game.InvisibilityPotions++; p.Game.InvisibilityPotions++;
int left = ZombieGame.InvisibilityPotions - p.Game.InvisibilityPotions; int left = MaxPotions - p.Game.InvisibilityPotions;
Player.Message(p, "Lasts for &a{0} %Sseconds. You can buy &a{1} %Smore this round.", duration, left); Player.Message(p, "Lasts for &a{0} %Sseconds. You can buy &a{1} %Smore this round.", Duration, left);
Server.zombie.CurLevel.ChatLevel(p.ColoredName + " %Svanished. &a*POOF*"); Server.zombie.CurLevel.ChatLevel(p.ColoredName + " %Svanished. &a*POOF*");
Entities.GlobalDespawn(p, false); Entities.GlobalDespawn(p, false);
Economy.MakePurchase(p, Price, "%3Invisibility: " + duration); Economy.MakePurchase(p, Price, "%3Invisibility: " + Duration);
} }
protected override void OnBuyCommand(Player p, string message, string[] args) { } protected override void OnBuyCommand(Player p, string message, string[] args) { }
protected internal override void OnStoreCommand(Player p) { protected internal override void OnStoreCommand(Player p) {
base.OnStoreCommand(p); base.OnStoreCommand(p);
int duration = ZombieGame.InvisibilityDuration; Player.Message(p, "%HLasts for " + Duration + " seconds before you reappear.");
Player.Message(p, "%HLasts for " + duration + " seconds before you reappear.");
} }
} }
public sealed class HumanInvisibilityItem : InvisibilityItem {
public HumanInvisibilityItem() {
Aliases = new[] { "invisibility", "invisible", "invis" };
Price = 3;
}
public override string Name { get { return "Invisibility"; } }
protected override int MaxPotions { get { return ZombieGame.InvisibilityPotions; } }
protected override int Duration { get { return ZombieGame.InvisibilityDuration; } }
protected override bool ForHumans { get { return true; } }
}
public sealed class ZombieInvisibilityItem : InvisibilityItem {
public ZombieInvisibilityItem() {
Aliases = new[] { "zinvisibility", "zinvisible", "zinvis" };
Price = 3;
}
public override string Name { get { return "ZombieInvisibility"; } }
protected override int MaxPotions { get { return ZombieGame.ZombieInvisibilityPotions; } }
protected override int Duration { get { return ZombieGame.ZombieInvisibilityDuration; } }
protected override bool ForHumans { get { return false; } }
}
} }

View File

@ -114,7 +114,7 @@ namespace MCGalaxy.Gui {
[Description("How many seconds an invisibility potion bought using /buy invisibility lasts.")] [Description("How many seconds an invisibility potion bought using /buy invisibility lasts.")]
[Category("Human settings")] [Category("Human settings")]
[DisplayName("Invisibility durations")] [DisplayName("Invisibility duration")]
public int InvisibilityDuration { get; set; } public int InvisibilityDuration { get; set; }
[Description("Maximum number of invisibility potions a human is allowed to buy in a round.")] [Description("Maximum number of invisibility potions a human is allowed to buy in a round.")]
@ -122,6 +122,16 @@ namespace MCGalaxy.Gui {
[DisplayName("Invisibility potions")] [DisplayName("Invisibility potions")]
public int InvisibilityPotions { get; set; } public int InvisibilityPotions { get; set; }
[Description("How many seconds an invisibility potion bought using /buy zinvisibility lasts.")]
[Category("Zombie settings")]
[DisplayName("Invisibility duration")]
public int ZInvisibilityDuration { get; set; }
[Description("Maximum number of invisibility potions a zombie is allowed to buy in a round.")]
[Category("Zombie settings")]
[DisplayName("Invisibility potions")]
public int ZInvisibilityPotions { get; set; }
[Description("The percentage chance that a revive potion will actually disinfect a zombie.")] [Description("The percentage chance that a revive potion will actually disinfect a zombie.")]
[Category("Revive settings")] [Category("Revive settings")]
@ -179,6 +189,8 @@ namespace MCGalaxy.Gui {
Model = ZombieGame.ZombieModel; Model = ZombieGame.ZombieModel;
InvisibilityDuration = ZombieGame.InvisibilityDuration; InvisibilityDuration = ZombieGame.InvisibilityDuration;
InvisibilityPotions = ZombieGame.InvisibilityPotions; InvisibilityPotions = ZombieGame.InvisibilityPotions;
ZInvisibilityDuration = ZombieGame.ZombieInvisibilityDuration;
ZInvisibilityPotions = ZombieGame.ZombieInvisibilityPotions;
Chance = ZombieGame.ReviveChance; Chance = ZombieGame.ReviveChance;
InsufficientTime = ZombieGame.ReviveNoTime; InsufficientTime = ZombieGame.ReviveNoTime;
@ -217,6 +229,8 @@ namespace MCGalaxy.Gui {
ZombieGame.ZombieModel = "zombie"; ZombieGame.ZombieModel = "zombie";
ZombieGame.InvisibilityDuration = InvisibilityDuration; ZombieGame.InvisibilityDuration = InvisibilityDuration;
ZombieGame.InvisibilityPotions = InvisibilityPotions; ZombieGame.InvisibilityPotions = InvisibilityPotions;
ZombieGame.ZombieInvisibilityDuration = ZInvisibilityDuration;
ZombieGame.ZombieInvisibilityPotions = ZInvisibilityPotions;
ZombieGame.ReviveChance = Chance; ZombieGame.ReviveChance = Chance;
ZombieGame.ReviveNoTime = InsufficientTime; ZombieGame.ReviveNoTime = InsufficientTime;

View File

@ -43,7 +43,7 @@ namespace MCGalaxy.Games {
public bool Referee = false; public bool Referee = false;
/// <summary> Remaining number of blocks the player can place this round. </summary> /// <summary> Remaining number of blocks the player can place this round. </summary>
internal int BlocksLeft = 50; public int BlocksLeft = 50;
/// <summary> Number of blocks the player has sequentially pillared up. </summary> /// <summary> Number of blocks the player has sequentially pillared up. </summary>
internal int BlocksStacked = 0; internal int BlocksStacked = 0;

View File

@ -218,7 +218,7 @@ namespace MCGalaxy.Games {
if (aliveChanged) alive = Alive.Items; if (aliveChanged) alive = Alive.Items;
} }
CheckInvisibilityTime(Alive.Items); CheckInvisibilityTime();
Thread.Sleep(25); Thread.Sleep(25);
} }
} }
@ -233,18 +233,13 @@ namespace MCGalaxy.Games {
} }
} }
void CheckInvisibilityTime(Player[] alive) { void CheckInvisibilityTime() {
DateTime now = DateTime.UtcNow; DateTime now = DateTime.UtcNow;
foreach (Player p in alive) { Player[] players = PlayerInfo.Online.Items;
if (!p.Game.Invisible) continue; foreach (Player p in players) {
DateTime end = p.Game.InvisibilityEnd; if (!p.Game.Invisible || p.level != CurLevel) continue;
DateTime end = p.Game.InvisibilityEnd;
if (now >= end) { if (now >= end) { ResetInvisibility(p); continue; }
p.SendCpeMessage(CpeMessageType.BottomRight2, "", false);
p.Game.ResetInvisibility();
Entities.GlobalSpawn(p, false);
continue;
}
int left = (int)Math.Ceiling((end - now).TotalSeconds); int left = (int)Math.Ceiling((end - now).TotalSeconds);
if (left == p.Game.InvisibilityTime) continue; if (left == p.Game.InvisibilityTime) continue;

View File

@ -123,6 +123,10 @@ namespace MCGalaxy.Games {
public static int InvisibilityDuration = 7; public static int InvisibilityDuration = 7;
[ConfigInt("zombie-invisibility-potions", "Zombie", null, 7, 1)] [ConfigInt("zombie-invisibility-potions", "Zombie", null, 7, 1)]
public static int InvisibilityPotions = 7; public static int InvisibilityPotions = 7;
[ConfigInt("zombie-zinvisibility-duration", "Zombie", null, 5, 1)]
public static int ZombieInvisibilityDuration = 5;
[ConfigInt("zombie-zinvisibility-potions", "Zombie", null, 4, 1)]
public static int ZombieInvisibilityPotions = 4;
[ConfigBool("enable-changing-levels", "Zombie", null, true)] [ConfigBool("enable-changing-levels", "Zombie", null, true)]
public static bool ChangeLevels = true; public static bool ChangeLevels = true;
[ConfigBool("zombie-awards", "Zombie", null, false)] [ConfigBool("zombie-awards", "Zombie", null, false)]

View File

@ -97,12 +97,7 @@ namespace MCGalaxy.Games {
Alive.Remove(p); Alive.Remove(p);
p.Game.CurrentRoundsSurvived = 0; p.Game.CurrentRoundsSurvived = 0;
p.SetPrefix(); p.SetPrefix();
ResetInvisibility(p);
if (p.Game.Invisible) {
p.SendCpeMessage(CpeMessageType.BottomRight2, "", false);
Entities.GlobalSpawn(p, false);
p.Game.ResetInvisibility();
}
int delta = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds; int delta = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds;
if (delta >= 0 && delta <= 5) if (delta >= 0 && delta <= 5)
@ -119,12 +114,20 @@ namespace MCGalaxy.Games {
if (!RoundInProgress || p == null) return; if (!RoundInProgress || p == null) return;
Infected.Remove(p); Infected.Remove(p);
Alive.Add(p); Alive.Add(p);
ResetInvisibility(p);
p.Game.Infected = false; p.Game.Infected = false;
UpdatePlayerColor(p, p.color); UpdatePlayerColor(p, p.color);
UpdateAllPlayerStatus(); UpdateAllPlayerStatus();
PlayerMoneyChanged(p); PlayerMoneyChanged(p);
} }
void ResetInvisibility(Player p) {
if (!p.Game.Invisible) return;
p.SendCpeMessage(CpeMessageType.BottomRight2, "", false);
p.Game.ResetInvisibility();
Entities.GlobalSpawn(p, false);
}
void ChangeLevel(string next) { void ChangeLevel(string next) {
Player[] online = PlayerInfo.Online.Items; Player[] online = PlayerInfo.Online.Items;
@ -168,12 +171,8 @@ namespace MCGalaxy.Games {
foreach (Player pl in online) { foreach (Player pl in online) {
pl.Game.Referee = false; pl.Game.Referee = false;
pl.Game.ResetZombieState(); pl.Game.ResetZombieState();
ResetInvisibility(pl);
if (pl.Game.Invisible) {
pl.Game.ResetInvisibility();
Entities.GlobalSpawn(pl, false);
}
pl.SetPrefix(); pl.SetPrefix();
if (pl.level == null || !pl.level.name.CaselessEq(CurLevelName)) if (pl.level == null || !pl.level.name.CaselessEq(CurLevelName))

View File

@ -75,10 +75,10 @@ namespace MCGalaxy {
} }
public static Alias Find(string cmd) { public static Alias Find(string cmd) {
foreach (Alias alias in coreAliases) { foreach (Alias alias in aliases) {
if (alias.Trigger == cmd) return alias; if (alias.Trigger == cmd) return alias;
} }
foreach (Alias alias in aliases) { foreach (Alias alias in coreAliases) {
if (alias.Trigger == cmd) return alias; if (alias.Trigger == cmd) return alias;
} }
return null; return null;