361 lines
13 KiB
C#
361 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using MetaAssets;
|
|
|
|
|
|
using USER_GUID = System.String;
|
|
|
|
|
|
namespace ServerCommon;
|
|
|
|
public class UgqQuestInfo
|
|
{
|
|
[JsonProperty()]
|
|
public UInt32 QuestRevision { get; set; } = 0;
|
|
|
|
[JsonProperty()]
|
|
public Int32 QuestCost { get; set; } = 0;
|
|
|
|
[JsonProperty()]
|
|
public UgqStateType UqgState { get; set; } = UgqStateType.None;
|
|
}
|
|
|
|
public class QuestAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
|
{
|
|
[JsonProperty()]
|
|
public UInt32 QuestId { get; set; } = 0;
|
|
|
|
[JsonProperty()]
|
|
public EQuestType QuestType { get; set; } = EQuestType.NONE;
|
|
|
|
[JsonProperty()]
|
|
public UgqQuestInfo UgqInfo { get; set; } = new();
|
|
|
|
[JsonProperty()]
|
|
public DateTime QuestAssignTime { get; set; } = DateTimeHelper.Current;
|
|
|
|
[JsonProperty()]
|
|
public Int32 CurrentTaskNum { get; set; } = 0;
|
|
|
|
[JsonProperty()]
|
|
public DateTime TaskStartTime { get; set; } = DateTimeHelper.Current;
|
|
|
|
[JsonProperty()]
|
|
public DateTime QuestCompleteTime { get; set; } = DateTimeHelper.Current;
|
|
|
|
|
|
public List<string> ActiveEvents { get; set; } = new();
|
|
|
|
public Int32 HasCounter { get; set; } = 0;
|
|
|
|
|
|
public Int32 MinCounter { get; set; } = 0;
|
|
|
|
public Int32 MaxCounter { get; set; } = 0;
|
|
|
|
|
|
public Int32 CurrentCounter { get; set; } = 0;
|
|
|
|
public Int32 IsComplete { get; set; } = 0;
|
|
|
|
|
|
public Int32 ReplacedRewardGroupId { get; set; } = 0;
|
|
|
|
|
|
public Int32 HasTimer { get; set; } = 0;
|
|
|
|
|
|
public DateTime TimerCompleteTime { get; set; } = DateTimeHelper.Current;
|
|
|
|
[JsonProperty()]
|
|
public Int32 CurrentTaskComplete { get; set; } = 0;
|
|
|
|
[JsonProperty()]
|
|
public List<string> CompletedIdxStrings { get; set; } = new();
|
|
|
|
public QuestDoc? m_quest_doc_nullable { get; set; } = null;
|
|
|
|
public QuestAttribute(EntityBase owner, EntityBase entityOfOwnerEntityType)
|
|
: base(owner, entityOfOwnerEntityType)
|
|
{
|
|
}
|
|
|
|
|
|
public override void onClear()
|
|
{
|
|
QuestId = 0;
|
|
QuestType = EQuestType.NONE;
|
|
UgqInfo = new();
|
|
QuestAssignTime = new();
|
|
CurrentTaskNum = 0;
|
|
TaskStartTime = new();
|
|
QuestCompleteTime = new();
|
|
ActiveEvents.Clear();
|
|
HasCounter = 0;
|
|
MinCounter = 0;
|
|
MaxCounter = 0;
|
|
CurrentCounter = 0;
|
|
IsComplete = 0;
|
|
ReplacedRewardGroupId = 0;
|
|
HasTimer = 0;
|
|
TimerCompleteTime = new();
|
|
CurrentTaskComplete = 0;
|
|
CompletedIdxStrings.Clear();
|
|
|
|
m_quest_doc_nullable = null;
|
|
|
|
getAttributeState().reset();
|
|
}
|
|
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var owner = getOwner();
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"player is null !!!");
|
|
|
|
var result = new Result();
|
|
|
|
var quest_attribute = owner.getEntityAttribute<QuestAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(quest_attribute, () => $"quest_attribute is null !!! - {owner.toBasicString()}");
|
|
|
|
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 QuestDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = new QuestDoc(user_guid, QuestId, UgqInfo.QuestRevision);
|
|
|
|
var origin_doc = getOriginDocBase<QuestAttribute>();
|
|
if (null != origin_doc)
|
|
{
|
|
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
|
}
|
|
|
|
try_pending_doc = to_copy_doc;
|
|
|
|
setTryPendingDocBase(try_pending_doc);
|
|
}
|
|
|
|
var to_copy_quest_attrib = try_pending_doc.getAttrib<QuestAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(to_copy_quest_attrib, () => $"to_copy_quest_attrib is null !!!");
|
|
|
|
to_copy_quest_attrib.m_quest_id = QuestId;
|
|
to_copy_quest_attrib.m_ugq_quest_info = new UgqQuestInfo();
|
|
to_copy_quest_attrib.m_ugq_quest_info.QuestRevision = UgqInfo.QuestRevision;
|
|
to_copy_quest_attrib.m_ugq_quest_info.QuestCost = UgqInfo.QuestCost;
|
|
to_copy_quest_attrib.m_ugq_quest_info.UqgState = UgqInfo.UqgState;
|
|
to_copy_quest_attrib.m_quest_type = QuestType;
|
|
to_copy_quest_attrib.m_ugq_quest_info = UgqInfo;
|
|
to_copy_quest_attrib.m_quest_assign_time = QuestAssignTime;
|
|
to_copy_quest_attrib.m_current_task_num = CurrentTaskNum;
|
|
to_copy_quest_attrib.m_task_start_time = TaskStartTime;
|
|
to_copy_quest_attrib.m_quest_complete_time = QuestCompleteTime;
|
|
to_copy_quest_attrib.m_active_events = ActiveEvents;
|
|
to_copy_quest_attrib.m_has_counter = HasCounter;
|
|
to_copy_quest_attrib.m_min_counter = MinCounter;
|
|
to_copy_quest_attrib.m_max_counter = MaxCounter;
|
|
to_copy_quest_attrib.m_current_counter = CurrentCounter;
|
|
to_copy_quest_attrib.m_is_complete = IsComplete;
|
|
to_copy_quest_attrib.m_replaced_reward_group_id = ReplacedRewardGroupId;
|
|
to_copy_quest_attrib.m_has_timer = HasTimer;
|
|
to_copy_quest_attrib.m_timer_complete_time = TimerCompleteTime;
|
|
to_copy_quest_attrib.m_is_current_task_complete = CurrentTaskComplete;
|
|
to_copy_quest_attrib.m_completed_idx_strings = CompletedIdxStrings;
|
|
|
|
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 QuestAttribute(getOwner(), owner_entity_type);
|
|
cloned.deepCopyFromBase(this);
|
|
|
|
cloned.QuestId = QuestId;
|
|
cloned.QuestType = QuestType;
|
|
cloned.UgqInfo = new();
|
|
cloned.UgqInfo.QuestRevision = UgqInfo.QuestRevision;
|
|
cloned.UgqInfo.QuestCost = UgqInfo.QuestCost;
|
|
cloned.UgqInfo.UqgState = UgqInfo.UqgState;
|
|
cloned.QuestAssignTime = QuestAssignTime;
|
|
cloned.CurrentTaskNum = CurrentTaskNum;
|
|
cloned.TaskStartTime = TaskStartTime;
|
|
cloned.QuestCompleteTime = QuestCompleteTime;
|
|
cloned.ActiveEvents.AddRange(ActiveEvents);
|
|
cloned.HasCounter = HasCounter;
|
|
cloned.MinCounter = MinCounter;
|
|
cloned.MaxCounter = MaxCounter;
|
|
cloned.CurrentCounter = CurrentCounter;
|
|
cloned.IsComplete = IsComplete;
|
|
cloned.ReplacedRewardGroupId = ReplacedRewardGroupId;
|
|
cloned.HasTimer = HasTimer;
|
|
cloned.TimerCompleteTime = TimerCompleteTime;
|
|
cloned.CurrentTaskComplete = CurrentTaskComplete;
|
|
cloned.CompletedIdxStrings.AddRange(CompletedIdxStrings);
|
|
|
|
return cloned;
|
|
}
|
|
|
|
public Result onMerge(EntityAttributeBase otherEntityAttribute)
|
|
{
|
|
var result = new Result();
|
|
if(getAttributeState().hasFlag(StateType.Removed))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
var owner = getOwner();
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
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;
|
|
}
|
|
var other_attribute = otherEntityAttribute as QuestAttribute;
|
|
if (null == other_attribute)
|
|
{
|
|
err_msg = $"Failed to cast QuestAttribute !!!, other_attribute is null";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// OtherAttribute => Attribute
|
|
//=====================================================================================
|
|
QuestId = other_attribute.QuestId;
|
|
QuestType = other_attribute.QuestType;
|
|
UgqInfo = new UgqQuestInfo();
|
|
UgqInfo.QuestCost = other_attribute.UgqInfo.QuestCost;
|
|
UgqInfo.QuestRevision = other_attribute.UgqInfo.QuestRevision;
|
|
UgqInfo.UqgState = other_attribute.UgqInfo.UqgState;
|
|
QuestAssignTime = other_attribute.QuestAssignTime;
|
|
CurrentTaskNum = other_attribute.CurrentTaskNum;
|
|
TaskStartTime = other_attribute.TaskStartTime;
|
|
QuestCompleteTime = other_attribute.QuestCompleteTime;
|
|
ActiveEvents = other_attribute.ActiveEvents;
|
|
HasCounter = other_attribute.HasCounter;
|
|
MinCounter = other_attribute.MinCounter;
|
|
MaxCounter = other_attribute.MaxCounter;
|
|
CurrentCounter = other_attribute.CurrentCounter;
|
|
IsComplete = other_attribute.IsComplete;
|
|
ReplacedRewardGroupId = other_attribute.ReplacedRewardGroupId;
|
|
HasTimer = other_attribute.HasTimer;
|
|
TimerCompleteTime = other_attribute.TimerCompleteTime;
|
|
CurrentTaskComplete = other_attribute.CurrentTaskComplete;
|
|
CompletedIdxStrings = other_attribute.CompletedIdxStrings.ToList();
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = other_attribute.getTryPendingDocBase() as QuestDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
other_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<QuestAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<QuestAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var quest_attrib = origin_doc_base.getAttrib<QuestAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(quest_attrib, () => $"quest_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
quest_attrib.m_quest_id = QuestId;
|
|
quest_attrib.m_quest_type = QuestType;
|
|
quest_attrib.m_ugq_quest_info = new UgqQuestInfo();
|
|
quest_attrib.m_ugq_quest_info.QuestCost = UgqInfo.QuestCost;
|
|
quest_attrib.m_ugq_quest_info.QuestRevision = UgqInfo.QuestRevision;
|
|
quest_attrib.m_ugq_quest_info.UqgState = UgqInfo.UqgState;
|
|
quest_attrib.m_quest_assign_time = QuestAssignTime;
|
|
quest_attrib.m_current_task_num = CurrentTaskNum;
|
|
quest_attrib.m_task_start_time = TaskStartTime;
|
|
quest_attrib.m_quest_complete_time = QuestCompleteTime;
|
|
quest_attrib.m_active_events = other_attribute.ActiveEvents;
|
|
quest_attrib.m_has_counter = HasCounter;
|
|
quest_attrib.m_min_counter = other_attribute.MinCounter;
|
|
quest_attrib.m_max_counter = MaxCounter;
|
|
quest_attrib.m_current_counter = CurrentCounter;
|
|
quest_attrib.m_is_complete = IsComplete;
|
|
quest_attrib.m_replaced_reward_group_id = ReplacedRewardGroupId;
|
|
quest_attrib.m_has_timer = HasTimer;
|
|
quest_attrib.m_timer_complete_time = TimerCompleteTime;
|
|
quest_attrib.m_is_current_task_complete = CurrentTaskComplete;
|
|
quest_attrib.m_completed_idx_strings = CompletedIdxStrings.ToList();
|
|
|
|
return result;
|
|
}
|
|
|
|
public bool copyEntityAttributeFromDoc(DynamoDbDocBase customDoc)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
|
|
return new QuestsAttributeTransactor(getOwner());
|
|
}
|
|
}
|
|
|
|
|
|
public class QuestsAttributeTransactor : EntityAttributeTransactorBase<QuestAttribute>
|
|
{
|
|
public QuestsAttributeTransactor(EntityBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public bool copyEntityAttributeTransactorBaseFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
|
{
|
|
//아직 미사용
|
|
Log.getLogger().info("copyEntityDbTransactBaseFromEntityAttribute call");
|
|
|
|
return true;
|
|
}
|
|
}
|