Add custom infection messages to zombie survival, also fix /rp rainbow 2+ not working when the block is not a wool to start with.

This commit is contained in:
UnknownShadow200 2016-03-28 08:38:09 +11:00
parent f227631255
commit daa003db1e
11 changed files with 98 additions and 28 deletions

View File

@ -133,7 +133,7 @@ namespace MCGalaxy.Commands
SetBool(p, lvl, ref lvl.leafDecay, "Leaf deacy: "); break;
case "flow":
case "randomflow":
SetBool(p, lvl, ref lvl.randomFlow, "Ranbow flow: "); break;
SetBool(p, lvl, ref lvl.randomFlow, "Random flow: "); break;
case "tree":
case "growtrees":
SetBool(p, lvl, ref lvl.growTrees, "Tree growing: "); break;

View File

@ -55,11 +55,23 @@ namespace MCGalaxy {
}
public static void SetLoginMessage(string name, string value) {
CP437Writer.WriteAllText("text/login/" + name.ToLower() + ".txt", value);
CP437Writer.WriteAllText("text/login/" + name.ToLower() + ".txt", value);
}
public static void SetLogoutMessage(string name, string value) {
CP437Writer.WriteAllText("text/logout/" + name.ToLower() + ".txt", value);
CP437Writer.WriteAllText("text/logout/" + name.ToLower() + ".txt", value);
}
public static List<string> GetInfectMessages(Player p) {
if (p.name == null || !Directory.Exists("text/infect")) return null;
string path = "text/infect/" + p.name.ToLower() + ".txt";
return File.Exists(path) ? CP437Reader.ReadAllLines(path) : null;
}
public static void AppendInfectMessage(string name, string value) {
if (!Directory.Exists("text/infect"))
Directory.CreateDirectory("text/infect");
CP437Writer.AppendLine("text/infect/" + name.ToLower() + ".txt", value);
}
}
}

View File

