143 lines
6.1 KiB
C#
143 lines
6.1 KiB
C#
using Google.Protobuf.WellKnownTypes;
|
|
using ServerCommon;
|
|
using ServerCore; using ServerBase;
|
|
|
|
using BEACON_GUID = System.String;
|
|
using USER_GUID = System.String;
|
|
|
|
namespace GameServer
|
|
{
|
|
public class BeaconShopItem : Item
|
|
{
|
|
public BeaconShopItem(UgcNpc owner)
|
|
: base(owner)
|
|
{
|
|
}
|
|
|
|
public override async Task<Result> onInit()
|
|
{
|
|
var direct_parent = getDirectParent();
|
|
NullReferenceCheckHelper.throwIfNull(direct_parent, () => $"direct_parent is null !!!");
|
|
addEntityAttribute(new BeaconShopItemAttribute(this, direct_parent));
|
|
return await base.onInit();
|
|
}
|
|
|
|
public override string toBasicString()
|
|
{
|
|
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
|
|
}
|
|
|
|
public override string toSummaryString()
|
|
{
|
|
return $"{this.getTypeName()} - {getRootParent().toBasicString()}";
|
|
}
|
|
|
|
public static async Task<(Result, BeaconShopItem?)> createBeaconShopFromDoc(UgcNpc owner, BeaconShopItemDoc doc)
|
|
{
|
|
var beacon_shop_item = new BeaconShopItem(owner);
|
|
var result = await beacon_shop_item.onInit();
|
|
if (result.isFail())
|
|
{
|
|
return (result, null);
|
|
}
|
|
|
|
var err_msg = string.Empty;
|
|
|
|
var beacon_shop_attribute = beacon_shop_item.getEntityAttribute<BeaconShopItemAttribute>();
|
|
if (beacon_shop_attribute == null)
|
|
{
|
|
err_msg = $"Failed to get beacon shop attribute : {nameof(BeaconShopItemAttribute)}";
|
|
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
return (result, null);
|
|
}
|
|
|
|
if (beacon_shop_attribute.copyEntityAttributeFromDoc(doc) == false)
|
|
{
|
|
err_msg = $"Failed to copyEntityAttributeFromDoc !!! : doc_type {doc.GetType()} - {beacon_shop_item.getRootParent().toBasicString()}";
|
|
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
return (result, null);
|
|
}
|
|
|
|
return (result, beacon_shop_item);
|
|
}
|
|
|
|
public static async Task<(Result, BeaconShopItem?)> createBeaconShop(UgcNpc owner, USER_GUID user_guid, BEACON_GUID beacon_guid, DateTime selling_finish_time, double price_for_unit, ushort amount, ItemAttributeBase deleted_item_attribute)
|
|
{
|
|
var err_msg = string.Empty;
|
|
|
|
var beacon_shop_item = new BeaconShopItem(owner);
|
|
var result = await beacon_shop_item.onInit();
|
|
if (result.isFail())
|
|
{
|
|
err_msg = $"Failed to create onInit!!";
|
|
Log.getLogger().error(err_msg);
|
|
return (result, null);
|
|
}
|
|
|
|
var beacon_shop_attribute = beacon_shop_item.getEntityAttribute<BeaconShopItemAttribute>();
|
|
if (beacon_shop_attribute == null)
|
|
{
|
|
err_msg = $"Failed to get beacon shop attribute : {nameof(BeaconShopItemAttribute)}";
|
|
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
return (result, null);
|
|
}
|
|
|
|
beacon_shop_attribute.UserGuid = user_guid;
|
|
beacon_shop_attribute.BeaconGuid = beacon_guid;
|
|
beacon_shop_attribute.SellingFinishTime = selling_finish_time;
|
|
beacon_shop_attribute.PriceForUnit = price_for_unit;
|
|
beacon_shop_attribute.IsActiveSelling = true;
|
|
|
|
beacon_shop_attribute.ItemMetaId = deleted_item_attribute.ItemMetaId;
|
|
beacon_shop_attribute.ItemStackCount = amount;
|
|
beacon_shop_attribute.Level = deleted_item_attribute.Level;
|
|
beacon_shop_attribute.Attributes = deleted_item_attribute.Attributes.Select(x => x).ToList();
|
|
beacon_shop_attribute.EquipedInvenType = deleted_item_attribute.EquipedInvenType;
|
|
beacon_shop_attribute.EquipedPos = deleted_item_attribute.EquipedPos;
|
|
|
|
beacon_shop_attribute.newEntityAttribute();
|
|
|
|
return (result, beacon_shop_item);
|
|
}
|
|
|
|
public override MetaAssets.ItemMetaData? getItemMeta()
|
|
{
|
|
var parent = getRootParent();
|
|
NullReferenceCheckHelper.throwIfNull(parent, () => $"parent is null !!!");
|
|
|
|
var beacon_shop_item_attribute = getEntityAttribute<BeaconShopItemAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(beacon_shop_item_attribute, () => $"beacon_shop_item_attribute is null !!! - {parent.toBasicString()}");
|
|
|
|
if (!MetaData.Instance._ItemTable.TryGetValue((int)beacon_shop_item_attribute.ItemMetaId, out var found_item_meta_data))
|
|
{
|
|
var err_msg = $"Not found meta of Item !!! : itemMetaId:{beacon_shop_item_attribute.ItemMetaId} - {parent.toBasicString()}";
|
|
Log.getLogger().error(err_msg);
|
|
return null;
|
|
}
|
|
|
|
return found_item_meta_data;
|
|
}
|
|
|
|
public BeaconShopInfo toBeaconShopData4Client()
|
|
{
|
|
var beacon_shop_4_client = new BeaconShopInfo();
|
|
|
|
var beacon_shop_attribute = getEntityAttribute<BeaconShopItemAttribute>();
|
|
NullReferenceCheckHelper.throwIfNull(beacon_shop_attribute, () => $"beacon_shop_attribute is null !!!");
|
|
|
|
beacon_shop_4_client.BeaconGuid = beacon_shop_attribute.BeaconGuid;
|
|
beacon_shop_4_client.ItemGuid = beacon_shop_attribute.ItemGuid;
|
|
beacon_shop_4_client.ItemMetaid = (int)beacon_shop_attribute.ItemMetaId;
|
|
beacon_shop_4_client.SellingFinishTime = Timestamp.FromDateTime(beacon_shop_attribute.SellingFinishTime);
|
|
beacon_shop_4_client.PriceForUnit = beacon_shop_attribute.PriceForUnit;
|
|
beacon_shop_4_client.IsActiveSelling = beacon_shop_attribute.IsActiveSelling == true ? BoolType.True : BoolType.False;
|
|
beacon_shop_4_client.Amount = beacon_shop_attribute.ItemStackCount;
|
|
|
|
return beacon_shop_4_client;
|
|
}
|
|
}
|
|
}
|