초기커밋
This commit is contained in:
422
ServerCommon/Entity/Attribute/UgcNpcAttribute.cs
Normal file
422
ServerCommon/Entity/Attribute/UgcNpcAttribute.cs
Normal file
@@ -0,0 +1,422 @@
|
||||
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 SESSION_ID = System.Int32;
|
||||
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 UGC_NPC_META_GUID = System.String;
|
||||
using ITEM_GUID = System.String;
|
||||
using ANCHOR_META_GUID = System.String;
|
||||
|
||||
|
||||
namespace ServerCommon
|
||||
{
|
||||
public class UgcNpcAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
|
||||
{
|
||||
[JsonProperty]
|
||||
public UGC_NPC_META_GUID UgcNpcMetaGuid { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public string Nickname { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public string Greeting { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public string Introduction { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public string WorldScenario { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public META_ID DefaultSocialActionMetaId { get; set; } = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public List<META_ID> HabitSocialActionMetaIds { get; set; } = new List<META_ID>();
|
||||
|
||||
[JsonProperty]
|
||||
public List<META_ID> DialogueSocialActionMetaIds { get; set; } = new List<META_ID>() { 110054 };
|
||||
|
||||
[JsonProperty]
|
||||
public META_ID BodyItemMetaId { get; set; } = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public List<META_ID> HashTagMetaIds { get; set; } = new();
|
||||
|
||||
[JsonProperty]
|
||||
public OwnerEntityType OwnerEntityType { get; set; } = OwnerEntityType.None;
|
||||
|
||||
[JsonProperty]
|
||||
public OWNER_GUID OwnerGuid { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public LanguageType LanguageType { get; set; } = LanguageType.None;
|
||||
|
||||
[JsonProperty]
|
||||
public EntityStateType State { get; set; } = EntityStateType.None;
|
||||
|
||||
[JsonProperty]
|
||||
public ANCHOR_META_GUID AnchorMetaGuid { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public META_ID MetaIdOfEntityStateType { get; set; } = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public string LocatedInstanceGuid { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty]
|
||||
public META_ID LocatedInstanceMetaId { get; set; } = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public bool IsRegisteredAiChatServer { get; set; } = false;
|
||||
|
||||
private EntityPos m_current_pos = new();
|
||||
|
||||
public UgcNpcAttribute(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override void newEntityAttribute()
|
||||
{
|
||||
UgcNpcMetaGuid = System.Guid.NewGuid().ToString("N");
|
||||
base.newEntityAttribute();
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
UgcNpcMetaGuid = string.Empty;
|
||||
Nickname = string.Empty;
|
||||
Title = string.Empty;
|
||||
Greeting = string.Empty;
|
||||
Introduction = string.Empty;
|
||||
Description = string.Empty;
|
||||
WorldScenario = string.Empty;
|
||||
DefaultSocialActionMetaId = 0;
|
||||
HabitSocialActionMetaIds.Clear();
|
||||
DialogueSocialActionMetaIds.Clear();
|
||||
BodyItemMetaId = 0;
|
||||
HashTagMetaIds.Clear();
|
||||
|
||||
OwnerEntityType = OwnerEntityType.None;
|
||||
OwnerGuid = string.Empty;
|
||||
LanguageType = LanguageType.None;
|
||||
AnchorMetaGuid = string.Empty;
|
||||
State = EntityStateType.None;
|
||||
LocatedInstanceGuid = string.Empty;
|
||||
LocatedInstanceMetaId = 0;
|
||||
|
||||
IsRegisteredAiChatServer = false;
|
||||
|
||||
m_current_pos = new();
|
||||
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var cloned = new UgcNpcAttribute(owner);
|
||||
|
||||
cloned.deepCopyFromBase(this);
|
||||
|
||||
cloned.UgcNpcMetaGuid = UgcNpcMetaGuid;
|
||||
cloned.Nickname = Nickname;
|
||||
cloned.Title = Title;
|
||||
cloned.Greeting = Greeting;
|
||||
cloned.Introduction = Introduction;
|
||||
cloned.Description = Description;
|
||||
cloned.WorldScenario = WorldScenario;
|
||||
cloned.DefaultSocialActionMetaId = DefaultSocialActionMetaId;
|
||||
cloned.HabitSocialActionMetaIds = HabitSocialActionMetaIds.Select(x => x).ToList();
|
||||
cloned.DialogueSocialActionMetaIds = DialogueSocialActionMetaIds.Select(x => x).ToList();
|
||||
cloned.BodyItemMetaId = BodyItemMetaId;
|
||||
cloned.HashTagMetaIds = HashTagMetaIds.Select(x => x).ToList();
|
||||
|
||||
cloned.OwnerEntityType = OwnerEntityType;
|
||||
cloned.OwnerGuid = OwnerGuid;
|
||||
cloned.LanguageType = LanguageType;
|
||||
cloned.State = State;
|
||||
cloned.AnchorMetaGuid = AnchorMetaGuid;
|
||||
cloned.MetaIdOfEntityStateType = MetaIdOfEntityStateType;
|
||||
cloned.LocatedInstanceGuid = LocatedInstanceGuid;
|
||||
cloned.LocatedInstanceMetaId = LocatedInstanceMetaId;
|
||||
|
||||
cloned.IsRegisteredAiChatServer = IsRegisteredAiChatServer;
|
||||
|
||||
cloned.m_current_pos = m_current_pos.clone();
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new UgcNpcAttributeTransactor(getOwner());
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute => try pending Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = getTryPendingDocBase() as UgcNpcDoc;
|
||||
if (null == try_pending_doc)
|
||||
{
|
||||
var to_copy_doc = new UgcNpcDoc(OwnerEntityType, OwnerGuid, UgcNpcMetaGuid);
|
||||
|
||||
var origin_doc = getOriginDocBase<UgcNpcAttribute>();
|
||||
if (null != origin_doc)
|
||||
{
|
||||
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
||||
}
|
||||
|
||||
try_pending_doc = to_copy_doc;
|
||||
|
||||
setTryPendingDocBase(try_pending_doc);
|
||||
}
|
||||
|
||||
var to_copy_doc_ugc_npc_attrib = try_pending_doc.getAttrib<UgcNpcAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(to_copy_doc_ugc_npc_attrib, () => $"to_copy_doc_ugc_npc_attrib is null !!! - {owner.toBasicStringWithMaster()}");
|
||||
|
||||
to_copy_doc_ugc_npc_attrib.Nickname = Nickname;
|
||||
to_copy_doc_ugc_npc_attrib.Title = Title;
|
||||
to_copy_doc_ugc_npc_attrib.Greeting = Greeting;
|
||||
to_copy_doc_ugc_npc_attrib.Introduction = Introduction;
|
||||
to_copy_doc_ugc_npc_attrib.Description = Description;
|
||||
to_copy_doc_ugc_npc_attrib.WorldScenario = WorldScenario;
|
||||
to_copy_doc_ugc_npc_attrib.DefaultSocialActionMetaId = DefaultSocialActionMetaId;
|
||||
to_copy_doc_ugc_npc_attrib.HabitSocialActionMetaIds = HabitSocialActionMetaIds.Select(x => x).ToList();
|
||||
to_copy_doc_ugc_npc_attrib.DialogueSocialActionMetaIds = DialogueSocialActionMetaIds.Select(x => x).ToList();
|
||||
to_copy_doc_ugc_npc_attrib.BodyItemMetaId = BodyItemMetaId;
|
||||
to_copy_doc_ugc_npc_attrib.HashTagMetaIds = HashTagMetaIds.Select(x => x).ToList();
|
||||
|
||||
to_copy_doc_ugc_npc_attrib.OwnerEntityType = OwnerEntityType;
|
||||
to_copy_doc_ugc_npc_attrib.OwnerGuid = OwnerGuid;
|
||||
to_copy_doc_ugc_npc_attrib.LanguageType = LanguageType;
|
||||
to_copy_doc_ugc_npc_attrib.AnchorMetaGuid = AnchorMetaGuid;
|
||||
to_copy_doc_ugc_npc_attrib.MetaIdOfEntityStateType = MetaIdOfEntityStateType;
|
||||
to_copy_doc_ugc_npc_attrib.State = State;
|
||||
to_copy_doc_ugc_npc_attrib.LocatedInstanceGuid = LocatedInstanceGuid;
|
||||
to_copy_doc_ugc_npc_attrib.LocatedInstanceMetaId = LocatedInstanceMetaId;
|
||||
|
||||
to_copy_doc_ugc_npc_attrib.IsRegisteredAiChatServer = IsRegisteredAiChatServer;
|
||||
|
||||
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();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
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_ugc_npc_attribute = otherEntityAttribute as UgcNpcAttribute;
|
||||
if (null == other_ugc_npc_attribute)
|
||||
{
|
||||
err_msg = $"Failed to cast ItemAttribute !!!, other_item_attribute is null - {owner.toBasicStringWithMaster()}";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UgcNpcMetaGuid = other_ugc_npc_attribute.UgcNpcMetaGuid;
|
||||
Nickname = other_ugc_npc_attribute.Nickname;
|
||||
Title = other_ugc_npc_attribute.Title;
|
||||
Greeting = other_ugc_npc_attribute.Greeting;
|
||||
Introduction = other_ugc_npc_attribute.Introduction;
|
||||
Description = other_ugc_npc_attribute.Description;
|
||||
WorldScenario = other_ugc_npc_attribute.WorldScenario;
|
||||
DefaultSocialActionMetaId = other_ugc_npc_attribute.DefaultSocialActionMetaId;
|
||||
HabitSocialActionMetaIds = other_ugc_npc_attribute.HabitSocialActionMetaIds.Select(x => x).ToList();
|
||||
DialogueSocialActionMetaIds = other_ugc_npc_attribute.DialogueSocialActionMetaIds.Select(x => x).ToList();
|
||||
BodyItemMetaId = other_ugc_npc_attribute.BodyItemMetaId;
|
||||
HashTagMetaIds = other_ugc_npc_attribute.HashTagMetaIds.Select(x => x).ToList();
|
||||
|
||||
OwnerEntityType = other_ugc_npc_attribute.OwnerEntityType;
|
||||
OwnerGuid = other_ugc_npc_attribute.OwnerGuid;
|
||||
LanguageType = other_ugc_npc_attribute.LanguageType;
|
||||
State = other_ugc_npc_attribute.State;
|
||||
AnchorMetaGuid = other_ugc_npc_attribute.AnchorMetaGuid;
|
||||
MetaIdOfEntityStateType = other_ugc_npc_attribute.MetaIdOfEntityStateType;
|
||||
LocatedInstanceGuid = other_ugc_npc_attribute.LocatedInstanceGuid;
|
||||
LocatedInstanceMetaId = other_ugc_npc_attribute.LocatedInstanceMetaId;
|
||||
|
||||
IsRegisteredAiChatServer = other_ugc_npc_attribute.IsRegisteredAiChatServer;
|
||||
|
||||
m_current_pos = other_ugc_npc_attribute.m_current_pos.clone();
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute Try Pending Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = other_ugc_npc_attribute.getTryPendingDocBase() as UgcNpcDoc;
|
||||
if (null != try_pending_doc)
|
||||
{
|
||||
other_ugc_npc_attribute.resetTryPendingDocBase();
|
||||
|
||||
syncOriginDocBaseWithNewDoc<UgcNpcAttribute>(try_pending_doc);
|
||||
}
|
||||
|
||||
var origin_doc_base = getOriginDocBase<UgcNpcAttribute>();
|
||||
if (null == origin_doc_base)
|
||||
{
|
||||
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
||||
return result;
|
||||
}
|
||||
|
||||
var ugc_npc_attrib = origin_doc_base.getAttrib<UgcNpcAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(ugc_npc_attrib, () => $"ugc_npc_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
ugc_npc_attrib.UgcNpcMetaGuid = UgcNpcMetaGuid;
|
||||
ugc_npc_attrib.Nickname = Nickname;
|
||||
ugc_npc_attrib.Title = Title;
|
||||
ugc_npc_attrib.Greeting = Greeting;
|
||||
ugc_npc_attrib.Introduction = Introduction;
|
||||
ugc_npc_attrib.Description = Description;
|
||||
ugc_npc_attrib.WorldScenario = WorldScenario;
|
||||
ugc_npc_attrib.DefaultSocialActionMetaId = DefaultSocialActionMetaId;
|
||||
ugc_npc_attrib.HabitSocialActionMetaIds = HabitSocialActionMetaIds.Select(x => x).ToList();
|
||||
ugc_npc_attrib.DialogueSocialActionMetaIds = DialogueSocialActionMetaIds.Select(x => x).ToList();
|
||||
ugc_npc_attrib.BodyItemMetaId = BodyItemMetaId;
|
||||
ugc_npc_attrib.HashTagMetaIds = HashTagMetaIds.Select(x => x).ToList();
|
||||
|
||||
ugc_npc_attrib.OwnerEntityType = OwnerEntityType;
|
||||
ugc_npc_attrib.OwnerGuid = OwnerGuid;
|
||||
ugc_npc_attrib.LanguageType = LanguageType;
|
||||
ugc_npc_attrib.State = State;
|
||||
ugc_npc_attrib.AnchorMetaGuid = AnchorMetaGuid;
|
||||
ugc_npc_attrib.MetaIdOfEntityStateType = MetaIdOfEntityStateType;
|
||||
ugc_npc_attrib.LocatedInstanceGuid = LocatedInstanceGuid;
|
||||
ugc_npc_attrib.LocatedInstanceMetaId = LocatedInstanceMetaId;
|
||||
|
||||
ugc_npc_attrib.IsRegisteredAiChatServer = IsRegisteredAiChatServer;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeFromDoc(DynamoDbDocBase? docBase)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var to_cast_string = typeof(UgcNpcDoc).Name;
|
||||
|
||||
var ugc_npc_doc = docBase as UgcNpcDoc;
|
||||
if (null == ugc_npc_doc)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, ugc_npc_doc is null :{to_cast_string} - {owner.toBasicStringWithMaster()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// New Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
syncOriginDocBaseWithNewDoc<UgcNpcAttribute>(ugc_npc_doc);
|
||||
|
||||
var doc_ugc_npc_attrib = ugc_npc_doc.getAttrib<UgcNpcAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(doc_ugc_npc_attrib, () => $"doc_ugc_npc_attrib is null !!! - {owner.toBasicStringWithMaster()}");
|
||||
|
||||
UgcNpcMetaGuid = doc_ugc_npc_attrib.UgcNpcMetaGuid;
|
||||
Nickname = doc_ugc_npc_attrib.Nickname;
|
||||
Title = doc_ugc_npc_attrib.Title;
|
||||
Greeting = doc_ugc_npc_attrib.Greeting;
|
||||
Introduction = doc_ugc_npc_attrib.Introduction;
|
||||
Description = doc_ugc_npc_attrib.Description;
|
||||
WorldScenario = doc_ugc_npc_attrib.WorldScenario;
|
||||
DefaultSocialActionMetaId = doc_ugc_npc_attrib.DefaultSocialActionMetaId;
|
||||
HabitSocialActionMetaIds = doc_ugc_npc_attrib.HabitSocialActionMetaIds.Select(x => x).ToList();
|
||||
DialogueSocialActionMetaIds = doc_ugc_npc_attrib.DialogueSocialActionMetaIds.Select(x => x).ToList();
|
||||
BodyItemMetaId = doc_ugc_npc_attrib.BodyItemMetaId;
|
||||
HashTagMetaIds = doc_ugc_npc_attrib.HashTagMetaIds.Select(x => x).ToList();
|
||||
|
||||
OwnerEntityType = doc_ugc_npc_attrib.OwnerEntityType;
|
||||
OwnerGuid = doc_ugc_npc_attrib.OwnerGuid;
|
||||
LanguageType = doc_ugc_npc_attrib.LanguageType;
|
||||
State = doc_ugc_npc_attrib.State;
|
||||
AnchorMetaGuid = doc_ugc_npc_attrib.AnchorMetaGuid;
|
||||
MetaIdOfEntityStateType = doc_ugc_npc_attrib.MetaIdOfEntityStateType;
|
||||
LocatedInstanceGuid = doc_ugc_npc_attrib.LocatedInstanceGuid;
|
||||
LocatedInstanceMetaId = doc_ugc_npc_attrib.LocatedInstanceMetaId;
|
||||
|
||||
IsRegisteredAiChatServer = doc_ugc_npc_attrib.IsRegisteredAiChatServer;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setCurrentPos(EntityPos pos) => m_current_pos = pos;
|
||||
|
||||
public EntityPos getCurrentPos() => m_current_pos;
|
||||
|
||||
public override string toBasicString()
|
||||
{
|
||||
return $"UgcNpcNickname:{Nickname}, UgcNpcMetaGuid:{UgcNpcMetaGuid}";
|
||||
}
|
||||
}
|
||||
|
||||
public class UgcNpcAttributeTransactor : EntityAttributeTransactorBase<UgcNpcAttribute>
|
||||
{
|
||||
public UgcNpcAttributeTransactor(EntityBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user