Add /bot copy

This commit is contained in:
UnknownShadow200 2018-04-18 08:12:41 +10:00
parent e4e850a223
commit db294ce5cf
9 changed files with 87 additions and 56 deletions

View File

@ -44,7 +44,7 @@ namespace MCGalaxy.Bots {
PlayerBot bot = new PlayerBot(props.Name, lvl); PlayerBot bot = new PlayerBot(props.Name, lvl);
props.ApplyTo(bot); props.ApplyTo(bot);
bot.ModelBB = AABB.ModelAABB(bot, lvl); bot.SetModel(bot.Model, lvl);
LoadAi(props, bot); LoadAi(props, bot);
PlayerBot.Add(bot, false); PlayerBot.Add(bot, false);
} }
@ -72,7 +72,7 @@ namespace MCGalaxy.Bots {
} }
} }
static void LoadAi(BotProperties props, PlayerBot bot) { internal static void LoadAi(BotProperties props, PlayerBot bot) {
if (String.IsNullOrEmpty(props.AI)) return; if (String.IsNullOrEmpty(props.AI)) return;
try { try {
ScriptFile.Parse(null, bot, "bots/" + props.AI); ScriptFile.Parse(null, bot, "bots/" + props.AI);
@ -128,7 +128,7 @@ namespace MCGalaxy.Bots {
} }
public void ApplyTo(PlayerBot bot) { public void ApplyTo(PlayerBot bot) {
bot.Pos = new Position(X, Y, Z); bot.SetInitialPos(new Position(X, Y, Z));
bot.SetYawPitch(RotX, RotY); bot.SetYawPitch(RotX, RotY);
Orientation rot = bot.Rot; Orientation rot = bot.Rot;
rot.RotX = BodyX; rot.RotZ = BodyZ; rot.RotX = BodyX; rot.RotZ = BodyZ;

View File

@ -49,8 +49,8 @@ namespace MCGalaxy {
public PlayerBot(string n, Level lvl) { public PlayerBot(string n, Level lvl) {
name = n; DisplayName = n; SkinName = n; name = n; DisplayName = n; SkinName = n;
color = "&1"; color = "&1";
ModelBB = AABB.ModelAABB(this, lvl);
level = lvl; level = lvl;
SetModel(Model, lvl);
hasExtPositions = true; hasExtPositions = true;
BotsScheduler.Activate(); BotsScheduler.Activate();
} }

View File

@ -35,19 +35,19 @@ namespace MCGalaxy.Commands.Bots {
if (args.Length < 2) { Help(p); return; } if (args.Length < 2) { Help(p); return; }
if (!Formatter.ValidName(p, args[1], "bot")) return; if (!Formatter.ValidName(p, args[1], "bot")) return;
string bot = args[1], value = args.Length > 2 ? args[2] : null;
if (args[0].CaselessEq("add")) { if (args[0].CaselessEq("add")) {
AddBot(p, args[1]); AddBot(p, bot);
} else if (args[0].CaselessEq("remove")) { } else if (args[0].CaselessEq("remove")) {
RemoveBot(p, args[1]); RemoveBot(p, bot);
} else if (args[0].CaselessEq("text")) { } else if (args[0].CaselessEq("text")) {
string text = args.Length > 2 ? args[2] : null; SetBotText(p, bot, value);
SetBotText(p, args[1], text);
} else if (args[0].CaselessEq("deathmsg") || args[0].CaselessEq("deathmessage")) { } else if (args[0].CaselessEq("deathmsg") || args[0].CaselessEq("deathmessage")) {
string text = args.Length > 2 ? args[2] : null; SetDeathMessage(p, bot, value);
SetDeathMessage(p, args[1], text);
} else if (args[0].CaselessEq("rename")) { } else if (args[0].CaselessEq("rename")) {
string newName = args.Length > 2 ? args[2] : null; RenameBot(p, bot, value);
RenameBot(p, args[1], newName); } else if (args[0].CaselessEq("copy")) {
CopyBot(p, bot, value);
} else { } else {
Help(p); Help(p);
} }
@ -55,16 +55,19 @@ namespace MCGalaxy.Commands.Bots {
void AddBot(Player p, string botName) { void AddBot(Player p, string botName) {
if (!LevelInfo.ValidateAction(p, p.level.name, "add bots to this level")) return; if (!LevelInfo.ValidateAction(p, p.level.name, "add bots to this level")) return;
PlayerBot bot = new PlayerBot(botName, p.level);
TryAddBot(p, bot);
}
if (BotExists(p.level, botName, null)) { void TryAddBot(Player p, PlayerBot bot) {
if (BotExists(p.level, bot.name, null)) {
Player.Message(p, "A bot with that name already exists."); return; Player.Message(p, "A bot with that name already exists."); return;
} }
if (p.level.Bots.Count >= ServerConfig.MaxBotsPerLevel) { if (p.level.Bots.Count >= ServerConfig.MaxBotsPerLevel) {
Player.Message(p, "Reached maximum number of bots allowed on this map."); return; Player.Message(p, "Reached maximum number of bots allowed on this map."); return;
} }
PlayerBot bot = new PlayerBot(botName, p.level); bot.SetInitialPos(p.Pos);
bot.Pos = p.Pos; bot.lastPos = bot.Pos;
bot.SetYawPitch(p.Rot.RotY, 0); bot.SetYawPitch(p.Rot.RotY, 0);
Player.Message(p, "You added the bot " + bot.ColoredName); Player.Message(p, "You added the bot " + bot.ColoredName);
@ -95,28 +98,6 @@ namespace MCGalaxy.Commands.Bots {
} }
} }
void RenameBot(Player p, string botName, string newName) {
if (!LevelInfo.ValidateAction(p, p.level.name, "rename bots on this level")) return;
if (newName == null) { Player.Message(p, "New name of bot required."); return; }
if (!Formatter.ValidName(p, newName, "bot")) return;
PlayerBot bot = Matcher.FindBots(p, botName);
if (bot == null) return;
if (BotExists(p.level, newName, bot)) {
Player.Message(p, "A bot with the new name already exists."); return;
}
Player.Message(p, "Renamed bot {0}", bot.ColoredName);
if (bot.DisplayName == bot.name) {
bot.DisplayName = newName;
bot.GlobalDespawn();
bot.GlobalSpawn();
}
bot.name = newName;
BotsFile.Save(bot.level);
}
void SetBotText(Player p, string botName, string text) { void SetBotText(Player p, string botName, string text) {
PlayerBot bot = Matcher.FindBots(p, botName); PlayerBot bot = Matcher.FindBots(p, botName);
if (bot == null) return; if (bot == null) return;
@ -149,6 +130,48 @@ namespace MCGalaxy.Commands.Bots {
BotsFile.Save(bot.level); BotsFile.Save(bot.level);
} }
void RenameBot(Player p, string botName, string newName) {
if (!LevelInfo.ValidateAction(p, p.level.name, "rename bots on this level")) return;
if (newName == null) { Player.Message(p, "New name of bot required."); return; }
if (!Formatter.ValidName(p, newName, "bot")) return;
PlayerBot bot = Matcher.FindBots(p, botName);
if (bot == null) return;
if (BotExists(p.level, newName, bot)) {
Player.Message(p, "A bot with the new name already exists."); return;
}
Player.Message(p, "Renamed bot {0}", bot.ColoredName);
if (bot.DisplayName == bot.name) {
bot.DisplayName = newName;
bot.GlobalDespawn();
bot.GlobalSpawn();
}
bot.name = newName;
BotsFile.Save(bot.level);
}
void CopyBot(Player p, string botName, string newName) {
if (!LevelInfo.ValidateAction(p, p.level.name, "copy bots on this level")) return;
if (newName == null) { Player.Message(p, "Name of new bot required."); return; }
if (!Formatter.ValidName(p, newName, "bot")) return;
PlayerBot bot = Matcher.FindBots(p, botName);
if (bot == null) return;
PlayerBot clone = new PlayerBot(newName, p.level);
BotProperties props = new BotProperties();
props.FromBot(bot);
props.ApplyTo(clone);
clone.SetModel(clone.Model, p.level);
BotsFile.LoadAi(props, clone);
// Preserve custom name tag
if (bot.DisplayName == bot.name) clone.DisplayName = newName;
TryAddBot(p, clone);
}
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "%T/Bot add [name] %H- Adds a new bot at your position"); 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, "%T/Bot remove [name] %H- Removes the bot with that name");
@ -160,6 +183,7 @@ namespace MCGalaxy.Commands.Bots {
Player.Message(p, "%HSets the message shown when this bot kills a player"); Player.Message(p, "%HSets the message shown when this bot kills a player");
Player.Message(p, "%T/Bot rename [name] [new name] %H- Renames a bot"); Player.Message(p, "%T/Bot rename [name] [new name] %H- Renames a bot");
Player.Message(p, "%H Note: To only change name tag of a bot, use %T/Nick bot"); Player.Message(p, "%H Note: To only change name tag of a bot, use %T/Nick bot");
Player.Message(p, "%T/Bot copy [name] [new name] %H- Clones an existing bot");
} }
} }
} }

View File

@ -107,7 +107,7 @@ namespace MCGalaxy.Commands.Info {
string realmOwner = cfg.RealmOwner; string realmOwner = cfg.RealmOwner;
if (String.IsNullOrEmpty(cfg.RealmOwner)) { if (String.IsNullOrEmpty(cfg.RealmOwner)) {
realmOwner = GetRealmMapOwner(data.Name); realmOwner = DefaultRealmOwner(data.Name);
} }
if (String.IsNullOrEmpty(realmOwner)) return; if (String.IsNullOrEmpty(realmOwner)) return;
@ -135,7 +135,7 @@ namespace MCGalaxy.Commands.Info {
cfg.Likes, cfg.Dislikes); cfg.Likes, cfg.Dislikes);
} }
static string GetRealmMapOwner(string map) { static string DefaultRealmOwner(string map) {
bool plus = ServerConfig.ClassicubeAccountPlus; bool plus = ServerConfig.ClassicubeAccountPlus;
// Early out when accounts have + and map doesn't. // Early out when accounts have + and map doesn't.
if (plus && map.IndexOf('+') == -1) return null; if (plus && map.IndexOf('+') == -1) return null;

View File

@ -44,7 +44,7 @@ namespace MCGalaxy.Core {
p.prevMsg = ""; p.prevMsg = "";
p.showMBs = false; p.showMBs = false;
p.showPortals = false; p.showPortals = false;
p.ModelBB = AABB.ModelAABB(p, level); // in case had been using a level-only custom block for their model p.SetModel(p.Model, level); // in case had been using a level-only custom block for their model
if (!Hacks.CanUseHacks(p, level) && p.isFlying) { if (!Hacks.CanUseHacks(p, level) && p.isFlying) {
Player.Message(p, "You cannot use /fly on this map."); Player.Message(p, "You cannot use /fly on this map.");

View File

@ -182,9 +182,8 @@ namespace MCGalaxy {
public static void UpdateModel(Entity entity, string model) { public static void UpdateModel(Entity entity, string model) {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
entity.Model = model;
Level lvl = entity.Level; Level lvl = entity.Level;
entity.ModelBB = AABB.ModelAABB(entity, lvl); entity.SetModel(model, lvl);
foreach (Player pl in players) { foreach (Player pl in players) {
if (pl.level != lvl || !pl.Supports(CpeExt.ChangeModel)) continue; if (pl.level != lvl || !pl.Supports(CpeExt.ChangeModel)) continue;

View File

@ -46,6 +46,15 @@ namespace MCGalaxy {
set { Interlocked.Exchange(ref _pos, value.Pack()); OnSetPos(); } set { Interlocked.Exchange(ref _pos, value.Pack()); OnSetPos(); }
} }
public void SetInitialPos(Position pos) {
Pos = pos; lastPos = pos;
}
public void SetModel(string model, Level lvl) {
Model = model;
ModelBB = AABB.ModelAABB(this, lvl);
}
public void SetYawPitch(byte yaw, byte pitch) { public void SetYawPitch(byte yaw, byte pitch) {
Orientation rot = Rot; Orientation rot = Rot;
rot.RotY = yaw; rot.HeadX = pitch; rot.RotY = yaw; rot.HeadX = pitch;

View File

@ -212,8 +212,7 @@ namespace MCGalaxy {
byte.TryParse(bits[1], out rot.RotZ); byte.TryParse(bits[1], out rot.RotZ);
Rot = rot; Rot = rot;
} }
SetModel(Model, level);
ModelBB = AABB.ModelAABB(this, level);
} }
void GetPlayerStats() { void GetPlayerStats() {