Files
caliverse_server/ServerCommon/Entity/Attribute/AppearanceCustomizeAttribute.cs
2025-05-01 07:20:41 +09:00

288 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Amazon.S3.Model;
using Newtonsoft.Json;
using ServerCore; using ServerBase;
using SESSION_ID = System.Int32;
using WORLD_ID = System.UInt32;
using META_ID = System.UInt32;
using ENTITY_GUID = System.String;
using ACCOUNT_ID_STRING = System.String;
using ACCOUNT_ID = System.String;
using OWNER_GUID = System.String;
using USER_GUID = System.String;
using CHARACTER_GUID = System.String;
using ITEM_GUID = System.String;
namespace ServerCommon
{
public class AppearanceCustomizeAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute
{
[JsonProperty]
public Int32 BasicStyle { get; set; } = 0;
[JsonProperty]
public Int32 BodyShape { get; set; } = 0;
[JsonProperty]
public Int32 HairStyle { get; set; } = 0;
public List<Int32> CustomValues { get; set; } = new();
public AppearanceCustomizeAttribute(EntityBase owner)
: base(owner, owner)
{
}
public override void onClear()
{
BasicStyle = 0;
BodyShape = 0;
HairStyle = 0;
CustomValues.Clear();
getAttributeState().reset();
}
public override EntityAttributeBase onCloned()
{
var owner = getOwner();
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var cloned = new AppearanceCustomizeAttribute(owner);
cloned.deepCopyFromBase(this);
cloned.BasicStyle = BasicStyle;
cloned.BodyShape = BodyShape;
cloned.HairStyle = HairStyle;
cloned.CustomValues = CustomValues;
return cloned;
}
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
{
return new AppearanceCustomizeAttributeTransactor(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 => Doc
//=====================================================================================
var try_pending_doc = getTryPendingDocBase() as AppearanceCustomizeDoc;
if (null == try_pending_doc)
{
(result, var owner_entity_type, var owner_guid) = onToOwnerEntity4Db(owner);
if(result.isFail())
{
return (result, null);
}
var to_copy_doc = new AppearanceCustomizeDoc(owner_entity_type, owner_guid);
var origin_doc = getOriginDocBase<AppearanceCustomizeAttribute>();
if (null != origin_doc)
{
to_copy_doc.copyTimestampsFromOriginDocBase(origin_doc);
}
try_pending_doc = to_copy_doc;
setTryPendingDocBase(try_pending_doc);
}
var to_copy_doc_attrib = try_pending_doc.getAttrib<AppearanceCustomizeAttrib>();
NullReferenceCheckHelper.throwIfNull(to_copy_doc_attrib, () => $"to_copy_doc_attrib is null !!!");
to_copy_doc_attrib.BasicStyle = BasicStyle;
to_copy_doc_attrib.BodyShape = BodyShape;
to_copy_doc_attrib.HairStyle = HairStyle;
to_copy_doc_attrib.CustomValues = CustomValues;
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);
}
NullReferenceCheckHelper.throwIfNull(to_query_doc, () => $"to_query_doc is null !!!");
return (result, to_query_doc);
}
public override (Result, OwnerEntityType, OWNER_GUID) onToOwnerEntity4Db(EntityBase ownerEntity)
{
var result = new Result();
var owner_entity_type = ownerEntity.getEntityType().toOwnerEntityType();
if(OwnerEntityType.None == owner_entity_type)
{
return (result, OwnerEntityType.None, string.Empty);
}
return (result, owner_entity_type, ownerEntity.onGetDbGuid());
}
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 => Attribute
//=====================================================================================
var other_appearance_customize_attribute = otherEntityAttribute as AppearanceCustomizeAttribute;
if (null == other_appearance_customize_attribute)
{
err_msg = $"Failed to cast AppearanceCustomizeAttribute !!!, other_appearance_customize_attribute is null";
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
BasicStyle = other_appearance_customize_attribute.BasicStyle;
BodyShape = other_appearance_customize_attribute.BodyShape;
HairStyle = other_appearance_customize_attribute.HairStyle;
CustomValues = other_appearance_customize_attribute.CustomValues;
//=====================================================================================
// Attribute Try Pending Doc => Origin Doc
//=====================================================================================
var try_pending_doc = other_appearance_customize_attribute.getTryPendingDocBase() as AppearanceCustomizeDoc;
if (null != try_pending_doc)
{
other_appearance_customize_attribute.resetTryPendingDocBase();
syncOriginDocBaseWithNewDoc<AppearanceCustomizeAttribute>(try_pending_doc);
}
var origin_doc_base = getOriginDocBase<AppearanceCustomizeAttribute>();
if(null == origin_doc_base)
{
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
return result;
}
var appearance_customize_attrib = origin_doc_base.getAttrib<AppearanceCustomizeAttrib>();
NullReferenceCheckHelper.throwIfNull(appearance_customize_attrib, () => $"appearance_customize_attrib is null !!! - {owner.toBasicString()}");
appearance_customize_attrib.BasicStyle = BasicStyle;
appearance_customize_attrib.BodyShape = BodyShape;
appearance_customize_attrib.HairStyle = HairStyle;
appearance_customize_attrib.CustomValues = CustomValues;
return result;
}
public bool copyEntityAttributeFromDoc(DynamoDbDocBase? docBase)
{
var err_msg = string.Empty;
var to_cast_string = typeof(AppearanceCustomizeDoc).Name;
var appearance_customize_doc = docBase as AppearanceCustomizeDoc;
if (null == appearance_customize_doc)
{
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, appearance_customize_doc is null :{to_cast_string}";
Log.getLogger().error(err_msg);
return false;
}
//=====================================================================================
// New Doc => Origin Doc
//=====================================================================================
syncOriginDocBaseWithNewDoc<AppearanceCustomizeAttribute>(appearance_customize_doc);
//=====================================================================================
// Doc => Attribute
//=====================================================================================
var appearance_customize_attrib = appearance_customize_doc.getAttrib<AppearanceCustomizeAttrib>();
NullReferenceCheckHelper.throwIfNull(appearance_customize_attrib, () => $"appearance_customize_attrib is null !!! - {toBasicString()}");
BasicStyle = appearance_customize_attrib.BasicStyle;
BodyShape = appearance_customize_attrib.BodyShape;
HairStyle = appearance_customize_attrib.HairStyle;
CustomValues = appearance_customize_attrib.CustomValues;
return true;
}
}
public class AppearanceCustomizeAttributeTransactor : EntityAttributeTransactorBase<AppearanceCustomizeAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
{
public AppearanceCustomizeAttributeTransactor(EntityBase owner)
: base(owner)
{
}
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase entityAttributeBase)
{
ArgumentNullReferenceCheckHelper.throwIfNull(entityAttributeBase, () => $"entityAttributeBase is null !!!");
var err_msg = string.Empty;
var to_cast_string = typeof(AppearanceCustomizeAttribute).Name;
var copy_from_appearance_customize_attribute = entityAttributeBase as AppearanceCustomizeAttribute;
if (null == copy_from_appearance_customize_attribute)
{
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_appearance_customize_attribute is null :{to_cast_string}";
Log.getLogger().error(err_msg);
return false;
}
var copy_to_appearance_customize_attribute = getClonedEntityAttribute() as AppearanceCustomizeAttribute;
if (null == copy_to_appearance_customize_attribute)
{
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_appearance_customize_attribute is null :{to_cast_string}";
Log.getLogger().error(err_msg);
return false;
}
copy_to_appearance_customize_attribute.BasicStyle = copy_from_appearance_customize_attribute.BasicStyle;
copy_to_appearance_customize_attribute.BodyShape = copy_from_appearance_customize_attribute.BodyShape;
copy_to_appearance_customize_attribute.HairStyle = copy_from_appearance_customize_attribute.HairStyle;
copy_to_appearance_customize_attribute.CustomValues = copy_from_appearance_customize_attribute.CustomValues.ToList();
return true;
}
}
}