초기커밋

This commit is contained in:
2025-05-01 07:20:41 +09:00
commit 98bb2e3c5c
2747 changed files with 646947 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameServer
{
internal class ItemFirstPurchaseHistoryAgentAction : EntityActionBase
{
ConcurrentDictionary<int, ItemFirstPurchaseHistory> m_item_first_purchase_histories = new();
public ItemFirstPurchaseHistoryAgentAction(Player owner)
: base(owner)
{ }
public override async Task<Result> onInit()
{
await Task.CompletedTask;
var result = new Result();
return result;
}
public override void onClear()
{
m_item_first_purchase_histories.Clear();
}
public List<ItemFirstPurchaseHistory> getItemFirstPurchaseHistories()
{
return m_item_first_purchase_histories.Select(x => x.Value).ToList();
}
public bool isItemFirstPurchase(int itemMetaId)
{
return !m_item_first_purchase_histories.ContainsKey(itemMetaId);
}
public async Task<Result> tryAddItemFirstPurchaseHistoryFromDoc(ItemFirstPurchaseHistoryDoc itemFirstPurchaseHistoryDoc)
{
var result = new Result();
var err_msg = string.Empty;
var player = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(player, () => "player is null !!!");
ItemFirstPurchaseHistory item_first_purchase_history = new(player);
await item_first_purchase_history.onInit();
var item_first_purchase_history_attribute = item_first_purchase_history.getEntityAttribute<ItemFirstPurchaseHistoryAttribute>();
NullReferenceCheckHelper.throwIfNull(item_first_purchase_history_attribute, () => $"item_first_purchase_history_attribute is null !!! - {player.toBasicString()}");
if (!item_first_purchase_history_attribute.copyEntityAttributeFromDoc(itemFirstPurchaseHistoryDoc))
{
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! to:{item_first_purchase_history_attribute.getTypeName()}, from:{itemFirstPurchaseHistoryDoc.getTypeName()} : {this.getTypeName()}";
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
if (!m_item_first_purchase_histories.TryAdd((int)item_first_purchase_history_attribute.ItemMetaId, item_first_purchase_history))
{
err_msg = $"Failed to TryAdd() !!! : {item_first_purchase_history.toBasicString()} : {this.getTypeName()}";
result.setFail(ServerErrorCode.ItemFirstPurchaseHistoryDocLoadDuplicatedItem, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
return result;
}
public async Task<Result> tryAddItemFirstPurchaseHistoryFromMetaId(int itemMetaId)
{
var result = new Result();
var err_msg = string.Empty;
var player = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(player, () => "player is null !!!");
if (!MetaData.Instance._ItemTable.TryGetValue(itemMetaId, out var itemMetaData))
{
err_msg = $"Failed to TryGetValue() !!! : itemMetaId:{itemMetaId} : {this.getTypeName()}";
result.setFail(ServerErrorCode.ItemMetaDataNotFound, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
if (itemMetaData.Buy_Discount_Rate == 0)
return result;
ItemFirstPurchaseHistory item_first_purchase_history = new(player);
await item_first_purchase_history.onInit();
var item_first_purchase_history_attribute = item_first_purchase_history.getEntityAttribute<ItemFirstPurchaseHistoryAttribute>();
NullReferenceCheckHelper.throwIfNull(item_first_purchase_history_attribute, () => $"item_first_purchase_history_attribute is null !!! - {player.toBasicString()}");
item_first_purchase_history_attribute.ItemMetaId = (uint)itemMetaId;
item_first_purchase_history_attribute.FirstPurchaseTime = DateTime.UtcNow;
item_first_purchase_history_attribute.newEntityAttribute();
if (!m_item_first_purchase_histories.TryAdd((int)item_first_purchase_history_attribute.ItemMetaId, item_first_purchase_history))
{
err_msg = $"Failed to TryAdd() !!! : {item_first_purchase_history.toBasicString()} : {this.getTypeName()}";
result.setFail(ServerErrorCode.ItemFirstPurchaseHistoryAlreadyExist, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
return result;
}
}
}

View File

@@ -0,0 +1,114 @@
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameServer
{
internal class DBQItemFirstPurchaseHistoryReadAll : QueryExecutorBase
{
private string m_combination_key_for_pk = string.Empty;
private string m_pk = string.Empty;
private readonly List<ItemFirstPurchaseHistoryDoc> m_to_read_item_first_purchase_history_docs = new();
public DBQItemFirstPurchaseHistoryReadAll(string combinationKeyForPK)
: base(typeof(DBQItemFirstPurchaseHistoryReadAll).Name)
{
m_combination_key_for_pk = combinationKeyForPK;
}
//=====================================================================================
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
//=====================================================================================
public override async Task<Result> onPrepareQuery()
{
var result = new Result();
var err_msg = string.Empty;
var owner = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var doc = new ItemFirstPurchaseHistoryDoc();
doc.setCombinationKeyForPK(m_combination_key_for_pk);
var error_code = doc.onApplyPKSK();
if (error_code.isFail())
{
err_msg = $"Failed to onApplyPKSK() !!! : {error_code.toBasicString()} - {toBasicString()}, {owner.toBasicString()}";
result.setFail(error_code, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
m_pk = doc.getPK();
return await Task.FromResult(result);
}
//=====================================================================================
// onPrepareQuery()를 성공할 경우 호출된다.
//=====================================================================================
public override async Task<Result> onQuery()
{
var result = new Result();
var err_msg = string.Empty;
var owner = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var query_batch = getQueryBatch();
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!!");
var db_connector = query_batch.getDynamoDbConnector();
var query_config = db_connector.makeQueryConfigForReadByPKOnly(m_pk);
(result, var read_docs) = await db_connector.simpleQueryDocTypesWithQueryOperationConfig<ItemFirstPurchaseHistoryDoc>(query_config, eventTid: query_batch.getTransId());
if (result.isFail())
{
return result;
}
var item_first_purchase_history_agent_action = owner.getEntityAction<ItemFirstPurchaseHistoryAgentAction>();
NullReferenceCheckHelper.throwIfNull(item_first_purchase_history_agent_action, () => $"item_first_purchase_history_agent_action is null !!!");
foreach (var read_doc in read_docs)
{
result = await item_first_purchase_history_agent_action.tryAddItemFirstPurchaseHistoryFromDoc(read_doc);
if (result.isFail())
{
return result;
}
m_to_read_item_first_purchase_history_docs.Add(read_doc);
}
return await Task.FromResult(result);
}
public List<ItemFirstPurchaseHistoryDoc> getToReadItemFirstPurchaseHistoryDocs() => m_to_read_item_first_purchase_history_docs;
//=====================================================================================
// DB 쿼리를 성공하고, doFnCommit()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
//=====================================================================================
public override async Task onQueryResponseCommit()
{
await Task.CompletedTask;
return;
}
//=====================================================================================
// DB 쿼리를 실패하고, doFnRollback()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
//=====================================================================================
public override async Task onQueryResponseRollback(Result errorResult)
{
await Task.CompletedTask;
return;
}
}
}

View File

@@ -0,0 +1,48 @@
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameServer
{
internal static class ItemFirstPurchaseHistoryHelper
{
public static Result checkItemFirstPurchaseItemCount(this Player player, int itemMetaId, int itemCount)
{
var result = new Result();
var err_msg = string.Empty;
if (!MetaData.Instance._ItemTable.TryGetValue(itemMetaId, out var itemMetaData))
{
err_msg = $"Failed to TryGetValue() !!! : itemMetaId:{itemMetaId}";
result.setFail(ServerErrorCode.ItemMetaDataNotFound, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
if (itemMetaData.Buy_Discount_Rate == 0)
return result;
var item_first_purchase_history_agent_action = player.getEntityAction<ItemFirstPurchaseHistoryAgentAction>();
NullReferenceCheckHelper.throwIfNull(item_first_purchase_history_agent_action, () => $"item_first_purchase_history_agent_action is null !!! - {player.toBasicString()}");
if (item_first_purchase_history_agent_action.isItemFirstPurchase(itemMetaId))
{
if (itemCount > 1)
{
err_msg = $"Fail to check item first purchased discount item count : purchase count - {itemCount}";
result.setFail(ServerErrorCode.ItemFirstPurchaseDiscountItemCountWrong, err_msg);
Log.getLogger().error(err_msg);
return result;
}
}
return result;
}
}
}

View File

@@ -0,0 +1,40 @@
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ClientToGameMessage.Types;
namespace GameServer
{
internal static class ItemFirstPurchaseHistoryNotifyHelper
{
public static bool send_S2C_NTF_ITEM_FIRST_PURCHASE_HISTORY(this Player player)
{
var item_first_purchase_history_agent_action = player.getEntityAction<ItemFirstPurchaseHistoryAgentAction>();
NullReferenceCheckHelper.throwIfNull(item_first_purchase_history_agent_action, () => $"item_first_purchase_history_agent_action is null !!! - {player.toBasicString()}");
var ntf_packet = new ClientToGame();
ntf_packet.Message = new ClientToGameMessage();
ntf_packet.Message.NtfItemFirstPurchaseHistory = new GS2C_NTF_ITEM_FIRST_PURCHASE_HISTORY();
var item_first_purchase_histories = item_first_purchase_history_agent_action.getItemFirstPurchaseHistories();
foreach (var item_first_purchase_history in item_first_purchase_histories)
{
var item_first_purchase_history_attribute = item_first_purchase_history.getEntityAttribute<ItemFirstPurchaseHistoryAttribute>();
NullReferenceCheckHelper.throwIfNull(item_first_purchase_history_attribute, () => $"ItemFirstPurchaseHistoryAttrib is null !!! - player:{player.toBasicString()}");
ntf_packet.Message.NtfItemFirstPurchaseHistory.ItemMetaids.Add(item_first_purchase_history_attribute.ItemMetaId);
}
if (false == GameServerApp.getServerLogic().onSendPacket(player, ntf_packet))
{
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerCore; using ServerBase;
using ServerCommon;
namespace GameServer
{
internal class ItemFirstPurchaseHistory : EntityBase
{
public ItemFirstPurchaseHistory(Player parent)
: base(EntityType.SocialAction, parent)
{
}
public override async Task<Result> onInit()
{
var direct_parent = getDirectParent();
NullReferenceCheckHelper.throwIfNull(direct_parent, () => $"direct_parent is null !!!");
addEntityAttribute(new ItemFirstPurchaseHistoryAttribute(this, direct_parent));
return await base.onInit();
}
public override string toBasicString()
{
return $"{this.getTypeName()}, ItemMetaId:{getOriginEntityAttribute<ItemFirstPurchaseHistoryAttribute>()?.ItemMetaId}";
}
public override string toSummaryString()
{
return $"{this.getTypeName()}, {getEntityAttribute<ItemFirstPurchaseHistoryAttribute>()?.toBasicString()}";
}
}
}