// Token: 0x060010AC RID: 4268 RVA: 0x00049178 File Offset: 0x00047378
 public string GetContextString(Interactor activator)
 {
     PurchaseInteraction.sharedStringBuilder.Clear();
     PurchaseInteraction.sharedStringBuilder.Append(Language.GetString(this.contextToken));
     if (this.costType != CostTypeIndex.None)
     {
         PurchaseInteraction.sharedStringBuilder.Append(" <nobr>(");
         CostTypeCatalog.GetCostTypeDef(this.costType).BuildCostStringStyled(this.cost, PurchaseInteraction.sharedStringBuilder, false, true);
         PurchaseInteraction.sharedStringBuilder.Append(")</nobr>");
     }
     return(PurchaseInteraction.sharedStringBuilder.ToString());
 }
 // Token: 0x060009DE RID: 2526 RVA: 0x0002B010 File Offset: 0x00029210
 private void FixedUpdate()
 {
     if (this.targetTextMesh)
     {
         CostHologramContent.sharedStringBuilder.Clear();
         Color       color       = Color.white;
         CostTypeDef costTypeDef = CostTypeCatalog.GetCostTypeDef(this.costType);
         if (costTypeDef != null)
         {
             costTypeDef.BuildCostStringStyled(this.displayValue, CostHologramContent.sharedStringBuilder, true, false);
             color = costTypeDef.GetCostColor(true);
         }
         this.targetTextMesh.SetText(CostHologramContent.sharedStringBuilder);
         this.targetTextMesh.color = color;
     }
 }
        // 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;
        }
 // Token: 0x060010AE RID: 4270 RVA: 0x00049245 File Offset: 0x00047445
 public bool CanBeAffordedByInteractor(Interactor activator)
 {
     return(CostTypeCatalog.GetCostTypeDef(this.costType).IsAffordable(this.cost, activator));
 }
Example #5
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
            });