示例#1
0
    public GameObject SetIcon(int index, GameObject iconPrefab, string label = "", int lootRewardPrefabIndex = 0, bool isDuplicatePart = false, bool addToRewardsList = true)
    {
        if (this.iconRoots == null || index < 0 || index >= this.iconRoots.Length || iconPrefab == null || this.lootRewardPrefabs == null || lootRewardPrefabIndex < 0 || lootRewardPrefabIndex >= this.lootRewardPrefabs.Length)
        {
            return(null);
        }
        GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.lootRewardPrefabs[lootRewardPrefabIndex]);

        gameObject.transform.parent        = this.iconRoots[index];
        gameObject.transform.localPosition = Vector3.zero;
        gameObject.transform.localScale    = this.lootRewardPrefabs[lootRewardPrefabIndex].transform.localScale;
        LootRewardElement component = gameObject.GetComponent <LootRewardElement>();

        if (component != null && addToRewardsList)
        {
            component.IsDuplicatePart = isDuplicatePart;
            component.InitElement(this);
            this.rewardElements.Add(component);
        }
        Transform transform = gameObject.transform.Find("Label");

        if (transform)
        {
            if (string.IsNullOrEmpty(label))
            {
                transform.gameObject.SetActive(false);
            }
            else
            {
                TextMesh component2 = transform.GetComponent <TextMesh>();
                if (component2)
                {
                    component2.text = label;
                }
            }
        }
        GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(iconPrefab);

        if (component != null)
        {
            gameObject2.transform.parent = component.IconRoot;
        }
        else
        {
            gameObject2.transform.parent = gameObject.transform;
        }
        gameObject2.transform.localPosition = -Vector3.forward * 0.5f;
        gameObject2.transform.localScale    = Vector3.one;
        Renderer[] componentsInChildren = gameObject2.GetComponentsInChildren <Renderer>();
        for (int i = 0; i < componentsInChildren.Length; i++)
        {
            componentsInChildren[i].sortingLayerName = "Popup";
            componentsInChildren[i].sortingOrder     = 1;
        }
        if (addToRewardsList)
        {
            this.openIndex++;
        }
        return(gameObject);
    }
示例#2
0
    private void ShowReward(BasePart part, int exp)
    {
        if (this.rewardGameObject != null)
        {
            UnityEngine.Object.Destroy(this.rewardGameObject);
        }
        this.rewardGameObject = UnityEngine.Object.Instantiate <GameObject>(this.lootRewardBackgrounds[(int)part.m_partTier]);
        this.rewardGameObject.transform.parent        = this.rewardSpawnRoot.transform;
        this.rewardGameObject.transform.localPosition = Vector3.zero;
        this.rewardGameObject.transform.localScale    = Vector3.one * 2f;
        this.rewardGameObject.transform.localRotation = Quaternion.identity;
        GameObject        gameObject = UnityEngine.Object.Instantiate <GameObject>(part.m_constructionIconSprite.gameObject);
        LootRewardElement component  = this.rewardGameObject.GetComponent <LootRewardElement>();

        if (component)
        {
            gameObject.transform.parent = component.IconRoot;
        }
        gameObject.transform.localPosition    = -Vector3.forward * 0.5f;
        gameObject.transform.localScale       = Vector3.one * 1.5f;
        gameObject.transform.localEulerAngles = Vector3.forward * 270f;
        base.StartCoroutine(this.WaitForReward(this.rewardGameObject, exp));
    }
