1111
This commit is contained in:
@@ -2,5 +2,22 @@
|
||||
|
||||
public interface IGameEquService
|
||||
{
|
||||
#region 装备资源
|
||||
|
||||
Task<game_equ> GetEquInfo(int equId);
|
||||
|
||||
#endregion
|
||||
#region 用户装备
|
||||
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex, int PageSize,
|
||||
RefAsync<int> Total);
|
||||
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, int equId);
|
||||
Task<bool> AddUserEqu(string userId, int equId, int count, string remark);
|
||||
Task<bool> DeductUserEqu(string userId, List<unit_user_equ> equData, string remark);
|
||||
Task<bool> DeductUserEqu(string userId, int equId, int count, string remark);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public interface IGameGoodsService
|
||||
Task<unit_user_goods> GetUserGoodsInfo(string userId, int goodsId);
|
||||
Task<int> GetUserGoodsCount(string userId, int goodsId);
|
||||
|
||||
Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, string search, int page,
|
||||
Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, List<string> noCode, string search, int page,
|
||||
int limit, RefAsync<int> total);
|
||||
|
||||
Task<bool> UpdateUserGoods(string userId, int op, int goodsId, int count, string remark = "");
|
||||
|
||||
@@ -5,8 +5,10 @@ public interface IGameMapService
|
||||
#region 城市地图数据
|
||||
|
||||
Task<game_city> GetCityInfo(int cityId);
|
||||
Task<List<game_city>> GetCityData();
|
||||
Task<List<game_city_map>> GetCityMap(int cityId);
|
||||
Task<List<game_city_map>> GetCityShowMap(int cityId);
|
||||
Task<game_city_map> GetMapInfo(string mapId);
|
||||
Task<List<game_city_map>> GetMapCity(int cityId);
|
||||
Task<int> GetMapCityByMapId(string mapId);
|
||||
Task<List<game_city_npc>> GetMapNpc(string mapId);
|
||||
Task<game_city_npc> GetNpcInfo(int npcId);
|
||||
@@ -17,7 +19,9 @@ public interface IGameMapService
|
||||
Task<string> GetUserOnMapId(string userId);
|
||||
Task<unit_user_online> GetUserOnMap(string userId);
|
||||
Task UpdateUserOnMap(string userId, string ip, string mapId);
|
||||
|
||||
Task<bool> UpdateUserOnMap(unit_user_online data, string mapId);
|
||||
Task SetUserMapDefult(string userId);
|
||||
Task<game_city_map> GetToMapInfo(string userId, string toMap, bool isUpUserMap = true, bool isChangeCity = false);
|
||||
#endregion
|
||||
|
||||
#region 其他相关
|
||||
@@ -27,5 +31,12 @@ public interface IGameMapService
|
||||
Task<List<UserModel>> GetMapUser(string mapId, int area, int showArea, List<string> noUser, int page,
|
||||
int limit, RefAsync<int> total);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 自动寻路
|
||||
|
||||
Task<List<MapLine>> CreateAutoMap(string start, string end);
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IUnitUserAttrService
|
||||
{
|
||||
Task<unit_user_blood> GetUserBlood(string userId);
|
||||
Task<bool> UpdateUserBlood(string userId, int op, int count, bool mustUp = false);
|
||||
}
|
||||
@@ -2,4 +2,237 @@
|
||||
|
||||
public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGameEquService, ITransient
|
||||
{
|
||||
#region 装备资源
|
||||
|
||||
public async Task<game_equ> GetEquInfo(int equId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "EquData", "EquInfo");
|
||||
var data = await redis.GetHashAsync<game_equ>(key, equId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ>();
|
||||
data = await db.Queryable<game_equ>().Where(it => it.equId == equId).SingleAsync();
|
||||
await redis.AddHashAsync(key, equId.ToString(), data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 用户装备
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex,
|
||||
int PageSize, RefAsync<int> Total)
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
return await db.Queryable<unit_user_equ>().Where(it => it.userId == userId)
|
||||
.WhereIF(type == 2, it => it.useEndTime < onTime)
|
||||
.WhereIF(type == 1, it => it.isOn == 1)
|
||||
.WhereIF(type == 3, it => it.isAppr == 0)
|
||||
.WhereIF(!string.IsNullOrEmpty(equName),
|
||||
it => it.equName.Contains(equName) || it.unitEquName.Contains(equName))
|
||||
.OrderByDescending(it => it.lev)
|
||||
.OrderByDescending(it => it.ueId).ToPageListAsync(PageIndex, PageSize, Total);
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int equId)
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
return await db.Queryable<unit_user_equ>().Where(it => it.userId == userId && it.equId == equId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> AddUserEqu(string userId, int equId, int count, string remark)
|
||||
{
|
||||
bool result = false;
|
||||
var equ = await GetEquInfo(equId);
|
||||
if (equ != null)
|
||||
{
|
||||
List<unit_user_equ> adds = new List<unit_user_equ>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
unit_user_equ ue = new unit_user_equ();
|
||||
string ueId = StringAssist.NewGuid;
|
||||
ue.ueId = ueId;
|
||||
ue.userId = userId;
|
||||
ue.owerId = userId;
|
||||
ue.equId = equ.equId;
|
||||
ue.equName = equ.equName;
|
||||
ue.unitEquName = equ.equName;
|
||||
ue.img = equ.img;
|
||||
ue.sign = "";
|
||||
if (equ.isAppr == 0)
|
||||
{
|
||||
ue.minAtk = equ.minAtk;
|
||||
ue.maxAtk = equ.maxAtk;
|
||||
ue.Defense = Convert.ToInt32(equ.defense);
|
||||
ue.Agility = Convert.ToInt32(equ.agility);
|
||||
ue.Morale = Convert.ToInt32(equ.morale);
|
||||
ue.Blood = Convert.ToInt32(equ.blood);
|
||||
ue.isAppr = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ue.minAtk = 0;
|
||||
ue.maxAtk = 0;
|
||||
ue.Defense = 0;
|
||||
ue.Agility = 0;
|
||||
ue.Morale = 0;
|
||||
ue.Blood = 0;
|
||||
ue.isAppr = 0;
|
||||
}
|
||||
|
||||
ue.code = equ.code;
|
||||
ue.suitCode = equ.suitCode;
|
||||
ue.lev = equ.lev;
|
||||
ue.durability = equ.durability;
|
||||
ue.maxdurability = equ.durability;
|
||||
ue.isIntensify = equ.isIntensify;
|
||||
ue.intensifyLev = 0;
|
||||
ue.isLock = 0;
|
||||
ue.holeCount = equ.holeCount;
|
||||
ue.sex = equ.sex;
|
||||
ue.quality = 0;
|
||||
ue.qualityName = "普通";
|
||||
ue.qualityAttr = new List<AttrItem>();
|
||||
ue.weight = equ.weight;
|
||||
ue.sysPrice = equ.sysPrice;
|
||||
ue.EquAttr = equ.equAttr;
|
||||
ue.canEqualUp = equ.canEqualUp;
|
||||
ue.isDeal = equ.isDeal;
|
||||
ue.isGive = equ.isGive;
|
||||
ue.opTime = 0;
|
||||
ue.start = 0;
|
||||
ue.EquMent = new EquMent();
|
||||
ue.EquAwaken = new List<EquAwaken>();
|
||||
ue.GemMent = new List<EquGem>();
|
||||
ue.useEndTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddYears(20));
|
||||
adds.Add(ue);
|
||||
}
|
||||
|
||||
if (adds.Count > 0)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
result = await db.Insertable(adds).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
//添加日志
|
||||
await AddEquLog(adds, 1, remark, userId, true);
|
||||
//更新负重
|
||||
int weightCount = Convert.ToInt32(equ.weight) * count;
|
||||
if (weightCount > 0)
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserWeight>();
|
||||
await attrService.UpdateUserWeight(userId, 1, weightCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> DeductUserEqu(string userId, List<unit_user_equ> equData, string remark)
|
||||
{
|
||||
bool result = false;
|
||||
List<string> DelEqu = new List<string>();
|
||||
List<unit_user_equ_log> logs = new List<unit_user_equ_log>();
|
||||
int weightCount = 0;
|
||||
foreach (var item in equData)
|
||||
{
|
||||
weightCount += (int)item.weight;
|
||||
DelEqu.Add(item.ueId);
|
||||
//生成日志集合
|
||||
unit_user_equ_log log = new unit_user_equ_log();
|
||||
log.logId = StringAssist.NewGuid;
|
||||
log.ueId = item.ueId;
|
||||
log.userId = item.userId;
|
||||
log.code = nameof(GameEnum.LogCode.减少);
|
||||
log.equData = item;
|
||||
log.remark = remark;
|
||||
log.addTime = DateTime.Now;
|
||||
logs.Add(log);
|
||||
}
|
||||
|
||||
if (DelEqu.Count > 0)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
result = await db.Deleteable<unit_user_equ>().Where(i => DelEqu.Contains(i.ueId)).ExecuteCommandAsync() > 0;
|
||||
if (result) //生成成功
|
||||
{
|
||||
//更新负重
|
||||
if (weightCount > 0)
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserWeight>();
|
||||
await attrService.UpdateUserWeight(userId, 0, weightCount);
|
||||
}
|
||||
|
||||
if (logs.Count > 0)
|
||||
{
|
||||
await AddEquLog(logs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> DeductUserEqu(string userId, int equId, int count, string remark)
|
||||
{
|
||||
var userEqu = await GetUserEquData(userId, equId);
|
||||
if (userEqu.Count < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
userEqu = userEqu.FindAll(it => it.isLock == 0);
|
||||
if (userEqu.Count < count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
userEqu = userEqu.OrderBy(it => (int)it.intensifyLev)
|
||||
.OrderBy(it => it.quality)
|
||||
.ToList();
|
||||
var opData = userEqu.Take(count).ToList();
|
||||
return await DeductUserEqu(userId, opData, remark);
|
||||
}
|
||||
|
||||
private async Task AddEquLog(List<unit_user_equ> ues, int code, string remark, string userId,
|
||||
bool isAddAttr = false)
|
||||
{
|
||||
List<unit_user_equ_log> adds = new List<unit_user_equ_log>();
|
||||
foreach (var item in ues)
|
||||
{
|
||||
unit_user_equ_log bagLog = new unit_user_equ_log();
|
||||
bagLog.logId = StringAssist.NewGuid;
|
||||
bagLog.userId = userId;
|
||||
bagLog.ueId = item.ueId;
|
||||
bagLog.code = code == 0
|
||||
? bagLog.code = nameof(GameEnum.LogCode.减少)
|
||||
: bagLog.code = nameof(GameEnum.LogCode.增加);
|
||||
if (isAddAttr)
|
||||
{
|
||||
bagLog.equData = item;
|
||||
}
|
||||
|
||||
bagLog.addTime = DateTime.Now;
|
||||
bagLog.remark = remark;
|
||||
adds.Add(bagLog);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ_log>();
|
||||
await db.Insertable(adds).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
private async Task AddEquLog(List<unit_user_equ_log> logs)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ_log>();
|
||||
await db.Insertable(logs).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -55,12 +55,13 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
return info == null ? 0 : (int)info.count;
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, string search, int page,
|
||||
public async Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, List<string> noCode, string search, int page,
|
||||
int limit, RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
|
||||
return await db.Queryable<unit_user_goods>().Where(it => it.userId == userId && it.count > 0)
|
||||
.WhereIF(code.Count > 0, it => code.Contains(it.code))
|
||||
.WhereIF(noCode.Count > 0, it => !noCode.Contains(it.code))
|
||||
.WhereIF(!string.IsNullOrEmpty(search), it => it.goodsName.Contains(search))
|
||||
.OrderBy(it => it.lev, OrderByType.Desc)
|
||||
.OrderBy(it => it.count, OrderByType.Desc)
|
||||
|
||||
@@ -6,7 +6,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
public async Task<game_city> GetCityInfo(int cityId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "CityData");
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "CityInfo");
|
||||
var data = await redis.GetHashAsync<game_city>(key, cityId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
@@ -18,9 +18,53 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<game_city>> GetCityData()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "CityData");
|
||||
var data = await redis.GetAsync<List<game_city>>(key);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city>();
|
||||
data = await db.Queryable<game_city>().ToListAsync();
|
||||
await redis.SetAsync(key, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<List<game_city_map>> GetCityMap(int cityId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "CityMap");
|
||||
var data = await redis.GetHashAsync<List<game_city_map>>(key, cityId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map>();
|
||||
data = await db.Queryable<game_city_map>().Where(it => it.cityId == cityId).ToListAsync();
|
||||
await redis.AddHashAsync(key, cityId.ToString(), data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<game_city_map>> GetCityShowMap(int cityId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "CityShowMap");
|
||||
var data = await redis.GetHashAsync<List<game_city_map>>(key, cityId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map>();
|
||||
data = await db.Queryable<game_city_map>().Where(it => it.cityId == cityId && it.show == 1).ToListAsync();
|
||||
await redis.AddHashAsync(key, cityId.ToString(), data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<game_city_map> GetMapInfo(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "MapData");
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapData");
|
||||
var data = await redis.GetHashAsync<game_city_map>(key, mapId);
|
||||
if (data == null)
|
||||
{
|
||||
@@ -32,19 +76,6 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<game_city_map>> GetMapCity(int cityId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "CityShowMap");
|
||||
var data = await redis.GetHashAsync<List<game_city_map>>(key, cityId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map>();
|
||||
data = await db.Queryable<game_city_map>().Where(it => it.cityId == cityId && it.show == 1).ToListAsync();
|
||||
await redis.AddHashAsync(key, cityId.ToString(), data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<int> GetMapCityByMapId(string mapId)
|
||||
{
|
||||
@@ -61,7 +92,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
public async Task<List<game_city_npc>> GetMapNpc(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "NpcData");
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "NpcData");
|
||||
var data = await redis.GetHashAsync<List<game_city_npc>>(key, mapId);
|
||||
if (data == null)
|
||||
{
|
||||
@@ -75,7 +106,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
public async Task<game_city_npc> GetNpcInfo(int npcId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "NpcInfo");
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "NpcInfo");
|
||||
var data = await redis.GetHashAsync<game_city_npc>(key, npcId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
@@ -131,6 +162,119 @@ 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;
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
|
||||
if (await redis.AddHashAsync(key, data.userId, data))
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
await db.Updateable<unit_user_online>(data).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task SetUserMapDefult(string userId)
|
||||
{
|
||||
var userMap = await GetUserOnMap(userId);
|
||||
var MapInfo = await GetMapInfo(userMap.mapId);
|
||||
if (MapInfo != null)
|
||||
{
|
||||
await UpdateUserOnMap(userMap, MapInfo.retMap);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<game_city_map> GetToMapInfo(string userId, string toMap, bool isUpUserMap = true,
|
||||
bool isChangeCity = false)
|
||||
{
|
||||
bool result = false;
|
||||
var onMapUser = await GetUserOnMap(userId);
|
||||
var onMap = onMapUser.mapId;
|
||||
var onMapInfo = await GetMapInfo(onMap);
|
||||
var mapInfo = await GetMapInfo(toMap);
|
||||
if (onMap == toMap) //相同地图不更新
|
||||
{
|
||||
if (isUpUserMap)
|
||||
{
|
||||
await UpdateUserOnMap(onMapUser, toMap);
|
||||
}
|
||||
|
||||
return mapInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新挂机,结束挂机
|
||||
}
|
||||
|
||||
if (mapInfo == null)
|
||||
{
|
||||
var myOnMap = await GetMapInfo(onMap);
|
||||
return myOnMap;
|
||||
}
|
||||
|
||||
if (isChangeCity)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mapInfo.show == 1)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] onMaps = onMap.Split('_');
|
||||
int onMapX = Convert.ToInt32(onMaps[0]);
|
||||
int onMapY = Convert.ToInt32(onMaps[1]);
|
||||
if (onMapX == mapInfo.x)
|
||||
{
|
||||
if (onMapY == (mapInfo.y - 1) || onMapY == (mapInfo.y + 1))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (onMapY == mapInfo.y)
|
||||
{
|
||||
if (onMapX == (mapInfo.x - 1) || onMapX == (mapInfo.x + 1))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//当传送有效时,此处判断是否跨城市
|
||||
if (result)
|
||||
{
|
||||
result = onMapInfo.cityId == mapInfo.cityId;
|
||||
}
|
||||
}
|
||||
|
||||
if (isUpUserMap && result)
|
||||
{
|
||||
result = await UpdateUserOnMap(onMapUser, toMap);
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (mapInfo.lockTime > 0)
|
||||
{
|
||||
// await SetUserMapLock(userId, (int)mapInfo.lockTime); //增加地图锁定
|
||||
}
|
||||
|
||||
return mapInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
return onMapInfo;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 其他相关
|
||||
@@ -141,7 +285,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
long time = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddMinutes(0 - GameConfig.OnLineTime));
|
||||
var data = await db.Queryable<unit_user_online>().Where(it => it.upTime > time && it.mapId == mapId)
|
||||
.WhereIF(noUser.Count > 0, it => !noUser.Contains(it.userId))
|
||||
.OrderByDescending(it=>it.upTime)
|
||||
.OrderByDescending(it => it.upTime)
|
||||
.ToListAsync();
|
||||
|
||||
List<UserModel> result = new List<UserModel>();
|
||||
@@ -168,11 +312,204 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
{
|
||||
var data = await GetMapUser(mapId, area, showArea, noUser);
|
||||
total = data.Count;
|
||||
return data.Skip((page - 1) * limit) // 跳过前面的页
|
||||
.Take(limit) // 取当前页
|
||||
return data.Skip((page - 1) * limit) // 跳过前面的页
|
||||
.Take(limit) // 取当前页
|
||||
.ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 自动寻路
|
||||
|
||||
private async Task<List<game_city>> GetCityDataExcludeParent()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapPathData", "CityParent");
|
||||
var data = await redis.GetAsync<List<game_city>>(key);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city>();
|
||||
data = await db.Queryable<game_city>().Where(it => it.parent != 0).ToListAsync();
|
||||
|
||||
await redis.SetAsync(key, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
private async Task<List<game_city_map>> GetAllMaoToData()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapPathData", "CityInterCityPortal");
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
return await redis.GetAsync<List<game_city_map>>(key);
|
||||
}
|
||||
|
||||
List<game_city_map> result = new List<game_city_map>();
|
||||
|
||||
var cityData = await GetCityDataExcludeParent();
|
||||
foreach (var item in cityData)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item.toMap))
|
||||
{
|
||||
var map = await GetMapInfo(item.toMap);
|
||||
if (map != null)
|
||||
{
|
||||
result.Add(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
await redis.SetAsync(key, result);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 城市信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<List<CityNode>> GetCityNode()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapPathData", "CityNode");
|
||||
var data = await redis.GetAsync<List<CityNode>>(key);
|
||||
if (data == null)
|
||||
{
|
||||
data = new List<CityNode>();
|
||||
var cityData = await GetCityDataExcludeParent(); //获取所有城市
|
||||
foreach (var city in cityData)
|
||||
{
|
||||
var mdMap = await GetMapInfo(city.toMap);
|
||||
if (mdMap != null)
|
||||
{
|
||||
var cityTemp = new CityNode(city.cityId, city.cityName, new Point((int)mdMap.x, (int)mdMap.y),
|
||||
mdMap.mapName, (int)city.x_s, (int)city.x_e, (int)city.y_s, (int)city.y_e);
|
||||
data.Add(cityTemp);
|
||||
}
|
||||
}
|
||||
|
||||
await redis.SetAsync(key, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 城市网络
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<Dictionary<int, List<game_city_map>>> GetCityRoadNetwork()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapPathData", "CityRoadNetwork");
|
||||
var data = await redis.GetAsync<Dictionary<int, List<game_city_map>>>(key);
|
||||
if (data == null)
|
||||
{
|
||||
data = new Dictionary<int, List<game_city_map>>();
|
||||
var cityData = await GetCityDataExcludeParent(); //获取所有城市
|
||||
foreach (var city in cityData)
|
||||
{
|
||||
//添加地图
|
||||
var mapData = await GetCityMap(city.cityId);
|
||||
data.Add(city.cityId, mapData);
|
||||
}
|
||||
|
||||
await redis.SetAsync(key, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 传送点信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<List<InterCityPortal>> GetCityInterCityPortal()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "CityInterCityPortal");
|
||||
var data = await redis.GetAsync<List<InterCityPortal>>(key);
|
||||
if (data == null)
|
||||
{
|
||||
data = new List<InterCityPortal>();
|
||||
var toAddr = await GetAllMaoToData(); //获取所有传送点
|
||||
var cityData = await GetCityDataExcludeParent(); //获取所有城市
|
||||
foreach (var item in toAddr)
|
||||
{
|
||||
var toMapInfo = await GetMapInfo(item.retMap);
|
||||
//获取反向传送点
|
||||
var retAddr = cityData.Find(it => it.cityId == (int)item.cityId);
|
||||
|
||||
data.Add(new InterCityPortal(item.mapId, (int)item.cityId, new Point((int)item.x, (int)item.y),
|
||||
(int)toMapInfo.cityId, item.mapName, 1, retAddr.toMap));
|
||||
}
|
||||
|
||||
await redis.SetAsync(key, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task<List<MapLine>> FinderMapLine(Point start, Point end)
|
||||
{
|
||||
//初始化
|
||||
var globalNetwork = new GlobalRoadNetwork();
|
||||
//注册城市
|
||||
var NodeData = await GetCityNode();
|
||||
NodeData.ForEach(item => { globalNetwork.AddCity(item); });
|
||||
//注册传送点
|
||||
var CityInterCityPortal = await GetCityInterCityPortal();
|
||||
CityInterCityPortal.ForEach(item => { globalNetwork.AddPortal(item); });
|
||||
var pathFinder = new CrossCityPathFinder(globalNetwork); //初始化寻找器
|
||||
//注册城市网络
|
||||
List<CityRoadNetwork> NetworkData = new List<CityRoadNetwork>();
|
||||
var NetworkCityData = await GetCityRoadNetwork();
|
||||
foreach (var cityNet in NetworkCityData)
|
||||
{
|
||||
var cityNetwork = new CityRoadNetwork(cityNet.Key);
|
||||
foreach (var map in cityNet.Value)
|
||||
{
|
||||
cityNetwork.AddWalkablePoint((int)map.x, (int)map.y);
|
||||
}
|
||||
|
||||
NetworkData.Add(cityNetwork);
|
||||
}
|
||||
|
||||
NetworkData.ForEach(item => { pathFinder.AddCityRoadNetwork(item); });
|
||||
|
||||
//获取所有城市ID
|
||||
var cityData = await GetCityDataExcludeParent();
|
||||
List<int> cityRoute = cityData.Select(it => it.cityId).ToList();
|
||||
var path = pathFinder.FindCrossCityPath(start, end);
|
||||
List<MapLine> result = new List<MapLine>();
|
||||
if (path != null)
|
||||
{
|
||||
foreach (var item in path)
|
||||
{
|
||||
if (item.StepType == PathStepType.Move)
|
||||
{
|
||||
MapLine line = new MapLine();
|
||||
line.x = item.Position.X;
|
||||
line.y = item.Position.Y;
|
||||
line.mapId = $"{line.x}_{line.y}";
|
||||
result.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<MapLine>> CreateAutoMap(string start, string end)
|
||||
{
|
||||
//获取所有起始点
|
||||
var startMap = await GetMapInfo(start);
|
||||
var endMap = await GetMapInfo(end);
|
||||
Point startPoint = new Point((int)startMap.x, (int)startMap.y);
|
||||
Point endPoint = new Point((int)endMap.x, (int)endMap.y);
|
||||
var result = await FinderMapLine(startPoint, endPoint);
|
||||
if (result.Count > 0)
|
||||
{
|
||||
result.RemoveAt(0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) : IUnitUserAttrService, ITransient
|
||||
{
|
||||
|
||||
#region 体力操作
|
||||
public async Task<unit_user_blood> GetUserBlood(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData","Blood");
|
||||
var data = await redis.GetHashAsync<unit_user_blood>(key, userId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_blood>();
|
||||
data = await db.Queryable<unit_user_blood>().Where(it => it.userId == userId).SingleAsync();
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserBlood(string userId, int op, int count, bool mustUp = false)
|
||||
{
|
||||
bool result = false;
|
||||
unit_user_blood data = new unit_user_blood();
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData","Blood");
|
||||
if (op == 2)
|
||||
{
|
||||
data.userId = userId;
|
||||
data.blood = count;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = await GetUserBlood(userId);
|
||||
if (op == 0)
|
||||
{
|
||||
data.blood -= count;
|
||||
}
|
||||
else if (op == 1)
|
||||
{
|
||||
data.blood += count;
|
||||
}
|
||||
}
|
||||
|
||||
data.blood = data.blood < 0 ? 0 : data.blood;
|
||||
result = await redis.AddHashAsync(key, userId, data);
|
||||
|
||||
if (mustUp)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_blood>();
|
||||
result = await db.Updateable<unit_user_blood>()
|
||||
.SetColumnsIF(op == 0, it => it.blood == it.blood - count)
|
||||
.SetColumnsIF(op == 1, it => it.blood == it.blood + count)
|
||||
.SetColumnsIF(op == 2, it => it.blood == count)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user