1233
This commit is contained in:
203
Service/Application.Web/Controllers/Pub/RecoverController.cs
Normal file
203
Service/Application.Web/Controllers/Pub/RecoverController.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.Pub;
|
||||
|
||||
/// <summary>
|
||||
/// 恢复接口
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复体力
|
||||
/// </summary>
|
||||
/// <param name="npcId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> 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("恢复失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复士气
|
||||
/// </summary>
|
||||
/// <param name="npcId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> 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("恢复失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取个人活力
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetUserVigour()
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
var data = await _attrService.GetUserVigourInfo(userId);
|
||||
return PoAction.Ok(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复活力
|
||||
/// </summary>
|
||||
/// <param name="npcId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> 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("恢复失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user