mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-08 22:59:29 -04:00
Add a zombie invisibility item, also make it so custom command aliases override core command aliases.
This commit is contained in:
parent
57abf03099
commit
e705ef6d50
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
if (p.money < Price * count) {
|
||||
Player.Message(p, "&cYou don't have enough &3{2} &cto buy {1} {0}.",
|
||||
Name, count * 10, Server.moneys); return;
|
||||
Player.Message(p, "&cYou don't have enough &3{2} &cto buy {1} {0}.",
|
||||
Name, count * 10, Server.moneys); return;
|
||||
}
|
||||
|
||||
p.Game.BlocksLeft += 10 * count;
|
||||
@ -48,7 +48,7 @@ namespace MCGalaxy.Eco {
|
||||
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, "Costs &f{0} * [num] &3{1}", Price, Server.moneys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class QueueLevelItem : SimpleItem {
|
||||
@ -86,13 +86,13 @@ namespace MCGalaxy.Eco {
|
||||
string text = message.SplitSpaces(2)[1]; // keep spaces this way
|
||||
bool hasAToken = false;
|
||||
for (int i = 0; i < text.Length; i++) {
|
||||
if (!CheckEscape(text, i, ref hasAToken)) {
|
||||
Player.Message(p, "You can only use {0} and {1} for tokens in infect messages."); return;
|
||||
if (!CheckEscape(text, i, ref hasAToken)) {
|
||||
Player.Message(p, "You can only use {0} and {1} for tokens in infect messages."); return;
|
||||
}
|
||||
}
|
||||
if (!hasAToken) {
|
||||
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);
|
||||
@ -111,54 +111,80 @@ namespace MCGalaxy.Eco {
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class InvisibilityItem : SimpleItem {
|
||||
public abstract class InvisibilityItem : SimpleItem {
|
||||
|
||||
public InvisibilityItem() {
|
||||
Aliases = new[] { "invisibility", "invisible", "invis" };
|
||||
Price = 3;
|
||||
}
|
||||
protected abstract int MaxPotions { get; }
|
||||
protected abstract int Duration { get; }
|
||||
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) {
|
||||
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.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 (p.Game.InvisibilityPotions >= ZombieGame.InvisibilityPotions) {
|
||||
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;
|
||||
"when a round of zombie survival is in progress."); return;
|
||||
}
|
||||
|
||||
DateTime end = Server.zombie.RoundEnd;
|
||||
if (DateTime.UtcNow.AddSeconds(60) > end) {
|
||||
Player.Message(p, "You cannot buy an invisibility potion " +
|
||||
"during the last minute of a round."); return;
|
||||
}
|
||||
int duration = ZombieGame.InvisibilityDuration;
|
||||
"during the last minute of a round."); return;
|
||||
}
|
||||
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; } }
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
DateTime end = p.Game.InvisibilityEnd;
|
||||
|
||||
if (now >= end) {
|
||||
p.SendCpeMessage(CpeMessageType.BottomRight2, "", false);
|
||||
p.Game.ResetInvisibility();
|
||||
Entities.GlobalSpawn(p, false);
|
||||
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) { ResetInvisibility(p); continue; }
|
||||
|
||||
int left = (int)Math.Ceiling((end - now).TotalSeconds);
|
||||
if (left == p.Game.InvisibilityTime) continue;
|
||||
|
@ -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)]
|
||||
|
@ -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,12 +114,20 @@ namespace MCGalaxy.Games {
|
||||
if (!RoundInProgress || p == null) return;
|
||||
Infected.Remove(p);
|
||||
Alive.Add(p);
|
||||
ResetInvisibility(p);
|
||||
|
||||
p.Game.Infected = false;
|
||||
UpdatePlayerColor(p, p.color);
|
||||
UpdateAllPlayerStatus();
|
||||
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;
|
||||
@ -168,12 +171,8 @@ 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);
|
||||
}
|
||||
pl.Game.ResetZombieState();
|
||||
ResetInvisibility(pl);
|
||||
pl.SetPrefix();
|
||||
|
||||
if (pl.level == null || !pl.level.name.CaselessEq(CurLevelName))
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user