This commit is contained in:
Putoo
2026-07-05 18:51:01 +08:00
parent fdb16f5d91
commit a1dbce8a96
15 changed files with 468 additions and 47 deletions

View File

@@ -17,10 +17,11 @@ public class FightController : ControllerBase
private readonly IGameMapService _mapService;
private readonly IUnitUserAccService _accService;
private readonly IGameGoodsService _goodsService;
private readonly IUnitUserService _userService;
public FightController(IGameFightService fightService, IGameMonsterService monsterService,
IUnitUserAttrService attrService, IGameMapService mapService, IUnitUserAccService accService,
IGameGoodsService goodsService)
IGameGoodsService goodsService, IUnitUserService userService)
{
_fightService = fightService;
_monsterService = monsterService;
@@ -28,6 +29,7 @@ public class FightController : ControllerBase
_mapService = mapService;
_accService = accService;
_goodsService = goodsService;
_userService = userService;
}
/// <summary>
@@ -136,7 +138,7 @@ public class FightController : ControllerBase
return PoAction.Message("战斗结束", 100);
}
#region
#region
FightResultModel fightResult = new FightResultModel()
{
@@ -144,19 +146,20 @@ public class FightController : ControllerBase
};
if (!string.IsNullOrEmpty(parms.data))
{
fightResult = JsonConvert.DeserializeObject<FightResultModel>(parms.data);
fightResult = JsonConvert.DeserializeObject<FightResultModel>(parms.data);
}
#endregion
//更新攻击
if (fightResult.result == 0)
{
myHarm = fightResult.myHarm;
myHarm += await _fightService.GetUserFightHarm(userId);
otHarm = fightResult.otHarm;
await _attrService.UpdateUserBlood(userId, 1, fightResult.myHarm);
}
var myAttr = await _attrService.GetUserAttrModel(userId, fight.scene);
UserAttrModel otAttr = new UserAttrModel();
if (fight.code == nameof(GameEnum.FightCode.PVE))
@@ -172,19 +175,36 @@ public class FightController : ControllerBase
}
else
{
otAttr = await _attrService.GetUserAttrModel(fight.mainId, fight.scene);
if (fightResult.result == 0)
{
await _fightService.SetUserFightHarm(fight.mainId, fightResult.otHarm);
await _attrService.UpdateUserBlood(fight.mainId, 1, fightResult.otHarm);
}
otAttr = await _attrService.GetUserAttrModel(fight.mainId, fight.scene);
}
//结束战斗都此处直接返回
if (otAttr.blood < 1||myAttr.blood<1)
if (otAttr.blood < 1 || myAttr.blood < 1)
{
await _fightService.RemoveUserFight(userId, fightId);
if (otAttr.blood < 1)
{
await _fightService.SetFightWin(fight, userId);
}
else
{
await _fightService.SetFightWin(fight, fight.mainId);
}
await _fightService.RemoveUserFight(userId, fightId);
return PoAction.Message("战斗结束", 100);
}
else
{
//自动使用药品
}
//获取个人药品栏
var myDrug = await _attrService.GetUserDrug(userId);
//获取个人负面
@@ -192,7 +212,7 @@ public class FightController : ControllerBase
//冷却时间
int cool = 1000;
if (myAttr.agility > otAttr.agility&&otAttr.agility>0)
if (myAttr.agility > otAttr.agility && otAttr.agility > 0)
{
decimal diff = myAttr.agility - otAttr.agility;
decimal bl = diff / otAttr.agility;
@@ -206,10 +226,10 @@ public class FightController : ControllerBase
{
cool = Convert.ToInt32(cool * (1 + atkCoolData.count * 0.1M));
}
//更新伤害提示
int exitCopper = otAttr.lev * 5;
var result = new
{
@@ -274,6 +294,7 @@ public class FightController : ControllerBase
{
if (await _fightService.RemoveUserFight(userId, fightId))
{
await _fightService.SetFightWin(fight, fight.mainId);
await _fightService.RemoveFightHarm(fightId, userId); //移除伤害
var nextFight = myFight.FindAll(it => it != fightId);
string nextId = nextFight.Count > 0 ? nextFight[0] : "";
@@ -305,6 +326,7 @@ public class FightController : ControllerBase
{
return PoAction.Message("战斗不存在!");
}
var fight = await _fightService.GetFightInfo(fightId);
if (fight == null)
{
@@ -317,7 +339,7 @@ public class FightController : ControllerBase
await _fightService.RemoveUserFight(userId, fightId);
return PoAction.Message("战斗结束!");
}
var myDrug = await _attrService.GetUserDrug(userId);
var onDrug = myDrug.drug.Find(it => it.id == drugId);
if (onDrug == null)
@@ -355,7 +377,93 @@ public class FightController : ControllerBase
{
return PoAction.Message("药品使用失败!");
}
}
/// <summary>
/// 战斗信息
/// </summary>
/// <param name="fightId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetFightMsg(string fightId)
{
string userId = StateHelper.userId;
var myFight = await _fightService.GetUserFight(userId);
var fight = await _fightService.GetFightInfo(fightId);
if (fight == null)
{
return PoAction.Message("战斗不存在!");
}
if (fight.userId != userId)
{
return PoAction.Message("战斗不存在!");
}
if (fight.state == 0)
{
return PoAction.Message("战斗未完成", 100);
}
int isWin = 0;
if (fight.winUser == fight.mainId)
{
isWin = 0;
}
else if(fight.winUser==userId)
{
isWin = 1;
}
else
{
isWin = 2;
}
string otName = string.Empty;
if (isWin == 0)
{
if (fight.code == nameof(GameEnum.FightCode.PVP))
{
var userInfo = await _userService.GetUserInfoByUserId(fight.winUser);
otName = userInfo.nick;
}
else
{
var monsterInfo = await _monsterService.GetMonsterInfo(fight.winUser);
otName = monsterInfo.name;
}
}
else if (isWin == 1)
{
if (fight.code == nameof(GameEnum.FightCode.PVP))
{
var userInfo = await _userService.GetUserInfoByUserId(fight.mainId);
otName = userInfo.nick;
}
else
{
var monsterInfo = await _monsterService.GetMonsterInfo(fight.mainId);
otName = monsterInfo.name;
}
}
else
{
if (fight.winCode == nameof(UserEnum.AttrCode.Person))
{
var userInfo = await _userService.GetUserInfoByUserId(fight.winUser);
otName = userInfo.nick;
}
else
{
var monsterInfo = await _monsterService.GetMonsterInfo(fight.winUser);
otName = monsterInfo.name;
}
}
var myAttr = await _attrService.GetUserAttrModel(userId, fight.scene);
return PoAction.Ok(new { isWin, otName, blood = myAttr.blood, upBlood = myAttr.upBlood, fight });
}
}