Beispiel #1
0
 void AttemptInteraction(On.RoR2.Interactor.orig_AttemptInteraction orig, RoR2.Interactor interactor, GameObject gameObject)
 {
     if (Data.modEnabled && interactor.GetComponent <NetworkBehaviour>().hasAuthority)
     {
         if (Data.mode == DataShop.mode)
         {
             latestInteractionName = gameObject.name;
             DataShop.purchaseCost = 0;
             DataShop.purchaseTier = -1;
             if (gameObject.name.ToLower().Contains("duplicator"))
             {
                 Util.LogComponentsOfObject(gameObject);
             }
             if (gameObject.name == "Scrapper(Clone)")
             {
                 DataShop.purchaseCost = gameObject.GetComponent <ScrapperController>().maxItemsToScrapAtATime;
             }
             else
             {
                 RoR2.PurchaseInteraction purchaseInteraction = purchaseInteraction = gameObject.GetComponent <RoR2.PurchaseInteraction>();
                 if (purchaseInteraction != null)
                 {
                     if (DataShop.costTypeTier.ContainsKey(purchaseInteraction.costType))
                     {
                         DataShop.purchaseTier = DataShop.costTypeTier[purchaseInteraction.costType];
                         DataShop.purchaseCost = purchaseInteraction.cost;
                     }
                 }
             }
         }
     }
     orig(interactor, gameObject);
 }
Beispiel #2
0
        // Token: 0x0600138C RID: 5004 RVA: 0x0005F66C File Offset: 0x0005D86C
        public bool CanBeAffordedByInteractor(Interactor activator)
        {
            switch (this.costType)
            {
            case CostType.None:
                return(true);

            case CostType.Money:
            {
                CharacterBody component = activator.GetComponent <CharacterBody>();
                if (component)
                {
                    CharacterMaster master = component.master;
                    if (master)
                    {
                        return((ulong)master.money >= (ulong)((long)this.cost));
                    }
                }
                return(false);
            }

            case CostType.PercentHealth:
            {
                HealthComponent component2 = activator.GetComponent <HealthComponent>();
                return(component2 && component2.health / component2.fullHealth * 100f >= (float)this.cost);
            }

            case CostType.Lunar:
            {
                NetworkUser networkUser = Util.LookUpBodyNetworkUser(activator.gameObject);
                return(networkUser && (ulong)networkUser.lunarCoins >= (ulong)((long)this.cost));
            }

            case CostType.WhiteItem:
            case CostType.GreenItem:
            case CostType.RedItem:
            {
                ItemTier      itemTier   = PurchaseInteraction.CostTypeToItemTier(this.costType);
                CharacterBody component3 = activator.gameObject.GetComponent <CharacterBody>();
                if (component3)
                {
                    Inventory inventory = component3.inventory;
                    if (inventory)
                    {
                        return(inventory.HasAtLeastXTotalItemsOfTier(itemTier, this.cost));
                    }
                }
                return(false);
            }

            default:
                return(false);
            }
        }
Beispiel #3
0
 private static void BloodShrinePriceRandom(On.RoR2.ShrineBloodBehavior.orig_FixedUpdate orig, RoR2.ShrineBloodBehavior self)
 {
     //This 'if' is essentially the same as the first line of the orig method(, save that they don't need to do reflection).
     if ((bool)BloodShrineWaitingForRefresh.GetValue(self))
     {
         orig(self);
         //reflect to get the purchaseinteractioncomponent. I then get a random number to change it's price. The price is hidden by the language modification.
         RoR2.PurchaseInteraction pi = ((RoR2.PurchaseInteraction)BloodShrinePurchaseInteraction.GetValue(self));
         if (pi)
         {
             pi.Networkcost = RoR2.Run.instance.stageRng.RangeInt(50, 100);
         }
     }
 }
