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

@ -48,9 +48,9 @@ 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,39 +35,42 @@ 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")) {
} else { CopyBot(p, bot, value);
} else {
Help(p); Help(p);
} }
} }
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);
if (BotExists(p.level, botName, null)) { TryAddBot(p, bot);
}
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);
PlayerBot.Add(bot); PlayerBot.Add(bot);
} }
@ -95,9 +98,41 @@ namespace MCGalaxy.Commands.Bots {
} }
} }
void SetBotText(Player p, string botName, string text) {
PlayerBot bot = Matcher.FindBots(p, botName);
if (bot == null) return;
if (!LevelInfo.ValidateAction(p, p.level.name, "set bot text of that bot")) return;
if (text == null) {
Player.Message(p, "Removed text shown when bot {0} %Sclicked on", bot.ColoredName);
bot.ClickedOnText = null;
} else {
if (!MessageBlock.Validate(p, text, false)) return;
Player.Message(p, "Set text shown when bot {0} %Sis clicked on to {1}", bot.ColoredName, text);
bot.ClickedOnText = text;
}
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);
}
void RenameBot(Player p, string botName, string newName) { void RenameBot(Player p, string botName, string newName) {
if (!LevelInfo.ValidateAction(p, p.level.name, "rename bots on this level")) return; 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 (newName == null) { Player.Message(p, "New name of bot required."); return; }
if (!Formatter.ValidName(p, newName, "bot")) return; if (!Formatter.ValidName(p, newName, "bot")) return;
PlayerBot bot = Matcher.FindBots(p, botName); PlayerBot bot = Matcher.FindBots(p, botName);
@ -117,36 +152,24 @@ namespace MCGalaxy.Commands.Bots {
BotsFile.Save(bot.level); BotsFile.Save(bot.level);
} }
void SetBotText(Player p, string botName, string text) { 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); PlayerBot bot = Matcher.FindBots(p, botName);
if (bot == null) return; if (bot == null) return;
if (!LevelInfo.ValidateAction(p, p.level.name, "set bot text of that bot")) return;
if (text == null) { PlayerBot clone = new PlayerBot(newName, p.level);
Player.Message(p, "Removed text shown when bot {0} %Sclicked on", bot.ColoredName); BotProperties props = new BotProperties();
bot.ClickedOnText = null; props.FromBot(bot);
} else { props.ApplyTo(clone);
if (!MessageBlock.Validate(p, text, false)) return;
Player.Message(p, "Set text shown when bot {0} %Sis clicked on to {1}", bot.ColoredName, text); clone.SetModel(clone.Model, p.level);
bot.ClickedOnText = text; BotsFile.LoadAi(props, clone);
} // Preserve custom name tag
BotsFile.Save(bot.level); if (bot.DisplayName == bot.name) clone.DisplayName = newName;
} TryAddBot(p, clone);
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) { public override void Help(Player p) {
@ -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

@ -242,7 +242,7 @@ namespace MCGalaxy {
if (!Directory.Exists("levels/prev")) Directory.CreateDirectory("levels/prev"); if (!Directory.Exists("levels/prev")) Directory.CreateDirectory("levels/prev");
if (Changed || !File.Exists(path) || force || (physicschanged && clearPhysics)) { if (Changed || !File.Exists(path) || force || (physicschanged && clearPhysics)) {
lock (saveLock) SaveCore(path); lock (saveLock) SaveCore(path);
if (clearPhysics) ClearPhysics(); if (clearPhysics) ClearPhysics();
} else { } else {
Logger.Log(LogType.SystemActivity, "Skipping level save for " + name + "."); Logger.Log(LogType.SystemActivity, "Skipping level save for " + name + ".");

View File

@ -211,9 +211,8 @@ namespace MCGalaxy {
byte.TryParse(bits[0], out rot.RotX); byte.TryParse(bits[0], out rot.RotX);
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() {