예제 #1
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;
        }
예제 #2
0
        private static void Init()
        {
            CostTypeCatalog.costTypeDefs = new CostTypeDef[11];
            CostTypeIndex costType     = CostTypeIndex.None;
            CostTypeDef   costTypeDef7 = new CostTypeDef();

            costTypeDef7.buildCostString = delegate(CostTypeDef costTypeDef, CostTypeDef.BuildCostStringContext context)
            {
                context.stringBuilder.Append("");
            };
            costTypeDef7.isAffordable = ((CostTypeDef costTypeDef, CostTypeDef.IsAffordableContext context) => true);
            costTypeDef7.payCost      = delegate(CostTypeDef costTypeDef, CostTypeDef.PayCostContext context)
            {
            };
            CostTypeCatalog.Register(costType, costTypeDef7);
            CostTypeIndex costType2    = CostTypeIndex.Money;
            CostTypeDef   costTypeDef2 = new CostTypeDef();

            costTypeDef2.costStringFormatToken = "COST_MONEY_FORMAT";
            costTypeDef2.isAffordable          = delegate(CostTypeDef costTypeDef, CostTypeDef.IsAffordableContext context)
            {
                CharacterBody component = context.activator.GetComponent <CharacterBody>();
                if (component)
                {
                    CharacterMaster master = component.master;
                    if (master)
                    {
                        return((ulong)master.money >= (ulong)((long)context.cost));
                    }
                }
                return(false);
            };
            costTypeDef2.payCost = delegate(CostTypeDef costTypeDef, CostTypeDef.PayCostContext context)
            {
                if (context.activatorMaster)
                {
                    context.activatorMaster.money -= (uint)context.cost;
                }
            };
            costTypeDef2.colorIndex = ColorCatalog.ColorIndex.Money;
            CostTypeCatalog.Register(costType2, costTypeDef2);
            CostTypeIndex costType3    = CostTypeIndex.PercentHealth;
            CostTypeDef   costTypeDef3 = new CostTypeDef();

            costTypeDef3.costStringFormatToken         = "COST_PERCENTHEALTH_FORMAT";
            costTypeDef3.saturateWorldStyledCostString = false;
            costTypeDef3.darkenWorldStyledCostString   = true;
            costTypeDef3.isAffordable = delegate(CostTypeDef costTypeDef, CostTypeDef.IsAffordableContext context)
            {
                HealthComponent component = context.activator.GetComponent <HealthComponent>();
                return(component && component.combinedHealth / component.fullCombinedHealth * 100f >= (float)context.cost);
            };
            costTypeDef3.payCost = delegate(CostTypeDef costTypeDef, CostTypeDef.PayCostContext context)
            {
                HealthComponent component = context.activator.GetComponent <HealthComponent>();
                if (component)
                {
                    float combinedHealth = component.combinedHealth;
                    float num            = component.fullCombinedHealth * (float)context.cost / 100f;
                    if (combinedHealth > num)
                    {
                        component.TakeDamage(new DamageInfo
                        {
                            damage     = num,
                            attacker   = context.purchasedObject,
                            position   = context.purchasedObject.transform.position,
                            damageType = (DamageType.NonLethal | DamageType.BypassArmor)
                        });
                    }
                }
            };
            costTypeDef3.colorIndex = ColorCatalog.ColorIndex.Blood;
            CostTypeCatalog.Register(costType3, costTypeDef3);
            CostTypeIndex costType4    = CostTypeIndex.LunarCoin;
            CostTypeDef   costTypeDef4 = new CostTypeDef();

            costTypeDef4.costStringFormatToken         = "COST_LUNARCOIN_FORMAT";
            costTypeDef4.saturateWorldStyledCostString = false;
            costTypeDef4.darkenWorldStyledCostString   = true;
            costTypeDef4.isAffordable = delegate(CostTypeDef costTypeDef, CostTypeDef.IsAffordableContext context)
            {
                NetworkUser networkUser = Util.LookUpBodyNetworkUser(context.activator.gameObject);
                return(networkUser && (ulong)networkUser.lunarCoins >= (ulong)((long)context.cost));
            };
            costTypeDef4.payCost = delegate(CostTypeDef costTypeDef, CostTypeDef.PayCostContext context)
            {
                NetworkUser networkUser = Util.LookUpBodyNetworkUser(context.activator.gameObject);
                if (networkUser)
                {
                    networkUser.DeductLunarCoins((uint)context.cost);
                }
            };
            costTypeDef4.colorIndex = ColorCatalog.ColorIndex.LunarCoin;
            CostTypeCatalog.Register(costType4, costTypeDef4);
            CostTypeCatalog.Register(CostTypeIndex.WhiteItem, new CostTypeDef
            {
                costStringFormatToken = "COST_ITEM_FORMAT",
                isAffordable          = new CostTypeDef.IsAffordableDelegate(CostTypeCatalog.< > c.< > 9. < Init > g__IsAffordableItem | 5_0),
                payCost    = new CostTypeDef.PayCostDelegate(CostTypeCatalog.< > c.< > 9. < Init > g__PayCostItems | 5_1),
                colorIndex = ColorCatalog.ColorIndex.Tier1Item,
                itemTier   = ItemTier.Tier1
            });