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);
props.ApplyTo(bot);
bot.ModelBB = AABB.ModelAABB(bot, lvl);
bot.SetModel(bot.Model, lvl);
LoadAi(props, bot);
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;
try {
ScriptFile.Parse(null, bot, "bots/" + props.AI);
@ -128,7 +128,7 @@ namespace MCGalaxy.Bots {
}
public void ApplyTo(PlayerBot bot) {
bot.Pos = new Position(X, Y, Z);
bot.SetInitialPos(new Position(X, Y, Z));
bot.SetYawPitch(RotX, RotY);
Orientation rot = bot.Rot;
rot.RotX = BodyX; rot.RotZ = BodyZ;

View File

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

View File

@ -35,39 +35,42 @@ namespace MCGalaxy.Commands.Bots {
if (args.Length < 2) { Help(p); 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")) {
AddBot(p, args[1]);
AddBot(p, bot);
} else if (args[0].CaselessEq("remove")) {
RemoveBot(p, args[1]);
RemoveBot(p, bot);
} else if (args[0].CaselessEq("text")) {
string text = args.Length > 2 ? args[2] : null;
SetBotText(p, args[1], text);
SetBotText(p, bot, value);
} else if (args[0].CaselessEq("deathmsg") || args[0].CaselessEq("deathmessage")) {
string text = args.Length > 2 ? args[2] : null;
SetDeathMessage(p, args[1], text);
SetDeathMessage(p, bot, value);
} else if (args[0].CaselessEq("rename")) {
string newName = args.Length > 2 ? args[2] : null;
RenameBot(p, args[1], newName);
} else {
RenameBot(p, bot, value);
} else if (args[0].CaselessEq("copy")) {
CopyBot(p, bot, value);
} else {
Help(p);
}
}
void AddBot(Player p, string botName) {
if (!LevelInfo.ValidateAction(p, p.level.name, "add bots to this level")) return;
if (BotExists(p.level, botName, null)) {
PlayerBot bot = new PlayerBot(botName, p.level);
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;
}
if (p.level.Bots.Count >= ServerConfig.MaxBotsPerLevel) {
Player.Message(p, "Reached maximum number of bots allowed on this map."); return;
}
PlayerBot bot = new PlayerBot(botName, p.level);
bot.Pos = p.Pos; bot.lastPos = bot.Pos;
bot.SetInitialPos(p.Pos);
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);
}
@ -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) {
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;
PlayerBot bot = Matcher.FindBots(p, botName);
@ -117,36 +152,24 @@ namespace MCGalaxy.Commands.Bots {
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);
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);
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) {
@ -160,6 +183,7 @@ namespace MCGalaxy.Commands.Bots {
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, "%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;
if (String.IsNullOrEmpty(cfg.RealmOwner)) {
realmOwner = GetRealmMapOwner(data.Name);
realmOwner = DefaultRealmOwner(data.Name);
}
if (String.IsNullOrEmpty(realmOwner)) return;
@ -135,7 +135,7 @@ namespace MCGalaxy.Commands.Info {
cfg.Likes, cfg.Dislikes);
}
static string GetRealmMapOwner(string map) {
static string DefaultRealmOwner(string map) {
bool plus = ServerConfig.ClassicubeAccountPlus;
// Early out when accounts have + and map doesn't.
if (plus && map.IndexOf('+') == -1) return null;

View File

@ -44,7 +44,7 @@ namespace MCGalaxy.Core {
p.prevMsg = "";
p.showMBs = 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) {
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) {
Player[] players = PlayerInfo.Online.Items;
entity.Model = model;
Level lvl = entity.Level;
entity.ModelBB = AABB.ModelAABB(entity, lvl);
entity.SetModel(model, lvl);
foreach (Player pl in players) {
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(); }
}
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) {
Orientation rot = Rot;
rot.RotY = yaw; rot.HeadX = pitch;

View File

@ -242,7 +242,7 @@ namespace MCGalaxy {
if (!Directory.Exists("levels/prev")) Directory.CreateDirectory("levels/prev");
if (Changed || !File.Exists(path) || force || (physicschanged && clearPhysics)) {
lock (saveLock) SaveCore(path);
lock (saveLock) SaveCore(path);
if (clearPhysics) ClearPhysics();
} else {
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[1], out rot.RotZ);
Rot = rot;
}
ModelBB = AABB.ModelAABB(this, level);
}
SetModel(Model, level);
}
void GetPlayerStats() {