Beispiel #4
0
 private void OnEquipmentSpentOnPurchase(PurchaseInteraction purchaseInteraction, Interactor interactor, EquipmentIndex equipmentIndex)
 {
     if (!NetworkServer.active)
     {
         Debug.LogWarning("[Server] function 'System.Void RoR2.SummonMasterBehavior::OnEquipmentSpentOnPurchase(RoR2.PurchaseInteraction,RoR2.Interactor,RoR2.EquipmentIndex)' called on client");
         return;
     }
     if (purchaseInteraction == base.GetComponent <PurchaseInteraction>())
     {
         CharacterMaster characterMaster = this.OpenSummonReturnMaster(interactor);
         if (characterMaster)
         {
             characterMaster.inventory.SetEquipmentIndex(equipmentIndex);
         }
     }
 }
 // Token: 0x060010AD RID: 4269 RVA: 0x000491F8 File Offset: 0x000473F8
 public Interactability GetInteractability(Interactor activator)
 {
     if (!string.IsNullOrEmpty(this.requiredUnlockable) && !PurchaseInteraction.ActivatorHasUnlockable(activator, this.requiredUnlockable))
     {
         return(Interactability.Disabled);
     }
     if (!this.available || this.lockGameObject)
     {
         return(Interactability.Disabled);
     }
     if (!this.CanBeAffordedByInteractor(activator))
     {
         return(Interactability.ConditionsNotMet);
     }
     return(Interactability.Available);
 }
 // Token: 0x060011C6 RID: 4550 RVA: 0x00057F38 File Offset: 0x00056138
 private void Start()
 {
     if (Run.instance && NetworkServer.active)
     {
         this.Networkcost = Run.instance.GetDifficultyScaledCost(this.baseCost);
         if (this.terminalGameObjects != null)
         {
             GameObject[] array = this.terminalGameObjects;
             for (int i = 0; i < array.Length; i++)
             {
                 PurchaseInteraction component = array[i].GetComponent <PurchaseInteraction>();
                 component.Networkcost = this.cost;
                 component.costType    = this.costType;
             }
         }
     }
 }
 // Token: 0x0600130C RID: 4876 RVA: 0x0005D55C File Offset: 0x0005B75C
 public void GrantPortalEntry()
 {
     PortalStatueBehavior.PortalType portalType = this.portalType;
     if (portalType != PortalStatueBehavior.PortalType.Shop)
     {
         if (portalType == PortalStatueBehavior.PortalType.Goldshores)
         {
             if (TeleporterInteraction.instance)
             {
                 TeleporterInteraction.instance.shouldAttemptToSpawnGoldshoresPortal = true;
             }
             EffectManager.instance.SpawnEffect(Resources.Load <GameObject>("Prefabs/Effects/ShrineUseEffect"), new EffectData
             {
                 origin   = base.transform.position,
                 rotation = Quaternion.identity,
                 scale    = 1f,
                 color    = ColorCatalog.GetColor(ColorCatalog.ColorIndex.Money)
             }, true);
         }
     }
     else
     {
         if (TeleporterInteraction.instance)
         {
             TeleporterInteraction.instance.shouldAttemptToSpawnShopPortal = true;
         }
         EffectManager.instance.SpawnEffect(Resources.Load <GameObject>("Prefabs/Effects/ShrineUseEffect"), new EffectData
         {
             origin   = base.transform.position,
             rotation = Quaternion.identity,
             scale    = 1f,
             color    = ColorCatalog.GetColor(ColorCatalog.ColorIndex.LunarItem)
         }, true);
     }
     foreach (PortalStatueBehavior portalStatueBehavior in UnityEngine.Object.FindObjectsOfType <PortalStatueBehavior>())
     {
         if (portalStatueBehavior.portalType == this.portalType)
         {
             PurchaseInteraction component = portalStatueBehavior.GetComponent <PurchaseInteraction>();
             if (component)
             {
                 component.Networkavailable = false;
             }
         }
     }
 }
