Exemple #1
0
    /// <summary>
    /// Adds new reward request to queue.
    /// </summary>
    /// <param name="notificationEntry">Notification entry.</param>
    public void AddToRewardQueue(RewardQueueData.GenericDelegate functionToCall)
    {
        RewardQueueData.AddReward(functionToCall);

        if (!isRewardingActive)
        {
//			Debug.Log("Try next reward----");
            TryNextReward();
        }
        else
        {
//			Debug.Log("Reward queue FULL----");
        }
    }
Exemple #2
0
    public void RewardShards(int numberOfShards)
    {
        // Data saving
        DataManager.Instance.GameData.Stats.AddShard(numberOfShards);

        if (numberOfShards > 0)
        {
            // Queue up the reward in RewardManager
            RewardQueueData.GenericDelegate function2 = delegate {
                FireCrystalUIManager.Instance.PopupAndRewardShards(numberOfShards);
            };
            RewardManager.Instance.AddToRewardQueue(function2);
        }
    }
Exemple #3
0
    //Event Listener that updates the Level badges UI when a new badge is unlocked
    private void UnlockBadge(object senders, BadgeManager.BadgeEventArgs arg)
    {
        // Populate the unlocked badge into the unlock queue
        badgeUnlockQueue.Enqueue(arg.UnlockedBadge);

        // Check for waiting in reward queue because there might be more badges coming in during waiting so only want to enqueue
        if (!isWaitingInRewardQueue)
        {
            isWaitingInRewardQueue = true;

            RewardQueueData.GenericDelegate funtion = delegate() {
                // Try to animate, lock the queue animation. might be more badges coming in during animation so only want to enqueue
                if (!isQueueAnimating)
                {
                    isQueueAnimating = true;
                    StartCoroutine(TryPopBadgeQueue());
                }
            };
            RewardManager.Instance.AddToRewardQueue(funtion);
        }
    }
Exemple #4
0
    public void TryNextReward()
    {
        if (!RewardQueueData.IsEmpty())
        {
            isRewardingActive      = true;
            isDoAnimationDoneCheck = true;
            RewardQueueData.GenericDelegate functionToCall = RewardQueueData.PopReward();
            functionToCall();
        }
        else            // End condition here
        {
            isRewardingActive = false;

            // Called only when it has animated and finished
            if (isDoAnimationDoneCheck)
            {
                isDoAnimationDoneCheck = false;
                if (OnAllRewardsDone != null)
                {
                    OnAllRewardsDone(this, EventArgs.Empty);
                }
            }
        }
    }
