示例#1
0
    public PlayerGoalRunner(PlayerGoalConfig config)
    {
        SceneLoader           instance            = SceneLoader.Instance;
        UIIngameNotifications IngameNotifications = BindingManager.Instance.IngameNotifications;

        GoalConfig   = config;
        GoalState    = PlayerGoalStateFactory.GetOrCreatePlayerGoalState(config.ID);
        GoalAction   = PlayerGoalActionFactory.Create(GoalConfig, GoalState);
        GoalName     = new ReactiveProperty <string>(PersistentSingleton <LocalizationService> .Instance.Text("PlayerGoal.Title." + config.ID));
        ClaimedStars = GoalState.ClaimedStars;
        GoalAction.CompletedStars.Subscribe(delegate(int val)
        {
            GoalState.CompletedStars.Value = val;
        }).AddTo(instance);
        if (GoalConfig.IsTutorialGoal)
        {
            Unlocked = (from step in PlayerData.Instance.TutorialStep
                        select step >= GoalConfig.Index).TakeUntilDestroy(instance).ToReactiveProperty();
        }
        else
        {
            Unlocked = (from lvl in Singleton <HeroTeamRunner> .Instance.GetOrCreateHeroRunner(0).LifetimeLevel
                        select lvl >= GoalConfig.HeroLevelReq).TakeUntilDestroy(instance).ToReactiveProperty();
        }
        ClaimAvailable = GoalState.CompletedStars.CombineLatest(GoalState.ClaimedStars, (int comp, int claim) => comp > claim).CombineLatest(Unlocked, (bool claimAvailable, bool unlocked) => claimAvailable && unlocked).TakeUntilDestroy(instance)
                         .ToReactiveProperty();
        GoalState.CompletedStars.Skip(1).Subscribe(delegate
        {
            IngameNotifications.InstantiatePlayerGoalNotification(this);
        }).AddTo(instance);
        CompletedStars = GoalAction.CompletedStars.TakeUntilDestroy(instance).ToReactiveProperty();
        CompletedStars.Skip(1).Subscribe(delegate
        {
            if (PersistentSingleton <GameAnalytics> .Instance != null)
            {
                PersistentSingleton <GameAnalytics> .Instance.GoalCompleted.Value = this;
            }
        }).AddTo(instance);
        FullyCompleted = (from max in GoalAction.ProgressMax
                          select max < BigDouble.ZERO).TakeUntilDestroy(instance).ToReactiveProperty();
        (from full in FullyCompleted
         where full
         select full).Take(1).Subscribe(delegate
        {
            ReportAchievement(GoalConfig);
        }).AddTo(instance);
        Progress     = GoalAction.Progress.TakeUntilDestroy(instance).ToReactiveProperty();
        ProgressText = GoalAction.ProgressCurrent.CombineLatest(GoalAction.ProgressMax, (BigDouble cur, BigDouble max) => BigString.ToString(cur) + "/" + BigString.ToString(max)).TakeUntilDestroy(instance).ToReactiveProperty();
        GemReward    = (from stars in GoalState.ClaimedStars
                        select Mathf.Min(stars, PersistentSingleton <Economies> .Instance.PlayerGoalRewards.Count - 1) into stars
                        select PersistentSingleton <Economies> .Instance.PlayerGoalRewards[stars].GemReward).TakeUntilDestroy(instance).ToReactiveProperty();
    }
