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;
public RecoverController(IUnitUserAttrService attrService, IGameMapService mapService)
{
_attrService = attrService;
_mapService = mapService;
}
///
/// 恢复体力
///
///
///
[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);
return PoAction.Ok(data);
}
///
/// 恢复活力
///
///
///
[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("今天已恢复过活力啦!");
}
if (data.vitality >= data.upVitality)
{
return PoAction.Message("活力满满,无需恢复!");
}
bool result = await _attrService.UpdateUserVigour(userId, 2, (long)data.upVitality,time);
if (result)
{
return PoAction.Ok(true);
}
else
{
return PoAction.Message("恢复失败,请稍后尝试!");
}
}
}