From 723a6861a08335607718a90e2e56437dd10aef61 Mon Sep 17 00:00:00 2001 From: Putoo <290555932@qq.com> Date: Sat, 18 Jul 2026 11:24:44 +0800 Subject: [PATCH] 12121 --- .../logdb/db/game_fight_data.cs | 15 ++++- .../Interface/Fight/IGameFightService.cs | 5 +- .../Interface/User/IUnitUserService.cs | 1 + .../Service/Fight/GameFightService.cs | 32 ++++++++- .../Services/Service/User/UnitUserService.cs | 32 ++++++--- .../Application.Domain/Tool/Base/FightTool.cs | 65 +++++++++++++++++++ .../Controllers/Pub/FightController.cs | 37 +++++------ Web/src/config/BaseConfig.ts | 8 +-- Web/src/utility‌/FightTool.ts | 4 +- 9 files changed, 158 insertions(+), 41 deletions(-) create mode 100644 Service/Application.Domain/Tool/Base/FightTool.cs diff --git a/Service/Application.Domain.Entity/logdb/db/game_fight_data.cs b/Service/Application.Domain.Entity/logdb/db/game_fight_data.cs index 9871963..5e6fd63 100644 --- a/Service/Application.Domain.Entity/logdb/db/game_fight_data.cs +++ b/Service/Application.Domain.Entity/logdb/db/game_fight_data.cs @@ -62,12 +62,14 @@ namespace Application.Domain.Entity [SugarColumn(Length = 50, IsNullable = true)] public string? winCode { get; set; } + /// /// 胜利方 /// [SugarColumn(Length = 50, IsNullable = true)] public string? winUser { get; set; } + /// /// 经验 /// @@ -91,9 +93,16 @@ namespace Application.Domain.Entity /// [SugarColumn(IsNullable = true)] public string? award { get; set; } - - [SugarColumn(IsNullable = true)] + + [SugarColumn(IsNullable = true)] public string? pars { get; set; } + + /// + /// 预计用时 + /// + [SugarColumn(IsNullable = true)] + public long? dueTime { get; set; } + /// /// addTime /// @@ -112,4 +121,4 @@ namespace Application.Domain.Entity [SugarColumn(IsNullable = true)] public long? endTime { get; set; } } -} +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/Fight/IGameFightService.cs b/Service/Application.Domain/Services/Interface/Fight/IGameFightService.cs index 8974fe2..ef8b379 100644 --- a/Service/Application.Domain/Services/Interface/Fight/IGameFightService.cs +++ b/Service/Application.Domain/Services/Interface/Fight/IGameFightService.cs @@ -13,9 +13,9 @@ public interface IGameFightService Task RemoveFightHarm(string fightId, string userId); Task AddFight(string fightId, string areaCode, string keyId, string mainId, string code, string scene, string mapId, - string userId, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = ""); + string userId,long dueTime, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = ""); - Task SetFightWin(game_fight_data fightData, string winUser,bool setDefMap=true); + Task SetFightWin(game_fight_data fightData, string winUser, bool setDefMap=true); Task HandleFightData(); #endregion @@ -29,6 +29,7 @@ public interface IGameFightService Task RemoveFightGoods(string mapId, string mgId); Task AutoUseDrug(UserAttrModel user, game_fight_data fight); Task HandelFightEnd(string userId, List data); + Task ValidFight(game_fight_data fight, bool isBlack = true); #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/User/IUnitUserService.cs b/Service/Application.Domain/Services/Interface/User/IUnitUserService.cs index 0b8ae43..c72a6ac 100644 --- a/Service/Application.Domain/Services/Interface/User/IUnitUserService.cs +++ b/Service/Application.Domain/Services/Interface/User/IUnitUserService.cs @@ -12,6 +12,7 @@ public interface IUnitUserService Task UpdateUserNick(string userId, string nick); Task UpdateUserSex(string userId, string sex); Task UpdateUserSign(string userId, string sign); + Task BlackUser(string userId); #endregion #region 用户注册 diff --git a/Service/Application.Domain/Services/Service/Fight/GameFightService.cs b/Service/Application.Domain/Services/Service/Fight/GameFightService.cs index 1d4567c..277cdd5 100644 --- a/Service/Application.Domain/Services/Service/Fight/GameFightService.cs +++ b/Service/Application.Domain/Services/Service/Fight/GameFightService.cs @@ -94,7 +94,8 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa public async Task AddFight(string fightId, string areaCode, string keyId, string mainId, string code, string scene, string mapId, - string userId, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = "") + string userId, long dueTime, long exp = 0, long copper = 0, long petExp = 0, string award = "", + string pars = "") { long addTime = TimeExtend.GetTimeStampMilliseconds; long endTime = TimeExtend.GetTimeStampSeconds + 24 * 60 * 60; @@ -118,6 +119,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa petExp = petExp, award = award, pars = pars, + dueTime = dueTime, addTime = addTime, okTime = 0, endTime = endTime @@ -161,6 +163,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa return result; } + public async Task SetFightWin(game_fight_data fightData, string winUser, bool setDefMap = true) { bool result = false; @@ -379,6 +382,11 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa public async Task HandleFight(game_fight_data fightData) { + if (await ValidFight(fightData) == false) + { + return; + } + string winUser = fightData.winUser; string lowUser = fightData.userId == winUser ? fightData.mainId : fightData.userId; @@ -448,7 +456,6 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa await attrService.DeductUserExp(lowUser, 1, 1); //扣除1级 //设置回威尼斯 await mapService.UpdateUserOnMap(lowUser, "15_27"); - } } @@ -695,5 +702,26 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa await Task.CompletedTask; } + public async Task ValidFight(game_fight_data fight, bool isBlack = true) + { + bool result = true; + if (fight.dueTime > 0) + { + int diffTime = Convert.ToInt32(fight.okTime - fight.addTime); + if (diffTime < 3000) + { + result = diffTime >= fight.dueTime; + if (result == false && isBlack) //异常处理 + { + //封禁账号 + var userService = App.GetService(); + await userService.BlackUser(fight.userId); + } + } + } + + return result; + } + #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/User/UnitUserService.cs b/Service/Application.Domain/Services/Service/User/UnitUserService.cs index 6997195..11c4e73 100644 --- a/Service/Application.Domain/Services/Service/User/UnitUserService.cs +++ b/Service/Application.Domain/Services/Service/User/UnitUserService.cs @@ -4,7 +4,6 @@ namespace Application.Domain; public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUnitUserService, ITransient { - #region 用户信息 public async Task> GetUserDataByAccId(string accId) @@ -101,6 +100,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni return result; } + public async Task UpdateUserSex(string userId, string sex) { var db = DbClient.AsTenant().GetConnectionWithAttr(); @@ -113,6 +113,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni return result; } + public async Task UpdateUserSign(string userId, string sign) { var db = DbClient.AsTenant().GetConnectionWithAttr(); @@ -126,6 +127,21 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni return result; } + public async Task BlackUser(string userId) + { + string newToken = await GetToken(); + var db = DbClient.AsTenant().GetConnectionWithAttr(); + bool result = await db.Updateable().SetColumns(it => it.status == 0) + .SetColumns(it => it.token == newToken) + .Where(it => it.userId == userId).ExecuteCommandAsync() > 0; + if (result) + { + await ClearUserInfo(0, userId); + } + + return result; + } + #endregion #region 用户注册 @@ -186,7 +202,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni acc.cowry = 0; acc.gold = 0; db.Insertable(acc).AddQueue(); - + unit_user_data userData = new unit_user_data(); userData.userId = userId; userData.teach = 0; @@ -204,7 +220,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni unit_user_attr userAttr = GameTool.GetAttrData(1); userAttr.userId = userId; db.Insertable(userAttr).AddQueue(); - + //注册配置 unit_user_config config = new unit_user_config(); config.userId = userId; @@ -261,7 +277,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni onlineTime.monthTime = 0; onlineTime.totalTime = 0; db.Insertable(onlineTime).AddQueue(); - + //注册队伍 unit_user_team team = new unit_user_team(); team.userId = userId; @@ -271,9 +287,8 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni await db.SaveQueuesAsync(false); } - if (result)//注册各项后处理 + if (result) //注册各项后处理 { - } return result; @@ -330,7 +345,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni #endregion - #region 权限配置 + #region 权限配置 public async Task GetUserConfigInfo(string userId) { @@ -370,8 +385,8 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni case "MsgRole": result = (int)config.msgRole; break; - } + return result; } @@ -400,6 +415,5 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni return result; } - #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Tool/Base/FightTool.cs b/Service/Application.Domain/Tool/Base/FightTool.cs new file mode 100644 index 0000000..2ea14aa --- /dev/null +++ b/Service/Application.Domain/Tool/Base/FightTool.cs @@ -0,0 +1,65 @@ +namespace Application.Domain; + +public class FightTool +{ + /// + /// 攻击冷却时间 + /// + /// + /// + /// + /// + public static int GetFightCool(long atk, long def, List loads = null) + { + int result = 1000; + if (atk > def && def > 0) + { + decimal diff = atk - def; + decimal bl = diff / def; + result = Convert.ToInt32((1 - bl) * result); + result = result < 300 ? 300 : result; + result = result > 1000 ? 1000 : result; + } + + if (loads != null) + { + //麻痹状态增加冷却时间 + var atkCoolData = loads.Find(it => it.code == nameof(GameEnum.AttrCode.PalsyAtk)); + if (atkCoolData != null) + { + result = Convert.ToInt32(result * (1 + atkCoolData.count * 0.1M)); + } + } + + return result; + } + + /// + /// 战斗预计时间 + /// + /// + /// + /// + public static long GetFightDueTime(UserAttrModel atkUser, UserAttrModel defUser) + { + long result = 3 * 60 * 60 * 1000; + if (atkUser.minAtk > defUser.defense && defUser.defense > 0) + { + decimal harmRide = (atkUser.minAtk - defUser.defense) / defUser.defense; + harmRide = harmRide > 1.2M ? 1.2M : harmRide; + decimal fight_Harm = harmRide * atkUser.maxAtk; + if (fight_Harm >= defUser.blood) + { + return 0; + } + else + { + int cool = GetFightCool(atkUser.agility, defUser.agility); + int count = Convert.ToInt32(defUser.blood / fight_Harm); + result = count * cool; + } + } + + return result; + } +} \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Pub/FightController.cs b/Service/Application.Web/Controllers/Pub/FightController.cs index 99f5ab6..8ed18d9 100644 --- a/Service/Application.Web/Controllers/Pub/FightController.cs +++ b/Service/Application.Web/Controllers/Pub/FightController.cs @@ -83,10 +83,10 @@ public class FightController : ControllerBase pars = JsonConvert.SerializeObject(new { type = "Create", code = monster.code, par = monster.par }); } + var userAttr = await _attrService.GetUserAttrModel(userId, scene); var monsterInfo = await _monsterService.GetMonsterInfo(mainId); if (monsterInfo != null) { - var userAttr = await _attrService.GetUserAttrModel(userId, scene); //处理奖励和资源 exp = Convert.ToInt64(monsterInfo.exp * (1.0m + userAttr.addExp)); copper = Convert.ToInt64(monsterInfo.copper * (1.0m + userAttr.addGold)); @@ -102,7 +102,10 @@ public class FightController : ControllerBase } } - bool result = await _fightService.AddFight(fightId, areaCode, keyId, mainId, code, scene, mapId, userId, exp, + var otAttr = await _monsterService.GetMonsterAttrModel(keyId, mainId); + long dueTime = FightTool.GetFightDueTime(userAttr, otAttr); + bool result = await _fightService.AddFight(fightId, areaCode, keyId, mainId, code, scene, mapId, userId, + dueTime, exp, copper, petExp, award, pars); if (result) { @@ -174,8 +177,11 @@ public class FightController : ControllerBase long petExp = 0; string award = string.Empty; string pars = ""; + var userAttr = await _attrService.GetUserAttrModel(userId); + var otAttr = await _attrService.GetUserAttrModel(otUser.userId); + long dueTime = FightTool.GetFightDueTime(userAttr, otAttr); bool result = await _fightService.AddFight(fightId, areaCode, keyId, otUser.userId, code, onMapInfo.code, - onMapInfo.mapId, userId, exp, + onMapInfo.mapId, userId, dueTime, exp, copper, petExp, award, pars); if (result) { @@ -257,9 +263,10 @@ public class FightController : ControllerBase otAttr = await _attrService.GetUserAttrModel(fight.mainId, fight.scene); } + if (fightResult.result == 0) { - if (otAttr.blood >0) + if (otAttr.blood > 0) { myHarm = fightResult.myHarm; myHarm += await _fightService.GetUserFightHarm(userId); @@ -306,22 +313,8 @@ public class FightController : ControllerBase var myLoad = await _attrService.GetUserLoadState(userId); //冷却时间 - int cool = 1000; - if (myAttr.agility > otAttr.agility && otAttr.agility > 0) - { - decimal diff = myAttr.agility - otAttr.agility; - decimal bl = diff / otAttr.agility; - cool = Convert.ToInt32((1 - bl) * 1000.0m); - cool = cool < 10 ? 10 : cool; - cool = cool > 1000 ? 1000 : cool; - } + int cool = FightTool.GetFightCool(myAttr.agility, otAttr.agility); - //麻痹状态增加冷却时间 - var atkCoolData = myLoad.Find(it => it.code == nameof(GameEnum.AttrCode.PalsyAtk)); - if (atkCoolData != null) - { - cool = Convert.ToInt32(cool * (1 + atkCoolData.count * 0.1M)); - } int exitCopper = otAttr.lev * 5; //退出战斗需要的铜贝 var result = new @@ -638,8 +631,14 @@ public class FightController : ControllerBase return PoAction.Message("该战斗不可复刻挂机!"); } + if (await _fightService.ValidFight(fight,false) == false) + { + return PoAction.Message("异常的战斗,无法挂机!"); + } + var myAttr = await _attrService.GetUserAttrModel(userId, fight.scene); int diffTime = Convert.ToInt32(fight.okTime - fight.addTime); + diffTime = diffTime < 300 ? 300 : diffTime; decimal score = myAttr.score * 0.7M; bool result = await _hookService.StartOnHook(userId, fight.scene, (long)monster.copper, (long)monster.exp, monster.name, diff --git a/Web/src/config/BaseConfig.ts b/Web/src/config/BaseConfig.ts index 3f8dda4..300e453 100644 --- a/Web/src/config/BaseConfig.ts +++ b/Web/src/config/BaseConfig.ts @@ -2,8 +2,8 @@ 统一配置中心 */ export class BaseConfig { - // public static BaseUrl: string = 'https://localhost:7198' - // public static BaseMediaUrl: string = 'https://localhost:7198/' - public static BaseUrl:string="http://v3.pccsh.com"; - public static BaseMediaUrl:string="http://v3.pccsh.com"; + public static BaseUrl: string = 'https://localhost:7198' + public static BaseMediaUrl: string = 'https://localhost:7198/' + // public static BaseUrl:string="http://v3.pccsh.com"; + // public static BaseMediaUrl:string="http://v3.pccsh.com"; } diff --git a/Web/src/utility‌/FightTool.ts b/Web/src/utility‌/FightTool.ts index 152910c..6a856aa 100644 --- a/Web/src/utility‌/FightTool.ts +++ b/Web/src/utility‌/FightTool.ts @@ -84,7 +84,7 @@ export class FightTool { if (defUser.rebound > 0) { let reboundRide = defUser.rebound = atkUser.reboundLess; if (reboundRide > 0) { - atkHarm = defHarm * reboundRide; + atkHarm += defHarm * reboundRide; } } defHarm += 0 - atkUser.harm_Add;//额外伤害 @@ -92,7 +92,7 @@ export class FightTool { if (atkUser.atk_Next > 0) { if (this.randomTrigger(atkUser.atk_Next)) { defHarm = defHarm * 1.3; - atkHarm = atkHarm * 1.3; + atkHarm += atkHarm * 1.3; } } //免伤处理