초기커밋
This commit is contained in:
254
ServerCommon/Entity/Attribute/QuestPeriodRepeatCheckAttribute.cs
Normal file
254
ServerCommon/Entity/Attribute/QuestPeriodRepeatCheckAttribute.cs
Normal file
@@ -0,0 +1,254 @@
|
||||
|
||||
using JsonConvert = Newtonsoft.Json.JsonConvert;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
|
||||
using USER_GUID = System.String;
|
||||
|
||||
|
||||
|
||||
namespace ServerCommon;
|
||||
|
||||
public class QuestPeriodRepeatCheckAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
||||
{
|
||||
public Dictionary<OncePeriodRangeType, QuestPeriodRepeatInfo> m_period_repeat_quests = new();
|
||||
|
||||
|
||||
public QuestPeriodRepeatCheckAttribute(EntityBase owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var owner = getOwner();
|
||||
|
||||
var quest_period_repeat_attribute = owner.getEntityAttribute<QuestPeriodRepeatCheckAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(quest_period_repeat_attribute, () => $"quest_period_repeat_attribute is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var user_attribute = owner.getRootParent().getEntityAttribute<UserAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(user_attribute, () => $"user_attribute is null !!! - {owner.toBasicString()}");
|
||||
|
||||
USER_GUID user_guid = user_attribute.UserGuid;
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute => try pending Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = getTryPendingDocBase() as QuestPeriodRepeatCheckDoc;
|
||||
if (null == try_pending_doc)
|
||||
{
|
||||
var to_copy_doc = new QuestPeriodRepeatCheckDoc(user_guid);
|
||||
|
||||
var origin_doc = getOriginDocBase<QuestPeriodRepeatCheckAttribute>();
|
||||
if (null != origin_doc)
|
||||
{
|
||||
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
||||
}
|
||||
|
||||
try_pending_doc = to_copy_doc;
|
||||
|
||||
setTryPendingDocBase(try_pending_doc);
|
||||
}
|
||||
|
||||
var to_copy_attrib = try_pending_doc.getAttrib<QuestPeriodRepeatAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(to_copy_attrib, () => $"QuestPeriodRepeatAttrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
foreach (var info in m_period_repeat_quests)
|
||||
{
|
||||
//repeat_info = info.Value;
|
||||
QuestPeriodRepeatInfo repeat_info = new();
|
||||
foreach (var sended_quest in info.Value.m_sended_quest)
|
||||
{
|
||||
repeat_info.m_sended_quest.TryAdd(sended_quest.Key, sended_quest.Value);
|
||||
}
|
||||
|
||||
if (false == to_copy_attrib.m_period_repeat_quests.TryAdd(info.Key, repeat_info))
|
||||
{
|
||||
Log.getLogger().warn($"QuestPeriodRepeatAttrib add Fail info.key : {info.Key}, value : {JsonConvert.SerializeObject(info.Value)}");
|
||||
}
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// Doc QueryType 반영
|
||||
//=====================================================================================
|
||||
(var 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 cloned = new QuestPeriodRepeatCheckAttribute(getOwner());
|
||||
cloned.deepCopyFromBase(this);
|
||||
|
||||
foreach (var info in m_period_repeat_quests)
|
||||
{
|
||||
QuestPeriodRepeatInfo repeat_info = new();
|
||||
foreach (var sended_quest in info.Value.m_sended_quest)
|
||||
{
|
||||
repeat_info.m_sended_quest.TryAdd(sended_quest.Key, sended_quest.Value);
|
||||
}
|
||||
|
||||
if (false == cloned.m_period_repeat_quests.TryAdd(info.Key, repeat_info))
|
||||
{
|
||||
Log.getLogger().warn($"m_period_repeat_quests add Fail info.key : {info.Key}, value : {JsonConvert.SerializeObject(info.Value)}");
|
||||
}
|
||||
}
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public Result onMerge(EntityAttributeBase otherEntityAttribute)
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
if (getAttributeState().hasFlag(StateType.Removed))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var owner = getOwner();
|
||||
|
||||
var other_attribute = otherEntityAttribute as QuestPeriodRepeatCheckAttribute;
|
||||
if (null == other_attribute)
|
||||
{
|
||||
err_msg = $"Failed to cast QuestPeriodRepeatCheckAttribute !!!, other_attribute is null";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// OtherAttribute => Attribute
|
||||
//=====================================================================================
|
||||
foreach (var info in other_attribute.m_period_repeat_quests)
|
||||
{
|
||||
QuestPeriodRepeatInfo repeat_info = new();
|
||||
foreach (var sended_quest in info.Value.m_sended_quest)
|
||||
{
|
||||
repeat_info.m_sended_quest.TryAdd(sended_quest.Key, sended_quest.Value);
|
||||
}
|
||||
|
||||
if (false == m_period_repeat_quests.TryAdd(info.Key, repeat_info))
|
||||
{
|
||||
Log.getLogger().warn($"m_period_repeat_quests add Fail info.key : {info.Key}, value : {JsonConvert.SerializeObject(info.Value)}");
|
||||
}
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute Try Pending Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = other_attribute.getTryPendingDocBase() as QuestPeriodRepeatCheckDoc;
|
||||
if (null != try_pending_doc)
|
||||
{
|
||||
other_attribute.resetTryPendingDocBase();
|
||||
|
||||
syncOriginDocBaseWithNewDoc<QuestPeriodRepeatCheckAttribute>(try_pending_doc);
|
||||
}
|
||||
|
||||
var origin_doc_base = getOriginDocBase<QuestPeriodRepeatCheckAttribute>();
|
||||
if (null == origin_doc_base)
|
||||
{
|
||||
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
||||
return result;
|
||||
}
|
||||
|
||||
var attrib = origin_doc_base.getAttrib<QuestPeriodRepeatAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(attrib, () => $"QuestPeriodRepeatAttrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
foreach (var info in m_period_repeat_quests)
|
||||
{
|
||||
QuestPeriodRepeatInfo repeat_info = new();
|
||||
foreach (var sended_quest in info.Value.m_sended_quest)
|
||||
{
|
||||
repeat_info.m_sended_quest.TryAdd(sended_quest.Key, sended_quest.Value);
|
||||
}
|
||||
|
||||
if (false == attrib.m_period_repeat_quests.TryAdd(info.Key, repeat_info))
|
||||
{
|
||||
Log.getLogger().warn($"m_period_repeat_quests add Fail info.key : {info.Key}, value : {JsonConvert.SerializeObject(info.Value)}");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeFromDoc(DynamoDbDocBase customDoc)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(QuestPeriodRepeatCheckDoc).Name;
|
||||
|
||||
var period_repeat_quest_doc = customDoc as QuestPeriodRepeatCheckDoc;
|
||||
if (null == period_repeat_quest_doc)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, period_repeat_quest_doc is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// New Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
syncOriginDocBaseWithNewDoc<QuestPeriodRepeatCheckAttribute>(period_repeat_quest_doc);
|
||||
|
||||
//=====================================================================================
|
||||
// Doc => Attribute
|
||||
//=====================================================================================
|
||||
var period_repeat_quest_attrib = period_repeat_quest_doc.getAttrib<QuestPeriodRepeatAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(period_repeat_quest_attrib, () => $"period_repeat_quest_attrib is null !!!");
|
||||
|
||||
foreach (var info in period_repeat_quest_attrib.m_period_repeat_quests)
|
||||
{
|
||||
QuestPeriodRepeatInfo repeat_info = new();
|
||||
foreach (var sended_quest in info.Value.m_sended_quest)
|
||||
{
|
||||
repeat_info.m_sended_quest.TryAdd(sended_quest.Key, sended_quest.Value);
|
||||
}
|
||||
|
||||
if (false == m_period_repeat_quests.TryAdd(info.Key, repeat_info))
|
||||
{
|
||||
Log.getLogger().warn($"m_period_repeat_quests add Fail info.key : {info.Key}, value : {JsonConvert.SerializeObject(info.Value)}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new QuestPeriodRepeatTransactor(getOwner());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class QuestPeriodRepeatTransactor : EntityAttributeTransactorBase<QuestPeriodRepeatCheckAttribute>
|
||||
{
|
||||
public QuestPeriodRepeatTransactor(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorBaseFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user