248 lines
9.7 KiB
C#
248 lines
9.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using ServerCore; using ServerBase;
|
|
|
|
|
|
using SESSION_ID = System.Int32;
|
|
using WORLD_ID = System.UInt32;
|
|
using META_ID = System.UInt32;
|
|
using ENTITY_GUID = System.String;
|
|
using ACCOUNT_ID = System.String;
|
|
using OWNER_GUID = System.String;
|
|
using USER_GUID = System.String;
|
|
using CHARACTER_GUID = System.String;
|
|
using ITEM_GUID = System.String;
|
|
using ENTITY_UNIQUE_ID = System.String;
|
|
using ANCHOR_META_GUID = System.String;
|
|
using TARGET_UNIQUE_ID = System.String;
|
|
using NPC_UNIQUE_ID = System.String;
|
|
using FARMING_ENTITY_GUID = System.String;
|
|
using LOCATION_UNIQUE_ID = System.String;
|
|
using FARMING_EFFECT_DOC_LINK_PKSK = System.String;
|
|
|
|
|
|
|
|
namespace ServerCommon
|
|
{
|
|
public class FarmingEffectOwnerAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
// 파밍을 하고 있는 OwnerEntityType.User or UgcNpc
|
|
[JsonProperty]
|
|
public OwnerEntityType OwnerEntityType { get; set; } = OwnerEntityType.None;
|
|
// 파밍을 하고 있는 OwnerEntityType.User or UgcNpc GUID
|
|
[JsonProperty]
|
|
public OWNER_GUID OwnerGuid { get; set; } = string.Empty;
|
|
|
|
public FARMING_EFFECT_DOC_LINK_PKSK FarmingEffectDocLinkPKSK { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
public FarmingEffectOwnerAttribute(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
OwnerEntityType = OwnerEntityType.None;
|
|
OwnerGuid = string.Empty;
|
|
FarmingEffectDocLinkPKSK = string.Empty;
|
|
|
|
getAttributeState().reset();
|
|
}
|
|
|
|
public override EntityAttributeBase onCloned()
|
|
{
|
|
var owner = getOwner();
|
|
|
|
var cloned = new FarmingEffectOwnerAttribute(owner);
|
|
|
|
cloned.deepCopyFromBase(this);
|
|
|
|
cloned.OwnerEntityType = OwnerEntityType;
|
|
cloned.OwnerGuid = OwnerGuid;
|
|
cloned.FarmingEffectDocLinkPKSK = FarmingEffectDocLinkPKSK;
|
|
|
|
return cloned;
|
|
}
|
|
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
return new FarmingEffectOwnerAttributeTransactor(getOwner());
|
|
}
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var owner = getOwner();
|
|
|
|
if (true == FarmingEffectDocLinkPKSK.isNullOrWhiteSpace())
|
|
{
|
|
err_msg = $"Not make FARMING_EFFECT_DOC_LINK_PKSK !!! - {toBasicString()}, {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.FarmingEffectDocLinkPkSkNotSet, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return (result, null);
|
|
}
|
|
|
|
//=====================================================================================
|
|
// Attribute => try pending Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = getTryPendingDocBase() as FarmingEffectOwnerDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = new FarmingEffectOwnerDoc( OwnerEntityType, OwnerGuid
|
|
, FarmingEffectDocLinkPKSK );
|
|
|
|
var origin_doc = getOriginDocBase<FarmingEffectOwnerAttribute>();
|
|
if (null != origin_doc)
|
|
{
|
|
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
|
}
|
|
|
|
try_pending_doc = to_copy_doc;
|
|
|
|
setTryPendingDocBase(try_pending_doc);
|
|
}
|
|
|
|
var to_copy_doc_farming_effect_owner_attrib = try_pending_doc.getAttrib<FarmingEffectOwnerAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(to_copy_doc_farming_effect_owner_attrib, () => $"to_copy_doc_farming_effect_owner_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
to_copy_doc_farming_effect_owner_attrib.OwnerEntityType = OwnerEntityType;
|
|
to_copy_doc_farming_effect_owner_attrib.OwnerGuid = OwnerGuid;
|
|
to_copy_doc_farming_effect_owner_attrib.FarmingEffectDocLinkPKSK = FarmingEffectDocLinkPKSK;
|
|
|
|
if (false == isForQuery)
|
|
{
|
|
return (result, try_pending_doc);
|
|
}
|
|
|
|
//=====================================================================================
|
|
// Doc QueryType 반영
|
|
//=====================================================================================
|
|
(result, var to_query_doc) = await applyDoc4Query(try_pending_doc);
|
|
if (result.isFail())
|
|
{
|
|
return (result, null);
|
|
}
|
|
|
|
return (result, to_query_doc);
|
|
}
|
|
|
|
public Result onMerge(EntityAttributeBase otherEntityAttribute)
|
|
{
|
|
var owner = getOwner();
|
|
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
if (null == otherEntityAttribute)
|
|
{
|
|
err_msg = $"Invalid Param !!!, otherEntityAttribute is null";
|
|
result.setFail(ServerErrorCode.FunctionParamNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// OtherAttribute => Origin Attribute
|
|
//=====================================================================================
|
|
var other_farming_effect_owner_attribute = otherEntityAttribute as FarmingEffectOwnerAttribute;
|
|
if (null == other_farming_effect_owner_attribute)
|
|
{
|
|
err_msg = $"Failed to cast FarmingEffectOwnerAttribute !!!, other_farming_effect_owner_attribute is null - {owner.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
OwnerEntityType = other_farming_effect_owner_attribute.OwnerEntityType;
|
|
OwnerGuid = other_farming_effect_owner_attribute.OwnerGuid;
|
|
FarmingEffectDocLinkPKSK = other_farming_effect_owner_attribute.FarmingEffectDocLinkPKSK;
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = other_farming_effect_owner_attribute.getTryPendingDocBase() as FarmingEffectOwnerDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
other_farming_effect_owner_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<FarmingEffectOwnerAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<FarmingEffectOwnerAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var farming_effect_owner_attrib = origin_doc_base.getAttrib<FarmingEffectOwnerAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(farming_effect_owner_attrib, () => $"farming_effect_owner_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
farming_effect_owner_attrib.OwnerEntityType = OwnerEntityType;
|
|
farming_effect_owner_attrib.OwnerGuid = OwnerGuid;
|
|
farming_effect_owner_attrib.FarmingEffectDocLinkPKSK = FarmingEffectDocLinkPKSK;
|
|
|
|
return result;
|
|
}
|
|
|
|
public bool copyEntityAttributeFromDoc(DynamoDbDocBase? docBase)
|
|
{
|
|
var err_msg = string.Empty;
|
|
|
|
var owner = getOwner();
|
|
|
|
var to_cast_string = typeof(FarmingEffectOwnerDoc).Name;
|
|
|
|
var farming_location_owner_doc = docBase as FarmingEffectOwnerDoc;
|
|
if (null == farming_location_owner_doc)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, farming_location_owner_doc is null :{to_cast_string} - {owner.toBasicString}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// New Doc => Origin Doc
|
|
//=====================================================================================
|
|
syncOriginDocBaseWithNewDoc<FarmingEffectOwnerAttribute>(farming_location_owner_doc);
|
|
|
|
var farming_effect_owner_attrib = farming_location_owner_doc.getAttrib<FarmingEffectOwnerAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(farming_effect_owner_attrib, () => $"farming_effect_owner_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
OwnerEntityType = farming_effect_owner_attrib.OwnerEntityType;
|
|
OwnerGuid = farming_effect_owner_attrib.OwnerGuid;
|
|
FarmingEffectDocLinkPKSK = farming_effect_owner_attrib.FarmingEffectDocLinkPKSK;
|
|
|
|
return true;
|
|
}
|
|
|
|
public void makeFARMING_EFFECT_DOC_LINK_PKSK(LOCATION_UNIQUE_ID locationUniqueId, ANCHOR_META_GUID anchorMetaGuid)
|
|
{
|
|
FarmingEffectDocLinkPKSK = $"{locationUniqueId}#{anchorMetaGuid}";
|
|
}
|
|
}
|
|
|
|
public class FarmingEffectOwnerAttributeTransactor : EntityAttributeTransactorBase<FarmingEffectOwnerAttribute>
|
|
{
|
|
public FarmingEffectOwnerAttributeTransactor(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
}
|
|
}
|