This commit is contained in:
Putoo
2026-05-27 18:26:50 +08:00
parent 36a7575990
commit 0d5443ef36
28 changed files with 1043 additions and 25 deletions

View File

@@ -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
{
,

View File

@@ -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 = "",

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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))
{

View File

@@ -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();
}
}

View 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
}

View File

@@ -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;
}
}