优化使用和生成指令;提高练级奖励至两倍;添加控制台测试;

This commit is contained in:
milimoe 2025-07-16 00:04:14 +08:00
parent 4127d2ffdc
commit 485a8a0118
Signed by: milimoe
GPG Key ID: 9554D37E4B8991D0
4 changed files with 68 additions and 17 deletions

View File

@ -1401,10 +1401,10 @@ namespace Oshima.FunGame.OshimaServers.Service
int totalMinutes = (int)diff.TotalMinutes; int totalMinutes = (int)diff.TotalMinutes;
// 每分钟经验 // 每分钟经验
int experiencePerMinute = 1; int experiencePerMinute = 2;
// 最大练级时间 // 最大练级时间
int dailyTrainingMinutes = 1440; int dailyTrainingMinutes = 2880;
// 计算总经验奖励 // 计算总经验奖励
totalExperience = Math.Min(totalMinutes, dailyTrainingMinutes) * experiencePerMinute; totalExperience = Math.Min(totalMinutes, dailyTrainingMinutes) * experiencePerMinute;
@ -1419,25 +1419,25 @@ namespace Oshima.FunGame.OshimaServers.Service
if (trainingHours >= 8) if (trainingHours >= 8)
{ {
smallBookCount = Math.Min(1, trainingHours); smallBookCount = Math.Min(2, trainingHours);
} }
if (trainingHours >= 16) if (trainingHours >= 16)
{ {
mediumBookCount = Math.Min(1, (trainingHours - 16) / 1); mediumBookCount = Math.Min(2, (trainingHours - 16) / 1);
} }
if (trainingHours >= 24) if (trainingHours >= 24)
{ {
largeBookCount = Math.Min(1, (trainingHours - 24) / 1); largeBookCount = Math.Min(2, (trainingHours - 24) / 1);
} }
double TotalHR = Math.Min(character.MaxHP, character.HR * diff.TotalSeconds); double TotalHR = Math.Min(character.MaxHP, character.HR * 60 * (int)diff.TotalMinutes);
double TotalMR = Math.Min(character.MaxMP, character.MR * diff.TotalSeconds); double TotalMR = Math.Min(character.MaxMP, character.MR * 60 * (int)diff.TotalMinutes);
return $"练级时长:{totalMinutes} 分钟,{(isPre ? "" : "")}获得:{totalExperience} 点经验值,{smallBookCount} 本小经验书,{mediumBookCount} 本中经验书,{largeBookCount} 本大经验书。" + return $"练级时长:{totalMinutes} 分钟,{(isPre ? "" : "")}获得:{totalExperience} 点经验值,{smallBookCount} 本小经验书,{mediumBookCount} 本中经验书,{largeBookCount} 本大经验书。" +
$"回复角色 {TotalHR:0.##} 点生命值和 {TotalMR:0.##} 点魔法值。" + $"回复角色 {TotalHR:0.##} 点生命值和 {TotalMR:0.##} 点魔法值。" +
$"{(isPre ? " 1440 24" : "")}"; $"{(isPre ? " 2880 48" : "")}";
} }
public static string GetSkillLevelUpNeedy(int level) public static string GetSkillLevelUpNeedy(int level)

View File

