This commit is contained in:
Putoo
2026-07-18 11:24:44 +08:00
parent e4d39f3f2f
commit 723a6861a0
9 changed files with 158 additions and 41 deletions

View File

@@ -62,12 +62,14 @@ namespace Application.Domain.Entity
[SugarColumn(Length = 50, IsNullable = true)] [SugarColumn(Length = 50, IsNullable = true)]
public string? winCode { get; set; } public string? winCode { get; set; }
/// <summary> /// <summary>
/// 胜利方 /// 胜利方
/// </summary> /// </summary>
[SugarColumn(Length = 50, IsNullable = true)] [SugarColumn(Length = 50, IsNullable = true)]
public string? winUser { get; set; } public string? winUser { get; set; }
/// <summary> /// <summary>
/// 经验 /// 经验
/// </summary> /// </summary>
@@ -94,6 +96,13 @@ namespace Application.Domain.Entity
[SugarColumn(IsNullable = true)] [SugarColumn(IsNullable = true)]
public string? pars { get; set; } public string? pars { get; set; }
/// <summary>
/// 预计用时
/// </summary>
[SugarColumn(IsNullable = true)]
public long? dueTime { get; set; }
/// <summary> /// <summary>
/// addTime /// addTime
/// </summary> /// </summary>

View File

@@ -13,9 +13,9 @@ public interface IGameFightService
Task RemoveFightHarm(string fightId, string userId); Task RemoveFightHarm(string fightId, string userId);
Task<bool> AddFight(string fightId, string areaCode, string keyId, string mainId, string code, Task<bool> AddFight(string fightId, string areaCode, string keyId, string mainId, string code,
string scene, string mapId, 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<bool> SetFightWin(game_fight_data fightData, string winUser,bool setDefMap=true); Task<bool> SetFightWin(game_fight_data fightData, string winUser, bool setDefMap=true);
Task HandleFightData(); Task HandleFightData();
#endregion #endregion
@@ -29,6 +29,7 @@ public interface IGameFightService
Task RemoveFightGoods(string mapId, string mgId); Task RemoveFightGoods(string mapId, string mgId);
Task AutoUseDrug(UserAttrModel user, game_fight_data fight); Task AutoUseDrug(UserAttrModel user, game_fight_data fight);
Task HandelFightEnd(string userId, List<FightRemoveData> data); Task HandelFightEnd(string userId, List<FightRemoveData> data);
Task<bool> ValidFight(game_fight_data fight, bool isBlack = true);
#endregion #endregion
} }

View File

@@ -12,6 +12,7 @@ public interface IUnitUserService
Task<bool> UpdateUserNick(string userId, string nick); Task<bool> UpdateUserNick(string userId, string nick);
Task<bool> UpdateUserSex(string userId, string sex); Task<bool> UpdateUserSex(string userId, string sex);
Task<bool> UpdateUserSign(string userId, string sign); Task<bool> UpdateUserSign(string userId, string sign);
Task<bool> BlackUser(string userId);
#endregion #endregion
#region #region

View File

@@ -94,7 +94,8 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
public async Task<bool> AddFight(string fightId, string areaCode, string keyId, string mainId, string code, public async Task<bool> AddFight(string fightId, string areaCode, string keyId, string mainId, string code,
string scene, string mapId, 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 addTime = TimeExtend.GetTimeStampMilliseconds;
long endTime = TimeExtend.GetTimeStampSeconds + 24 * 60 * 60; long endTime = TimeExtend.GetTimeStampSeconds + 24 * 60 * 60;
@@ -118,6 +119,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
petExp = petExp, petExp = petExp,
award = award, award = award,
pars = pars, pars = pars,
dueTime = dueTime,
addTime = addTime, addTime = addTime,
okTime = 0, okTime = 0,
endTime = endTime endTime = endTime
@@ -161,6 +163,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
return result; return result;
} }
public async Task<bool> SetFightWin(game_fight_data fightData, string winUser, bool setDefMap = true) public async Task<bool> SetFightWin(game_fight_data fightData, string winUser, bool setDefMap = true)
{ {
bool result = false; bool result = false;
@@ -379,6 +382,11 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
public async Task HandleFight(game_fight_data fightData) public async Task HandleFight(game_fight_data fightData)
{ {
if (await ValidFight(fightData) == false)
{
return;
}
string winUser = fightData.winUser; string winUser = fightData.winUser;
string lowUser = fightData.userId == winUser ? fightData.mainId : fightData.userId; 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 attrService.DeductUserExp(lowUser, 1, 1); //扣除1级
//设置回威尼斯 //设置回威尼斯
await mapService.UpdateUserOnMap(lowUser, "15_27"); await mapService.UpdateUserOnMap(lowUser, "15_27");
} }
} }
@@ -695,5 +702,26 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
await Task.CompletedTask; await Task.CompletedTask;
} }
public async Task<bool> 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<IUnitUserService>();
await userService.BlackUser(fight.userId);
}
}
}
return result;
}
#endregion #endregion
} }

