73 lines
3.0 KiB
C#
73 lines
3.0 KiB
C#
using Google.Protobuf;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using ServerCommon;
|
|
using ServerCommon.BusinessLogDomain;
|
|
using MetaAssets;
|
|
|
|
|
|
|
|
namespace GameServer.PacketHandler;
|
|
|
|
[PacketHandler("allgameserver", typeof(ServerMessage.Types.GS2GS_NTF_ADD_BUILDING_PROFIT_HISTORY), typeof(NtfAddBuildingProfitHistoryMQPacketHandler), typeof(RabbitMQ4Game))]
|
|
internal class NtfAddBuildingProfitHistoryMQPacketHandler : PacketRecvHandler
|
|
{
|
|
public override async Task<Result> onProcessPacket(ISession session, IMessage recvMessage)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
var server_logic = GameServerApp.getServerLogic();
|
|
ArgumentNullException.ThrowIfNull(server_logic, $"server_logic is null !!!");
|
|
|
|
var message = recvMessage as ServerMessage;
|
|
ArgumentNullException.ThrowIfNull(message, $"message is null !!!");
|
|
|
|
var ntf_add_building_profit_history = message.NtfAddBuildingProfitHistory;
|
|
ArgumentNullException.ThrowIfNull(ntf_add_building_profit_history, $"ntf_add_building_profit_history is null !!!");
|
|
|
|
if (ntf_add_building_profit_history.ExceptServerName == server_logic.getServerName())
|
|
return result;
|
|
|
|
Log.getLogger().info($"MQ - NtfAddBuildingProfitHistory");
|
|
|
|
if (!server_logic.getBuildingManager().tryGetBuilding(ntf_add_building_profit_history.BuildingMetaId, out var building))
|
|
{
|
|
err_msg = $"Failed to tryGetBuilding() !!! : buildingMetaId:{ntf_add_building_profit_history.BuildingMetaId}";
|
|
result.setFail(ServerErrorCode.BuildingNotFound, err_msg);
|
|
Log.getLogger().error(result.toBasicString());
|
|
|
|
return result;
|
|
}
|
|
|
|
var profits = new Dictionary<CurrencyType, double>();
|
|
foreach(var (key, value) in ntf_add_building_profit_history.FloorProfit.Profits)
|
|
{
|
|
var currency_type = (CurrencyType)key;
|
|
|
|
profits[currency_type] = value.Amount;
|
|
}
|
|
|
|
var building_profit_history_agent_action = building.getEntityAction<BuildingProfitHistoryAgentAction>();
|
|
NullReferenceCheckHelper.throwIfNull(building_profit_history_agent_action, () => $"building_profit_history_agent_action is null !!!");
|
|
|
|
(result, var building_profit_history, _) = await BuildingProfitHistoryHelper.tryMakeBuildingProfitHistory(building, ntf_add_building_profit_history.BuildingMetaId, ntf_add_building_profit_history.Floor, ntf_add_building_profit_history.ProfitTime.ToDateTime(), ntf_add_building_profit_history.ProfitHistoryType, profits);
|
|
if (result.isFail())
|
|
{
|
|
err_msg = $"Failed to tryMakeBuildingProfitHistory() !!! : {result.toBasicString()}";
|
|
Log.getLogger().error(err_msg);
|
|
|
|
return result;
|
|
}
|
|
NullReferenceCheckHelper.throwIfNull(building_profit_history, () => $"building_profit_history is null !!!");
|
|
|
|
// Memory
|
|
building_profit_history_agent_action.addBuildingProfitHistory(building_profit_history);
|
|
|
|
return result;
|
|
}
|
|
}
|