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(),
new TitleItem(), new RankItem(), new LevelItem(), new LoginMessageItem(),
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) {
foreach (Item item in Items) {

View File

@ -111,26 +111,28 @@ namespace MCGalaxy.Eco {
}
}
public sealed class InvisibilityItem : SimpleItem {
public abstract class InvisibilityItem : SimpleItem {
public InvisibilityItem() {
Aliases = new[] { "invisibility", "invisible", "invis" };
Price = 3;
}
public override string Name { get { return "Invisibility"; } }
protected abstract int MaxPotions { get; }
protected abstract int Duration { get; }
protected abstract bool ForHumans { get; }
protected internal override void OnBuyCommand(Command cmd, Player p,
string message, string[] args) {
if (p.money < Price) {
Player.Message(p, "%cYou don't have enough &3{1} &c to buy a {0}.", Name, Server.moneys); return;
}
if (p.Game.Invisible) {
Player.Message(p, "You are already invisible."); return;
}
if (p.Game.InvisibilityPotions >= ZombieGame.InvisibilityPotions) {
if (p.Game.Invisible) { 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 (ForHumans && p.Game.Infected) {
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) {
Player.Message(p, "You can only buy an invisiblity potion " +
"when a round of zombie survival is in progress."); return;
@ -141,24 +143,48 @@ namespace MCGalaxy.Eco {
Player.Message(p, "You cannot buy an invisibility potion " +
"during the last minute of a round."); return;
}
int duration = ZombieGame.InvisibilityDuration;
p.Game.Invisible = true;
p.Game.InvisibilityEnd = DateTime.UtcNow.AddSeconds(duration);
p.Game.InvisibilityEnd = DateTime.UtcNow.AddSeconds(Duration);
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*");
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 internal override void OnStoreCommand(Player 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.")]
[Category("Human settings")]
[DisplayName("Invisibility durations")]
[DisplayName("Invisibility duration")]
public int InvisibilityDuration { get; set; }
[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")]
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.")]
[Category("Revive settings")]
@ -179,6 +189,8 @@ namespace MCGalaxy.Gui {
Model = ZombieGame.ZombieModel;
InvisibilityDuration = ZombieGame.InvisibilityDuration;
InvisibilityPotions = ZombieGame.InvisibilityPotions;
ZInvisibilityDuration = ZombieGame.ZombieInvisibilityDuration;
ZInvisibilityPotions = ZombieGame.ZombieInvisibilityPotions;
Chance = ZombieGame.ReviveChance;
InsufficientTime = ZombieGame.ReviveNoTime;
@ -217,6 +229,8 @@ namespace MCGalaxy.Gui {
ZombieGame.ZombieModel = "zombie";
ZombieGame.InvisibilityDuration = InvisibilityDuration;
ZombieGame.InvisibilityPotions = InvisibilityPotions;
ZombieGame.ZombieInvisibilityDuration = ZInvisibilityDuration;
ZombieGame.ZombieInvisibilityPotions = ZInvisibilityPotions;
ZombieGame.ReviveChance = Chance;
ZombieGame.ReviveNoTime = InsufficientTime;

View File

@ -43,7 +43,7 @@ namespace MCGalaxy.Games {
public bool Referee = false;
/// <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>
internal int BlocksStacked = 0;

View File

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

View File

@ -123,6 +123,10 @@ namespace MCGalaxy.Games {
public static int InvisibilityDuration = 7;
[ConfigInt("zombie-invisibility-potions", "Zombie", null, 7, 1)]
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)]
public static bool ChangeLevels = true;
[ConfigBool("zombie-awards", "Zombie", null, false)]

View File

@ -97,12 +97,7 @@ namespace MCGalaxy.Games {
Alive.Remove(p);
p.Game.CurrentRoundsSurvived = 0;
p.SetPrefix();
if (p.Game.Invisible) {
p.SendCpeMessage(CpeMessageType.BottomRight2, "", false);
Entities.GlobalSpawn(p, false);
p.Game.ResetInvisibility();
}
ResetInvisibility(p);
int delta = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds;
if (delta >= 0 && delta <= 5)
@ -119,6 +114,7 @@ namespace MCGalaxy.Games {
if (!RoundInProgress || p == null) return;
Infected.Remove(p);
Alive.Add(p);
ResetInvisibility(p);
p.Game.Infected = false;
UpdatePlayerColor(p, p.color);
@ -126,6 +122,13 @@ namespace MCGalaxy.Games {
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) {
Player[] online = PlayerInfo.Online.Items;
if (CurLevel != null) {
@ -169,11 +172,7 @@ namespace MCGalaxy.Games {
foreach (Player pl in online) {
pl.Game.Referee = false;
pl.Game.ResetZombieState();
if (pl.Game.Invisible) {
pl.Game.ResetInvisibility();
Entities.GlobalSpawn(pl, false);
}
ResetInvisibility(pl);
pl.SetPrefix();
if (pl.level == null || !pl.level.name.CaselessEq(CurLevelName))

View File

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