This commit is contained in:
Putoo
2026-06-27 16:32:11 +08:00
parent aefd94ccd6
commit 438027de21
9 changed files with 144 additions and 19 deletions

View File

@@ -14,5 +14,8 @@ public static class GoodsEnum
Card,//附魔卡片 Card,//附魔卡片
Mark,//圣痕 Mark,//圣痕
Pack,//宝箱 Pack,//宝箱
Weight,//负重
Exp,//经验
State,//状态物品
} }
} }

View File

@@ -200,9 +200,6 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
if (result && IsUpUserAttr) if (result && IsUpUserAttr)
{ {
//增加负重
var wightService = App.GetService<IUnitUserWeight>();
await wightService.UpdateUserMaxWeight(userId, 1, GameConfig.UpLevAddWeight, 1, 0, "升级增加负重");
await ClearUserAttrCache(userId); await ClearUserAttrCache(userId);
} }

View File

@@ -268,9 +268,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
if (result)//注册各项后处理 if (result)//注册各项后处理
{ {
//赠送初始负重
var weightService = App.GetService<IUnitUserWeight>();
await weightService.UpdateUserMaxWeight(userId, 1, 100, 1, 0, "初始负重");
} }
return result; return result;

View File

@@ -19,8 +19,12 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
private async Task<int> GetUserMaxWeight(unit_user_weight data) private async Task<int> GetUserMaxWeight(unit_user_weight data)
{ {
int result = (int)data.maxWeight; int result = 100 + (int)data.maxWeight;
var attrService = App.GetService<IUnitUserAttrService>();
int myLev = await attrService.GetUserLev(data.userId);
result += myLev * GameConfig.UpLevAddWeight;
//其他属性加层 //其他属性加层
return result; return result;
} }
@@ -41,7 +45,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return result; return result;
} }
public async Task<bool> UpdateUserWeight(string userId, int op, int weight) public async Task<bool> UpdateUserWeight(string userId, int op, int weight)
{ {
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_weight>(); var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_weight>();
@@ -119,6 +123,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
} }
#region #region
public async Task<unit_user_ship> GetUserShipInfo(string usId) public async Task<unit_user_ship> GetUserShipInfo(string usId)
{ {
string key = string.Format(UserCache.BaseCacheKeys, "UserShip", "Info"); string key = string.Format(UserCache.BaseCacheKeys, "UserShip", "Info");
@@ -132,6 +137,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return data; return data;
} }
public async Task<List<unit_user_ship>> GetUserShip(string userId) public async Task<List<unit_user_ship>> GetUserShip(string userId)
{ {
string key = string.Format(UserCache.BaseCacheKeys, "WeightData", "Ship"); string key = string.Format(UserCache.BaseCacheKeys, "WeightData", "Ship");

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Application.Web.Controllers.Pub; namespace Application.Web.Controllers.Pub;
@@ -11,10 +12,17 @@ namespace Application.Web.Controllers.Pub;
public class GoodsController : ControllerBase public class GoodsController : ControllerBase
{ {
private readonly IGameGoodsService _goodsService; 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; _goodsService = goodsService;
_attrService = attrService;
_messageService = messageService;
_weightService = weightService;
} }
/// <summary> /// <summary>
@@ -37,11 +45,87 @@ public class GoodsController : ControllerBase
switch (goodsInfo.code) switch (goodsInfo.code)
{ {
case "Pack": case "Pack":
UseState = 1; UseState = 1;
break;
case "Weight":
UseState = 1;
break; break;
} }
return PoAction.Ok(new { goods = goodsInfo, count, use = UseState }); 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("使用失败,请稍后尝试!");
}
}
} }

View File

