using Microsoft.AspNetCore.Mvc; namespace Application.Web.Controllers.Pub; /// /// 恢复接口 /// [Route("[controller]/[action]")] [ApiController] [Authorize] public class RecoverController : ControllerBase { private readonly IUnitUserAttrService _attrService; private readonly IGameMapService _mapService; private readonly IUnitUserAccService _accService; private readonly IGameEquService _equService; public RecoverController(IUnitUserAttrService attrService, IGameMapService mapService, IUnitUserAccService accService, IGameEquService equService) { _attrService = attrService; _mapService = mapService; _accService = accService; _equService = equService; } /// /// 恢复体力 /// /// /// [HttpGet] public async Task RecoverBlood(int npcId) { string userId = StateHelper.userId; #region NPC验证 var npcInfo = await _mapService.GetNpcInfo(npcId); if (npcInfo == null) { return PoAction.Message("Npc不存在!"); } if (npcInfo.status != 1) { return PoAction.Message("Npc不存在!"); } if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.RetBlood))) { return PoAction.Message("业务不可用!"); } var onMap = await _mapService.GetUserOnMapId(userId); if (npcInfo.mapId != onMap) { return PoAction.Message("Npc不存在!"); } #endregion var userAttr = await _attrService.GetUserAttrModel(userId); if (userAttr.blood >= userAttr.upBlood) { return PoAction.Message("体力满满,无需恢复!"); } bool result = await _attrService.UpdateUserBlood(userId, 2, userAttr.upBlood, true); if (result) { return PoAction.Ok(true); } else { return PoAction.Message("恢复失败,请稍后尝试!"); } } /// /// 恢复士气 /// /// /// [HttpGet] public async Task RecoverMorale(int npcId) { string userId = StateHelper.userId; #region NPC验证 var npcInfo = await _mapService.GetNpcInfo(npcId); if (npcInfo == null) { return PoAction.Message("Npc不存在!"); } if (npcInfo.status != 1) { return PoAction.Message("Npc不存在!"); } if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.RetMorale))) { return PoAction.Message("业务不可用!"); } var onMap = await _mapService.GetUserOnMapId(userId); if (npcInfo.mapId != onMap) { return PoAction.Message("Npc不存在!"); } #endregion if (await _attrService.CheackRecoverMorale(userId)) { return PoAction.Message("今天已恢复过士气啦!"); } var userAttr = await _attrService.GetUserAttrModel(userId); if (userAttr.morale >= userAttr.upMorale) { return PoAction.Message("士气满满,无需恢复!"); } bool result = await _attrService.UpdateUserMorale(userId, 2, userAttr.upMorale); if (result) { await _attrService.LockRecoverMorale(userId); return PoAction.Ok(true); } else { return PoAction.Message("恢复失败,请稍后尝试!"); } } /// /// 获取个人活力 /// /// [HttpGet] public async Task GetUserVigour() { string userId = StateHelper.userId; var data = await _attrService.GetUserVigourInfo(userId); long maxVigour = await _attrService.GetUserMaxVitality(userId); return PoAction.Ok(new { data, maxVigour }); } /// /// 恢复活力 /// /// /// [HttpGet] public async Task RecoverVigour(int npcId) { string userId = StateHelper.userId; #region NPC验证 var npcInfo = await _mapService.GetNpcInfo(npcId); if (npcInfo == null) { return PoAction.Message("Npc不存在!"); } if (npcInfo.status != 1) { return PoAction.Message("Npc不存在!"); } if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.RetVigour))) { return PoAction.Message("业务不可用!"); } var onMap = await _mapService.GetUserOnMapId(userId); if (npcInfo.mapId != onMap) { return PoAction.Message("Npc不存在!"); } #endregion var data = await _attrService.GetUserVigourInfo(userId); string time = TimeAssist.GetDateTimeYMDString(0); if (data.upTime == time) { return PoAction.Message("今天已恢复过活力啦!"); } long maxVitality = await _attrService.GetUserMaxVitality(userId); if (data.vitality >= maxVitality) { return PoAction.Message("活力满满,无需恢复!"); } bool result = await _attrService.UpdateUserVigour(userId, 2, maxVitality, time); if (result) { return PoAction.Ok(true); } else { return PoAction.Message("恢复失败,请稍后尝试!"); } } /// /// 获取恢复耐久的装备 /// /// /// [HttpGet] public async Task GetUserRecoverEqu(int npcId) { string userId = StateHelper.userId; #region NPC验证 var npcInfo = await _mapService.GetNpcInfo(npcId); if (npcInfo == null) { return PoAction.Message("Npc不存在!"); } if (npcInfo.status != 1) { return PoAction.Message("Npc不存在!"); } if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.RetEqu))) { return PoAction.Message("业务不可用!"); } var onMap = await _mapService.GetUserOnMapId(userId); if (npcInfo.mapId != onMap) { return PoAction.Message("Npc不存在!"); } #endregion int need = 0; var data = await _equService.GetUserOnEqu(userId); var needData = data.FindAll(it => it.isAppr == 1 && it.durability < it.maxdurability && it.useEndTime > TimeExtend.GetTimeStampSeconds); need = needData.Sum(it => (int)it.maxdurability - (int)it.durability); return PoAction.Ok(new { data, need }); } /// /// 恢复装备耐久 /// /// /// /// [HttpGet] public async Task RecoverEqu(int npcId, string? ueId) { string userId = StateHelper.userId; #region NPC验证 var npcInfo = await _mapService.GetNpcInfo(npcId); if (npcInfo == null) { return PoAction.Message("Npc不存在!"); } if (npcInfo.status != 1) { return PoAction.Message("Npc不存在!"); } if (!npcInfo.bus.Any(it => it.code == nameof(GameEnum.NpcBusCode.RetEqu))) { return PoAction.Message("业务不可用!"); } var onMap = await _mapService.GetUserOnMapId(userId); if (npcInfo.mapId != onMap) { return PoAction.Message("Npc不存在!"); } #endregion if (string.IsNullOrEmpty(ueId)) { var myEqu = await _equService.GetUserOnEqu(userId); myEqu = myEqu.FindAll(it => it.isAppr == 1 && it.durability < it.maxdurability && it.useEndTime > TimeExtend.GetTimeStampSeconds); int need = myEqu.Sum(it => (int)it.maxdurability - (int)it.durability); if (need < 1) { return PoAction.Message("耐久已满,无需恢复!"); } var myAcc = await _accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper)); if (need > myAcc) { return PoAction.Message("铜贝不足!"); } if (await _accService.UpdateUserCopper(userId, 0, need, "修复装备")) { foreach (var item in myEqu) { item.durability = item.maxdurability; await _equService.UpdateUserEquInfo(item); } return PoAction.Ok(true, $"恢复成功,花费{need}铜贝!"); } else { return PoAction.Message("恢复失败,请稍后尝试!"); } } else { var equInfo = await _equService.GetUserEquInfo(ueId); if (equInfo == null) { return PoAction.Message("装备不存在!"); } if (equInfo.userId != userId) { return PoAction.Message("装备不存在!"); } if (equInfo.isAppr != 1) { return PoAction.Message("装备未鉴定!"); } if (equInfo.useEndTime < TimeExtend.GetTimeStampSeconds) { return PoAction.Message("装备已过期!"); } if (equInfo.durability >= equInfo.maxdurability) { return PoAction.Message("耐久已满,无需恢复!"); } int need = (int)equInfo.maxdurability - (int)equInfo.durability; var myAcc = await _accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper)); if (need > myAcc) { return PoAction.Message("铜贝不足!"); } if (await _accService.UpdateUserCopper(userId, 0, need, "修复装备")) { equInfo.durability = equInfo.maxdurability; if (await _equService.UpdateUserEquInfo(equInfo)) { return PoAction.Ok(true, $"恢复成功,花费{need}铜贝!"); } else { return PoAction.Message("恢复失败,请稍后尝试!"); } } else { return PoAction.Message("恢复失败,请稍后尝试!"); } } } }