示例#3
0
    public void AddLootCrate(LootCrateType lootCrateType, int amount, LootCrate.AnalyticData data, bool fromQueue = false, int xp = 0)
    {
        if (this.lootcrateRewardQueue == null)
        {
            this.lootcrateRewardQueue = new Queue <LootCrateRewardQueueElement>();
        }
        if (this.lootCrateAnimation != null)
        {
            if (this.lootCrateAnimationInstance == null)
            {
                this.lootCrateAnimationInstance = UnityEngine.Object.Instantiate <GameObject>(this.lootCrateAnimation, Vector3.up * 1000f, Quaternion.identity);
            }
            else
            {
                this.lootCrateAnimationInstance.SetActive(true);
            }
            this.lootCrateAnimationInstance.transform.parent = base.transform;
            LootCrateRewardQueueElement lootCrateRewardQueueElement = null;
            if (!fromQueue)
            {
                bool flag = this.lootcrateRewardQueue.Count == 0;
                for (int i = 0; i < amount; i++)
                {
                    lootCrateRewardQueueElement = new LootCrateRewardQueueElement(lootCrateType, data, xp);
                    this.lootcrateRewardQueue.Enqueue(lootCrateRewardQueueElement);
                }
                if (!flag)
                {
                    return;
                }
            }
            else
            {
                lootCrateRewardQueueElement = this.lootcrateRewardQueue.Peek();
            }
            this.closeButton.SetActive(false);
            this.closeButtonGfx.SetActive(false);
            this.crateOpened = false;
            LootCrateRewards.SlotRewards[] randomRewards = LootCrateRewards.GetRandomRewards(lootCrateType);
            if (randomRewards == null)
            {
                return;
            }
            int             num = 0;
            LootCrateButton componentInChildren = this.lootCrateAnimationInstance.GetComponentInChildren <LootCrateButton>();
            componentInChildren.GainedXP = lootCrateRewardQueueElement.xp;
            componentInChildren.Init(lootCrateType);
            LootCrateButton lootCrateButton = componentInChildren;
            lootCrateButton.onOpeningDone = (Action)Delegate.Combine(lootCrateButton.onOpeningDone, new Action(delegate()
            {
                base.StartCoroutine(this.CrateOpened());
            }));
            base.StartCoroutine(this.DelayIntro(componentInChildren, Vector3.forward * -1f));
            List <BasePart> list  = new List <BasePart>();
            int             num2  = 0;
            int             num3  = 0;
            int             num4  = 0;
            int             num5  = 0;
            int             num6  = 0;
            int             num7  = 0;
            List <int>      list2 = new List <int>();
            for (int j = 0; j < randomRewards.Length; j++)
            {
                int num8 = UnityEngine.Random.Range(0, randomRewards.Length);
                int num9 = randomRewards.Length;
                while (list2.Contains(num8) && num9 >= 0)
                {
                    if (++num8 >= randomRewards.Length)
                    {
                        num8 = 0;
                    }
                    num9--;
                }
                if (num9 >= 0)
                {
                    list2.Add(num8);
                    LootCrateRewards.SlotRewards reward = randomRewards[num8];
                    LootCrateRewards.Reward      type   = reward.Type;
                    switch (type)
                    {
                    case LootCrateRewards.Reward.Part:
                    {
                        bool     isDuplicatePart = false;
                        int      num10           = 0;
                        int      num11           = 10;
                        BasePart randomLootCrateRewardPartFromTier;
                        do
                        {
                            randomLootCrateRewardPartFromTier = CustomizationManager.GetRandomLootCrateRewardPartFromTier(reward.PartTier, false);
                            num11--;
                        }while (list.Contains(randomLootCrateRewardPartFromTier) && num11 > 0);
                        list.Add(randomLootCrateRewardPartFromTier);
                        if (CustomizationManager.IsPartUnlocked(randomLootCrateRewardPartFromTier))
                        {
                            num10 = Singleton <GameConfigurationManager> .Instance.GetValue <int>("part_salvage_rewards", randomLootCrateRewardPartFromTier.m_partTier.ToString());

                            GameProgress.AddScrap(num10);
                            num2 += num10;
                            num7++;
                            isDuplicatePart = true;
                        }
                        else
                        {
                            CustomizationManager.UnlockPart(randomLootCrateRewardPartFromTier, lootCrateType.ToString() + "_crate");
                        }
                        componentInChildren.SetIcon(num, randomLootCrateRewardPartFromTier.m_constructionIconSprite.gameObject, string.Empty, (int)reward.PartTier, isDuplicatePart, true);
                        componentInChildren.SetScrapIcon(num, this.scrapIcons[0], num10.ToString());
                        BasePart.PartTier partTier = reward.PartTier;
                        if (partTier != BasePart.PartTier.Common)
                        {
                            if (partTier != BasePart.PartTier.Rare)
                            {
                                if (partTier == BasePart.PartTier.Epic)
                                {
                                    num6++;
                                }
                            }
                            else
                            {
                                num5++;
                            }
                        }
                        else
                        {
                            num4++;
                        }
                        break;
                    }

                    case LootCrateRewards.Reward.Powerup:
                    {
                        GameObject iconPrefab       = this.powerUpIcons[reward.Powerup - LootCrateRewards.Powerup.Magnet];
                        string     customTypeOfGain = lootCrateType.ToString() + " crate";
                        switch (reward.Powerup)
                        {
                        case LootCrateRewards.Powerup.Magnet:
                            GameProgress.AddSuperMagnet(1);
                            if (Singleton <IapManager> .Instance != null)
                            {
                                Singleton <IapManager> .Instance.SendFlurryInventoryGainEvent(IapManager.InAppPurchaseItemType.SuperMagnetSingle, 1, customTypeOfGain);
                            }
                            break;

                        case LootCrateRewards.Powerup.Superglue:
                            GameProgress.AddSuperGlue(1);
                            if (Singleton <IapManager> .Instance != null)
                            {
                                Singleton <IapManager> .Instance.SendFlurryInventoryGainEvent(IapManager.InAppPurchaseItemType.SuperGlueSingle, 1, customTypeOfGain);
                            }
                            break;

                        case LootCrateRewards.Powerup.Turbo:
                            GameProgress.AddTurboCharge(1);
                            if (Singleton <IapManager> .Instance != null)
                            {
                                Singleton <IapManager> .Instance.SendFlurryInventoryGainEvent(IapManager.InAppPurchaseItemType.TurboChargeSingle, 1, customTypeOfGain);
                            }
                            break;

                        case LootCrateRewards.Powerup.Supermechanic:
                            GameProgress.AddBluePrints(1);
                            if (Singleton <IapManager> .Instance != null)
                            {
                                Singleton <IapManager> .Instance.SendFlurryInventoryGainEvent(IapManager.InAppPurchaseItemType.BlueprintSingle, 1, customTypeOfGain);
                            }
                            break;

                        case LootCrateRewards.Powerup.NightVision:
                            GameProgress.AddNightVision(1);
                            if (Singleton <IapManager> .Instance != null)
                            {
                                Singleton <IapManager> .Instance.SendFlurryInventoryGainEvent(IapManager.InAppPurchaseItemType.NightVisionSingle, 1, customTypeOfGain);
                            }
                            break;
                        }
                        componentInChildren.SetIcon(num, iconPrefab, string.Empty, 0, false, true);
                        break;
                    }

                    case LootCrateRewards.Reward.Dessert:
                        if (reward.GoldenCupcake)
                        {
                            GameObject gameObject = WPFMonoBehaviour.gameData.m_desserts[WPFMonoBehaviour.gameData.m_desserts.Count - 1];
                            Dessert    component  = gameObject.GetComponent <Dessert>();
                            GameProgress.AddDesserts(component.saveId, 1);
                            componentInChildren.SetIcon(num, this.dessertIcons[1], string.Empty, 0, false, true);
                        }
                        else
                        {
                            GameObject gameObject2 = WPFMonoBehaviour.gameData.m_desserts[UnityEngine.Random.Range(0, WPFMonoBehaviour.gameData.m_desserts.Count - 1)];
                            Dessert    component2  = gameObject2.GetComponent <Dessert>();
                            GameProgress.AddDesserts(component2.saveId, reward.Desserts);
                            componentInChildren.SetIcon(num, this.dessertIcons[0], reward.Desserts.ToString(), 0, false, true);
                        }
                        num3 += reward.Desserts;
                        break;

                    case LootCrateRewards.Reward.Scrap:
                    {
                        GameProgress.AddScrap(reward.Scrap);
                        num2 += reward.Scrap;
                        GameObject        scrapRewardContainer = componentInChildren.SetIcon(num, this.scrapIcons[0], reward.Scrap.ToString(), 0, false, true);
                        LootRewardElement component3           = scrapRewardContainer.GetComponent <LootRewardElement>();
                        if (component3 != null)
                        {
                            LootRewardElement lootRewardElement = component3;
                            lootRewardElement.onRewardOpened = (Action)Delegate.Combine(lootRewardElement.onRewardOpened, new Action(delegate()
                                {
                                    ScrapButton.Instance.AddParticles(scrapRewardContainer, reward.Scrap, 0f, (float)reward.Scrap);
                                }));
                        }
                        break;
                    }

                    case LootCrateRewards.Reward.Coin:
                    {
                        GameProgress.AddSnoutCoins(reward.Coins);
                        GameObject        coinRewardContainer = componentInChildren.SetIcon(num, this.coinIcons[0], reward.Coins.ToString(), 0, false, true);
                        LootRewardElement component4          = coinRewardContainer.GetComponent <LootRewardElement>();
                        if (component4 != null)
                        {
                            LootRewardElement lootRewardElement2 = component4;
                            lootRewardElement2.onRewardOpened = (Action)Delegate.Combine(lootRewardElement2.onRewardOpened, new Action(delegate()
                                {
                                    SnoutButton.Instance.AddParticles(coinRewardContainer, reward.Scrap, 0f, (float)reward.Scrap);
                                }));
                        }
                        break;
                    }
                    }
                    num++;
                }
            }
            if (lootCrateRewardQueueElement != null && num > 0)
            {
                lootCrateRewardQueueElement.SetRewarded();
                int @int = GameProgress.GetInt(lootCrateType.ToString() + "_crates_collected", 0, GameProgress.Location.Local, null);
                GameProgress.SetInt(lootCrateType.ToString() + "_crates_collected", @int + 1, GameProgress.Location.Local);
            }
            EventManager.Send(new LootCrateDelivered(lootCrateType));
            int value = GameProgress.GetInt("Total_parts_scrapped", 0, GameProgress.Location.Local, null) + num7;
            GameProgress.SetInt("Total_parts_scrapped", value, GameProgress.Location.Local);
            int value2 = GameProgress.GetInt("Total_parts_received", 0, GameProgress.Location.Local, null) + num4 + num5 + num6;
            GameProgress.SetInt("Total_parts_received", value2, GameProgress.Location.Local);
        }
    }