From 578d6f23dbb8a1ee5a8975403182cea96c324d39 Mon Sep 17 00:00:00 2001 From: Putoo <290555932@qq.com> Date: Tue, 14 Jul 2026 16:23:20 +0800 Subject: [PATCH] 1212 --- .../Service/User/UnitUserAttrService.cs | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs b/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs index 04f2ed8..72c6ada 100644 --- a/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs +++ b/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs @@ -92,12 +92,13 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) : ExtendAttrData.AddRange(item.attr); } } + #endregion #region 加层处理 var otTemp = GameAttrTool.GetRoleAttrTemp(temp, ExtendAttrData); - + result = GameAttrTool.GetRoleAttrTempMerge(result, otTemp); //加层其他 result = GameAttrTool.GetRoleAttrTempMerge(result, temp); //加层其他 result.minAtk += minAtk; @@ -272,7 +273,6 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) : try { var db = DbClient.AsTenant().GetConnectionWithAttr(); - await DbClient.AsTenant().BeginTranAsync(); if (op == 0) //扣除经验 { result = await db.Updateable().SetColumns(it => it.exp == it.exp - exp) @@ -290,40 +290,44 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) : else //足够升级 { var myAttr = await GetUserAttr(userId); - int OnLev = (int)myAttr.lev + 1; - if (OnLev <= GameConfig.GameMaxLev) + int OnLev = (int)myAttr.lev; + if (OnLev >= GameConfig.GameMaxLev) { - long upExp = onExp - (long)MyExp.upExp; - decimal nextExp = GameTool.GetUserUpExp(OnLev); - result = await db.Updateable().SetColumns(it => it.exp == upExp) - .SetColumns(it => it.upExp == nextExp).Where(it => it.userId == userId) - .ExecuteCommandAsync() > 0; - if (result) //更新成功,更新各项属性 + return true; + } + + long upExp = (long)MyExp.upExp; + + while (onExp >= upExp) + { + if (OnLev < GameConfig.GameMaxLev) { - var data = GameTool.GetAttrData(OnLev); - result = await db.Updateable(data).Where(i => i.userId == userId) - .ExecuteCommandAsync() > 0; - IsUpUserAttr = result; + OnLev = OnLev + 1; + onExp -= upExp; + upExp = GameTool.GetUserUpExp(OnLev); + } + else + { + break; } } - else + + result = await db.Updateable().SetColumns(it => it.exp == onExp) + .SetColumns(it => it.upExp == upExp).Where(it => it.userId == userId) + .ExecuteCommandAsync() > 0; + if (result) //更新成功,更新各项属性 { - decimal maxOnExp = (decimal)MyExp.upExp - 1; - if ((decimal)MyExp.exp < maxOnExp) - { - result = await db.Updateable().SetColumns(it => it.exp == maxOnExp) - .Where(it => it.userId == userId).ExecuteCommandAsync() > 0; - } + var data = GameTool.GetAttrData(OnLev); + result = await db.Updateable(data).Where(i => i.userId == userId) + .ExecuteCommandAsync() > 0; + IsUpUserAttr = result; } } } - - await DbClient.AsTenant().CommitTranAsync(); } catch { result = false; - await DbClient.AsTenant().RollbackTranAsync(); } if (result && IsUpUserAttr) @@ -458,7 +462,6 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) : } - public async Task GetUserMaxVitality(string userId) { var OnLev = await GetUserLev(userId);