mirror of
https://github.com/oshima-studios/OshimaGameModule.git
synced 2025-12-05 08:09:04 +00:00
多线程访问优化
This commit is contained in:
parent
dee953ea7b
commit
6a8d584ea9
@ -25,12 +25,13 @@ namespace Oshima.FunGame.OshimaModules.Skills
|
||||
{
|
||||
public override long Id => Skill.Id;
|
||||
public override string Name => Skill.Name;
|
||||
public override string Description => $"敏捷提高 20% [ {敏捷提升:0.##} ] 点,然后将目前的力量补充到与敏捷持平,持续 {Duration:0.##} {GameplayEquilibriumConstant.InGameTime}。";
|
||||
public override string Description => $"敏捷提高 20% [ {敏捷提升:0.##} ] 点,然后将当前力量补充到敏捷的 {平衡系数 * 100:0.##}%{(Skill.Character != null ? $" [ {Skill.Character.AGI * 平衡系数:0.##} ]" : "")},持续 {Duration:0.##} {GameplayEquilibriumConstant.InGameTime}。";
|
||||
public override bool Durative => true;
|
||||
public override double Duration => 30;
|
||||
public override DispelledType DispelledType => DispelledType.CannotBeDispelled;
|
||||
|
||||
private double 敏捷提升 => 0.2 * Skill.Character?.BaseAGI ?? 0;
|
||||
private double 敏捷提升 => (0.2 * Skill.Character?.BaseAGI) ?? 0.2;
|
||||
private double 平衡系数 => 0.5 + 0.1 * (Skill.Level - 1);
|
||||
private double 本次提升的敏捷 = 0;
|
||||
private double 本次提升的力量 = 0;
|
||||
|
||||
@ -43,9 +44,10 @@ namespace Oshima.FunGame.OshimaModules.Skills
|
||||
本次提升的敏捷 = character.BaseAGI * 0.2;
|
||||
character.ExAGI += 本次提升的敏捷;
|
||||
本次提升的力量 = 0;
|
||||
if (character.STR < character.AGI)
|
||||
double 平衡敏捷 = character.AGI * 平衡系数;
|
||||
if (character.STR < 平衡敏捷)
|
||||
{
|
||||
本次提升的力量 = character.AGI - character.STR;
|
||||
本次提升的力量 = 平衡敏捷 - character.STR;
|
||||
character.ExSTR += 本次提升的力量;
|
||||
}
|
||||
character.Recovery(pastHP, pastMP, pastMaxHP, pastMaxMP);
|
||||
|
||||
@ -135,7 +135,7 @@ namespace Oshima.FunGame.OshimaServers
|
||||
foreach (string filePath in filePaths)
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(filePath);
|
||||
PluginConfig pc = FunGameService.GetUserConfig(fileName);
|
||||
PluginConfig pc = FunGameService.GetUserConfig(fileName, out _);
|
||||
if (pc.Count > 0)
|
||||
{
|
||||
User user = FunGameService.GetUser(pc);
|
||||
@ -161,7 +161,7 @@ namespace Oshima.FunGame.OshimaServers
|
||||
}
|
||||
if (updateQuest || updateExplore)
|
||||
{
|
||||
FunGameService.SetUserConfig(user.Id, pc, user);
|
||||
FunGameService.SetUserConfigAndReleaseSemaphoreSlim(user.Id, pc, user);
|
||||
}
|
||||
if (FunGameConstant.UserLastVisitStore.TryGetValue(user.Id, out LastStoreModel? value) && value != null && (DateTime.Now - value.LastTime).TotalMinutes > 2)
|
||||
{
|
||||
@ -205,7 +205,7 @@ namespace Oshima.FunGame.OshimaServers
|
||||
foreach (string filePath in filePaths)
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(filePath);
|
||||
PluginConfig pc = FunGameService.GetUserConfig(fileName);
|
||||
PluginConfig pc = FunGameService.GetUserConfig(fileName, out _);
|
||||
pc.Add("signed", false);
|
||||
pc.Add("logon", false);
|
||||
pc.Add("exploreTimes", FunGameConstant.MaxExploreTimes);
|
||||
@ -384,7 +384,7 @@ namespace Oshima.FunGame.OshimaServers
|
||||
|
||||
public string SCList(Dictionary<string, object> data)
|
||||
{
|
||||
string result = "";
|
||||
string result;
|
||||
|
||||
SQLHelper? sql = Controller.SQLHelper;
|
||||
if (sql != null)
|
||||
|
||||
@ -18,6 +18,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
public const int MaxExploreTimes = 60;
|
||||
public const int DrawCardReduce = 1000;
|
||||
public const int DrawCardReduce_Material = 5;
|
||||
public const int SemaphoreSlimTimeout = 5000;
|
||||
public static List<Character> Characters { get; } = [];
|
||||
public static List<Skill> Skills { get; } = [];
|
||||
public static List<Skill> PassiveSkills { get; } = [];
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using Milimoe.FunGame;
|
||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
@ -965,7 +966,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
tasks.Add(Task.Run(() =>
|
||||
{
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
|
||||
PluginConfig pc = GetUserConfig(fileNameWithoutExtension);
|
||||
PluginConfig pc = GetUserConfig(fileNameWithoutExtension, out _);
|
||||
if (pc.Count > 0)
|
||||
{
|
||||
User user = GetUser(pc);
|
||||
@ -982,7 +983,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
item.IsTradable = true;
|
||||
}
|
||||
}
|
||||
SetUserConfig(user.Id, pc, user, false);
|
||||
SetUserConfigAndReleaseSemaphoreSlim(user.Id, pc, user, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2016,7 +2017,13 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
if (daily is null)
|
||||
{
|
||||
// 生成每日商店
|
||||
daily = new($"{user.Username}的每日商店");
|
||||
daily = new($"{user.Username}的每日商店")
|
||||
{
|
||||
AutoRefresh = true,
|
||||
NextRefreshDate = DateTime.Today.AddHours(4),
|
||||
RefreshInterval = 1
|
||||
};
|
||||
daily.UpdateRefreshTime(daily.NextRefreshDate);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Item item;
|
||||
@ -3282,8 +3289,8 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
itemsTradeRecord.Add("offeree", offereeItems);
|
||||
itemsTradeRecord.SaveConfig();
|
||||
|
||||
SetUserConfig(user.Id, pc, user);
|
||||
SetUserConfig(user2.Id, pc2, user2);
|
||||
SetUserConfigAndReleaseSemaphoreSlim(user.Id, pc, user);
|
||||
SetUserConfigAndReleaseSemaphoreSlim(user2.Id, pc2, user2);
|
||||
|
||||
AddNotice(offer.Offeror, $"报价编号 {offerId} 已交易完成,请通过【查报价{offerId}】查询报价记录。");
|
||||
|
||||
@ -3960,7 +3967,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
|
||||
public static void ReleaseUserSemaphoreSlim(string key)
|
||||
{
|
||||
if (FunGameConstant.UserSemaphoreSlims.TryGetValue(key, out SemaphoreSlim? obj) && obj != null)
|
||||
if (FunGameConstant.UserSemaphoreSlims.TryGetValue(key, out SemaphoreSlim? obj) && obj != null && obj.CurrentCount == 0)
|
||||
{
|
||||
obj.Release();
|
||||
}
|
||||
@ -3968,37 +3975,40 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
|
||||
public static void ReleaseUserSemaphoreSlim(long uid) => ReleaseUserSemaphoreSlim(uid.ToString());
|
||||
|
||||
public static void SetUserConfig(string key, PluginConfig pc, User user, bool updateLastTime = true)
|
||||
public static void SetUserConfig(string key, PluginConfig pc, User user, bool updateLastTime = true, bool release = true)
|
||||
{
|
||||
if (updateLastTime) user.LastTime = DateTime.Now;
|
||||
pc.Add("user", user);
|
||||
pc.SaveConfig();
|
||||
if (FunGameConstant.UserSemaphoreSlims.TryGetValue(key, out SemaphoreSlim? obj) && obj != null)
|
||||
if (release && FunGameConstant.UserSemaphoreSlims.TryGetValue(key, out SemaphoreSlim? obj) && obj != null && obj.CurrentCount == 0)
|
||||
{
|
||||
obj.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetUserConfig(long uid, PluginConfig pc, User user, bool updateLastTime = true) => SetUserConfig(uid.ToString(), pc, user, updateLastTime);
|
||||
public static void SetUserConfigAndReleaseSemaphoreSlim(long uid, PluginConfig pc, User user, bool updateLastTime = true) => SetUserConfig(uid.ToString(), pc, user, updateLastTime);
|
||||
|
||||
public static void SetUserConfigButNotRelease(long uid, PluginConfig pc, User user, bool updateLastTime = true) => SetUserConfig(uid.ToString(), pc, user, updateLastTime, false);
|
||||
|
||||
public static PluginConfig GetUserConfig(string key)
|
||||
public static PluginConfig GetUserConfig(string key, out bool isTimeout)
|
||||
{
|
||||
if (FunGameConstant.UserSemaphoreSlims.TryGetValue(key, out SemaphoreSlim? obj) && obj != null)
|
||||
isTimeout = false;
|
||||
try
|
||||
{
|
||||
obj.Wait();
|
||||
SemaphoreSlim obj = FunGameConstant.UserSemaphoreSlims.GetOrAdd(key, _ => new SemaphoreSlim(1, 1));
|
||||
obj.Wait(FunGameConstant.SemaphoreSlimTimeout);
|
||||
PluginConfig pc = new("saved", key);
|
||||
pc.LoadConfig();
|
||||
return pc;
|
||||
}
|
||||
else
|
||||
catch
|
||||
{
|
||||
obj = new(1, 1);
|
||||
obj.Wait();
|
||||
FunGameConstant.UserSemaphoreSlims[key] = obj;
|
||||
isTimeout = true;
|
||||
return new("saved", "0");
|
||||
}
|
||||
PluginConfig pc = new("saved", key);
|
||||
pc.LoadConfig();
|
||||
return pc;
|
||||
}
|
||||
|
||||
public static PluginConfig GetUserConfig(long uid) => GetUserConfig(uid.ToString());
|
||||
public static PluginConfig GetUserConfig(long uid, out bool isTimeout) => GetUserConfig(uid.ToString(), out isTimeout);
|
||||
|
||||
public static bool CheckSemaphoreSlim(string key)
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -567,9 +567,9 @@ namespace Oshima.FunGame.WebAPI.Services
|
||||
}
|
||||
|
||||
if (e.Detail.StartsWith("生成"))
|
||||
{
|
||||
e.UseNotice = false;
|
||||
string pattern = @"生成\s*(\d+)\s*个\s*([\s\S]+)(?:\s*给\s*(\d+))?";
|
||||
{
|
||||
e.UseNotice = false;
|
||||
string pattern = @"生成\s*(\d+)\s*个\s*([^给\s]+)(?:\s*给\s*(\d+))?";
|
||||
Regex regex = new(pattern, RegexOptions.IgnoreCase);
|
||||
Match match = regex.Match(e.Detail);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user