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

286 lines
11 KiB
C#

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;
}*/
}
}