using Google.Protobuf.WellKnownTypes; using ServerCommon; using ServerCore; using ServerBase; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GameServer { internal static class BuildingProfitHistoryHelper { public static BuildingProfitHistoryInfo toBuildingProfitHistoryInfo(this BuildingProfitHistory buildingProfitHistory) { var building_profit_history_attribute = buildingProfitHistory.getEntityAttribute(); NullReferenceCheckHelper.throwIfNull(building_profit_history_attribute, () => $"building_profit_history_attribute is null !!!"); var building_profit_history_info = new BuildingProfitHistoryInfo { HistoryDate = building_profit_history_attribute.ProfitTime.ToTimestamp(), Floor = (int)building_profit_history_attribute.Floor, ProfitHistoryType = building_profit_history_attribute.ProfitHistoryType, FloorProfit = new FloorProfitInfo() }; foreach (var (currency_type, currency_amount) in building_profit_history_attribute.Profits) { var money = new Money(); money.Amount = currency_amount; building_profit_history_info.FloorProfit.Profits.Add((int)currency_type, money); } return building_profit_history_info; } public static async Task<(Result, BuildingProfitHistory?, DynamoDbDocBase?)> tryMakeBuildingProfitHistory(Building building, int buildingMetaId, int floor, DateTime profitTime, ProfitHistoryType profitHistoryType, Dictionary profits) { var result = new Result(); var err_msg = string.Empty; var building_profit_history = new BuildingProfitHistory(building); await building_profit_history.onInit(); var building_profit_history_attribute = building_profit_history.getEntityAttribute(); NullReferenceCheckHelper.throwIfNull(building_profit_history_attribute, () => $"building_profit_history_attribute is null !!!"); building_profit_history_attribute.BuildingMetaId = buildingMetaId; building_profit_history_attribute.Floor = floor; building_profit_history_attribute.ProfitTime = profitTime; building_profit_history_attribute.ProfitHistoryType = profitHistoryType; building_profit_history_attribute.Profits = profits; building_profit_history_attribute.newEntityAttribute(); (result, var building_profit_history_doc) = await building_profit_history_attribute.toDocBase(); if (result.isFail()) { err_msg = $"Failed to toDocBase() !!! : {result.toBasicString()}"; Log.getLogger().error(err_msg); return (result, null, null); } return (result, building_profit_history, building_profit_history_doc); } } }