//Returns the next reward that the player should recieve in the specified rewardConfigId. public RewardItemConfigData NextReward(string rewardConfigId) { //If not advent List <RewardItemConfigData> possibleRewards = rewardItemConfigModel.GetRewards(rewardConfigId); RewardItemConfigData lastReward = GetLastReward(rewardConfigId); //skip rewards if the time for them have passed (advent only) int rewardSkip = RewardSkip(rewardConfigId); for (int i = 0; lastReward != null && i < possibleRewards.Count; i++) { if (possibleRewards[i].id == lastReward.id) { //Returns the next in line or the first if were at the end. (MATH!) if (rewardConfigModel.GetRewardType(rewardConfigId) != RewardType.Advent) { return(possibleRewards[(i + rewardSkip) % possibleRewards.Count]); } else { int index = i + rewardSkip >= possibleRewards.Count ? 0 : i + rewardSkip; return(possibleRewards[index]); } } } return(possibleRewards[0]); }
public float GetRewardDelayInSeconds() { RewardItemConfigData nextReward = rewardStateModel.NextReward("gifts"); List <int> delays = rewardConfigModel.GetDelays("gifts"); int delay = delays[nextReward.index % delays.Count]; float seconds = 1; switch (rewardConfigModel.GetDelayType("gifts")) { case DelayType.Days: int hours = delay * 24; seconds = (hours * 60) * 60; break; case DelayType.Hours: seconds = (delay * 60) * 60; break; case DelayType.Minutes: seconds = (delay * 60); break; } return(seconds); }
public IConfigData Clone() { RewardItemConfigData c = new RewardItemConfigData(); c.id = id; c.weight = weight; c.allowRVFactor = allowRVFactor; c.allowSocialFactor = allowSocialFactor; c.rewardConfigId = rewardConfigId; c.index = index; c.rangeMultiplayer = rangeMultiplayer; c.rewards = new List <GameElementData>(rewards.Clone()); c.restrictions = new List <GameElementData>(restrictions.Clone()); return(c); }
List <GameElementData> ClaimItemConfigId(string rewardItemConfigId) { RewardItemConfigData rewardItem = rewardItemConfigModel.GetItemById(rewardItemConfigId); List <GameElementData> rewards = rewardItemConfigModel.GetRewardsForItem(rewardItemConfigId); bool applyRvFactor = rvFactors.ContainsKey(rewardItem.rewardConfigId) ? rvFactors[rewardItem.rewardConfigId] : false; applyRvFactor = applyRvFactor && rewardItem.allowRVFactor; RewardConfigData rewardConfig = rewardConfigModel.GetById(rewardItem.rewardConfigId); var items = new List <GameElementData>(); //increase items by factors. foreach (var item in rewards) { if (applyRvFactor) { item.value = Mathf.RoundToInt(item.value * rewardConfig.rvFactor); } if (rewardItem.allowSocialFactor && socialFactor && (!applyRvFactor || (applyRvFactor && rewardConfig.doubleFactor))) { item.value = Mathf.RoundToInt(item.value * rewardConfig.socialFactor); } if (rewardItem.rangeMultiplayer > 1.0f) { float randomMultiplayer = UnityEngine.Random.Range(1.0f, rewardItem.rangeMultiplayer); Debug.Log("RewardService - Applying random range multiplier : " + randomMultiplayer); } items.Add(item); } collectGameElementsSignal.Dispatch(items); //reset rvFactor. rvFactors[rewardItem.rewardConfigId] = false; return(rewards); }
/// <summary> /// Collects the reward for specified rewardConfigId, if it eligable /// </summary> /// <returns>The rewards that were claimed</returns> /// <param name="rewardConfigId">Reward config identifier.</param> public List <GameElementData> CollectReward(string rewardConfigId) { if (!EligbleForReward(rewardConfigId)) { return(new List <GameElementData>()); } RewardItemConfigData rewardClaimed = rewardStateModel.NextReward(rewardConfigId); if (TimeForConsecutiveRewardPassed(rewardConfigId)) { rewardStateModel.ResetRewards(rewardConfigId); rewardClaimed = rewardStateModel.NextReward(rewardConfigId); } List <GameElementData> rewards = ClaimItemConfigId(rewardClaimed.id); rewardStateModel.ClaimReward(rewardConfigId, rewardClaimed.id); return(rewards); }
private bool TimeForConsecutiveRewardPassed(string rewardConfigId) { if (rewardConfigModel.GetRewardType(rewardConfigId) != RewardType.Consecutive) { return(false); } RewardItemConfigData nextReward = rewardStateModel.NextReward(rewardConfigId); List <int> delays = rewardConfigModel.GetDelays(rewardConfigId); int delay = delays[nextReward.index % delays.Count]; DateTime todayStart = serverTime.GetLocalTime(); DateTime lastReward = serverTime.ToLocal(rewardStateModel.GetLastRewardedDate(rewardConfigId)); todayStart = serverTime.GetDateStart(todayStart); lastReward = serverTime.GetDateStart(lastReward); //true if more than <delay> days have passed. (because we set the hours to be the same, it will only be in multiples of 24) return(todayStart - lastReward > TimeSpan.FromHours(delay * 24)); }
private bool VerifyDelayPassed(string rewardConfigId) { RewardItemConfigData nextReward = rewardStateModel.NextReward(rewardConfigId); List <int> delays = rewardConfigModel.GetDelays(rewardConfigId); if (delays.Count == 0) { return(true); } int delay = delays[nextReward.index % delays.Count]; DateTime todayStart = serverTime.GetLocalTime(); DateTime lastReward = serverTime.ToLocal(rewardStateModel.GetLastRewardedDate(rewardConfigId)); switch (rewardConfigModel.GetDelayType(rewardConfigId)) { case DelayType.Days: //todayStart = serverTime.GetDateStart (todayStart); //lastReward = serverTime.GetDateStart(lastReward); return(todayStart - lastReward >= TimeSpan.FromHours(24 * delay)); case DelayType.Hours: return(todayStart - lastReward >= TimeSpan.FromHours(delay)); case DelayType.Minutes: return(todayStart - lastReward >= TimeSpan.FromMinutes(delay)); case DelayType.None: return(true); default: return(false); //or true? } }