@ -3271,7 +3271,7 @@ namespace Oshima.FunGame.WebAPI.Controllers
user.LastTime = DateTime.Now; user.LastTime = DateTime.Now;
pc.Add("user", user); pc.Add("user", user);
pc.SaveConfig(); pc.SaveConfig();
return $"角色 [{character}] 开始练级,请过一段时间后进行【练级结算】,时间越长奖励越丰盛!练级时间上限 1440 分钟24小时),超时将不会再产生收益,请按时领取奖励!"; return $"角色 [{character}] 开始练级,请过一段时间后进行【练级结算】,时间越长奖励越丰盛!练级时间上限 2880 分钟48小时),超时将不会再产生收益,请按时领取奖励!练级结束时,角色将根据练级总分钟数获得生命回复和魔法回复。";
} }
else else
{ {
@ -3318,8 +3318,8 @@ namespace Oshima.FunGame.WebAPI.Controllers
if (totalExperience > 0) if (totalExperience > 0)
{ {
character.EXP += totalExperience; character.EXP += totalExperience;
character.HP += character.HR * diff.TotalSeconds; character.HP += character.HR * 60 * (int)diff.TotalMinutes;
character.MP += character.MR * diff.TotalSeconds; character.MP += character.MR * 60 * (int)diff.TotalMinutes;
} }
for (int i = 0; i < smallBookCount; i++) for (int i = 0; i < smallBookCount; i++)

View File

@ -29,12 +29,54 @@ namespace Oshima.FunGame.WebAPI
public override string Author => OshimaGameModuleConstant.Author; public override string Author => OshimaGameModuleConstant.Author;
private IServiceScopeFactory? _serviceScopeFactory = null;
public override void ProcessInput(string input) public override void ProcessInput(string input)
{ {
// RainBOT 测试
using (IServiceScope? scope = _serviceScopeFactory?.CreateScope())
{
if (scope != null)
{
// 从作用域中获取 IServiceProvider
IServiceProvider serviceProvider = scope.ServiceProvider;
try
{
if (input.Trim() != "")
{
// 获取 RainBOTService 实例
RainBOTService bot = serviceProvider.GetRequiredService<RainBOTService>();
Controller.WriteLine("成功获取 RainBOTService 实例!");
ThirdPartyMessage message = new()
{
IsGroup = false,
AuthorOpenId = "1",
OpenId = "1",
Detail = input,
Id = "1",
Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
};
bool result = bot.Handler(message).GetAwaiter().GetResult();
if (!result || message.IsCompleted)
{
Controller.WriteLine(message.Result);
}
}
if (input == "test") if (input == "test")
{ {
//FunGameController controller = new(new Logger<FunGameController>(new LoggerFactory())); //FunGameController funGameController = serviceProvider.GetRequiredService<FunGameController>();
//Controller.WriteLine(Controller.JSON.GetObject<string>(controller.ShowDailyStore(1)) ?? "test"); //Controller.WriteLine(Controller.JSON.GetObject<string>(funGameController.ShowDailyStore(1)) ?? "test");
}
}
catch (Exception e)
{
Controller.Error(e);
}
}
} }
if (input == "testuser") if (input == "testuser")
@ -189,6 +231,15 @@ namespace Oshima.FunGame.WebAPI
WebAPIAuthenticator.WebAPICustomBearerTokenAuthenticator += CustomBearerTokenAuthenticator; WebAPIAuthenticator.WebAPICustomBearerTokenAuthenticator += CustomBearerTokenAuthenticator;
} }
public override void OnWebAPIStarted(params object[] objs)
{
if (objs.Length > 0 && objs[0] is WebApplication app)
{
_serviceScopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();
Controller.WriteLine("获取到IServiceScopeFactory");
}
}
private string CustomBearerTokenAuthenticator(string token) private string CustomBearerTokenAuthenticator(string token)
{ {
if (GeneralSettings.TokenList.Contains(token)) if (GeneralSettings.TokenList.Contains(token))

View File

@ -496,7 +496,7 @@ namespace Oshima.FunGame.WebAPI.Services
if (e.Detail.StartsWith("生成")) if (e.Detail.StartsWith("生成"))
{ {
e.UseNotice = false; e.UseNotice = false;
string pattern = @"生成\s*(\d+)\s*个\s*([\s\S]+)(?:\s*给\s*(\d+))"; string pattern = @"生成\s*(\d+)\s*个\s*([\s\S]+)(?:\s*给\s*(\d+))?";
Regex regex = new(pattern, RegexOptions.IgnoreCase); Regex regex = new(pattern, RegexOptions.IgnoreCase);
Match match = regex.Match(e.Detail); Match match = regex.Match(e.Detail);
@ -1385,7 +1385,7 @@ namespace Oshima.FunGame.WebAPI.Services
{ {
string detail = e.Detail.Replace("使用", "").Trim(); string detail = e.Detail.Replace("使用", "").Trim();
char[] chars = [',', ' ', '', '', ';']; char[] chars = [',', ' ', '', '', ';'];
string pattern = @"^\s*(?:(?<itemId>\d+)|(?<itemPart>[^\d\s].*?))\s*(?:(?<countPart>\d+)(?:\s+角色\s*(?<characterIds>[\d\s,;]*))?)?$"; string pattern = @"^\s*(?:(?<itemId>\d+)|(?<itemPart>[^\d\s].*?))(?:\s+(?<countPart>\d+))?(?:\s*角色\s*(?<characterIds>[\d\s,;]*))?$";
Match match = Regex.Match(detail, pattern); Match match = Regex.Match(detail, pattern);
if (match.Success) if (match.Success)
{ {