Beispiel #8
0
        // Token: 0x06000E3F RID: 3647 RVA: 0x00046090 File Offset: 0x00044290
        private void FixedUpdate()
        {
            if (this.targetTextMesh)
            {
                switch (this.costType)
                {
                case CostType.Money:
                    this.targetTextMesh.text  = string.Format("${0}", this.displayValue);
                    this.targetTextMesh.color = ColorCatalog.GetColor(ColorCatalog.ColorIndex.Money);
                    return;

                case CostType.PercentHealth:
                    this.targetTextMesh.text  = string.Format("{0}% HP", this.displayValue);
                    this.targetTextMesh.color = ColorCatalog.GetColor(ColorCatalog.ColorIndex.Teleporter);
                    return;

                case CostType.Lunar:
                    this.targetTextMesh.text  = string.Format("{0} Lunar", this.displayValue);
                    this.targetTextMesh.color = ColorCatalog.GetColor(ColorCatalog.ColorIndex.LunarCoin);
                    return;

                case CostType.WhiteItem:
                    this.targetTextMesh.text  = string.Format("{0} Items", this.displayValue);
                    this.targetTextMesh.color = ColorCatalog.GetColor(PurchaseInteraction.CostTypeToColorIndex(this.costType));
                    return;

                case CostType.GreenItem:
                    this.targetTextMesh.text  = string.Format("{0} Items", this.displayValue);
                    this.targetTextMesh.color = ColorCatalog.GetColor(PurchaseInteraction.CostTypeToColorIndex(this.costType));
                    return;

                case CostType.RedItem:
                    this.targetTextMesh.text  = string.Format("{0} Items", this.displayValue);
                    this.targetTextMesh.color = ColorCatalog.GetColor(PurchaseInteraction.CostTypeToColorIndex(this.costType));
                    return;

                default:
                    this.targetTextMesh.text  = string.Format("${0}", this.displayValue);
                    this.targetTextMesh.color = ColorCatalog.GetColor(ColorCatalog.ColorIndex.Error);
                    break;
                }
            }
        }
        // Token: 0x060010B3 RID: 4275 RVA: 0x00049330 File Offset: 0x00047530
        public void OnInteractionBegin(Interactor activator)
        {
            if (!this.CanBeAffordedByInteractor(activator))
            {
                return;
            }
            CharacterBody        component   = activator.GetComponent <CharacterBody>();
            CostTypeDef          costTypeDef = CostTypeCatalog.GetCostTypeDef(this.costType);
            ItemIndex            itemIndex   = ItemIndex.None;
            ShopTerminalBehavior component2  = base.GetComponent <ShopTerminalBehavior>();

            if (component2)
            {
                itemIndex = component2.CurrentPickupIndex().itemIndex;
            }
            CostTypeDef.PayCostResults payCostResults = costTypeDef.PayCost(this.cost, activator, base.gameObject, this.rng, itemIndex);
            foreach (ItemIndex itemIndex2 in payCostResults.itemsTaken)
            {
                PurchaseInteraction.CreateItemTakenOrb(component.corePosition, base.gameObject, itemIndex2);
                if (itemIndex2 != itemIndex)
                {
                    Action <PurchaseInteraction, Interactor> action = PurchaseInteraction.onItemSpentOnPurchase;
                    if (action != null)
                    {
                        action(this, activator);
                    }
                }
            }
            foreach (EquipmentIndex arg in payCostResults.equipmentTaken)
            {
                Action <PurchaseInteraction, Interactor, EquipmentIndex> action2 = PurchaseInteraction.onEquipmentSpentOnPurchase;
                if (action2 != null)
                {
                    action2(this, activator, arg);
                }
            }
            IEnumerable <StatDef> statDefsToIncrement = this.purchaseStatNames.Select(new Func <string, StatDef>(StatDef.Find));

            StatManager.OnPurchase <IEnumerable <StatDef> >(component, this.costType, statDefsToIncrement);
            this.onPurchase.Invoke(activator);
            this.lastActivator = activator;
        }
