diff --git a/Service/Application.Domain.Entity/log/db/unit_user_equ_log.cs b/Service/Application.Domain.Entity/log/db/unit_user_equ_log.cs index 4e1e488..1857d0d 100644 --- a/Service/Application.Domain.Entity/log/db/unit_user_equ_log.cs +++ b/Service/Application.Domain.Entity/log/db/unit_user_equ_log.cs @@ -9,7 +9,7 @@ namespace Application.Domain.Entity; public class unit_user_equ_log { [SugarColumn(IsPrimaryKey = true)] public string logId { get; set; } - + [SugarColumn(Length = 50, IsNullable = true)] public string? ueId { get; set; } @@ -19,11 +19,11 @@ public class unit_user_equ_log [SugarColumn(Length = 50, IsNullable = true)] public string? code { get; set; } - [SugarColumn(ColumnDataType = "varchar(max)", IsNullable = true, IsJson = true)] + [SugarColumn(ColumnDataType = "longtext", IsNullable = true, IsJson = true)] public unit_user_equ? equData { get; set; } [SugarColumn(Length = 255, IsNullable = true)] public string? remark { get; set; } - public DateTime? addTime { get; set; } + [SugarColumn(IsNullable = true)] public DateTime? addTime { get; set; } } \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/NpcBus.cs b/Service/Application.Domain.Entity/model/NpcBus.cs new file mode 100644 index 0000000..80eaf2c --- /dev/null +++ b/Service/Application.Domain.Entity/model/NpcBus.cs @@ -0,0 +1,7 @@ +namespace Application.Domain.Entity; + +public class NpcBus +{ + public string name { get; set; } + public string url { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/resource/game/game_city_npc.cs b/Service/Application.Domain.Entity/resource/game/game_city_npc.cs index 65aa42e..e48b872 100644 --- a/Service/Application.Domain.Entity/resource/game/game_city_npc.cs +++ b/Service/Application.Domain.Entity/resource/game/game_city_npc.cs @@ -57,7 +57,7 @@ namespace Application.Domain.Entity /// /// bus /// - [SugarColumn(IsNullable = true)] - public string? bus { get; set; } + [SugarColumn(IsNullable = true,IsJson = true)] + public List? bus { get; set; } } } \ No newline at end of file diff --git a/Service/Application.Domain.Entity/resource/game/game_city_npc_store.cs b/Service/Application.Domain.Entity/resource/game/game_city_npc_store.cs new file mode 100644 index 0000000..654969b --- /dev/null +++ b/Service/Application.Domain.Entity/resource/game/game_city_npc_store.cs @@ -0,0 +1,63 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Resource")] + public class game_city_npc_store + { + /// + /// storeId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public string storeId { get; set; } + + /// + /// npcId + /// + [SugarColumn(IsNullable = true)] + public int? npcId { get; set; } + + /// + /// areaId + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? areaId { get; set; } + + /// + /// type + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? type { get; set; } + + /// + /// name + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? name { get; set; } + + /// + /// parameter + /// + [SugarColumn(Length = 11, IsNullable = true)] + public string? parameter { get; set; } + + /// + /// price + /// + [SugarColumn(IsNullable = true)] + public long? price { get; set; } + + /// + /// payType + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? payType { get; set; } + + /// + /// sort + /// + [SugarColumn(IsNullable = true)] + public int? sort { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain/Enum/GameEnum.cs b/Service/Application.Domain/Enum/GameEnum.cs index afc4b20..c171c69 100644 --- a/Service/Application.Domain/Enum/GameEnum.cs +++ b/Service/Application.Domain/Enum/GameEnum.cs @@ -2,6 +2,43 @@ public static class GameEnum { + public enum PropCode//游戏资源编码 + { + Monster,//怪物 + Goods,//物品 + Equ,//装备 + Rare,//奇珍 + copper,//铜 + exp,//经验 + renown,//声望 + teach,//师德 + cowry,//海贝 + gold,//金 + Mark,//圣痕 + Palace,//九宫 + skill,//技能 + map,//城市地图 + maxName,//称号 + badge,//徽章 + Points,//随从点数 + expType,//经验类型 + lev,//等级 + vip,//VIP等级 + vigour,//活力 + Attire,//装扮 + Attend,//随从 + Constell,//星宿 + Sacred,//圣物 + Daily,//日常积分 + CryAcc,//水晶积分 + Seed,//花园花朵 + SeedLev,//花园等级 + Coin,//花园花币 + RegTime,//注册时间 + StartTime,//开始时间 + EndTime,//结束时间 + Pet,//宠物 + } public enum LogCode { 减少, diff --git a/Service/Application.Domain/Services/Interface/Equ/IGameEquService.cs b/Service/Application.Domain/Services/Interface/Equ/IGameEquService.cs index 8875e85..9bdbf52 100644 --- a/Service/Application.Domain/Services/Interface/Equ/IGameEquService.cs +++ b/Service/Application.Domain/Services/Interface/Equ/IGameEquService.cs @@ -10,9 +10,12 @@ public interface IGameEquService #region 用户装备 Task> GetUserEquData(string userId, int type, string equName, int PageIndex, int PageSize, - RefAsync Total); + RefAsync Total, bool isRemOn = false); Task> GetUserEquData(string userId, int equId); + Task GetUserEquInfo(string ueId); + Task GetUserEquByEquIdCount(string userId, int equId); + Task> GetUserEquByEquId(string userId, int equId); Task AddUserEqu(string userId, int equId, int count, string remark); Task UpdateUserEquInfo(unit_user_equ equData, bool isAddLog = false, string code = "", diff --git a/Service/Application.Domain/Services/Interface/Map/IGameStoreService.cs b/Service/Application.Domain/Services/Interface/Map/IGameStoreService.cs new file mode 100644 index 0000000..123a42b --- /dev/null +++ b/Service/Application.Domain/Services/Interface/Map/IGameStoreService.cs @@ -0,0 +1,9 @@ +namespace Application.Domain; + +public interface IGameStoreService +{ + Task> GetStoreData(int npc, int area, int page, int limit, + RefAsync total); + + Task GetStoreInfo(string storeId); +} \ 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 de9e422..05f04b7 100644 --- a/Service/Application.Domain/Services/Service/Equ/GameEquService.cs +++ b/Service/Application.Domain/Services/Service/Equ/GameEquService.cs @@ -23,7 +23,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame #region 用户装备 public async Task> GetUserEquData(string userId, int type, string equName, int PageIndex, - int PageSize, RefAsync Total) + int PageSize, RefAsync Total, bool isRemOn = false) { long onTime = TimeExtend.GetTimeStampSeconds; var db = DbClient.AsTenant().GetConnectionWithAttr(); @@ -31,6 +31,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame .WhereIF(type == 2, it => it.useEndTime < onTime) .WhereIF(type == 1, it => it.isOn == 1) .WhereIF(type == 3, it => it.isAppr == 0) + .WhereIF(isRemOn, it => it.isOn == 0) .WhereIF(!string.IsNullOrEmpty(equName), it => it.equName.Contains(equName) || it.unitEquName.Contains(equName)) .OrderByDescending(it => it.lev) @@ -44,6 +45,26 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame return await db.Queryable().Where(it => it.userId == userId && it.equId == equId).ToListAsync(); } + public async Task GetUserEquInfo(string ueId) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Queryable().Where(i => i.ueId == ueId).SingleAsync(); + } + + public async Task GetUserEquByEquIdCount(string userId, int equId) + { + int result = 0; + var data = await GetUserEquByEquId(userId, equId); + result = data.Count; + return result; + } + + public async Task> GetUserEquByEquId(string userId, int equId) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Queryable().Where(i => i.userId == userId && i.equId == equId).ToListAsync(); + } + public async Task AddUserEqu(string userId, int equId, int count, string remark) { bool result = false; @@ -109,6 +130,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame ue.EquAwaken = new List(); ue.GemMent = new List(); ue.useEndTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddYears(20)); + ue.isOn = 0; adds.Add(ue); } @@ -234,7 +256,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame log.remark = remark; var db = DbClient.AsTenant().GetConnectionWithAttr(); - await db.Insertable(log).ExecuteCommandAsync(); + await db.Insertable(log).SplitTable().ExecuteCommandAsync(); } private async Task AddEquLogs(List ues, int code, string remark, @@ -261,13 +283,13 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame } var db = DbClient.AsTenant().GetConnectionWithAttr(); - await db.Insertable(adds).ExecuteCommandAsync(); + await db.Insertable(adds).SplitTable().ExecuteCommandAsync(); } private async Task AddEquLogs(List logs) { var db = DbClient.AsTenant().GetConnectionWithAttr(); - await db.Insertable(logs).ExecuteCommandAsync(); + await db.Insertable(logs).SplitTable().ExecuteCommandAsync(); } #endregion diff --git a/Service/Application.Domain/Services/Service/Map/GameMapService.cs b/Service/Application.Domain/Services/Service/Map/GameMapService.cs index e4e884a..79ee6b8 100644 --- a/Service/Application.Domain/Services/Service/Map/GameMapService.cs +++ b/Service/Application.Domain/Services/Service/Map/GameMapService.cs @@ -153,7 +153,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame onLine.userId = userId; onLine.mapId = mapId; onLine.ip = ip; - onLine.upTime = TimeAssist.GetTimeStampNum; + onLine.upTime = TimeExtend.GetTimeStampSeconds; string key = string.Format(UserCache.BaseCacheKey, "UserOnline"); if (await redis.AddHashAsync(key, userId, onLine)) { @@ -165,7 +165,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame public async Task UpdateUserOnMap(unit_user_online data, string mapId) { data.mapId = mapId; - data.upTime = TimeAssist.GetTimeStampNum; + data.upTime = TimeExtend.GetTimeStampSeconds; string key = string.Format(UserCache.BaseCacheKey, "UserOnline"); if (await redis.AddHashAsync(key, data.userId, data)) { diff --git a/Service/Application.Domain/Services/Service/Map/GameStoreService.cs b/Service/Application.Domain/Services/Service/Map/GameStoreService.cs new file mode 100644 index 0000000..e9f6f42 --- /dev/null +++ b/Service/Application.Domain/Services/Service/Map/GameStoreService.cs @@ -0,0 +1,20 @@ +namespace Application.Domain; + +public class GameStoreService(ISqlSugarClient DbClient, IRedisCache redis) : IGameStoreService, ITransient +{ + public async Task> GetStoreData(int npc, int area, int page, int limit, + RefAsync total) + { + string _area = area.ToString(); + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Queryable() + .Where(it => it.npcId == npc && (it.areaId == "0" || it.areaId == _area)) + .ToPageListAsync(page, limit, total); + } + + public async Task GetStoreInfo(string storeId) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Queryable().Where(it => it.storeId == storeId).SingleAsync(); + } +} \ No newline at end of file diff --git a/Service/Application.Domain/Tool/Base/GameBus.cs b/Service/Application.Domain/Tool/Base/GameBus.cs new file mode 100644 index 0000000..619ba47 --- /dev/null +++ b/Service/Application.Domain/Tool/Base/GameBus.cs @@ -0,0 +1,72 @@ +namespace Application.Domain; + +public class GameBus +{ + #region 物品资源操作 + + public static async Task UpdateBag(string userId, int operate, string goodsType, string parameter, long count, + string remark) + { + bool isok = false; + if (goodsType.Equals(nameof(GameEnum.PropCode.Goods))) + { + var goodsService = App.GetService(); + isok = await goodsService.UpdateUserGoods(userId, operate, Convert.ToInt32(parameter), (int)count, remark); + } + else if (goodsType.Equals(nameof(GameEnum.PropCode.Equ))) + { + var equService = App.GetService(); + if (operate == 1) + { + isok = await equService.AddUserEqu(userId, Convert.ToInt32(parameter), (int)count, remark); + } + else + { + isok = await equService.DeductUserEqu(userId, Convert.ToInt32(parameter), (int)count, remark); + } + } + else if (goodsType.Equals(nameof(GameEnum.PropCode.copper))) + { + var accService = App.GetService(); + isok = await accService.UpdateUserCopper(userId, operate, count); + } + else if (goodsType.Equals(nameof(GameEnum.PropCode.gold))) + { + var accService = App.GetService(); + isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.gold), count, + nameof(AccEnum.Name.其他), remark); + } + else if (goodsType.Equals(nameof(GameEnum.PropCode.cowry))) + { + var accService = App.GetService(); + isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.cowry), count, + nameof(AccEnum.Name.其他), remark); + } + else if (goodsType.Equals(nameof(GameEnum.PropCode.vigour))) + { + var attrService = App.GetService(); + isok = await attrService.UpdateUserVigour(userId, operate, count); + } + else if (goodsType.Equals(nameof(GameEnum.PropCode.exp))) + { + var attrService = App.GetService(); + isok = await attrService.UpdateUserExp(userId, count, operate); + } + else if (goodsType.Equals(nameof(GameEnum.PropCode.renown))) + { + var accService = App.GetService(); + isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.renown), count, + nameof(AccEnum.Name.其他), remark); + } + else if (goodsType.Equals(nameof(GameEnum.PropCode.teach))) + { + var accService = App.GetService(); + isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.teach), count, + nameof(AccEnum.Name.其他), remark); + } + + return isok; + } + + #endregion +} \ No newline at end of file diff --git a/Service/Application.Domain/Tool/Base/GameTool.cs b/Service/Application.Domain/Tool/Base/GameTool.cs index c2842a8..7b486aa 100644 --- a/Service/Application.Domain/Tool/Base/GameTool.cs +++ b/Service/Application.Domain/Tool/Base/GameTool.cs @@ -1,5 +1,4 @@ - -namespace Application.Domain; +namespace Application.Domain; public class GameTool { @@ -21,6 +20,7 @@ public class GameTool data.levUpdate = TimeExtend.GetTimeStampSeconds; return data; } + /// /// 获取等级升级经验 /// @@ -32,10 +32,59 @@ public class GameTool return result; } - public static bool AreaVerify( int area,string areas) + public static bool AreaVerify(int area, string areas) { - List onArea = new List() {"0",area.ToString() }; + List onArea = new List() { "0", area.ToString() }; return onArea.Any(it => areas.Contains(it)); } - + + public static string GetCurrencyName(string payCode) + { + string result = ""; + switch (payCode) + { + case "gold": + result = "金元"; + break; + case "cowry": + result = "金贝"; + break; + case "copper": + result = "铜贝"; + break; + case "teach": + result = "师德"; + break; + case "renown": + result = "声望"; + break; + } + + return result; + } + + public static async Task GetPropWeight(string goodsType, string parameter) + { + int weight = 0; + if (goodsType.Equals(nameof(GameEnum.PropCode.Goods))) + { + var goodsService = App.GetService(); + var info = await goodsService.GetGoodsInfo(Convert.ToInt32(parameter)); + if (info != null) + { + weight = (int)info.weight; + } + } + else if (goodsType.Equals(nameof(GameEnum.PropCode.Equ))) + { + var equService = App.GetService(); + var info = await equService.GetEquInfo(Convert.ToInt32(parameter)); + if (info != null) + { + weight = (int)info.weight; + } + } + + return weight; + } } \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Map/MapController.cs b/Service/Application.Web/Controllers/Map/MapController.cs index 67f6c2d..14359c4 100644 --- a/Service/Application.Web/Controllers/Map/MapController.cs +++ b/Service/Application.Web/Controllers/Map/MapController.cs @@ -162,4 +162,38 @@ public class MapController : ControllerBase return PoAction.Message("无法自动寻路!"); } } + + #region npc相关 + + /// + /// 获取NPC相关信息 + /// + /// + /// + [HttpGet] + public async Task GetNpcInfo(int npcId) + { + string userId = StateHelper.userId; + var data = await _mapService.GetNpcInfo(npcId); + if (data == null) + { + return PoAction.Message("Npc不存在!"); + } + + if (data.status != 1) + { + return PoAction.Message("Npc不存在!"); + } + + var onMap = await _mapService.GetUserOnMapId(userId); + if (data.mapId != onMap) + { + return PoAction.Message("Npc不存在!"); + } + + return PoAction.Ok(data); + } + + + #endregion } \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Map/StoreController.cs b/Service/Application.Web/Controllers/Map/StoreController.cs new file mode 100644 index 0000000..88879dd --- /dev/null +++ b/Service/Application.Web/Controllers/Map/StoreController.cs @@ -0,0 +1,284 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Application.Web.Controllers.Map; + +/// +/// 商店接口 +/// +[ApiExplorerSettings(GroupName = "Map")] +[Route("Map/[controller]/[action]")] +[ApiController] +[Authorize] +public class StoreController : ControllerBase +{ + private readonly IGameStoreService _storeService; + private readonly IGameMapService _mapService; + private readonly IUnitUserAccService _accService; + private readonly IUnitUserWeight _weightService; + private readonly IGameEquService _equService; + private readonly IGameGoodsService _goodsService; + + public StoreController(IGameStoreService storeService, IGameMapService mapService, IUnitUserAccService accService, + IUnitUserWeight weightService, IGameEquService equService, IGameGoodsService goodsService) + { + _storeService = storeService; + _mapService = mapService; + _accService = accService; + _weightService = weightService; + _equService = equService; + _goodsService = goodsService; + } + + /// + /// 获取npc商店信息 + /// + /// + /// + /// + [HttpGet] + public async Task GetNpcStore(int npcId, int page) + { + 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不存在!"); + } + + var onMap = await _mapService.GetUserOnMapId(userId); + if (npcInfo.mapId != onMap) + { + return PoAction.Message("Npc不存在!"); + } + + RefAsync Total = 0; + var data = await _storeService.GetStoreData(npcId, areaId, page, 10, Total); + + return PoAction.Ok(new { data, total = Total.Value, npcInfo.npcName }); + } + + /// + /// 购买物品 + /// + /// + /// + [HttpPost] + public async Task Buy([FromBody] StoreBuyParms parms) + { + parms.count = parms.count < 1 ? 1 : parms.count; + string userId = StateHelper.userId; + int areaId = StateHelper.areaId; + var npcInfo = await _mapService.GetNpcInfo(parms.npcId); + if (npcInfo == null) + { + return PoAction.Message("Npc不存在!"); + } + + if (npcInfo.status != 1) + { + return PoAction.Message("Npc不存在!"); + } + + var onMap = await _mapService.GetUserOnMapId(userId); + if (npcInfo.mapId != onMap) + { + return PoAction.Message("Npc不存在!"); + } + + var storeInfo = await _storeService.GetStoreInfo(parms.storeId); + if (storeInfo == null) + { + return PoAction.Message("商品已下架!"); + } + + if (!GameTool.AreaVerify(areaId, storeInfo.areaId)) + { + return PoAction.Message("商品已下架!"); + } + + if (storeInfo.npcId != parms.npcId) + { + return PoAction.Message("商品已下架!"); + } + + //此处需要计算负重 + var needWeight = await GameTool.GetPropWeight(storeInfo.type, storeInfo.parameter); + needWeight = needWeight * parms.count; + if (await _weightService.CheakUserWeight(userId, needWeight) == false) + { + return PoAction.Message("负重不足!"); + } + + long need = parms.count * (long)storeInfo.price; + var myAcc = await _accService.GetUserAccInfo(userId, storeInfo.payType); + if (myAcc < need) + { + return PoAction.Message($"您的{GameTool.GetCurrencyName(storeInfo.payType)}不足!"); + } + + if (await _accService.UpdateUserAccBath(userId, 0, storeInfo.payType, need, nameof(AccEnum.Name.Npc商城), + $"商城购买物品:{storeInfo.name}×{parms.count}")) + { + await GameBus.UpdateBag(userId, 1, storeInfo.type, storeInfo.parameter, parms.count, "Npc商店购买"); + return PoAction.Ok(true); + } + else + { + return PoAction.Message("购买失败,请稍后尝试!"); + } + } + + /// + /// 出售物品 + /// + /// + /// + /// + /// + /// + [HttpGet] + public async Task GetNpcSale(int npcId, int type, string? query, int page) + { + 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不存在!"); + } + + var onMap = await _mapService.GetUserOnMapId(userId); + if (npcInfo.mapId != onMap) + { + return PoAction.Message("Npc不存在!"); + } + + RefAsync total = 0; + + if (type == 0) + { + var data = await _equService.GetUserEquData(userId, 0, query, page, 10, total, true); + return PoAction.Ok(new { data, total.Value }); + } + else if (type == 1) + { + List code = new List() { nameof(GoodsEnum.Code.Drug) }; + var data = await _goodsService.GetUserGoodsData(userId, code, new List(), query, page, 10, total); + return PoAction.Ok(new { data, total.Value }); + } + else if (type == 2) + { + List code = new List(); + List noCode = new List() { nameof(GoodsEnum.Code.Drug) }; + var data = await _goodsService.GetUserGoodsData(userId, code, noCode, query, page, 10, total); + return PoAction.Ok(new { data, total.Value }); + } + else + { + return PoAction.Ok(new { data = new List(), total.Value }); + } + } + + /// + /// 出售物品 + /// + /// + /// + [HttpPost] + public async Task Sale([FromBody] StoreSaleParms parms) + { + parms.count = parms.count < 1 ? 1 : parms.count; + string userId = StateHelper.userId; + int areaId = StateHelper.areaId; + var npcInfo = await _mapService.GetNpcInfo(parms.npcId); + if (npcInfo == null) + { + return PoAction.Message("Npc不存在!"); + } + + if (npcInfo.status != 1) + { + return PoAction.Message("Npc不存在!"); + } + + var onMap = await _mapService.GetUserOnMapId(userId); + if (npcInfo.mapId != onMap) + { + return PoAction.Message("Npc不存在!"); + } + + if (parms.type == 0)//装备 + { + var equInfo = await _equService.GetUserEquInfo(parms.id); + if (equInfo == null) + { + return PoAction.Message("装备不存在!"); + } + + if (equInfo.userId != userId) + { + return PoAction.Message("装备不存在!"); + } + + if (equInfo.isOn == 1) + { + return PoAction.Message("穿戴中的装备无法出售!"); + } + + if (equInfo.isLock == 1) + { + return PoAction.Message("装备已锁定!"); + } + + if (await _equService.DeductUserEqu(userId, new List() { equInfo }, "出售装备")) + { + await _accService.UpdateUserCopper(userId, 1, (int)equInfo.sysPrice, "出售装备"); + return PoAction.Ok(true, $"出售成功,获得{equInfo.sysPrice}铜贝!"); + } + else + { + return PoAction.Message("出售失败,请稍后尝试!"); + } + } + else //物品 + { + var goodsInfo = await _goodsService.GetUserGoodsInfo(parms.id); + if (goodsInfo == null) + { + return PoAction.Message("物品不存在!"); + } + + if (goodsInfo.userId != userId) + { + return PoAction.Message("物品不存在!"); + } + + if (goodsInfo.count < parms.count) + { + return PoAction.Message("物品不足!"); + } + + if (await _goodsService.UpdateUserGoods(userId, 0, (int)goodsInfo.goodsId, parms.count, "出售物品")) + { + long copper = (int)goodsInfo.sysPrice * parms.count; + await _accService.UpdateUserCopper(userId, 1, copper, "出售装备"); + return PoAction.Ok(true, $"出售成功,获得{copper}铜贝!"); + } + else + { + return PoAction.Message("出售失败,请稍后尝试!"); + } + } + } +} \ No newline at end of file diff --git a/Service/Application.Web/Controllers/User/UserController.cs b/Service/Application.Web/Controllers/User/UserController.cs index 069fb6a..b956143 100644 --- a/Service/Application.Web/Controllers/User/UserController.cs +++ b/Service/Application.Web/Controllers/User/UserController.cs @@ -70,7 +70,8 @@ public class UserController : ControllerBase object acc = new { accInfo.teach }; var online = await _mapService.GetUserOnMap(userInfo.userId); - int isOnline = online.upTime > TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddMinutes(GameConfig.OnLineTime)) + int isOnline = online.upTime > + TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddMinutes(0 - GameConfig.OnLineTime)) ? 1 : 0; var onMapInfo = await _mapService.GetMapInfo(online.mapId); diff --git a/Service/Application.Web/Model/RequestParms/Store/StoreBuyParms.cs b/Service/Application.Web/Model/RequestParms/Store/StoreBuyParms.cs new file mode 100644 index 0000000..383b5e0 --- /dev/null +++ b/Service/Application.Web/Model/RequestParms/Store/StoreBuyParms.cs @@ -0,0 +1,9 @@ +namespace Application.Web; + +public class StoreBuyParms +{ + public int npcId { get; set; } + public string storeId { get; set; } + public int count { get; set; } + +} \ No newline at end of file diff --git a/Service/Application.Web/Model/RequestParms/Store/StoreSaleParms.cs b/Service/Application.Web/Model/RequestParms/Store/StoreSaleParms.cs new file mode 100644 index 0000000..ef4c489 --- /dev/null +++ b/Service/Application.Web/Model/RequestParms/Store/StoreSaleParms.cs @@ -0,0 +1,10 @@ +namespace Application.Web; + +public class StoreSaleParms +{ + public int npcId { get; set; } + public int count { get; set; } + public string search { get; set; } + public int type { get; set; } + public string id { get; set; } +} \ No newline at end of file diff --git a/Web/src/composables/LocalStorageHelper.ts b/Web/src/composables/LocalStorageHelper.ts new file mode 100644 index 0000000..90246ff --- /dev/null +++ b/Web/src/composables/LocalStorageHelper.ts @@ -0,0 +1,12 @@ +export class LocalStorageHelper { + + /**npc相关 */ + private static key: string = 'OnNpc'; + public static GetOnNpc() { + return LocalStorageExtend.Get(this.key); + } + public static SetOnNpc(npcId: String) { + LocalStorageExtend.Set(this.key, npcId); + } + +} \ No newline at end of file diff --git a/Web/src/pages/business/retBlooad.vue b/Web/src/pages/business/retBlooad.vue new file mode 100644 index 0000000..41a40c8 --- /dev/null +++ b/Web/src/pages/business/retBlooad.vue @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Web/src/pages/business/retMorale.vue b/Web/src/pages/business/retMorale.vue new file mode 100644 index 0000000..41a40c8 --- /dev/null +++ b/Web/src/pages/business/retMorale.vue @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Web/src/pages/map/index.vue b/Web/src/pages/map/index.vue index ce2a0a6..ead271d 100644 --- a/Web/src/pages/map/index.vue +++ b/Web/src/pages/map/index.vue @@ -20,7 +20,7 @@
- {{ item.npcName }}{{ item.tips }} + {{ item.npcName }}{{ item.tips }}
diff --git a/Web/src/pages/npc/index.vue b/Web/src/pages/npc/index.vue new file mode 100644 index 0000000..3828d30 --- /dev/null +++ b/Web/src/pages/npc/index.vue @@ -0,0 +1,49 @@ + + \ No newline at end of file diff --git a/Web/src/pages/store/buy.vue b/Web/src/pages/store/buy.vue new file mode 100644 index 0000000..2799cf2 --- /dev/null +++ b/Web/src/pages/store/buy.vue @@ -0,0 +1,100 @@ + + \ No newline at end of file diff --git a/Web/src/pages/store/sale.vue b/Web/src/pages/store/sale.vue new file mode 100644 index 0000000..320819a --- /dev/null +++ b/Web/src/pages/store/sale.vue @@ -0,0 +1,141 @@ + + \ No newline at end of file diff --git a/Web/src/pages/user/user.vue b/Web/src/pages/user/user.vue index 70b6455..0c73190 100644 --- a/Web/src/pages/user/user.vue +++ b/Web/src/pages/user/user.vue @@ -70,7 +70,7 @@ const BindData = async (): Promise => { userData.value = result.data.user; attrData.value = result.data.attr; accData.value = result.data.acc; - online.value = result.data.isOnline; + online.value = result.data.isOnline; onMap.value = result.data.onMapName; console.log(result); } diff --git a/Web/src/services/map/MapService.ts b/Web/src/services/map/MapService.ts index 3ca14d4..7d8cd81 100644 --- a/Web/src/services/map/MapService.ts +++ b/Web/src/services/map/MapService.ts @@ -30,4 +30,12 @@ export class MapService { static async GetAutoMapPath(toMap: string) { return await ApiService.Request("get", "/Map/Map/GetAutoMapPath", { toMap }); } + + /** + * 获取NPC相关信息 + * GET /Map/Map/GetNpcInfo + */ + static async GetNpcInfo(npcId: number) { + return await ApiService.Request("get", "/Map/Map/GetNpcInfo", { npcId }); + } } \ No newline at end of file diff --git a/Web/src/services/map/StoreService.ts b/Web/src/services/map/StoreService.ts new file mode 100644 index 0000000..49299a6 --- /dev/null +++ b/Web/src/services/map/StoreService.ts @@ -0,0 +1,41 @@ +export class StoreService { + /** + * 获取npc商店信息 + * GET /Map/Store/GetNpcStore + */ + static async GetNpcStore(npcId: number, page: number) { + return await ApiService.Request("get", "/Map/Store/GetNpcStore", { npcId, page }); + } + + /** + * 购买物品 + * POST /Map/Store/Buy + * @param npcId body + * @param storeId body + * @param count body + */ + static async Buy(npcId: number, storeId: string, count: number) { + return await ApiService.Request("post", "/Map/Store/Buy", { npcId, storeId, count }); + } + + /** + * 出售物品 + * GET /Map/Store/GetNpcSale + */ + static async GetNpcSale(npcId: number, type: number, query: string, page: number) { + return await ApiService.Request("get", "/Map/Store/GetNpcSale", { npcId, type, query, page }); + } + + /** + * 出售物品 + * POST /Map/Store/Sale + * @param npcId body + * @param count body + * @param search body + * @param type body + * @param id body + */ + static async Sale(npcId: number, count: number, search: string, type: number, id: string) { + return await ApiService.Request("post", "/Map/Store/Sale", { npcId, count, search, type, id }); + } +} \ No newline at end of file diff --git a/Web/src/utility‌/GameTool.ts b/Web/src/utility‌/GameTool.ts index 0199f64..29e8d15 100644 --- a/Web/src/utility‌/GameTool.ts +++ b/Web/src/utility‌/GameTool.ts @@ -1,9 +1,9 @@ export class GameTool { - /** - * 静态方法:将总铜数转换为 金/银/铜 字符串 - * @param totalCopper 总铜数量 - * @returns 格式化字符串,如:1金 234银 567铜 - */ + /** + * 静态方法:将总铜数转换为 金/银/铜 字符串 + * @param totalCopper 总铜数量 + * @returns 格式化字符串,如:1金 234银 567铜 + */ public static FormatCopper(totalCopper: number | string): string { // 安全转为数字并取整(货币无小数) let copper = Math.floor(Number(totalCopper) || 0); @@ -35,4 +35,49 @@ export class GameTool { return result; } + + /**获取货币名称 */ + public static GetCurrency‌Name(pay: string): string { + let result = ""; + switch (pay) { + case 'gold': + result = '金元'; + break; + case 'cowry': + result = '金贝'; + break; + case 'copper': + result = '铜贝'; + break; + case 'teach': + result = '师德'; + break; + case 'renown': + result = '声望'; + break; + } + return result; + } + public static GetCurrency‌NameAll(num: number, pay: string): string { + let result = ""; + switch (pay) { + case 'gold': + result = '金元'; + break; + case 'cowry': + result = '金贝'; + break; + case 'copper': + return this.FormatCopper(num); + break; + case 'teach': + result = '师德'; + break; + case 'renown': + result = '声望'; + break; + } + return `${num}${result}`; + } + } \ No newline at end of file