From 1ee3a739b37cd9d484d72d1de472516edf21a2b9 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 15 Sep 2017 12:45:23 +1000 Subject: [PATCH] Add custom kill/death messages for bots. --- MCGalaxy/Blocks/Block.CoreProps.cs | 1 - MCGalaxy/Bots/BotsFile.cs | 7 ++-- .../Bots/Instructions/HunterInstructions.cs | 4 ++- MCGalaxy/Bots/PlayerBot.cs | 1 + MCGalaxy/Commands/Bots/CmdBot.cs | 33 +++++++++++++++---- MCGalaxy/Commands/Chat/CmdHug.cs | 2 +- MCGalaxy/Commands/Fun/CmdGun.cs | 4 +-- MCGalaxy/Commands/Fun/CmdMissile.cs | 4 +-- MCGalaxy/Commands/other/CmdKill.cs | 2 +- MCGalaxy/Player/Player.Handlers.cs | 6 ++-- 10 files changed, 43 insertions(+), 21 deletions(-) diff --git a/MCGalaxy/Blocks/Block.CoreProps.cs b/MCGalaxy/Blocks/Block.CoreProps.cs index 622f69d47..2954a863b 100644 --- a/MCGalaxy/Blocks/Block.CoreProps.cs +++ b/MCGalaxy/Blocks/Block.CoreProps.cs @@ -255,7 +255,6 @@ namespace MCGalaxy { SetDeath(Block.StillWater, drowned, false); SetDeath(Block.Lava, drowned, false); SetDeath(Block.StillLava, drowned, false); - SetDeath(Block.Invalid, "@p %Swas &cterminated.", false); } static void SetDeath(byte block, string message, bool collideKill = true) { diff --git a/MCGalaxy/Bots/BotsFile.cs b/MCGalaxy/Bots/BotsFile.cs index 0aa942b2e..0d2a221ef 100644 --- a/MCGalaxy/Bots/BotsFile.cs +++ b/MCGalaxy/Bots/BotsFile.cs @@ -93,6 +93,7 @@ namespace MCGalaxy.Bots { public string Model { get; set; } public string Color { get; set; } public string ClickedOnText { get; set; } + public string DeathMessage { get; set; } public string AI { get; set; } public bool Kill { get; set; } @@ -115,7 +116,7 @@ namespace MCGalaxy.Bots { Kill = bot.kill; Hunt = bot.hunt; DisplayName = bot.DisplayName; CurInstruction = bot.cur; CurJump = bot.curJump; - ClickedOnText = bot.ClickedOnText; + ClickedOnText = bot.ClickedOnText; DeathMessage = bot.DeathMessage; X = bot.Pos.X; Y = bot.Pos.Y; Z = bot.Pos.Z; RotX = bot.Rot.RotY; RotY = bot.Rot.HeadX; @@ -134,7 +135,7 @@ namespace MCGalaxy.Bots { bot.DisplayName = DisplayName; bot.cur = CurInstruction; bot.curJump = CurJump; - bot.ClickedOnText = ClickedOnText; + bot.ClickedOnText = ClickedOnText; bot.DeathMessage = DeathMessage; } public BotProperties Copy() { @@ -145,7 +146,7 @@ namespace MCGalaxy.Bots { copy.AI = AI; copy.Kill = Kill; copy.Hunt = Hunt; copy.CurInstruction = CurInstruction; copy.CurJump = CurJump; - copy.ClickedOnText = ClickedOnText; + copy.ClickedOnText = ClickedOnText; copy.DeathMessage = DeathMessage; copy.X = X; copy.Y = Y; copy.Z = Z; copy.RotX = RotX; copy.RotY = RotY; diff --git a/MCGalaxy/Bots/Instructions/HunterInstructions.cs b/MCGalaxy/Bots/Instructions/HunterInstructions.cs index 6f4e159ec..fda32c0ca 100644 --- a/MCGalaxy/Bots/Instructions/HunterInstructions.cs +++ b/MCGalaxy/Bots/Instructions/HunterInstructions.cs @@ -109,7 +109,9 @@ namespace MCGalaxy.Bots { int dz = Math.Abs(bot.Pos.Z - p.Pos.Z); if (dx <= 8 && dy <= 16 && dz <= 8) { - p.HandleDeath(ExtBlock.Invalid); + string msg = bot.DeathMessage; + if (msg == null) msg = "@p %Swas &cterminated."; + p.HandleDeath((ExtBlock)Block.Cobblestone, msg); } } bot.NextInstruction(); return true; diff --git a/MCGalaxy/Bots/PlayerBot.cs b/MCGalaxy/Bots/PlayerBot.cs index 09f425b83..d423c565f 100644 --- a/MCGalaxy/Bots/PlayerBot.cs +++ b/MCGalaxy/Bots/PlayerBot.cs @@ -31,6 +31,7 @@ namespace MCGalaxy { public string AIName = "", color; public string name, DisplayName; public string ClickedOnText; + public string DeathMessage; public string ColoredName { get { return color + DisplayName; } } public byte id; diff --git a/MCGalaxy/Commands/Bots/CmdBot.cs b/MCGalaxy/Commands/Bots/CmdBot.cs index 4db303179..9d6bf6aba 100644 --- a/MCGalaxy/Commands/Bots/CmdBot.cs +++ b/MCGalaxy/Commands/Bots/CmdBot.cs @@ -42,7 +42,10 @@ namespace MCGalaxy.Commands.Bots { } else if (args[0].CaselessEq("text")) { string text = args.Length > 2 ? args[2] : null; SetBotText(p, args[1], text); - } else { + } else if (args[0].CaselessEq("deathmsg") || args[0].CaselessEq("deathmessage")) { + string text = args.Length > 2 ? args[2] : null; + SetDeathMessage(p, args[1], text); + } else { Help(p); } } @@ -103,16 +106,32 @@ namespace MCGalaxy.Commands.Bots { } BotsFile.Save(bot.level); } - + + void SetDeathMessage(Player p, string botName, string text) { + PlayerBot bot = Matcher.FindBots(p, botName); + if (bot == null) return; + if (!LevelInfo.ValidateAction(p, p.level.name, "set kill message of that bot")) return; + + if (text == null) { + Player.Message(p, "Reset shown when bot {0} %Skills someone", bot.ColoredName); + bot.DeathMessage = null; + } else { + if (!MessageBlock.Validate(p, text, false)) return; + Player.Message(p, "Set message shown when bot {0} %Skills someone to {1}", bot.ColoredName, text); + bot.DeathMessage = text; + } + BotsFile.Save(bot.level); + } + public override void Help(Player p) { - Player.Message(p, "%T/Bot add [name]"); - Player.Message(p, "%HAdds a new bot at your position."); - Player.Message(p, "%T/Bot remove [name]"); - Player.Message(p, "%HRemove a bot on the same level as you"); - Player.Message(p, "%HIf [name] is \"all\", all bots on your map are removed"); + Player.Message(p, "%T/Bot add [name] %H- Adds a new bot at your position"); + Player.Message(p, "%T/Bot remove [name] %H- Removes the bot with that name"); + Player.Message(p, "%H If [name] is \"all\", removes all bots on your map"); Player.Message(p, "%T/Bot text [name] "); Player.Message(p, "%HSets the text shown when a player clicks on this bot"); Player.Message(p, "%HSee %T/help mb %Hfor more details on "); + Player.Message(p, "%T/Bot deathmessage [name] "); + Player.Message(p, "%HSets the message shown when this bot kills a player"); } } } diff --git a/MCGalaxy/Commands/Chat/CmdHug.cs b/MCGalaxy/Commands/Chat/CmdHug.cs index 2340c61d5..915ffe7d2 100644 --- a/MCGalaxy/Commands/Chat/CmdHug.cs +++ b/MCGalaxy/Commands/Chat/CmdHug.cs @@ -43,7 +43,7 @@ namespace MCGalaxy.Commands.Chatting { if (p != null && who.Rank > p.Rank) { MessageTooHighRank(p, "&cdeath-hug%S", true); return; } - who.HandleDeath((ExtBlock)Block.Stone, " died from a %cdeadly hug."); + who.HandleDeath((ExtBlock)Block.Stone, "@p %Sdied from a %cdeadly hug."); } TryMessageAction(p, args[0], "{0} %Sgave {1} %Sa " + hugType + " hug.", false); return; } diff --git a/MCGalaxy/Commands/Fun/CmdGun.cs b/MCGalaxy/Commands/Fun/CmdGun.cs index 727d648ea..ca5045333 100644 --- a/MCGalaxy/Commands/Fun/CmdGun.cs +++ b/MCGalaxy/Commands/Fun/CmdGun.cs @@ -106,9 +106,9 @@ namespace MCGalaxy.Commands.Fun { ExtBlock stone = (ExtBlock)Block.Cobblestone; Player p = args.player; if (p.level.physics >= 3 && args.weaponType >= WeaponType.Explode) { - pl.HandleDeath(stone, " was blown up by " + p.ColoredName, true); + pl.HandleDeath(stone, "@p %Swas blown up by " + p.ColoredName, true); } else { - pl.HandleDeath(stone, " was shot by " + p.ColoredName); + pl.HandleDeath(stone, "@p %Swas shot by " + p.ColoredName); } return true; } diff --git a/MCGalaxy/Commands/Fun/CmdMissile.cs b/MCGalaxy/Commands/Fun/CmdMissile.cs index 66829b515..12ff75251 100644 --- a/MCGalaxy/Commands/Fun/CmdMissile.cs +++ b/MCGalaxy/Commands/Fun/CmdMissile.cs @@ -125,9 +125,9 @@ namespace MCGalaxy.Commands.Fun { ExtBlock stone = (ExtBlock)Block.Cobblestone; Player p = args.player; if (p.level.physics >= 3 && args.weaponType >= WeaponType.Explode) { - pl.HandleDeath(stone, " was blown up by " + p.ColoredName, true); + pl.HandleDeath(stone, "@p %Swas blown up by " + p.ColoredName, true); } else { - pl.HandleDeath(stone, " was hit by a missile from " + p.ColoredName); + pl.HandleDeath(stone, "@p %Swas hit by a missile from " + p.ColoredName); } return true; } diff --git a/MCGalaxy/Commands/other/CmdKill.cs b/MCGalaxy/Commands/other/CmdKill.cs index b9af8b421..45409e558 100644 --- a/MCGalaxy/Commands/other/CmdKill.cs +++ b/MCGalaxy/Commands/other/CmdKill.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.Misc { ExtBlock rock = (ExtBlock)Block.Stone; if (target == null) { - if (p != null) p.HandleDeath(rock, " killed themselves in their confusion"); + if (p != null) p.HandleDeath(rock, "@p %Skilled themselves in their confusion"); return; } if (p != null && (target != p && target.Rank >= p.Rank)) { diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index d1276f85e..660c9d929 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -359,7 +359,7 @@ namespace MCGalaxy { HandleDeath((ExtBlock)b, customMessage, explode, immediate); } - public void HandleDeath(ExtBlock block, string customMessage = "", bool explode = false, bool immediate = false) { + public void HandleDeath(ExtBlock block, string customMsg = "", bool explode = false, bool immediate = false) { OnPlayerDeathEvent.Call(this, block); if (Server.lava.active && Server.lava.HasPlayer(this) && Server.lava.IsPlayerDead(this)) return; @@ -379,9 +379,9 @@ namespace MCGalaxy { if (block.BlockID == Block.Stone || block.BlockID == Block.Cobblestone) { if (explode) level.MakeExplosion(x, y, z, 1); if (block.BlockID == Block.Stone) { - Chat.MessageGlobal(this, ColoredName + "%S" + customMessage, false); + Chat.MessageGlobal(this, customMsg.Replace("@p", ColoredName), false); } else { - Chat.MessageLevel(this, ColoredName + "%S" + customMessage, false, level); + Chat.MessageLevel(this, customMsg.Replace("@p", ColoredName), false, level); } }