Don't allow adding two bots to map with same name, fixes #308.

As if multiple bots have same name, all but 1 bots are lost on map unload then load again. They also can't be targeted individually in commands.
This commit is contained in:
UnknownShadow200 2017-08-12 16:12:51 +10:00
parent bc14e5e242
commit 0d80d86b54

View File

@ -32,6 +32,10 @@ namespace MCGalaxy.Commands.Bots {
}
if (!Formatter.ValidName(p, message, "bot")) return;
if (BotExists(p.level, message)) {
Player.Message(p, "A bot with that name already exists."); return;
}
PlayerBot bot = new PlayerBot(message, p.level);
bot.Pos = p.Pos;
bot.SetYawPitch(p.Rot.RotY, 0);
@ -39,6 +43,14 @@ namespace MCGalaxy.Commands.Bots {
Player.Message(p, "You added the bot " + bot.ColoredName + "%S.");
PlayerBot.Add(bot);
}
static bool BotExists(Level lvl, string name) {
PlayerBot[] bots = lvl.Bots.Items;
foreach (PlayerBot bot in bots) {
if (bot.name.CaselessEq(name)) return true;
}
return false;
}
public override void Help(Player p) {
Player.Message(p, "%T/BotAdd [name]");