12121
This commit is contained in:
@@ -15,14 +15,19 @@ public class FightController : ControllerBase
|
||||
private readonly IGameMonsterService _monsterService;
|
||||
private readonly IUnitUserAttrService _attrService;
|
||||
private readonly IGameMapService _mapService;
|
||||
private readonly IUnitUserAccService _accService;
|
||||
private readonly IGameGoodsService _goodsService;
|
||||
|
||||
public FightController(IGameFightService fightService, IGameMonsterService monsterService,
|
||||
IUnitUserAttrService attrService, IGameMapService mapService)
|
||||
IUnitUserAttrService attrService, IGameMapService mapService, IUnitUserAccService accService,
|
||||
IGameGoodsService goodsService)
|
||||
{
|
||||
_fightService = fightService;
|
||||
_monsterService = monsterService;
|
||||
_attrService = attrService;
|
||||
_mapService = mapService;
|
||||
_accService = accService;
|
||||
_goodsService = goodsService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,20 +73,21 @@ public class FightController : ControllerBase
|
||||
areaCode = monster.areaCode;
|
||||
pars = JsonConvert.SerializeObject(new { type = "Create", code = monster.code, par = monster.par });
|
||||
}
|
||||
|
||||
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)) ;
|
||||
exp = Convert.ToInt64(monsterInfo.exp * (1.0m + userAttr.addExp));
|
||||
copper = Convert.ToInt64(monsterInfo.copper * (1.0m + userAttr.addGold));
|
||||
petExp = (long)monsterInfo.petExp;
|
||||
if (!string.IsNullOrEmpty(monsterInfo.award))//生成奖励
|
||||
if (!string.IsNullOrEmpty(monsterInfo.award)) //生成奖励
|
||||
{
|
||||
var awardModel = JsonConvert.DeserializeObject<MonsterAwardModel>(monsterInfo.award);
|
||||
if (awardModel.type == nameof(MonsterEnum.AwardCode.Default))
|
||||
{
|
||||
var getAward = GameBus.GetRandomGoods(awardModel.award, 1,userAttr.burst);
|
||||
var getAward = GameBus.GetRandomGoods(awardModel.award, 1, userAttr.burst);
|
||||
award = JsonConvert.SerializeObject(new FightAwardModel() { code = "Default", award = getAward });
|
||||
}
|
||||
}
|
||||
@@ -99,9 +105,257 @@ public class FightController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 战斗接口
|
||||
/// </summary>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> Fight([FromBody] FightParms parms)
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
string userId = StateHelper.userId;
|
||||
string fightId = parms.fightId;
|
||||
int myHarm = 0;
|
||||
int otHarm = 0;
|
||||
var myFight = await _fightService.GetUserFight(userId);
|
||||
if (myFight.Any(it => it == fightId) == false)
|
||||
{
|
||||
return PoAction.Message("战斗不存在!");
|
||||
}
|
||||
|
||||
var fight = await _fightService.GetFightInfo(fightId);
|
||||
if (fight == null)
|
||||
{
|
||||
await _fightService.RemoveUserFight(userId, fightId);
|
||||
return PoAction.Message("战斗不存在!");
|
||||
}
|
||||
|
||||
if (fight.state == 1)
|
||||
{
|
||||
await _fightService.RemoveUserFight(userId, fightId);
|
||||
return PoAction.Message("战斗结束", 100);
|
||||
}
|
||||
|
||||
#region 此处处理战斗
|
||||
|
||||
FightResultModel fightResult = new FightResultModel()
|
||||
{
|
||||
result = -1
|
||||
};
|
||||
if (!string.IsNullOrEmpty(parms.data))
|
||||
{
|
||||
fightResult = JsonConvert.DeserializeObject<FightResultModel>(parms.data);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
//更新攻击
|
||||
if (fightResult.result == 0)
|
||||
{
|
||||
myHarm = fightResult.myHarm;
|
||||
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))
|
||||
{
|
||||
otAttr = await _monsterService.GetMonsterAttrModel(fight.keyId, fight.mainId);
|
||||
if (fightResult.result == 0)
|
||||
{
|
||||
otAttr.blood = otAttr.blood + fightResult.otHarm;
|
||||
otAttr.blood = otAttr.blood < 0 ? 0 : otAttr.blood;
|
||||
otAttr.blood = otAttr.blood > otAttr.upBlood ? otAttr.upBlood : otAttr.blood;
|
||||
await _monsterService.SetMonsterBlood(fight.keyId, otAttr.blood);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
otAttr = await _attrService.GetUserAttrModel(fight.mainId, fight.scene);
|
||||
if (fightResult.result == 0)
|
||||
{
|
||||
await _attrService.UpdateUserBlood(fight.mainId, 1, fightResult.otHarm);
|
||||
}
|
||||
}
|
||||
|
||||
//结束战斗都此处直接返回
|
||||
if (otAttr.blood < 1||myAttr.blood<1)
|
||||
{
|
||||
await _fightService.RemoveUserFight(userId, fightId);
|
||||
return PoAction.Message("战斗结束", 100);
|
||||
}
|
||||
//获取个人药品栏
|
||||
var myDrug = await _attrService.GetUserDrug(userId);
|
||||
//获取个人负面
|
||||
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(bl * 1000.0m);
|
||||
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;
|
||||
var result = new
|
||||
{
|
||||
myHarm,
|
||||
otHarm,
|
||||
myAttr = myAttr,
|
||||
otAttr = otAttr,
|
||||
myDrug = myDrug.drug,
|
||||
myLoad = myLoad,
|
||||
exitCopper,
|
||||
cool,
|
||||
};
|
||||
return PoAction.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退出战斗
|
||||
/// </summary>
|
||||
/// <param name="fightId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> Exit(string fightId)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
var myFight = await _fightService.GetUserFight(userId);
|
||||
if (myFight.Any(it => it == fightId) == false)
|
||||
{
|
||||
return PoAction.Message("战斗不存在!");
|
||||
}
|
||||
|
||||
var fight = await _fightService.GetFightInfo(fightId);
|
||||
if (fight == null)
|
||||
{
|
||||
await _fightService.RemoveUserFight(userId, fightId);
|
||||
return PoAction.Message("战斗不存在!");
|
||||
}
|
||||
|
||||
if (fight.state == 1)
|
||||
{
|
||||
await _fightService.RemoveUserFight(userId, fightId);
|
||||
return PoAction.Message("战斗结束", 100);
|
||||
}
|
||||
|
||||
UserAttrModel otAttr = new UserAttrModel();
|
||||
if (fight.code == nameof(GameEnum.FightCode.PVE))
|
||||
{
|
||||
otAttr = await _monsterService.GetMonsterAttrModel(fight.keyId, fight.mainId);
|
||||
}
|
||||
else
|
||||
{
|
||||
otAttr = await _attrService.GetUserAttrModel(fight.mainId, fight.scene);
|
||||
}
|
||||
|
||||
int needCopper = otAttr.lev * 5;
|
||||
var myAcc = await _accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper));
|
||||
if (myAcc < needCopper)
|
||||
{
|
||||
return PoAction.Message("铜贝不足!", 101);
|
||||
}
|
||||
|
||||
if (await _accService.UpdateUserCopper(userId, 0, needCopper, "退出战斗"))
|
||||
{
|
||||
if (await _fightService.RemoveUserFight(userId, fightId))
|
||||
{
|
||||
await _fightService.RemoveFightHarm(fightId, userId); //移除伤害
|
||||
var nextFight = myFight.FindAll(it => it != fightId);
|
||||
string nextId = nextFight.Count > 0 ? nextFight[0] : "";
|
||||
return PoAction.Ok(nextId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("退出失败,请稍后尝试!", 101);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("退出失败,请稍后尝试!", 101);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用药品
|
||||
/// </summary>
|
||||
/// <param name="fightId"></param>
|
||||
/// <param name="drugId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> UseFightDrug(string fightId, string drugId)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
var myFight = await _fightService.GetUserFight(userId);
|
||||
if (myFight.Any(it => it == fightId) == false)
|
||||
{
|
||||
return PoAction.Message("战斗不存在!");
|
||||
}
|
||||
var fight = await _fightService.GetFightInfo(fightId);
|
||||
if (fight == null)
|
||||
{
|
||||
await _fightService.RemoveUserFight(userId, fightId);
|
||||
return PoAction.Message("战斗不存在!");
|
||||
}
|
||||
|
||||
if (fight.state == 1)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return PoAction.Message("药品不存在!");
|
||||
}
|
||||
|
||||
if (onDrug.count < 1)
|
||||
{
|
||||
return PoAction.Message("药品不足!");
|
||||
}
|
||||
|
||||
var drugConfig = await _goodsService.GetGoodsContent(onDrug.goodsId);
|
||||
string check = await _goodsService.CheckUseDrug(userId, onDrug.goodsId, drugConfig, fightId);
|
||||
if (!string.IsNullOrEmpty(check))
|
||||
{
|
||||
return PoAction.Message(check);
|
||||
}
|
||||
|
||||
foreach (var item in myDrug.drug)
|
||||
{
|
||||
if (item.id == drugId)
|
||||
{
|
||||
item.count = item.count - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (await _attrService.UpdateUserDrug(myDrug))
|
||||
{
|
||||
await _goodsService.UseDrug(userId, onDrug.goodsId, drugConfig, fightId);
|
||||
return PoAction.Ok("药品使用成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("药品使用失败!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user