View File

@@ -4,7 +4,6 @@ namespace Application.Domain;
public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUnitUserService, ITransient public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUnitUserService, ITransient
{ {
#region #region
public async Task<List<unit_user>> GetUserDataByAccId(string accId) public async Task<List<unit_user>> GetUserDataByAccId(string accId)
@@ -101,6 +100,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
return result; return result;
} }
public async Task<bool> UpdateUserSex(string userId, string sex) public async Task<bool> UpdateUserSex(string userId, string sex)
{ {
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>(); var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
@@ -113,6 +113,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
return result; return result;
} }
public async Task<bool> UpdateUserSign(string userId, string sign) public async Task<bool> UpdateUserSign(string userId, string sign)
{ {
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>(); var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
@@ -126,6 +127,21 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
return result; return result;
} }
public async Task<bool> BlackUser(string userId)
{
string newToken = await GetToken();
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
bool result = await db.Updateable<unit_user>().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 #endregion
#region #region
@@ -271,9 +287,8 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
await db.SaveQueuesAsync(false); await db.SaveQueuesAsync(false);
} }
if (result)//注册各项后处理 if (result) //注册各项后处理
{ {
} }
return result; return result;
@@ -330,7 +345,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
#endregion #endregion
#region #region
public async Task<unit_user_config> GetUserConfigInfo(string userId) public async Task<unit_user_config> GetUserConfigInfo(string userId)
{ {
@@ -370,8 +385,8 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
case "MsgRole": case "MsgRole":
result = (int)config.msgRole; result = (int)config.msgRole;
break; break;
} }
return result; return result;
} }
@@ -400,6 +415,5 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
return result; return result;
} }
#endregion #endregion
} }

View File

@@ -0,0 +1,65 @@
namespace Application.Domain;
public class FightTool
{
/// <summary>
/// 攻击冷却时间
/// </summary>
/// <param name="atk"></param>
/// <param name="def"></param>
/// <param name="loads"></param>
/// <returns></returns>
public static int GetFightCool(long atk, long def, List<unit_user_load> 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;
}
/// <summary>
/// 战斗预计时间
/// </summary>
/// <param name="atkUser"></param>
/// <param name="defUser"></param>
/// <returns></returns>
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;
}
}

View File

