Files
2025-05-01 07:20:41 +09:00

202 lines
7.2 KiB
C#

using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using META_ID = System.UInt32;
namespace GameServer
{
internal class LandAction : EntityActionBase
{
public LandAction(Land owner)
: base(owner)
{ }
public override async Task<Result> onInit()
{
var result = new Result();
return await Task.FromResult(result);
}
public override void onClear()
{
return;
}
public async Task<Result> tryLoadLandFromDb(int landMetaId)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
var db_client = server_logic.getDynamoDbClient();
var doc = new LandDoc();
doc.setCombinationKeyForPK(landMetaId.ToString());
var error_code = doc.onApplyPKSK();
if (error_code.isFail())
{
err_msg = $"Failed to onApplyPKSK() !!! : {error_code.toBasicString()}";
result.setFail(error_code, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
var query_config = db_client.makeQueryConfigForReadByPKSK(doc.getPK());
(result, var read_docs) = await db_client.simpleQueryDocTypesWithQueryOperationConfig<LandDoc>(query_config);
if (result.isFail())
{
err_msg = $"Failed to simpleQueryDocTypesWithQueryOperationConfig() !!! : {result.toBasicString()}";
Log.getLogger().error(err_msg);
return result;
}
var land = getOwner() as Land;
NullReferenceCheckHelper.throwIfNull(land, () => $"land is null !!!");
var land_attribute = land.getEntityAttribute<LandAttribute>();
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!!");
foreach (var read_doc in read_docs)
{
if (!land_attribute.copyEntityAttributeFromDoc(read_doc))
{
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! to:{land_attribute.getTypeName()}, from:{read_doc.getTypeName()} : {this.getTypeName()}";
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
}
if (land_attribute.LandMetaId == 0)
{
land_attribute.LandMetaId = (uint)landMetaId;
if (read_docs.Count != 0)
{
Log.getLogger().info($"LandDoc.LandAtrib.LandMetaId is 0 !!! - landMetaId:{landMetaId}");
}
}
return result;
}
public async Task<(Result, DynamoDbDocBase?)> modifyLandInfo(string landName, string landDescription)
{
var result = new Result();
var err_msg = string.Empty;
var land = getOwner() as Land;
NullReferenceCheckHelper.throwIfNull(land, () => $"land is null !!!");
var land_attribute = land.getEntityAttribute<LandAttribute>();
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!!");
land_attribute.LandName = landName;
land_attribute.Description = landDescription;
land_attribute.IsLoadFromDb = true;
land_attribute.modifiedEntityAttribute();
(result, var land_doc) = await land_attribute.toDocBase();
if (result.isFail())
{
err_msg = $"Failed to toDocBase() !!! : {result.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null);
}
return (result, land_doc);
}
public void modifyLandInfo(LandInfo landInfo)
{
var land = getOwner() as Land;
NullReferenceCheckHelper.throwIfNull(land, () => $"land is null !!!");
var land_attribute = land.getEntityAttribute<LandAttribute>();
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!!");
land_attribute.OwnerUserGuid = landInfo.OwnerUserGuid;
land_attribute.LandName = landInfo.LandName;
land_attribute.Description = landInfo.LandDescription;
land_attribute.modifiedEntityAttribute();
}
public bool isExistOwner()
{
var land = getOwner() as Land;
NullReferenceCheckHelper.throwIfNull(land, () => $"land is null !!!");
var land_attribute = land.getEntityAttribute<LandAttribute>();
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!!");
return land_attribute.OwnerUserGuid != string.Empty;
}
public void setLandOwner(int landMetaId, string userGuid)
{
var land = getOwner() as Land;
NullReferenceCheckHelper.throwIfNull(land, () => $"land is null !!!");
var land_attribute = land.getEntityAttribute<LandAttribute>();
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!!");
if (!land_attribute.IsLoadFromDb)
{
land_attribute.LandMetaId = (uint)landMetaId;
land_attribute.OwnerUserGuid = userGuid;
land_attribute.newEntityAttribute();
}
else
{
land_attribute.OwnerUserGuid = userGuid;
land_attribute.modifiedEntityAttribute();
}
}
public void changeOwner(string userGuid)
{
var land = getOwner() as Land;
NullReferenceCheckHelper.throwIfNull(land, () => $"land is null !!!");
var land_attribute = land.getEntityAttribute<LandAttribute>();
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!!");
land_attribute.OwnerUserGuid = userGuid;
land_attribute.modifiedEntityAttribute();
}
public void initOwner()
{
var land = getOwner() as Land;
NullReferenceCheckHelper.throwIfNull(land, () => $"land is null !!!");
var land_attribute = land.getEntityAttribute<LandAttribute>();
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!!");
land_attribute.OwnerUserGuid = string.Empty;
land_attribute.modifiedEntityAttribute();
}
public bool isLandOwner(string userGuid)
{
var land = getOwner() as Land;
NullReferenceCheckHelper.throwIfNull(land, () => $"land is null !!!");
var land_attribute = land.getEntityAttribute<LandAttribute>();
NullReferenceCheckHelper.throwIfNull(land_attribute, () => $"land_attribute is null !!!");
return land_attribute.OwnerUserGuid == userGuid;
}
}
}