适配热更新功能

This commit is contained in:
milimoe 2026-02-03 23:39:50 +08:00
parent 1b54e5228a
commit f0c930e4d9
Signed by: milimoe
GPG Key ID: 9554D37E4B8991D0
9 changed files with 153 additions and 86 deletions

View File

@ -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()
{
}
}
}

View File

@ -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()
{
}
}
}

View File

@ -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<Character> EntityFactory()
{
return (id, name, args) =>

View File

@ -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<Item> ItemFactory()
{
return (id, name, args) =>

View File

@ -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<Skill> SkillFactory()
{
return (id, name, args) =>

View File

@ -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), () =>
}
/// <summary>
/// 卸载前调用
/// </summary>
/// <exception cref="NotImplementedException"></exception>
public void OnBeforeUnload()
{
Controller.WriteLine("已重置所有人的今日运势");
Daily.ClearDaily();
// 刷新活动缓存
FunGameService.GetEventCenter(null);
FunGameService.RefreshNotice();
FunGameService.PreRefreshStore();
});
TaskScheduler.Shared.AddTask("上九", new TimeSpan(9, 0, 0), () =>
GamingObjects.Clear();
_ = Send(_clientModels, SocketMessageType.EndGame, Factory.GetRoom(), Factory.GetUser());
IServerModel[] models = [.. _clientModels];
foreach (IServerModel model in models)
{
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);
}
}
/// <summary>

View File

@ -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()
{
}
}
}

View File

@ -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()
{
}
}
}

View File

@ -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<BotConfig>(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)