초기커밋
This commit is contained in:
405
ServerCommon/Entity/Attribute/SeasonPassAttribute.cs
Normal file
405
ServerCommon/Entity/Attribute/SeasonPassAttribute.cs
Normal file
@@ -0,0 +1,405 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
|
||||
|
||||
using USER_GUID = System.String;
|
||||
using META_ID = System.UInt32;
|
||||
using Amazon.S3.Model;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
|
||||
|
||||
|
||||
namespace ServerCommon;
|
||||
|
||||
public class SeasonPassAttribute : EntityAttributeBase, ICopyEntityAttributeFromDoc, IMergeWithEntityAttribute, IWithCommonResultFiller
|
||||
{
|
||||
[JsonProperty]
|
||||
public META_ID SeasonPassMetaId { get; set; } = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public UInt32 Exp
|
||||
{
|
||||
get { return m_exp; }
|
||||
set
|
||||
{
|
||||
var recorder = getEntityRecorder();
|
||||
if (null != recorder)
|
||||
{
|
||||
recorder.applyDeltaCounter(EntityDeltaType.SeasonPassExp, (value - m_exp), value);
|
||||
}
|
||||
m_exp = value;
|
||||
}
|
||||
}
|
||||
private UInt32 m_exp = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public Int32 Grade
|
||||
{
|
||||
get { return m_grade; }
|
||||
set
|
||||
{
|
||||
var recorder = getEntityRecorder();
|
||||
if (null != recorder)
|
||||
{
|
||||
recorder.applyDeltaCounter(EntityDeltaType.SeasonPassGrade, (value - m_grade), value);
|
||||
}
|
||||
m_grade = value;
|
||||
}
|
||||
}
|
||||
private Int32 m_grade = 0;
|
||||
|
||||
[JsonProperty]
|
||||
public List<Int32> takenRewards { get; set; } = new();
|
||||
|
||||
[JsonProperty]
|
||||
public bool IsChargedPass { get; set; } = false;
|
||||
|
||||
|
||||
public SeasonPassAttribute(EntityBase owner)
|
||||
: base(owner, true)
|
||||
{
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
SeasonPassMetaId = 0;
|
||||
Exp = 0;
|
||||
Grade = 0;
|
||||
takenRewards.Clear();
|
||||
IsChargedPass = false;
|
||||
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var owner = getOwner() as UserBase;
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var cloned = new SeasonPassAttribute(owner);
|
||||
|
||||
cloned.SeasonPassMetaId = SeasonPassMetaId;
|
||||
cloned.Exp = Exp;
|
||||
cloned.Grade = Grade;
|
||||
cloned.IsChargedPass = IsChargedPass;
|
||||
cloned.takenRewards = takenRewards.Select(x => x).ToList();
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
var owner = getOwner() as UserBase;
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
return new SeasonPassAttributeTransactor(owner);
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var acoount_attribute = owner.getEntityAttribute<AccountAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(acoount_attribute, () => $"acoount_attribute is null !!!");
|
||||
|
||||
USER_GUID user_guid = acoount_attribute.UserGuid;
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute => try pending Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = getTryPendingDocBase() as SeasonPassDoc;
|
||||
if (null == try_pending_doc)
|
||||
{
|
||||
var to_copy_doc = new SeasonPassDoc(user_guid);
|
||||
|
||||
var origin_doc = getOriginDocBase<SeasonPassAttribute>();
|
||||
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<SeasonPassAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(to_copy_doc_attrib, () => $"to_copy_doc_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
to_copy_doc_attrib.SeasonPassMetaId = SeasonPassMetaId;
|
||||
to_copy_doc_attrib.Exp = Exp;
|
||||
to_copy_doc_attrib.Grade = Grade;
|
||||
to_copy_doc_attrib.IsChargedPass = IsChargedPass;
|
||||
to_copy_doc_attrib.takenRewards = takenRewards.Select(x => x).ToList();
|
||||
|
||||
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 bool copyEntityAttributeFromDoc(DynamoDbDocBase docBase)
|
||||
{
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(SeasonPassDoc).Name;
|
||||
|
||||
var season_pass_doc_base = docBase as SeasonPassDoc;
|
||||
if (null == season_pass_doc_base)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDoc() !!!, season_pass_doc_base is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// New Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
syncOriginDocBaseWithNewDoc<SeasonPassAttribute>(season_pass_doc_base);
|
||||
|
||||
//=====================================================================================
|
||||
// Doc => Attribute
|
||||
//=====================================================================================
|
||||
var doc_attrib = season_pass_doc_base.getAttrib<SeasonPassAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(doc_attrib, () => $"doc_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
SeasonPassMetaId = doc_attrib.SeasonPassMetaId;
|
||||
Exp = doc_attrib.Exp;
|
||||
Grade = doc_attrib.Grade;
|
||||
IsChargedPass = doc_attrib.IsChargedPass;
|
||||
takenRewards = doc_attrib.takenRewards.Select(x => x).ToList();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onFillCommonResult(EntityCommonResult commonResult, EntityAttributeBase origin, QueryBatchBase? queryBatch = null)
|
||||
{
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var before = origin as SeasonPassAttribute;
|
||||
NullReferenceCheckHelper.throwIfNull(before, () => $"before is null !!! - {owner.toBasicString()}");
|
||||
var after = this as SeasonPassAttribute;
|
||||
NullReferenceCheckHelper.throwIfNull(after, () => $"after is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var recorder = after.getEntityRecorder();
|
||||
NullReferenceCheckHelper.throwIfNull(recorder, () => $"recorder is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var exp_result = commonResult.Exp;
|
||||
NullReferenceCheckHelper.throwIfNull(exp_result, () => $"exp_result is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var season_pass_meta_id = after.SeasonPassMetaId;
|
||||
|
||||
var target_types = EnumHelper.getValuesBeginEndBetweenWord<EntityDeltaType>("SeasonPass_");
|
||||
foreach (var type in target_types)
|
||||
{
|
||||
var found_delta_counter = recorder.findDeltaCounter(type);
|
||||
if (null != found_delta_counter)
|
||||
{
|
||||
var delta_value = (Int32)found_delta_counter.getDeltaCount();
|
||||
|
||||
var level_exp_type = (Int32)LevelExpType.SeasonPass;
|
||||
if (false == exp_result.LevelExps.TryGetValue(level_exp_type, out var found_level_by_id))
|
||||
{
|
||||
found_level_by_id = new LevelExpById();
|
||||
exp_result.LevelExps.Add(level_exp_type, found_level_by_id);
|
||||
}
|
||||
if (false == found_level_by_id.LevelExpsByMetaId.TryGetValue(season_pass_meta_id, out var found_level))
|
||||
{
|
||||
found_level = new LevelExp();
|
||||
found_level_by_id.LevelExpsByMetaId.Add(season_pass_meta_id, found_level);
|
||||
}
|
||||
|
||||
if (false == exp_result.LevelExpDeltas.TryGetValue(level_exp_type, out var found_exp_delta_amount_by_meta_id))
|
||||
{
|
||||
found_exp_delta_amount_by_meta_id = new LevelExpDeltaAmountById();
|
||||
exp_result.LevelExpDeltas.Add(level_exp_type, found_exp_delta_amount_by_meta_id);
|
||||
}
|
||||
if (false == found_exp_delta_amount_by_meta_id.DeltasByMetaId.TryGetValue(season_pass_meta_id, out var found_exp_delta_amount))
|
||||
{
|
||||
found_exp_delta_amount = new LevelExpDeltaAmount();
|
||||
found_exp_delta_amount_by_meta_id.DeltasByMetaId.Add(season_pass_meta_id, found_exp_delta_amount);
|
||||
}
|
||||
|
||||
if (EntityDeltaType.SeasonPassGrade == type)
|
||||
{
|
||||
found_level.Level = after.Grade;
|
||||
found_exp_delta_amount.LevelAmount = delta_value;
|
||||
appendOrWriteBusinessLog4SeasonPass(type, delta_value, (UInt32)after.Grade, queryBatch);
|
||||
}
|
||||
else if (EntityDeltaType.SeasonPassExp == type)
|
||||
{
|
||||
found_level.ExpInTotal = after.Exp;
|
||||
found_exp_delta_amount.ExpDeltaType = AmountDeltaType.Merge;
|
||||
found_exp_delta_amount.ExpAmount = delta_value;
|
||||
appendOrWriteBusinessLog4SeasonPass(type, delta_value, after.Exp, queryBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void appendOrWriteBusinessLog4SeasonPass( EntityDeltaType entityDeltaType, int deltaCount, UInt32 amount
|
||||
, QueryBatchBase? queryBatch = null )
|
||||
{
|
||||
var owner = getOwner();
|
||||
|
||||
var season_pass_log_data = new SeasonPassLogData();
|
||||
switch (entityDeltaType)
|
||||
{
|
||||
case EntityDeltaType.SeasonPassGrade:
|
||||
season_pass_log_data.Grade = (int)amount;
|
||||
season_pass_log_data.DeltaGrade = deltaCount;
|
||||
break;
|
||||
case EntityDeltaType.SeasonPassExp:
|
||||
season_pass_log_data.Exp = amount;
|
||||
season_pass_log_data.DeltaExp = deltaCount;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
var season_pass_business_log = new SeasonPassBusinessLog(season_pass_log_data);
|
||||
|
||||
if (null != queryBatch)
|
||||
{
|
||||
queryBatch.appendBusinessLog(season_pass_business_log);
|
||||
}
|
||||
else
|
||||
{
|
||||
var log_actor = owner as IWithLogActor;
|
||||
NullReferenceCheckHelper.throwIfNull(log_actor, () => $"log_actor is null !!! - {owner.toBasicString()}");
|
||||
|
||||
BusinessLogger.collectLog(log_actor, season_pass_business_log);
|
||||
}
|
||||
}
|
||||
|
||||
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 season_pass_attribute = otherEntityAttribute as SeasonPassAttribute;
|
||||
if (null == season_pass_attribute)
|
||||
{
|
||||
err_msg = $"Failed to cast SeasonPassAttribute !!!, season_pass_attribute is null";
|
||||
result.setFail(ServerErrorCode.ClassTypeCastIsNull, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
SeasonPassMetaId = season_pass_attribute.SeasonPassMetaId;
|
||||
Exp = season_pass_attribute.Exp;
|
||||
Grade = season_pass_attribute.Grade;
|
||||
IsChargedPass = season_pass_attribute.IsChargedPass;
|
||||
takenRewards = season_pass_attribute.takenRewards.Select(x => x).ToList();
|
||||
|
||||
//=====================================================================================
|
||||
// Attribute Try Pending Doc => Origin Doc
|
||||
//=====================================================================================
|
||||
var try_pending_doc = season_pass_attribute.getTryPendingDocBase() as SeasonPassDoc;
|
||||
if (null != try_pending_doc)
|
||||
{
|
||||
season_pass_attribute.resetTryPendingDocBase();
|
||||
|
||||
syncOriginDocBaseWithNewDoc<SeasonPassAttribute>(try_pending_doc);
|
||||
}
|
||||
|
||||
var origin_doc_base = getOriginDocBase<SeasonPassAttribute>();
|
||||
if (null == origin_doc_base)
|
||||
{
|
||||
// DB 에 저장되어 있지 않는 경우 OriginDoc은 null 이다 !!!
|
||||
return result;
|
||||
}
|
||||
|
||||
var season_pass_attrib = origin_doc_base.getAttrib<SeasonPassAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(season_pass_attrib, () => $"season_pass_attrib is null !!! - {owner.toBasicString()}");
|
||||
|
||||
season_pass_attrib.SeasonPassMetaId = SeasonPassMetaId;
|
||||
season_pass_attrib.Exp = Exp;
|
||||
season_pass_attrib.Grade = Grade;
|
||||
season_pass_attrib.IsChargedPass = IsChargedPass;
|
||||
season_pass_attrib.takenRewards = takenRewards.Select(x => x).ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class SeasonPassAttributeTransactor : EntityAttributeTransactorBase<SeasonPassAttribute>, ICopyEntityAttributeTransactorFromEntityAttribute
|
||||
{
|
||||
public SeasonPassAttributeTransactor(UserBase owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttributeBase)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = typeof(SeasonPassAttribute).Name;
|
||||
|
||||
var copy_from_season_pass_attribute = entityAttributeBase as SeasonPassAttribute;
|
||||
if (null == copy_from_season_pass_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_from_season_pass_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
var copy_to_season_pass_attribute = getClonedEntityAttribute() as SeasonPassAttribute;
|
||||
if (null == copy_to_season_pass_attribute)
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeTransactorFromEntityAttribute() !!!, copy_to_season_pass_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_to_season_pass_attribute.SeasonPassMetaId = copy_from_season_pass_attribute.SeasonPassMetaId;
|
||||
copy_to_season_pass_attribute.Exp = copy_from_season_pass_attribute.Exp;
|
||||
copy_to_season_pass_attribute.Grade = copy_from_season_pass_attribute.Grade;
|
||||
copy_to_season_pass_attribute.IsChargedPass = copy_from_season_pass_attribute.IsChargedPass;
|
||||
copy_to_season_pass_attribute.takenRewards = copy_from_season_pass_attribute.takenRewards.Select(x => x).ToList();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user