From 438027de216c260324b4c3e44a71edfc1acdb9e2 Mon Sep 17 00:00:00 2001 From: Putoo <290555932@qq.com> Date: Sat, 27 Jun 2026 16:32:11 +0800 Subject: [PATCH] 12121 --- Service/Application.Domain/Enum/GoodsEnum.cs | 3 + .../Service/User/UnitUserAttrService.cs | 3 - .../Services/Service/User/UnitUserService.cs | 4 +- .../Services/Service/User/UnitUserWeight.cs | 10 ++- .../Controllers/Pub/GoodsController.cs | 90 ++++++++++++++++++- Web/src/extends/MessageExtend.ts | 4 +- Web/src/pages/prop/goods.vue | 32 ++++++- Web/src/pages/user/bag/index.vue | 9 +- Web/src/services/Index/GoodsService.ts | 8 ++ 9 files changed, 144 insertions(+), 19 deletions(-) diff --git a/Service/Application.Domain/Enum/GoodsEnum.cs b/Service/Application.Domain/Enum/GoodsEnum.cs index 29130f3..60f5988 100644 --- a/Service/Application.Domain/Enum/GoodsEnum.cs +++ b/Service/Application.Domain/Enum/GoodsEnum.cs @@ -14,5 +14,8 @@ public static class GoodsEnum Card,//附魔卡片 Mark,//圣痕 Pack,//宝箱 + Weight,//负重 + Exp,//经验 + State,//状态物品 } } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs b/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs index cb287c2..1c05567 100644 --- a/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs +++ b/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs @@ -200,9 +200,6 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) : if (result && IsUpUserAttr) { - //增加负重 - var wightService = App.GetService(); - await wightService.UpdateUserMaxWeight(userId, 1, GameConfig.UpLevAddWeight, 1, 0, "升级增加负重"); await ClearUserAttrCache(userId); } diff --git a/Service/Application.Domain/Services/Service/User/UnitUserService.cs b/Service/Application.Domain/Services/Service/User/UnitUserService.cs index af10ad3..82203d4 100644 --- a/Service/Application.Domain/Services/Service/User/UnitUserService.cs +++ b/Service/Application.Domain/Services/Service/User/UnitUserService.cs @@ -268,9 +268,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni if (result)//注册各项后处理 { - //赠送初始负重 - var weightService = App.GetService(); - await weightService.UpdateUserMaxWeight(userId, 1, 100, 1, 0, "初始负重"); + } return result; diff --git a/Service/Application.Domain/Services/Service/User/UnitUserWeight.cs b/Service/Application.Domain/Services/Service/User/UnitUserWeight.cs index cf771a9..0e2689d 100644 --- a/Service/Application.Domain/Services/Service/User/UnitUserWeight.cs +++ b/Service/Application.Domain/Services/Service/User/UnitUserWeight.cs @@ -19,8 +19,12 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit private async Task GetUserMaxWeight(unit_user_weight data) { - int result = (int)data.maxWeight; + int result = 100 + (int)data.maxWeight; + var attrService = App.GetService(); + int myLev = await attrService.GetUserLev(data.userId); + result += myLev * GameConfig.UpLevAddWeight; //其他属性加层 + return result; } @@ -41,7 +45,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit return result; } - + public async Task UpdateUserWeight(string userId, int op, int weight) { var db = DbClient.AsTenant().GetConnectionWithAttr(); @@ -119,6 +123,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit } #region 船只相关 + public async Task GetUserShipInfo(string usId) { string key = string.Format(UserCache.BaseCacheKeys, "UserShip", "Info"); @@ -132,6 +137,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit return data; } + public async Task> GetUserShip(string userId) { string key = string.Format(UserCache.BaseCacheKeys, "WeightData", "Ship"); diff --git a/Service/Application.Web/Controllers/Pub/GoodsController.cs b/Service/Application.Web/Controllers/Pub/GoodsController.cs index d271bf6..88a278e 100644 --- a/Service/Application.Web/Controllers/Pub/GoodsController.cs +++ b/Service/Application.Web/Controllers/Pub/GoodsController.cs @@ -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; } /// @@ -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 }); } + + /// + /// 使用物品 + /// + /// + /// + /// + [HttpGet] + public async Task 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(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("使用失败,请稍后尝试!"); + } + } } \ No newline at end of file diff --git a/Web/src/extends/MessageExtend.ts b/Web/src/extends/MessageExtend.ts index 09dbf81..e86434d 100644 --- a/Web/src/extends/MessageExtend.ts +++ b/Web/src/extends/MessageExtend.ts @@ -3,11 +3,11 @@ */ export class MessageExtend { // 消息通知 - static Notify(message: any, type?: 'primary' | 'success' | 'danger' | 'warning') { + static Notify(message: any, type?: 'primary' | 'success' | 'danger' | 'warning', time?: number) { showNotify({ type: type, message: message, - duration: 1500, + duration: time || 1500, }); } diff --git a/Web/src/pages/prop/goods.vue b/Web/src/pages/prop/goods.vue index 9cf609c..60e4ed4 100644 --- a/Web/src/pages/prop/goods.vue +++ b/Web/src/pages/prop/goods.vue @@ -20,8 +20,8 @@
添加药品栏
-
- 使用物品 +
+ 使用物品
@@ -39,6 +39,17 @@ + + +
+ 物品名称:{{ data.goodsName }}
+ 物品数量:{{ count }}
+
+
+ 使用数量:
+ +
+
\ No newline at end of file diff --git a/Web/src/pages/user/bag/index.vue b/Web/src/pages/user/bag/index.vue index 6cfa7d9..5fafd37 100644 --- a/Web/src/pages/user/bag/index.vue +++ b/Web/src/pages/user/bag/index.vue @@ -1,15 +1,16 @@