2222
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
7
Service/Application.Domain.Entity/model/NpcBus.cs
Normal file
7
Service/Application.Domain.Entity/model/NpcBus.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Application.Domain.Entity;
|
||||
|
||||
public class NpcBus
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string url { get; set; }
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace Application.Domain.Entity
|
||||
/// <summary>
|
||||
/// bus
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? bus { get; set; }
|
||||
[SugarColumn(IsNullable = true,IsJson = true)]
|
||||
public List<NpcBus>? bus { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_city_npc_store
|
||||
{
|
||||
/// <summary>
|
||||
/// storeId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string storeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// npcId
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? npcId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// areaId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? areaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// type
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// parameter
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 11, IsNullable = true)]
|
||||
public string? parameter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// price
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? price { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// payType
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? payType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// sort
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? sort { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
减少,
|
||||
|
||||
@@ -10,9 +10,12 @@ public interface IGameEquService
|
||||
#region 用户装备
|
||||
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex, int PageSize,
|
||||
RefAsync<int> Total);
|
||||
RefAsync<int> Total, bool isRemOn = false);
|
||||
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, int equId);
|
||||
Task<unit_user_equ> GetUserEquInfo(string ueId);
|
||||
Task<int> GetUserEquByEquIdCount(string userId, int equId);
|
||||
Task<List<unit_user_equ>> GetUserEquByEquId(string userId, int equId);
|
||||
Task<bool> AddUserEqu(string userId, int equId, int count, string remark);
|
||||
|
||||
Task<bool> UpdateUserEquInfo(unit_user_equ equData, bool isAddLog = false, string code = "",
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameStoreService
|
||||
{
|
||||
Task<List<game_city_npc_store>> GetStoreData(int npc, int area, int page, int limit,
|
||||
RefAsync<int> total);
|
||||
|
||||
Task<game_city_npc_store> GetStoreInfo(string storeId);
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
#region 用户装备
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex,
|
||||
int PageSize, RefAsync<int> Total)
|
||||
int PageSize, RefAsync<int> Total, bool isRemOn = false)
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
@@ -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<unit_user_equ>().Where(it => it.userId == userId && it.equId == equId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<unit_user_equ> GetUserEquInfo(string ueId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
return await db.Queryable<unit_user_equ>().Where(i => i.ueId == ueId).SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<int> GetUserEquByEquIdCount(string userId, int equId)
|
||||
{
|
||||
int result = 0;
|
||||
var data = await GetUserEquByEquId(userId, equId);
|
||||
result = data.Count;
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquByEquId(string userId, int equId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
return await db.Queryable<unit_user_equ>().Where(i => i.userId == userId && i.equId == equId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> 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<EquAwaken>();
|
||||
ue.GemMent = new List<EquGem>();
|
||||
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<unit_user_equ_log>();
|
||||
await db.Insertable(log).ExecuteCommandAsync();
|
||||
await db.Insertable(log).SplitTable().ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
private async Task AddEquLogs(List<unit_user_equ> ues, int code, string remark,
|
||||
@@ -261,13 +283,13 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ_log>();
|
||||
await db.Insertable(adds).ExecuteCommandAsync();
|
||||
await db.Insertable(adds).SplitTable().ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
private async Task AddEquLogs(List<unit_user_equ_log> logs)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ_log>();
|
||||
await db.Insertable(logs).ExecuteCommandAsync();
|
||||
await db.Insertable(logs).SplitTable().ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -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<bool> 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))
|
||||
{
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameStoreService(ISqlSugarClient DbClient, IRedisCache redis) : IGameStoreService, ITransient
|
||||
{
|
||||
public async Task<List<game_city_npc_store>> GetStoreData(int npc, int area, int page, int limit,
|
||||
RefAsync<int> total)
|
||||
{
|
||||
string _area = area.ToString();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_npc_store>();
|
||||
return await db.Queryable<game_city_npc_store>()
|
||||
.Where(it => it.npcId == npc && (it.areaId == "0" || it.areaId == _area))
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
|
||||
public async Task<game_city_npc_store> GetStoreInfo(string storeId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_npc_store>();
|
||||
return await db.Queryable<game_city_npc_store>().Where(it => it.storeId == storeId).SingleAsync();
|
||||
}
|
||||
}
|
||||
72
Service/Application.Domain/Tool/Base/GameBus.cs
Normal file
72
Service/Application.Domain/Tool/Base/GameBus.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameBus
|
||||
{
|
||||
#region 物品资源操作
|
||||
|
||||
public static async Task<bool> 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<IGameGoodsService>();
|
||||
isok = await goodsService.UpdateUserGoods(userId, operate, Convert.ToInt32(parameter), (int)count, remark);
|
||||
}
|
||||
else if (goodsType.Equals(nameof(GameEnum.PropCode.Equ)))
|
||||
{
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
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<IUnitUserAccService>();
|
||||
isok = await accService.UpdateUserCopper(userId, operate, count);
|
||||
}
|
||||
else if (goodsType.Equals(nameof(GameEnum.PropCode.gold)))
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
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<IUnitUserAccService>();
|
||||
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<IUnitUserAttrService>();
|
||||
isok = await attrService.UpdateUserVigour(userId, operate, count);
|
||||
}
|
||||
else if (goodsType.Equals(nameof(GameEnum.PropCode.exp)))
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
isok = await attrService.UpdateUserExp(userId, count, operate);
|
||||
}
|
||||
else if (goodsType.Equals(nameof(GameEnum.PropCode.renown)))
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
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<IUnitUserAccService>();
|
||||
isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.teach), count,
|
||||
nameof(AccEnum.Name.其他), remark);
|
||||
}
|
||||
|
||||
return isok;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取等级升级经验
|
||||
/// </summary>
|
||||
@@ -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<string> onArea = new List<string>() {"0",area.ToString() };
|
||||
List<string> onArea = new List<string>() { "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<int> GetPropWeight(string goodsType, string parameter)
|
||||
{
|
||||
int weight = 0;
|
||||
if (goodsType.Equals(nameof(GameEnum.PropCode.Goods)))
|
||||
{
|
||||
var goodsService = App.GetService<IGameGoodsService>();
|
||||
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<IGameEquService>();
|
||||
var info = await equService.GetEquInfo(Convert.ToInt32(parameter));
|
||||
if (info != null)
|
||||
{
|
||||
weight = (int)info.weight;
|
||||
}
|
||||
}
|
||||
|
||||
return weight;
|
||||
}
|
||||
}
|
||||
@@ -162,4 +162,38 @@ public class MapController : ControllerBase
|
||||
return PoAction.Message("无法自动寻路!");
|
||||
}
|
||||
}
|
||||
|
||||
#region npc相关
|
||||
|
||||
/// <summary>
|
||||
/// 获取NPC相关信息
|
||||
/// </summary>
|
||||
/// <param name="npcId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> 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
|
||||
}
|
||||
284
Service/Application.Web/Controllers/Map/StoreController.cs
Normal file
284
Service/Application.Web/Controllers/Map/StoreController.cs
Normal file
@@ -0,0 +1,284 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.Map;
|
||||
|
||||
/// <summary>
|
||||
/// 商店接口
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取npc商店信息
|
||||
/// </summary>
|
||||
/// <param name="npcId"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> 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<int> Total = 0;
|
||||
var data = await _storeService.GetStoreData(npcId, areaId, page, 10, Total);
|
||||
|
||||
return PoAction.Ok(new { data, total = Total.Value, npcInfo.npcName });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 购买物品
|
||||
/// </summary>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> 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("购买失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 出售物品
|
||||
/// </summary>
|
||||
/// <param name="npcId"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> 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<int> 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<string> code = new List<string>() { nameof(GoodsEnum.Code.Drug) };
|
||||
var data = await _goodsService.GetUserGoodsData(userId, code, new List<string>(), query, page, 10, total);
|
||||
return PoAction.Ok(new { data, total.Value });
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
List<string> code = new List<string>();
|
||||
List<string> noCode = new List<string>() { 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<string>(), total.Value });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 出售物品
|
||||
/// </summary>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> 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<unit_user_equ>() { 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("出售失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
Reference in New Issue
Block a user