mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Move bots file to be per-level
This commit is contained in:
parent
2c05d65247
commit
2b245672d4
@ -16,59 +16,60 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using MCGalaxy.Maths;
|
using MCGalaxy.Maths;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace MCGalaxy.Bots {
|
namespace MCGalaxy.Bots {
|
||||||
|
|
||||||
/// <summary> Maintains persistent data for in-game bots. </summary>
|
/// <summary> Maintains persistent data for in-game bots. </summary>
|
||||||
public static class BotsFile {
|
public static class BotsFile {
|
||||||
|
|
||||||
public static List<BotProperties> SavedBots = new List<BotProperties>();
|
public static string BotsPath(string mapName) {
|
||||||
|
return "extra/bots/" + mapName + ".json";
|
||||||
|
}
|
||||||
|
|
||||||
static readonly object locker = new object();
|
public static void Load(Level lvl) {
|
||||||
|
string path = BotsPath(lvl.MapName);
|
||||||
|
if (!File.Exists(path)) return;
|
||||||
|
string json = File.ReadAllText(path);
|
||||||
|
BotProperties[] bots = JsonConvert.DeserializeObject<BotProperties[]>(json);
|
||||||
|
|
||||||
public static void Load() {
|
foreach (BotProperties props in bots) {
|
||||||
if (!File.Exists(Paths.BotsFile)) return;
|
if (String.IsNullOrEmpty(props.DisplayName)) {
|
||||||
lock (locker) {
|
props.DisplayName = props.Name;
|
||||||
string json = File.ReadAllText(Paths.BotsFile);
|
|
||||||
BotProperties[] bots = JsonConvert.DeserializeObject<BotProperties[]>(json);
|
|
||||||
SavedBots = new List<BotProperties>(bots);
|
|
||||||
|
|
||||||
foreach (BotProperties bot in SavedBots) {
|
|
||||||
if (String.IsNullOrEmpty(bot.DisplayName))
|
|
||||||
bot.DisplayName = bot.Name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerBot bot = new PlayerBot(props.Name, lvl);
|
||||||
|
props.ApplyTo(bot);
|
||||||
|
|
||||||
|
bot.ModelBB = AABB.ModelAABB(bot.Model, lvl);
|
||||||
|
LoadAi(props, bot);
|
||||||
|
PlayerBot.Add(bot, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Save() {
|
public static void Save(Level lvl) {
|
||||||
BotProperties[] bots = SavedBots.ToArray();
|
PlayerBot[] bots = lvl.Bots.Items;
|
||||||
string json = JsonConvert.SerializeObject(bots);
|
string path = BotsPath(lvl.MapName);
|
||||||
|
if (!File.Exists(path) && bots.Length == 0) return;
|
||||||
|
|
||||||
|
BotProperties[] props = new BotProperties[bots.Length];
|
||||||
|
for (int i = 0; i < props.Length; i++) {
|
||||||
|
BotProperties savedProps = new BotProperties();
|
||||||
|
savedProps.FromBot(bots[i]);
|
||||||
|
props[i] = savedProps;
|
||||||
|
}
|
||||||
|
|
||||||
|
string json = JsonConvert.SerializeObject(props);
|
||||||
try {
|
try {
|
||||||
File.WriteAllText(Paths.BotsFile, json);
|
File.WriteAllText(path, json);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.Log(LogType.Warning, "Failed to save bots file");
|
Logger.Log(LogType.Warning, "Failed to save bots file");
|
||||||
Logger.LogError(ex);
|
Logger.LogError(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadBots(Level lvl) {
|
|
||||||
lock (locker) {
|
|
||||||
foreach (BotProperties props in SavedBots) {
|
|
||||||
if (lvl.name != props.Level) continue;
|
|
||||||
PlayerBot bot = new PlayerBot(props.Name, lvl);
|
|
||||||
props.ApplyTo(bot);
|
|
||||||
|
|
||||||
bot.ModelBB = AABB.ModelAABB(bot.Model, lvl);
|
|
||||||
LoadAi(props, bot);
|
|
||||||
PlayerBot.Add(bot, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void LoadAi(BotProperties props, PlayerBot bot) {
|
static void LoadAi(BotProperties props, PlayerBot bot) {
|
||||||
if (String.IsNullOrEmpty(props.AI)) return;
|
if (String.IsNullOrEmpty(props.AI)) return;
|
||||||
try {
|
try {
|
||||||
@ -78,96 +79,7 @@ namespace MCGalaxy.Bots {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bot.cur = props.CurInstruction;
|
bot.cur = props.CurInstruction;
|
||||||
if (bot.cur >= bot.Instructions.Count)
|
if (bot.cur >= bot.Instructions.Count) bot.cur = 0;
|
||||||
bot.cur = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void UnloadBots(Level lvl) {
|
|
||||||
lock (locker) {
|
|
||||||
PlayerBot[] bots = lvl.Bots.Items;
|
|
||||||
|
|
||||||
foreach (PlayerBot bot in bots) {
|
|
||||||
DoUpdateBot(bot, false);
|
|
||||||
}
|
|
||||||
if (bots.Length > 0) Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveBot(PlayerBot bot) {
|
|
||||||
lock (locker) {
|
|
||||||
for (int i = 0; i < SavedBots.Count; i++) {
|
|
||||||
BotProperties props = SavedBots[i];
|
|
||||||
if (bot.name != props.Name || bot.level.name != props.Level) continue;
|
|
||||||
SavedBots.RemoveAt(i);
|
|
||||||
Save();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Deletes all bots which are located on the given map. </summary>
|
|
||||||
public static void DeleteBots(string level) {
|
|
||||||
lock (locker) {
|
|
||||||
int removed = 0;
|
|
||||||
for (int i = 0; i < SavedBots.Count; i++) {
|
|
||||||
BotProperties props = SavedBots[i];
|
|
||||||
if (!props.Level.CaselessEq(level)) continue;
|
|
||||||
|
|
||||||
SavedBots.RemoveAt(i);
|
|
||||||
removed++; i--;
|
|
||||||
}
|
|
||||||
if (removed > 0) Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Moves all bots located on the given source map to the destination map. </summary>
|
|
||||||
public static void MoveBots(string srcLevel, string dstLevel) {
|
|
||||||
lock (locker) {
|
|
||||||
int moved = 0;
|
|
||||||
for (int i = 0; i < SavedBots.Count; i++) {
|
|
||||||
BotProperties props = SavedBots[i];
|
|
||||||
if (!props.Level.CaselessEq(srcLevel)) continue;
|
|
||||||
|
|
||||||
props.Level = dstLevel;
|
|
||||||
moved++;
|
|
||||||
}
|
|
||||||
if (moved > 0) Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Copies all bots located on the given source map to the destination map. </summary>
|
|
||||||
public static void CopyBots(string srcLevel, string dstLevel) {
|
|
||||||
lock (locker) {
|
|
||||||
int copied = 0, count = SavedBots.Count;
|
|
||||||
for (int i = 0; i < SavedBots.Count; i++) {
|
|
||||||
BotProperties props = SavedBots[i];
|
|
||||||
if (!props.Level.CaselessEq(srcLevel)) continue;
|
|
||||||
|
|
||||||
BotProperties copy = props.Copy();
|
|
||||||
copy.Level = dstLevel;
|
|
||||||
SavedBots.Add(copy);
|
|
||||||
copied++;
|
|
||||||
}
|
|
||||||
if (copied > 0) Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void UpdateBot(PlayerBot bot) {
|
|
||||||
lock (locker) DoUpdateBot(bot, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void DoUpdateBot(PlayerBot bot, bool save) {
|
|
||||||
foreach (BotProperties props in SavedBots) {
|
|
||||||
if (bot.name != props.Name || bot.level.name != props.Level) continue;
|
|
||||||
props.FromBot(bot);
|
|
||||||
if (save) Save();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BotProperties newProps = new BotProperties();
|
|
||||||
newProps.FromBot(bot);
|
|
||||||
SavedBots.Add(newProps);
|
|
||||||
if (save) Save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using MCGalaxy.Bots;
|
using MCGalaxy.Bots;
|
||||||
using MCGalaxy.Maths;
|
using MCGalaxy.Maths;
|
||||||
using MCGalaxy.Network;
|
using MCGalaxy.Network;
|
||||||
@ -71,24 +72,24 @@ namespace MCGalaxy {
|
|||||||
public static void Add(PlayerBot bot, bool save = true) {
|
public static void Add(PlayerBot bot, bool save = true) {
|
||||||
bot.level.Bots.Add(bot);
|
bot.level.Bots.Add(bot);
|
||||||
bot.GlobalSpawn();
|
bot.GlobalSpawn();
|
||||||
if (save) BotsFile.UpdateBot(bot);
|
if (save) BotsFile.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Remove(PlayerBot bot, bool save = true) {
|
public static void Remove(PlayerBot bot, bool save = true) {
|
||||||
bot.level.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.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UnloadFromLevel(Level lvl) {
|
public static void UnloadFromLevel(Level lvl) {
|
||||||
BotsFile.UnloadBots(lvl);
|
BotsFile.Save(lvl);
|
||||||
RemoveLoadedBots(lvl, false);
|
RemoveLoadedBots(lvl, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveAllFromLevel(Level lvl) {
|
public static void RemoveAllFromLevel(Level lvl) {
|
||||||
RemoveLoadedBots(lvl, true);
|
RemoveLoadedBots(lvl, false);
|
||||||
BotsFile.DeleteBots(lvl.name);
|
BotsFile.Save(lvl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RemoveLoadedBots(Level lvl, bool save) {
|
static void RemoveLoadedBots(Level lvl, bool save) {
|
||||||
|
@ -102,7 +102,7 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
Player.Message(p, "Set text shown when bot {0} %Sis clicked on to {1}", bot.ColoredName, text);
|
Player.Message(p, "Set text shown when bot {0} %Sis clicked on to {1}", bot.ColoredName, text);
|
||||||
bot.ClickedOnText = text;
|
bot.ClickedOnText = text;
|
||||||
}
|
}
|
||||||
BotsFile.UpdateBot(bot);
|
BotsFile.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(Player p) {
|
public override void Help(Player p) {
|
||||||
|
@ -74,7 +74,7 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
static void UpdateBot(Player p, PlayerBot bot, string msg) {
|
static void UpdateBot(Player p, PlayerBot bot, string msg) {
|
||||||
Player.Message(p, bot.ColoredName + "%S" + msg);
|
Player.Message(p, bot.ColoredName + "%S" + msg);
|
||||||
Logger.Log(LogType.UserActivity, bot.name + msg);
|
Logger.Log(LogType.UserActivity, bot.name + msg);
|
||||||
BotsFile.UpdateBot(bot);
|
BotsFile.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(Player p) {
|
public override void Help(Player p) {
|
||||||
|
@ -36,7 +36,7 @@ namespace MCGalaxy.Commands.Bots {
|
|||||||
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);
|
||||||
BotsFile.UpdateBot(bot);
|
BotsFile.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(Player p) {
|
public override void Help(Player p) {
|
||||||
|
@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
|
|
||||||
protected override void SetBotData(Player p, PlayerBot bot, string args) {
|
protected override void SetBotData(Player p, PlayerBot bot, string args) {
|
||||||
if (!ParseArgs(p, args, bot)) return;
|
if (!ParseArgs(p, args, bot)) return;
|
||||||
BotsFile.UpdateBot(bot);
|
BotsFile.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetPlayerData(Player p, Player who, string args) {
|
protected override void SetPlayerData(Player p, Player who, string args) {
|
||||||
|
@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
Entities.UpdateModel(bot, model);
|
Entities.UpdateModel(bot, model);
|
||||||
|
|
||||||
Player.Message(p, "You changed the model of bot " + bot.ColoredName + " %Sto a &c" + model);
|
Player.Message(p, "You changed the model of bot " + bot.ColoredName + " %Sto a &c" + model);
|
||||||
BotsFile.UpdateBot(bot);
|
BotsFile.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetPlayerData(Player p, Player who, string model) {
|
protected override void SetPlayerData(Player p, Player who, string model) {
|
||||||
|
@ -43,7 +43,7 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
|
|
||||||
bot.GlobalDespawn();
|
bot.GlobalDespawn();
|
||||||
bot.GlobalSpawn();
|
bot.GlobalSpawn();
|
||||||
BotsFile.UpdateBot(bot);
|
BotsFile.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetPlayerData(Player p, Player who, string skin) {
|
protected override void SetPlayerData(Player p, Player who, string skin) {
|
||||||
|
@ -47,7 +47,7 @@ namespace MCGalaxy.Commands.Chatting {
|
|||||||
|
|
||||||
bot.GlobalDespawn();
|
bot.GlobalDespawn();
|
||||||
bot.GlobalSpawn();
|
bot.GlobalSpawn();
|
||||||
BotsFile.UpdateBot(bot);
|
BotsFile.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetPlayerData(Player p, Player who, string colName) {
|
protected override void SetPlayerData(Player p, Player who, string colName) {
|
||||||
|
@ -53,7 +53,7 @@ namespace MCGalaxy.Commands.Chatting {
|
|||||||
|
|
||||||
bot.GlobalDespawn();
|
bot.GlobalDespawn();
|
||||||
bot.GlobalSpawn();
|
bot.GlobalSpawn();
|
||||||
BotsFile.UpdateBot(bot);
|
BotsFile.Save(bot.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetPlayerData(Player p, Player who, string nick) {
|
protected override void SetPlayerData(Player p, Player who, string nick) {
|
||||||
|
@ -337,7 +337,7 @@ namespace MCGalaxy {
|
|||||||
lvl.Config.jailroty = lvl.roty;
|
lvl.Config.jailroty = lvl.roty;
|
||||||
|
|
||||||
LoadMetadata(lvl);
|
LoadMetadata(lvl);
|
||||||
MCGalaxy.Bots.BotsFile.LoadBots(lvl);
|
MCGalaxy.Bots.BotsFile.Load(lvl);
|
||||||
|
|
||||||
object locker = ThreadSafeCache.DBCache.GetLocker(name);
|
object locker = ThreadSafeCache.DBCache.GetLocker(name);
|
||||||
lock (locker) {
|
lock (locker) {
|
||||||
|
@ -41,13 +41,14 @@ namespace MCGalaxy {
|
|||||||
"blockdefs/lvl_" + dst + ".json");
|
"blockdefs/lvl_" + dst + ".json");
|
||||||
MoveIfExists("blockprops/lvl_" + src + ".txt",
|
MoveIfExists("blockprops/lvl_" + src + ".txt",
|
||||||
"blockprops/lvl_" + dst + ".txt");
|
"blockprops/lvl_" + dst + ".txt");
|
||||||
|
MoveIfExists(BotsFile.BotsPath(src),
|
||||||
|
BotsFile.BotsPath(dst));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MoveBackups(src, dst);
|
MoveBackups(src, dst);
|
||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
|
|
||||||
BotsFile.MoveBots(src, dst);
|
|
||||||
RenameDatabaseTables(src, dst);
|
RenameDatabaseTables(src, dst);
|
||||||
BlockDBFile.MoveBackingFile(src, dst);
|
BlockDBFile.MoveBackingFile(src, dst);
|
||||||
}
|
}
|
||||||
@ -132,8 +133,8 @@ namespace MCGalaxy {
|
|||||||
DeleteIfExists("levels/level properties/" + name + ".properties");
|
DeleteIfExists("levels/level properties/" + name + ".properties");
|
||||||
DeleteIfExists("blockdefs/lvl_" + name + ".json");
|
DeleteIfExists("blockdefs/lvl_" + name + ".json");
|
||||||
DeleteIfExists("blockprops/lvl_" + name + ".txt");
|
DeleteIfExists("blockprops/lvl_" + name + ".txt");
|
||||||
|
DeleteIfExists(BotsFile.BotsPath(name));
|
||||||
|
|
||||||
BotsFile.DeleteBots(name);
|
|
||||||
DeleteDatabaseTables(name);
|
DeleteDatabaseTables(name);
|
||||||
BlockDBFile.DeleteBackingFile(name);
|
BlockDBFile.DeleteBackingFile(name);
|
||||||
}
|
}
|
||||||
@ -217,8 +218,9 @@ namespace MCGalaxy {
|
|||||||
"blockdefs/lvl_" + dst + ".json");
|
"blockdefs/lvl_" + dst + ".json");
|
||||||
CopyIfExists("blockprops/lvl_" + src + ".txt",
|
CopyIfExists("blockprops/lvl_" + src + ".txt",
|
||||||
"blockprops/lvl_" + dst + ".txt");
|
"blockprops/lvl_" + dst + ".txt");
|
||||||
|
CopyIfExists(BotsFile.BotsPath(src),
|
||||||
|
BotsFile.BotsPath(dst));
|
||||||
|
|
||||||
BotsFile.CopyBots(src, dst);
|
|
||||||
CopyDatabaseTables(src, dst);
|
CopyDatabaseTables(src, dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +128,7 @@ namespace MCGalaxy {
|
|||||||
Background.QueueOnce(UpgradeTasks.UpgradeDBTimeSpent);
|
Background.QueueOnce(UpgradeTasks.UpgradeDBTimeSpent);
|
||||||
Background.QueueOnce(LoadPlayerLists);
|
Background.QueueOnce(LoadPlayerLists);
|
||||||
Background.QueueOnce(UpgradeTasks.UpgradeOldLockdown);
|
Background.QueueOnce(UpgradeTasks.UpgradeOldLockdown);
|
||||||
|
Background.QueueOnce(UpgradeTasks.UpgradeBots);
|
||||||
|
|
||||||
Background.QueueOnce(SetupSocket);
|
Background.QueueOnce(SetupSocket);
|
||||||
Background.QueueOnce(InitTimers);
|
Background.QueueOnce(InitTimers);
|
||||||
@ -163,6 +164,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
if (!Directory.Exists("extra")) Directory.CreateDirectory("extra");
|
if (!Directory.Exists("extra")) Directory.CreateDirectory("extra");
|
||||||
if (!Directory.Exists("extra/Waypoints")) Directory.CreateDirectory("extra/Waypoints");
|
if (!Directory.Exists("extra/Waypoints")) Directory.CreateDirectory("extra/Waypoints");
|
||||||
|
if (!Directory.Exists("extra/bots")) Directory.CreateDirectory("extra/bots");
|
||||||
if (!Directory.Exists("blockdefs")) Directory.CreateDirectory("blockdefs");
|
if (!Directory.Exists("blockdefs")) Directory.CreateDirectory("blockdefs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +194,6 @@ namespace MCGalaxy {
|
|||||||
zombie.LoadInfectMessages();
|
zombie.LoadInfectMessages();
|
||||||
Colors.LoadList();
|
Colors.LoadList();
|
||||||
Alias.Load();
|
Alias.Load();
|
||||||
Bots.BotsFile.Load();
|
|
||||||
BlockDefinition.LoadGlobal();
|
BlockDefinition.LoadGlobal();
|
||||||
ImagePalette.Load();
|
ImagePalette.Load();
|
||||||
|
|
||||||
|
@ -17,16 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Threading;
|
|
||||||
using MCGalaxy.Commands.World;
|
|
||||||
using MCGalaxy.Games;
|
|
||||||
using MCGalaxy.Generator;
|
|
||||||
using MCGalaxy.DB;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.IO;
|
||||||
|
using MCGalaxy.Bots;
|
||||||
|
using MCGalaxy.DB;
|
||||||
using MCGalaxy.SQL;
|
using MCGalaxy.SQL;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace MCGalaxy.Tasks {
|
namespace MCGalaxy.Tasks {
|
||||||
internal static class UpgradeTasks {
|
internal static class UpgradeTasks {
|
||||||
@ -182,6 +178,39 @@ namespace MCGalaxy.Tasks {
|
|||||||
File.WriteAllLines(Paths.TempRanksFile, lines);
|
File.WriteAllLines(Paths.TempRanksFile, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void UpgradeBots(SchedulerTask task) {
|
||||||
|
if (!File.Exists(Paths.BotsFile)) return;
|
||||||
|
string json = File.ReadAllText(Paths.BotsFile);
|
||||||
|
File.WriteAllText(Paths.BotsFile + ".bak", json);
|
||||||
|
Logger.Log(LogType.SystemActivity, "Making bots file per-level.. " +
|
||||||
|
"saved backup of global bots file to extra/bots.json.bak");
|
||||||
|
|
||||||
|
BotProperties[] bots = JsonConvert.DeserializeObject<BotProperties[]>(json);
|
||||||
|
Dictionary<string, List<BotProperties>> botsByLevel = new Dictionary<string, List<BotProperties>>();
|
||||||
|
|
||||||
|
foreach (BotProperties bot in bots) {
|
||||||
|
List<BotProperties> levelBots;
|
||||||
|
if (bot.Level == null || bot.Level.Length == 0) continue;
|
||||||
|
|
||||||
|
if (!botsByLevel.TryGetValue(bot.Level, out levelBots)) {
|
||||||
|
levelBots = new List<BotProperties>();
|
||||||
|
botsByLevel[bot.Level] = levelBots;
|
||||||
|
}
|
||||||
|
levelBots.Add(bot);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var kvp in botsByLevel) {
|
||||||
|
json = JsonConvert.SerializeObject(kvp.Value);
|
||||||
|
File.WriteAllText(BotsFile.BotsPath(kvp.Key), json);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Server.mainLevel.Bots.Count == 0) {
|
||||||
|
BotsFile.Load(Server.mainLevel);
|
||||||
|
}
|
||||||
|
File.Delete(Paths.BotsFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static void UpgradeDBTimeSpent(SchedulerTask task) {
|
internal static void UpgradeDBTimeSpent(SchedulerTask task) {
|
||||||
DataTable table = Database.Backend.GetRows(PlayerData.DBTable, "TimeSpent", "LIMIT 1");
|
DataTable table = Database.Backend.GetRows(PlayerData.DBTable, "TimeSpent", "LIMIT 1");
|
||||||
if (table.Rows.Count == 0) return; // no players
|
if (table.Rows.Count == 0) return; // no players
|
||||||
|
@ -36,7 +36,6 @@ namespace MCGalaxy {
|
|||||||
public const string WelcomeFile = "text/welcome.txt";
|
public const string WelcomeFile = "text/welcome.txt";
|
||||||
public const string JokerFile = "text/joker.txt";
|
public const string JokerFile = "text/joker.txt";
|
||||||
|
|
||||||
|
|
||||||
public const string BlockPermsFile = "properties/block.properties";
|
public const string BlockPermsFile = "properties/block.properties";
|
||||||
public const string CmdPermsFile = "properties/command.properties";
|
public const string CmdPermsFile = "properties/command.properties";
|
||||||
public const string CmdExtraPermsFile = "properties/ExtraCommandPermissions.properties";
|
public const string CmdExtraPermsFile = "properties/ExtraCommandPermissions.properties";
|
||||||
@ -44,7 +43,6 @@ namespace MCGalaxy {
|
|||||||
public const string ServerPropsFile = "properties/server.properties";
|
public const string ServerPropsFile = "properties/server.properties";
|
||||||
public const string RankPropsFile = "properties/ranks.properties";
|
public const string RankPropsFile = "properties/ranks.properties";
|
||||||
|
|
||||||
|
|
||||||
public const string BotsFile = "extra/bots.json";
|
public const string BotsFile = "extra/bots.json";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user