초기커밋

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,95 @@
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 SocialActionAction : EntityActionBase
{
public SocialActionAction(SocialAction owner)
: base(owner)
{
}
public override async Task<Result> onInit()
{
await Task.CompletedTask;
var result = new Result();
return result;
}
public override void onClear()
{
return;
}
public Result tryEquipSocialAction(UInt16 equipPos)
{
var result = new Result();
var err_msg = string.Empty;
var owner = getOwner();
ArgumentNullException.ThrowIfNull(owner, $"owner is null !!!");
var parent = owner.getRootParent();
ArgumentNullException.ThrowIfNull(parent, $"parent is null !!! - {parent.toBasicString()}");
if (equipPos > ServerCommon.Constant.MAX_SOCIAL_ACTION_SLOT)
{
err_msg = $"Out of Range SocailActionSlot !!! : socialActionSlot:{equipPos} - {parent.toBasicString()}";
result.setFail(ServerErrorCode.SocialActionSlotOutOfRange, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
var users_social_action_attribute = getOwner().getEntityAttribute<UserSocialActionAttribute>();
ArgumentNullException.ThrowIfNull(users_social_action_attribute, $"users_social_action_attribute is null !!! - {parent.toBasicString()}");
users_social_action_attribute.EquipedPos = equipPos;
users_social_action_attribute.modifiedEntityAttribute();
return result;
}
public void unequipSocialAction()
{
var owner = getOwner();
ArgumentNullException.ThrowIfNull(owner, $"owner is null !!!");
var parent = owner.getRootParent();
ArgumentNullException.ThrowIfNull(parent, $"parent is null !!! - {parent.toBasicString()}");
var users_social_action_attribute = owner.getEntityAttribute<UserSocialActionAttribute>();
ArgumentNullException.ThrowIfNull(users_social_action_attribute, $"users_social_action_attribute is null !!! - {parent.toBasicString()}");
users_social_action_attribute.EquipedPos = 0;
users_social_action_attribute.modifiedEntityAttribute();
}
public bool isSocialActionOnSlot()
{
var owner = getOwner();
ArgumentNullException.ThrowIfNull(owner, $"owner is null !!!");
var parent = owner.getRootParent();
ArgumentNullException.ThrowIfNull(parent, $"parent is null !!! - {parent.toBasicString()}");
var users_social_action_attribute = owner.getEntityAttribute<UserSocialActionAttribute>();
ArgumentNullException.ThrowIfNull(users_social_action_attribute, $"users_social_action_attribute is null !!! - {parent.toBasicString()}");
if (users_social_action_attribute.EquipedPos == 0)
{
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,236 @@
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using ServerCore;
using ServerBase;
using ServerCommon;
using ServerCommon.BusinessLogDomain;
using MetaAssets;
namespace GameServer;
public class SocialActionLoadAction : EntityActionBase
{
private ConcurrentDictionary<int, SocialAction> m_social_actions = new();
public SocialActionLoadAction(EntityBase owner)
: base(owner)
{ }
public override async Task<Result> onInit()
{
await Task.CompletedTask;
var result = new Result();
return result;
}
public override void onClear()
{
m_social_actions.Clear();
}
public bool isOwnedSocialAction(int socialActionMetaId)
{
return m_social_actions.ContainsKey(socialActionMetaId);
}
public bool tryGetSocialAction(int socialActionMetaId, [MaybeNullWhen(false)] out SocialAction socialAction)
{
return m_social_actions.TryGetValue(socialActionMetaId, out socialAction);
}
public List<SocialAction> getSocialActions()
{
return m_social_actions.Select(x => x.Value).ToList();
}
public async Task<Result> tryAddSocialActionFromDoc(SocialActionDoc socialActionDoc)
{
var result = new Result();
var err_msg = string.Empty;
var owner = getOwner();
var social_action = new SocialAction(owner);
result = await social_action.onInit();
if (result.isFail())
{
return result;
}
var found_social_action_attribute = social_action.getEntityAttribute<UserSocialActionAttribute>();
NullReferenceCheckHelper.throwIfNull(found_social_action_attribute, () => $"found_social_action_attribute is null !!! - {owner.toBasicString()}");
if (false == found_social_action_attribute.copyEntityAttributeFromDoc(socialActionDoc))
{
err_msg = $"Failed to copyEntityAttributeFromDoc() !!! to:{found_social_action_attribute.getTypeName()}, from:{socialActionDoc.getTypeName()} : {this.getTypeName()} - {owner.toBasicString()}";
result.setFail(ServerErrorCode.DynamoDbDocCopyToEntityAttributeFailed, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
if (false == m_social_actions.TryAdd((int)found_social_action_attribute.SocialActionMetaId, social_action))
{
err_msg = $"Failed to TryAdd() !!! : {social_action.toBasicString()} : {this.getTypeName()} - {owner.toBasicString()}";
result.setFail(ServerErrorCode.SocialActionDocLoadDuplicatedSocialAction, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
return result;
}
public async Task<Result> tryAddSocialActionFromMetaId(int socialActionMetaId)
{
var result = new Result();
var err_msg = string.Empty;
var owner = getOwner();
if (false == MetaData.Instance._SocialActionTable.TryGetValue(socialActionMetaId, out _))
{
err_msg = $"Failed to TryGetValue() !!! : socialActionMetaId:{socialActionMetaId} - {owner.toBasicString()}";
result.setFail(ServerErrorCode.SocialActionMetaDataNotFound, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
// 최대 획득 조건 추가
var social_action_slot_max = MetaHelper.GameConfigMeta.MaxSocialActionSlot;
if (m_social_actions.Count >= social_action_slot_max)
{
err_msg = $"Social Action Max count exceed !!! : {m_social_actions.Count} <= {social_action_slot_max} - socialActionMetaId:{socialActionMetaId}, {owner.toBasicString()}";
result.setFail(ServerErrorCode.SocialActionSlotOutOfRange, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
var social_action = new SocialAction(owner);
await social_action.onInit();
var social_action_attribute = social_action.getEntityAttribute<UserSocialActionAttribute>();
NullReferenceCheckHelper.throwIfNull(social_action_attribute, () => $"social_action_attribute is null !!! - {owner.toBasicString()}");
social_action_attribute.SocialActionMetaId = (uint)socialActionMetaId;
social_action_attribute.newEntityAttribute();
if (!m_social_actions.TryAdd((int)social_action_attribute.SocialActionMetaId, social_action))
{
err_msg = $"Failed to TryAdd() !!! : {social_action.toBasicString()} - {owner.toBasicString()}";
result.setFail(ServerErrorCode.SocialActionAlreadyExist, err_msg);
Log.getLogger().error(result.toBasicString());
return result;
}
return result;
}
public bool tryGetSocialActionByEquipedPos(UInt16 equipedPos, [MaybeNullWhen(false)] out SocialAction socialAction)
{
socialAction = null;
var owner = getOwner();
foreach (var social_action in m_social_actions.Values)
{
var origin_social_action_attribute = social_action.getOriginEntityAttribute<UserSocialActionAttribute>();
NullReferenceCheckHelper.throwIfNull(origin_social_action_attribute, () => $"origin_social_action_attribute is null !!! - {owner.toBasicString()}");
if (origin_social_action_attribute.EquipedPos == equipedPos)
{
socialAction = social_action;
return true;
}
}
return false;
}
public (Result, List<ILogInvoker>?) tryExchangeSocialActionSlot(int socialActionSlot, int socialActionMetaId)
{
var result = new Result();
var err_msg = string.Empty;
var business_logs = new List<ILogInvoker>();
var player = getOwner() as Player;
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var user_guid = player.getUserGuid();
var old_social_action_meta_id = 0;
if (tryGetSocialActionByEquipedPos((UInt16)socialActionSlot, out var equipedSocialAction))
{
var equiped_social_action_action = equipedSocialAction.getEntityAction<SocialActionAction>();
NullReferenceCheckHelper.throwIfNull(equiped_social_action_action, () => $"equiped_social_action_action is null !!! - {player.toBasicString()}");
// 슬롯에서 제거
equiped_social_action_action.unequipSocialAction();
var equiped_social_action_attribute = equipedSocialAction.getEntityAttribute<UserSocialActionAttribute>();
NullReferenceCheckHelper.throwIfNull(equiped_social_action_attribute, () => $"equiped_social_action_action is null !!! - {player.toBasicString()}");
old_social_action_meta_id = (int)equiped_social_action_attribute.SocialActionMetaId;
}
if (socialActionMetaId == 0)
{
var social_action_slot_exchange_log_info = SocialActionBusinessLogHelper.toSocialActionSlotExchangeLogInfo(user_guid, socialActionSlot, old_social_action_meta_id, socialActionMetaId);
var social_action_slot_exchange_business_log = new SocialActionSlotExchangeBusinessLog(social_action_slot_exchange_log_info);
business_logs.Add(social_action_slot_exchange_business_log);
return (result, business_logs);
}
if (!MetaData.Instance._SocialActionTable.TryGetValue(socialActionMetaId, out var social_action_meta_data))
{
err_msg = $"Failed to TryGetValue() !!! : socialActionMetaId:{socialActionMetaId} - {player.toBasicString()}";
result.setFail(ServerErrorCode.SocialActionMetaDataNotFound, err_msg);
Log.getLogger().error(result.toBasicString());
return (result, null);
}
if (!tryGetSocialAction(socialActionMetaId, out var social_action))
{
err_msg = $"Failed to tryGetSocialAction() !!! : socialActionMetaId:{socialActionMetaId} - {player.toBasicString()}";
result.setFail(ServerErrorCode.SocialActionNotFound, err_msg);
Log.getLogger().error(result.toBasicString());
return (result, null);
}
var social_action_action = social_action.getEntityAction<SocialActionAction>();
NullReferenceCheckHelper.throwIfNull(social_action_action, () => $"social_action_action is null !!! - {player.toBasicString()}");
result = social_action_action.tryEquipSocialAction((UInt16)socialActionSlot);
if (result.isFail())
{
err_msg = $"Failed to tryEquipSocialAction() !!! : {result.toBasicString()} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null);
}
{
var social_action_slot_exchange_log_info = SocialActionBusinessLogHelper.toSocialActionSlotExchangeLogInfo(user_guid, socialActionSlot, old_social_action_meta_id, socialActionMetaId);
var social_action_slot_exchange_business_log = new SocialActionSlotExchangeBusinessLog(social_action_slot_exchange_log_info);
business_logs.Add(social_action_slot_exchange_business_log);
}
return (result, business_logs);
}
}

View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerCore; using ServerBase;
using ServerCommon;
namespace GameServer
{
public class SocialAction : EntityBase
{
public SocialAction(EntityBase parent)
: base(EntityType.SocialAction, parent)
{
}
public override async Task<Result> onInit()
{
var parent = getDirectParent();
ArgumentNullException.ThrowIfNull(parent, $"parent is null !!!");
addEntityAttribute(new UserSocialActionAttribute(this));
addEntityAction(new SocialActionAction(this));
return await base.onInit();
}
public override TAttribute getEntityAttribute<TAttribute>()
{
var parent = getRootParent();
ArgumentNullException.ThrowIfNull(parent, $"parent is null !!!");
TAttribute? to_cast_entity_attribute;
if (typeof(TAttribute) == typeof(SocialActionAttributeBase))
{
to_cast_entity_attribute = base.getEntityAttribute<UserSocialActionAttribute>() as TAttribute;
NullReferenceCheckHelper.throwIfNull(to_cast_entity_attribute, () => $"to_cast_entity_attribute is null !!!");
return to_cast_entity_attribute;
}
to_cast_entity_attribute = base.getEntityAttribute<TAttribute>();
NullReferenceCheckHelper.throwIfNull(to_cast_entity_attribute, () => $"to_cast_entity_attribute is null !!!");
return to_cast_entity_attribute;
}
public override TAttribute getOriginEntityAttribute<TAttribute>()
{
var parent = getRootParent();
ArgumentNullException.ThrowIfNull(parent, $"parent is null !!!");
TAttribute? to_cast_entity_attribute;
if (typeof(TAttribute) == typeof(SocialActionAttributeBase))
{
to_cast_entity_attribute = base.getOriginEntityAttribute<UserSocialActionAttribute>() as TAttribute;
NullReferenceCheckHelper.throwIfNull(to_cast_entity_attribute, () => $"to_cast_entity_attribute is null !!!");
return to_cast_entity_attribute;
}
to_cast_entity_attribute = base.getOriginEntityAttribute<TAttribute>();
NullReferenceCheckHelper.throwIfNull(to_cast_entity_attribute, () => $"to_cast_entity_attribute is null !!!");
return to_cast_entity_attribute;
}
public override string toBasicString()
{
return $"{this.getTypeName()}, SocialActionMetaId:{getOriginEntityAttribute<UserSocialActionAttribute>()?.SocialActionMetaId}";
}
public override string toSummaryString()
{
return $"{this.getTypeName()}, {getEntityAttribute<UserSocialActionAttribute>()?.toSummaryString()}";
}
}
}

View File

@@ -0,0 +1,126 @@
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameServer
{
public class DBQSocailActionReadAll : QueryExecutorBase
{
private readonly string m_combination_key_for_pk = string.Empty;
private string m_pk = string.Empty;
private readonly List<SocialActionDoc> m_to_read_social_action_docs = new();
public DBQSocailActionReadAll(string ownerGuid)
: base(typeof(DBQSocailActionReadAll).Name)
{
m_combination_key_for_pk = ownerGuid;
}
//=====================================================================================
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
//=====================================================================================
public override async Task<Result> onPrepareQuery()
{
var result = new Result();
var err_msg = string.Empty;
var owner = getOwner();
var doc = new SocialActionDoc();
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();
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<SocialActionDoc>(query_config, eventTid: query_batch.getTransId());
if (result.isFail())
{
return result;
}
foreach (var read_doc in read_docs)
{
result = owner.getEntityAction<UserSocialActionExecutorAction>(out var found_social_action_executor_action);
if (result.isFail())
{
return result;
}
NullReferenceCheckHelper.throwIfNull(found_social_action_executor_action, () => $"found_social_action_executor_action is null !!!");
result = await found_social_action_executor_action.tryAddSocialActionFromDoc(read_doc);
if (result.isFail())
{
return result;
}
m_to_read_social_action_docs.Add(read_doc);
}
return await Task.FromResult(result);
}
public List<SocialActionDoc> getToReadSocialActionDocs() => m_to_read_social_action_docs;
//=====================================================================================
// DB 쿼리를 성공하고, doFnCommit()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
//=====================================================================================
public override async Task onQueryResponseCommit()
{
await Task.CompletedTask;
}
//=====================================================================================
// DB 쿼리를 실패하고, doFnRollback()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
//=====================================================================================
public override async Task onQueryResponseRollback(Result errorResult)
{
await Task.CompletedTask;
}
public override Player getOwner()
{
var query_batch = getQueryBatch();
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!!");
var owner = query_batch.getLogActor() as Player;
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
return owner;
}
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Amazon.DynamoDBv2.DocumentModel;
using ServerCommon.BusinessLogDomain;
namespace GameServer
{
public static class SocialActionBusinessLogHelper
{
public static SocialActionLogInfo toSocialActionLogInfo(int socialActionId)
{
var social_action_log_info = new SocialActionLogInfo();
social_action_log_info.setSocialActionInfo(socialActionId);
return social_action_log_info;
}
public static void setSocialActionInfo(this SocialActionLogInfo logData, int socialActionId)
{
logData.SocialActionMetaId = socialActionId;
}
public static SocialActionSlotExchangeLogInfo toSocialActionSlotExchangeLogInfo(string usetGuid, int socialActionSlot, int oldSocialActionMetaId, int newSocialActionMetaId)
{
var social_action_slot_exchange_log_info = new SocialActionSlotExchangeLogInfo();
social_action_slot_exchange_log_info.setSocialActionSlotExchangeInfo(usetGuid, socialActionSlot, oldSocialActionMetaId, newSocialActionMetaId);
return social_action_slot_exchange_log_info;
}
public static void setSocialActionSlotExchangeInfo(this SocialActionSlotExchangeLogInfo logData, string usetGuid, int socialActionSlot, int oldSocialActionMetaId, int newSocialActionMetaId)
{
logData.UserGuid = usetGuid;
logData.SocialActionSlot = socialActionSlot;
logData.OldSocialActionMetaId = oldSocialActionMetaId;
logData.NewSocialActionMetaId = newSocialActionMetaId;
}
}
}

View File

@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes;
using ServerCore; using ServerBase;
using ServerCommon;
using static ClientToGameMessage.Types;
namespace GameServer
{
internal static class SocialActionNotifyHelper
{
public static bool send_S2C_NTF_OWNED_SOCIAL_ACTION(this Player player)
{
ArgumentNullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var social_action_agent_action = player.getEntityAction<SocialActionLoadAction>();
NullReferenceCheckHelper.throwIfNull(social_action_agent_action, () => $"social_action_agent_action is null !!! - {player.toBasicString()}");
var ntf_packet = new ClientToGame();
ntf_packet.Message = new ClientToGameMessage();
ntf_packet.Message.OwnedSocialActionNoti = new OwnedSocialActionNoti();
var social_actions = social_action_agent_action.getSocialActions();
foreach (var social_action in social_actions)
{
var social_action_attribute = social_action.getEntityAttribute<UserSocialActionAttribute>();
NullReferenceCheckHelper.throwIfNull(social_action_attribute, () => $"social_action_attribute is null !!! - {player.toBasicString()}");
ntf_packet.Message.OwnedSocialActionNoti.OwnedList.Add((int)social_action_attribute.SocialActionMetaId);
if (social_action_attribute.EquipedPos != 0)
{
var slot_info = new SlotInfo();
slot_info.Slot = social_action_attribute.EquipedPos - 1; // 인덱스가 클라는 0번부터 서버는 1번부터
slot_info.Id = (int)social_action_attribute.SocialActionMetaId;
ntf_packet.Message.OwnedSocialActionNoti.EquipList.Add(slot_info);
}
}
if (false == GameServerApp.getServerLogic().onSendPacket(player, ntf_packet))
{
return false;
}
return true;
}
public static bool send_S2C_NTF_PLAY_SOCIAL_ACTION(this Player player)
{
ArgumentNullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var user_social_action_executor_action = player.getEntityAction<UserSocialActionExecutorAction>();
NullReferenceCheckHelper.throwIfNull(user_social_action_executor_action, () => $"$user_social_action_executor_action is null - {player.toBasicString()}");
var game_zone_action = player.getEntityAction<GameZoneAction>();
NullReferenceCheckHelper.throwIfNull(game_zone_action, () => $"game_zone_action is null - {player.toBasicString()}");
var ntf_packet = new ClientToGame();
ntf_packet.Message = new ClientToGameMessage();
ntf_packet.Message.PlaySocialActionNoti = new PlaySocialActionNoti();
ntf_packet.Message.PlaySocialActionNoti.ActorGuid = player.getUserGuid();
ntf_packet.Message.PlaySocialActionNoti.SocialActionId = user_social_action_executor_action.getPlayingSocialActionMetaId();
ntf_packet.Message.PlaySocialActionNoti.StartTime = user_social_action_executor_action.getPlayingSocialActionStartTime().ToTimestamp();
game_zone_action.broadcast(player, ntf_packet);
return true;
}
public static bool send_S2C_NTF_STOP_SOCIAL_ACTION(this Player player)
{
ArgumentNullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var game_zone_action = player.getEntityAction<GameZoneAction>();
NullReferenceCheckHelper.throwIfNull(game_zone_action, () => $"game_zone_action is null - {player.toBasicString()}");
var ntf_packet = new ClientToGame();
ntf_packet.Message = new ClientToGameMessage();
ntf_packet.Message.StopSocialActionNoti = new StopSocialActionNoti();
ntf_packet.Message.StopSocialActionNoti.ActorGuid = player.getUserGuid();
game_zone_action.broadcast(player, ntf_packet);
return true;
}
public static ClientToGame makeNtfSocialActionAddPacket(int social_action_meta_id)
{
var ntf_packet = new ClientToGame();
ntf_packet.Message = new ClientToGameMessage();
ntf_packet.Message.SocialActionAddNoti = new SocialActionAddNoti();
ntf_packet.Message.SocialActionAddNoti.SocialActionId = social_action_meta_id;
return ntf_packet;
}
}
}

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerCore; using ServerBase;
using ServerCommon;
namespace GameServer
{
public class UserSocialActionExecutorAction : SocialActionLoadAction
{
private Int32 m_playing_social_action_meta_id = 0;
private DateTime m_playing_social_action_start_time = default;
public UserSocialActionExecutorAction(Player owner)
: base(owner)
{
}
public (Result, ClientToGameRes.Types.UseSocialActionRes) tryUseSocialAction(int socialActionMetaId)
{
var result = new Result();
var err_msg = string.Empty;
var owner = getOwner();
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
var res = new ClientToGameRes.Types.UseSocialActionRes();
if (!tryGetSocialAction(socialActionMetaId, out var social_action))
{
err_msg = $"Failed to tryGetSocialAction() !!! : socialActionMetaId:{socialActionMetaId} : {this.getTypeName()} - {owner.toBasicString()}";
result.setFail(ServerErrorCode.SocialActionNotFound, err_msg);
Log.getLogger().error(result.toBasicString());
return (result, res);
}
var social_action_action = social_action.getEntityAction<SocialActionAction>();
NullReferenceCheckHelper.throwIfNull(social_action_action, () => $"social_action_action is null !!! - {owner.toBasicString()}");
if (!social_action_action.isSocialActionOnSlot())
{
err_msg = $"SocialAction is not on slot !!! : {social_action.toBasicString()} : {this.getTypeName()} - {owner.toBasicString()}";
result.setFail(ServerErrorCode.SocialActionNotOnSlot, err_msg);
Log.getLogger().error(result.toBasicString());
return (result, res);
}
m_playing_social_action_meta_id = socialActionMetaId;
m_playing_social_action_start_time = DateTime.UtcNow;
res.SocialActionId = m_playing_social_action_meta_id;
return (result, res);
}
public void stopSocialAction()
{
m_playing_social_action_meta_id = 0;
m_playing_social_action_start_time = default;
}
public int getPlayingSocialActionMetaId() => m_playing_social_action_meta_id;
public DateTime getPlayingSocialActionStartTime() => m_playing_social_action_start_time;
}
}

View File

@@ -0,0 +1,125 @@
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using ServerCore;
using ServerBase;
using ServerCommon;
using ServerCommon.BusinessLogDomain;
using MetaAssets;
namespace GameServer.PacketHandler;
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.ExchangeSocialActionSlotReq), typeof(ExchangeSocialActionSlotPacketHandler), typeof(GameLoginListener))]
internal class ExchangeSocialActionSlotPacketHandler : PacketRecvHandler
{
public static bool send_S2C_ACK_EXCHANGE_SOCIAL_ACTION_SLOT(Player owner, Result result)
{
var ack_packet = new ClientToGame();
ack_packet.Response = new ClientToGameRes();
ack_packet.Response.ErrorCode = result.ErrorCode;
ack_packet.Response.ExchangeSocialActionSlotRes = new();
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
{
return false;
}
return true;
}
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
{
var result = new Result();
var err_msg = string.Empty;
var player = entityWithSession as Player;
NullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var recv_msg = recvMessage as ClientToGame;
NullReferenceCheckHelper.throwIfNull(recv_msg, () => $"recv_msg is null !!! - {player.toBasicString()}");
var request = recv_msg.Request.ExchangeSocialActionSlotReq;
var server_logic = GameServerApp.getServerLogic();
var player_action = player.getEntityAction<PlayerAction>();
NullReferenceCheckHelper.throwIfNull(player_action, () => $"player_action is null !!! - {player.toBasicString()}");
var selected_character = player_action.getSelectedCharacter();
if (null == selected_character)
{
err_msg = $"Not selected Character !!! - {player.toBasicString()}";
result.setFail(ServerErrorCode.CharacterNotSelected, err_msg);
Log.getLogger().error(result.toBasicString());
send_S2C_ACK_EXCHANGE_SOCIAL_ACTION_SLOT(player, result);
return result;
}
var character_action = selected_character.getEntityAction<CharacterAction>();
NullReferenceCheckHelper.throwIfNull(character_action, () => $"character_action is null !!! - {selected_character.toBasicString()}");
if (character_action.isFarming())
{
err_msg = $"Character is Farming !!! - {selected_character.toBasicString()}, {player.toBasicString()}";
result.setFail(ServerErrorCode.FarimgState, err_msg);
Log.getLogger().error(result.toBasicString());
send_S2C_ACK_EXCHANGE_SOCIAL_ACTION_SLOT(player, result);
return result;
}
var social_action_agent_action = player.getEntityAction<SocialActionLoadAction>();
NullReferenceCheckHelper.throwIfNull(social_action_agent_action, () => $"social_action_agent_action is null !!! - {player.toBasicString()}");
var fn_transaction_runner = async delegate ()
{
var result = new Result();
var social_action_slot = request.SocialActionSlot + 1; // 인덱스가 클라는 0번부터 서버는 1번부터
(result, var business_logs) = social_action_agent_action.tryExchangeSocialActionSlot(social_action_slot, request.SocialActionId);
if (result.isFail())
{
err_msg = $"Failed to tryExchangeSocialActionSlot() !!! : {result.toBasicString()} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
send_S2C_ACK_EXCHANGE_SOCIAL_ACTION_SLOT(player, result);
return result;
}
NullReferenceCheckHelper.throwIfNull(business_logs, () => $"business_logs is null !!! - {player.toBasicString()}");
var batch = new QueryBatchEx<QueryRunnerWithDocument>(player, LogActionType.None, server_logic.getDynamoDbClient());
{
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
batch.addQuery(new QueryFinal());
}
batch.appendBusinessLogs(business_logs);
result = await QueryHelper.sendQueryAndBusinessLog(batch);
if (result.isFail())
{
err_msg = $"Failed to sendQueryAndBusinessLog() !!! : {result.toBasicString()} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
send_S2C_ACK_EXCHANGE_SOCIAL_ACTION_SLOT(player, result);
return result;
}
send_S2C_ACK_EXCHANGE_SOCIAL_ACTION_SLOT(player, result);
return result;
};
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "ExchangeSocialActionSlot", fn_transaction_runner);
if (result.isFail())
{
err_msg = $"Failed to runTransactionRunnerSafely() !!! : {result.toBasicString()} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
}
return result;
}
}

View File

@@ -0,0 +1,87 @@
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using ServerCore;
using ServerBase;
using ServerCommon;
using ServerCommon.BusinessLogDomain;
using MetaAssets;
namespace GameServer.PacketHandler;
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.StopSocialActionReq), typeof(StopSocialActionPacketHandler), typeof(GameLoginListener))]
internal class StopSocialActionPacketHandler : PacketRecvHandler
{
public static bool send_S2C_ACK_STOP_SOCIAL_ACTION(Player owner, Result result)
{
var ack_packet = new ClientToGame();
ack_packet.Response = new ClientToGameRes();
ack_packet.Response.ErrorCode = result.ErrorCode;
ack_packet.Response.StopSocialActionRes = new();
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
{
return false;
}
return true;
}
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
{
await Task.CompletedTask;
var result = new Result();
var player = entityWithSession as Player;
ArgumentNullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var game_msg = recvMessage as ClientToGame;
ArgumentNullReferenceCheckHelper.throwIfNull(game_msg, () => $"game_msg is null !!! - {player.toBasicString()}");
var player_action = player.getEntityAction<PlayerAction>();
NullReferenceCheckHelper.throwIfNull(player_action, () => $"player_action is null !!! - {player.toBasicString()}");
var selected_character = player_action.getSelectedCharacter();
if (null == selected_character)
{
var err_msg = $"Not selected Character !!! - {player.toBasicString()}";
result.setFail(ServerErrorCode.CharacterNotSelected, err_msg);
Log.getLogger().error(result.toBasicString());
send_S2C_ACK_STOP_SOCIAL_ACTION(player, result);
return result;
}
var character_action = selected_character.getEntityAction<CharacterAction>();
NullReferenceCheckHelper.throwIfNull(character_action, () => $"character_action is null !!! - {selected_character.toBasicString()}");
if (character_action.isFarming())
{
var err_msg = $"Character is Farming !!! - {selected_character.toBasicString()}, {player.toBasicString()}";
result.setFail(ServerErrorCode.FarimgState, err_msg);
Log.getLogger().error(result.toBasicString());
send_S2C_ACK_STOP_SOCIAL_ACTION(player, result);
return result;
}
result = player.getEntityAction<UserSocialActionExecutorAction>(out var social_action_executor_action);
if(result.isFail())
{
send_S2C_ACK_STOP_SOCIAL_ACTION(player, result);
return result;
}
NullReferenceCheckHelper.throwIfNull(social_action_executor_action, () => $"social_action_executor_action is null !!! - {player.toBasicString()}");
social_action_executor_action.stopSocialAction();
send_S2C_ACK_STOP_SOCIAL_ACTION(player, result);
player.send_S2C_NTF_STOP_SOCIAL_ACTION();
return result;
}
}

View File

@@ -0,0 +1,97 @@
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using ServerCore;
using ServerBase;
using ServerCommon;
using ServerCommon.BusinessLogDomain;
using MetaAssets;
using static ClientToGameRes.Types;
namespace GameServer.PacketHandler;
[PacketHandler(typeof(ClientToGameReq), typeof(ClientToGameReq.Types.UseSocialActionReq), typeof(UseSocialActionPacketHandler), typeof(GameLoginListener))]
internal class UseSocialActionPacketHandler : PacketRecvHandler
{
public static bool send_S2C_ACK_USE_SOCIAL_ACTION(Player owner, Result result, UseSocialActionRes ack)
{
var ack_packet = new ClientToGame();
ack_packet.Response = new ClientToGameRes();
ack_packet.Response.ErrorCode = result.ErrorCode;
ack_packet.Response.UseSocialActionRes = ack;
if (false == GameServerApp.getServerLogic().onSendPacket(owner, ack_packet))
{
return false;
}
return true;
}
public override async Task<Result> onProcessPacket(ISession entityWithSession, Google.Protobuf.IMessage recvMessage)
{
var player = entityWithSession as Player;
ArgumentNullReferenceCheckHelper.throwIfNull(player, () => $"player is null !!!");
var req_msg = recvMessage as ClientToGame;
ArgumentNullReferenceCheckHelper.throwIfNull(req_msg, () => $"req_msg is null !!! - {player.toBasicString()}");
var request = req_msg.Request.UseSocialActionReq;
ArgumentNullReferenceCheckHelper.throwIfNull(request, () => $"request is null !!! - {player.toBasicString()}");
var result = new Result();
var err_msg = string.Empty;
var player_action = player.getEntityAction<PlayerAction>();
NullReferenceCheckHelper.throwIfNull(player_action, () => $"player_action is null !!! - {player.toBasicString()}");
var ack = new UseSocialActionRes();
var selected_character = player_action.getSelectedCharacter();
if (null == selected_character)
{
err_msg = $"Not selected Character !!! - {player.toBasicString()}";
result.setFail(ServerErrorCode.CharacterNotSelected, err_msg);
Log.getLogger().error(result.toBasicString());
send_S2C_ACK_USE_SOCIAL_ACTION(player, result, ack);
return result;
}
var character_action = selected_character.getEntityAction<CharacterAction>();
NullReferenceCheckHelper.throwIfNull(character_action, () => $"character_action is null !!! - {player.toBasicString()}");
if (character_action.isFarming())
{
err_msg = $"Character is Farming !!! - {selected_character.toBasicString()}, {player.toBasicString()}";
result.setFail(ServerErrorCode.FarimgState, err_msg);
Log.getLogger().error(result.toBasicString());
send_S2C_ACK_USE_SOCIAL_ACTION(player, result, ack);
return result;
}
var user_social_action_executor_action = player.getEntityAction<UserSocialActionExecutorAction>();
NullReferenceCheckHelper.throwIfNull(user_social_action_executor_action, () => $"user_social_action_executor_action is null !!! - {player.toBasicString()}");
(result, ack) = user_social_action_executor_action.tryUseSocialAction(request.SocialActionId);
if (result.isFail())
{
err_msg = $"Failed to tryUseSocialAction() !!! : {result.toBasicString()} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
send_S2C_ACK_USE_SOCIAL_ACTION(player, result, ack);
return result;
}
send_S2C_ACK_USE_SOCIAL_ACTION(player, result, ack);
player.send_S2C_NTF_PLAY_SOCIAL_ACTION();
await QuestManager.It.QuestCheck(player, new QuestSocialAction(EQuestEventTargetType.SOCIALACTION, EQuestEventNameType.USED, request.SocialActionId));
return result;
}
}

View File

@@ -0,0 +1,61 @@
using ServerCommon;
using ServerCore; using ServerBase;
namespace GameServer;
[ChatCommandAttribute("socialactionall", typeof(ChatCommandSocialActionAll), AuthAdminLevelType.Developer, AuthAdminLevelType.GmNormal, AuthAdminLevelType.GmSuper)]
internal class ChatCommandSocialActionAll : ChatCommandBase
{
public override async Task invoke(Player player, string token, string[] args)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
NullReferenceCheckHelper.throwIfNull(server_logic, () => $"server_logic is null !!! - {player.toBasicString()}");
var social_action_load_action = player.getEntityAction<SocialActionLoadAction>();
NullReferenceCheckHelper.throwIfNull(social_action_load_action, () => $"social_action_load_action is null !!! - {player.toBasicString()}");
var fn_transaction_runner = async delegate ()
{
var result = new Result();
foreach (var social_action_meta_data in MetaData.Instance._SocialActionTable.Values)
{
if (social_action_load_action.isOwnedSocialAction(social_action_meta_data.SocialActionId))
{
continue;
}
await social_action_load_action.tryAddSocialActionFromMetaId(social_action_meta_data.SocialActionId);
}
var batch = new QueryBatchEx<QueryRunnerWithDocument>(player, LogActionType.None, server_logic.getDynamoDbClient());
{
batch.addQuery(new DBQWriteToAttributeAllWithTransactionRunner());
batch.addQuery(new QueryFinal());
}
result = await QueryHelper.sendQueryAndBusinessLog(batch);
if (result.isFail())
{
err_msg = $"Failed to sendQueryAndBusinessLog() !!! : {result.toBasicString()} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
return result;
}
player.send_S2C_NTF_OWNED_SOCIAL_ACTION();
return result;
};
result = await player.runTransactionRunnerSafely(TransactionIdType.PrivateContents, "ExchangeSocialActionSlot", fn_transaction_runner);
if (result.isFail())
{
err_msg = $"Failed to runTransactionRunnerSafely() !!! : {result.toBasicString()} - {player.toBasicString()}";
Log.getLogger().error(err_msg);
}
}
}