示例#2
0
    public HeroRunner(int heroIndex)
    {
        SceneLoader           instance            = SceneLoader.Instance;
        UIIngameNotifications IngameNotifications = BindingManager.Instance.IngameNotifications;

        HeroIndex = heroIndex;
        BerryIndex.SetValueAndForceNotify(HeroIndex % 5);
        m_heroConfig  = PersistentSingleton <Economies> .Instance.Heroes[HeroIndex];
        m_heroState   = HeroStateFactory.GetOrCreateHeroState(HeroIndex);
        Level         = m_heroState.Level;
        LifetimeLevel = m_heroState.LifetimeLevel;
        Tier          = m_heroState.Tier;
        Berries       = m_heroState.Berries;
        UnusedBerries = m_heroState.UnusedBerries;
        (from lvl in Level
         where lvl > LifetimeLevel.Value
         select lvl).Subscribe(delegate(int lvl)
        {
            LifetimeLevel.Value = lvl;
        }).AddTo(instance);
        Rank = (from tier in Tier
                select(int) Singleton <EconomyHelpers> .Instance.GetRank(tier)).TakeUntilDestroy(instance).ToReactiveProperty();
        LocalizedName      = new ReactiveProperty <string>(PersistentSingleton <LocalizationService> .Instance.Text("Companion.Name." + HeroIndex));
        LocalizedNameDesc  = new ReactiveProperty <string>(PersistentSingleton <LocalizationService> .Instance.Text("Companion.Name.Desc." + HeroIndex));
        MiniMilestoneTitle = new ReactiveProperty <string>(LocalizedName + " " + PersistentSingleton <LocalizationService> .Instance.Text("Attribute.Milestone") + "!");
        ChunkIndex         = new ReactiveProperty <int>(m_heroConfig.UnlockAtChunk);
        FoundOnce          = (from level in LifetimeLevel
                              select level >= 1).TakeUntilDestroy(instance).ToReactiveProperty();
        Found = (from level in Level
                 select level >= 1).TakeUntilDestroy(instance).ToReactiveProperty();
        IsNextLevelMilestone = (from lvl in Level
                                select Singleton <EconomyHelpers> .Instance.IsMilestone(heroIndex, lvl + 1)).TakeUntilDestroy(instance).ToReactiveProperty();
        UnlockedPerkCount = (from heroLevel in Level
                             select Singleton <EconomyHelpers> .Instance.GetUnlockedPerkCount(heroLevel)).TakeUntilDestroy(instance).ToReactiveProperty();
        PerkUnlockTriggered = (from pair in UnlockedPerkCount.Pairwise()
                               where pair.Previous != pair.Current
                               where pair.Current > 0
                               select new PerkUnlockedInfo(HeroIndex, pair.Current - 1)).TakeUntilDestroy(instance).ToSequentialReadOnlyReactiveProperty();
        if (heroIndex > 0)
        {
            (from _ in PerkUnlockTriggered
             where LifetimeLevel.Value > Level.Value
             select _).Subscribe(delegate(PerkUnlockedInfo perk)
            {
                IngameNotifications.InstantiatePerkNotification(perk);
            }).AddTo(instance);
        }
        MiniMilestoneTriggered = (from lvl in Level.Pairwise()
                                  select Singleton <EconomyHelpers> .Instance.GetMiniMilestoneOrNull(HeroIndex, lvl.Previous, lvl.Current) into cfg
                                  where cfg != null
                                  select cfg).TakeUntilDestroy(instance).ToSequentialReadOnlyReactiveProperty();
        MiniMilestoneText = MiniMilestoneTriggered.Select(delegate(BonusMultConfig cfg)
        {
            if (IngameNotifications.CurrentHeroIndex == HeroIndex && IngameNotifications.CurrentNotification != null && IngameNotifications.CurrentNotification.activeSelf)
            {
                m_currentMiniMilestoneMultiplier *= cfg.Amount;
                return(GetMilestoneString(cfg.BonusType, m_currentMiniMilestoneMultiplier));
            }
            m_currentMiniMilestoneMultiplier = cfg.Amount;
            return(GetMilestoneString(cfg.BonusType, m_currentMiniMilestoneMultiplier));
        }).TakeUntilDestroy(instance).ToSequentialReadOnlyReactiveProperty();
        MiniMilestoneText.Subscribe(delegate
        {
            IngameNotifications.InstantiateMiniMilestoneNotification(this);
        }).AddTo(instance);
        HeroTierUpgradeTriggered = (from pair in Tier.Pairwise()
                                    where pair.Previous != pair.Current
                                    select HeroIndex).TakeUntilDestroy(instance).ToSequentialReadOnlyReactiveProperty();
        MilestoneProgress = (from level in Level
                             select Singleton <EconomyHelpers> .Instance.GetMilestoneProgress(level)).TakeUntilDestroy(instance).ToReactiveProperty();
        BerryProgress = (from tier_berry in Tier.CombineLatest(Berries, (int tier, int berries) => new
        {
            tier,
            berries
        })
                         select Singleton <EconomyHelpers> .Instance.GetBerryProgress(tier_berry.tier, tier_berry.berries)).TakeUntilDestroy(instance).ToReactiveProperty();
        BerryRequirement = (from tier_berry in Tier.CombineLatest(Berries, (int tier, int berries) => new
        {
            tier,
            berries
        })
                            select Singleton <EconomyHelpers> .Instance.GetBerryRequirementText(tier_berry.tier, tier_berry.berries)).TakeUntilDestroy(instance).ToReactiveProperty();
        TierUpAvailable = (from berry_tier in Berries.CombineLatest(UnusedBerries, (int berries, int unused) => berries + unused).CombineLatest(Tier, (int berries, int tier) => new
        {
            berries,
            tier
        })
                           select berry_tier.berries >= Singleton <EconomyHelpers> .Instance.GetTierBerryDeltaReq(berry_tier.tier)).TakeUntilDestroy(instance).ToReactiveProperty();
        NextMilestoneText = (from lvl in Level
                             where lvl >= 1
                             select Singleton <EconomyHelpers> .Instance.GetNextMilestoneText(HeroIndex, lvl)).TakeUntilDestroy(instance).ToReactiveProperty();
    }