using Microsoft.AspNetCore.Mvc; namespace Application.Web.Controllers.Pub; /// /// 装备接口 /// [Route("[controller]/[action]")] [ApiController] [Authorize] public class EquController : ControllerBase { private readonly IGameEquService _equService; private readonly IUnitUserAttrService _attrService; private readonly IUnitUserService _userService; public EquController(IGameEquService equService, IUnitUserAttrService attrService, IUnitUserService userService) { _equService = equService; _attrService = attrService; _userService = userService; } /// /// 获取装备信息 /// /// /// /// [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 GetUserOnEqu() { string userId = StateHelper.userId; var data = await _equService.GetUserOnEqu(userId); var suit = await _equService.GetUserEquSuit(userId); return PoAction.Ok(new { data, suit }); } /// /// 穿/卸装备 /// /// /// [HttpGet] public async Task DownOrUpEqu(string ueId, string? de) { string userId = StateHelper.userId; var equInfo = await _equService.GetUserEquInfo(ueId); if (equInfo == null) { return PoAction.Message("装备不存在!"); } if (equInfo.userId != userId) { return PoAction.Message("装备不存在!"); } if (equInfo.isOn == 0) //穿装 { if (equInfo.isAppr == 0) { return PoAction.Message("装备未鉴定!"); } if (equInfo.useEndTime < TimeExtend.GetTimeStampSeconds) { return PoAction.Message("装备已过期!"); } int myLev = await _attrService.GetUserLev(userId); if (equInfo.lev > myLev) { return PoAction.Message($"等级达到{equInfo.lev}级可穿戴!"); } if (equInfo.sex != nameof(EquEnum.Sex.Default)) { var userInfo = await _userService.GetUserInfoByUserId(userId); string needSex = equInfo.sex == nameof(EquEnum.Sex.Girl) ? nameof(GameEnum.Sex.女) : nameof(GameEnum.Sex.男); if (userInfo.sex != needSex) { return PoAction.Message($"该装备只允许{needSex}性角色穿戴!"); } } var userOnEqu = await _equService.GetUserOnEqu(userId); if (equInfo.canEqualUp > 0) { int onCount = userOnEqu.Count(it => it.equId == equInfo.equId); if (onCount >= equInfo.canEqualUp) { return PoAction.Message($"该装备最多穿戴{equInfo.canEqualUp}件!"); } } bool isOk = true; if (string.IsNullOrEmpty(de)) { int MaxCount = GameTool.GetEquPlaceCount(equInfo.code); int OnCount = userOnEqu.Count(it => it.code == equInfo.code) + 1; if (OnCount > MaxCount) { return PoAction.Message($"该部位装备最多穿戴{MaxCount}件!", 100); } } else { var DownOnEqu = await _equService.GetUserEquInfo(de); if (DownOnEqu == null) { return PoAction.Message("装备不存在!"); } if (userOnEqu.Any(it => it.ueId == de) == false) { return PoAction.Message("装备未穿戴!"); } if (DownOnEqu.code != equInfo.code) { return PoAction.Message("装备部位不一致!"); } isOk = await _equService.EquOnOrDown(DownOnEqu, 0); } if (isOk) { bool result = await _equService.EquOnOrDown(equInfo, 1); if (result) { return PoAction.Ok(true, "穿装成功!"); } else { return PoAction.Message("穿装失败,请稍后尝试"); } } else { return PoAction.Message("穿装失败,请稍后尝试"); } } else //卸装 { bool result = await _equService.EquOnOrDown(equInfo, 0); if (result) { return PoAction.Ok(true, "卸装成功!"); } else { return PoAction.Message("卸装失败,请稍后尝试"); } } } /// /// 获取可穿戴装备 /// /// /// [HttpGet] public async Task GetCanOnEqu(int type) { string code = nameof(EquEnum.EquPlace.Hold); switch (type) { case 1: code = nameof(EquEnum.EquPlace.Hold); break; case 2: code = nameof(EquEnum.EquPlace.Vice); break; case 3: code = nameof(EquEnum.EquPlace.Head); break; case 4: code = nameof(EquEnum.EquPlace.Wear); break; case 5: code = nameof(EquEnum.EquPlace.Waist); break; case 6: code = nameof(EquEnum.EquPlace.Foot); break; case 7: code = nameof(EquEnum.EquPlace.Ornaments); break; case 8: code = nameof(EquEnum.EquPlace.Fashion); break; case 9: code = nameof(EquEnum.EquPlace.Wing); break; case 10: code = nameof(EquEnum.EquPlace.Decorate); break; } string userId = StateHelper.userId; var userOnEqu = await _equService.GetUserOnEqu(userId); var NoEqu = userOnEqu.FindAll(it => it.code == code).Select(it => it.ueId).ToList(); var CanEqu = await _equService.GetUserEquData(userId, code, NoEqu); long onTime = TimeExtend.GetTimeStampSeconds; CanEqu = CanEqu.FindAll(it => it.isAppr == 1 && it.useEndTime > onTime); CanEqu = CanEqu.OrderByDescending(it => it.lev).ToList(); return PoAction.Ok(CanEqu); } /// /// 获取激活套装属性 /// /// /// [HttpGet] public async Task GetUserOnSuitInfo(string suitCode) { var userId = StateHelper.userId; var onSuit = await _equService.GetUserEquSuit(userId); var suit = onSuit.Find(it => it.suitCode == suitCode); if (suit == null) { return PoAction.Message("套装不存在!"); } var data = await _equService.GetEuqSuitInfo(suitCode); if (data == null) { return PoAction.Message("套装不存在!"); } return PoAction.Ok(new { data, suit }); } }