Beispiel #10
0
        // Token: 0x06000674 RID: 1652 RVA: 0x0001A624 File Offset: 0x00018824
        private void Rebuild()
        {
            BlueprintTerminal.UnlockableOption unlockableOption = this.unlockableOptions[this.unlockableChoice];
            if (this.displayInstance)
            {
                UnityEngine.Object.Destroy(this.displayInstance);
            }
            this.displayBaseTransform.gameObject.SetActive(!this.hasBeenPurchased);
            if (!this.hasBeenPurchased && this.displayBaseTransform)
            {
                Debug.Log("Found base");
                UnlockableDef unlockableDef = UnlockableCatalog.GetUnlockableDef(unlockableOption.unlockableName);
                if (unlockableDef != null)
                {
                    Debug.Log("Found unlockable");
                    GameObject gameObject = Resources.Load <GameObject>(unlockableDef.displayModelPath);
                    if (gameObject)
                    {
                        Debug.Log("Found prefab");
                        this.displayInstance = UnityEngine.Object.Instantiate <GameObject>(gameObject, this.displayBaseTransform.position, this.displayBaseTransform.transform.rotation, this.displayBaseTransform);
                        Renderer componentInChildren = this.displayInstance.GetComponentInChildren <Renderer>();
                        float    num = 1f;
                        if (componentInChildren)
                        {
                            this.displayInstance.transform.rotation = Quaternion.identity;
                            Vector3 size = componentInChildren.bounds.size;
                            float   f    = size.x * size.y * size.z;
                            num *= Mathf.Pow(this.idealDisplayVolume, 0.33333334f) / Mathf.Pow(f, 0.33333334f);
                        }
                        this.displayInstance.transform.localScale = new Vector3(num, num, num);
                    }
                }
            }
            PurchaseInteraction component = base.GetComponent <PurchaseInteraction>();

            if (component)
            {
                component.Networkcost = unlockableOption.cost;
            }
        }
            void GenerateNewPickupServer(On.RoR2.ShopTerminalBehavior.orig_GenerateNewPickupServer orig, ShopTerminalBehavior shopTerminalBehavior)
            {
                List <PickupIndex> shopList = new List <PickupIndex>();

                if (shopTerminalBehavior.itemTier == ItemTier.Tier1)
                {
                    shopList = Run.instance.availableTier1DropList;
                }
                else if (shopTerminalBehavior.itemTier == ItemTier.Tier2)
                {
                    shopList = Run.instance.availableTier2DropList;
                }
                else if (shopTerminalBehavior.itemTier == ItemTier.Tier3)
                {
                    shopList = Run.instance.availableTier3DropList;
                }
                else if (shopTerminalBehavior.itemTier == ItemTier.Boss)
                {
                    shopList = Run.instance.availableBossDropList;
                }
                else if (shopTerminalBehavior.itemTier == ItemTier.Lunar)
                {
                    shopList = Run.instance.availableLunarDropList;
                }
                if (shopList.Count > 0)
                {
                    orig(shopTerminalBehavior);
                }
                else
                {
                    shopTerminalBehavior.SetNoPickup();
                    RoR2.PurchaseInteraction purchaseInteraction = shopTerminalBehavior.GetComponent <RoR2.PurchaseInteraction>();
                    if (purchaseInteraction != null)
                    {
                        purchaseInteraction.SetAvailable(false);
                    }
                }
            }
        // Token: 0x06001294 RID: 4756 RVA: 0x0004FF00 File Offset: 0x0004E100
        private void PopulateScene()
        {
            ClassicStageInfo component = SceneInfo.instance.GetComponent <ClassicStageInfo>();

            this.PlaceTeleporter();
            Action action = new Action(this.DefaultPlayerSpawnPointGenerator);

            SceneDirector.GenerateSpawnPointsDelegate generateSpawnPointsDelegate = SceneDirector.onPreGeneratePlayerSpawnPointsServer;
            if (generateSpawnPointsDelegate != null)
            {
                generateSpawnPointsDelegate(this, ref action);
            }
            if (action != null)
            {
                action();
            }
            Run.instance.OnPlayerSpawnPointsPlaced(this);
            while (this.interactableCredit > 0)
            {
                DirectorCard directorCard = this.SelectCard(component.interactableSelection, this.interactableCredit);
                if (directorCard == null)
                {
                    break;
                }
                if (directorCard.CardIsValid())
                {
                    this.interactableCredit -= directorCard.cost;
                    if (Run.instance)
                    {
                        int i = 0;
                        while (i < 10)
                        {
                            DirectorPlacementRule placementRule = new DirectorPlacementRule
                            {
                                placementMode = DirectorPlacementRule.PlacementMode.Random
                            };
                            GameObject gameObject = this.directorCore.TrySpawnObject(new DirectorSpawnRequest(directorCard.spawnCard, placementRule, this.rng));
                            if (gameObject)
                            {
                                PurchaseInteraction component2 = gameObject.GetComponent <PurchaseInteraction>();
                                if (component2 && component2.costType == CostTypeIndex.Money)
                                {
                                    component2.Networkcost = Run.instance.GetDifficultyScaledCost(component2.cost);
                                    break;
                                }
                                break;
                            }
                            else
                            {
                                i++;
                            }
                        }
                    }
                }
            }
            if (Run.instance && Run.instance.stageClearCount == 0)
            {
                this.monsterCredit = 0;
            }
            int num = 0;

            while (this.monsterCredit > 0 && num < 40)
            {
                DirectorCard directorCard2 = this.SelectCard(component.monsterSelection, this.monsterCredit);
                if (directorCard2 == null)
                {
                    break;
                }
                if (directorCard2.CardIsValid())
                {
                    this.monsterCredit -= directorCard2.cost;
                    int j = 0;
                    while (j < 10)
                    {
                        DirectorSpawnRequest directorSpawnRequest = new DirectorSpawnRequest(directorCard2.spawnCard, new DirectorPlacementRule
                        {
                            placementMode = DirectorPlacementRule.PlacementMode.Random
                        }, this.rng);
                        directorSpawnRequest.teamIndexOverride = new TeamIndex?(TeamIndex.Monster);
                        GameObject gameObject2 = this.directorCore.TrySpawnObject(directorSpawnRequest);
                        if (gameObject2)
                        {
                            num++;
                            CharacterMaster component3 = gameObject2.GetComponent <CharacterMaster>();
                            if (component3)
                            {
                                GameObject bodyObject = component3.GetBodyObject();
                                if (bodyObject)
                                {
                                    DeathRewards component4 = bodyObject.GetComponent <DeathRewards>();
                                    if (component4)
                                    {
                                        component4.expReward  = (uint)((float)directorCard2.cost * this.expRewardCoefficient * Run.instance.difficultyCoefficient);
                                        component4.goldReward = (uint)((float)directorCard2.cost * this.expRewardCoefficient * 2f * Run.instance.difficultyCoefficient);
                                    }
                                    foreach (EntityStateMachine entityStateMachine in bodyObject.GetComponents <EntityStateMachine>())
                                    {
                                        entityStateMachine.initialStateType = entityStateMachine.mainStateType;
                                    }
                                }
                                num++;
                                break;
                            }
                            break;
                        }
                        else
                        {
                            j++;
                        }
                    }
                }
            }
            Xoroshiro128Plus xoroshiro128Plus = new Xoroshiro128Plus(this.rng.nextUlong);

            if (SceneInfo.instance.countsAsStage)
            {
                int num2 = 0;
                foreach (CharacterMaster characterMaster in CharacterMaster.readOnlyInstancesList)
                {
                    num2 += characterMaster.inventory.GetItemCount(ItemIndex.TreasureCache);
                }
                if (num2 > 0)
                {
                    GameObject gameObject3 = DirectorCore.instance.TrySpawnObject(new DirectorSpawnRequest(Resources.Load <SpawnCard>("SpawnCards/InteractableSpawnCard/iscLockbox"), new DirectorPlacementRule
                    {
                        placementMode = DirectorPlacementRule.PlacementMode.Random
                    }, xoroshiro128Plus));
                    if (gameObject3)
                    {
                        ChestBehavior component5 = gameObject3.GetComponent <ChestBehavior>();
                        if (component5)
                        {
                            component5.tier2Chance *= (float)num2;
                            component5.tier3Chance *= Mathf.Pow((float)num2, 2f);
                        }
                    }
                }
            }
        }
