using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub;
///
/// 装备接口
///
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class EquController : ControllerBase
{
private readonly IGameEquService _equService;
public EquController(IGameEquService equService)
{
_equService = equService;
}
///
/// 获取装备信息
///
///
///
///
[HttpGet]
public async Task GetEquInfo(int? equId, string? ueId)
{
game_equ equInfo = new game_equ();
game_equ_suit suit = new game_equ_suit();
unit_user_equ ueInfo = new unit_user_equ();
UserModel user = new UserModel();
if (equId != 0)
{
equInfo = await _equService.GetEquInfo((int)equId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.suitCode != "0" && !string.IsNullOrEmpty(equInfo.suitCode))
{
suit = await _equService.GetEuqSuitInfo(equInfo.suitCode);
}
}
else
{
ueInfo = await _equService.GetUserEquInfo(ueId);
if (ueInfo == null)
{
return PoAction.Message("装备不存在!");
}
equInfo = await _equService.GetEquInfo((int)ueInfo.equId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (ueInfo.suitCode != "0" && !string.IsNullOrEmpty(ueInfo.suitCode))
{
suit = await _equService.GetEuqSuitInfo(ueInfo.suitCode);
}
user = await UserModelTool.GetUserView(ueInfo.owerId);
}
return PoAction.Ok(new { equ = equInfo, suit, equData = ueInfo,user });
}
///
/// 获取套装详情
///
///
///
[HttpGet]
public async Task GetEquSuitInfo(string suitCode)
{
var data = await _equService.GetEuqSuitInfo(suitCode);
if (data == null)
{
return PoAction.Message("套装不存在!");
}
return PoAction.Ok(data);
}
///
/// 绑定操作
///
///
///
[HttpGet]
public async Task EquLock(string ueId)
{
var userId = StateHelper.userId;
var equInfo = await _equService.GetUserEquInfo(ueId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.userId != userId)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.isAppr == 0)
{
return PoAction.Message("装备未鉴定!");
}
equInfo.isLock = equInfo.isLock == 0 ? 1 : 0;
bool result = await _equService.UpdateUserEquInfo(equInfo);
if (result)
{
string msg = equInfo.isLock == 1 ? "成功绑定装备!" : "成功解除装备绑定!";
return PoAction.Ok(true, msg);
}
else
{
return PoAction.Message("操作失败,请稍后尝试!");
}
}
///
/// 穿/卸装备
///
///
///
[HttpGet]
public async Task DownOrUpEqu(string ueId)
{
return PoAction.Ok(true);
}
}