Exemple #5
0
    /// <summary>
    /// Changes the stats.
    /// Locations are on screen space
    /// </summary>
    /// <param name="xpDelta">Delta points.</param>
    /// <param name="xpPos">Points location.</param>
    /// <param name="coinsDelta">Delta stars.</param>
    /// <param name="coinsPos">Stars location.</param>
    /// <param name="healthDelta">Delta health.</param>
    /// <param name="healthPos">Health location.</param>
    /// <param name="hungerDelta">Delta mood.</param>
    /// <param name="hungerPos">Mood location.</param>
    /// <param name="bFloaty">If set to <c>true</c> spawn floaty on the pet. (this will not play sound)</param>
    /// <param name="isInternal">If set to <c>true</c> skip all animations + rewarding</param>
    public void ChangeStats(int xpDelta     = 0, Vector3 xpPos       = default(Vector3),
                            int coinsDelta  = 0, Vector3 coinsPos    = default(Vector3),
                            int healthDelta = 0, Vector3 healthPos   = default(Vector3),
                            int hungerDelta = 0, Vector3 hungerPos   = default(Vector3),
                            bool isFloaty   = false, bool is3DObject = false, float animDelay = 0f,
                            bool isInternal = false)
    {
        // Make necessary changes in the DataManager and HUDAnimator
        if (xpDelta != 0)
        {
            if (xpDelta > 0)
            {
                DataManager.Instance.GameData.Stats.AddCurrentLevelXp(xpDelta);
            }
            else if (xpDelta < 0)               // Invalid case
            {
                Debug.LogError("Subtracting experience points");
            }
        }

        if (coinsDelta != 0)
        {
            DataManager.Instance.GameData.Stats.UpdateCoins(coinsDelta);
        }

        // NOTE: so that the pet animations play properly, make sure to change and check mood BEFORE health
        if (hungerDelta != 0)
        {
            PetMoods oldMood = DataManager.Instance.GameData.Stats.GetMoodState();
            DataManager.Instance.GameData.Stats.UpdateHunger(hungerDelta);
            PetMoods newMood = DataManager.Instance.GameData.Stats.GetMoodState();

            if (isPetAnimationManagerPresent)
            {
                CheckForMoodTransition(oldMood, newMood);
            }
        }

        if (healthDelta != 0)
        {
            PetHealthStates oldHealth = DataManager.Instance.GameData.Stats.GetHealthState();
            DataManager.Instance.GameData.Stats.UpdateHealth(healthDelta);
            PetHealthStates newHealth = DataManager.Instance.GameData.Stats.GetHealthState();

            if (isPetAnimationManagerPresent)
            {
                CheckForHealthTransition(oldHealth, newHealth);
                CheckForZeroHealth();
            }
        }

        // If internal checked, skip all animations and reward checking
        if (isInternal == false)
        {
            if (isFloaty && !bBeingDestroyed && PetFloatyUIManager.Instance)
            {
                PetFloatyUIManager.Instance.CreateStatsFloaty(xpDelta, healthDelta, hungerDelta, coinsDelta);
            }

            //when stats are modified make sure PetAnimationManager knows about it
            if (isPetAnimationManagerPresent)
            {
                PetAnimationManager.Instance.PetStatsModified(DataManager.Instance.GameData.Stats.Health,
                                                              DataManager.Instance.GameData.Stats.Mood);
            }

            // Adjust for custom positions using screen position for 3D objects
            if (is3DObject)
            {
                if (xpPos != default(Vector3))
                {
                    // WorldToScreen returns screen coordinates based on 0,0 being bottom left, so we need to transform those into respective NGUI Anchors
                    xpPos = CameraManager.Instance.WorldToScreen(CameraManager.Instance.CameraMain, xpPos);
                    Debug.LogWarning("COMMENTED OUT THINGS HERE, fix");
                    //InterfaceAnchors endAnchor = (InterfaceAnchors)Enum.Parse(typeof(InterfaceAnchors), Constants.GetConstant<String>("Points_Anchor"));
                    //xpPos = CameraManager.Instance.TransformAnchorPosition(xpPos, InterfaceAnchors.BottomLeft, endAnchor);
                }
                if (coinsPos != default(Vector3))
                {
                    coinsPos = CameraManager.Instance.WorldToScreen(CameraManager.Instance.CameraMain, coinsPos);
                    Debug.LogWarning("COMMENTED OUT THINGS HERE, fix");
                    //InterfaceAnchors endAnchor = (InterfaceAnchors)Enum.Parse(typeof(InterfaceAnchors), Constants.GetConstant<String>("Stars_Anchor"));
                    //coinsPos = CameraManager.Instance.TransformAnchorPosition(coinsPos, InterfaceAnchors.BottomLeft, endAnchor);
                }
                if (healthPos != default(Vector3))
                {
                    healthPos = CameraManager.Instance.WorldToScreen(CameraManager.Instance.CameraMain, healthPos);
                    Debug.LogWarning("COMMENTED OUT THINGS HERE, fix");
                    //InterfaceAnchors endAnchor = (InterfaceAnchors)Enum.Parse(typeof(InterfaceAnchors), Constants.GetConstant<String>("Health_Anchor"));
                    //healthPos = CameraManager.Instance.TransformAnchorPosition(healthPos, InterfaceAnchors.BottomLeft, endAnchor);
                }
                if (hungerPos != default(Vector3))
                {
                    hungerPos = CameraManager.Instance.WorldToScreen(CameraManager.Instance.CameraMain, hungerPos);
                    Debug.LogWarning("COMMENTED OUT THINGS HERE, fix");
                    //InterfaceAnchors endAnchor = (InterfaceAnchors)Enum.Parse(typeof(InterfaceAnchors), Constants.GetConstant<String>("Mood_Anchor"));
                    //hungerPos = CameraManager.Instance.TransformAnchorPosition(hungerPos, InterfaceAnchors.BottomLeft, endAnchor);
                }
            }
            // Adjust for custom position using screen position for NGUI objects
            else
            {
                // Not needed yet
            }

            // Tell HUDAnimator to animate and change
            List <StatPair> listStats = new List <StatPair>();
            listStats.Add(new StatPair(StatType.Xp, xpDelta, xpPos, xpDelta > 0 ? "XpSingleTick" : null));
            listStats.Add(new StatPair(StatType.Coin, coinsDelta, coinsPos, coinsDelta > 0 ? "CoinSingleTick" : null));
            listStats.Add(new StatPair(StatType.Health, healthDelta, healthPos, healthDelta > 0 ? "HealthSingleTick" : null));
            listStats.Add(new StatPair(StatType.Hunger, hungerDelta, hungerPos, hungerDelta > 0 ? "HungerSingleTick" : null));

            if (hudAnimator != null && !bBeingDestroyed)
            {
                // Push this into the reward queue
                RewardQueueData.GenericDelegate function1 = delegate {
                    StartCoroutine(hudAnimator.StartCurveStats(listStats, isFloaty, animDelay));
                };
                RewardManager.Instance.AddToRewardQueue(function1);
            }

            //Check if there are enough coins/stars to unlock badge, we want to do this last after reward
            BadgeManager.Instance.CheckSeriesUnlockProgress(BadgeType.Coin, DataManager.Instance.GameData.Stats.TotalStars, true);
        }
    }