This commit is contained in:
Putoo
2026-07-16 17:52:33 +08:00
parent 2cd2ed02f8
commit 00c2758df2
43 changed files with 897 additions and 72 deletions

View File

@@ -140,7 +140,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
};
if (item.code == nameof(MapEnum.NpcCode.Task))
{
var task = await taskService.GetTaskDataByNpc(userId,item.npcId);
var task = await taskService.GetTaskDataByNpc(userId, item.npcId);
if (task.Count > 0)
{
temp.state = task.Any(it => it.state == 0) ? 1 : 2;
@@ -218,9 +218,14 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
};
}
public async Task UpdateUserOnMap(string userId)
public async Task UpdateUserOnMap(string userId, string mapId = "")
{
unit_user_online onLine = await GetUserOnMap(userId);
if (!string.IsNullOrEmpty(mapId))
{
onLine.mapId = mapId;
}
onLine.upTime = TimeExtend.GetTimeStampSeconds;
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
if (await redis.AddHashAsync(key, userId, onLine))
@@ -400,7 +405,28 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
#region
private async Task<List<UserModel>> GetMapUser(string mapId, int area, int showArea, List<string> noUser)
public async Task<List<UserModel>> GetMapUserByAll(string mapId, int area, int showArea, List<string> noUser)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
var data = await db.Queryable<unit_user_online>().Where(it => 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)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
long time = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddMinutes(0 - GameConfig.OnLineTime));