초기커밋

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,22 @@
using ServerCommon.BusinessLogDomain;
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 BuildingProfitBusinessLogHelper
{
public static BuildingProfitLogInfo toBuildingProfitLogInfo(int buildingMetaId, int floor, CurrencyType currencyType, AmountDeltaType amountDeltaType, double deltaAmount, double currencyAmount)
{
var building_profit_log_info = new BuildingProfitLogInfo();
building_profit_log_info.setLogProperty(buildingMetaId, floor, currencyType, amountDeltaType, deltaAmount, currencyAmount);
return building_profit_log_info;
}
}
}

View File

@@ -0,0 +1,123 @@
using Amazon.DynamoDBv2.Model;
using Amazon.DynamoDBv2;
using Amazon.Runtime.Internal.Transform;
using ServerCommon;
using ServerCore; using ServerBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Org.BouncyCastle.Asn1.Ocsp;
namespace GameServer
{
internal static class BuildingProfitHelper
{
public static FloorProfitInfo toFloorProfitInfo(this BuildingProfit buildingProfit)
{
var building_profit_attribute = buildingProfit.getEntityAttribute<BuildingProfitAttribute>();
NullReferenceCheckHelper.throwIfNull(building_profit_attribute, () => $"building_profit_history_attribute is null !!!");
var floor_profit_info = new FloorProfitInfo();
foreach (var (currency_type, currency_amount) in building_profit_attribute.Profits)
{
var money = new Money();
money.Amount = currency_amount;
floor_profit_info.Profits.Add((int)currency_type, money);
}
return floor_profit_info;
}
public static (Result, DynamoDbItemRequestQueryContext?) tryMakeUpdateItemRequestFromBuildingProfit(int buildingMetaId, int floor, CurrencyType currencyType, double deltaAmount)
{
var result = new Result();
var err_msg = string.Empty;
var server_logic = GameServerApp.getServerLogic();
var db_client = server_logic.getDynamoDbClient();
var doc = new BuildingProfitDoc(buildingMetaId, floor);
var primary_key = doc.getPrimaryKey();
var query_builder = new DynamoDbItemRequestHelper.UpdateItemRequestBuilder(db_client.getTableFullName(doc.TableName));
query_builder.withKeys(primary_key.toKeyWithAttributeValue());
var attrib_path_json_string = doc.toJsonStringOfAttribs();
var target_key = JsonHelper.getJsonPropertyName<BuildingProfitAttrib>(nameof(BuildingProfitAttrib.Profits));
(var is_success, var attribute_expression) = DynamoDbClientHelper.toAttributeExpressionFromJson(attrib_path_json_string, target_key);
if (false == is_success)
{
err_msg = $"Failed to DynamoDbClientHelper.toAttributeExpressionFromJson() !!! : attribPath:{attrib_path_json_string}, targetKey:{target_key}";
result.setFail(ServerErrorCode.AttribPathMakeFailed, err_msg);
Log.getLogger().error(result.toBasicString());
return (result, null);
}
var attributeNames = DynamoDbClientHelper.toExpressionAttributeNamesFromJson(attrib_path_json_string, target_key);
attributeNames.Add($"#{currencyType}", currencyType.ToString());
query_builder.withExpressionAttributeNames(attributeNames);
attribute_expression += $".#{currencyType}";
var update_expression = (deltaAmount >= 0)
? $"SET {attribute_expression} = if_not_exists({attribute_expression}, :start) + :changeValue"
: $"SET {attribute_expression} = if_not_exists({attribute_expression}, :start) - :changeValue";
query_builder.withUpdateExpression(update_expression);
var expression_attribute_values = new Dictionary<string, AttributeValue>
{
{ ":changeValue", new AttributeValue { N = Math.Abs(deltaAmount).ToString() } },
{ ":start", new AttributeValue { N = "0" } }
};
query_builder.withExpressionAttributeValues(expression_attribute_values);
query_builder.withReturnValues(ReturnValue.ALL_NEW);
(result, var update_item_request) = query_builder.build();
if (result.isFail())
{
err_msg = $"Failed to DynamoDbItemRequestHelper.build() !!! : {result.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null);
}
NullReferenceCheckHelper.throwIfNull(update_item_request, () => $"update_item_request is null !!! - {primary_key.toBasicString()}");
return (result, update_item_request.createItemRequestQueryContext(QueryType.Update));
}
public static async Task<(Result, BuildingProfit?, DynamoDbDocBase?)> tryMakeBuildingProfit(Building building, int buildingMetaId, int floor, CurrencyType currencyType, double currencyAmount)
{
var result = new Result();
var err_msg = string.Empty;
var building_profit = new BuildingProfit(building);
await building_profit.onInit();
var new_building_profit_attribute = building_profit.getEntityAttribute<BuildingProfitAttribute>();
NullReferenceCheckHelper.throwIfNull(new_building_profit_attribute, () => $"new_building_profit_attribute is null !!!");
new_building_profit_attribute.BuildingMetaId = buildingMetaId;
new_building_profit_attribute.Floor = floor;
new_building_profit_attribute.Profits[currencyType] = currencyAmount;
new_building_profit_attribute.newEntityAttribute();
(result, var building_profit_doc) = await new_building_profit_attribute.toDocBase();
if (result.isFail())
{
err_msg = $"Failed to toDocBase() !!! : {result.toBasicString()}";
Log.getLogger().error(err_msg);
return (result, null, null);
}
NullReferenceCheckHelper.throwIfNull(building_profit_doc, () => $"building_profit_doc is null !!!");
return (result, building_profit, building_profit_doc);
}
}
}

View File

@@ -0,0 +1,55 @@
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;
using static ServerMessage.Types;
namespace GameServer
{
internal static class BuildingProfitNotifyHelper
{
public static bool send_GS2GS_NTF_MODIFY_BUILDING_PROFIT(int buildingMetaId, List<(int, CurrencyType, double)> profits)
{
var server_logic = GameServerApp.getServerLogic();
var message = new ServerMessage();
message.NtfModifyBuildingProfit = new GS2GS_NTF_MODIFY_BUILDING_PROFIT();
message.NtfModifyBuildingProfit.ExceptServerName = server_logic.getServerName();
message.NtfModifyBuildingProfit.BuildingMetaId = buildingMetaId;
foreach (var (floor, currency_type, delta_amount) in profits)
{
if (!message.NtfModifyBuildingProfit.FloorProfits.TryGetValue(floor, out var floor_profits))
{
floor_profits = new FloorProfitInfo();
message.NtfModifyBuildingProfit.FloorProfits[floor] = floor_profits;
}
var money = new Money();
money.Amount = delta_amount;
floor_profits.Profits[(int)currency_type] = money;
}
var rabbit_mq = server_logic.getRabbitMqConnector() as RabbitMQ4Game;
NullReferenceCheckHelper.throwIfNull(rabbit_mq, () => $"rabbit_mq is null !!!");
rabbit_mq.sendMessageToExchangeAllGame(message);
return true;
}
public static bool send_GS2GS_NTF_MODIFY_BUILDING_PROFIT(int buildingMetaId, int floor, CurrencyType currencyType, double currencyAmount)
{
var modify_profits = new List<(int, CurrencyType, double)>();
modify_profits.Add((floor, currencyType, currencyAmount));
return send_GS2GS_NTF_MODIFY_BUILDING_PROFIT(buildingMetaId, modify_profits);
}
}
}