@ -150,7 +150,7 @@ namespace MCGalaxy {
public static Item[] Items = { new ColorItem(), new TitleColorItem(),
new TitleItem(), new RankItem(), new LevelItem(), new LoginMessageItem(),
new LogoutMessageItem(), new BlocksItem(), new QueueLevelItem() };
new LogoutMessageItem(), new BlocksItem(), new QueueLevelItem(), new InfectMessageItem() };
public static Item GetItem(string name) {
foreach (Item item in Items) {

View File

@ -82,23 +82,23 @@ namespace MCGalaxy.Eco {
writer.WriteLine(Name + ":price:" + Price);
}
protected internal override void OnBuyCommand(Command cmd, Player p,
protected internal override void OnBuyCommand(Command cmd, Player p,
string message, string[] args) {
if (NoArgsResetsItem && args.Length == 1) {
OnBuyCommand(p, message, args); return;
}
// Must always provide an argument.
if (args.Length < 2) { cmd.Help(p); return; }
if (NoArgsResetsItem && args.Length == 1) {
OnBuyCommand(p, message, args); return;
}
// Must always provide an argument.
if (args.Length < 2) { cmd.Help(p); return; }
if (p.money < Price) {
Player.SendMessage(p, "%cYou don't have enough %3" + Server.moneys + "%c to buy a " + Name + "."); return;
}
OnBuyCommand(p, message, args);
}
OnBuyCommand(p, message, args);
}
protected abstract void OnBuyCommand(Player p, string message, string[] args);
protected abstract void OnBuyCommand(Player p, string message, string[] args);
protected internal override void OnSetupCommand(Player p, string[] args) {
switch (args[1].ToLower()) {
switch (args[1].ToLower()) {
case "enable":
Player.SendMessage(p, "%a" + Name + "s are now enabled for the economy system.");
Enabled = true; break;
@ -118,7 +118,8 @@ namespace MCGalaxy.Eco {
}
protected internal override void OnStoreCommand(Player p) {
Player.SendMessage(p, Name + "s cost %f" + Price + " %3" + Server.moneys + " %Seach");
string plural = Name[Name.Length - 1] == 's' ? Name : Name + "s";
Player.SendMessage(p, plural + " cost %f" + Price + " %3" + Server.moneys + " %Seach");
}
}
}

View File

@ -123,10 +123,9 @@ namespace MCGalaxy.Eco {
Group maxrank = Group.Find(MaxRank);
Player.SendMessage(p, "%fThe maximum buyable rank is: " + maxrank.color + maxrank.name);
Player.SendMessage(p, "%cRanks purchased will be bought in order.");
Player.SendMessage(p, "%fRanks cost:");
foreach (Rank rnk in RanksList) {
Player.SendMessage(p, rnk.group.color + rnk.group.name + ": %f" + rnk.price + " %3" + Server.moneys);
Player.SendMessage(p, rnk.group.color + rnk.group.name + " costs&f" + rnk.price + " &3" + Server.moneys);
if (rnk.group.name.CaselessEq(maxrank.name)) break;
}
}

View File

@ -16,6 +16,7 @@
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
namespace MCGalaxy.Eco {
@ -64,4 +65,43 @@ namespace MCGalaxy.Eco {
MakePurchase(p, Price, "%3QueueLevel: " + message);
}
}
public sealed class InfectMessageItem : SimpleItem {
public InfectMessageItem() {
Aliases = new[] { "infectmessage", "infectmsg" };
Price = 150;
}
public override string Name { get { return "InfectMessage"; } }
static char[] trimChars = { ' ' };
protected override void OnBuyCommand(Player p, string message, string[] args) {
string text = message.Split(trimChars, 2)[1]; // keep spaces this way
bool hasAToken = false;
for (int i = 0; i < text.Length; i++) {
if (!CheckEscape(text, i, ref hasAToken)) {
Player.SendMessage(p, "You can only use {0} and {1} for tokens in infect messages."); return;
}
}
if (!hasAToken) {
Player.SendMessage(p, "You need to include a \"{0}\" (placeholder for zombie player) " +
"and/or a \"{1}\" (placeholder for human player) in the infect message."); return;
}
PlayerDB.AppendInfectMessage(p.name, text);
if (p.infectMessages == null) p.infectMessages = new List<string>();
p.infectMessages.Add(text);
Player.SendMessage(p, "%aAdded infect message: %f" + text);
MakePurchase(p, Price, "%3InfectMessage: " + message);
}
static bool CheckEscape(string text, int i, ref bool hasAToken) {
// Only {0} and {1} are allowed in infect messages for the Format() call
if (text[i] != '{') return true;
hasAToken = true;
if ((i + 2) >= text.Length) return false;
return (text[i + 1] == '0' || text[i + 1] == '1') && text[i + 2] == '}';
}
}
}

View File

@ -186,11 +186,7 @@ namespace MCGalaxy.Games {
lastPlayerToInfect = pKiller.name;
pKiller.playersInfected++;
CurLevel.ChatLevel(String.Format(
messages[random.Next(messages.Length)],
Colors.red + pKiller.DisplayName + Colors.yellow,
Colors.red + pAlive.DisplayName + Colors.yellow));
ShowInfectMessage(random, pAlive, pKiller);
CheckHumanPledge(pAlive);
CheckBounty(pAlive, pKiller);
UpdatePlayerColor(pAlive, InfectCol);
@ -210,6 +206,19 @@ namespace MCGalaxy.Games {
pAlive.OnMoneyChanged();
}
void ShowInfectMessage(Random random, Player pAlive, Player pKiller) {
string text = null;
List<string> infectMsgs = pKiller.infectMessages;
if (infectMsgs != null && random.Next(0, 10) < 5)
text = infectMsgs[random.Next(infectMsgs.Count)];
else
text = messages[random.Next(messages.Length)];
CurLevel.ChatLevel(String.Format(text,
Colors.red + pKiller.DisplayName + Colors.yellow,
Colors.red + pAlive.DisplayName + Colors.yellow));
}
void CheckBounty(Player pAlive, Player pKiller) {
BountyData bounty;
if (Bounties.TryGetValue(pAlive.name, out bounty))

View File

@ -179,7 +179,7 @@ namespace MCGalaxy.BlockPhysics {
if (rainbownum > 2) {
byte block = lvl.blocks[C.b];
if (block < Block.red || block > Block.darkpink) {
lvl.AddUpdate(C.b, Block.red, true);
lvl.AddUpdate(C.b, Block.red, true, C.data);
} else {
byte next = block == Block.darkpink ? Block.red : (byte)(block + 1);
lvl.AddUpdate(C.b, next);

View File

@ -532,6 +532,7 @@ namespace MCGalaxy {
}
Server.s.Log(name + " [" + ip + "] has joined the server.");
infectMessages = PlayerDB.GetInfectMessages(this);
Server.zombie.PlayerJoinedServer(this);
try {
ushort x = (ushort)((0.5 + level.spawnx) * 32);

View File

@ -188,17 +188,18 @@ namespace MCGalaxy {
//Zombie
public bool referee = false;
public int blockCount = 50;
internal int blockCount = 50;
public bool voted = false;
public int blocksStacked = 0;
public int lastYblock = 0, lastXblock = 0, lastZblock = 0;
internal int blocksStacked = 0;
internal int lastYblock = 0, lastXblock = 0, lastZblock = 0;
public bool infected = false;
public bool aka = false;
public bool flipHead = false;
public int playersInfected = 0;
internal int playersInfected = 0;
internal string lastSpawnColor = "";
internal bool ratedMap = false;
internal bool pledgeSurvive = false;
internal List<string> infectMessages = null;
//Tnt Wars
public bool PlayingTntWars = false;

View File

@ -63,6 +63,13 @@ namespace MCGalaxy {
writer.Write(text);
}
public static void AppendLine(string file, string text) {
using (CP437Writer writer = new CP437Writer(file, true)) {
writer.Write(text);
writer.WriteLine();
}
}
public static string ConvertToUnicode(string text) {
if (text == null) return null;
if (text.Length == 0) return "";