using Amazon.Runtime.Internal; using Org.BouncyCastle.Asn1.Ocsp; using ServerCommon; using ServerCore; using ServerBase; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GameServer { internal static class LandHelper { public static async Task toLandInfo(this Land land) { var land_attribute = land.getEntityAttribute(); NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!!"); var land_info = new LandInfo(); land_info.LandMetaId = (int)land_attribute.LandMetaId; land_info.LandName = land_attribute.LandName; land_info.LandDescription = land_attribute.Description; land_info.OwnerUserGuid = land_attribute.OwnerUserGuid; if (land_attribute.OwnerUserGuid != string.Empty) { var (result, nickname_attrib) = await NicknameDoc.findNicknameFromGuid(land_attribute.OwnerUserGuid); if (result.isSuccess() && nickname_attrib != null) { land_info.OwnerUserNickname = nickname_attrib.Nickname; } } return land_info; } public static async Task<(Result, Land?, OwnedLand?, DynamoDbDocBase?)> tryGainLand(Player player, int landMetaId) { var result = new Result(); var err_msg = string.Empty; var server_logic = GameServerApp.getServerLogic(); if (!MetaData.Instance._LandTable.TryGetValue(landMetaId, out var land_meta_data)) { err_msg = $"Failed to MetaData.TryGetValue() !!! : LandMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.LandMetaDataNotFound, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } if (land_meta_data.Editor != MetaAssets.EditorType.USER) { err_msg = $"Land EditorType is NOT USER !!! : LandMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.LandEditorIsNotUser, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } if (!MapManager.Instance.GetLandMapTree(landMetaId, out var land_map_tree)) { err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } var land_manager = server_logic.getLandManager(); if (!land_manager.tryGetLand(landMetaId, out var land)) { err_msg = $"Failed to tryGetLand() !!! : landMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.LandNotFound, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } var land_action = land.getEntityAction(); NullReferenceCheckHelper.throwIfNull(land_action, () => $"land_action is null !!! - {player.toBasicString()}"); if (land_action.isExistOwner()) { err_msg = $"Land Exist Owner !!! : landMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.LandExistOwner, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } var user_guid = player.getUserGuid(); land_action.setLandOwner(landMetaId, user_guid); var land_attribute = land.getEntityAttribute(); NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!! - {player.toBasicString()}"); (result, var land_doc_base) = await land_attribute.toDocBase(); if (result.isFail()) { err_msg = $"Failed to toDocBase() !!! : {result.toBasicString()}"; Log.getLogger().error(err_msg); return (result, null, null, null); } NullReferenceCheckHelper.throwIfNull(land_doc_base, () => $"land_doc_base is null !!! - {player.toBasicString()}"); (result, var owned_land) = await OwnedLandHelper.createOwnedLand(player, landMetaId, OwnedType.Own); if (result.isFail()) { err_msg = $"Failed to createOwnedLand() !!! : {result.toBasicString()}"; Log.getLogger().error(err_msg); return (result, null, null, null); } NullReferenceCheckHelper.throwIfNull(owned_land, () => $"owned_land is null !!! - {player.toBasicString()}"); return (result, land, owned_land, land_doc_base); } public static async Task<(Result, Land?, OwnedLand?, DynamoDbDocBase?)> tryInitMyLandOwnership(Player player, int landMetaId) { var result = new Result(); var err_msg = string.Empty; var server_logic = GameServerApp.getServerLogic(); if (!MetaData.Instance._LandTable.TryGetValue(landMetaId, out var land_meta_data)) { err_msg = $"Failed to MetaData.TryGetValue() !!! : LandMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.LandMetaDataNotFound, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } if (land_meta_data.Editor != MetaAssets.EditorType.USER) { err_msg = $"Land EditorType is NOT USER !!! : LandMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.LandEditorIsNotUser, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } if (!MapManager.Instance.GetLandMapTree(landMetaId, out var land_map_tree)) { err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } var land_manager = server_logic.getLandManager(); if (!land_manager.tryGetLand(landMetaId, out var land)) { err_msg = $"Failed to tryGetLand() !!! : landMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.LandNotFound, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } var land_action = land.getEntityAction(); NullReferenceCheckHelper.throwIfNull(land_action, () => $"land_action is null !!! - {player.toBasicString()}"); var user_guid = player.getUserGuid(); if (!land_action.isLandOwner(user_guid)) { err_msg = $"Land Owner is Not Match !!! : landMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.LandOwnerIsNotMatch, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } land_action.initOwner(); var land_attribute = land.getEntityAttribute(); NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!! - {player.toBasicString()}"); (result, var land_doc_base) = await land_attribute.toDocBase(); if (result.isFail()) { err_msg = $"Failed to toDocBase() !!! : {result.toBasicString()}"; Log.getLogger().error(err_msg); return (result, null, null, null); } NullReferenceCheckHelper.throwIfNull(land_doc_base, () => $"land_doc_base is null !!! - {player.toBasicString()}"); var owned_land_agent_action = player.getEntityAction(); NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!! - {player.toBasicString()}"); if (!owned_land_agent_action.tryGetOwnedLand(landMetaId, out var owned_land)) { err_msg = $"Failed to tryGetOwnedLand() !!! : landMetaId:{landMetaId} - {player.toBasicString()}"; result.setFail(ServerErrorCode.OwnedLandNotFound, err_msg); Log.getLogger().error(result.toBasicString()); return (result, null, null, null); } var owned_land_action = owned_land.getEntityAction(); NullReferenceCheckHelper.throwIfNull(owned_land_action, () => $"owned_land_action is null !!! - {player.toBasicString()}"); owned_land_action.DeleteOwnedLand(); return (result, land, owned_land, land_doc_base); } } }