Exemple #1
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);
            }
        }
Exemple #2
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;
        }