diff --git a/OshimaMaps/AnonymousMap.cs b/OshimaMaps/AnonymousMap.cs index 78df925..a78675d 100644 --- a/OshimaMaps/AnonymousMap.cs +++ b/OshimaMaps/AnonymousMap.cs @@ -1,10 +1,11 @@ using Milimoe.FunGame.Core.Interface.Base; +using Milimoe.FunGame.Core.Interface.Base.Addons; using Milimoe.FunGame.Core.Library.Common.Addon; using Oshima.Core.Constant; namespace Oshima.FunGame.OshimaMaps { - public class AnonymousMap : GameMap + public class AnonymousMap : GameMap, IHotReloadAware { public override string Name => OshimaGameModuleConstant.AnonymousMap; @@ -28,5 +29,10 @@ namespace Oshima.FunGame.OshimaMaps map.Load(); return map; } + + public void OnBeforeUnload() + { + + } } } diff --git a/OshimaMaps/FastAutoMap.cs b/OshimaMaps/FastAutoMap.cs index ee02000..0ef5212 100644 --- a/OshimaMaps/FastAutoMap.cs +++ b/OshimaMaps/FastAutoMap.cs @@ -1,11 +1,12 @@ using Milimoe.FunGame.Core.Interface.Base; +using Milimoe.FunGame.Core.Interface.Base.Addons; using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Model; using Oshima.Core.Constant; namespace Oshima.FunGame.OshimaMaps { - public class FastAutoMap : GameMap + public class FastAutoMap : GameMap, IHotReloadAware { public override string Name => OshimaGameModuleConstant.FastAutoMap; @@ -35,5 +36,10 @@ namespace Oshima.FunGame.OshimaMaps return map; } + + public void OnBeforeUnload() + { + + } } } diff --git a/OshimaModules/Modules/CharacterModule.cs b/OshimaModules/Modules/CharacterModule.cs index 97b8564..f9b1cdd 100644 --- a/OshimaModules/Modules/CharacterModule.cs +++ b/OshimaModules/Modules/CharacterModule.cs @@ -1,11 +1,12 @@ using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; +using Milimoe.FunGame.Core.Interface.Base.Addons; using Oshima.Core.Constant; using Oshima.FunGame.OshimaModules.Characters; namespace Oshima.FunGame.OshimaModules { - public class CharacterModule : Milimoe.FunGame.Core.Library.Common.Addon.CharacterModule + public class CharacterModule : Milimoe.FunGame.Core.Library.Common.Addon.CharacterModule, IHotReloadAware { public override string Name => OshimaGameModuleConstant.Character; public override string Description => OshimaGameModuleConstant.Description; @@ -29,6 +30,11 @@ namespace Oshima.FunGame.OshimaModules } } + public void OnBeforeUnload() + { + + } + protected override Factory.EntityFactoryDelegate EntityFactory() { return (id, name, args) => diff --git a/OshimaModules/Modules/ItemModule.cs b/OshimaModules/Modules/ItemModule.cs index 4ce2fbf..cba11c1 100644 --- a/OshimaModules/Modules/ItemModule.cs +++ b/OshimaModules/Modules/ItemModule.cs @@ -1,11 +1,12 @@ using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; +using Milimoe.FunGame.Core.Interface.Base.Addons; using Oshima.Core.Constant; using Oshima.FunGame.OshimaModules.Items; namespace Oshima.FunGame.OshimaModules { - public class ItemModule : Milimoe.FunGame.Core.Library.Common.Addon.ItemModule + public class ItemModule : Milimoe.FunGame.Core.Library.Common.Addon.ItemModule, IHotReloadAware { public override string Name => OshimaGameModuleConstant.Item; public override string Description => OshimaGameModuleConstant.Description; @@ -29,6 +30,11 @@ namespace Oshima.FunGame.OshimaModules } } + public void OnBeforeUnload() + { + + } + protected override Factory.EntityFactoryDelegate ItemFactory() { return (id, name, args) => diff --git a/OshimaModules/Modules/SkillModule.cs b/OshimaModules/Modules/SkillModule.cs index 894e6bd..77100c6 100644 --- a/OshimaModules/Modules/SkillModule.cs +++ b/OshimaModules/Modules/SkillModule.cs @@ -1,5 +1,6 @@ using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; +using Milimoe.FunGame.Core.Interface.Base.Addons; using Milimoe.FunGame.Core.Library.Constant; using Oshima.Core.Constant; using Oshima.FunGame.OshimaModules.Effects.ItemEffects; @@ -9,7 +10,7 @@ using Oshima.FunGame.OshimaModules.Skills; namespace Oshima.FunGame.OshimaModules { - public class SkillModule : Milimoe.FunGame.Core.Library.Common.Addon.SkillModule + public class SkillModule : Milimoe.FunGame.Core.Library.Common.Addon.SkillModule, IHotReloadAware { public override string Name => OshimaGameModuleConstant.Skill; public override string Description => OshimaGameModuleConstant.Description; @@ -40,6 +41,11 @@ namespace Oshima.FunGame.OshimaModules General.GameplayEquilibriumConstant.UseMagicType = [MagicType.None]; } + public void OnBeforeUnload() + { + + } + protected override Factory.EntityFactoryDelegate SkillFactory() { return (id, name, args) => diff --git a/OshimaServers/AnonymousServer.cs b/OshimaServers/AnonymousServer.cs index cabe382..194fcc9 100644 --- a/OshimaServers/AnonymousServer.cs +++ b/OshimaServers/AnonymousServer.cs @@ -1,5 +1,6 @@ using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Interface.Base; +using Milimoe.FunGame.Core.Interface.Base.Addons; using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Library.Constant; using Oshima.Core.Configs; @@ -10,7 +11,7 @@ using TaskScheduler = Milimoe.FunGame.Core.Api.Utility.TaskScheduler; namespace Oshima.FunGame.OshimaServers { - public class AnonymousServer : GameModuleServer + public class AnonymousServer : GameModuleServer, IHotReloadAware { public override string Name => OshimaGameModuleConstant.Anonymous; @@ -99,85 +100,29 @@ namespace Oshima.FunGame.OshimaServers { foreach (ItemModule itemModule in loader.Items.Values) { - if (itemModule is OshimaModules.ItemModule items) + foreach (string key in itemModule.Items.Keys) { - foreach (string key in items.KnownItems.Keys) - { - Controller.WriteLine(key + ": " + items.KnownItems[key].BackgroundStory, LogLevel.Debug); - } + Controller.WriteLine(key + ": " + itemModule.Items[key].BackgroundStory, LogLevel.Debug); } } Controller.NewSQLHelper(); Controller.NewMailSender(); - FunGameConstant.InitFunGame(); - FunGameSimulation.InitFunGameSimulation(); - FunGameService.RefreshNotice(); - TaskScheduler.Shared.AddTask("重置每日运势", new TimeSpan(0, 0, 0), () => + } + + /// + /// 卸载前调用 + /// + /// + public void OnBeforeUnload() + { + GamingObjects.Clear(); + _ = Send(_clientModels, SocketMessageType.EndGame, Factory.GetRoom(), Factory.GetUser()); + IServerModel[] models = [.. _clientModels]; + foreach (IServerModel model in models) { - Controller.WriteLine("已重置所有人的今日运势"); - Daily.ClearDaily(); - // 刷新活动缓存 - FunGameService.GetEventCenter(null); - FunGameService.RefreshNotice(); - FunGameService.PreRefreshStore(); - }); - TaskScheduler.Shared.AddTask("上九", new TimeSpan(9, 0, 0), () => - { - Controller.WriteLine("重置物品交易冷却时间/刷新地区天气"); - _ = FunGameService.AllowSellAndTrade(); - _ = FunGameService.UpdateRegionWeather(); - }); - TaskScheduler.Shared.AddTask("下三", new TimeSpan(15, 0, 0), () => - { - Controller.WriteLine("重置物品交易冷却时间/刷新地区天气"); - _ = FunGameService.AllowSellAndTrade(); - _ = FunGameService.UpdateRegionWeather(); - }); - TaskScheduler.Shared.AddRecurringTask("刷新存档缓存", TimeSpan.FromMinutes(1), () => - { - FunGameService.RefreshSavedCache(); - FunGameService.RefreshClubData(); - Controller.WriteLine("读取 FunGame 存档缓存", LogLevel.Debug); - OnlineService.RoomsAutoDisband(); - Controller.WriteLine("清除空闲房间", LogLevel.Debug); - }, true); - TaskScheduler.Shared.AddTask("刷新每日任务", new TimeSpan(4, 0, 0), () => - { - // 刷新每日任务 - Task.Run(() => - { - FunGameService.RefreshDailyQuest(); - Controller.WriteLine("刷新每日任务"); - }); - Task.Run(() => - { - FunGameService.RefreshDailySignIn(); - Controller.WriteLine("刷新签到"); - }); - Task.Run(() => - { - FunGameService.RefreshStoreData(); - Controller.WriteLine("刷新商店"); - }); - Task.Run(() => - { - FunGameService.RefreshMarketData(); - Controller.WriteLine("刷新市场"); - }); - // 刷新活动缓存 - FunGameService.GetEventCenter(null); - FunGameService.RefreshNotice(); - }); - TaskScheduler.Shared.AddRecurringTask("刷新boss", TimeSpan.FromHours(1), () => - { - FunGameService.GenerateBoss(); - Controller.WriteLine("刷新boss"); - }, true); - TaskScheduler.Shared.AddRecurringTask("刷新活动缓存", TimeSpan.FromHours(4), () => - { - FunGameService.GetEventCenter(null); - Controller.WriteLine("刷新活动缓存"); - }, true); + model.NowGamingServer = null; + CloseAnonymousServer(model); + } } /// diff --git a/OshimaServers/FastAutoServer.cs b/OshimaServers/FastAutoServer.cs index 1a4b059..328cbb0 100644 --- a/OshimaServers/FastAutoServer.cs +++ b/OshimaServers/FastAutoServer.cs @@ -4,6 +4,7 @@ using Milimoe.FunGame.Core.Api.Transmittal; using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Interface.Base; +using Milimoe.FunGame.Core.Interface.Base.Addons; using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Model; @@ -14,7 +15,7 @@ using Oshima.FunGame.OshimaServers.Service; namespace Oshima.FunGame.OshimaServers { - public class FastAutoServer : GameModuleServer + public class FastAutoServer : GameModuleServer, IHotReloadAware { public override string Name => OshimaGameModuleConstant.FastAuto; public override string Description => OshimaGameModuleConstant.Description; @@ -375,5 +376,10 @@ namespace Oshima.FunGame.OshimaServers } } } + + public void OnBeforeUnload() + { + + } } } diff --git a/OshimaServers/OshimaServer.cs b/OshimaServers/OshimaServer.cs index af51a16..e87414f 100644 --- a/OshimaServers/OshimaServer.cs +++ b/OshimaServers/OshimaServer.cs @@ -1,5 +1,6 @@ using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Interface; +using Milimoe.FunGame.Core.Interface.Base.Addons; using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Library.Common.Event; using Oshima.Core; @@ -8,7 +9,7 @@ using Oshima.FunGame.OshimaServers.Service; namespace Oshima.FunGame.OshimaServers { - public class OshimaServer : ServerPlugin, IOpenStoreEvent + public class OshimaServer : ServerPlugin, IHotReloadAware, IOpenStoreEvent { public override string Name => OshimaGameModuleConstant.Server; @@ -20,10 +21,6 @@ namespace Oshima.FunGame.OshimaServers public override async void ProcessInput(string input) { - if (input == "fungametest") - { - await FunGameSimulation.StartSimulationGame(true, true); - } // OSM指令 if (input.StartsWith(".osm", StringComparison.CurrentCultureIgnoreCase)) { @@ -47,5 +44,10 @@ namespace Oshima.FunGame.OshimaServers { if (e.EventMsg != "") Controller.WriteLine(e.EventMsg, Milimoe.FunGame.Core.Library.Constant.LogLevel.Debug); } + + public void OnBeforeUnload() + { + + } } } diff --git a/OshimaWebAPI/OshimaWebAPI.cs b/OshimaWebAPI/OshimaWebAPI.cs index af900c4..204c93c 100644 --- a/OshimaWebAPI/OshimaWebAPI.cs +++ b/OshimaWebAPI/OshimaWebAPI.cs @@ -4,22 +4,26 @@ using Milimoe.FunGame.Core.Api.Transmittal; using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Interface; +using Milimoe.FunGame.Core.Interface.Base.Addons; using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Library.Common.Event; +using Milimoe.FunGame.Core.Library.Constant; using Oshima.Core.Configs; using Oshima.Core.Constant; using Oshima.FunGame.OshimaModules.Characters; using Oshima.FunGame.OshimaModules.Items; +using Oshima.FunGame.OshimaModules.Models; using Oshima.FunGame.OshimaServers.Service; using Oshima.FunGame.WebAPI.Constant; using Oshima.FunGame.WebAPI.Controllers; using Oshima.FunGame.WebAPI.Models; using Oshima.FunGame.WebAPI.Services; using ProjectRedbud.FunGame.SQLQueryExtension; +using TaskScheduler = Milimoe.FunGame.Core.Api.Utility.TaskScheduler; namespace Oshima.FunGame.WebAPI { - public class OshimaWebAPI : WebAPIPlugin, ILoginEvent + public class OshimaWebAPI : WebAPIPlugin, IHotReloadAware, ILoginEvent { public override string Name => OshimaGameModuleConstant.WebAPI; @@ -224,6 +228,86 @@ namespace Oshima.FunGame.WebAPI builder.Services.Configure(builder.Configuration.GetSection("Bot")); } WebAPIAuthenticator.WebAPICustomBearerTokenAuthenticator += CustomBearerTokenAuthenticator; + FunGameConstant.InitFunGame(); + FunGameSimulation.InitFunGameSimulation(); + FunGameService.RefreshNotice(); + TaskScheduler.Shared.AddTask("重置每日运势", new TimeSpan(0, 0, 0), () => + { + Controller.WriteLine("已重置所有人的今日运势"); + Daily.ClearDaily(); + // 刷新活动缓存 + FunGameService.GetEventCenter(null); + FunGameService.RefreshNotice(); + FunGameService.PreRefreshStore(); + }); + TaskScheduler.Shared.AddTask("上九", new TimeSpan(9, 0, 0), () => + { + Controller.WriteLine("重置物品交易冷却时间/刷新地区天气"); + _ = FunGameService.AllowSellAndTrade(); + _ = FunGameService.UpdateRegionWeather(); + }); + TaskScheduler.Shared.AddTask("下三", new TimeSpan(15, 0, 0), () => + { + Controller.WriteLine("重置物品交易冷却时间/刷新地区天气"); + _ = FunGameService.AllowSellAndTrade(); + _ = FunGameService.UpdateRegionWeather(); + }); + TaskScheduler.Shared.AddRecurringTask("刷新存档缓存", TimeSpan.FromMinutes(1), () => + { + FunGameService.RefreshSavedCache(); + FunGameService.RefreshClubData(); + Controller.WriteLine("读取 FunGame 存档缓存", LogLevel.Debug); + OnlineService.RoomsAutoDisband(); + Controller.WriteLine("清除空闲房间", LogLevel.Debug); + }, true); + TaskScheduler.Shared.AddTask("刷新每日任务", new TimeSpan(4, 0, 0), () => + { + // 刷新每日任务 + Task.Run(() => + { + FunGameService.RefreshDailyQuest(); + Controller.WriteLine("刷新每日任务"); + }); + Task.Run(() => + { + FunGameService.RefreshDailySignIn(); + Controller.WriteLine("刷新签到"); + }); + Task.Run(() => + { + FunGameService.RefreshStoreData(); + Controller.WriteLine("刷新商店"); + }); + Task.Run(() => + { + FunGameService.RefreshMarketData(); + Controller.WriteLine("刷新市场"); + }); + // 刷新活动缓存 + FunGameService.GetEventCenter(null); + FunGameService.RefreshNotice(); + }); + TaskScheduler.Shared.AddRecurringTask("刷新boss", TimeSpan.FromHours(1), () => + { + FunGameService.GenerateBoss(); + Controller.WriteLine("刷新boss"); + }, true); + TaskScheduler.Shared.AddRecurringTask("刷新活动缓存", TimeSpan.FromHours(4), () => + { + FunGameService.GetEventCenter(null); + Controller.WriteLine("刷新活动缓存"); + }, true); + } + + public void OnBeforeUnload() + { + TaskScheduler.Shared.RemoveTask("重置每日运势"); + TaskScheduler.Shared.RemoveTask("上九"); + TaskScheduler.Shared.RemoveTask("下三"); + TaskScheduler.Shared.RemoveTask("刷新存档缓存"); + TaskScheduler.Shared.RemoveTask("刷新每日任务"); + TaskScheduler.Shared.RemoveTask("刷新boss"); + TaskScheduler.Shared.RemoveTask("刷新活动缓存"); } public override void OnWebAPIStarted(params object[] objs)