protected void RefreshButton(ShopItemListItem itemList, Consumable c)
    {
        int count = 0;

        PlayerData.instance.consumables.TryGetValue(c.GetConsumableType(), out count);
        itemList.countText.text = count.ToString();

        if (c.GetPrice() > PlayerData.instance.coins)
        {
            itemList.buyButton.interactable = false;
            itemList.pricetext.color        = Color.red;
        }
        else
        {
            itemList.pricetext.color = Color.black;
        }

        if (c.GetPremiumCost() > PlayerData.instance.premium)
        {
            itemList.buyButton.interactable = false;
            itemList.premiumText.color      = Color.red;
        }
        else
        {
            itemList.premiumText.color = Color.black;
        }
    }
Example #2
0
    protected void RefreshButton(ShopItemListItem itemList, Consumable c)
    {
        int count = 0;

        PlayerData.instance.consumables.TryGetValue(c.GetConsumableType(), out count);
        itemList.countText.text = count.ToString();
    }
    public void UseConsumable(Consumable c)
    {
        if (c.GetConsumableType() == Consumable.ConsumableType.INVINCIBILITY)
        {
            characterCollider.sosi = c;
        }

        characterCollider.audio.PlayOneShot(powerUpUseSound);

        for (int i = 0; i < m_ActiveConsumables.Count; ++i)
        {
            if (m_ActiveConsumables[i].GetType() == c.GetType())
            {
                // If we already have an active consumable of that type, we just reset the time
                m_ActiveConsumables[i].ResetTime();
                Destroy(c.gameObject);
                return;
            }
        }

        // If we didn't had one, activate that one
        c.transform.SetParent(transform, false);
        c.gameObject.SetActive(false);

        m_ActiveConsumables.Add(c);
        c.Started(this);
    }
    public void Buy(Consumable c)
    {
        PlayerData.instance.coins   -= c.GetPrice();
        PlayerData.instance.premium -= c.GetPremiumCost();
        PlayerData.instance.Add(c.GetConsumableType());
        PlayerData.instance.Save();

#if UNITY_ANALYTICS // Using Analytics Standard Events v0.3.0
        var transactionId      = System.Guid.NewGuid().ToString();
        var transactionContext = "store";
        var level    = PlayerData.instance.rank.ToString();
        var itemId   = c.GetConsumableName();
        var itemType = "consumable";
        var itemQty  = 1;

        AnalyticsEvent.ItemAcquired(
            AcquisitionType.Soft,
            transactionContext,
            itemQty,
            itemId,
            itemType,
            level,
            transactionId
            );

        if (c.GetPrice() > 0)
        {
            AnalyticsEvent.ItemSpent(
                AcquisitionType.Soft, // Currency type
                transactionContext,
                c.GetPrice(),
                itemId,
                PlayerData.instance.coins, // Balance
                itemType,
                level,
                transactionId
                );
        }

        if (c.GetPremiumCost() > 0)
        {
            AnalyticsEvent.ItemSpent(
                AcquisitionType.Premium, // Currency type
                transactionContext,
                c.GetPremiumCost(),
                itemId,
                PlayerData.instance.premium, // Balance
                itemType,
                level,
                transactionId
                );
        }
#endif

        Refresh();
    }
Example #5
0
    static public void AddConsumables()
    {
        for (int i = 0; i < ShopItemList.s_ConsumablesTypes.Length; ++i)
        {
            Consumable c = ConsumableDatabase.GetConsumable(ShopItemList.s_ConsumablesTypes[i]);
            if (c != null)
            {
                PlayerData.instance.consumables[c.GetConsumableType()] = 10;
            }
        }

        PlayerData.instance.Save();
    }
    protected void OnTriggerEnter(Collider c)
    {
        if (c.gameObject.layer == k_CoinsLayerIndex)
        {
            if (magnetCoins.Contains(c.gameObject))
            {
                magnetCoins.Remove(c.gameObject);
            }

            if (c.GetComponent <Coin>().isPremium)
            {
                Destroy(c.gameObject);
                PlayerData.instance.premium += 1;
                controller.premium          += 1;
                m_Audio.PlayOneShot(premiumSound);
            }
            else
            {
                Coin.coinPool.Free(c.gameObject);
                PlayerData.instance.coins += 1;
                controller.coins          += 1;
                m_Audio.PlayOneShot(coinSound);
            }
        }
        else if (c.gameObject.layer == k_ObstacleLayerIndex)
        {
            if (m_Invincible || controller.IsCheatInvincible())
            {
                return;
            }

            controller.StopMoving();

            c.enabled = false;

            Obstacle ob = c.gameObject.GetComponent <Obstacle>();

            if (ob != null)
            {
                ob.Impacted();
            }
            else
            {
                Destroy(c.gameObject);
            }

            controller.currentLife -= 1;
            controller.character.animator.SetTrigger(s_HitHash);

            if (controller.currentLife > 0)
            {
                m_Audio.PlayOneShot(controller.character.hitSound);
                SetInvincible();
            }
            // The collision killed the player, record all data to analytics.
            else
            {
                m_Audio.PlayOneShot(controller.character.deathSound);

                m_DeathData.character     = controller.character.characterName;
                m_DeathData.themeUsed     = controller.trackManager.currentTheme.themeName;
                m_DeathData.obstacleType  = ob.GetType().ToString();
                m_DeathData.coins         = controller.coins;
                m_DeathData.premium       = controller.premium;
                m_DeathData.score         = controller.trackManager.score;
                m_DeathData.worldDistance = controller.trackManager.worldDistance;
            }
        }
        else if (c.gameObject.layer == k_PowerupLayerIndex)
        {
            Consumable consumable = c.GetComponent <Consumable>();
            if (consumable != null)
            {
                if (!consumed.ContainsKey(consumable.GetConsumableType()))
                {
                    consumed.Add(consumable.GetConsumableType(), 1);
                }
                consumed[consumable.GetConsumableType()] += 1;
                controller.UseConsumable(consumable);
            }
        }
    }