using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; namespace Application.Web.Controllers.Pub; /// /// 业务操作接口 /// [Route("[controller]/[action]")] [ApiController] [Authorize] public class BusinessController : ControllerBase { private readonly IGameMapService _mapService; private readonly IGameEquService _equService; private readonly IGameGoodsService _goodsService; public BusinessController(IGameEquService equService, IGameGoodsService goodsService, IGameMapService mapService) { _equService = equService; _goodsService = goodsService; _mapService = mapService; } /// /// 获取打造图纸 /// /// [HttpGet] public async Task GetEquPaper() { string userId = StateHelper.userId; var data = await _goodsService.GetUserGoodsData(userId, nameof(GoodsEnum.Code.Paper)); List result = new List(); foreach (var item in data) { MakePaperView temp = new MakePaperView(); temp.goods = await _goodsService.GetGoodsInfo((int)item.goodsId); temp.count = (long)item.count; result.Add(temp); } return PoAction.Ok(result); } /// /// 打造装备 /// /// /// /// [HttpGet] public async Task HandleEquPaper(int npcId, int goodsId) { 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.Make))) { return PoAction.Message("业务不可用!"); } var onMap = await _mapService.GetUserOnMapId(userId); if (npcInfo.mapId != onMap) { return PoAction.Message("Npc不存在!"); } #endregion var myGoods = await _goodsService.GetUserGoodsInfo(userId, goodsId); if (myGoods == null) { return PoAction.Message("暂无图纸!"); } if (myGoods.count < 1) { return PoAction.Message("暂无图纸!"); } if (myGoods.code != nameof(GoodsEnum.Code.Paper)) { return PoAction.Message("非图纸材料,无法打造!"); } string needstr = await _goodsService.GetGoodsContent(goodsId); var needs = JsonConvert.DeserializeObject>(needstr); var check = await GameBus.CheckNeed(userId, needs); if (check.result) { if (await GameBus.UpdateBag(userId, 0, needs, "装备打造")) { var onEqu = await _equService.GetMakeEquByGoodsId(goodsId); if (onEqu == null) { return PoAction.Message("打造失败,请联系客服!"); } //发放装备 bool isRd = onEqu.rdAttr != 0; var getEqu = await _equService.AddUserEqu(userId, (int)onEqu.equId, isRd, "打造装备"); if (getEqu != null) { return PoAction.Ok(getEqu.ueId, $"打造成功,获得装备[{onEqu.equName}]"); } else { return PoAction.Message("打造失败,请稍后尝试!"); } } else { return PoAction.Message("打造失败,请稍后尝试!"); } } else { return PoAction.Message("材料不足!"); } } }