초기커밋
This commit is contained in:
213
ServerCommon/Entity/Attribute/DailyQuestCheckAttribute.cs
Normal file
213
ServerCommon/Entity/Attribute/DailyQuestCheckAttribute.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
|
||||
|
||||
using USER_GUID = System.String;
|
||||
|
||||
namespace ServerCommon;
|
||||
|
||||
public class DailyQuestCheckAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
||||
{
|
||||
public HashSet<UInt32> m_daily_sended_quest { get; set; } = new();
|
||||
|
||||
public DateTime m_next_refresh_time { get; set; } = DateTimeHelper.Current.Date.AddDays(-1);
|
||||
|
||||
public DailyQuestCheckDoc? m_daily_quest_check_doc_nullable { get; set; } = null;
|
||||
|
||||
|
||||
|
||||
public DailyQuestCheckAttribute(EntityBase owner) : base(owner)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var owner = getOwner();
|
||||
|
||||
var daily_quest_check_attribute = owner.getEntityAttribute<DailyQuestCheckAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(daily_quest_check_attribute, () => $"daily_quest_check_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 DailyQuestCheckDoc;
|
||||
if (null == try_pending_doc)
|
||||
{
|
||||
var to_copy_doc = new DailyQuestCheckDoc(user_guid);
|
||||
|
||||
var origin_doc = getOriginDocBase<DailyQuestCheckAttribute>();
|
||||
if (null != origin_doc)
|
||||
{
|
||||
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
||||
}
|
||||
|
||||
try_pending_doc = to_copy_doc;
|
||||
|
||||
setTryPendingDocBase(try_pending_doc);
|
||||
}
|
||||
|
||||
var to_copy_daily_quest_check_attrib = try_pending_doc.getAttrib<DailyQuestCheckAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(to_copy_daily_quest_check_attrib, () => $"to_copy_daily_quest_check_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
foreach (var id in m_daily_sended_quest)
|
||||
{
|
||||
to_copy_daily_quest_check_attrib.m_daily_sended_quest.Add(id);
|
||||
}
|
||||
to_copy_daily_quest_check_attrib.m_next_refresh_time = m_next_refresh_time;
|
||||
|
||||
//=====================================================================================
|
||||
// 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 DailyQuestCheckAttribute(getOwner());
|
||||
cloned.deepCopyFromBase(this);
|
||||
|
||||
cloned.m_next_refresh_time = m_next_refresh_time;
|
||||
foreach (var id in m_daily_sended_quest)
|
||||
{
|
||||
cloned.m_daily_sended_quest.Add(id);
|
||||
}
|
||||
|
||||
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 DailyQuestCheckAttribute;
|
||||
if (null == other_attribute)
|
||||
{
|
||||
err_msg = $"Failed to cast DailyQuestCheckAttribute !!!, other_attribute is null";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// OtherAttribute => Attribute
|
||||
//=====================================================================================
|
||||
foreach (var id in other_attribute.m_daily_sended_quest)
|
||||
{
|
||||
m_daily_sended_quest.Add(id);
|
||||
}
|
||||
m_next_refresh_time = other_attribute.m_next_refresh_time;
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute Try Pending Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = other_attribute.getTryPendingDocBase() as DailyQuestCheckDoc;
|
||||
if (null != try_pending_doc)
|
||||
{
|
||||
other_attribute.resetTryPendingDocBase();
|
||||
|
||||
syncOriginDocBaseWithNewDoc<DailyQuestCheckAttribute>(try_pending_doc);
|
||||
}
|
||||
|
||||
var origin_doc_base = getOriginDocBase<DailyQuestCheckAttribute>();
|
||||
if (null == origin_doc_base)
|
||||
{
|
||||
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
||||
return result;
|
||||
}
|
||||
|
||||
var daily_quest_check_attrib = origin_doc_base.getAttrib<DailyQuestCheckAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(daily_quest_check_attrib, () => $"daily_quest_check_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
foreach (var id in m_daily_sended_quest)
|
||||
{
|
||||
daily_quest_check_attrib.m_daily_sended_quest.Add(id);
|
||||
}
|
||||
daily_quest_check_attrib.m_next_refresh_time = m_next_refresh_time;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeFromDoc(DynamoDbDocBase docBase)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(DailyQuestCheckDoc).Name;
|
||||
|
||||
var daily_quest_check_doc = docBase as DailyQuestCheckDoc;
|
||||
if (null == daily_quest_check_doc)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, daily_quest_check_doc is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// New Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
syncOriginDocBaseWithNewDoc<DailyQuestCheckAttribute>(daily_quest_check_doc);
|
||||
|
||||
//=====================================================================================
|
||||
// Doc => Attribute
|
||||
//=====================================================================================
|
||||
var daily_quest_check_attrib = daily_quest_check_doc.getAttrib<DailyQuestCheckAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(daily_quest_check_attrib, () => $"daily_quest_check_attrib is null !!!");
|
||||
|
||||
foreach (var id in daily_quest_check_attrib.m_daily_sended_quest)
|
||||
{
|
||||
m_daily_sended_quest.Add(id);
|
||||
}
|
||||
m_next_refresh_time = daily_quest_check_attrib.m_next_refresh_time;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new DailyQuestCheckTransactor(getOwner());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class DailyQuestCheckTransactor : EntityAttributeTransactorBase<DailyQuestCheckAttribute>
|
||||
{
|
||||
public DailyQuestCheckTransactor(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorBaseFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user