Beispiel #13
0
        private void PurchaseInteraction_OnInteractionBegin(On.RoR2.PurchaseInteraction.orig_OnInteractionBegin orig, RoR2.PurchaseInteraction self, RoR2.Interactor activator)
        {
            //Get the lowercase name of the Interacted Object
            string objName = self.gameObject.name.ToLower();

            //Check if its a supported Chest
            if (!objName.Contains("chest1") && !objName.Contains("chest2") && !objName.Contains("goldchest") && !objName.Contains("equipmentbarrel") && !objName.Contains("isclockbox"))
            {
                orig.Invoke(self, activator);
                return;
            }

            //Get the chest type
            //Too lazy and tired to make it prettier
            int chestType = objName.Contains("chest1") ? 0 : objName.Contains("chest2") ? 1 : objName.Contains("goldchest") ? 2 : objName.Contains("isclockbox") ? 3 : -1;

            //Randomly Select Tier
            double tier = GetRandomTier(chestType);

            //Send every client a message that a chest has been opened
            ExampleFuncClient.Invoke(activator.gameObject, check =>
            {
                //Check which client opened the chest and wheter or not he is idling
                Debug.Log("Check: " + check);
                if (check == 0)
                {
                    orig.Invoke(self, activator);
                }
                if (check != 0)
                {
                    return;
                }


                if (objName.Contains("equipmentbarrel"))
                {
                    //Signal the server that a chest has been opened
                    //Give the player that opend it and the chest position
                    ExampleCommandClientCustom.Invoke(x =>
                    {
                        x.Write("Chest");
                        x.Write(activator.gameObject);
                        x.Write(self.gameObject.transform);
                        //Specify tier as Equipment
                        x.Write((double)6);
                    });
                }
                else
                {
                    // RNG Value was above specified percantage values
                    // Cancel the drop

                    /*if (tier == 0)
                     * {
                     *  Debug.Log("Mhh Unlucky you found nothing in this Chest.");
                     *  return;
                     * }*/

                    //Signal the server that a chest has been opened
                    //Give the player that opend it and the chest position
                    ExampleCommandClientCustom.Invoke(x =>
                    {
                        x.Write("Chest");
                        x.Write(activator.gameObject);
                        x.Write(self.gameObject.transform);
                        x.Write(tier);
                    });
                }
            });
        }
