This commit is contained in:
Putoo
2026-06-29 18:17:54 +08:00
parent e47a5a19a6
commit 93d21ba9fd
35 changed files with 1073 additions and 293 deletions

View File

@@ -50,6 +50,15 @@ public class GoodsController : ControllerBase
case "Weight":
UseState = 1;
break;
case "State":
UseState = 1;
break;
case "Ship":
UseState = 2;
break;
case "ChoicePack":
UseState = 3;
break;
}
@@ -85,6 +94,19 @@ public class GoodsController : ControllerBase
return PoAction.Message($"该物品{goodsInfo.lev}级才可使用!");
}
#region
if (goodsInfo.code == nameof(GoodsEnum.Code.Ship))
{
var myShip = await _weightService.GetUserShip(userId);
if (myShip.Count >= 5)
{
return PoAction.Message($"每人最多拥有5个船只,您已达到上限!");
}
}
#endregion
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "使用物品"))
{
string message = "";
@@ -119,6 +141,23 @@ public class GoodsController : ControllerBase
}
else if (goodsInfo.code == nameof(GoodsEnum.Code.State))
{
UserStateModel stateConfig = JsonConvert.DeserializeObject<UserStateModel>(goodsInfo.content);
await _attrService.AddUserState(userId, goodsInfo.goodsId.ToString(), stateConfig.name,
stateConfig.scene, stateConfig.tips, stateConfig.attr, stateConfig.time, count);
message = $"使用[{goodsInfo.goodsName}]×{count},状态时间+{stateConfig.time * count}分钟";
}
else if (goodsInfo.code == nameof(GoodsEnum.Code.Ship))
{
dynamic shipInfo = JsonConvert.DeserializeObject<dynamic>(goodsInfo.content);
string name = shipInfo.name;
int speed = shipInfo.speed;
int weight = shipInfo.weight;
int copper = shipInfo.copper;
long sale = shipInfo.sale;
string remark = shipInfo.remark;
await _weightService.AddUserShip(userId, name, goodsId, speed, weight, copper, sale, remark);
message = $"使用[{goodsInfo.goodsName}],获得{name}+1";
}
return PoAction.Ok(true, message);
@@ -128,4 +167,69 @@ public class GoodsController : ControllerBase
return PoAction.Message("使用失败,请稍后尝试!");
}
}
/// <summary>
/// 使用选择物品礼包
/// </summary>
/// <param name="goodsId"></param>
/// <param name="count"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> UseChoiceGoods(int goodsId, int num)
{
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 < 1)
{
return PoAction.Message("物品不足!");
}
var myLev = await _attrService.GetUserLev(userId);
if (myLev < (int)goodsInfo.lev)
{
return PoAction.Message($"该物品{goodsInfo.lev}级才可使用!");
}
if (goodsInfo.code != nameof(GoodsEnum.Code.ChoicePack))
{
return PoAction.Message("无法使用该物品!");
}
List<ChoiceGoods> choiceGoods = JsonConvert.DeserializeObject<List<ChoiceGoods>>(goodsInfo.content);
var onAward = choiceGoods.Find(it => it.id == num);
if (onAward == null)
{
return PoAction.Message("物品中不包含该选择!");
}
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, 1, "使用物品"))
{
if (await GameBus.UpdateBag(userId, 1, onAward.award, "打开礼包获取"))
{
string message = $"打开[{goodsInfo.goodsName}],获得:";
foreach (var item in onAward.award)
{
message += $"{item.name}+{item.count},";
}
message = message.TrimEnd(',');
await _messageService.SendBroadcast(userId, nameof(MessageEnum.BroadcastCode.Award), message);
return PoAction.Ok(true, message);
}
else
{
return PoAction.Message("使用失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("使用失败,请稍后尝试!");
}
}
}