85 lines
3.9 KiB
C#
85 lines
3.9 KiB
C#
using Amazon.S3.Model;
|
|
using ServerControlCenter;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using ServerCore; using ServerBase;
|
|
|
|
|
|
|
|
namespace ServerCommon.BusinessLogDomain
|
|
{
|
|
public static class ItemBusinessLogHelper
|
|
{
|
|
public static (Result, ItemLogInfo?) toItemLogInfo( this ItemAttributeBase itemAttributeBase )
|
|
{
|
|
var try_pending_item_doc = itemAttributeBase.getTryPendingDocBase() as ItemDoc;
|
|
NullReferenceCheckHelper.throwIfNull(try_pending_item_doc, () => $"try_pending_item_doc is null !!!");
|
|
var item_attrib = try_pending_item_doc.getAttrib<ItemAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(item_attrib, () => $"item_attrib is null !!! : {itemAttributeBase.toBasicString()}");
|
|
|
|
var result = new Result();
|
|
|
|
var item_meta_id = (int)itemAttributeBase.ItemMetaId;
|
|
if (false == MetaData.Instance._ItemTable.TryGetValue(item_meta_id, out var found_item_meta_data))
|
|
{
|
|
var err_msg = $"Failed to TryGetValue() !!! : itemMetaId:{item_meta_id} - {itemAttributeBase.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemMetaDataNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return (result, null);
|
|
}
|
|
|
|
var log_item_info = new ItemLogInfo();
|
|
log_item_info.setLogProperty( item_attrib.ItemGuid
|
|
, try_pending_item_doc.getPK(), try_pending_item_doc.getSK()
|
|
, item_attrib.OwnerEntityType, item_attrib.OwnerGuid
|
|
, CountDeltaType.None, item_attrib.ItemStackCount, 0
|
|
, item_attrib.ItemMetaId, found_item_meta_data.Name
|
|
, item_attrib.Level, 0
|
|
, found_item_meta_data.TypeLarge, found_item_meta_data.TypeSmall
|
|
, itemAttributeBase.Attributes.Select(x => (int)x).ToList(), new List<int>() );
|
|
|
|
return (result, log_item_info);
|
|
}
|
|
|
|
public static async Task<(Result, ItemLogInfo?)> toItemLogInfo4Create( this ItemDoc itemDoc )
|
|
{
|
|
var result = new Result();
|
|
|
|
var item_attrib = itemDoc.getAttrib<ItemAttrib>();
|
|
NullReferenceCheckHelper.throwIfNull(item_attrib, () => $"item_attrib is null !!!");
|
|
|
|
var item_meta_id = (int)item_attrib.ItemMetaId;
|
|
if (false == MetaData.Instance._ItemTable.TryGetValue(item_meta_id, out var found_item_meta_data))
|
|
{
|
|
var err_msg = $"Failed to TryGetValue() !!! : itemMetaId:{item_meta_id} - {item_attrib.toBasicString()}";
|
|
result.setFail(ServerErrorCode.ItemMetaDataNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return (result, null);
|
|
}
|
|
|
|
var delta_stack_count = item_attrib.ItemStackCount;
|
|
var delta_level = item_attrib.Level;
|
|
|
|
var log_item_info = new ItemLogInfo();
|
|
log_item_info.setLogProperty( item_attrib.ItemGuid
|
|
, itemDoc.getPK(), itemDoc.getSK()
|
|
, item_attrib.OwnerEntityType, item_attrib.OwnerGuid
|
|
, CountDeltaType.Acquire, item_attrib.ItemStackCount, delta_stack_count
|
|
, item_attrib.ItemMetaId, found_item_meta_data.Name
|
|
, item_attrib.Level, delta_level
|
|
, found_item_meta_data.TypeLarge, found_item_meta_data.TypeSmall
|
|
, item_attrib.Attributes.Select(x => (int)x).ToList(), new List<int>() );
|
|
|
|
return await Task.FromResult((result, log_item_info));
|
|
}
|
|
}
|
|
}
|