mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Move bots to be per-level, remove obsolete bot functions and minorly optimise bots
This commit is contained in:
parent
f843237188
commit
16e87c8c3a
@ -93,15 +93,12 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
public static void UnloadBots(Level lvl) {
|
public static void UnloadBots(Level lvl) {
|
||||||
lock (locker) {
|
lock (locker) {
|
||||||
PlayerBot[] bots = PlayerBot.Bots.Items;
|
PlayerBot[] bots = lvl.Bots.Items;
|
||||||
bool hasBots = false;
|
|
||||||
|
|
||||||
foreach (PlayerBot bot in bots) {
|
foreach (PlayerBot bot in bots) {
|
||||||
if (bot.level != lvl) continue;
|
|
||||||
DoUpdateBot(bot, false);
|
DoUpdateBot(bot, false);
|
||||||
hasBots = true;
|
|
||||||
}
|
}
|
||||||
if (hasBots) Save();
|
if (bots.Length > 0) Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,9 +37,10 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void BotsTick(SchedulerTask task) {
|
static void BotsTick(SchedulerTask task) {
|
||||||
PlayerBot[] bots = PlayerBot.Bots.Items;
|
Level[] levels = LevelInfo.Loaded.Items;
|
||||||
for (int i = 0; i < bots.Length; i++) {
|
for (int i = 0; i < levels.Length; i++) {
|
||||||
BotTick(bots[i]);
|
PlayerBot[] bots = levels[i].Bots.Items;
|
||||||
|
for (int j = 0; j < bots.Length; j++) { BotTick(bots[j]); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to nod spin around for a certain interval. </summary>
|
/// <summary> Causes the bot to nod spin around for a certain interval. </summary>
|
||||||
public class SpinInstruction : BotInstruction {
|
public class SpinInstruction : BotInstruction {
|
||||||
public override string Name { get { return "spin"; } }
|
public SpinInstruction() { Name = "spin"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
Metadata meta = (Metadata)data.Metadata;
|
Metadata meta = (Metadata)data.Metadata;
|
||||||
@ -65,7 +65,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to nod down up and down for a certain interval. </summary>
|
/// <summary> Causes the bot to nod down up and down for a certain interval. </summary>
|
||||||
public sealed class NodInstruction : SpinInstruction {
|
public sealed class NodInstruction : SpinInstruction {
|
||||||
public override string Name { get { return "nod"; } }
|
public NodInstruction() { Name = "nod"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
Metadata meta = (Metadata)data.Metadata;
|
Metadata meta = (Metadata)data.Metadata;
|
||||||
|
@ -23,7 +23,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to move towards the closest player, within a defined search radius. </summary>
|
/// <summary> Causes the bot to move towards the closest player, within a defined search radius. </summary>
|
||||||
public sealed class HuntInstruction : BotInstruction {
|
public sealed class HuntInstruction : BotInstruction {
|
||||||
public override string Name { get { return "hunt"; } }
|
public HuntInstruction() { Name = "hunt"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
int search = 75;
|
int search = 75;
|
||||||
@ -99,7 +99,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to kill nearby players. </summary>
|
/// <summary> Causes the bot to kill nearby players. </summary>
|
||||||
public sealed class KillInstruction : BotInstruction {
|
public sealed class KillInstruction : BotInstruction {
|
||||||
public override string Name { get { return "kill"; } }
|
public KillInstruction() { Name = "kill"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
@ -123,7 +123,7 @@ namespace MCGalaxy.Bots {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public sealed class StareInstruction : BotInstruction {
|
public sealed class StareInstruction : BotInstruction {
|
||||||
public override string Name { get { return "stare"; } }
|
public StareInstruction() { Name = "stare"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
int search = 20000;
|
int search = 20000;
|
||||||
|
@ -25,7 +25,7 @@ namespace MCGalaxy.Bots {
|
|||||||
public abstract class BotInstruction {
|
public abstract class BotInstruction {
|
||||||
|
|
||||||
/// <summary> Gets the identifying name for this instruction. </summary>
|
/// <summary> Gets the identifying name for this instruction. </summary>
|
||||||
public abstract string Name { get; }
|
public string Name;
|
||||||
|
|
||||||
/// <summary> Performs a tick for this instruction. </summary>
|
/// <summary> Performs a tick for this instruction. </summary>
|
||||||
/// <returns> false if the bot should proceed to execute the
|
/// <returns> false if the bot should proceed to execute the
|
||||||
|
@ -22,7 +22,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to instantly teleport to a position. </summary>
|
/// <summary> Causes the bot to instantly teleport to a position. </summary>
|
||||||
public class TeleportInstruction : BotInstruction {
|
public class TeleportInstruction : BotInstruction {
|
||||||
public override string Name { get { return "teleport"; } }
|
public TeleportInstruction() { Name = "teleport"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
Coords coords = (Coords)data.Metadata;
|
Coords coords = (Coords)data.Metadata;
|
||||||
@ -65,7 +65,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to gradually move to to a position. </summary>
|
/// <summary> Causes the bot to gradually move to to a position. </summary>
|
||||||
public sealed class WalkInstruction : TeleportInstruction {
|
public sealed class WalkInstruction : TeleportInstruction {
|
||||||
public override string Name { get { return "walk"; } }
|
public WalkInstruction() { Name = "walk"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
Coords target = (Coords)data.Metadata;
|
Coords target = (Coords)data.Metadata;
|
||||||
@ -91,7 +91,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to begin jumping. </summary>
|
/// <summary> Causes the bot to begin jumping. </summary>
|
||||||
public sealed class JumpInstruction : BotInstruction {
|
public sealed class JumpInstruction : BotInstruction {
|
||||||
public override string Name { get { return "jump"; } }
|
public JumpInstruction() { Name = "jump"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
bot.jumping = true;
|
bot.jumping = true;
|
||||||
@ -109,7 +109,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to change how fast it moves. </summary>
|
/// <summary> Causes the bot to change how fast it moves. </summary>
|
||||||
public sealed class SpeedInstruction : BotInstruction {
|
public sealed class SpeedInstruction : BotInstruction {
|
||||||
public override string Name { get { return "speed"; } }
|
public SpeedInstruction() { Name = "speed"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
bot.movementSpeed = (int)Math.Round(3m * (short)data.Metadata / 100m);
|
bot.movementSpeed = (int)Math.Round(3m * (short)data.Metadata / 100m);
|
||||||
|
@ -22,7 +22,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to reset to the and execute first instruction. </summary>
|
/// <summary> Causes the bot to reset to the and execute first instruction. </summary>
|
||||||
public sealed class ResetInstruction : BotInstruction {
|
public sealed class ResetInstruction : BotInstruction {
|
||||||
public override string Name { get { return "reset"; } }
|
public ResetInstruction() { Name = "reset"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
bot.cur = 0; return false;
|
bot.cur = 0; return false;
|
||||||
@ -37,7 +37,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to be removed from the world. </summary>
|
/// <summary> Causes the bot to be removed from the world. </summary>
|
||||||
public sealed class RemoveInstruction : BotInstruction {
|
public sealed class RemoveInstruction : BotInstruction {
|
||||||
public override string Name { get { return "remove"; } }
|
public RemoveInstruction() { Name = "remove"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
PlayerBot.Remove(bot); return true;
|
PlayerBot.Remove(bot); return true;
|
||||||
@ -52,7 +52,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to switch to a different AI. </summary>
|
/// <summary> Causes the bot to switch to a different AI. </summary>
|
||||||
public sealed class LinkScriptInstruction : BotInstruction {
|
public sealed class LinkScriptInstruction : BotInstruction {
|
||||||
public override string Name { get { return "linkscript"; } }
|
public LinkScriptInstruction() { Name = "linkscript"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
string script = (string)data.Metadata;
|
string script = (string)data.Metadata;
|
||||||
@ -87,7 +87,7 @@ namespace MCGalaxy.Bots {
|
|||||||
|
|
||||||
/// <summary> Causes the bot to wait/do nothing for a certain interval. </summary>
|
/// <summary> Causes the bot to wait/do nothing for a certain interval. </summary>
|
||||||
public sealed class WaitInstruction : BotInstruction {
|
public sealed class WaitInstruction : BotInstruction {
|
||||||
public override string Name { get { return "wait"; } }
|
public WaitInstruction() { Name = "wait"; }
|
||||||
|
|
||||||
public override bool Execute(PlayerBot bot, InstructionData data) {
|
public override bool Execute(PlayerBot bot, InstructionData data) {
|
||||||
if (bot.countdown == 0) {
|
if (bot.countdown == 0) {
|
||||||
|
@ -24,10 +24,6 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public sealed class PlayerBot : Entity {
|
public sealed class PlayerBot : Entity {
|
||||||
|
|
||||||
[Obsolete("Use PlayerBot.Bots.Items instead")]
|
|
||||||
public static List<PlayerBot> playerbots;
|
|
||||||
public static VolatileArray<PlayerBot> Bots = new VolatileArray<PlayerBot>(true);
|
|
||||||
|
|
||||||
public bool hunt = false, kill = false;
|
public bool hunt = false, kill = false;
|
||||||
|
|
||||||
public string AIName = "", color;
|
public string AIName = "", color;
|
||||||
@ -42,8 +38,6 @@ namespace MCGalaxy {
|
|||||||
public List<InstructionData> Instructions = new List<InstructionData>();
|
public List<InstructionData> Instructions = new List<InstructionData>();
|
||||||
|
|
||||||
public Position TargetPos;
|
public Position TargetPos;
|
||||||
public ushort[] pos = new ushort[3];
|
|
||||||
public byte[] rot = new byte[2];
|
|
||||||
public bool movement = false;
|
public bool movement = false;
|
||||||
public int movementSpeed = 3;
|
public int movementSpeed = 3;
|
||||||
internal bool jumping = false;
|
internal bool jumping = false;
|
||||||
@ -72,26 +66,14 @@ namespace MCGalaxy {
|
|||||||
public override byte EntityID { get { return id; } }
|
public override byte EntityID { get { return id; } }
|
||||||
public override Level Level { get { return level; } }
|
public override Level Level { get { return level; } }
|
||||||
|
|
||||||
protected override void OnSetPos() {
|
|
||||||
Position p = Pos;
|
|
||||||
pos[0] = (ushort)p.X; pos[1] = (ushort)p.Y; pos[2] = (ushort)p.Z;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnSetRot() {
|
|
||||||
Orientation r = Rot;
|
|
||||||
rot[0] = r.RotY; rot[1] = r.HeadX;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Add(PlayerBot bot, bool save = true) {
|
public static void Add(PlayerBot bot, bool save = true) {
|
||||||
Bots.Add(bot);
|
bot.level.Bots.Add(bot);
|
||||||
bot.GlobalSpawn();
|
bot.GlobalSpawn();
|
||||||
|
if (save) BotsFile.UpdateBot(bot);
|
||||||
if (save)
|
|
||||||
BotsFile.UpdateBot(bot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Remove(PlayerBot bot, bool save = true) {
|
public static void Remove(PlayerBot bot, bool save = true) {
|
||||||
Bots.Remove(bot);
|
bot.level.Bots.Remove(bot);
|
||||||
bot.GlobalDespawn();
|
bot.GlobalDespawn();
|
||||||
bot.jumping = false;
|
bot.jumping = false;
|
||||||
if (save) BotsFile.RemoveBot(bot);
|
if (save) BotsFile.RemoveBot(bot);
|
||||||
@ -108,10 +90,9 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void RemoveLoadedBots(Level lvl, bool save) {
|
static void RemoveLoadedBots(Level lvl, bool save) {
|
||||||
PlayerBot[] bots = Bots.Items;
|
PlayerBot[] bots = lvl.Bots.Items;
|
||||||
for (int i = 0; i < bots.Length; i++) {
|
for (int i = 0; i < bots.Length; i++) {
|
||||||
PlayerBot bot = bots[i];
|
Remove(bots[i], save);
|
||||||
if (bots[i].level == lvl) Remove(bot, save);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,22 +112,11 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void GlobalUpdatePosition() {
|
public static void GlobalUpdatePosition() {
|
||||||
PlayerBot[] bots = Bots.Items;
|
Level[] levels = LevelInfo.Loaded.Items;
|
||||||
foreach (PlayerBot b in bots) b.UpdatePosition();
|
for (int i = 0; i < levels.Length; i++) {
|
||||||
|
PlayerBot[] bots = levels[i].Bots.Items;
|
||||||
|
for (int j = 0; j < bots.Length; j++) { bots[j].UpdatePosition(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static PlayerBot Find(string name) {
|
|
||||||
PlayerBot match = null; int matches = 0;
|
|
||||||
PlayerBot[] bots = Bots.Items;
|
|
||||||
|
|
||||||
foreach (PlayerBot bot in bots) {
|
|
||||||
if (bot.name.CaselessEq(name)) return bot;
|
|
||||||
if (bot.name.CaselessContains(name)) {
|
|
||||||
match = bot; matches++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return matches == 1 ? match : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatePosition() {
|
void UpdatePosition() {
|
||||||
@ -179,10 +149,9 @@ namespace MCGalaxy {
|
|||||||
used[i] = 0;
|
used[i] = 0;
|
||||||
|
|
||||||
// Lock to ensure that no two bots can end up with the same playerid
|
// Lock to ensure that no two bots can end up with the same playerid
|
||||||
lock (Bots.locker) {
|
lock (bot.level.Bots.locker) {
|
||||||
PlayerBot[] bots = Bots.Items;
|
PlayerBot[] bots = bot.level.Bots.Items;
|
||||||
for (int i = 0; i < bots.Length; i++) {
|
for (int i = 0; i < bots.Length; i++) {
|
||||||
if (bots[i].level != bot.level) continue;
|
|
||||||
byte id = bots[i].id;
|
byte id = bots[i].id;
|
||||||
used[id] = 1;
|
used[id] = 1;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
if (message.CaselessEq("all")) {
|
if (message.CaselessEq("all")) {
|
||||||
PlayerBot.RemoveAllFromLevel(p.level); return;
|
PlayerBot.RemoveAllFromLevel(p.level); return;
|
||||||
} else {
|
} else {
|
||||||
PlayerBot bot = Matcher.FindBotsInLevel(p, message);
|
PlayerBot bot = Matcher.FindBots(p, message);
|
||||||
if (bot == null) return;
|
if (bot == null) return;
|
||||||
|
|
||||||
PlayerBot.Remove(bot);
|
PlayerBot.Remove(bot);
|
||||||
|
@ -25,6 +25,7 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
public override string type { get { return CommandTypes.Other; } }
|
public override string type { get { return CommandTypes.Other; } }
|
||||||
public override bool museumUsable { get { return false; } }
|
public override bool museumUsable { get { return false; } }
|
||||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||||
|
public override bool SuperUseable { get { return false; } }
|
||||||
public override CommandPerm[] ExtraPerms {
|
public override CommandPerm[] ExtraPerms {
|
||||||
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can set bots to be killer") }; }
|
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can set bots to be killer") }; }
|
||||||
}
|
}
|
||||||
@ -32,7 +33,7 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
if (message.Length == 0) { Help(p); return; }
|
if (message.Length == 0) { Help(p); return; }
|
||||||
string[] args = message.SplitSpaces();
|
string[] args = message.SplitSpaces();
|
||||||
PlayerBot bot = Matcher.FindBotsInLevel(p, args[0]);
|
PlayerBot bot = Matcher.FindBots(p, args[0]);
|
||||||
if (bot == null) return;
|
if (bot == null) return;
|
||||||
|
|
||||||
if (p != null && !bot.level.BuildAccess.CheckDetailed(p)) {
|
if (p != null && !bot.level.BuildAccess.CheckDetailed(p)) {
|
||||||
|
@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerBot bot = Matcher.FindBotsInLevel(p, message);
|
PlayerBot bot = Matcher.FindBots(p, message);
|
||||||
if (bot == null) return;
|
if (bot == null) return;
|
||||||
|
|
||||||
bot.Pos = p.Pos; bot.SetYawPitch(p.Rot.RotY, p.Rot.HeadX);
|
bot.Pos = p.Pos; bot.SetYawPitch(p.Rot.RotY, p.Rot.HeadX);
|
||||||
|
@ -36,19 +36,12 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
if (lvl == null) return;
|
if (lvl == null) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerBot[] bots = PlayerBot.Bots.Items;
|
PlayerBot[] bots = lvl.Bots.Items;
|
||||||
List<PlayerBot> inScope = new List<PlayerBot>();
|
string cmd = (lvl == p.level) ? "bots" : "bots " + lvl.name;
|
||||||
foreach (PlayerBot bot in bots) {
|
|
||||||
if (lvl != null && bot.level != lvl) continue;
|
|
||||||
inScope.Add(bot);
|
|
||||||
}
|
|
||||||
|
|
||||||
string cmd = (lvl == null || lvl == p.level) ? "bots" : "bots " + lvl.name;
|
|
||||||
string modifier = args.Length > offset ? args[offset] : "";
|
string modifier = args.Length > offset ? args[offset] : "";
|
||||||
|
|
||||||
string group = lvl == null ? "All bots:" : "Bots in " + lvl.ColoredName + ":";
|
Player.Message(p, "Bots in " + lvl.ColoredName + ":");
|
||||||
Player.Message(p, group);
|
MultiPageOutput.Output(p, bots, FormatBot, cmd, "Bots", modifier, false);
|
||||||
MultiPageOutput.Output(p, inScope, FormatBot, cmd, "Bots", modifier, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static string FormatBot(PlayerBot bot) {
|
static string FormatBot(PlayerBot bot) {
|
||||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands {
|
|||||||
|
|
||||||
Player who = null;
|
Player who = null;
|
||||||
PlayerBot bot = null;
|
PlayerBot bot = null;
|
||||||
if (isBot) bot = Matcher.FindBotsInLevel(p, args[1]);
|
if (isBot) bot = Matcher.FindBots(p, args[1]);
|
||||||
else who = PlayerInfo.FindMatches(p, args[0]);
|
else who = PlayerInfo.FindMatches(p, args[0]);
|
||||||
if (bot == null && who == null) return;
|
if (bot == null && who == null) return;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ namespace MCGalaxy.Commands.Misc {
|
|||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
if (!CheckPlayer(p, target)) return;
|
if (!CheckPlayer(p, target)) return;
|
||||||
} else if (args[0].CaselessEq("bot")) {
|
} else if (args[0].CaselessEq("bot")) {
|
||||||
bot = Matcher.FindBotsInLevel(p, args[1]);
|
bot = Matcher.FindBots(p, args[1]);
|
||||||
if (bot == null) return;
|
if (bot == null) return;
|
||||||
} else {
|
} else {
|
||||||
Help(p); return;
|
Help(p); return;
|
||||||
|
@ -113,9 +113,8 @@ namespace MCGalaxy {
|
|||||||
GlobalSpawn(p, pos, rot, true);
|
GlobalSpawn(p, pos, rot, true);
|
||||||
|
|
||||||
if (!bots) return;
|
if (!bots) return;
|
||||||
PlayerBot[] botsList = PlayerBot.Bots.Items;
|
PlayerBot[] botsList = p.level.Bots.Items;
|
||||||
foreach (PlayerBot b in botsList)
|
foreach (PlayerBot b in botsList) { Spawn(p, b); }
|
||||||
if (b.level == p.level) Spawn(p, b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Despawns this player to all other players, and despawns all others players to this player. </summary>
|
/// <summary> Despawns this player to all other players, and despawns all others players to this player. </summary>
|
||||||
@ -127,10 +126,8 @@ namespace MCGalaxy {
|
|||||||
GlobalDespawn(p, true, true);
|
GlobalDespawn(p, true, true);
|
||||||
|
|
||||||
if (!bots) return;
|
if (!bots) return;
|
||||||
PlayerBot[] botsList = PlayerBot.Bots.Items;
|
PlayerBot[] botsList = p.level.Bots.Items;
|
||||||
foreach (PlayerBot b in botsList) {
|
foreach (PlayerBot b in botsList) { Despawn(p, b); }
|
||||||
if (p.level == b.level) Despawn(p, b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void Spawn(Player dst, PlayerBot b) {
|
internal static void Spawn(Player dst, PlayerBot b) {
|
||||||
|
@ -42,6 +42,7 @@ namespace MCGalaxy {
|
|||||||
public BlockDefinition[] CustomBlockDefs = new BlockDefinition[Block.Count];
|
public BlockDefinition[] CustomBlockDefs = new BlockDefinition[Block.Count];
|
||||||
public BlockProps[] BlockProps = new BlockProps[Block.Count * 2];
|
public BlockProps[] BlockProps = new BlockProps[Block.Count * 2];
|
||||||
public ExtrasCollection Extras = new ExtrasCollection();
|
public ExtrasCollection Extras = new ExtrasCollection();
|
||||||
|
public VolatileArray<PlayerBot> Bots = new VolatileArray<PlayerBot>(false);
|
||||||
|
|
||||||
internal HandleDelete[] deleteHandlers = new HandleDelete[Block.Count * 2];
|
internal HandleDelete[] deleteHandlers = new HandleDelete[Block.Count * 2];
|
||||||
internal HandlePlace[] placeHandlers = new HandlePlace[Block.Count * 2];
|
internal HandlePlace[] placeHandlers = new HandlePlace[Block.Count * 2];
|
||||||
|
@ -339,7 +339,7 @@ namespace MCGalaxy {
|
|||||||
lvl.Config.jailroty = lvl.roty;
|
lvl.Config.jailroty = lvl.roty;
|
||||||
|
|
||||||
LoadMetadata(lvl);
|
LoadMetadata(lvl);
|
||||||
Bots.BotsFile.LoadBots(lvl);
|
MCGalaxy.Bots.BotsFile.LoadBots(lvl);
|
||||||
|
|
||||||
object locker = ThreadSafeCache.DBCache.GetLocker(name);
|
object locker = ThreadSafeCache.DBCache.GetLocker(name);
|
||||||
lock (locker) {
|
lock (locker) {
|
||||||
|
@ -78,7 +78,6 @@ namespace MCGalaxy {
|
|||||||
Player.players = PlayerInfo.Online.list;
|
Player.players = PlayerInfo.Online.list;
|
||||||
PlayerInfo.players = PlayerInfo.Online.list;
|
PlayerInfo.players = PlayerInfo.Online.list;
|
||||||
Server.levels = LevelInfo.Loaded.list;
|
Server.levels = LevelInfo.Loaded.list;
|
||||||
PlayerBot.playerbots = PlayerBot.Bots.list;
|
|
||||||
#pragma warning restore 0618
|
#pragma warning restore 0618
|
||||||
|
|
||||||
StartTime = DateTime.UtcNow;
|
StartTime = DateTime.UtcNow;
|
||||||
|
@ -36,18 +36,11 @@ namespace MCGalaxy {
|
|||||||
return award == null ? null : award.Name;
|
return award == null ? null : award.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Finds partial matches of 'name' against the list of all bots. </summary>
|
/// <summary> Finds partial matches of 'name' against the list of bots in same level as player. </summary>
|
||||||
public static PlayerBot FindBots(Player p, string name) {
|
public static PlayerBot FindBots(Player p, string name) {
|
||||||
int matches = 0;
|
int matches = 0;
|
||||||
return Find<PlayerBot>(p, name, out matches, PlayerBot.Bots.Items,
|
return Find<PlayerBot>(p, name, out matches, p.level.Bots.Items,
|
||||||
null, b => b.name, "bots");
|
b => b.level == p.level, b => b.name, "bots");
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Finds partial matches of 'name' against the list of bots in same level as player. </summary>
|
|
||||||
public static PlayerBot FindBotsInLevel(Player p, string name) {
|
|
||||||
int matches = 0;
|
|
||||||
return Find<PlayerBot>(p, name, out matches, PlayerBot.Bots.Items,
|
|
||||||
b => b.level == p.level, b => b.name, "bots in this level");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Find partial matches of 'name' against the list of loaded maps/levels. </summary>
|
/// <summary> Find partial matches of 'name' against the list of loaded maps/levels. </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user