using Grpc.Core; using MetaAssets; using ServerCommon; using ServerCore; using ServerBase; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GameServer { public class LandManager { ConcurrentDictionary m_lands = new(); public async Task loadLands() { var result = new Result(); var err_msg = string.Empty; var land_meta_ids = MapManager.Instance.getLandMetaIds(); foreach (var land_meta_id in land_meta_ids) { var land = new Land(); await land.onInit(); m_lands.TryAdd(land_meta_id, land); var land_action = land.getEntityAction(); NullReferenceCheckHelper.throwIfNull(land_action, () => $"land_action is null !!!"); result = await land_action.tryLoadLandFromDb(land_meta_id); if (result.isFail()) { err_msg = $"Failed to tryLoadLandFromDb() !!! : {result.toBasicString()}"; Log.getLogger().error(err_msg); return result; } } return result; } public bool tryGetLand(int landMetaId, [MaybeNullWhen(false)] out Land land) { return m_lands.TryGetValue(landMetaId, out land); } public async Task> getLandInfos() { var land_infos = new List(); foreach (var land in m_lands.Values) { var land_info = await land.toLandInfo(); if (land_info.LandMetaId == 0) continue; land_infos.Add(land_info); } return land_infos; } } }