Files
caliverse_server/GameServer/Event/EventManager.cs
2025-05-01 07:20:41 +09:00

87 lines
3.0 KiB
C#

using Google.Protobuf.WellKnownTypes;
using ServerCommon;
using ServerCore; using ServerBase;
using System.Collections.Concurrent;
using System.Security.Claims;
using Amazon.DynamoDBv2.Model.Internal.MarshallTransformations;
using GameServer;
namespace GameServer
{
public class EventManager : Singleton<EventManager>
{
//private static readonly EventManager _instance = new EventManager();
//public static EventManager Instance { get { return _instance; } }
private ConcurrentDictionary<int, MetaAssets.ClaimMetaData> AcceptableClaim = new();
//private ConcurrentDictionary<int, MetaAssets.ClaimMetaData> NextDeletableClaim = new();
public EventManager()
{
OnInit();
}
private void OnInit()
{
DateTime now_dt = DateTimeHelper.Current;
AcceptableClaim = new();
foreach (MetaAssets.ClaimMetaData claim in MetaData.Instance._ClaimTable)
{
if (now_dt > claim.EndTime) continue; // 이미 종료된 이벤트는 무시
if (AcceptableClaim.TryAdd(claim.ClaimId, claim) == false)
{
Log.getLogger().error($"{claim.ClaimId} Add Error");
continue;
}
}
}
public (List<int>, List<int>) claimEventActiveCheckAndGet()
{
DateTime now_dt = DateTime.UtcNow;
List<int> deletables = new List<int>();
List<int> currents = new List<int>();
foreach (var claime in AcceptableClaim)
{
//삭제 가능 이벤트 중에 지난 것들 deletables에 추가
if (claime.Value.EndTime < now_dt) deletables.Add(claime.Key);
if (claime.Value.StartTime <= now_dt && now_dt < claime.Value.EndTime) currents.Add(claime.Key);
}
foreach (int idx in deletables)
{
if (AcceptableClaim.TryRemove(idx, out var claimData) == false)
{
Log.getLogger().error($"NextAcceptableClaim TryRemove Error idx : idx");
}
}
return (deletables, currents);
}
public async Task playerClaimUpdateAndNoti(Player player, List<Int32> deletableClaimIds, List<Int32> currentClaimsIds)
{
var server_logic = GameServerApp.getServerLogic();
var claim_action = player.getEntityAction<ClaimAction>();
NullReferenceCheckHelper.throwIfNull(claim_action, () => $"claim_action is null !!!");
var is_load = claim_action.getDataLoad();
if (is_load == false) return;
(var result, var acceptables, var deletables) = await claim_action.update();
if(result.isFail()) return;
if (acceptables.Count > 0)
{
claim_action.send_GS2C_NTF_CLAIM_UPDATE();
}
}
}
}