초기커밋
This commit is contained in:
352
GameServer/Contents/OwnedLand/Helper/OwnedLandHelper.cs
Normal file
352
GameServer/Contents/OwnedLand/Helper/OwnedLandHelper.cs
Normal file
@@ -0,0 +1,352 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using META_ID = System.UInt32;
|
||||
using USER_GUID = System.String;
|
||||
using LAND_OWNER_GUID = System.String;
|
||||
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public static class OwnedLandHelper
|
||||
{
|
||||
public class OwnedLandOwnerChangedInfo
|
||||
{
|
||||
public LandDoc? LandDoc { get; set; } = null;
|
||||
public OwnedLandDoc? OwnedLandDoc { get; set; } = null;
|
||||
public BuildingDoc? BuildingDoc { get; set; } = null;
|
||||
public OwnedBuildingDoc? OwnedBuildingDoc { get; set; } = null;
|
||||
}
|
||||
|
||||
public static (Result, Land?, Building?) applyChangedToOwnedLand(this OwnedLandOwnerChangedInfo changedInfo)
|
||||
{
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var land_doc = changedInfo.LandDoc;
|
||||
NullReferenceCheckHelper.throwIfNull(land_doc, () => $"land_doc is null !!!");
|
||||
var building_doc = changedInfo.BuildingDoc;
|
||||
NullReferenceCheckHelper.throwIfNull(building_doc, () => $"land_doc is null !!!");
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
Land? updated_land = null;
|
||||
Building? updated_building = null;
|
||||
|
||||
var land_attrib = land_doc.getAttrib<LandAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_attrib, () => $"land_attrib is null !!!");
|
||||
{
|
||||
var land_manager = server_logic.getLandManager();
|
||||
|
||||
var land_meta_id = land_attrib.LandMetaId;
|
||||
if(false == land_manager.tryGetLand((Int32)land_meta_id, out var found_land))
|
||||
{
|
||||
err_msg = $"Failed to tryGetLand() !!!, Not found Land !!! : landMetaId:{land_meta_id}";
|
||||
result.setFail(ServerErrorCode.LandNotFound, err_msg);
|
||||
return (result, null, null);
|
||||
}
|
||||
var attribute = found_land.getEntityAttribute<LandAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(attribute, () => $"attribute is null !!!");
|
||||
if (false == attribute.copyEntityAttributeFromDoc(land_doc))
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! : {land_doc.getTypeName()} - landMetaId:{land_meta_id}";
|
||||
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return (result, null, null);
|
||||
}
|
||||
|
||||
updated_land = found_land;
|
||||
}
|
||||
|
||||
var building_attrib = building_doc.getAttrib<BuildingAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_attrib, () => $"building_attrib is null !!!");
|
||||
{
|
||||
var building_manager = server_logic.getBuildingManager();
|
||||
|
||||
var building_meta_id = building_attrib.BuildingMetaId;
|
||||
if (false == building_manager.tryGetBuilding((Int32)building_meta_id, out var found_building))
|
||||
{
|
||||
err_msg = $"Failed to tryGetBuilding() !!!, Not found Building !!! : buildingMetaId:{building_meta_id}";
|
||||
result.setFail(ServerErrorCode.BuildingNotFound, err_msg);
|
||||
return (result, null, null);
|
||||
}
|
||||
var attribute = found_building.getEntityAttribute<BuildingAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(attribute, () => $"attribute is null !!!");
|
||||
if (false == attribute.copyEntityAttributeFromDoc(building_doc))
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! : {building_doc.getTypeName()} - buildingMetaId:{building_meta_id}";
|
||||
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return (result, null, null);
|
||||
}
|
||||
|
||||
updated_building = found_building;
|
||||
}
|
||||
|
||||
return (result, updated_land, updated_building);
|
||||
}
|
||||
|
||||
public static void attachOwnedLandAndBuilding( this Player newOwner
|
||||
, META_ID landMetaId, OwnedLand ownedLand
|
||||
, META_ID buildingMetaId, OwnedBuilding ownedBuilding)
|
||||
{
|
||||
var owned_land_agent_action = newOwner.getEntityAction<OwnedLandAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!! - {newOwner.toBasicString()}");
|
||||
var owned_building_agent_action = newOwner.getEntityAction<OwnedBuildingAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_building_agent_action, () => $"owned_building_agent_action is null !!! - {newOwner.toBasicString()}");
|
||||
|
||||
owned_land_agent_action.addOwnedLand((Int32)landMetaId, ownedLand);
|
||||
owned_building_agent_action.addOwnedBuilding((Int32)buildingMetaId, ownedBuilding);
|
||||
}
|
||||
|
||||
public static async Task<(Result, OwnedLandOwnerChangedInfo?)> makeOwnedLandOwnerChangedInfo(META_ID landMetaId, OwnedType ownedType, USER_GUID newOwnerGuid)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
//=====================================================================================
|
||||
// Land 소유자 관련 Doc 정보를 만든다.
|
||||
//=====================================================================================
|
||||
(result, var land_meta_data) = validCheckOwnedLand(landMetaId);
|
||||
if(result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to validCheckOwnerLand() !!! : {result.toBasicString()} - newOwnerGuid:{newOwnerGuid}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(land_meta_data, () => $"land_meta_data is null !!! - newOwnerGuid:{newOwnerGuid}");
|
||||
|
||||
var land_manager = server_logic.getLandManager();
|
||||
if (false == land_manager.tryGetLand((Int32)landMetaId, out var found_land))
|
||||
{
|
||||
err_msg = $"Failed to tryGetLand() !!! : landMetaId:{landMetaId} - newOwnerGuid:{newOwnerGuid}";
|
||||
result.setFail(ServerErrorCode.LandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return (result, null);
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(found_land, () => $"found_land is null !!! - newOwnerGuid:{newOwnerGuid}");
|
||||
|
||||
var land_action = found_land.getEntityAction<LandAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_action, () => $"land_action is null !!! - newOwnerGuid:{newOwnerGuid}");
|
||||
if (land_action.isExistOwner())
|
||||
{
|
||||
err_msg = $"Land Exist Owner !!! : landMetaId:{landMetaId} - newOwnerGuid:{newOwnerGuid}";
|
||||
result.setFail(ServerErrorCode.LandExistOwner, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var land_attribute = found_land.getEntityAttribute<LandAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!! - newOwnerGuid:{newOwnerGuid}");
|
||||
|
||||
var land_doc = new LandDoc(landMetaId);
|
||||
var land_attrib = land_doc.getAttrib<LandAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_attrib, () => $"land_attrib is null !!! - newOwnerGuid:{newOwnerGuid}");
|
||||
land_attrib.LandMetaId = (uint)landMetaId;
|
||||
land_attrib.OwnerUserGuid = newOwnerGuid;
|
||||
land_attrib.LandName = land_attribute.LandName;
|
||||
land_attrib.Description = land_attribute.Description;
|
||||
result = await land_doc.upsertDoc4Query();
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to upsertDoc4Query() !!! : {result.toBasicString()} - newOwnerGuid:{newOwnerGuid}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var owned_land_doc = new OwnedLandDoc(newOwnerGuid, (META_ID)landMetaId);
|
||||
var owned_land_attrib = owned_land_doc.getAttrib<OwnedLandAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_attrib, () => $"owned_land_attrib is null !!! - newOwnerGuid:{newOwnerGuid}");
|
||||
owned_land_attrib.LandMetaId = landMetaId;
|
||||
owned_land_attrib.OwnedType = ownedType;
|
||||
result = await owned_land_doc.upsertDoc4Query();
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to upsertDoc4Query() !!! : {result.toBasicString()} - newOwnerGuid:{newOwnerGuid}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// Land에 종속된 Building 소유자 관련 Doc 정보를 만든다.
|
||||
//=====================================================================================
|
||||
if (!MapManager.Instance.tryGetLandChildBuildingMetaId((Int32)landMetaId, out var building_meta_id))
|
||||
{
|
||||
err_msg = $"Failed to tryGetLandChildBuildingMetaId() !!! - newOwnerGuid:{newOwnerGuid}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
(result, _, var rental_fee_meta_data) = BuildingHelper.validCheckBuilding((META_ID)building_meta_id);
|
||||
if(result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to validCheckBuilding() !!! : {result.toBasicString()} - newOwnerGuid:{newOwnerGuid}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(rental_fee_meta_data, () => $"rental_fee_meta_data is null !!! - newOwnerGuid:{newOwnerGuid}");
|
||||
|
||||
var building_manager = server_logic.getBuildingManager();
|
||||
if (false == building_manager.tryGetBuilding(building_meta_id, out var building))
|
||||
{
|
||||
err_msg = $"Failed to tryGetBuilding() !!! : BuildingMetaId:{building_meta_id} - newOwnerGuid:{newOwnerGuid}";
|
||||
result.setFail(ServerErrorCode.BuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return (result, null);
|
||||
}
|
||||
var building_attribute = building.getEntityAttribute<BuildingAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_attribute, () => $"building_attribute is null !!! - newOwnerGuid:{newOwnerGuid}");
|
||||
|
||||
var building_doc = new BuildingDoc((META_ID)building_meta_id);
|
||||
var building_attrib = building_doc.getAttrib<BuildingAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_attrib, () => $"building_attrib is null !!! - newOwnerGuid:{newOwnerGuid}");
|
||||
|
||||
if (false == building_attribute.IsLoadFromDb)
|
||||
{
|
||||
building_attrib.BuildingMetaId = (META_ID)building_meta_id;
|
||||
building_attrib.OwnerUserGuid = newOwnerGuid;
|
||||
building_attrib.RentalCurrencyType = (CurrencyType)rental_fee_meta_data.CurrencyType;
|
||||
building_attrib.RentalCurrencyAmount = rental_fee_meta_data.CurrencyValue;
|
||||
building_attrib.IsRentalOpen = land_meta_data.RentalAvailable;
|
||||
}
|
||||
else
|
||||
{
|
||||
building_attrib.BuildingMetaId = (META_ID)building_meta_id;
|
||||
building_attrib.OwnerUserGuid = newOwnerGuid;
|
||||
}
|
||||
result = await building_doc.upsertDoc4Query();
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to upsertDoc4Query() !!! : {result.toBasicString()} - newOwnerGuid:{newOwnerGuid}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var owned_building_doc = new OwnedBuildingDoc(newOwnerGuid, (META_ID)building_meta_id);
|
||||
var owned_building_attrib = owned_building_doc.getAttrib<OwnedBuildingAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_building_attrib, () => $"owned_building_attrib is null !!! - newOwnerGuid:{newOwnerGuid}");
|
||||
owned_building_attrib.BuildingMetaId = (uint)building_meta_id;
|
||||
owned_building_attrib.OwnedType = ownedType;
|
||||
result = await owned_building_doc.upsertDoc4Query();
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to upsertDoc4Query() !!! : {result.toBasicString()} - newOwnerGuid:{newOwnerGuid}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
var changed_info = new OwnedLandOwnerChangedInfo();
|
||||
changed_info.LandDoc = land_doc;
|
||||
changed_info.OwnedLandDoc = owned_land_doc;
|
||||
changed_info.BuildingDoc = building_doc;
|
||||
changed_info.OwnedBuildingDoc = owned_building_doc;
|
||||
|
||||
return await Task.FromResult((result, changed_info));
|
||||
}
|
||||
|
||||
public static Result checkLandWithoutOwner(META_ID landMetaId)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var land_manager = server_logic.getLandManager();
|
||||
if (false == land_manager.tryGetLand((Int32)landMetaId, out var found_land))
|
||||
{
|
||||
err_msg = $"Failed to tryGetLand() !!! : landMetaId:{landMetaId}";
|
||||
result.setFail(ServerErrorCode.LandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(found_land, () => $"found_land is null !!!");
|
||||
|
||||
var land_action = found_land.getEntityAction<LandAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_action, () => $"land_action is null !!!");
|
||||
if (land_action.isExistOwner())
|
||||
{
|
||||
err_msg = $"Land Exist Owner !!! - landMetaId:{landMetaId}";
|
||||
result.setFail(ServerErrorCode.LandExistOwner, err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static (Result, LandMetaData?) validCheckOwnedLand(META_ID landMetaId)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
if (!MetaData.Instance._LandTable.TryGetValue((Int32)landMetaId, out var land_meta_data))
|
||||
{
|
||||
err_msg = $"Failed to MetaData.TryGetValue() !!! : LandMetaId:{landMetaId}";
|
||||
result.setFail(ServerErrorCode.LandMetaDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
if (land_meta_data.Editor != MetaAssets.EditorType.USER)
|
||||
{
|
||||
err_msg = $"Land EditorType is NOT USER !!! : LandMetaId:{landMetaId}";
|
||||
result.setFail(ServerErrorCode.LandEditorIsNotUser, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
if (!MapManager.Instance.GetLandMapTree((Int32)landMetaId, out var land_map_tree))
|
||||
{
|
||||
err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{landMetaId}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
return (result, land_meta_data);
|
||||
}
|
||||
|
||||
public static async Task<(Result, OwnedLand)> createOwnedLand(Player player, int landMetaId, OwnedType ownedType)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owned_land = new OwnedLand(player);
|
||||
result = await owned_land.onInit();
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to OwnedLand.onInit() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return (result, owned_land);
|
||||
}
|
||||
|
||||
var owned_land_attribute = owned_land.getEntityAttribute<OwnedLandAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_attribute, () => $"owned_land_attribute is null !!!");
|
||||
|
||||
owned_land_attribute.LandMetaId = (uint)landMetaId;
|
||||
owned_land_attribute.OwnedType = ownedType;
|
||||
owned_land_attribute.newEntityAttribute();
|
||||
|
||||
return (result, owned_land);
|
||||
}
|
||||
|
||||
public static int getLandMetaId(this OwnedLand ownedLand)
|
||||
{
|
||||
var owned_land_attribute = ownedLand.getEntityAttribute<OwnedLandAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_attribute, () => $"owned_land_attribute is null !!!");
|
||||
|
||||
return (int)owned_land_attribute.LandMetaId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user