@@ -3,11 +3,11 @@
*/ */
export class MessageExtend { export class MessageExtend {
// 消息通知 // 消息通知
static Notify(message: any, type?: 'primary' | 'success' | 'danger' | 'warning') { static Notify(message: any, type?: 'primary' | 'success' | 'danger' | 'warning', time?: number) {
showNotify({ showNotify({
type: type, type: type,
message: message, message: message,
duration: 1500, duration: time || 1500,
}); });
} }

View File

@@ -20,8 +20,8 @@
<div class="common" v-if="data.code == 'Drug'"> <div class="common" v-if="data.code == 'Drug'">
<Abutton @click="ShowDrugBar">添加药品栏</Abutton> <Abutton @click="ShowDrugBar">添加药品栏</Abutton>
</div> </div>
<div class="common" v-if="useState==1"> <div class="common" v-if="useState == 1">
<Abutton>使用物品</Abutton> <Abutton @click="showUseNumView = true">使用物品</Abutton>
</div> </div>
</div> </div>
@@ -39,6 +39,17 @@
<button class="ipt-btn" name="serch" @click="AddDrugBar" style="margin-top: 15px;">确认</button> <button class="ipt-btn" name="serch" @click="AddDrugBar" style="margin-top: 15px;">确认</button>
</div> </div>
</GamePopup> </GamePopup>
<GamePopup v-model:show="showUseNumView" title="使用物品">
<!-- 自定义内容 -->
<div class="common">
物品名称{{ data.goodsName }}<br>
物品数量{{ count }}<br>
</div>
<div class="common" style="text-align: center;">
使用数量<input type="number" class="search-ipt" v-model="useCount"><br>
<button class="ipt-btn" name="serch" @click="UseGoods" style="margin-top: 15px;">确认</button>
</div>
</GamePopup>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@@ -49,6 +60,7 @@ definePageMeta({
const data = ref<any>({}); const data = ref<any>({});
const count = ref(0); const count = ref(0);
const useState = ref(0); const useState = ref(0);
const useCount = ref(1);
let goodsId = PageExtend.QueryString("id"); let goodsId = PageExtend.QueryString("id");
onMounted(async () => { onMounted(async () => {
try { try {
@@ -99,4 +111,20 @@ const AddDrugBar = async () => {
} }
} }
const showUseNumView = ref(false);
const UseGoods = async () => {
MessageExtend.LoadingToast("使用中...");
let result = await GoodsService.UseGoods(Number(goodsId),useCount.value);
MessageExtend.LoadingClose();
if (result.code == 0) {
showUseNumView.value = false;
await BindData();
MessageExtend.Notify(result.msg, "success",5000);
}
else {
MessageExtend.ShowDialog("提示", result.msg);
}
}
</script> </script>

View File

@@ -1,15 +1,16 @@
<template> <template>
<div class="content"> <div class="content">
我的物品.<Abutton @click="Refresh">刷新</Abutton> <br> 我的物品.<Abutton @click="Refresh">刷新</Abutton> <br>
金元:{{ bagInfo.gold }}<br /> 金元{{ bagInfo.gold }}<br />
金贝:{{ bagInfo.cowry }} <br /> 金贝{{ bagInfo.cowry }} <br />
负重:{{ bagInfo.onWeight }}/{{ bagInfo.maxWeight }} <br /> 负重{{ bagInfo.onWeight }}/{{ bagInfo.maxWeight }}&nbsp;<span v-if="bagInfo.onWeight > bagInfo.maxWeight"
style="color: red;font-weight: bold;">!</span><br />
{{ GameTool.FormatCopper(bagInfo.copper) }}<br /> {{ GameTool.FormatCopper(bagInfo.copper) }}<br />
<Abar href="/">交易记录</Abar><br> <Abar href="/">交易记录</Abar><br>
<Abar href="/">赠送记录</Abar> <Abar href="/">赠送记录</Abar>
</div> </div>
<div class="content"> <div class="content">
<div class="common"> <div class="common" style="">
<Acheak @click="ChangeBag('0')" :on-value="type" on-cheak="0">装备</Acheak>| <Acheak @click="ChangeBag('0')" :on-value="type" on-cheak="0">装备</Acheak>|
<Acheak @click="ChangeBag('1')" :on-value="type" on-cheak="1">药品</Acheak>| <Acheak @click="ChangeBag('1')" :on-value="type" on-cheak="1">药品</Acheak>|

View File

@@ -7,4 +7,12 @@ export class GoodsService {
static async GetGoodsInfo(goodsId: number) { static async GetGoodsInfo(goodsId: number) {
return await ApiService.Request("get", "/Goods/GetGoodsInfo", { goodsId }); return await ApiService.Request("get", "/Goods/GetGoodsInfo", { goodsId });
} }
/**
* 使用物品
* GET /Goods/UseGoods
*/
static async UseGoods(goodsId: number, count: number) {
return await ApiService.Request("get", "/Goods/UseGoods", { goodsId, count });
}
} }