Files
2025-05-01 07:20:41 +09:00

267 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pipelines.Sockets.Unofficial.Buffers;
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 = 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 abstract partial class SlotsWrapperBase<TSlots> : EntityBase
where TSlots : ISlots, new()
{
private readonly TSlots m_slots;
public SlotsWrapperBase(EntityType entityType, EntityBase parent)
: base(entityType, parent)
{
m_slots = new TSlots();
}
public virtual bool onInitSlots(int slotMaxCount)
{
return m_slots.onInitSlots(slotMaxCount);
}
public Result tryIsEquipableOrEquip<TSlotType>(TSlotType targetSlotType)
where TSlotType : Enum
{
var result = new Result();
var err_msg = string.Empty;
var direct_parent = getDirectParent();
ArgumentNullException.ThrowIfNull(direct_parent, $"direct_parent is null !!!");
var slots = getData() as ISlotsWithType<TSlotType>;
ArgumentNullException.ThrowIfNull(slots, $"slots is null !!! - {direct_parent.toBasicString()}");
var parent = getRootParent();
if (null != parent)
{
// Transaction 활성화 상태일 경우
var transaction_runner = parent.findTransactionRunner(TransactionIdType.PrivateContents);
if (null != transaction_runner)
{
var slot_type = targetSlotType.ToString();
var to_check_slot_type = slot_type;
if (true == EnumHelper.isEnumType(to_check_slot_type))
{
slot_type = to_check_slot_type.convertEnumToEnumTypeAndValueString();
}
// 장착 슬롯에 슬롯과 EntityBase를 장착 해제 예약 한다.
result = transaction_runner.tryEquipToReserveSlot(direct_parent, getEntityType(), slot_type);
if (result.isFail())
{
return result;
}
err_msg = $"Succss tryEquipToReserveSlot() : targetSlotType:{slot_type} - {toBasicString()}, {parent.toBasicString()}";
Log.getLogger().info(err_msg);
return result;
}
}
var error_code = slots.onTryEquip(targetSlotType);
if (error_code.isFail())
{
err_msg = $"Failed to onTryEquip() !!! : targetSlotType:{targetSlotType} - {toBasicString()}, {parent?.toBasicString()}";
result.setFail(error_code, err_msg);
return result;
}
return result;
}
public Result tryIsEquipableOrEquipWithEntityBase<TSlotType>(TSlotType targetSlotType, EntityBase entityBase)
where TSlotType : notnull
{
var result = new Result();
var err_msg = string.Empty;
var direct_parent = getDirectParent();
ArgumentNullException.ThrowIfNull(direct_parent, $"direct_parent is null !!!");
var slots = getData() as ISlotsWithType<TSlotType>;
ArgumentNullException.ThrowIfNull(slots, $"slots is null !!! - {direct_parent.toBasicString()}");
var parent = getRootParent();
if (null != parent)
{
// Transaction 활성화 상태일 경우
var transaction_runner = parent.findTransactionRunner(TransactionIdType.PrivateContents);
if (null != transaction_runner)
{
var slot_type = targetSlotType.ToString();
NullReferenceCheckHelper.throwIfNull(slot_type, () => $"slot_type is null !!!");
var to_check_slot_type = slot_type;
NullReferenceCheckHelper.throwIfNull(to_check_slot_type, () => $"to_check_slot_type is null !!!");
if (true == EnumHelper.isEnumType(to_check_slot_type))
{
slot_type = to_check_slot_type.convertEnumToEnumTypeAndValueString();
}
// 장착 슬롯에 슬롯과 EntityBase를 장착 예약 한다.
result = transaction_runner.tryEquipToReserveSlotWithEntityBase(direct_parent, getEntityType(), slot_type, entityBase);
if (result.isFail())
{
return result;
}
err_msg = $"Succss tryEquipToReserveSlotWithEntityBase() : targetSlotType:{slot_type} - {toBasicString()}, {parent.toBasicString()}";
Log.getLogger().info(err_msg);
return result;
}
}
var error_code = slots.onTryEquipWithEntityBase(targetSlotType, entityBase);
if (error_code.isFail())
{
err_msg = $"Failed to onTryEquipWithEntityBase() !!! : {error_code.toBasicString()}, targetSlotType:{targetSlotType}, {entityBase.toBasicString()} - {toBasicString()}, {parent?.toBasicString()}";
result.setFail(error_code, err_msg);
return result;
}
return result;
}
public Result tryUnequipableOrUnequip<TSlotType>(TSlotType targetSlotType)
where TSlotType : Enum
{
var result = new Result();
var err_msg = string.Empty;
var direct_parent = getDirectParent();
ArgumentNullException.ThrowIfNull(direct_parent, $"direct_parent is null !!!");
var slots = getData() as ISlotsWithType<TSlotType>;
ArgumentNullException.ThrowIfNull(slots, $"slots is null !!! - {direct_parent.toBasicString()}");
var parent = getRootParent();
if (null != parent)
{
// Transaction 활성화 상태일 경우
var transaction_runner = parent.findTransactionRunner(TransactionIdType.PrivateContents);
if (null != transaction_runner)
{
var slot_type = targetSlotType.ToString();
var to_check_slot_type = slot_type;
if (true == EnumHelper.isEnumType(to_check_slot_type))
{
slot_type = to_check_slot_type.convertEnumToEnumTypeAndValueString();
}
// 장착 슬롯에 슬롯과 EntityBase를 장착 해제 예약 한다.
result = transaction_runner.tryUnequipToReserveSlot(direct_parent, getEntityType(), slot_type);
if (result.isFail())
{
return result;
}
err_msg = $"Success tryUnequipToReserveSlot() : targetSlotType:{slot_type} - {toBasicString()}, {parent.toBasicString()}";
Log.getLogger().info(err_msg);
return result;
}
}
var error_code = slots.onTryUnequip(targetSlotType);
if (error_code.isFail())
{
err_msg = $"Failed to onTryUnequip() !!! : targetSlotType:{targetSlotType} - {toBasicString()}, {parent?.toBasicString()}";
result.setFail(error_code, err_msg);
return result;
}
return result;
}
public Result tryUnequipableOrUnequipWithEntityBase<TSlotType>(TSlotType targetSlotType, out EntityBase? unequipedEntityBase)
where TSlotType : notnull
{
unequipedEntityBase = null;
var result = new Result();
var err_msg = string.Empty;
var direct_parent = getDirectParent();
ArgumentNullException.ThrowIfNull(direct_parent, $"direct_parent is null !!!");
var slots = getData() as ISlotsWithType<TSlotType>;
ArgumentNullException.ThrowIfNull(slots, $"slots is null !!! - {direct_parent.toBasicString()}");
var parent = getRootParent();
if (null != parent)
{
// Transaction 활성화 상태일 경우
var transaction_runner = parent.findTransactionRunner(TransactionIdType.PrivateContents);
if (null != transaction_runner)
{
var slot_type = targetSlotType.ToString();
NullReferenceCheckHelper.throwIfNull(slot_type, () => $"slot_type is null !!!");
var to_check_slot_type = slot_type;
NullReferenceCheckHelper.throwIfNull(to_check_slot_type, () => $"to_check_slot_type is null !!!");
if (true == EnumHelper.isEnumType(to_check_slot_type))
{
slot_type = to_check_slot_type.convertEnumToEnumTypeAndValueString();
}
// 장착 슬롯에 슬롯과 EntityBase를 장착 해제 예약 한다.
result = transaction_runner.tryUnequipToReserveSlotWithEntityBase(direct_parent, getEntityType(), slot_type, slots.onFindEntityBase(targetSlotType));
if (result.isFail())
{
return result;
}
err_msg = $"Success tryUnequipToReserveSlotWithEntityBase() : targetSlotType:{slot_type} - {toBasicString()}, {parent.toBasicString()}";
Log.getLogger().info(err_msg);
return result;
}
}
var error_code = slots.onTryUnequipWithEntityBase(targetSlotType, out var unequiped_entity_base);
if (error_code.isFail())
{
err_msg = $"Failed to onTryUnequipWithEntityBase() !!! : {error_code.toBasicString()}, targetSlotType:{targetSlotType} - {toBasicString()}, {parent?.toBasicString()}";
result.setFail(error_code, err_msg);
return result;
}
unequipedEntityBase = unequiped_entity_base;
return result;
}
public virtual void onWriteLog()
{
return;
}
public TSlots getData() => m_slots;
public override string toBasicString()
{
return $"{this.getTypeName()}, {m_slots.toBasicString()}";
}
}
}