초기커밋
This commit is contained in:
424
GameServer/Contents/Shop/Action/PurchaseShopProductAction.cs
Normal file
424
GameServer/Contents/Shop/Action/PurchaseShopProductAction.cs
Normal file
@@ -0,0 +1,424 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using META_ID = System.UInt32;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class PurchaseShopProductAction : EntityActionBase
|
||||
{
|
||||
public PurchaseShopProductAction(MyShopProduct owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var result = new Result();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public (DiscountType discount_type, int discount_rate) checkPurchaseDiscountType(int productId)
|
||||
{
|
||||
var discount_type = DiscountType.None;
|
||||
int discount_rate = 0;
|
||||
|
||||
var player = getOwner().getRootParent() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
|
||||
var item_first_purchase_history_agent_action = player.getEntityAction<ItemFirstPurchaseHistoryAgentAction>();
|
||||
ArgumentNullException.ThrowIfNull(item_first_purchase_history_agent_action);
|
||||
|
||||
if (!MetaData.Instance._ShopProductMetaTable.TryGetValue(productId, out var shop_product_meta_data))
|
||||
return (discount_type, discount_rate);
|
||||
|
||||
if (null != shop_product_meta_data.ProductData.Item)
|
||||
{
|
||||
if (!MetaData.Instance._ItemTable.TryGetValue(shop_product_meta_data.ProductData.Item.Id, out var item_meta_data))
|
||||
return (discount_type, discount_rate);
|
||||
|
||||
if (item_first_purchase_history_agent_action.isItemFirstPurchase(item_meta_data.ItemId))
|
||||
{
|
||||
discount_type = DiscountType.ItemFirstPurchase;
|
||||
discount_rate = item_meta_data.Buy_Discount_Rate;
|
||||
}
|
||||
}
|
||||
|
||||
return (discount_type, discount_rate);
|
||||
}
|
||||
|
||||
public (Result result, MetaAssets.ShopProductMetaData? product_data) checkPurchaseShopProductConditions(int shop_id, int product_id, int purchase_count)
|
||||
{
|
||||
var result = new Result();
|
||||
string err_msg;
|
||||
|
||||
// 1. shop_id 체크
|
||||
var check_shop_id = ShopHelper.checkShopIdFromTableData(shop_id);
|
||||
if (check_shop_id.result.isFail())
|
||||
{
|
||||
err_msg = $"Fail to get shop data : shop id - {shop_id}";
|
||||
result.setFail(ServerErrorCode.NotFoundShopId, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
// 2. product_id 체크
|
||||
var check_product_id = ShopHelper.checkProductIdFromTableData(product_id);
|
||||
if (check_product_id.result.isFail())
|
||||
{
|
||||
err_msg = $"Fail to get product data : product id - {product_id}";
|
||||
result.setFail(ServerErrorCode.NotFoundProductId, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
// 3. 구매 시간 체크
|
||||
var shop_meter_attribute = getOwner().getEntityAttribute<ShopProductTradingMeterAttribute>();
|
||||
if (null == shop_meter_attribute)
|
||||
{
|
||||
err_msg = $"Fail to get ShopProductTradingMeter Attribute : {nameof(ShopProductTradingMeterAttribute)}.";
|
||||
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
if (shop_meter_attribute.EndTime < DateTime.UtcNow.ToTimestamp())
|
||||
{
|
||||
err_msg = $"Fail to buy Shop Item : Shop EndTime - {shop_meter_attribute.EndTime}";
|
||||
result.setFail(ServerErrorCode.NotFoundShopId, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
// 4. 구매 가능 수량 체크
|
||||
var shop_meter_sub_attribute = getShopTradingMeterSubAttribute(product_id);
|
||||
if (null == shop_meter_sub_attribute)
|
||||
{
|
||||
err_msg = $"Fail to get shop product info : {nameof(ShopProductTradingMeterSubAttribute)}";
|
||||
result.setFail(ServerErrorCode.EntityAttributeNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
if (shop_meter_sub_attribute.LeftCount < purchase_count || purchase_count <= 0)
|
||||
{
|
||||
err_msg = $"Fail to check purchased product count : left count - {shop_meter_sub_attribute.LeftCount} / purchase count - {purchase_count}";
|
||||
result.setFail(ServerErrorCode.InvalidItemCount, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
// 5. 첫 구매 아이템이 1개가 아닌경우 체크
|
||||
NullReferenceCheckHelper.throwIfNull(check_product_id.product_data, () => $"check_product_id.product_data is null !!!");
|
||||
if (check_product_id.product_data.ProductData.Item != null)
|
||||
{
|
||||
var player = getOwner().getRootParent() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
|
||||
result = player.checkItemFirstPurchaseItemCount(check_product_id.product_data.ProductData.Item.Id, purchase_count);
|
||||
if (result.isFail())
|
||||
{
|
||||
return (result, null);
|
||||
}
|
||||
}
|
||||
|
||||
return (result, check_product_id.product_data);
|
||||
}
|
||||
|
||||
public Result checkPurchaseCharacterConditions(MetaAssets.ShopProductMetaData? product_data)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
if (null == product_data)
|
||||
{
|
||||
var err_msg = $"Fail to get product data";
|
||||
result.setFail(ServerErrorCode.NotFoundProductId, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 1. 속성 조건 체크
|
||||
result = checkAbilityCondition(product_data.Attribute_Key, product_data.Attribute_Value);
|
||||
if (result.isFail()) return result;
|
||||
|
||||
// 2. 성별 조건 체크
|
||||
result = checkGenderCondition(product_data.Gender);
|
||||
if (result.isFail()) return result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Result checkAbilityCondition(string attribute_key, int attribute_value)
|
||||
{
|
||||
var result = new Result();
|
||||
string err_msg;
|
||||
|
||||
if (string.IsNullOrEmpty(attribute_key) || attribute_key == "None")
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var ability_action = getOwner().getRootParent().getEntityAction<AbilityAction>();
|
||||
ArgumentNullException.ThrowIfNull(ability_action);
|
||||
|
||||
if (false == EnumHelper.tryParse<AttributeType>(attribute_key, out var attribute_type))
|
||||
{
|
||||
err_msg =
|
||||
$"Fail to check AbilityCondition!!! : invalid attribute_key - attribute_key[{attribute_key}]";
|
||||
result.setFail(ServerErrorCode.NotEnoughAttribute, err_msg);
|
||||
Log.getLogger().info(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
var ability = ability_action.getAbility(attribute_type) ?? 0;
|
||||
if (attribute_value > ability)
|
||||
{
|
||||
err_msg =
|
||||
$"Fail to check AbilityCondition!!! : attribute_value - {attribute_value} / ability - {ability}";
|
||||
result.setFail(ServerErrorCode.NotEnoughAttribute, err_msg);
|
||||
Log.getLogger().info(err_msg);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Result checkGenderCondition(MetaAssets.EGenderType gender)
|
||||
{
|
||||
var result = new Result();
|
||||
string err_msg;
|
||||
|
||||
var player = getOwner().getRootParent() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
var action = player?.getEntityAction<PlayerAction>();
|
||||
if (null == action)
|
||||
{
|
||||
err_msg =
|
||||
$"Fail to check Gender Condition !!! : {nameof(PlayerAction)} is null";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().info(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
var select_character = action.getSelectedCharacter();
|
||||
ArgumentNullException.ThrowIfNull(select_character);
|
||||
|
||||
var own_appearance_profile = select_character.getOriginAppearanceProfile();
|
||||
var check_gender = ShopHelper.checkBasicStyleDataFromTableData(own_appearance_profile.BasicStyle);
|
||||
if (check_gender.result.isFail()) return check_gender.result;
|
||||
|
||||
if (MetaAssets.EGenderType.ALL != gender && gender != check_gender.basic_style_data!.Gender)
|
||||
{
|
||||
err_msg = $"Invalid Gender. user Gender : {gender}, need Gender : {check_gender.basic_style_data.Gender}";
|
||||
result.setFail(ServerErrorCode.InvalidGender, err_msg);
|
||||
Log.getLogger().info(err_msg);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Result> processPurchase(MetaAssets.ShopProductMetaData product_data, int purchase_count, int discountRate, ShopPurchaseInfo shopPurchaseInfo)
|
||||
{
|
||||
var result = new Result();
|
||||
if (product_data.ProductData.Item != null)
|
||||
{
|
||||
var process_for_item = await processForItem(product_data, product_data.ProductData.Item.Id, purchase_count, discountRate);
|
||||
if (process_for_item.result.isFail()) return process_for_item.result;
|
||||
|
||||
shopPurchaseInfo.m_spent = process_for_item.spent_info;
|
||||
shopPurchaseInfo.m_purchase = new PurchaseInfo();
|
||||
shopPurchaseInfo.m_purchase.m_purchase_items = process_for_item.purchased_items;
|
||||
}
|
||||
else if (product_data.ProductData.Currency != null)
|
||||
{
|
||||
var process_for_currency = await processForCurrency(product_data, product_data.ProductData.Currency.Id, purchase_count);
|
||||
if (process_for_currency.result.isFail()) return process_for_currency.result;
|
||||
|
||||
shopPurchaseInfo.m_spent = process_for_currency.spent_info;
|
||||
shopPurchaseInfo.m_purchase = new PurchaseInfo();
|
||||
|
||||
var check_currency_data = ShopHelper.checkCurrencyDataFromProductIdInTableData(product_data.ProductData.Currency.Id);
|
||||
if (check_currency_data.result.isFail()) return result;
|
||||
|
||||
NullReferenceCheckHelper.throwIfNull(check_currency_data.currency_data, () => $"check_currency_data.currency_data is null !!!");
|
||||
shopPurchaseInfo.m_purchase.m_purchase_currency_type = check_currency_data.currency_data.CurrencyType;
|
||||
shopPurchaseInfo.m_purchase.m_purchase_currency = product_data.ProductData.Currency.Value * purchase_count;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<(Result result, SpentInfo? spent_info, List<GameServer.Item>? purchased_items)> processForItem(MetaAssets.ShopProductMetaData product_data, int item_id, int purchase_count, int discountRate)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var my_shop_product = getOwner();
|
||||
ArgumentNullException.ThrowIfNull(my_shop_product);
|
||||
var player = my_shop_product.getRootParent() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
|
||||
// 1. 아이템 지급
|
||||
var inventory_action = player?.getEntityAction<InventoryActionBase>();
|
||||
if (null == inventory_action)
|
||||
{
|
||||
var err_msg = $"Fail to get Inventory Action : {nameof(InventoryActionBase)}.";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return (result, null, null);
|
||||
}
|
||||
|
||||
(result, var changed_items) = await inventory_action.tryTakalbleToBag((META_ID)item_id, (ushort)purchase_count);
|
||||
if (result.isFail()) return (result, null, null);
|
||||
|
||||
// 2. 요구 재화 체크
|
||||
var required_purchase = await ShopHelper.checkRequiredPurchaseFromProductMeta(product_data, purchase_count, discountRate);
|
||||
|
||||
return (required_purchase.result, required_purchase.spent_info, changed_items);
|
||||
}
|
||||
|
||||
private async Task<(Result result, SpentInfo? spent_info, List<GameServer.Item>? purchased_items)> processForCurrency(MetaAssets.ShopProductMetaData product_data, int currency_id, int purchase_count)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var my_shop_product = getOwner();
|
||||
ArgumentNullException.ThrowIfNull(my_shop_product);
|
||||
var player = my_shop_product.getRootParent() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
|
||||
|
||||
// 1. 재화 지급
|
||||
var money_action = player?.getEntityAction<MoneyAction>();
|
||||
if (null == money_action)
|
||||
{
|
||||
var err_msg = $"Fail to get Money Action : {nameof(MoneyAction)}.";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return (result, null, null);
|
||||
}
|
||||
|
||||
var check = ShopHelper.checkCurrencyDataFromProductIdInTableData(currency_id);
|
||||
if (check.result.isFail() || null == check.currency_data)
|
||||
{
|
||||
var err_msg = $"Fail to get Currency Data : {nameof(ShopHelper.checkCurrencyDataFromProductIdInTableData)}. product id - {currency_id}";
|
||||
result.setFail(ServerErrorCode.NotFoundItemTableId, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return (result, null, null);
|
||||
}
|
||||
|
||||
result = await money_action.changeMoney(check.currency_data.CurrencyType, product_data.ProductData.Currency.Value * purchase_count);
|
||||
if (result.isFail()) return (result, null, null);
|
||||
|
||||
var required = await ShopHelper.checkRequiredPurchaseFromProductMeta(product_data, purchase_count, 0);
|
||||
return (required.result, required.spent_info, null);
|
||||
}
|
||||
|
||||
public async Task<(Result result, IEnumerable<GameServer.Item>? del_items)> processSpent(SpentInfo spentInfo)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var my_shop_product = getOwner();
|
||||
ArgumentNullException.ThrowIfNull(my_shop_product);
|
||||
var player = my_shop_product.getRootParent() as Player;
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
List<GameServer.Item>? del_items = null;
|
||||
|
||||
switch (spentInfo.m_buy_type)
|
||||
{
|
||||
// 재화 감소
|
||||
case ShopBuyType.Currency:
|
||||
var money_action = player?.getEntityAction<MoneyAction>();
|
||||
ArgumentNullException.ThrowIfNull(money_action);
|
||||
|
||||
result = await money_action.changeMoney(spentInfo.m_currency_type, -1 * spentInfo.m_spent);
|
||||
break;
|
||||
|
||||
// 아이템 차감
|
||||
case ShopBuyType.Item:
|
||||
var inventory_action = player?.getEntityAction<InventoryActionBase>();
|
||||
ArgumentNullException.ThrowIfNull(inventory_action);
|
||||
|
||||
var delete_item = await inventory_action.tryDeleteItemByMetaId((uint)spentInfo.m_item_id, (ushort)spentInfo.m_spent);
|
||||
result = delete_item.Item1;
|
||||
del_items = delete_item.Item2;
|
||||
break;
|
||||
|
||||
//
|
||||
case ShopBuyType.None:
|
||||
default:
|
||||
var err_msg = $"fail to spent purchase !!! : invalid shop buy type - {spentInfo.m_buy_type}";
|
||||
result.setFail(ServerErrorCode.InvalidShopBuyType, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
|
||||
return (result, del_items);
|
||||
}
|
||||
|
||||
public async Task<Result> updateShopProductMeter(int product_id, int count)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var shop_trading_meter_action = getOwner().getEntityAction<ShopProductTradingMeterAction>();
|
||||
if (null == shop_trading_meter_action)
|
||||
{
|
||||
var err_msg = $"Fail to get ShopProductTradingMeter Action : {nameof(ShopProductTradingMeterAction)}.";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await shop_trading_meter_action.updateTradingMeter(product_id, -1 * count);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Result> updateItemFirstPurchaseHistory(DiscountType discountType, int itemMetaId)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var player = getOwner().getRootParent();
|
||||
ArgumentNullException.ThrowIfNull(player);
|
||||
|
||||
if (discountType != DiscountType.ItemFirstPurchase)
|
||||
return result;
|
||||
|
||||
var item_first_purchase_history_agent_action = player.getEntityAction<ItemFirstPurchaseHistoryAgentAction>();
|
||||
ArgumentNullException.ThrowIfNull(item_first_purchase_history_agent_action);
|
||||
|
||||
result = await item_first_purchase_history_agent_action.tryAddItemFirstPurchaseHistoryFromMetaId(itemMetaId);
|
||||
if (result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private ShopProductTradingMeterSubAttribute? getShopTradingMeterSubAttribute(int product_id)
|
||||
{
|
||||
var shop_meter_attribute = getOwner().getEntityAttribute<ShopProductTradingMeterAttribute>();
|
||||
if (null == shop_meter_attribute) return null;
|
||||
|
||||
var sub_attribute = shop_meter_attribute.getMeterSubAttribute(product_id);
|
||||
return sub_attribute ?? null;
|
||||
}
|
||||
}
|
||||
276
GameServer/Contents/Shop/Action/ShopAction.cs
Normal file
276
GameServer/Contents/Shop/Action/ShopAction.cs
Normal file
@@ -0,0 +1,276 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using ITEM_GUID = System.String;
|
||||
using META_ID = System.UInt32;
|
||||
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class ShopAction : EntityActionBase
|
||||
{
|
||||
private readonly ConcurrentDictionary<int, MyShopProduct> m_my_shop_products = new();
|
||||
private readonly MySoldProduct m_my_sold_product;
|
||||
|
||||
public ShopAction(Player owner) : base(owner)
|
||||
{
|
||||
m_my_sold_product = new MySoldProduct(owner);
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var result = new Result();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public MySoldProduct getMySoldProduct() => m_my_sold_product;
|
||||
|
||||
public ShopSoldProductAction getSolProductAction()
|
||||
{
|
||||
var shop_sold_product_action = m_my_sold_product.getEntityAction<ShopSoldProductAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(shop_sold_product_action, () => $"shop_sold_product_action is null !!!");
|
||||
return shop_sold_product_action;
|
||||
}
|
||||
|
||||
public IEnumerable<MyShopProduct> getMyShopProducts() => m_my_shop_products.Select(shop => shop.Value).ToList();
|
||||
|
||||
public MyShopProduct getMyShopProduct(int shop_id)
|
||||
{
|
||||
if (m_my_shop_products.TryGetValue(shop_id, out var my_shop_product))
|
||||
{
|
||||
return my_shop_product;
|
||||
}
|
||||
|
||||
var owner = getOwner() as Player;
|
||||
my_shop_product = new MyShopProduct(owner!);
|
||||
setMyShopProduct(shop_id, my_shop_product);
|
||||
|
||||
return my_shop_product;
|
||||
}
|
||||
|
||||
public async Task<Result> setMyShopProductFromDoc(ShopProductTradingMeterDoc docBase)
|
||||
{
|
||||
var result = new Result();
|
||||
string err_msg;
|
||||
|
||||
var owner = getOwner() as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var doc_attr = docBase.getAttrib<ShopProductTradingMeterAttrib>();
|
||||
if (null == doc_attr)
|
||||
{
|
||||
err_msg = $"Fail to get doc attrib : {nameof(ShopProductTradingMeterDoc)} is null";
|
||||
result.setFail(ServerErrorCode.EntityAttributeNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
var my_shop_product = getMyShopProduct(doc_attr.ShopId);
|
||||
var my_shop_attribute = my_shop_product.getEntityAttribute<ShopProductTradingMeterAttribute>();
|
||||
if (null == my_shop_attribute)
|
||||
{
|
||||
err_msg = $"Fail to get entity attribute : {nameof(ShopProductTradingMeterAttribute)} is null";
|
||||
result.setFail(ServerErrorCode.EntityAttributeIsNull, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
// doc 에서 직접 copy 된 경우 pk, sk 를 셋팅해야 한다.
|
||||
docBase.setCombinationKeyForPK(owner.getUserGuid());
|
||||
docBase.setCombinationKeyForSK(doc_attr.ShopId.ToString());
|
||||
var is_apply = docBase.onApplyPKSK();
|
||||
if (ServerErrorCode.Success != is_apply)
|
||||
{
|
||||
err_msg = $"Fail to copy to attribute from doc : invalid argument {nameof(setMyShopProductFromDoc)}";
|
||||
result.setFail(is_apply, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
var is_success = my_shop_attribute.copyEntityAttributeFromDoc(docBase);
|
||||
if (false == is_success)
|
||||
{
|
||||
err_msg = $"Fail to copy shop product trading meter attribute : to {nameof(ShopProductTradingMeterAttribute)} from {nameof(ShopProductTradingMeterDoc)}";
|
||||
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public async Task<Result> cheatInitResetTime()
|
||||
{
|
||||
foreach (var shop_product in m_my_shop_products)
|
||||
{
|
||||
var attribute = shop_product.Value.getEntityAttribute<ShopProductTradingMeterAttribute>();
|
||||
if (attribute == null) continue;
|
||||
|
||||
attribute.initEndTime();
|
||||
attribute.modifiedEntityAttribute();
|
||||
}
|
||||
|
||||
|
||||
return await Task.FromResult(new Result());
|
||||
}
|
||||
|
||||
public async Task<Result> cheatInitShopRenewalCount(Int32 shopId)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var shop = getMyShopProduct(shopId);
|
||||
var result = new Result();
|
||||
|
||||
var attribute = shop.getEntityAttribute<ShopProductTradingMeterAttribute> ();
|
||||
|
||||
var owner = getOwner();
|
||||
if (attribute is null)
|
||||
{
|
||||
Log.getLogger().error($"Shop Product Attribute not exist shopId : {shopId}, owner : {owner.toBasicString()}");
|
||||
return result;
|
||||
}
|
||||
|
||||
attribute.setCurrentRenewalCount(0);
|
||||
attribute.modifiedEntityAttribute();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void setMyShopProduct(int shop_id, MyShopProduct product) => m_my_shop_products.TryAdd(shop_id, product);
|
||||
|
||||
public async Task<(Result result, GameServer.Item? changed_item, CurrencyType spent_currency_type, double spent_currency)> processRePurchase(MetaAssets.ItemMetaData item_data, SoldProduct sold)
|
||||
{
|
||||
var result = new Result();
|
||||
var player = getOwner() as Player;
|
||||
|
||||
// 1. inventory 아이템 추가
|
||||
var inventory_action = player?.getEntityAction<InventoryActionBase>();
|
||||
if (null == inventory_action)
|
||||
{
|
||||
var err_msg = $"Fail to get Inventory Action : {nameof(InventoryActionBase)}.";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return (result, null, CurrencyType.None, 0);
|
||||
}
|
||||
|
||||
var item_attrib = sold.ItemDoc.getAttrib<ItemAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(item_attrib, () => $"item_attrib is null !!! - {player?.toBasicString()}");
|
||||
|
||||
(result, var changed_item) = await inventory_action.tryTakableToBag(sold.ItemDoc);
|
||||
if(result.isFail() || null == changed_item) return (result, null, CurrencyType.None, 0);
|
||||
|
||||
// 2. sold item list 갱신
|
||||
var sold_action = player?.getEntityAction<ShopAction>().getMySoldProduct().getEntityAction<ShopSoldProductAction>();
|
||||
if (null == sold_action)
|
||||
{
|
||||
var err_msg = $"Fail to get Sold Product Action : {nameof(ShopSoldProductAction)}.";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return (result, null, CurrencyType.None, 0);
|
||||
}
|
||||
|
||||
result = await sold_action.updateSoldProduct(item_attrib.ItemGuid, -1 * item_attrib.ItemStackCount);
|
||||
|
||||
var check_currency_type = ShopHelper.checkCurrencyTypeFromCurrencyId(item_data.SellId);
|
||||
if (check_currency_type.result.isFail()) return (check_currency_type.result, null, CurrencyType.None, 0);
|
||||
|
||||
return (result, changed_item, check_currency_type.currencyType, item_data.SellPrice * item_attrib.ItemStackCount);
|
||||
}
|
||||
|
||||
public async Task<Result> processSpent(CurrencyType spent_currency_type, double spent_currency)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var my_shop_product = getOwner();
|
||||
var player = my_shop_product.getRootParent() as Player;
|
||||
|
||||
var money_action = player?.getEntityAction<MoneyAction>();
|
||||
if (null == money_action)
|
||||
{
|
||||
var err_msg = $"Fail to get Money Action : {nameof(MoneyAction)}.";
|
||||
result.setFail(ServerErrorCode.EntityActionNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await money_action.changeMoney(spent_currency_type, -1 * spent_currency);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Result checkItemSellConditionAsync(ItemAttributeBase attribute, int sellCount)
|
||||
{
|
||||
var result = new Result();
|
||||
string err_msg;
|
||||
|
||||
var player = getOwner() as Player;
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
|
||||
|
||||
// 0. 재판매 여부 확인
|
||||
var check_item = ShopHelper.checkItemIdFromTableData((int)attribute.ItemMetaId);
|
||||
if (check_item.result.isFail() || null == check_item.item_data) return check_item.result;
|
||||
|
||||
if (false == check_item.item_data.IsSystemTradable)
|
||||
{
|
||||
err_msg = $"failed to check sell item : cannot sell item !! - itemId[{attribute.ItemMetaId}] , isSystemTrade[{check_item.item_data.IsSystemTradable}]";
|
||||
result.setFail(ServerErrorCode.ShopItemCannotSell, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return result;
|
||||
}
|
||||
|
||||
// 1. 착용 여부 확인
|
||||
if (InvenEquipType.None != attribute.EquipedIvenType)
|
||||
{
|
||||
err_msg = $"Failed to check equipped item : already equipped - {attribute.ItemGuid}";
|
||||
result.setFail(ServerErrorCode.SlotsAlreadyEquiped, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 2. 마이홈 배치 여부 확인
|
||||
var myhome_agent_action = player.getEntityAction<MyhomeAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(myhome_agent_action, () => $"myhome_agent_action is null !!! - {player.toBasicString()}");
|
||||
if (false == myhome_agent_action.tryGetSelectedMyhome(out var my_home)) return result;
|
||||
|
||||
var myhome_inventory_action = my_home.getEntityAction<MyhomeInventoryAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(myhome_inventory_action, () => $"myhome_inventory_action is null !!! - {player.toBasicString()}");
|
||||
|
||||
if (myhome_inventory_action.tryGetItemByItemGuid(attribute.ItemGuid) != null)
|
||||
{
|
||||
err_msg = $"Failed to check setting my home item : item guid - {attribute.ItemGuid}";
|
||||
result.setFail(ServerErrorCode.ShopIsMyHomeItem, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
// 3. stack 수량 체크
|
||||
if (attribute.ItemStackCount < sellCount)
|
||||
{
|
||||
err_msg =
|
||||
$"Failed to check stack count : stackCount[{attribute.ItemStackCount}] / sellCount[{sellCount}]";
|
||||
result.setFail(ServerErrorCode.InvalidItemCount, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class ShopProductTradingMeterAction : EntityActionBase
|
||||
{
|
||||
public ShopProductTradingMeterAction(MyShopProduct owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var result = new Result();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public async Task<Result> updateTradingMeter(int product_id, int delta)
|
||||
{
|
||||
var result = new Result();
|
||||
var attribute = getOwner().getEntityAttribute<ShopProductTradingMeterAttribute>();
|
||||
if (null == attribute)
|
||||
{
|
||||
var err_msg = $"Fail to get attribute() !!! : {nameof(ShopProductTradingMeterAttribute)}";
|
||||
result.setFail(ServerErrorCode.EntityAttributeNotFound, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = attribute.changeProductTradingMeter(product_id, delta);
|
||||
if (result.isFail()) return result;
|
||||
|
||||
attribute.modifiedEntityAttribute();
|
||||
|
||||
return await Task.FromResult(new Result());
|
||||
}
|
||||
}
|
||||
104
GameServer/Contents/Shop/Action/ShopSoldProductAction.cs
Normal file
104
GameServer/Contents/Shop/Action/ShopSoldProductAction.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using Newtonsoft.Json;
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using ITEM_GUID = System.String;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class SoldProduct
|
||||
{
|
||||
[JsonProperty("item_guid")] public ITEM_GUID ItemGuid { get; set; } = ITEM_GUID.Empty;
|
||||
|
||||
[JsonProperty("item")] public ItemDoc ItemDoc { get; set; } = null!;
|
||||
}
|
||||
|
||||
// ==============================================================
|
||||
// 기획 의도 : 채널이동 및 로그아웃시 해당 데이터 초기화
|
||||
// attribute 별도 제작 안함
|
||||
// ==============================================================
|
||||
public class ShopSoldProductAction : EntityActionBase
|
||||
{
|
||||
public ShopSoldProductAction(MySoldProduct owner) : base(owner)
|
||||
{
|
||||
m_sold_products = new List<SoldProduct>();
|
||||
}
|
||||
|
||||
public override async Task<Result> onInit()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var result = new Result();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public async Task<Result> setSoldProduct(ITEM_GUID item_guid, ItemDoc itemDoc)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var is_exist = m_sold_products.Any(product => product.ItemGuid == item_guid);
|
||||
if (is_exist) return result;
|
||||
|
||||
var sold = new SoldProduct { ItemGuid = item_guid, ItemDoc = itemDoc};
|
||||
m_sold_products.Add(sold);
|
||||
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public async Task<Result> updateSoldProduct(ITEM_GUID item_guid, int delta_count)
|
||||
{
|
||||
var result = new Result();
|
||||
var sold = findSoldProduct(item_guid);
|
||||
if (null == sold)
|
||||
{
|
||||
var err_msg = $"Fail to get item info : {nameof(updateSoldProduct)} - {item_guid}";
|
||||
result.setFail(ServerErrorCode.NotFoundItemTableId, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
var item_attrib = sold.ItemDoc.getAttrib<ItemAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(item_attrib, () => $"itemAttrib is null !! - itemGuid:{item_guid}");
|
||||
|
||||
var delta = item_attrib.ItemStackCount + delta_count;
|
||||
if (delta <= 0)
|
||||
{
|
||||
deleteSoldProduct(item_guid);
|
||||
return result;
|
||||
}
|
||||
|
||||
item_attrib.ItemStackCount = (ushort)delta;
|
||||
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
private void deleteSoldProduct(ITEM_GUID item_guid)
|
||||
{
|
||||
foreach (var sold in m_sold_products.Where(sold => sold.ItemGuid == item_guid))
|
||||
{
|
||||
m_sold_products.Remove(sold);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private List<SoldProduct> m_sold_products { get; set; }
|
||||
|
||||
public List<SoldProduct> getSoldList() => m_sold_products;
|
||||
|
||||
public SoldProduct? findSoldProduct(ITEM_GUID item_guid) => m_sold_products.FirstOrDefault(sold => sold.ItemGuid == item_guid);
|
||||
}
|
||||
Reference in New Issue
Block a user