@@ -83,10 +83,10 @@ public class FightController : ControllerBase
pars = JsonConvert.SerializeObject(new { type = "Create", code = monster.code, par = monster.par }); 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); var monsterInfo = await _monsterService.GetMonsterInfo(mainId);
if (monsterInfo != null) if (monsterInfo != null)
{ {
var userAttr = await _attrService.GetUserAttrModel(userId, scene);
//处理奖励和资源 //处理奖励和资源
exp = Convert.ToInt64(monsterInfo.exp * (1.0m + userAttr.addExp)); exp = Convert.ToInt64(monsterInfo.exp * (1.0m + userAttr.addExp));
copper = Convert.ToInt64(monsterInfo.copper * (1.0m + userAttr.addGold)); 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); copper, petExp, award, pars);
if (result) if (result)
{ {
@@ -174,8 +177,11 @@ public class FightController : ControllerBase
long petExp = 0; long petExp = 0;
string award = string.Empty; string award = string.Empty;
string pars = ""; 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, 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); copper, petExp, award, pars);
if (result) if (result)
{ {
@@ -257,9 +263,10 @@ public class FightController : ControllerBase
otAttr = await _attrService.GetUserAttrModel(fight.mainId, fight.scene); otAttr = await _attrService.GetUserAttrModel(fight.mainId, fight.scene);
} }
if (fightResult.result == 0) if (fightResult.result == 0)
{ {
if (otAttr.blood >0) if (otAttr.blood > 0)
{ {
myHarm = fightResult.myHarm; myHarm = fightResult.myHarm;
myHarm += await _fightService.GetUserFightHarm(userId); myHarm += await _fightService.GetUserFightHarm(userId);
@@ -306,22 +313,8 @@ public class FightController : ControllerBase
var myLoad = await _attrService.GetUserLoadState(userId); var myLoad = await _attrService.GetUserLoadState(userId);
//冷却时间 //冷却时间
int cool = 1000; int cool = FightTool.GetFightCool(myAttr.agility, otAttr.agility);
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;
}
//麻痹状态增加冷却时间
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; //退出战斗需要的铜贝 int exitCopper = otAttr.lev * 5; //退出战斗需要的铜贝
var result = new var result = new
@@ -638,8 +631,14 @@ public class FightController : ControllerBase
return PoAction.Message("该战斗不可复刻挂机!"); return PoAction.Message("该战斗不可复刻挂机!");
} }
if (await _fightService.ValidFight(fight,false) == false)
{
return PoAction.Message("异常的战斗,无法挂机!");
}
var myAttr = await _attrService.GetUserAttrModel(userId, fight.scene); var myAttr = await _attrService.GetUserAttrModel(userId, fight.scene);
int diffTime = Convert.ToInt32(fight.okTime - fight.addTime); int diffTime = Convert.ToInt32(fight.okTime - fight.addTime);
diffTime = diffTime < 300 ? 300 : diffTime;
decimal score = myAttr.score * 0.7M; decimal score = myAttr.score * 0.7M;
bool result = await _hookService.StartOnHook(userId, fight.scene, (long)monster.copper, (long)monster.exp, bool result = await _hookService.StartOnHook(userId, fight.scene, (long)monster.copper, (long)monster.exp,
monster.name, monster.name,

View File

@@ -2,8 +2,8 @@
统一配置中心 统一配置中心
*/ */
export class BaseConfig { export class BaseConfig {
// public static BaseUrl: string = 'https://localhost:7198' public static BaseUrl: string = 'https://localhost:7198'
// public static BaseMediaUrl: string = 'https://localhost:7198/' public static BaseMediaUrl: string = 'https://localhost:7198/'
public static BaseUrl:string="http://v3.pccsh.com"; // public static BaseUrl:string="http://v3.pccsh.com";
public static BaseMediaUrl:string="http://v3.pccsh.com"; // public static BaseMediaUrl:string="http://v3.pccsh.com";
} }

View File

@@ -84,7 +84,7 @@ export class FightTool {
if (defUser.rebound > 0) { if (defUser.rebound > 0) {
let reboundRide = defUser.rebound = atkUser.reboundLess; let reboundRide = defUser.rebound = atkUser.reboundLess;
if (reboundRide > 0) { if (reboundRide > 0) {
atkHarm = defHarm * reboundRide; atkHarm += defHarm * reboundRide;
} }
} }
defHarm += 0 - atkUser.harm_Add;//额外伤害 defHarm += 0 - atkUser.harm_Add;//额外伤害
@@ -92,7 +92,7 @@ export class FightTool {
if (atkUser.atk_Next > 0) { if (atkUser.atk_Next > 0) {
if (this.randomTrigger(atkUser.atk_Next)) { if (this.randomTrigger(atkUser.atk_Next)) {
defHarm = defHarm * 1.3; defHarm = defHarm * 1.3;
atkHarm = atkHarm * 1.3; atkHarm += atkHarm * 1.3;
} }
} }
//免伤处理 //免伤处理