290 lines
12 KiB
C#
290 lines
12 KiB
C#
using Newtonsoft.Json;
|
|
using ServerCore; using ServerBase;
|
|
|
|
|
|
using BEACON_GUID = System.String;
|
|
using META_ID = System.UInt32;
|
|
using USER_GUID = System.String;
|
|
using ITEM_GUID = System.String;
|
|
using Amazon.S3.Model;
|
|
|
|
|
|
|
|
namespace ServerCommon
|
|
{
|
|
public class BeaconShopItemAttribute : ItemAttributeBase, IWithCommonResultFiller
|
|
{
|
|
[JsonProperty]
|
|
public USER_GUID UserGuid { get; set; } = string.Empty;
|
|
|
|
[JsonProperty]
|
|
public BEACON_GUID BeaconGuid { get; set; } = string.Empty;
|
|
|
|
[JsonProperty]
|
|
public DateTime SellingFinishTime { get; set; } = new();
|
|
|
|
[JsonProperty]
|
|
public double PriceForUnit { get; set; } = 0.0;
|
|
|
|
[JsonProperty]
|
|
public bool IsActiveSelling { get; set; } = false;
|
|
|
|
public BeaconShopItemAttribute(ItemBase owner, EntityBase entityOfOwnerEntityType)
|
|
: base(owner, entityOfOwnerEntityType)
|
|
{
|
|
}
|
|
|
|
public override void onClear()
|
|
{
|
|
base.onClear();
|
|
|
|
UserGuid = string.Empty;
|
|
BeaconGuid = string.Empty;
|
|
ItemGuid = string.Empty;
|
|
SellingFinishTime = new();
|
|
PriceForUnit = 0;
|
|
IsActiveSelling = false;
|
|
}
|
|
|
|
public override EntityAttributeBase onCloned()
|
|
{
|
|
var owner = getOwner() as ItemBase;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
var entity_of_owner_entity_type = getEntityOfOwnerEntityType();
|
|
NullReferenceCheckHelper.throwIfNull(entity_of_owner_entity_type, () => $"entity_of_owner_entity_type is null !!!");
|
|
|
|
var cloned = new BeaconShopItemAttribute(owner, entity_of_owner_entity_type);
|
|
|
|
cloned.deepCopyFromBase(this);
|
|
|
|
cloned.UserGuid = UserGuid;
|
|
cloned.BeaconGuid = BeaconGuid;
|
|
cloned.SellingFinishTime = SellingFinishTime;
|
|
cloned.PriceForUnit = PriceForUnit;
|
|
cloned.IsActiveSelling = IsActiveSelling;
|
|
|
|
cloned.ItemGuid = ItemGuid;
|
|
cloned.ItemMetaId = ItemMetaId;
|
|
cloned.ItemStackCount = ItemStackCount;
|
|
cloned.Level = Level;
|
|
cloned.Attributes = Attributes.Select(x => x).ToList();
|
|
cloned.EquipedInvenType = EquipedInvenType;
|
|
cloned.EquipedPos = EquipedPos;
|
|
|
|
return cloned;
|
|
}
|
|
|
|
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
|
{
|
|
var owner = getOwner() as ItemBase;
|
|
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
|
|
|
return new BeaconShopItemAttributeTransactor(owner);
|
|
}
|
|
|
|
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
//=====================================================================================
|
|
// Attribute => try pending Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = getTryPendingDocBase() as BeaconShopItemDoc;
|
|
if (null == try_pending_doc)
|
|
{
|
|
var to_copy_doc = new BeaconShopItemDoc(getOwnerEntityType(), BeaconGuid, UserGuid, ItemGuid);
|
|
|
|
var origin_doc = getOriginDocBase<BeaconShopItemAttribute>();
|
|
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<BeaconShopItemAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(to_copy_doc_attrib, () => $"to_copy_doc_attrib is null !!!");
|
|
|
|
to_copy_doc_attrib.BeaconGuid = BeaconGuid;
|
|
to_copy_doc_attrib.SellingFinishTime = SellingFinishTime;
|
|
to_copy_doc_attrib.PriceForUnit = PriceForUnit;
|
|
to_copy_doc_attrib.IsActiveSelling = IsActiveSelling;
|
|
|
|
to_copy_doc_attrib.ItemGuid = ItemGuid;
|
|
to_copy_doc_attrib.ItemMetaId = ItemMetaId;
|
|
to_copy_doc_attrib.ItemStackCount = ItemStackCount;
|
|
to_copy_doc_attrib.Level = Level;
|
|
to_copy_doc_attrib.Attributes = Attributes.Select(x => x).ToList();
|
|
to_copy_doc_attrib.EquipedInvenType = EquipedInvenType;
|
|
to_copy_doc_attrib.EquipedPos = EquipedPos;
|
|
|
|
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, to_query_doc);
|
|
}
|
|
|
|
return (result, to_query_doc);
|
|
}
|
|
|
|
public override bool copyEntityAttributeFromDoc(DynamoDbDocBase docBase)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var to_cast_string = typeof(BeaconShopItemDoc).Name;
|
|
|
|
var beacon_shop_doc_base = docBase as BeaconShopItemDoc;
|
|
if (null == beacon_shop_doc_base)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, beacon_shop_doc_base is null :{to_cast_string}";
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
//=====================================================================================
|
|
// New Doc => Origin Doc
|
|
//=====================================================================================
|
|
syncOriginDocBaseWithNewDoc<BeaconShopItemAttribute>(beacon_shop_doc_base);
|
|
|
|
//=====================================================================================
|
|
// Doc => Attribute
|
|
//=====================================================================================
|
|
var doc_attrib = beacon_shop_doc_base.getAttrib<BeaconShopItemAttrib>();
|
|
if (doc_attrib == null)
|
|
{
|
|
err_msg = $"Failed to get beacon_shop attrib : {nameof(BeaconShopItemAttrib)}";
|
|
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
return false;
|
|
}
|
|
|
|
UserGuid = doc_attrib.UserGuid;
|
|
BeaconGuid = doc_attrib.BeaconGuid;
|
|
SellingFinishTime = doc_attrib.SellingFinishTime;
|
|
PriceForUnit = doc_attrib.PriceForUnit;
|
|
IsActiveSelling = doc_attrib.IsActiveSelling;
|
|
|
|
ItemGuid = doc_attrib.ItemGuid;
|
|
ItemMetaId = doc_attrib.ItemMetaId;
|
|
ItemStackCount = doc_attrib.ItemStackCount;
|
|
Level = doc_attrib.Level;
|
|
Attributes = doc_attrib.Attributes.Select(x => x).ToList();
|
|
EquipedInvenType = doc_attrib.EquipedInvenType;
|
|
EquipedPos = doc_attrib.EquipedPos;
|
|
|
|
return true;
|
|
}
|
|
|
|
public new void onFillCommonResult( EntityCommonResult commonResult
|
|
, EntityAttributeBase origin, QueryBatchBase? queryBatch = null )
|
|
{
|
|
// commonResult 정보를 채우지 못하게 재정의 하여 그냥 반환 한다.
|
|
return;
|
|
}
|
|
|
|
public override 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 beacon_shop_attribute = otherEntityAttribute as BeaconShopItemAttribute;
|
|
if (null == beacon_shop_attribute)
|
|
{
|
|
err_msg = $"Failed to cast Attribute !!!, beacon_shop_attribute is null";
|
|
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
UserGuid = beacon_shop_attribute.UserGuid;
|
|
BeaconGuid = beacon_shop_attribute.BeaconGuid;
|
|
SellingFinishTime = beacon_shop_attribute.SellingFinishTime;
|
|
PriceForUnit = beacon_shop_attribute.PriceForUnit;
|
|
IsActiveSelling = beacon_shop_attribute.IsActiveSelling;
|
|
|
|
ItemGuid = beacon_shop_attribute.ItemGuid;
|
|
ItemMetaId = beacon_shop_attribute.ItemMetaId;
|
|
ItemStackCount = beacon_shop_attribute.ItemStackCount;
|
|
Level = beacon_shop_attribute.Level;
|
|
Attributes = beacon_shop_attribute.Attributes.Select(x => x).ToList();
|
|
EquipedInvenType = beacon_shop_attribute.EquipedInvenType;
|
|
EquipedPos = beacon_shop_attribute.EquipedPos;
|
|
|
|
//=====================================================================================
|
|
// Attribute Try Pending Doc => Origin Doc
|
|
//=====================================================================================
|
|
var try_pending_doc = beacon_shop_attribute.getTryPendingDocBase() as BeaconShopItemDoc;
|
|
if (null != try_pending_doc)
|
|
{
|
|
beacon_shop_attribute.resetTryPendingDocBase();
|
|
|
|
syncOriginDocBaseWithNewDoc<BeaconShopItemAttribute>(try_pending_doc);
|
|
}
|
|
|
|
var origin_doc_base = getOriginDocBase<BeaconShopItemAttribute>();
|
|
if (null == origin_doc_base)
|
|
{
|
|
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
|
return result;
|
|
}
|
|
|
|
var beacon_shop_attrib = origin_doc_base.getAttrib<BeaconShopItemAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(beacon_shop_attrib, () => $"beaconshop_attrib is null !!! - {owner.toBasicString()}");
|
|
|
|
beacon_shop_attrib.UserGuid = UserGuid;
|
|
beacon_shop_attrib.BeaconGuid = BeaconGuid;
|
|
beacon_shop_attrib.SellingFinishTime = SellingFinishTime;
|
|
beacon_shop_attrib.PriceForUnit = PriceForUnit;
|
|
beacon_shop_attrib.IsActiveSelling = IsActiveSelling;
|
|
|
|
beacon_shop_attrib.ItemGuid = ItemGuid;
|
|
beacon_shop_attrib.ItemMetaId = ItemMetaId;
|
|
beacon_shop_attrib.ItemStackCount = ItemStackCount;
|
|
beacon_shop_attrib.Level = Level;
|
|
beacon_shop_attrib.Attributes = Attributes.Select(x => x).ToList(); ;
|
|
beacon_shop_attrib.EquipedInvenType = EquipedInvenType;
|
|
beacon_shop_attrib.EquipedPos = EquipedPos;
|
|
|
|
return result;
|
|
}
|
|
|
|
public class BeaconShopItemAttributeTransactor : ItemAttributeBaseTransactor<BeaconShopItemAttribute>
|
|
{
|
|
public BeaconShopItemAttributeTransactor(ItemBase owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|