public override void RunAction()
        {
            MechanicsContext           context     = ElementsContext.GetData <MechanicsContext.Data>()?.Context;
            EnchantPoolDataDescription description = new EnchantPoolDataDescription();

            if (context == null)
            {
                UberDebug.LogError((UnityEngine.Object) this, (object)"Unable to apply buff: no context found", (object[])Array.Empty <object>());
            }
            else
            {
                Rounds         rounds      = this.DurationValue.Calculate(context);
                UnitEntityData maybeCaster = context.MaybeCaster;
                if (maybeCaster == null)
                {
                    UberDebug.LogError((UnityEngine.Object) this, (object)"Can't apply buff: target is null", (object[])Array.Empty <object>());
                }
                else
                {
                    maybeCaster.Ensure <UnitPartEnchantPoolData>().ClearEnchantPool(this.EnchantPool);
                    ItemEntity itemEntity = maybeCaster.Body.PrimaryHand.HasWeapon ? (ItemEntity)maybeCaster.Body.PrimaryHand.MaybeWeapon : (ItemEntity)maybeCaster.Body.EmptyHandWeapon;
                    if (itemEntity == null)
                    {
                        return;
                    }
                    int num1      = 0;
                    int groupSize = maybeCaster.Descriptor.Progression.Features.GetRank(Feature);
                    description.EnchantedItem = itemEntity;
                    description.EnchantPool   = this.EnchantPool;
                    if (itemEntity.Enchantments.Any <ItemEnchantment>())
                    {
                        foreach (WeaponEnhancementBonus enhancementBonus in itemEntity.Enchantments.SelectMany <ItemEnchantment, WeaponEnhancementBonus>((Func <ItemEnchantment, IEnumerable <WeaponEnhancementBonus> >)(e => e.SelectComponents <WeaponEnhancementBonus>())))
                        {
                            num1 += enhancementBonus.EnhancementBonus;
                        }
                    }

                    foreach (AddBondProperty selectFactComponent in maybeCaster.Buffs.SelectFactComponents <AddBondProperty>())
                    {
                        if (selectFactComponent.EnchantPool == this.EnchantPool && !itemEntity.HasEnchantment(selectFactComponent.Enchant))
                        {
                            groupSize -= selectFactComponent.Enchant.EnchantmentCost;
                            description.Enchantments.Add(itemEntity.AddEnchantment(selectFactComponent.Enchant, context, new Rounds?(rounds)));
                        }
                    }

                    int num2 = Math.Min(Math.Max(0, 5 - num1), groupSize);
                    if (num2 > 0)
                    {
                        description.Enchantments.Add(itemEntity.AddEnchantment(this.DefaultEnchantments[num2 - 1], context, new Rounds?(rounds)));
                    }
                    maybeCaster.Ensure <UnitPartEnchantPoolData>().RecordEnchantPool(description);
                }
            }
        }
Beispiel #2
0
        public override void OnTurnOn()
        {
            Main.logger.Log("AddSacredWordBonus OnTurnOn");
            EnchantPoolDataDescription description = new EnchantPoolDataDescription();

            Rounds         rounds      = new Rounds(1);
            UnitEntityData maybeCaster = base.Owner.Unit;

            maybeCaster.Ensure <UnitPartEnchantPoolData>().ClearEnchantPool(this.EnchantPool);
            ItemEntity itemEntity = maybeCaster.Body.PrimaryHand.HasWeapon ? (ItemEntity)maybeCaster.Body.PrimaryHand.MaybeWeapon : (ItemEntity)maybeCaster.Body.EmptyHandWeapon;

            if (itemEntity == null)
            {
                return;
            }
            int num1      = 0;
            int groupSize = maybeCaster.Ensure <UnitPartActivatableAbility>().GetGroupSize(this.Group);

            description.EnchantedItem = itemEntity;
            description.EnchantPool   = this.EnchantPool;
            if (itemEntity.Enchantments.Any <ItemEnchantment>())
            {
                foreach (WeaponEnhancementBonus enhancementBonus in itemEntity.Enchantments.SelectMany <ItemEnchantment, WeaponEnhancementBonus>((Func <ItemEnchantment, IEnumerable <WeaponEnhancementBonus> >)(e => e.SelectComponents <WeaponEnhancementBonus>())))
                {
                    num1 += enhancementBonus.EnhancementBonus;
                }
            }

            foreach (AddBondProperty selectFactComponent in maybeCaster.Buffs.SelectFactComponents <AddBondProperty>())
            {
                if (selectFactComponent.EnchantPool == this.EnchantPool && !itemEntity.HasEnchantment(selectFactComponent.Enchant))
                {
                    groupSize -= selectFactComponent.Enchant.EnchantmentCost;
                    description.Enchantments.Add(itemEntity.AddEnchantment(selectFactComponent.Enchant, null, new Rounds?(rounds)));
                }
            }

            int num2 = Math.Min(Math.Max(0, 5 - num1), groupSize);

            if (num2 > 0)
            {
                description.Enchantments.Add(itemEntity.AddEnchantment(this.DefaultEnchantments[num2 - 1], null, new Rounds?(rounds)));
            }
            maybeCaster.Ensure <UnitPartEnchantPoolData>().RecordEnchantPool(description);
            Main.logger.Log("AddSacredWordBonus end");
        }
Beispiel #3
0
        public override void OnFactActivate()
        {
            m_unlock = false;
            var unit = this.Owner;

            if (unit == null)
            {
                return;
            }

            Main.DebugLog(unit.Body.Wrist.MaybeItem?.ToString() ?? "wrist is null");

            ItemEntity armor = unit.Body.Armor.MaybeArmor;

            Main.DebugLog("1: " + armor?.ToString() ?? "armor is null");
            if (armor == null)
            {
                armor = unit.Body.Wrist.MaybeItem;
            }
            Main.DebugLog("2: " + armor?.ToString() ?? "wrist-armor is null");
            if (armor == null)
            {
                return;
            }

            int bonus = value.Calculate(Context) - 1;

            Main.DebugLog("3: " + bonus);
            if (bonus < 0)
            {
                bonus = 0;
            }
            if (bonus >= enchantments.Length)
            {
                bonus = enchantments.Length - 1;
            }
            Main.DebugLog("4: " + bonus);
            Main.DebugLog("5: " + enchantments.Length);

            if (armor.Enchantments.HasFact(enchantments[bonus]))
            {
                Main.DebugLog("6: Enchantments.HasFact");
                return;
            }

            m_Enchantment = armor.AddEnchantment(enchantments[bonus], Context, new Rounds?());

            //armor.RecalculateStats();
            m_Armor = armor;
            if (lock_slot && !armor.IsNonRemovable)
            {
                armor.IsNonRemovable = true;
                m_unlock             = true;
            }

            Main.DebugLog("x: ");
        }