diff --git a/Service/Application.Domain.Entity/logdb/db/game_exchange_log.cs b/Service/Application.Domain.Entity/logdb/db/game_exchange_log.cs new file mode 100644 index 0000000..178e514 --- /dev/null +++ b/Service/Application.Domain.Entity/logdb/db/game_exchange_log.cs @@ -0,0 +1,45 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Log")] + public class game_exchange_log + { + /// + /// ueId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public string ueId { get; set; } + + /// + /// userId + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? userId { get; set; } + + /// + /// exId + /// + [SugarColumn(IsNullable = true)] + public int? exId { get; set; } + + /// + /// count + /// + [SugarColumn(IsNullable = true)] + public int? count { get; set; } + + /// + /// addTime + /// + [SugarColumn(IsNullable = true)] + public long? addTime { get; set; } + + /// + /// endTime + /// + [SugarColumn(IsNullable = true)] + public long? endTime { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/resource/game/game_exchange.cs b/Service/Application.Domain.Entity/resource/game/game_exchange.cs new file mode 100644 index 0000000..9876048 --- /dev/null +++ b/Service/Application.Domain.Entity/resource/game/game_exchange.cs @@ -0,0 +1,75 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Resource")] + public class game_exchange + { + /// + /// exId + /// + [SugarColumn(IsPrimaryKey = true)] + public int exId { get; set; } + + /// + /// areaId + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? areaId { get; set; } + + /// + /// npcId + /// + [SugarColumn(IsNullable = true)] + public int? npcId { get; set; } + + /// + /// name + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? name { get; set; } + + /// + /// tips + /// + [SugarColumn(IsNullable = true)] + public string? tips { get; set; } + + /// + /// exType + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? exType { get; set; } + + /// + /// count + /// + [SugarColumn(IsNullable = true)] + public int? count { get; set; } + + /// + /// needData + /// + [SugarColumn(IsNullable = true,IsJson = true)] + public List needData { get; set; } + + /// + /// getData + /// + [SugarColumn(IsNullable = true,IsJson = true)] + public List getData { get; set; } + + /// + /// startTime + /// + [SugarColumn(IsNullable = true)] + public DateTime? startTime { get; set; } + + /// + /// endTime + /// + [SugarColumn(IsNullable = true)] + public DateTime? endTime { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain/Config/GameConfig.cs b/Service/Application.Domain/Config/GameConfig.cs index 0c643ed..cb4956e 100644 --- a/Service/Application.Domain/Config/GameConfig.cs +++ b/Service/Application.Domain/Config/GameConfig.cs @@ -4,18 +4,18 @@ public static class GameConfig { public const int GameMaxLev = 320;//最大等级 public const int OnLineTime = 30;//在线延迟时间(分钟) - public const int SendChatGoodsBase = 10014;//小海螺 + public const int SendChatGoodsBase = 10000;//小海螺 public const int SendChatGoodsArea = 10001;//大海螺 public const int SendChatGoodsService = 10002;//金海螺 public const int UpLevAddWeight = 10;//升级增加负重 public const int GameBaseVigour = 50;//初始活力 public const int GameRelationEnemyNeedGold = 300;//添加仇人所需金元 - public const int GameUpdateNickNeedGoods = 10001;//更新昵称所需道具 - public const int GameUpdateSexNeedGoods = 10001;//更新性别所需道具 + public const int GameUpdateNickNeedGoods = 10018;//更新昵称所需道具 + public const int GameUpdateSexNeedGoods = 10065;//更新性别所需道具 public const int GameUserFriendMaxCount = 50;//好友最大上限人数 - public const int GameAutoBagGoodsId = 10001;//百宝箱物品ID - public const int GameAutoDrugGoodsId = 10001;//急救箱物品ID + public const int GameAutoBagGoodsId = 10022;//百宝箱物品ID + public const int GameAutoDrugGoodsId = 10023;//急救箱物品ID public const int GameToMapNeedCopper = 5;//传送每海里费用 public const int TeamCacheTime = 300;//队伍缓存时间 - public const int GameEquApprGoods = 10001;//鉴定装备道具 + public const int GameEquApprGoods = 10019;//鉴定装备道具 } \ No newline at end of file diff --git a/Service/Application.Domain/Enum/GameEnum.cs b/Service/Application.Domain/Enum/GameEnum.cs index ac93b6e..1c76ba3 100644 --- a/Service/Application.Domain/Enum/GameEnum.cs +++ b/Service/Application.Domain/Enum/GameEnum.cs @@ -59,6 +59,7 @@ public static class GameEnum MapTo, Store, Make, + Exchange, } public enum DicCode diff --git a/Service/Application.Domain/Services/Interface/Business/IExchangeService.cs b/Service/Application.Domain/Services/Interface/Business/IExchangeService.cs new file mode 100644 index 0000000..8dd0e95 --- /dev/null +++ b/Service/Application.Domain/Services/Interface/Business/IExchangeService.cs @@ -0,0 +1,9 @@ +namespace Application.Domain; + +public interface IExchangeService +{ + Task> GetExchangeData(int npcId); + Task GetExchangeInfo(int exId); + Task GetExchangeCount(string userId, int exId); + Task AddUserExchangeLog(string userId, int exId, int count, long endTime); +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/Equ/IGameEquService.cs b/Service/Application.Domain/Services/Interface/Equ/IGameEquService.cs index 0a7913c..794192a 100644 --- a/Service/Application.Domain/Services/Interface/Equ/IGameEquService.cs +++ b/Service/Application.Domain/Services/Interface/Equ/IGameEquService.cs @@ -18,7 +18,7 @@ public interface IGameEquService Task> GetUserEquData(string userId, string code, List noUeId); Task GetUserEquInfo(string ueId); Task GetUserEquByEquIdCount(string userId, int equId); - Task> GetUserEquByEquId(string userId, int equId); + Task> GetUserEquByEquIdToDeduct(string userId, int equId); Task AddUserEqu(string userId, int equId, int count, string remark); Task AddUserEqu(unit_user_equ equData, string remark); Task AddUserEqu(string userId, int equId, bool rdAttr = false, string remark = ""); diff --git a/Service/Application.Domain/Services/Service/Business/ExchangeService.cs b/Service/Application.Domain/Services/Service/Business/ExchangeService.cs new file mode 100644 index 0000000..58a58c8 --- /dev/null +++ b/Service/Application.Domain/Services/Service/Business/ExchangeService.cs @@ -0,0 +1,41 @@ +namespace Application.Domain; + +public class ExchangeService(ISqlSugarClient DbClient, IRedisCache redis) : IExchangeService, ITransient +{ + public async Task> GetExchangeData(int npcId) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.npcId == npcId).ToListAsync(); + return data; + } + + public async Task GetExchangeInfo(int exId) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Queryable().Where(it => it.exId == exId).SingleAsync(); + } + + public async Task GetExchangeCount(string userId, int exId) + { + int result = 0; + string key = $"{userId}_{exId}"; + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Queryable().Where(it => it.userId == userId && it.exId == exId) + .SumAsync(it => (int)it.count); + } + + public async Task AddUserExchangeLog(string userId, int exId, int count,long endTime) + { + game_exchange_log log = new game_exchange_log(); + log.ueId = StringAssist.NewGuid; + log.userId = userId; + log.exId = exId; + log.count = count; + log.addTime = TimeExtend.GetTimeStampSeconds; + log.endTime = endTime; + var db = DbClient.AsTenant().GetConnectionWithAttr(); + bool result = await db.Insertable(log).ExecuteCommandAsync() > 0; + return result; + } + +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/Equ/GameEquService.cs b/Service/Application.Domain/Services/Service/Equ/GameEquService.cs index 7af2341..c9600d0 100644 --- a/Service/Application.Domain/Services/Service/Equ/GameEquService.cs +++ b/Service/Application.Domain/Services/Service/Equ/GameEquService.cs @@ -78,16 +78,21 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame public async Task GetUserEquByEquIdCount(string userId, int equId) { int result = 0; - var data = await GetUserEquByEquId(userId, equId); + var data = await GetUserEquData(userId, equId); result = data.Count; return result; } - public async Task> GetUserEquByEquId(string userId, int equId) + public async Task> GetUserEquByEquIdToDeduct(string userId, int equId) { - var db = DbClient.AsTenant().GetConnectionWithAttr(); - return await db.Queryable().Where(i => i.userId == userId && i.equId == equId).ToListAsync(); + var userEqu = await GetUserEquData(userId, equId); + userEqu = userEqu.FindAll(it => it.isLock == 0 && it.isOn == 0); + userEqu = userEqu.OrderBy(it => (int)it.intensifyLev) + .ThenBy(it => it.quality) + .ToList(); + return userEqu; } + public async Task AddUserEqu(string userId, int equId, int count, string remark) { @@ -358,21 +363,11 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame public async Task DeductUserEqu(string userId, int equId, int count, string remark) { - var userEqu = await GetUserEquData(userId, equId); + var userEqu = await GetUserEquByEquIdToDeduct(userId, equId); if (userEqu.Count < 1) { return false; } - - userEqu = userEqu.FindAll(it => it.isLock == 0 && it.isOn == 0); - if (userEqu.Count < count) - { - return false; - } - - userEqu = userEqu.OrderBy(it => (int)it.intensifyLev) - .OrderBy(it => it.quality) - .ToList(); var opData = userEqu.Take(count).ToList(); return await DeductUserEqu(userId, opData, remark); } diff --git a/Service/Application.Domain/Tool/Base/EquTool.cs b/Service/Application.Domain/Tool/Base/EquTool.cs index e9be574..fc744f8 100644 --- a/Service/Application.Domain/Tool/Base/EquTool.cs +++ b/Service/Application.Domain/Tool/Base/EquTool.cs @@ -48,42 +48,42 @@ public class EquTool return onAttr; } - int result = onLev * 3; - result = result > 57 ? 57 : result; + int result = onLev; + result = result > 19 ? 19 : result; if (onLev > 19) { int addLev = onLev - 19; addLev = addLev > 10 ? 10 : addLev; - result += addLev * 5; + result += addLev * 3; } if (onLev > 29) { int addLev = onLev - 29; addLev = addLev > 10 ? 10 : addLev; - result += addLev * 10; + result += addLev * 5; } if (onLev > 39) { int addLev = onLev - 39; addLev = addLev > 10 ? 10 : addLev; - result += addLev * 15; + result += addLev * 10; } if (onLev > 49) { int addLev = onLev - 49; addLev = addLev > 10 ? 10 : addLev; - result += addLev * 20; + result += addLev * 15; } if (onLev > 59) { int addLev = onLev - 59; addLev = addLev > 10 ? 10 : addLev; - result += addLev * 25; + result += addLev * 20; } if (onLev > 69) @@ -91,7 +91,7 @@ public class EquTool int addLev = onLev - 69; addLev = addLev > 10 ? 10 : addLev; int unitAdd = Convert.ToInt32(onAttr * 0.05); - unitAdd = unitAdd < 30 ? 30 : unitAdd; + unitAdd = unitAdd < 25 ? 25 : unitAdd; result += addLev * unitAdd; } @@ -100,7 +100,7 @@ public class EquTool int addLev = onLev - 79; addLev = addLev > 10 ? 10 : addLev; int unitAdd = Convert.ToInt32(onAttr * 0.1); - unitAdd = unitAdd < 35 ? 35 : unitAdd; + unitAdd = unitAdd < 30 ? 30 : unitAdd; result += addLev * unitAdd; } @@ -109,7 +109,7 @@ public class EquTool int addLev = onLev - 89; addLev = addLev > 10 ? 10 : addLev; int unitAdd = Convert.ToInt32(onAttr * 0.15); - unitAdd = unitAdd < 40 ? 40 : unitAdd; + unitAdd = unitAdd < 35 ? 35 : unitAdd; result += addLev * unitAdd; } diff --git a/Service/Application.Domain/Tool/Base/GameBus.cs b/Service/Application.Domain/Tool/Base/GameBus.cs index d91f501..6f898dd 100644 --- a/Service/Application.Domain/Tool/Base/GameBus.cs +++ b/Service/Application.Domain/Tool/Base/GameBus.cs @@ -112,7 +112,8 @@ public static class GameBus if (item.code == nameof(GameEnum.PropCode.Equ)) { var equService = App.GetService(); - int MyCount = await equService.GetUserEquByEquIdCount(userId, Convert.ToInt32(item.parameter)); + var myOpEqu = await equService.GetUserEquByEquIdToDeduct(userId, Convert.ToInt32(item.parameter)); + int MyCount = myOpEqu.Count; long needCount = item.count * count; item.count = needCount; item.onCount = MyCount; diff --git a/Service/Application.Web/Controllers/Pub/ExchangeController.cs b/Service/Application.Web/Controllers/Pub/ExchangeController.cs new file mode 100644 index 0000000..0fad800 --- /dev/null +++ b/Service/Application.Web/Controllers/Pub/ExchangeController.cs @@ -0,0 +1,169 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Application.Web.Controllers.Pub; + +/// +/// 兑换接口 +/// +[Route("[controller]/[action]")] +[ApiController] +[Authorize] +public class ExchangeController : ControllerBase +{ + private readonly IGameMapService _mapService; + private readonly IExchangeService _exchangeService; + + public ExchangeController(IGameMapService mapService, IExchangeService exchangeService) + { + _mapService = mapService; + _exchangeService = exchangeService; + } + + /// + /// 获取兑换信息 + /// + /// + /// + [HttpGet] + public async Task GetExchangeData(int npcId) + { + string userId = StateHelper.userId; + int areaId = StateHelper.areaId; + 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.Exchange))) + { + return PoAction.Message("业务不可用!"); + } + + var onMap = await _mapService.GetUserOnMapId(userId); + if (npcInfo.mapId != onMap) + { + return PoAction.Message("Npc不存在!"); + } + + var data = await _exchangeService.GetExchangeData(npcId); + data = data.FindAll(it => GameTool.AreaVerify(areaId, it.areaId) && it.endTime > DateTime.Now); + + return PoAction.Ok(data); + } + + /// + /// 兑换物品 + /// + /// + /// + /// + /// + [HttpGet] + public async Task ExchangeOk(int npcId, int exId, int count) + { + count = count < 1 ? 1 : count; + string userId = StateHelper.userId; + int areaId = StateHelper.areaId; + 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.Exchange))) + { + return PoAction.Message("业务不可用!"); + } + + var onMap = await _mapService.GetUserOnMapId(userId); + if (npcInfo.mapId != onMap) + { + return PoAction.Message("Npc不存在!"); + } + + var exInfo = await _exchangeService.GetExchangeInfo(exId); + if (exInfo == null) + { + return PoAction.Message("兑换不存在!"); + } + + if (exInfo.endTime < DateTime.Now) + { + return PoAction.Message("兑换已结束!"); + } + + if (GameTool.AreaVerify(areaId, exInfo.areaId) == false) + { + return PoAction.Message("兑换不存在!"); + } + + int sumCount = await _exchangeService.GetExchangeCount(userId, exId); + if ((sumCount + count) > exInfo.count) + { + int endCount = (int)exInfo.count - sumCount; + if (endCount == 0) + { + return PoAction.Message("您已达到兑换上限!"); + } + else + { + return PoAction.Message($"您最多还能兑换{endCount}次!"); + } + } + + var result = await GameBus.CheckNeed(userId, exInfo.needData, count); + if (result.result) + { + if (await GameBus.UpdateBag(userId, 0, exInfo.needData, "兑换", count)) + { + long endTime = 0; + switch (exInfo.exType) + { + case "Long": + endTime = TimeExtend.GetTimeStampBySeconds((DateTime)exInfo.endTime); + break; + case "Day": + endTime = TimeExtend.GetTimeStampBySeconds(TimeAssist.GetDateTimeYMD(1)); + break; + case "Month": + DateTime nt = DateTime.Now.AddMonths(1); + nt = Convert.ToDateTime($"{nt.Year}-{nt.Month}-01"); + endTime = TimeExtend.GetTimeStampBySeconds(nt); + break; + case "Week": + endTime = TimeExtend.GetTimeStampBySeconds(TimeAssist.WeekEndTime); + break; + } + + if (await _exchangeService.AddUserExchangeLog(userId, exId, count, endTime)) + { + await GameBus.UpdateBag(userId, 1, exInfo.getData, "兑换", count); + return PoAction.Ok(true); + } + else + { + return PoAction.Message("兑换失败,请稍后尝试!"); + } + } + else + { + return PoAction.Message("兑换失败,请稍后尝试!"); + } + } + else + { + return PoAction.Message("兑换失败,请稍后尝试!"); + } + } +} \ No newline at end of file diff --git a/Web/src/components/Business/GameProp.vue b/Web/src/components/Business/GameProp.vue new file mode 100644 index 0000000..22c678b --- /dev/null +++ b/Web/src/components/Business/GameProp.vue @@ -0,0 +1,23 @@ + + \ No newline at end of file diff --git a/Web/src/pages/business/exchange.vue b/Web/src/pages/business/exchange.vue new file mode 100644 index 0000000..6f4df45 --- /dev/null +++ b/Web/src/pages/business/exchange.vue @@ -0,0 +1,93 @@ + + \ No newline at end of file diff --git a/Web/src/pages/mall/index.vue b/Web/src/pages/mall/index.vue index 41438af..68ebf36 100644 --- a/Web/src/pages/mall/index.vue +++ b/Web/src/pages/mall/index.vue @@ -14,9 +14,9 @@
名称|价格
{{ PageExtend.GetPageIndex(currentPage, 10, index + 1) }}. - + {{ item.name }}({{ GameTool.GetCurrency‌NameAll(item.price, item.payType) }}) - + {{ item.name }}({{ GameTool.GetCurrency‌NameAll(item.price, item.payType) }}) [购买]
diff --git a/Web/src/pages/prop/equ.vue b/Web/src/pages/prop/equ.vue index 2fbe64c..0aa88c2 100644 --- a/Web/src/pages/prop/equ.vue +++ b/Web/src/pages/prop/equ.vue @@ -124,9 +124,9 @@ 觉醒
- + 鉴定
diff --git a/Web/src/pages/prop/monster.vue b/Web/src/pages/prop/monster.vue index 450b3ce..c7df98f 100644 --- a/Web/src/pages/prop/monster.vue +++ b/Web/src/pages/prop/monster.vue @@ -56,8 +56,7 @@ const BindData = async (): Promise => { if (result.code == 0) { monster.value = result.data; if (monster.value.award != '') { - AwardTips.value = awardTipsStr(JSON.parse(monster.value.award)) - console.log(result); + AwardTips.value = awardTipsStr(JSON.parse(monster.value.award)) } } else { diff --git a/Web/src/services/Index/ExchangeService.ts b/Web/src/services/Index/ExchangeService.ts new file mode 100644 index 0000000..fde9686 --- /dev/null +++ b/Web/src/services/Index/ExchangeService.ts @@ -0,0 +1,17 @@ +export class ExchangeService { + /** + * 获取兑换信息 + * GET /Exchange/GetExchangeData + */ + static async GetExchangeData(npcId: number) { + return await ApiService.Request("get", "/Exchange/GetExchangeData", { npcId }); + } + + /** + * 兑换物品 + * GET /Exchange/ExchangeOk + */ + static async ExchangeOk(npcId: number, exId: number, count: number) { + return await ApiService.Request("get", "/Exchange/ExchangeOk", { npcId, exId, count }); + } +} \ No newline at end of file diff --git a/Web/src/utility‌/GameTool.ts b/Web/src/utility‌/GameTool.ts index adeb116..52b0144 100644 --- a/Web/src/utility‌/GameTool.ts +++ b/Web/src/utility‌/GameTool.ts @@ -128,6 +128,24 @@ export class GameTool { } return result; } + public static GetTimeCountTips(code: string, count: number) { + let result = ""; + switch (code) { + case "Long": + result = `永久${count}次`; + break; + case "Day": + result = `每天${count}次`; + break; + case "Week": + result = `每周${count}次`; + break; + case "Month": + result = `每月${count}次`; + break; + } + return result; + } } \ No newline at end of file