12121
This commit is contained in:
19
Service/Application.Domain/Enum/SkillEnum.cs
Normal file
19
Service/Application.Domain/Enum/SkillEnum.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public static class SkillEnum
|
||||
{
|
||||
public enum code
|
||||
{
|
||||
GATHER,//采集术
|
||||
FISH,//钓鱼术
|
||||
DIVE,//潜水术
|
||||
NEGOTI,//谈判术
|
||||
FINANC,//理财术
|
||||
ATK,//攻击术
|
||||
DEFENCE,//防御术
|
||||
AGILE,//敏捷术
|
||||
RIDI,//乘骑术
|
||||
WING,//翼形术
|
||||
Collect,//采集术
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user