Beispiel #14
0
        private static void OnShopPurchase(On.RoR2.PurchaseInteraction.orig_OnInteractionBegin orig, RoR2.PurchaseInteraction self, RoR2.Interactor activator)
        {
            if (!self.CanBeAffordedByInteractor(activator))
            {
                return;
            }
            #region Sharedmoney

            if (ShareSuite.MoneyIsShared.Value)
            {
                switch (self.costType)
                {
                case CostTypeIndex.Money:
                {
                    // Remove money from shared money pool
                    orig(self, activator);
                    MoneySharingHooks.SharedMoneyValue -= self.cost;
                    return;
                }

                case CostTypeIndex.PercentHealth:
                {
                    // Share the damage taken from a sacrifice
                    // as it generates shared money
                    orig(self, activator);
                    var teamMaxHealth = 0;
                    foreach (var playerCharacterMasterController in PlayerCharacterMasterController.instances)
                    {
                        var charMaxHealth = playerCharacterMasterController.master.GetBody().maxHealth;
                        if (charMaxHealth > teamMaxHealth)
                        {
                            teamMaxHealth = (int)charMaxHealth;
                        }
                    }

                    var purchaseInteraction = self.GetComponent <PurchaseInteraction>();
                    var shrineBloodBehavior = self.GetComponent <ShrineBloodBehavior>();
                    var amount = (uint)(teamMaxHealth * purchaseInteraction.cost / 100.0 *
                                        shrineBloodBehavior.goldToPaidHpRatio);

                    if (ShareSuite.MoneyScalarEnabled.Value)
                    {
                        amount *= (uint)ShareSuite.MoneyScalar.Value;
                    }

                    MoneySharingHooks.SharedMoneyValue += (int)amount;
                    return;
                }
                }
            }
            orig(self, activator);

            #endregion
        }
Beispiel #15
0
        // Token: 0x06001386 RID: 4998 RVA: 0x0005F488 File Offset: 0x0005D688
        private string GetCostString()
        {
            switch (this.costType)
            {
            case CostType.None:
                return("");

            case CostType.Money:
                return(string.Format(" (<nobr><style=cShrine>${0}</style></nobr>)", this.cost));

            case CostType.PercentHealth:
                return(string.Format(" (<nobr><style=cDeath>{0}% HP</style></nobr>)", this.cost));

            case CostType.Lunar:
                return(string.Format(" (<nobr><color=#{1}>{0}</color></nobr>)", this.cost, ColorCatalog.GetColorHexString(ColorCatalog.ColorIndex.LunarCoin)));

            case CostType.WhiteItem:
                return(string.Format(" <nobr>(<nobr><color=#{1}>{0} Items</color></nobr>)", this.cost, ColorCatalog.GetColorHexString(PurchaseInteraction.CostTypeToColorIndex(this.costType))));

            case CostType.GreenItem:
                return(string.Format(" <nobr>(<nobr><color=#{1}>{0} Items</color></nobr>)", this.cost, ColorCatalog.GetColorHexString(PurchaseInteraction.CostTypeToColorIndex(this.costType))));

            case CostType.RedItem:
                return(string.Format(" <nobr>(<nobr><color=#{1}>{0} Items</color></nobr>)", this.cost, ColorCatalog.GetColorHexString(PurchaseInteraction.CostTypeToColorIndex(this.costType))));

            default:
                return("");
            }
        }
