This commit is contained in:
Putoo
2026-06-05 18:06:38 +08:00
parent 5195407266
commit 1927e3f960
17 changed files with 575 additions and 27 deletions

View File

@@ -65,7 +65,11 @@ public interface IGameMapService
#region
Task<game_city_map_res> GetMapResInfo(string resId);
Task<List<game_city_map_res>> GetMapRes(string mapId);
Task<List<MapResModel>> GetMapResData(string mapId, int area);
Task<long> GetMapResLockTime(string resId, int area);
Task SetMapResLockTime(string resId, int area, int lockTime);
#endregion
}

View File

@@ -0,0 +1,11 @@
namespace Application.Domain;
public interface IGameSkillService
{
Task<game_skill> GetGameSkillInfo(int skillId);
Task<unit_user_skill> GetUserSkillInfo(string userId, string code);
Task<List<AttrItem>> GetUserSkillAttr(string userId);
Task<List<unit_user_skill>> GetUserSkill(string userId);
Task<bool> UpdateUserSkill(string userId, int skillId);
}

View File

@@ -877,14 +877,15 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
public async Task<game_city_map_bus> GetMapBusInfo(int busId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "CITY_MAP_BUS","BUS_INFO");
string key = string.Format(BaseCache.BaseCacheKeys, "CITY_MAP_BUS", "BUS_INFO");
if (await redis.HExistsHashAsync(key, busId.ToString()))
{
return await redis.GetHashAsync<game_city_map_bus>(key, busId.ToString());
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map_bus>();
var data = await db.Queryable<game_city_map_bus>().Where(it => it.busId == busId).SingleAsync();
await redis.AddHashAsync(key,busId.ToString(), data);
var data = await db.Queryable<game_city_map_bus>().Where(it => it.busId == busId).SingleAsync();
await redis.AddHashAsync(key, busId.ToString(), data);
return data;
}
@@ -924,7 +925,19 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
#endregion
#region
public async Task<game_city_map_res> GetMapResInfo(string resId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapResInfo");
var data = await redis.GetHashAsync<game_city_map_res>(key, resId);
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map_res>();
data = await db.Queryable<game_city_map_res>().Where(it => it.resId == resId).SingleAsync();
await redis.AddHashAsync(key, resId, data);
}
return data;
}
public async Task<List<game_city_map_res>> GetMapRes(string mapId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapRes");
@@ -933,12 +946,56 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map_res>();
data = await db.Queryable<game_city_map_res>().Where(it => it.mapId == mapId).ToListAsync();
await redis.AddHashAsync(key, mapId,data);
await redis.AddHashAsync(key, mapId, data);
}
return data;
}
public async Task<List<MapResModel>> GetMapResData(string mapId, int area)
{
var data = await GetMapRes(mapId);
List<MapResModel> result = new List<MapResModel>();
foreach (var item in data)
{
long lockTime = await GetMapResLockTime(item.resId, area);
MapResModel temp = new MapResModel()
{
resId = item.resId,
resName = item.resName,
lev = (int)item.lev,
lockTime = lockTime,
needVigour = (int)item.needVigour,
gather = (int)item.gatherTime
};
result.Add(temp);
}
return result;
}
public async Task<long> GetMapResLockTime(string resId, int area)
{
long result = 0;
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapResLockTime");
string field = $"{area}_{resId}";
if (await redis.HExistsHashAsync(key, field))
{
long lockTime = await redis.GetHashAsync<long>(key, field);
result = lockTime - TimeExtend.GetTimeStampSeconds;
result = result <= 0 ? 0 : result;
}
return result;
}
public async Task SetMapResLockTime(string resId, int area, int lockTime)
{
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapResLockTime");
string field = $"{area}_{resId}";
long atTime = TimeExtend.GetTimeStampSeconds + lockTime;
await redis.AddHashAsync(key, field, atTime);
}
#endregion
}

View File

@@ -0,0 +1,120 @@
using Newtonsoft.Json;
namespace Application.Domain;
public class GameSkillService(ISqlSugarClient DbClient, IRedisCache redis) : IGameSkillService, ITransient
{
public async Task<game_skill> GetGameSkillInfo(int skillId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "SkillData", "SkillInfo");
var data = await redis.GetHashAsync<game_skill>(key, skillId.ToString());
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_skill>();
data = await db.Queryable<game_skill>().Where(it => it.skill == skillId).SingleAsync();
await redis.AddHashAsync(key, skillId.ToString(), data);
}
return data;
}
private string GetUserSkillKey(string userId, string code)
{
return $"{userId}_{code}";
}
public async Task<unit_user_skill> GetUserSkillInfo(string userId, string code)
{
string usId = GetUserSkillKey(userId, code);
string key = string.Format(BaseCache.BaseCacheKeys, "SkillData", "UserSkill");
if (await redis.HExistsHashAsync(key,usId))
{
return await redis.GetHashAsync<unit_user_skill>(key,usId);
}
else
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_skill>();
var data = await db.Queryable<unit_user_skill>().Where(it => it.usId == usId).SingleAsync();
await redis.AddHashAsync(key,usId, data);
return data;
}
}
public async Task<List<AttrItem>> GetUserSkillAttr(string userId)
{
List<AttrItem> result = new List<AttrItem>();
string key = string.Format(BaseCache.BaseCacheKeys, "SkillData", "UserSkillAttr");
if (await redis.HExistsHashAsync(key,userId))
{
result = await redis.GetHashAsync<List<AttrItem>>(key,userId);
}
else
{
var data = await GetUserSkill(userId);
foreach (var item in data)
{
if (item.code == nameof(SkillEnum.code.ATK) || item.code ==nameof(SkillEnum.code.DEFENCE) ||
item.code == nameof(SkillEnum.code.AGILE))
{
List<AttrItem> attr = JsonConvert.DeserializeObject<List<AttrItem>>(item.sign);
result.AddRange(attr);
}
}
await redis.AddHashAsync(key,userId, result);
}
return result;
}
public async Task<List<unit_user_skill>> GetUserSkill(string userId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_skill>();
return await db.Queryable<unit_user_skill>().Where(it => it.userId == userId)
.OrderBy(it => it.name, OrderByType.Asc).ToListAsync();
}
private async Task ClearUserSkillInfo(string userId, string code)
{
string usId = GetUserSkillKey(userId, code);
string key = string.Format(BaseCache.BaseCacheKeys, "SkillData", "UserSkill");
await redis.DelHashAsync(key,usId);
key = string.Format(BaseCache.BaseCacheKeys, "SkillData", "UserSkillAttr");
await redis.DelHashAsync(key);
}
public async Task<bool> UpdateUserSkill(string userId, int skillId)
{
bool result = false;
var skillInfo = await GetGameSkillInfo(skillId);
if (skillInfo != null)
{
unit_user_skill usInfo = new unit_user_skill();
usInfo.usId = GetUserSkillKey(userId, skillInfo.code);
usInfo.userId = userId;
usInfo.code = skillInfo.code;
usInfo.skill = skillInfo.skill;
usInfo.name = skillInfo.name;
usInfo.lev = skillInfo.lev;
usInfo.sign = skillInfo.sign;
usInfo.remark = skillInfo.remark;
var userSkill = await GetUserSkillInfo(userId, skillInfo.code);
if (userSkill == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_skill>();
result = await db.Insertable(usInfo).ExecuteCommandAsync() > 0;
}
else if (userSkill.lev < skillInfo.lev)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_skill>();
result = await db.Updateable(usInfo).ExecuteCommandAsync() > 0;
}
}
if (result)
{
await ClearUserSkillInfo(userId, skillInfo.code);
}
return result;
}
}