160 lines
4.7 KiB
C#
160 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
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 ITEM_GUID = System.String;
|
|
|
|
|
|
|
|
namespace ServerCommon;
|
|
|
|
public class ItemAttrib : AttribBase
|
|
{
|
|
[JsonProperty("item_guid")]
|
|
public ITEM_GUID ItemGuid { get; set; } = string.Empty;
|
|
|
|
[JsonProperty("item_meta_id")]
|
|
public META_ID ItemMetaId { get; set; } = 0;
|
|
|
|
[JsonProperty("owner_guid")]
|
|
public OWNER_GUID OwnerGuid { get; set; } = string.Empty;
|
|
|
|
[JsonProperty("owner_entity_type")]
|
|
public OwnerEntityType OwnerEntityType { get; set; } = OwnerEntityType.None;
|
|
|
|
[JsonProperty("item_stack_count")]
|
|
public UInt16 ItemStackCount { get; set; } = 0;
|
|
|
|
[JsonProperty("level")]
|
|
public UInt16 Level { get; set; } = 0;
|
|
|
|
[JsonProperty("attributes")]
|
|
public List<UInt16> Attributes { get; set; } = new();
|
|
|
|
[JsonProperty("equiped_inven_type")]
|
|
public InvenEquipType EquipedIvenType { get; set; } = InvenEquipType.None;
|
|
|
|
[JsonProperty("equiped_pos")]
|
|
public UInt16 EquipedPos { get; set; } = 0;
|
|
|
|
public ItemAttrib()
|
|
: base(typeof(ItemAttrib).Name)
|
|
{ }
|
|
|
|
public ItemAttrib(string docType, bool isSaveToJsonInDb = true)
|
|
: base(docType, isSaveToJsonInDb)
|
|
{ }
|
|
}
|
|
|
|
//=============================================================================================
|
|
// Primary Key
|
|
// PK(Partition Key) : "item#owner_guid" [owner_guid : user_guid, ugc_npc_meta_guid]
|
|
// SK(Sort Key) : "item_guid"
|
|
// DocType : ItemDoc
|
|
// ItemAttrib : {}
|
|
// ...
|
|
//=============================================================================================
|
|
public class ItemDoc : DynamoDbDocBase, ICopyDocFromEntityAttribute
|
|
{
|
|
private static string getPrefixOfPK() { return "item#"; }
|
|
private static string getPrefixOfSK() { return ""; }
|
|
|
|
public ItemDoc()
|
|
: base(typeof(ItemDoc).Name)
|
|
{
|
|
appendAttribWrapperAll();
|
|
}
|
|
|
|
public ItemDoc(string docType)
|
|
: base(docType)
|
|
{
|
|
}
|
|
|
|
public ItemDoc(OwnerEntityType ownerEntityType, string ownerGuid, string itemGuid)
|
|
: base(typeof(ItemDoc).Name)
|
|
{
|
|
setCombinationKeyForPK(ownerGuid);
|
|
setCombinationKeyForSK(itemGuid);
|
|
|
|
appendAttribWrapperAll();
|
|
|
|
fillUpPrimaryKey(onMakePK(), onMakeSK());
|
|
|
|
var doc_item_attrib = getAttrib<ItemAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(doc_item_attrib, () => $"doc_item_attrib is null !!! - itemGuid:{itemGuid}, ownerGuid:{ownerGuid}, ownerEntityType:{ownerEntityType}");
|
|
|
|
doc_item_attrib.OwnerGuid = ownerGuid;
|
|
doc_item_attrib.OwnerEntityType = ownerEntityType;
|
|
doc_item_attrib.ItemGuid = itemGuid;
|
|
}
|
|
|
|
private void appendAttribWrapperAll()
|
|
{
|
|
appendAttribWrapper(new AttribWrapper<ItemAttrib>());
|
|
}
|
|
|
|
protected override string onGetPrefixOfPK()
|
|
{
|
|
return getPrefixOfPK();
|
|
}
|
|
|
|
protected override string onGetPrefixOfSK()
|
|
{
|
|
return getPrefixOfSK();
|
|
}
|
|
|
|
protected override ServerErrorCode onCheckAndSetSK(string sortKey)
|
|
{
|
|
getPrimaryKey().fillUpSK(sortKey);
|
|
setCombinationKeyForSK(sortKey);
|
|
|
|
return ServerErrorCode.Success;
|
|
}
|
|
|
|
// override ICopyDocFromEntityAttribute
|
|
public bool copyDocFromEntityAttribute(EntityAttributeBase entityAttributeBase)
|
|
{
|
|
ArgumentNullReferenceCheckHelper.throwIfNull(entityAttributeBase, () => $"entityAttributeBase is null !!! - {toBasicString()}");
|
|
|
|
var item_attribute = entityAttributeBase as ItemAttributeBase;
|
|
if(null == item_attribute)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var to_copy_doc_item_attrib = getAttrib<ItemAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(to_copy_doc_item_attrib, () => $"to_copy_doc_item_attrib is null !!! - {toBasicString()}");
|
|
|
|
to_copy_doc_item_attrib.ItemGuid = item_attribute.ItemGuid;
|
|
to_copy_doc_item_attrib.ItemMetaId = item_attribute.ItemMetaId;
|
|
to_copy_doc_item_attrib.ItemStackCount = item_attribute.ItemStackCount;
|
|
to_copy_doc_item_attrib.Level = item_attribute.Level;
|
|
to_copy_doc_item_attrib.Attributes = item_attribute.Attributes.Select(x => x).ToList();
|
|
to_copy_doc_item_attrib.EquipedIvenType = item_attribute.EquipedIvenType;
|
|
to_copy_doc_item_attrib.EquipedPos = item_attribute.EquipedPos;
|
|
|
|
|
|
return true;
|
|
}
|
|
}
|