250 lines
9.6 KiB
C#
250 lines
9.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using MetaAssets;
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using ServerCore; using ServerBase;
|
|
|
|
|
|
using USER_GUID = System.String;
|
|
|
|
|
|
namespace ServerCommon
|
|
{
|
|
public class QuestMailAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
[JsonProperty()]
|
|
public UInt32 QuestId { get; set; } = 0;
|
|
[JsonProperty()]
|
|
public UInt32 QuestRevision { get; set; } = 0;
|
|
//[JsonProperty()]
|
|
//public EQuestType QuestType { get; set; } = EQuestType.NONE;
|
|
//[JsonProperty()]
|
|
//UgqStateType UgqState { get; set; } = UgqStateType.None;
|
|
|
|
[JsonProperty()] public DateTime CreateTime { get; set; } = DateTimeHelper.Current;
|
|
[JsonProperty()] public DateTime? ExpireTime { get; set; }
|
|
|
|
[JsonProperty()]
|
|
public Int32 IsRead { get; set; } = 0;
|
|
|
|
public QuestMailAttribute(EntityBase owner, EntityBase entityOfOwnerEntityType)
|
|
: base(owner, entityOfOwnerEntityType)
|
|
{
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
QuestId = 0;
|
|
QuestRevision = 0;
|
|
//UgqState = UgqStateType.None;
|
|
CreateTime = DateTimeHelper.MinTime;
|
|
ExpireTime = null;
|
|
IsRead = 0;
|
|
|
|
getAttributeState().reset();
|
|
}
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var owner = getOwner();
|
|
var result = new Result();
|
|
|
|
var acoount_attribute = owner.getRootParent().getEntityAttribute<AccountAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(acoount_attribute, () => $"acoount_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
USER_GUID user_guid = acoount_attribute.UserGuid;
|
|
|
|
//=====================================================================================
|
|
// Attribute => try pending Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = getTryPendingDocBase() as QuestMailDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = (MetaHelper.GameConfigMeta.QuestMailStoragePeriod <= 0)
|
|
? new QuestMailDoc(user_guid, QuestId, QuestRevision)
|
|
: new QuestMailDoc(user_guid, QuestId, QuestRevision, MetaHelper.GameConfigMeta.QuestMailStoragePeriod);
|
|
|
|
var origin_doc = getOriginDocBase<QuestMailAttribute>();
|
|
if (null != origin_doc)
|
|
{
|
|
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
|
}
|
|
|
|
try_pending_doc = to_copy_doc;
|
|
|
|
setTryPendingDocBase(try_pending_doc);
|
|
}
|
|
|
|
var to_copy_quest_mail_attrib = try_pending_doc.getAttrib<QuestMailAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(to_copy_quest_mail_attrib, () => $"to_copy_quest_mail_attrib is null !!!");
|
|
|
|
to_copy_quest_mail_attrib.QuestId = QuestId;
|
|
to_copy_quest_mail_attrib.QuestRevision = QuestRevision;
|
|
to_copy_quest_mail_attrib.CreateTime = CreateTime;
|
|
to_copy_quest_mail_attrib.ExpireTime = ExpireTime;
|
|
to_copy_quest_mail_attrib.IsRead = IsRead;
|
|
|
|
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 override EntityAttributeBase onCloned()
|
|
{
|
|
var owner_entity_type = getEntityOfOwnerEntityType();
|
|
NullReferenceCheckHelper.throwIfNull(owner_entity_type, () => $"owner_entity_type is null !!!");
|
|
|
|
var cloned = new QuestMailAttribute(getOwner(), owner_entity_type);
|
|
cloned.deepCopyFromBase(this);
|
|
cloned.QuestId = QuestId;
|
|
cloned.QuestRevision = QuestRevision;
|
|
cloned.CreateTime = CreateTime;
|
|
cloned.ExpireTime = ExpireTime;
|
|
cloned.IsRead = IsRead;
|
|
|
|
return cloned;
|
|
}
|
|
|
|
public Result onMerge(EntityAttributeBase otherEntityAttribute)
|
|
{
|
|
var owner = getOwner();
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
var result = new Result();
|
|
|
|
if (null == otherEntityAttribute)
|
|
{
|
|
var err_msg = $"Invalid Param !!!, otherEntityAttribute is null";
|
|
result.setFail(ServerErrorCode.FunctionParamNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
return result;
|
|
}
|
|
|
|
var other_attribute = otherEntityAttribute as QuestMailAttribute;
|
|
if (null == other_attribute)
|
|
{
|
|
var err_msg = $"Failed to cast QuestMailAttribute !!!, other_attribute is null";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// OtherAttribute => Attribute
|
|
//=====================================================================================
|
|
IsRead = other_attribute.IsRead;
|
|
QuestRevision = other_attribute.QuestRevision;
|
|
CreateTime = other_attribute.CreateTime;
|
|
ExpireTime = other_attribute.ExpireTime;
|
|
QuestId = other_attribute.QuestId;
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = other_attribute.getTryPendingDocBase() as QuestMailDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
other_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<QuestMailAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<QuestMailAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var quest_mail_attrib = origin_doc_base.getAttrib<QuestMailAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(quest_mail_attrib, () => $"quest_mail_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
quest_mail_attrib.IsRead = IsRead;
|
|
quest_mail_attrib.QuestRevision = QuestRevision;
|
|
quest_mail_attrib.CreateTime = CreateTime;
|
|
quest_mail_attrib.ExpireTime = ExpireTime;
|
|
quest_mail_attrib.QuestId = QuestId;
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
public bool copyEntityAttributeFromDoc(DynamoDbDocBase customDoc)
|
|
{
|
|
var quest_mail_doc_base = customDoc as QuestMailDoc;
|
|
|
|
if (null == quest_mail_doc_base)
|
|
{
|
|
var to_cast_string = typeof(QuestMailDoc).Name;
|
|
var err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, item_doc_base is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// New Doc => Origin Doc
|
|
//=====================================================================================
|
|
syncOriginDocBaseWithNewDoc<QuestMailAttribute>(quest_mail_doc_base);
|
|
|
|
//=====================================================================================
|
|
// Doc => Attribute
|
|
//=====================================================================================
|
|
var doc_attrib = quest_mail_doc_base.getAttrib<QuestMailAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(doc_attrib, () => $"doc_attrib is null !!!");
|
|
|
|
QuestId = doc_attrib.QuestId;
|
|
QuestRevision = doc_attrib.QuestRevision;
|
|
CreateTime = doc_attrib.CreateTime;
|
|
ExpireTime = doc_attrib.ExpireTime;
|
|
IsRead = doc_attrib.IsRead;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
return new QuestMailAttributeTransactor(getOwner());
|
|
}
|
|
|
|
|
|
public class QuestMailAttributeTransactor : EntityAttributeTransactorBase<QuestMailAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
|
{
|
|
public QuestMailAttributeTransactor(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase entityAttributeBase)
|
|
{
|
|
//아직 미사용
|
|
Log.getLogger().info("copyEntityDbTransactBaseFromEntityAttribute call");
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|