Skip to content

Commit

Permalink
Add creation date timestamp to bots
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodlyay committed Jul 13, 2024
1 parent c76f2f4 commit 7417aca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions MCGalaxy/Bots/BotsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -156,6 +157,8 @@ public sealed class BotProperties {
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) {
Expand All @@ -175,6 +178,9 @@ public sealed class BotProperties {
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;
}
}
}
7 changes: 5 additions & 2 deletions MCGalaxy/Bots/PlayerBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -296,6 +298,7 @@ public sealed class PlayerBot : Entity {
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); }
Expand Down
3 changes: 3 additions & 0 deletions MCGalaxy/Commands/Bots/CmdBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
using MCGalaxy.Blocks.Extended;
using MCGalaxy.Bots;
using System;

namespace MCGalaxy.Commands.Bots
{
Expand Down Expand Up @@ -70,6 +71,7 @@ public sealed class CmdBot : Command2
botName = botName.Replace(' ', '_');
PlayerBot bot = new PlayerBot(botName, p.level);
bot.Owner = p.name;
bot.CreationDate = DateTime.UtcNow.ToUnixTime();
TryAddBot(p, bot);
}

Expand Down Expand Up @@ -207,6 +209,7 @@ public sealed class CmdBot : Command2
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;
Expand Down

0 comments on commit 7417aca

Please sign in to comment.