12121
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Application.Web.Controllers.Pub;
|
||||
|
||||
@@ -11,10 +12,17 @@ namespace Application.Web.Controllers.Pub;
|
||||
public class GoodsController : ControllerBase
|
||||
{
|
||||
private readonly IGameGoodsService _goodsService;
|
||||
private readonly IUnitUserAttrService _attrService;
|
||||
private readonly IMessageService _messageService;
|
||||
private readonly IUnitUserWeight _weightService;
|
||||
|
||||
public GoodsController(IGameGoodsService goodsService)
|
||||
public GoodsController(IGameGoodsService goodsService, IUnitUserAttrService attrService,
|
||||
IMessageService messageService, IUnitUserWeight weightService)
|
||||
{
|
||||
_goodsService = goodsService;
|
||||
_attrService = attrService;
|
||||
_messageService = messageService;
|
||||
_weightService = weightService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,11 +45,87 @@ public class GoodsController : ControllerBase
|
||||
switch (goodsInfo.code)
|
||||
{
|
||||
case "Pack":
|
||||
UseState = 1;
|
||||
UseState = 1;
|
||||
break;
|
||||
case "Weight":
|
||||
UseState = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return PoAction.Ok(new { goods = goodsInfo, count, use = UseState });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用物品
|
||||
/// </summary>
|
||||
/// <param name="goodsId"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> UseGoods(int goodsId, int count)
|
||||
{
|
||||
count = count < 1 ? 1 : count;
|
||||
string userId = StateHelper.userId;
|
||||
var goodsInfo = await _goodsService.GetGoodsInfo(goodsId);
|
||||
if (goodsInfo == null)
|
||||
{
|
||||
return PoAction.Message("物品不存在!");
|
||||
}
|
||||
|
||||
var MyGoods = await _goodsService.GetUserGoodsCount(userId, goodsId);
|
||||
if (MyGoods < count)
|
||||
{
|
||||
return PoAction.Message("物品不足!");
|
||||
}
|
||||
|
||||
var myLev = await _attrService.GetUserLev(userId);
|
||||
if (myLev < (int)goodsInfo.lev)
|
||||
{
|
||||
return PoAction.Message($"该物品{goodsInfo.lev}级才可使用!");
|
||||
}
|
||||
|
||||
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "使用物品"))
|
||||
{
|
||||
string message = "";
|
||||
if (goodsInfo.code == nameof(GoodsEnum.Code.Pack)) //使用礼包
|
||||
{
|
||||
var park = JsonConvert.DeserializeObject<RandomModel>(goodsInfo.content);
|
||||
var award = GameBus.GetRandomGoods(park, count);
|
||||
if (award.Count > 0)
|
||||
{
|
||||
message = $"打开[{goodsInfo.goodsName}]×{count},获得:";
|
||||
foreach (var item in award)
|
||||
{
|
||||
message += $"{item.name}+{item.count},";
|
||||
}
|
||||
|
||||
message = message.TrimEnd(',');
|
||||
await GameBus.UpdateBag(userId, 1, award, $"打开礼包:{goodsInfo.goodsName}×{count}获得");
|
||||
|
||||
await _messageService.SendBroadcast(userId, nameof(MessageEnum.BroadcastCode.Award), message);
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "空空如也,什么也没有得到!";
|
||||
}
|
||||
}
|
||||
else if (goodsInfo.code == nameof(GoodsEnum.Code.Weight))
|
||||
{
|
||||
int unitWeight = Convert.ToInt32(goodsInfo.content);
|
||||
await _weightService.UpdateUserMaxWeight(userId, 1, unitWeight, count, goodsInfo.goodsId,
|
||||
goodsInfo.goodsName);
|
||||
message = $"使用[{goodsInfo.goodsName}]×{count},负重+{unitWeight * count}";
|
||||
}
|
||||
else if (goodsInfo.code == nameof(GoodsEnum.Code.State))
|
||||
{
|
||||
}
|
||||
|
||||
return PoAction.Ok(true, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("使用失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user