using System.Collections.Generic; using System.Diagnostics; using System.Linq; using ProtoCSStruct; using Sog; namespace Game { public static class ActivitySvc { // public static void GetInfo(PlayerOnGame player) // { // if (player.RoleData.ActivityInfo.Count == 0) // { // AbstractActivity.TickAll(player); // } // var ret = new CSGetActInfoRes(); // ret.ActivityInfo.CopyFrom(ref player.RoleData.ActivityInfo); // ret.ActExtraInfo.CopyFrom(ref player.RoleData.ActExtraInfo); // player.SendToClient((int)CSGameMsgID.GetActivityInfoReq, ref ret); // } //活动是否正在开启 public static bool IsActivityInProgress(PlayerOnGame player, int actId) { return GetActivityState(player, actId) == ActivityState.InProgress; } //获取活动状态 public static ActivityState GetActivityState(PlayerOnGame player, int actId) { var actDesc = ActivityDescMgr.Instance.GetConfig(actId); if (actDesc == null) { TraceLog.Error("ActivitySvc.GetActivityState desc not found id=" + actId); return ActivityState.ActivityNotStarted; } var realmId = player.RealmID; if (realmId > 0) { if (!ActivityUtils.IsActivityValid(realmId, actId)) { return ActivityState.ActivityNotStarted; } } var timeTrigger = TimeTrigger.GetTimeTrigger(actDesc.timeType); if (timeTrigger == null) { TraceLog.Error("ActivitySvc.GetActivityState Activity Time Type not found type={0}", actDesc.timeType); return ActivityState.ActivityNotStarted; } return timeTrigger.GetActivityState(actId, player, realmId); } //活动还有多久结束 public static long GetLastTimeToEnd(PlayerOnGame player, int actId) { ActivityDesc actDesc = ActivityDescMgr.Instance.GetConfig(actId); if (actDesc == null) { TraceLog.Error("ActivitySvc.GetLastTimeToEnd desc not found id=" + actId); return -1; } var timeTrigger = TimeTrigger.GetTimeTrigger(actDesc.timeType); if (timeTrigger == null) { TraceLog.Error("ActivitySvc.GetLastTimeToEnd Activity Time Type not found type={0}", actDesc.timeType); return -1; } return timeTrigger.GetLastTimeToEnd(actId, player, player.RealmID); } //活动开启时间 public static long GetActOpenTimeDate(PlayerOnGame player, int actId) { var actDesc = ActivityDescMgr.Instance.GetConfig(actId); if (actDesc == null) { TraceLog.Error("ActivitySvc.GetActOpenTimeDate desc not found id=" + actId); return -1; } var timeTrigger = TimeTrigger.GetTimeTrigger(actDesc.timeType); if (timeTrigger == null) { TraceLog.Error("ActivitySvc.GetActOpenTimeDate Activity Time Type not found type={0}", actDesc.timeType); return -1; } return timeTrigger.GetActOpenTimeDate(actId, player, player.RealmID); } public static void GainDailyFreeReward(PlayerOnGame player, int actId) { var actDesc = ActivityDescMgr.Instance.GetConfig(actId); if (actDesc == null) { TraceLog.Error("ActivitySvc.GainDailyFreeReward desc not found id=" + actId); return; } if (!IsActivityInProgress(player, actId)) { return; } var index=GetActivityIndex(player, actId); var now=GameServerUtils.GetTimeSecond(); if ( AppTime.IsSameDay(player.RoleData.ActivityInfo[index].FreeTime,now)) { return; } player.RoleData.ActivityInfo[index].FreeTime = now; var reward=actDesc.dialyAward; } public static int GetActivityIndex(PlayerOnGame player, int actId) { for (var i = 0; i < player.RoleData.ActivityInfo.Count; i++) { if (player.RoleData.ActivityInfo[i].ActID == actId) { return i; } } return -1; } } }