Beispiel #16
0
        // Token: 0x0600138F RID: 5007 RVA: 0x0005F7EC File Offset: 0x0005D9EC
        public void OnInteractionBegin(Interactor activator)
        {
            if (!this.CanBeAffordedByInteractor(activator))
            {
                return;
            }
            CharacterBody component = activator.GetComponent <CharacterBody>();

            switch (this.costType)
            {
            case CostType.Money:
                if (component)
                {
                    CharacterMaster master = component.master;
                    if (master)
                    {
                        master.money -= (uint)this.cost;
                    }
                }
                break;

            case CostType.PercentHealth:
            {
                HealthComponent component2 = activator.GetComponent <HealthComponent>();
                if (component2)
                {
                    float health = component2.health;
                    float num    = component2.fullHealth * (float)this.cost / 100f;
                    if (health > num)
                    {
                        component2.TakeDamage(new DamageInfo
                            {
                                damage     = num,
                                attacker   = base.gameObject,
                                position   = base.transform.position,
                                damageType = DamageType.BypassArmor
                            });
                    }
                }
                break;
            }

            case CostType.Lunar:
            {
                NetworkUser networkUser = Util.LookUpBodyNetworkUser(activator.gameObject);
                if (networkUser)
                {
                    networkUser.DeductLunarCoins((uint)this.cost);
                }
                break;
            }

            case CostType.WhiteItem:
            case CostType.GreenItem:
            case CostType.RedItem:
            {
                ItemTier itemTier = PurchaseInteraction.CostTypeToItemTier(this.costType);
                if (component)
                {
                    Inventory inventory = component.inventory;
                    if (inventory)
                    {
                        ItemIndex            itemIndex  = ItemIndex.None;
                        ShopTerminalBehavior component3 = base.GetComponent <ShopTerminalBehavior>();
                        if (component3)
                        {
                            itemIndex = component3.CurrentPickupIndex().itemIndex;
                        }
                        WeightedSelection <ItemIndex> weightedSelection = new WeightedSelection <ItemIndex>(8);
                        foreach (ItemIndex itemIndex2 in ItemCatalog.allItems)
                        {
                            if (itemIndex2 != itemIndex)
                            {
                                int itemCount = inventory.GetItemCount(itemIndex2);
                                if (itemCount > 0 && ItemCatalog.GetItemDef(itemIndex2).tier == itemTier)
                                {
                                    weightedSelection.AddChoice(itemIndex2, (float)itemCount);
                                }
                            }
                        }
                        List <ItemIndex> list = new List <ItemIndex>();
                        int num2 = 0;
                        while (weightedSelection.Count > 0 && num2 < this.cost)
                        {
                            int num3 = weightedSelection.EvaluteToChoiceIndex(this.rng.nextNormalizedFloat);
                            WeightedSelection <ItemIndex> .ChoiceInfo choice = weightedSelection.GetChoice(num3);
                            ItemIndex value = choice.value;
                            int       num4  = (int)choice.weight;
                            num4--;
                            if (num4 <= 0)
                            {
                                weightedSelection.RemoveChoice(num3);
                            }
                            else
                            {
                                weightedSelection.ModifyChoiceWeight(num3, (float)num4);
                            }
                            list.Add(value);
                            num2++;
                        }
                        for (int i = num2; i < this.cost; i++)
                        {
                            list.Add(itemIndex);
                        }
                        for (int j = 0; j < list.Count; j++)
                        {
                            ItemIndex itemIndex3 = list[j];
                            PurchaseInteraction.CreateItemTakenOrb(component.corePosition, base.gameObject, itemIndex3);
                            inventory.RemoveItem(itemIndex3, 1);
                            if (itemIndex3 != itemIndex)
                            {
                                Action <PurchaseInteraction, Interactor> action = PurchaseInteraction.onItemSpentOnPurchase;
                                if (action != null)
                                {
                                    action(this, activator);
                                }
                            }
                        }
                    }
                }
                break;
            }
            }
            IEnumerable <StatDef> statDefsToIncrement = this.purchaseStatNames.Select(new Func <string, StatDef>(StatDef.Find));

            StatManager.OnPurchase <IEnumerable <StatDef> >(component, this.costType, statDefsToIncrement);
            this.onPurchase.Invoke(activator);
            this.lastActivator = activator;
        }