초기커밋
This commit is contained in:
285
GameServer/Event/ClaimRewardHelper.cs
Normal file
285
GameServer/Event/ClaimRewardHelper.cs
Normal file
@@ -0,0 +1,285 @@
|
||||
using GameServer;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Nettention.Proud;
|
||||
using ServerCommon;
|
||||
using ServerCore; using ServerBase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GameServer
|
||||
{
|
||||
public static class ClaimRewardHelper
|
||||
{
|
||||
|
||||
public static (Result, ClaimMetaData?) getClaimMeta(int claimId, MetaAssets.ClaimType type)
|
||||
{
|
||||
var result = new Result();
|
||||
if (!MetaData.Instance._ClaimMetaTable.TryGetValue((claimId, type), out var metaData))
|
||||
{
|
||||
string err_msg = $"_ClaimDataTable claimId = {claimId} Data not exist";
|
||||
result.setFail(ServerErrorCode.ClaimInfoNotExist, err_msg);
|
||||
return (result, null);
|
||||
}
|
||||
return (result, metaData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static List<ClaimMetaData> getReadyClaims()
|
||||
{
|
||||
List<ClaimMetaData> rets = new();
|
||||
DateTime now = DateTimeHelper.Current;
|
||||
|
||||
foreach (ClaimMetaData metaData in MetaData.Instance._ClaimMetaTable.Values)
|
||||
{
|
||||
if (now < metaData.StartTime )
|
||||
{
|
||||
rets.Add(metaData);
|
||||
}
|
||||
}
|
||||
return rets;
|
||||
}
|
||||
|
||||
public static List<ClaimMetaData> getCurrentClaims()
|
||||
{
|
||||
List<ClaimMetaData> rets = new();
|
||||
DateTime nowDt = DateTimeHelper.Current;
|
||||
|
||||
foreach (ClaimMetaData metaData in MetaData.Instance._ClaimMetaTable.Values)
|
||||
{
|
||||
if (metaData.StartTime <= nowDt && nowDt <= metaData.EndTime)
|
||||
{
|
||||
rets.Add(metaData);
|
||||
}
|
||||
}
|
||||
return rets;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static Dictionary<Int32, ClaimEventActiveInfo> MakeClaimSendInfo(Player owner, MetaAssets.ClaimType type)
|
||||
{
|
||||
var claim_action = owner.getEntityAction<ClaimAction>();
|
||||
var claims = claim_action.getClaims(type);
|
||||
List<int> normal_keys = claims.Keys.ToList();
|
||||
|
||||
Dictionary<Int32, ClaimEventActiveInfo> infos = new();
|
||||
|
||||
DateTime notDt = DateTimeHelper.Current;
|
||||
|
||||
foreach (int key in normal_keys)
|
||||
{
|
||||
var claim = claims[key];
|
||||
var claim_attribute = claim.getEntityAttribute<ClaimAttribute>();
|
||||
if (claim_attribute is null)
|
||||
{
|
||||
Log.getLogger().error($"claim_attribute is null !!!");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (false == MetaData.Instance._ClaimMetaTable.TryGetValue((key, type), out var metaData))
|
||||
{
|
||||
Log.getLogger().warn($"ClaimMetaData not exist. claimId = {key}");
|
||||
continue;
|
||||
}
|
||||
if (false == metaData.DetailInfo.TryGetValue(claim_attribute.ActiveRewardIdx, out var detailInfo))
|
||||
{
|
||||
Log.getLogger().warn($"ClaimMetaData not exist. claimId = {key}, claim_attribute.ActiveRewardIdx = {claim_attribute.ActiveRewardIdx}");
|
||||
continue;
|
||||
}
|
||||
|
||||
ClaimEventActiveInfo info = SetInfo(claim_attribute, detailInfo, notDt);
|
||||
infos.TryAdd(key, info);
|
||||
}
|
||||
return infos;
|
||||
}
|
||||
private static ClaimEventActiveInfo SetInfo(ClaimAttribute info, ClaimRewardDetail detailInfo, DateTime now)
|
||||
{
|
||||
ClaimEventActiveInfo newInfo = new();
|
||||
newInfo.ActiveRewardIdx = info.ActiveRewardIdx;
|
||||
newInfo.IsComplete = info.IsComplete;
|
||||
|
||||
var nextRewardTime = info.ActiveTime.AddSeconds(detailInfo.CoolTime);
|
||||
var time_diff = (nextRewardTime - now);
|
||||
long remainTime = (long)time_diff.TotalSeconds;
|
||||
if (remainTime < 0) remainTime = 0;
|
||||
newInfo.RewardRemainSecond = remainTime;
|
||||
|
||||
return newInfo;
|
||||
}
|
||||
|
||||
private static void SetClaimData(Player owner, ClientToGame clientToGame, ClaimRewardDetail normalDetailInfo, ClaimRewardDetail membershipDetailInfo, DateTime now, bool isResponse)
|
||||
{
|
||||
if (isResponse)
|
||||
{
|
||||
// clientToGame.Response = new();
|
||||
// clientToGame.Response.ErrorCode = ServerErrorCode.Success;
|
||||
// clientToGame.Response.GetClaimInfoRes = new();
|
||||
// clientToGame.Response.GetClaimInfoRes.ClaimId = normalInfo.ClaimId;
|
||||
// clientToGame.Response.GetClaimInfoRes.NormalInfo = SetInfo(normalInfo, normalDetailInfo, now);
|
||||
// clientToGame.Response.GetClaimInfoRes.MembershipInfo = SetInfo(membershipInfo, membershipDetailInfo, now);
|
||||
}
|
||||
else
|
||||
{
|
||||
// clientToGame.Message = new();
|
||||
// clientToGame.Message.ClaimUpdateNoti = new();
|
||||
// clientToGame.Message.ClaimUpdateNoti.ClaimId = normalInfo.ClaimId;
|
||||
// clientToGame.Message.ClaimUpdateNoti.NormalInfo = SetInfo(normalInfo, normalDetailInfo, now);
|
||||
// clientToGame.Message.ClaimUpdateNoti.MembershipInfo = SetInfo(membershipInfo, membershipDetailInfo, now);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
internal static List<ClientToGame> MakeClaimNotiSendInfo(Player player)
|
||||
{
|
||||
List<ClientToGame> clientToGames = new();
|
||||
|
||||
Timestamp nowTS = DateTime.UtcNow.ToTimestamp();
|
||||
|
||||
|
||||
List<int> keys = player.claimNormalEntity.Attr.Infos.Keys.ToList();
|
||||
|
||||
|
||||
foreach (int key in keys)
|
||||
{
|
||||
ClientToGame clientToGame = new();
|
||||
clientToGame.Message = new();
|
||||
clientToGame.Message.ClaimUpdateNoti = new();
|
||||
|
||||
|
||||
var normalInfo = player.claimNormalEntity.Attr.Infos[key];
|
||||
var membershipInfo = player.claimMembershipEntity.Attr.Infos[key];
|
||||
int claimId = normalInfo.ClaimId;
|
||||
if (!TableData.Instance._ClaimDataTable.TryGetValue((claimId, EClaimType.Normal), out var normalMetaData))
|
||||
{
|
||||
//log
|
||||
continue;
|
||||
}
|
||||
if (!normalMetaData.DetailInfo.TryGetValue(normalInfo.ActiveRewardIdx, out var normalDetailInfo))
|
||||
{
|
||||
//log
|
||||
continue;
|
||||
}
|
||||
if (!TableData.Instance._ClaimDataTable.TryGetValue((claimId, EClaimType.Membership), out var membershipMetaData))
|
||||
{
|
||||
//log
|
||||
continue;
|
||||
}
|
||||
if (!membershipMetaData.DetailInfo.TryGetValue(membershipInfo.ActiveRewardIdx, out var membershipDetailInfo))
|
||||
{
|
||||
//log
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
clientToGame.Message.ClaimUpdateNoti.ClaimId = normalInfo.ClaimId;
|
||||
clientToGame.Message.ClaimUpdateNoti.NormalInfo = new();
|
||||
clientToGame.Message.ClaimUpdateNoti.NormalInfo.ActiveRewardIdx = normalInfo.ActiveRewardIdx;
|
||||
clientToGame.Message.ClaimUpdateNoti.NormalInfo.IsComplete = normalInfo.IsComplete;
|
||||
long nextRewardTimeSec = normalInfo.ActiveTime.Seconds + normalDetailInfo.CoolTime;
|
||||
long remainTime = (nextRewardTimeSec - nowTS.Seconds);
|
||||
if(remainTime < 0) remainTime = 0;
|
||||
clientToGame.Message.ClaimUpdateNoti.NormalInfo.RewardRemainSecond = remainTime;
|
||||
|
||||
|
||||
|
||||
clientToGame.Message.ClaimUpdateNoti.MembershipInfo = new();
|
||||
clientToGame.Message.ClaimUpdateNoti.MembershipInfo.ActiveRewardIdx = membershipInfo.ActiveRewardIdx;
|
||||
clientToGame.Message.ClaimUpdateNoti.MembershipInfo.IsComplete = membershipInfo.IsComplete;
|
||||
long nextMembershipRewardTimeSec = membershipInfo.ActiveTime.Seconds + membershipDetailInfo.CoolTime;
|
||||
long membershipRemainTime = (nextMembershipRewardTimeSec - nowTS.Seconds);
|
||||
if (membershipRemainTime < 0) membershipRemainTime = 0;
|
||||
clientToGame.Message.ClaimUpdateNoti.MembershipInfo.RewardRemainSecond = membershipRemainTime;
|
||||
|
||||
|
||||
clientToGames.Add(clientToGame);
|
||||
}
|
||||
|
||||
|
||||
return clientToGames;
|
||||
}
|
||||
|
||||
|
||||
internal static List<ClientToGame> MakeClaimSendInfo(Player player)
|
||||
{
|
||||
List<ClientToGame> clientToGames = new();
|
||||
|
||||
Timestamp nowTS = DateTime.UtcNow.ToTimestamp();
|
||||
|
||||
|
||||
List<int> keys = player.claimNormalEntity.Attr.Infos.Keys.ToList();
|
||||
|
||||
|
||||
foreach (int key in keys)
|
||||
{
|
||||
ClientToGame clientToGame = new();
|
||||
clientToGame.Response = new();
|
||||
clientToGame.Response.GetClaimInfoRes = new();
|
||||
|
||||
|
||||
var normalInfo = player.claimNormalEntity.Attr.Infos[key];
|
||||
var membershipInfo = player.claimMembershipEntity.Attr.Infos[key];
|
||||
int claimId = normalInfo.ClaimId;
|
||||
|
||||
if (!TableData.Instance._ClaimDataTable.TryGetValue((claimId, EClaimType.Normal), out var normalMetaData))
|
||||
{
|
||||
//log
|
||||
continue;
|
||||
}
|
||||
if (!normalMetaData.DetailInfo.TryGetValue(normalInfo.ActiveRewardIdx, out var normalDetailInfo))
|
||||
{
|
||||
//log
|
||||
continue;
|
||||
}
|
||||
if (!TableData.Instance._ClaimDataTable.TryGetValue((claimId, EClaimType.Membership), out var membershipMetaData))
|
||||
{
|
||||
//log
|
||||
continue;
|
||||
}
|
||||
if (!membershipMetaData.DetailInfo.TryGetValue(membershipInfo.ActiveRewardIdx, out var membershipDetailInfo))
|
||||
{
|
||||
//log
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
clientToGame.Response.GetClaimInfoRes.ClaimId = normalInfo.ClaimId;
|
||||
clientToGame.Response.GetClaimInfoRes.NormalInfo = new();
|
||||
clientToGame.Response.GetClaimInfoRes.NormalInfo.ActiveRewardIdx = normalInfo.ActiveRewardIdx;
|
||||
clientToGame.Response.GetClaimInfoRes.NormalInfo.IsComplete = normalInfo.IsComplete;
|
||||
long nextRewardTimeSec = normalInfo.ActiveTime.Seconds + normalDetailInfo.CoolTime;
|
||||
long remainTime = (nextRewardTimeSec - nowTS.Seconds);
|
||||
if (remainTime < 0) remainTime = 0;
|
||||
clientToGame.Response.GetClaimInfoRes.NormalInfo.RewardRemainSecond = remainTime;
|
||||
|
||||
|
||||
clientToGame.Response.GetClaimInfoRes.MembershipInfo = new();
|
||||
clientToGame.Response.GetClaimInfoRes.MembershipInfo.ActiveRewardIdx = membershipInfo.ActiveRewardIdx;
|
||||
clientToGame.Response.GetClaimInfoRes.MembershipInfo.IsComplete = membershipInfo.IsComplete;
|
||||
long nextMembershipRewardTimeSec = membershipInfo.ActiveTime.Seconds + membershipDetailInfo.CoolTime;
|
||||
long membershipRemainTime = (nextMembershipRewardTimeSec - nowTS.Seconds);
|
||||
if (membershipRemainTime < 0) membershipRemainTime = 0;
|
||||
clientToGame.Message.ClaimUpdateNoti.MembershipInfo.RewardRemainSecond = membershipRemainTime;
|
||||
|
||||
clientToGames.Add(clientToGame);
|
||||
}
|
||||
|
||||
|
||||
return clientToGames;
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
86
GameServer/Event/EventManager.cs
Normal file
86
GameServer/Event/EventManager.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user