protected override void PerformOfflineAction(OfflineDatabase offlineDatabase, IOfflineDefinitionLoader offlineDefinitions) { ClubPenguin.Net.Offline.DailySpinData value = offlineDatabase.Read <ClubPenguin.Net.Offline.DailySpinData>(); value.CurrentChestId = requestBody.CurrentChestId; value.NumPunchesOnCurrentChest = requestBody.NumPunchesOnCurrentChest; value.NumChestsReceivedOfCurrentChestId = requestBody.NumChestsReceivedOfCurrentChestId; value.TimeOfLastSpinInMilliseconds = requestBody.TimeOfLastSpinInMilliseconds; if (requestBody.ResetRewards) { value.EarnedNonRepeatableRewardIds.Clear(); value.EarnedRepeatableRewardIds.Clear(); } offlineDatabase.Write(value); }
protected override void SetOfflineData(OfflineDatabase offlineDatabase, IOfflineDefinitionLoader offlineDefinitions) { BreadcrumbCollection value = offlineDatabase.Read <BreadcrumbCollection>(); value.breadcrumbs = ResponseBody.breadcrumbs.breadcrumbs; offlineDatabase.Write(value); ClaimableRewardData value2 = offlineDatabase.Read <ClaimableRewardData>(); value2.ClimedRewards = ResponseBody.claimedRewardIds; offlineDatabase.Write(value2); ClubPenguin.Net.Offline.DailySpinData value3 = offlineDatabase.Read <ClubPenguin.Net.Offline.DailySpinData>(); value3.CurrentChestId = ResponseBody.dailySpinData.currentChestId; value3.NumChestsReceivedOfCurrentChestId = ResponseBody.dailySpinData.numChestsReceivedOfCurrentChestId; value3.NumPunchesOnCurrentChest = ResponseBody.dailySpinData.numPunchesOnCurrentChest; value3.TimeOfLastSpinInMilliseconds = ResponseBody.dailySpinData.timeOfLastSpinInMilliseconds; offlineDatabase.Write(value3); ClubPenguin.Net.Offline.PlayerOutfitDetails value4 = offlineDatabase.Read <ClubPenguin.Net.Offline.PlayerOutfitDetails>(); value4.Parts = ResponseBody.outfit; offlineDatabase.Write(value4); ClubPenguin.Net.Offline.Profile value5 = offlineDatabase.Read <ClubPenguin.Net.Offline.Profile>(); value5.Colour = ResponseBody.profile.colour; value5.DateCreated = DateTime.UtcNow.AddDays(-1 * ResponseBody.profile.daysOld).GetTimeInMilliseconds(); offlineDatabase.Write(value5); SetProgressOperation.SetOfflineQuestStateCollection(offlineDatabase, ResponseBody.quests); TutorialData value6 = offlineDatabase.Read <TutorialData>(); for (int i = 0; i < value6.Bytes.Length; i++) { sbyte b = 0; if (i < ResponseBody.tutorialData.Count) { b = ResponseBody.tutorialData[i]; } value6.Bytes[i] = b; } offlineDatabase.Write(value6); }
private static CellPhoneDailySpinActivityDefinition.ChestReward getRepeatableChestReward(ClubPenguin.Net.Offline.DailySpinData dailySpinData, CellPhoneDailySpinActivityDefinition.ChestDefinition chestDefinition) { List <CellPhoneDailySpinActivityDefinition.ChestReward> list = new List <CellPhoneDailySpinActivityDefinition.ChestReward>(chestDefinition.RepeatableChestRewards); List <CellPhoneDailySpinActivityDefinition.ChestReward> list2 = filterRewardsAlreadyReceived(list, dailySpinData.EarnedRepeatableRewardIds); if (list2.Count > 0) { dailySpinData.EarnedRepeatableRewardIds.Clear(); } else { list = list2; } dailySpinData.EarnedRepeatableRewardIds.Add(list[0].RewardId); return(list[0]); }
private static CellPhoneDailySpinActivityDefinition.ChestReward getNonRepeatableChestReward(ClubPenguin.Net.Offline.DailySpinData dailySpinData, CellPhoneDailySpinActivityDefinition.ChestDefinition chestDefinition) { List <CellPhoneDailySpinActivityDefinition.ChestReward> nonRepeatableChestRewards = chestDefinition.NonRepeatableChestRewards; List <CellPhoneDailySpinActivityDefinition.ChestReward> list = filterRewardsAlreadyReceived(nonRepeatableChestRewards, dailySpinData.EarnedNonRepeatableRewardIds); if (list.Count > 0) { return(getRepeatableChestReward(dailySpinData, chestDefinition)); } nonRepeatableChestRewards = list; dailySpinData.EarnedNonRepeatableRewardIds.Add(nonRepeatableChestRewards[0].RewardId); return(nonRepeatableChestRewards[0]); }
private static void addChestReward(Reward chestReward, CellPhoneDailySpinActivityDefinition dailySpinDefinition, ClubPenguin.Net.Offline.DailySpinData dailySpinData, CellPhoneDailySpinActivityDefinition.ChestDefinition chestDefinition) { if (dailySpinData.NumChestsReceivedOfCurrentChestId == 0) { chestReward.AddReward(getRepeatableChestReward(dailySpinData, chestDefinition).Reward.ToReward()); chestReward.AddReward(chestDefinition.FirstTimeClaimedReward.ToReward()); } else { chestReward.AddReward(getRepeatableChestReward(dailySpinData, chestDefinition).Reward.ToReward()); chestReward.AddReward(getNonRepeatableChestReward(dailySpinData, chestDefinition).Reward.ToReward()); } }
private static bool isChestValidSpinReward(ClubPenguin.Net.Offline.DailySpinData dailySpinData, CellPhoneDailySpinActivityDefinition.ChestDefinition chestDefinition) { return(!chestDefinition.IsChestSpinNotAllowed && dailySpinData.NumPunchesOnCurrentChest < chestDefinition.NumPunchesPerChest); }
private static int addWeightedRandomSpinReward(Reward spinReward, CellPhoneDailySpinActivityDefinition dailySpinDefinition, ClubPenguin.Net.Offline.DailySpinData dailySpinData, CellPhoneDailySpinActivityDefinition.ChestDefinition chestDefinition) { int num = 0; List <KeyValuePair <int, int> > list = new List <KeyValuePair <int, int> >(); Dictionary <int, Reward> dictionary = new Dictionary <int, Reward>(); int num2 = dailySpinDefinition.InitialRespinWeight + dailySpinDefinition.RespinWeightIncreasePerSpin * dailySpinData.NumSpinsSinceReceivedExtraSpin; dictionary.Add(dailySpinDefinition.RespinSpinOutcomeId, dailySpinDefinition.RespinReward.ToReward()); list.Add(new KeyValuePair <int, int>(dailySpinDefinition.RespinSpinOutcomeId, num2)); num += num2; if (isChestValidSpinReward(dailySpinData, chestDefinition)) { int num3 = dailySpinDefinition.InitialChestWeight + dailySpinDefinition.ChestWeightIncreasePerSpin * dailySpinData.NumSpinsSinceReceivedChest; dictionary.Add(dailySpinDefinition.ChestSpinOutcomeId, new Reward()); list.Add(new KeyValuePair <int, int>(dailySpinDefinition.ChestSpinOutcomeId, num3)); num += num3; } foreach (CellPhoneDailySpinActivityDefinition.SpinReward spinReward2 in dailySpinDefinition.SpinRewards) { dictionary.Add(spinReward2.SpinOutcomeId, spinReward2.Reward.ToReward()); list.Add(new KeyValuePair <int, int>(spinReward2.SpinOutcomeId, spinReward2.Weight)); num += spinReward2.Weight; } int num4 = UnityEngine.Random.Range(0, num); int num5 = 0; foreach (KeyValuePair <int, int> item in list) { num5 += item.Value; if (num5 > num4) { spinReward.AddReward(dictionary[item.Key]); return(item.Key); } } return(-1); }
public int GetSpinResult(Reward spinReward, Reward chestReward) { CellPhoneDailySpinActivityDefinition widgetData = ClubPenguin.Core.SceneRefs.Get <CellPhoneActivityScreenDailySpinWidget>().WidgetData; ClubPenguin.Net.Offline.DailySpinData dailySpinData = offlineDatabase.Read <ClubPenguin.Net.Offline.DailySpinData>(); bool flag = dailySpinData.CurrentChestId == 0 && dailySpinData.NumPunchesOnCurrentChest == 0 && dailySpinData.NumChestsReceivedOfCurrentChestId == 0; CellPhoneDailySpinActivityDefinition.ChestDefinition chestDefinition = getChestDefinitionForId(dailySpinData.CurrentChestId, widgetData) ?? default(CellPhoneDailySpinActivityDefinition.ChestDefinition); dailySpinData.NumPunchesOnCurrentChest++; int num = -1; if (dailySpinData.NumPunchesOnCurrentChest >= chestDefinition.NumPunchesPerChest) { addChestReward(chestReward, widgetData, dailySpinData, chestDefinition); } if (flag && !widgetData.FirstTimeSpinReward.Reward.ToReward().isEmpty()) { num = widgetData.FirstTimeSpinReward.SpinOutcomeId; spinReward.AddReward(widgetData.FirstTimeSpinReward.Reward.ToReward()); } else { num = addWeightedRandomSpinReward(spinReward, widgetData, dailySpinData, chestDefinition); } if (num == widgetData.ChestSpinOutcomeId) { dailySpinData.NumSpinsSinceReceivedChest = 0; dailySpinData.NumSpinsSinceReceivedExtraSpin++; addChestReward(spinReward, widgetData, dailySpinData, chestDefinition); } else if (num == widgetData.RespinSpinOutcomeId) { dailySpinData.NumSpinsSinceReceivedExtraSpin = 0; if (isChestValidSpinReward(dailySpinData, chestDefinition)) { dailySpinData.NumSpinsSinceReceivedChest++; } } else { dailySpinData.NumSpinsSinceReceivedExtraSpin++; if (isChestValidSpinReward(dailySpinData, chestDefinition)) { dailySpinData.NumSpinsSinceReceivedChest++; } } if (num == widgetData.ChestSpinOutcomeId || !chestReward.isEmpty()) { dailySpinData.NumChestsReceivedOfCurrentChestId++; dailySpinData.NumPunchesOnCurrentChest = 0; if (dailySpinData.NumChestsReceivedOfCurrentChestId >= chestDefinition.NumChestsToNextLevel) { CellPhoneDailySpinActivityDefinition.ChestDefinition?chestDefinitionForId = getChestDefinitionForId(chestDefinition.ChestId + 1, widgetData); if (chestDefinitionForId.HasValue) { dailySpinData.CurrentChestId = chestDefinitionForId.Value.ChestId; dailySpinData.NumChestsReceivedOfCurrentChestId = 0; } } } if (spinReward.TryGetValue <MascotXPReward>(out var rewardable)) { bool flag2 = false; ProgressionService progressionService = Service.Get <ProgressionService>(); foreach (KeyValuePair <string, int> item in rewardable.XP) { if (progressionService.IsMascotMaxLevel(item.Key)) { flag2 = true; break; } } if (flag2) { rewardable.XP.Clear(); spinReward.AddReward(widgetData.DefaultReward.ToReward()); } } if (num != widgetData.RespinSpinOutcomeId) { dailySpinData.TimeOfLastSpinInMilliseconds = DateTime.UtcNow.GetTimeInMilliseconds(); } offlineDatabase.Write(dailySpinData); return(num); }
protected override void PerformOfflineAction(OfflineDatabase offlineDatabase, IOfflineDefinitionLoader offlineDefinitions) { ResponseBody = new LocalPlayerData(); ResponseBody.member = true; ResponseBody.membershipExpireDate = DateTime.UtcNow.AddMonths(1).GetTimeInMilliseconds(); ResponseBody.trialAvailable = false; ResponseBody.subscriptionPaymentPending = false; ResponseBody.id = new PlayerId { id = offlineDatabase.AccessToken, type = PlayerId.PlayerIdType.SWID }; ClubPenguin.Net.Offline.Profile profile = offlineDatabase.Read <ClubPenguin.Net.Offline.Profile>(); ResponseBody.profile = new ClubPenguin.Net.Domain.Profile { colour = profile.Colour, daysOld = profile.DaysOld }; ResponseBody.outfit = offlineDatabase.Read <ClubPenguin.Net.Offline.PlayerOutfitDetails>().Parts; ResponseBody.mascotXP = offlineDatabase.Read <ClubPenguin.Net.Offline.PlayerAssets>().Assets.mascotXP; ResponseBody.minigameProgress = new List <MinigameProgress>(); ResponseBody.quests = SetProgressOperation.GetQuestStateCollection(offlineDatabase.Read <QuestStates>(), offlineDefinitions, includeComplete: true); ResponseBody.tutorialData = new List <sbyte>(offlineDatabase.Read <TutorialData>().Bytes); List <Breadcrumb> list = new List <Breadcrumb>(); foreach (Breadcrumb breadcrumb in offlineDatabase.Read <BreadcrumbCollection>().breadcrumbs) { list.Add(new Breadcrumb { id = breadcrumb.id, breadcrumbType = breadcrumb.breadcrumbType }); } ResponseBody.breadcrumbs = new BreadcrumbsResponse { breadcrumbs = list }; RegistrationProfile registrationProfile = offlineDatabase.Read <RegistrationProfile>(); ResponseBody.name = registrationProfile.displayName; if (string.IsNullOrEmpty(ResponseBody.name)) { ResponseBody.name = registrationProfile.userName; } ResponseBody.claimedRewardIds = offlineDatabase.Read <ClaimableRewardData>().ClimedRewards; ZoneId zoneId = new ZoneId(); zoneId.name = "DefaultIgloo"; zoneId.instanceId = registrationProfile.Id(); ZoneId zoneId2 = zoneId; IglooEntity iglooEntity = offlineDatabase.Read <IglooEntity>(); if (iglooEntity.Data.activeLayout != null) { string zoneId3 = iglooEntity.Data.activeLayout.zoneId; if (!string.IsNullOrEmpty(zoneId3)) { zoneId2.name = zoneId3; } } ResponseBody.zoneId = zoneId2; List <SavedIglooLayoutSummary> list2 = new List <SavedIglooLayoutSummary>(); foreach (SavedSceneLayout layout in offlineDatabase.Read <SceneLayoutEntity>().Layouts) { list2.Add(new SavedIglooLayoutSummary { createdDate = layout.createdDate.GetValueOrDefault(0L), lastUpdatedDate = layout.lastModifiedDate.GetValueOrDefault(0L), layoutId = layout.layoutId, lot = layout.zoneId, memberOnly = layout.memberOnly, name = layout.name }); } ResponseBody.iglooLayouts = new SavedIglooLayoutsSummary { activeLayoutId = iglooEntity.Data.activeLayoutId, activeLayoutServerChangeNotification = ActiveLayoutServerChangeNotification.NoServerChange, visibility = iglooEntity.Data.visibility.GetValueOrDefault(IglooVisibility.PRIVATE), layouts = list2 }; ClubPenguin.Net.Offline.DailySpinData dailySpinData = offlineDatabase.Read <ClubPenguin.Net.Offline.DailySpinData>(); ResponseBody.dailySpinData = new ClubPenguin.Net.Domain.DailySpinData { currentChestId = dailySpinData.CurrentChestId, numChestsReceivedOfCurrentChestId = dailySpinData.NumChestsReceivedOfCurrentChestId, numPunchesOnCurrentChest = dailySpinData.NumPunchesOnCurrentChest, timeOfLastSpinInMilliseconds = dailySpinData.TimeOfLastSpinInMilliseconds }; ClubPenguin.Net.Offline.SessionData sessionData = offlineDatabase.Read <ClubPenguin.Net.Offline.SessionData>(); if (sessionData.Data.sessionId != 0) { ResponseBody.onlineLocation = sessionData.CurrentRoom; } }