From 7417acad4cc78734bb5b59af2298f8546e4a8285 Mon Sep 17 00:00:00 2001 From: Goodlyay Date: Sat, 13 Jul 2024 01:43:30 -0700 Subject: [PATCH] Add creation date timestamp to bots --- MCGalaxy/Bots/BotsFile.cs | 6 ++++++ MCGalaxy/Bots/PlayerBot.cs | 7 +++++-- MCGalaxy/Commands/Bots/CmdBot.cs | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/MCGalaxy/Bots/BotsFile.cs b/MCGalaxy/Bots/BotsFile.cs index b7612a74e..05909ed24 100644 --- a/MCGalaxy/Bots/BotsFile.cs +++ b/MCGalaxy/Bots/BotsFile.cs @@ -141,6 +141,7 @@ public sealed class BotProperties { [ConfigFloat] public float ScaleX; [ConfigFloat] public float ScaleY; [ConfigFloat] public float ScaleZ; + [ConfigString] public string CreationDate; public void FromBot(PlayerBot bot) { Owner = bot.Owner; @@ -156,6 +157,8 @@ public void FromBot(PlayerBot bot) { RotX = bot.Rot.RotY; RotY = bot.Rot.HeadX; BodyX = bot.Rot.RotX; BodyZ = bot.Rot.RotZ; ScaleX = bot.ScaleX; ScaleY = bot.ScaleY; ScaleZ = bot.ScaleZ; + + CreationDate = bot.CreationDate.ToString(); } public void ApplyTo(PlayerBot bot) { @@ -175,6 +178,9 @@ public void ApplyTo(PlayerBot bot) { if (CurSpeed != 0) bot.movementSpeed = CurSpeed; bot.ClickedOnText = ClickedOnText; bot.DeathMessage = DeathMessage; bot.ScaleX = ScaleX; bot.ScaleY = ScaleY; bot.ScaleZ = ScaleZ; + + long longCreationDate; + if (!String.IsNullOrEmpty(CreationDate) && long.TryParse(CreationDate, out longCreationDate)) bot.CreationDate = longCreationDate; } } } diff --git a/MCGalaxy/Bots/PlayerBot.cs b/MCGalaxy/Bots/PlayerBot.cs index 5b10d1403..ba99dfab9 100644 --- a/MCGalaxy/Bots/PlayerBot.cs +++ b/MCGalaxy/Bots/PlayerBot.cs @@ -46,8 +46,10 @@ public sealed class PlayerBot : Entity { public Position TargetPos; public bool movement = false; public int movementSpeed = 3; - internal int curJump = 0; - + internal int curJump = 0; + + public long CreationDate = 0; + public PlayerBot(string n, Level lvl) { name = n; DisplayName = n; SkinName = n; color = "&1"; @@ -296,6 +298,7 @@ void DoMove(int steps) { public void DisplayInfo(Player p) { p.Message("Bot {0} &S({1}) has:", ColoredName, name); p.Message(" Owner: &f{0}", string.IsNullOrEmpty(Owner) ? "no one" : p.FormatNick(Owner)); + if (CreationDate != 0) { p.Message(" Created: &f{0}", CreationDate.FromUnixTime().ToString("yyyy-MM-dd")); } if (!String.IsNullOrEmpty(AIName)) { p.Message(" AI: &f{0}", AIName); } if (hunt || kill) { p.Message(" Hunt: &f{0}&S, Kill: %f{1}", hunt, kill); } if (SkinName != name) { p.Message(" Skin: &f{0}", SkinName); } diff --git a/MCGalaxy/Commands/Bots/CmdBot.cs b/MCGalaxy/Commands/Bots/CmdBot.cs index 1908c4a89..75a464ece 100644 --- a/MCGalaxy/Commands/Bots/CmdBot.cs +++ b/MCGalaxy/Commands/Bots/CmdBot.cs @@ -17,6 +17,7 @@ permissions and limitations under the Licenses. */ using MCGalaxy.Blocks.Extended; using MCGalaxy.Bots; +using System; namespace MCGalaxy.Commands.Bots { @@ -70,6 +71,7 @@ void AddBot(Player p, string botName) { botName = botName.Replace(' ', '_'); PlayerBot bot = new PlayerBot(botName, p.level); bot.Owner = p.name; + bot.CreationDate = DateTime.UtcNow.ToUnixTime(); TryAddBot(p, bot); } @@ -207,6 +209,7 @@ void CopyBot(Player p, string botName, string newName) { props.ApplyTo(clone); clone.Owner = p.name; clone.SetModel(clone.Model); + clone.CreationDate = DateTime.UtcNow.ToUnixTime(); BotsFile.LoadAi(props, clone); // Preserve custom name tag if (bot.DisplayName == bot.name) clone.DisplayName = newName;