This commit is contained in:
Putoo
2026-05-23 18:36:37 +08:00
parent 05e340801f
commit dbace8a8b2
27 changed files with 729 additions and 52 deletions

View File

@@ -1,6 +1,6 @@
namespace Application.Domain;
public class GameMapService (ISqlSugarClient DbClient, IRedisCache redis): IGameMapService, ITransient
public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGameMapService, ITransient
{
#region
@@ -31,6 +31,7 @@ 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");
@@ -41,8 +42,10 @@ public class GameMapService (ISqlSugarClient DbClient, IRedisCache redis): IGame
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)
{
var data = await GetMapInfo(mapId);
@@ -69,6 +72,7 @@ public class GameMapService (ISqlSugarClient DbClient, IRedisCache redis): IGame
return data;
}
public async Task<game_city_npc> GetNpcInfo(int npcId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "NpcInfo");
@@ -77,8 +81,9 @@ public class GameMapService (ISqlSugarClient DbClient, IRedisCache redis): IGame
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
data = await db.Queryable<game_city_npc>().Where(it => it.npcId == npcId).SingleAsync();
await redis.AddHashAsync(key, npcId.ToString(),data);
await redis.AddHashAsync(key, npcId.ToString(), data);
}
return data;
}
@@ -126,5 +131,48 @@ public class GameMapService (ISqlSugarClient DbClient, IRedisCache redis): IGame
}
}
#endregion
#region
private async Task<List<UserModel>> GetMapUser(string mapId, int area, int showArea, List<string> noUser)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
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)
.ToListAsync();
List<UserModel> result = new List<UserModel>();
data.ForEach(async it =>
{
var temp = await UserModelTool.GetUserView(it.userId);
bool isAdd = showArea == 1 && area != temp.area ? false : true;
if (isAdd)
{
result.Add(temp);
}
});
return result;
}
public async Task<List<UserModel>> GetMapUser(string mapId, int area, int showArea, List<string> noUser, int take)
{
var data = await GetMapUser(mapId, area, showArea, noUser);
return data.Take(take).ToList();
}
public async Task<List<UserModel>> GetMapUser(string mapId, int area, int showArea, List<string> noUser, int page,
int limit, RefAsync<int> total)
{
var data = await GetMapUser(mapId, area, showArea, noUser);
total = data.Count;
return data.Skip((page - 1) * limit) // 跳过前面的页
.Take(limit) // 取当前页
.ToList();
}
#endregion
}