초기커밋
This commit is contained in:
39
GameServer/Contents/OwnedLand/Action/OwnedLandAction.cs
Normal file
39
GameServer/Contents/OwnedLand/Action/OwnedLandAction.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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 class OwnedLandAction : EntityActionBase
|
||||
{
|
||||
public OwnedLandAction(OwnedLand owner)
|
||||
: base(owner)
|
||||
{ }
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
var result = new Result();
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void DeleteOwnedLand()
|
||||
{
|
||||
var owned_land = getOwner() as OwnedLand;
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land, () => $"owned_land is null !!!");
|
||||
|
||||
var owned_land_attribute = owned_land.getEntityAttribute<OwnedLandAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_attribute, () => $"owned_land_attribute is null !!!");
|
||||
|
||||
owned_land_attribute.deleteEntityAttribute();
|
||||
}
|
||||
}
|
||||
}
|
||||
101
GameServer/Contents/OwnedLand/Action/OwnedLandAgentAction.cs
Normal file
101
GameServer/Contents/OwnedLand/Action/OwnedLandAgentAction.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
internal class OwnedLandAgentAction : EntityActionBase
|
||||
{
|
||||
ConcurrentDictionary<int, OwnedLand> m_owned_lands = new();
|
||||
|
||||
public OwnedLandAgentAction(Player owner)
|
||||
: base(owner)
|
||||
{ }
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
var result = new Result();
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
m_owned_lands.Clear();
|
||||
}
|
||||
|
||||
public bool tryGetOwnedLand(int landMetaId, [MaybeNullWhen(false)] out OwnedLand ownedLand)
|
||||
{
|
||||
return m_owned_lands.TryGetValue(landMetaId, out ownedLand);
|
||||
}
|
||||
|
||||
public List<OwnedLand> getOwnedLands()
|
||||
{
|
||||
return m_owned_lands.Values.ToList();
|
||||
}
|
||||
|
||||
public List<int> getOwnedLandMetaIds()
|
||||
{
|
||||
var land_meta_ids = new List<int>();
|
||||
|
||||
foreach (var owned_land in m_owned_lands.Values)
|
||||
{
|
||||
var land_meta_id = owned_land.getLandMetaId();
|
||||
|
||||
land_meta_ids.Add(land_meta_id);
|
||||
}
|
||||
|
||||
return land_meta_ids;
|
||||
}
|
||||
|
||||
public bool isOwnedLand(int landMetaId)
|
||||
{
|
||||
return m_owned_lands.ContainsKey(landMetaId);
|
||||
}
|
||||
|
||||
public void addOwnedLand(int landMetaId, OwnedLand ownedLand)
|
||||
{
|
||||
m_owned_lands[landMetaId] = ownedLand;
|
||||
}
|
||||
|
||||
public void removeOwnedLand(int landMetaId)
|
||||
{
|
||||
m_owned_lands.TryRemove(landMetaId, out _);
|
||||
}
|
||||
|
||||
public async Task<Result> tryAddOwnedLandFromDoc(OwnedLandDoc ownedLandDoc)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = getOwner() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
|
||||
var owned_land = new OwnedLand(player);
|
||||
await owned_land.onInit();
|
||||
|
||||
var owned_land_attribute = owned_land.getEntityAttribute<OwnedLandAttribute>();
|
||||
ArgumentNullException.ThrowIfNull(owned_land_attribute);
|
||||
|
||||
if (!owned_land_attribute.copyEntityAttributeFromDoc(ownedLandDoc))
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! to:{owned_land_attribute.getTypeName()}, from:{ownedLandDoc.getTypeName()} : {this.getTypeName()}";
|
||||
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!m_owned_lands.TryAdd((int)owned_land_attribute.LandMetaId, owned_land))
|
||||
{
|
||||
err_msg = $"Failed to TryAdd() !!! : {owned_land_attribute.toBasicString()} : {this.getTypeName()}";
|
||||
result.setFail(ServerErrorCode.OwnedLandDocLoadDuplicatedOwnedLand, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
115
GameServer/Contents/OwnedLand/DBQuery/DBQOwnedLandReadAll.cs
Normal file
115
GameServer/Contents/OwnedLand/DBQuery/DBQOwnedLandReadAll.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using Amazon.DynamoDBv2.DocumentModel;
|
||||
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 class DBQOwnedLandReadAll : QueryExecutorBase
|
||||
{
|
||||
private string m_combination_key_for_pk = string.Empty;
|
||||
|
||||
private string m_pk = string.Empty;
|
||||
|
||||
private readonly List<OwnedLandDoc> m_to_read_owned_land_docs = new();
|
||||
|
||||
public DBQOwnedLandReadAll(string combinationKeyForPK)
|
||||
: base(typeof(DBQOwnedLandReadAll).Name)
|
||||
{
|
||||
m_combination_key_for_pk = combinationKeyForPK;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onPrepareQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner() as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var doc = new OwnedLandDoc();
|
||||
doc.setCombinationKeyForPK(m_combination_key_for_pk);
|
||||
|
||||
var error_code = doc.onApplyPKSK();
|
||||
if (error_code.isFail())
|
||||
{
|
||||
err_msg = $"Failed to onApplyPKSK() !!! : {error_code.toBasicString()} - {toBasicString()}, {owner.toBasicString()}";
|
||||
result.setFail(error_code, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
m_pk = doc.getPK();
|
||||
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// onPrepareQuery()를 성공할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner() as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var query_batch = getQueryBatch();
|
||||
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!!");
|
||||
|
||||
var db_connector = query_batch.getDynamoDbConnector();
|
||||
var query_config = db_connector.makeQueryConfigForReadByPKOnly(m_pk);
|
||||
|
||||
(result, var read_docs) = await db_connector.simpleQueryDocTypesWithQueryOperationConfig<OwnedLandDoc>(query_config, eventTid: query_batch.getTransId());
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var owned_land_agent_action = owner.getEntityAction<OwnedLandAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!!");
|
||||
|
||||
foreach (var read_doc in read_docs)
|
||||
{
|
||||
result = await owned_land_agent_action.tryAddOwnedLandFromDoc(read_doc);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
m_to_read_owned_land_docs.Add(read_doc);
|
||||
}
|
||||
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public List<OwnedLandDoc> getToReadOwnedLandDocs() => m_to_read_owned_land_docs;
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리를 성공하고, doFnCommit()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task onQueryResponseCommit()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리를 실패하고, doFnRollback()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task onQueryResponseRollback(Result errorResult)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using static ClientToGameMessage.Types;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
internal static class OwnedLandNotifyHelper
|
||||
{
|
||||
public static bool send_S2C_NTF_OWNED_LAND_INFOS(this Player player)
|
||||
{
|
||||
var owned_land_agent_action = player.getEntityAction<OwnedLandAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var ntf_packet = new ClientToGame();
|
||||
ntf_packet.Message = new ClientToGameMessage();
|
||||
ntf_packet.Message.NtfOwnedLandInfos = new GS2C_NTF_OWNED_LAND_INFOS();
|
||||
|
||||
var owned_lands = owned_land_agent_action.getOwnedLands();
|
||||
foreach (var owned_land in owned_lands)
|
||||
{
|
||||
var owned_land_attribute = owned_land.getEntityAttribute<OwnedLandAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_attribute, () => $"owned_land_attribute is null !!! - {player.toBasicString()}");
|
||||
|
||||
ntf_packet.Message.NtfOwnedLandInfos.OwnedLandInfos.Add((int)owned_land_attribute.LandMetaId);
|
||||
}
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(player, ntf_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
GameServer/Contents/OwnedLand/OwnedLand.cs
Normal file
38
GameServer/Contents/OwnedLand/OwnedLand.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using ServerCommon;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public class OwnedLand : EntityBase
|
||||
{
|
||||
public OwnedLand(Player parent)
|
||||
: base(EntityType.OwnedLand, parent)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
var parent = getDirectParent();
|
||||
NullReferenceCheckHelper.throwIfNull(parent, () => $"parent is null !!!");
|
||||
addEntityAttribute(new OwnedLandAttribute(this, parent));
|
||||
addEntityAction(new OwnedLandAction(this));
|
||||
|
||||
return await base.onInit();
|
||||
}
|
||||
|
||||
public override string toBasicString()
|
||||
{
|
||||
return $"{this.getTypeName()}, LandMetaId:{getOriginEntityAttribute<OwnedLandAttribute>()?.LandMetaId}";
|
||||
}
|
||||
|
||||
public override string toSummaryString()
|
||||
{
|
||||
return $"{this.getTypeName()}, {getEntityAttribute<OwnedLandAttribute>()?.toBasicString()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.ExchangeBuildingReq), typeof(ExchangeBuildingPacketHandler), typeof(GameLoginListener))]
|
||||
internal class ExchangeBuildingPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_EXCHANGE_BUILDING(Player owner, Result result)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.ExchangeBuildingRes = new ExchangeBuildingRes();
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
|
||||
|
||||
var req_msg = recvMessage as ClientToGame;
|
||||
NullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
|
||||
|
||||
var request = req_msg.Request.ExchangeBuildingReq;
|
||||
|
||||
// 미사용 패킷 정리
|
||||
result.setFail(ServerErrorCode.FunctionNotImplemented);
|
||||
send_S2C_ACK_EXCHANGE_BUILDING(player, result);
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using static ClientToGameReq.Types;
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.ExchangeLandPropReq), typeof(ExchangeLandPropPacketHandler), typeof(GameLoginListener))]
|
||||
internal class ExchangeLandPropPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_EXCHANGE_LAND_PROP(Player owner, Result result)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.ExchangeLandPropRes = new ExchangeLandPropRes();
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
|
||||
|
||||
var req_msg = recvMessage as ClientToGame;
|
||||
NullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
|
||||
|
||||
var request = req_msg.Request.ExchangeLandPropReq;
|
||||
|
||||
// 미사용 패킷 정리
|
||||
result.setFail(ServerErrorCode.FunctionNotImplemented);
|
||||
send_S2C_ACK_EXCHANGE_LAND_PROP(player, result);
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_GAIN_LAND_PROFIT), typeof(GainLandProfitPacketHandler), typeof(GameLoginListener))]
|
||||
internal class GainLandProfitPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_GAIN_LAND_PROFIT(Player owner, Result result, GS2C_ACK_GAIN_LAND_PROFIT res)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckGainLandProfit = res;
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var req_msg = recvMessage as ClientToGame;
|
||||
NullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
|
||||
|
||||
var request = req_msg.Request.ReqGainLandProfit;
|
||||
var res = new GS2C_ACK_GAIN_LAND_PROFIT();
|
||||
|
||||
if (!MetaData.Instance._LandTable.TryGetValue(request.LandMetaId, out var land_meta_data))
|
||||
{
|
||||
err_msg = $"Failed to MetaData.TryGetValue() !!! : LandMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMetaDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!MapManager.Instance.GetLandMapTree(request.LandMetaId, out var land_map_tree))
|
||||
{
|
||||
err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_map_tree = land_map_tree.ChildBuildingMapTree;
|
||||
if (building_map_tree == null)
|
||||
{
|
||||
err_msg = $"Not Exist LandMapTree ChildBuilding !!! : LandMap:{land_map_tree.LandMapFileName} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeChildBuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var owned_land_agent_action = player.getEntityAction<OwnedLandAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
if (!owned_land_agent_action.isOwnedLand(request.LandMetaId))
|
||||
{
|
||||
err_msg = $"Not Owned Land !!! : landMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.OwnedLandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_manager = server_logic.getBuildingManager();
|
||||
if (!building_manager.tryGetBuilding(building_map_tree.BuildingMetaId, out var building))
|
||||
{
|
||||
err_msg = $"Failed to tryGetBuilding() !!! : buildingMetaId:{building_map_tree.BuildingMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.BuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!MetaData.Instance._RentalfeeTable.TryGetValue((land_meta_data.Editor, land_meta_data.LandSize), out var rentalfee_meta_data))
|
||||
{
|
||||
err_msg = $"Failed to MetaData.TryGetValue() !!! : Editor:{land_meta_data.Editor}, Size:{land_meta_data.LandSize} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.RentalfeeMetaDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_profit_agent_action = building.getEntityAction<BuildingProfitAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_profit_agent_action, () => $"building_profit_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
// 랜드 수익 획득
|
||||
var gain_profits = new Dictionary<CurrencyType, double>();
|
||||
var modify_profits = new Dictionary<BuildingProfit, (int, CurrencyType, double)>();
|
||||
|
||||
using (building_profit_agent_action.getAsyncLock().Lock())
|
||||
{
|
||||
var building_profits = new List<BuildingProfit>();
|
||||
|
||||
if (request.Floor == 0)
|
||||
{
|
||||
building_profits = building_profit_agent_action.getAllBuildingProfit();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!building_profit_agent_action.tryGetBuildingProfit(request.Floor, out var buildingProfit))
|
||||
{
|
||||
err_msg = $"Failed to tryGetBuildingProfit() !!! : floor:{request.Floor} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.BuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
building_profits.Add(buildingProfit);
|
||||
}
|
||||
|
||||
foreach (var building_profit in building_profits)
|
||||
{
|
||||
var building_profit_action = building_profit.getEntityAction<BuildingProfitAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_profit_action, () => $"building_profit_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var floor = building_profit_action.getFloor();
|
||||
var profits = building_profit_action.getProfits();
|
||||
|
||||
foreach (var (profit_type, profit_amount) in profits)
|
||||
{
|
||||
if (profit_amount <= 0)
|
||||
continue;
|
||||
|
||||
gain_profits.TryGetValue(profit_type, out var gain_amount);
|
||||
|
||||
gain_amount += profit_amount;
|
||||
gain_profits[profit_type] = gain_amount;
|
||||
|
||||
modify_profits[building_profit] = (floor, profit_type, -profit_amount);
|
||||
}
|
||||
}
|
||||
|
||||
if (modify_profits.Count <= 0)
|
||||
{
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_profit_business_logs = new List<ILogInvoker>();
|
||||
var building_profit_update_item_query_contexts = new List<DynamoDbItemRequestQueryContext>();
|
||||
|
||||
// 랜드 수익 DB
|
||||
foreach (var (building_profit, (floor, currency_type, delta_amount)) in modify_profits)
|
||||
{
|
||||
(result, var building_profit_update_item_query_context) = BuildingProfitHelper.tryMakeUpdateItemRequestFromBuildingProfit(building_map_tree.BuildingMetaId, floor, currency_type, delta_amount);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to tryMakeUpdateItemRequestFromBuildingProfit() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(building_profit_update_item_query_context, () => $"building_profit_update_item_query_context is null !!! - {player.toBasicString()}");
|
||||
|
||||
var profit_action = building_profit.getEntityAction<BuildingProfitAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(profit_action, () => $"profit_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var current_profit = profit_action.getProfit(currency_type);
|
||||
|
||||
var building_profit_log_info = BuildingProfitBusinessLogHelper.toBuildingProfitLogInfo(building_map_tree.BuildingMetaId, floor, currency_type, AmountDeltaType.Consume, delta_amount, current_profit);
|
||||
var building_profit_business_log = new BuildingProfitBusinessLog(building_profit_log_info);
|
||||
building_profit_business_logs.Add(building_profit_business_log);
|
||||
|
||||
building_profit_update_item_query_contexts.Add(building_profit_update_item_query_context);
|
||||
}
|
||||
|
||||
// Building Profit History
|
||||
(result, var building_profit_history, var building_profit_history_doc) = await BuildingProfitHistoryHelper.tryMakeBuildingProfitHistory(building, building_map_tree.BuildingMetaId, request.Floor, DateTime.UtcNow, ProfitHistoryType.Gain, gain_profits);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to tryMakeBuildingProfitHistory() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(building_profit_history, () => $"building_profit_history is null !!!");
|
||||
NullReferenceCheckHelper.throwIfNull(building_profit_history_doc, () => $"building_profit_history_doc is null !!!");
|
||||
|
||||
// Money
|
||||
var transaction_name = "GainLandProfit";
|
||||
|
||||
var fn_transaction_runner = async delegate ()
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var found_transaction_runner = player.findTransactionRunner(TransactionIdType.PrivateContents);
|
||||
NullReferenceCheckHelper.throwIfNull(found_transaction_runner, () => $"found_transaction_runner is null !!! - {player.toBasicString()}");
|
||||
|
||||
var money_action = player.getEntityAction<MoneyAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(money_action, () => $"money_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
foreach (var (profit_type, profit_amount) in gain_profits)
|
||||
{
|
||||
var gain_amount = profit_amount * (100 - rentalfee_meta_data.DutyRate) / 100;
|
||||
|
||||
result = await money_action.changeMoney(profit_type, gain_amount);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to changeMoney() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (profit_type == CurrencyType.Calium)
|
||||
{
|
||||
var calium_storage_entity = server_logic.findGlobalEntity<CaliumStorageEntity>();
|
||||
NullReferenceCheckHelper.throwIfNull(calium_storage_entity, () => $"calium_storage_entity is null !!! - {player.toBasicString()}");
|
||||
|
||||
var calium_event_action = calium_storage_entity.getEntityAction<CaliumEventAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(calium_event_action, () => $"calium_event_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var trans_id = found_transaction_runner.getTransId();
|
||||
var burn_calium_amount = profit_amount * rentalfee_meta_data.DutyRate / 100;
|
||||
|
||||
result = await calium_event_action.sendCaliumBurnEvent(player, trans_id, player.getUserNickname(), transaction_name, -burn_calium_amount);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to sendCaliumBurnEvent() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var batch = new QueryBatchEx<QueryRunnerWithItemRequest>(player, LogActionType.GainLandProfit, server_logic.getDynamoDbClient());
|
||||
{
|
||||
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
|
||||
batch.addQuery(new DBQWithItemRequestQueryContext(building_profit_update_item_query_contexts));
|
||||
batch.addQuery(new DBQEntityWrite(building_profit_history_doc));
|
||||
batch.addQuery(new QueryFinal());
|
||||
}
|
||||
|
||||
batch.appendBusinessLogs(building_profit_business_logs);
|
||||
|
||||
result = await QueryHelper.sendQueryAndBusinessLog(batch);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
res.CommonResult = found_transaction_runner.getCommonResult();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, transaction_name, fn_transaction_runner);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to runTransactionRunnerSafely() !!! : {result.toBasicString()} - {player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 랜드 수익 Memory
|
||||
foreach (var (building_profit, (floor, currency_type, currency_amount)) in modify_profits)
|
||||
{
|
||||
var building_profit_action = building_profit.getEntityAction<BuildingProfitAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_profit_action, () => $"building_profit_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
building_profit_action.modifyProfit(currency_type, currency_amount);
|
||||
|
||||
var floor_profit = building_profit.toFloorProfitInfo();
|
||||
res.FloorProfits.Add(floor, floor_profit);
|
||||
}
|
||||
|
||||
var building_profit_history_agent_action = building.getEntityAction<BuildingProfitHistoryAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_profit_history_agent_action, () => $"building_profit_history_agent_action is null !!!");
|
||||
|
||||
building_profit_history_agent_action.addBuildingProfitHistory(building_profit_history);
|
||||
|
||||
send_S2C_ACK_GAIN_LAND_PROFIT(player, result, res);
|
||||
|
||||
// 전 서버 동기화
|
||||
BuildingProfitNotifyHelper.send_GS2GS_NTF_MODIFY_BUILDING_PROFIT(building_map_tree.BuildingMetaId, modify_profits.Values.ToList());
|
||||
BuildingProfitHistoryNotifyHelper.send_GS2GS_NTF_ADD_BUILDING_PROFIT_HISTORY(building_profit_history);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_LAND_PROFIT_HISTORY), typeof(LandProfitHistoryPacketHandler), typeof(GameLoginListener))]
|
||||
internal class LandProfitHistoryPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_LAND_PROFIT_HISTORY(Player owner, Result result, GS2C_ACK_LAND_PROFIT_HISTORY res)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckLandProfitHistory = res;
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var req_msg = recvMessage as ClientToGame;
|
||||
NullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
|
||||
|
||||
var request = req_msg.Request.ReqLandProfitHistory;
|
||||
var res = new GS2C_ACK_LAND_PROFIT_HISTORY();
|
||||
|
||||
var fn_transaction_runner = async delegate ()
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
if (!MapManager.Instance.GetLandMapTree(request.LandMetaId, out var land_map_tree))
|
||||
{
|
||||
err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_PROFIT_HISTORY(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_map_tree = land_map_tree.ChildBuildingMapTree;
|
||||
if (building_map_tree == null)
|
||||
{
|
||||
err_msg = $"Not Exist LandMapTree ChildBuilding !!! : LandMap:{land_map_tree.LandMapFileName} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeChildBuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_PROFIT_HISTORY(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var owned_land_agent_action = player.getEntityAction<OwnedLandAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
if (!owned_land_agent_action.isOwnedLand(request.LandMetaId))
|
||||
{
|
||||
err_msg = $"Not Owned Land !!! : landMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.OwnedLandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_PROFIT_HISTORY(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_manager = server_logic.getBuildingManager();
|
||||
if (!building_manager.tryGetBuilding(building_map_tree.BuildingMetaId, out var building))
|
||||
{
|
||||
err_msg = $"Failed to tryGetBuilding() !!! : buildingMetaId:{building_map_tree.BuildingMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.BuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_PROFIT_HISTORY(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_profit_history_agent_action = building.getEntityAction<BuildingProfitHistoryAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_profit_history_agent_action, () => $"building_profit_history_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
// 수익 히스토리 획득
|
||||
var building_profit_history_infos = building_profit_history_agent_action.getBuildingProfitHistoryInfos();
|
||||
res.HistoryInfos.AddRange(building_profit_history_infos);
|
||||
|
||||
var batch = new QueryBatchEx<QueryRunnerWithDocument>(player, LogActionType.None, server_logic.getDynamoDbClient());
|
||||
{
|
||||
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
|
||||
batch.addQuery(new QueryFinal());
|
||||
}
|
||||
|
||||
result = await QueryHelper.sendQueryAndBusinessLog(batch);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_LAND_PROFIT_HISTORY(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
send_S2C_ACK_LAND_PROFIT_HISTORY(player, result, res);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "ModifyLandInfo", fn_transaction_runner);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to runTransactionRunnerSafely() !!! : {result.toBasicString()} - {player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_LAND_PROFIT_REPORT), typeof(LandProfitReportPacketHandler), typeof(GameLoginListener))]
|
||||
internal class LandProfitReportPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_LAND_PROFIT_REPORT(Player owner, Result result, GS2C_ACK_LAND_PROFIT_REPORT res)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckLandProfitReport = res;
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var req_msg = recvMessage as ClientToGame;
|
||||
NullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
|
||||
|
||||
var request = req_msg.Request.ReqLandProfitReport;
|
||||
var res = new GS2C_ACK_LAND_PROFIT_REPORT();
|
||||
|
||||
var fn_transaction_runner = async delegate ()
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
if (!MapManager.Instance.GetLandMapTree(request.LandMetaId, out var land_map_tree))
|
||||
{
|
||||
err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_PROFIT_REPORT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_map_tree = land_map_tree.ChildBuildingMapTree;
|
||||
if (building_map_tree == null)
|
||||
{
|
||||
err_msg = $"Not Exist LandMapTree ChildBuilding !!! : LandMap:{land_map_tree.LandMapFileName} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeChildBuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_PROFIT_REPORT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var owned_land_agent_action = player.getEntityAction<OwnedLandAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
if (!owned_land_agent_action.isOwnedLand(request.LandMetaId))
|
||||
{
|
||||
err_msg = $"Not Owned Land !!! : landMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.OwnedLandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_PROFIT_REPORT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_manager = server_logic.getBuildingManager();
|
||||
if (!building_manager.tryGetBuilding(building_map_tree.BuildingMetaId, out var building))
|
||||
{
|
||||
err_msg = $"Failed to tryGetBuilding() !!! : buildingMetaId:{building_map_tree.BuildingMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.BuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_PROFIT_REPORT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_profit_agent_action = building.getEntityAction<BuildingProfitAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_profit_agent_action, () => $"building_profit_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
// 랜드 수익 정보 얻기
|
||||
var building_profit_infos = building_profit_agent_action.getBuildingProfitInfos();
|
||||
foreach (var (floor, building_profit_info) in building_profit_infos)
|
||||
{
|
||||
res.FloorProfits.Add(floor, building_profit_info);
|
||||
}
|
||||
|
||||
var batch = new QueryBatchEx<QueryRunnerWithDocument>(player, LogActionType.None, server_logic.getDynamoDbClient());
|
||||
{
|
||||
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
|
||||
batch.addQuery(new QueryFinal());
|
||||
}
|
||||
|
||||
result = await QueryHelper.sendQueryAndBusinessLog(batch);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_LAND_PROFIT_REPORT(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
send_S2C_ACK_LAND_PROFIT_REPORT(player, result, res);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "ModifyLandInfo", fn_transaction_runner);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to runTransactionRunnerSafely() !!! : {result.toBasicString()} - {player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_LAND_RENTAL_HISTORY), typeof(LandRentalHistoryPacketHandler), typeof(GameLoginListener))]
|
||||
internal class LandRentalHistoryPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_LAND_RENTAL_HISTORY(Player owner, Result result, GS2C_ACK_LAND_RENTAL_HISTORY res)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckLandRentalHistory = res;
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var req_msg = recvMessage as ClientToGame;
|
||||
NullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
|
||||
|
||||
var request = req_msg.Request.ReqLandRentalHistory;
|
||||
var res = new GS2C_ACK_LAND_RENTAL_HISTORY();
|
||||
|
||||
var fn_transaction_runner = async delegate ()
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
if (!MapManager.Instance.GetLandMapTree(request.LandMetaId, out var land_map_tree))
|
||||
{
|
||||
err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_RENTAL_HISTORY(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_map_tree = land_map_tree.ChildBuildingMapTree;
|
||||
if (building_map_tree == null)
|
||||
{
|
||||
err_msg = $"Not Exist LandMapTree ChildBuilding !!! : LandMap:{land_map_tree.LandMapFileName} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeChildBuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_RENTAL_HISTORY(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var owned_land_agent_action = player.getEntityAction<OwnedLandAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
if (!owned_land_agent_action.isOwnedLand(request.LandMetaId))
|
||||
{
|
||||
err_msg = $"Not Owned Land !!! : landMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.OwnedLandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_RENTAL_HISTORY(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_manager = server_logic.getBuildingManager();
|
||||
if (!building_manager.tryGetBuilding(building_map_tree.BuildingMetaId, out var building))
|
||||
{
|
||||
err_msg = $"Failed to tryGetBuilding() !!! : buildingMetaId:{building_map_tree.BuildingMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.BuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_RENTAL_HISTORY(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_rental_history_agent_action = building.getEntityAction<BuildingRentalHistoryAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_rental_history_agent_action, () => $"building_rental_history_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
// 임대 히스토리 획득
|
||||
var building_rental_history_infos = await building_rental_history_agent_action.getBuildingRentalHistoryInfos();
|
||||
res.HistoryInfos.AddRange(building_rental_history_infos);
|
||||
|
||||
var batch = new QueryBatchEx<QueryRunnerWithDocument>(player, LogActionType.None, server_logic.getDynamoDbClient());
|
||||
{
|
||||
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
|
||||
batch.addQuery(new QueryFinal());
|
||||
}
|
||||
|
||||
result = await QueryHelper.sendQueryAndBusinessLog(batch);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_LAND_RENTAL_HISTORY(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
send_S2C_ACK_LAND_RENTAL_HISTORY(player, result, res);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "ModifyLandInfo", fn_transaction_runner);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to runTransactionRunnerSafely() !!! : {result.toBasicString()} - {player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_LAND_RENTAL_iNFO), typeof(LandRentalInfoPacketHandler), typeof(GameLoginListener))]
|
||||
internal class LandRentalInfoPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_LAND_RENTAL_INFO(Player owner, Result result, GS2C_ACK_LAND_RENTAL_INFO res)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckLandRentalInfo = res;
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var req_msg = recvMessage as ClientToGame;
|
||||
NullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
|
||||
|
||||
var request = req_msg.Request.ReqLandRentalInfo;
|
||||
var res = new GS2C_ACK_LAND_RENTAL_INFO();
|
||||
|
||||
if (!MapManager.Instance.GetLandMapTree(request.LandMetaId, out var land_map_tree))
|
||||
{
|
||||
err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_RENTAL_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_map_tree = land_map_tree.ChildBuildingMapTree;
|
||||
if (building_map_tree == null)
|
||||
{
|
||||
err_msg = $"Not Exist LandMapTree ChildBuilding !!! : LandMap:{land_map_tree.LandMapFileName} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeChildBuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_RENTAL_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var owned_land_agent_action = player.getEntityAction<OwnedLandAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
if (!owned_land_agent_action.isOwnedLand(request.LandMetaId))
|
||||
{
|
||||
err_msg = $"Not Owned Land !!! : landMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.OwnedLandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_RENTAL_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_manager = server_logic.getBuildingManager();
|
||||
if (!building_manager.tryGetBuilding(building_map_tree.BuildingMetaId, out var building))
|
||||
{
|
||||
err_msg = $"Failed to tryGetBuilding() !!! : buildingMetaId:{building_map_tree.BuildingMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.BuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_LAND_RENTAL_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_floor_agent_action = building.getEntityAction<BuildingFloorAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_floor_agent_action, () => $"building_floor_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
var building_floors = building_floor_agent_action.getBuildingFloors();
|
||||
foreach (var(floor, building_floor) in building_floors)
|
||||
{
|
||||
(result, var building_floor_info) = await building_floor.tryGetBuildingFloorInfo();
|
||||
|
||||
res.BuildingFloorInfos.Add(floor, building_floor_info);
|
||||
}
|
||||
|
||||
send_S2C_ACK_LAND_RENTAL_INFO(player, result, res);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using static ClientToGameRes.Types;
|
||||
|
||||
|
||||
namespace GameServer.PacketHandler;
|
||||
|
||||
|
||||
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.C2GS_REQ_MODIFY_LAND_INFO), typeof(ModifyLandInfoPacketHandler), typeof(GameLoginListener))]
|
||||
internal class ModifyLandInfoPacketHandler : PacketRecvHandler
|
||||
{
|
||||
public static bool send_S2C_ACK_MODIFY_LAND_INFO(Player owner, Result result, GS2C_ACK_MODIFY_LAND_INFO res)
|
||||
{
|
||||
var ack_packet = new ClientToGame();
|
||||
ack_packet.Response = new ClientToGameRes();
|
||||
|
||||
ack_packet.Response.ErrorCode = result.ErrorCode;
|
||||
ack_packet.Response.AckModifyLandInfo = res;
|
||||
|
||||
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var player = entityWithSession as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
|
||||
|
||||
var server_logic = GameServerApp.getServerLogic();
|
||||
|
||||
var req_msg = recvMessage as ClientToGame;
|
||||
NullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
|
||||
|
||||
var request = req_msg.Request.ReqModifyLandInfo;
|
||||
var res = new GS2C_ACK_MODIFY_LAND_INFO();
|
||||
|
||||
var fn_transaction_runner = async delegate ()
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
if (!MetaData.Instance._LandTable.TryGetValue(request.LandMetaId, out var land_meta_data))
|
||||
{
|
||||
err_msg = $"Failed to MetaData.TryGetValue() !!! : LandMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMetaDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!MapManager.Instance.GetLandMapTree(request.LandMetaId, out var land_map_tree))
|
||||
{
|
||||
err_msg = $"Failed to GetLandMapTree() !!! : LandMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_map_tree = land_map_tree.ChildBuildingMapTree;
|
||||
if (building_map_tree == null)
|
||||
{
|
||||
err_msg = $"Not Exist LandMapTree ChildBuilding !!! : LandMap:{land_map_tree.LandMapFileName} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandMapTreeChildBuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var owned_land_agent_action = player.getEntityAction<OwnedLandAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(owned_land_agent_action, () => $"owned_land_agent_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
if (!owned_land_agent_action.isOwnedLand(request.LandMetaId))
|
||||
{
|
||||
err_msg = $"Not Owned Land !!! : landMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.OwnedLandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!MetaData.Instance._RentalfeeTable.TryGetValue((land_meta_data.Editor, land_meta_data.LandSize), out var rentalfee_meta_data))
|
||||
{
|
||||
err_msg = $"Failed to MetaData.TryGetValue() !!! : Editor:{land_meta_data.Editor}, Size:{land_meta_data.LandSize} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.RentalfeeMetaDataNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (request.RentalCurrencyType != CurrencyType.Calium)
|
||||
{
|
||||
err_msg = $"RentalCurrencyType is Not Calium !!! : RentalCurrencyType:{request.RentalCurrencyType} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.RentalCurrencyTypeIsWrong, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calium 일 경우 소수점 3째 자리에서 나머지 일 경우 소수점 1째 자리에서 반올림
|
||||
var digits = request.RentalCurrencyType == CurrencyType.Calium ? 2 : 0;
|
||||
var rental_currency_amount = Math.Round(request.RentalCurrencyAmount, digits);
|
||||
|
||||
if (rental_currency_amount < rentalfee_meta_data.CustomMinRentalValue)
|
||||
{
|
||||
err_msg = $"Rental Currency Amount is Too Low !!! : ModifyRequest:{rental_currency_amount}, MinValue:{rentalfee_meta_data.CustomMinRentalValue} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.RentalCurrencyAmountIsTooLow, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 랜드
|
||||
var land_manager = server_logic.getLandManager();
|
||||
if (!land_manager.tryGetLand(request.LandMetaId, out var land))
|
||||
{
|
||||
err_msg = $"Failed to tryGetLand() !!! : landMetaId:{request.LandMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.LandNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var land_action = land.getEntityAction<LandAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(land_action, () => $"land_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
// 랜드 정보 수정
|
||||
(result, var land_doc) = await land_action.modifyLandInfo(request.LandName, request.LandDescription);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to modifyLandInfo() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(land_doc, () => $"land_doc is null !!! - {player.toBasicString()}");
|
||||
|
||||
var land_log_info = land.toLandLogInfo();
|
||||
var land_business_log = new LandBusinessLog(land_log_info);
|
||||
|
||||
// 빌딩
|
||||
var building_manager = server_logic.getBuildingManager();
|
||||
if (!building_manager.tryGetBuilding(building_map_tree.BuildingMetaId, out var building))
|
||||
{
|
||||
err_msg = $"Failed to tryGetBuilding() !!! : buildingMetaId:{building_map_tree.BuildingMetaId} - {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.BuildingNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
var building_action = building.getEntityAction<BuildingAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(building_action, () => $"building_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
// 빌딩 정보 수정
|
||||
var is_rental_open = land_meta_data.RentalAvailable;
|
||||
if (land_meta_data.RentalStateSwitch && MetaHelper.GameConfigMeta.UseRentalStateSwitch)
|
||||
is_rental_open = request.IsRentalOpen == BoolType.True;
|
||||
|
||||
(result, var building_doc) = await building_action.modifyBuildingInfo(request.BuildingName, request.BuildingDescription, request.RentalCurrencyType, rental_currency_amount, is_rental_open);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to modifyLandInfo() !!! : {result.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(building_doc, () => $"building_doc is null !!! - {player.toBasicString()}");
|
||||
|
||||
var building_log_info = building.toBuildingLogInfo();
|
||||
var building_business_log = new BuildingBusinessLog(building_log_info);
|
||||
|
||||
var batch = new QueryBatchEx<QueryRunnerWithDocument>(player, LogActionType.ModifyLandInfo, server_logic.getDynamoDbClient());
|
||||
{
|
||||
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
|
||||
batch.addQuery(new DBQEntityWrite(land_doc));
|
||||
batch.addQuery(new DBQEntityWrite(building_doc));
|
||||
batch.addQuery(new QueryFinal());
|
||||
}
|
||||
|
||||
batch.appendBusinessLog(land_business_log);
|
||||
batch.appendBusinessLog(building_business_log);
|
||||
|
||||
result = await QueryHelper.sendQueryAndBusinessLog(batch);
|
||||
if (result.isFail())
|
||||
{
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
return result;
|
||||
}
|
||||
|
||||
await LandNotifyHelper.sendNtfModifyLandInfo(land);
|
||||
await BuildingNotifyHelper.sendNtfModifyBuildingInfo(building);
|
||||
|
||||
send_S2C_ACK_MODIFY_LAND_INFO(player, result, res);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "ModifyLandInfo", fn_transaction_runner);
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to runTransactionRunnerSafely() !!! : {result.toBasicString()} - {player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user