void DrainTargetStrength(DaggerfallEntityBehaviour entity, int amount)
        {
            if (entity == null)
            {
                return;
            }

            EntityEffectManager targetManager = entity.GetComponent <EntityEffectManager>();

            if (targetManager == null)
            {
                return;
            }

            // Find incumbent strength drain effect on target or assign new drain
            DrainStrength drain = targetManager.FindIncumbentEffect <DrainStrength>() as DrainStrength;

            if (drain == null)
            {
                // Create and assign bundle
                // We bypass saving throws as target already had a chance at start of payload delivery
                EntityEffectBundle bundle = targetManager.CreateSpellBundle(DrainStrength.EffectKey);
                targetManager.AssignBundle(bundle, AssignBundleFlags.BypassSavingThrows);

                // Find new bundle now its assigned
                drain = targetManager.FindIncumbentEffect <DrainStrength>() as DrainStrength;
            }

            // Increment incumbent drain magnitude on target
            if (drain != null)
            {
                drain.IncreaseMagnitude(amount);
            }
        }
        MaceOfMolagBalEffect FindLiveEffect(DaggerfallEntityBehaviour entity)
        {
            if (entity == null)
            {
                return(null);
            }

            EntityEffectManager targetManager = entity.GetComponent <EntityEffectManager>();

            if (targetManager == null)
            {
                return(null);
            }

            return(targetManager.FindIncumbentEffect <MaceOfMolagBalEffect>() as MaceOfMolagBalEffect);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Attempt to trap a soul.
        /// </summary>
        /// <returns>True if entity is allowed to die after trap attempt.</returns>
        bool AttemptSoulTrap()
        {
            // Must have a peered DaggerfallEntityBehaviour and EntityEffectManager
            EntityEffectManager manager = (EntityBehaviour) ? EntityBehaviour.GetComponent <EntityEffectManager>() : null;

            if (!manager)
            {
                return(true);
            }

            // Find the soul trap incumbent
            SoulTrap soulTrapEffect = (SoulTrap)manager.FindIncumbentEffect <SoulTrap>();

            if (soulTrapEffect == null)
            {
                return(true);
            }

            // Roll chance for trap
            // If trap fails then entity should die as normal without trapping a soul
            // If trap succeeds and player has a free soul gem then entity should die after storing soul
            // If trap succeeds and player has no free soul gems then entity will not die until effect expires or fails
            if (soulTrapEffect.RollTrapChance())
            {
                // Attempt to fill an empty soul trap
                if (SoulTrap.FillEmptyTrapItem((MobileTypes)mobileEnemy.ID))
                {
                    // Trap filled, allow entity to die normally
                    DaggerfallUI.AddHUDText(TextManager.Instance.GetLocalizedText("trapSuccess"), 1.5f);
                    return(true);
                }
                else
                {
                    // No empty gems, keep entity tethered to life - player is alerted so they know what's happening
                    currentHealth = 1;
                    DaggerfallUI.AddHUDText(TextManager.Instance.GetLocalizedText("trapNoneEmpty"));
                    return(false);
                }
            }
            else
            {
                // Trap failed
                DaggerfallUI.AddHUDText(TextManager.Instance.GetLocalizedText("trapFail"), 1.5f);
                return(true);
            }
        }
Ejemplo n.º 4
0
        public int DecreaseHealth(int amount)
        {
            // Allow an active shield effect to mitigate incoming damage from all sources
            // Testing classic shows that Shield will mitigate physical, magical, and fall damage
            if (EntityBehaviour)
            {
                EntityEffectManager manager = EntityBehaviour.GetComponent <EntityEffectManager>();
                if (manager)
                {
                    Shield shield = (Shield)manager.FindIncumbentEffect <Shield>();
                    if (shield != null)
                    {
                        amount = shield.DamageShield(amount);
                    }
                }
            }

            return(SetHealth(currentHealth - amount));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Attempt to trap a soul.
        /// </summary>
        /// <returns>True if entity is allowed to die after trap attempt.</returns>
        bool AttemptSoulTrap()
        {
            // Must have a peered DaggerfallEntityBehaviour and EntityEffectManager
            EntityEffectManager manager = (EntityBehaviour) ? EntityBehaviour.GetComponent <EntityEffectManager>() : null;

            if (!manager)
            {
                return(true);
            }

            // Find the soul trap incumbent
            SoulTrap soulTrapEffect = (SoulTrap)manager.FindIncumbentEffect <SoulTrap>();

            if (soulTrapEffect == null)
            {
                return(true);
            }

            // Roll chance for trap, or always succeed if Azura's Star is equipped.
            // If trap fails then entity should die as normal without trapping a soul
            // If trap succeeds and player has a free soul gem then entity should die after storing soul
            // If trap succeeds and player has no free soul gems then entity will not die until effect expires or fails
            bool azurasStarEquipped        = false;
            DaggerfallUnityItem azurasStar = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(EquipSlots.Amulet0);

            if (azurasStar != null && azurasStar.ContainsEnchantment(EnchantmentTypes.SpecialArtifactEffect, (short)ArtifactsSubTypes.Azuras_Star))
            {
                azurasStarEquipped = true;
            }
            else
            {
                azurasStar = GameManager.Instance.PlayerEntity.ItemEquipTable.GetItem(Game.Items.EquipSlots.Amulet1);
                if (azurasStar != null && azurasStar.ContainsEnchantment(EnchantmentTypes.SpecialArtifactEffect, (short)ArtifactsSubTypes.Azuras_Star))
                {
                    azurasStarEquipped = true;
                }
            }

            if (azurasStarEquipped || soulTrapEffect.RollTrapChance())
            {
                // Attempt to fill an empty soul trap
                if (soulTrapEffect.FillEmptyTrapItem((MobileTypes)mobileEnemy.ID))
                {
                    // Trap filled, allow entity to die normally
                    DaggerfallUI.AddHUDText(TextManager.Instance.GetText("ClassicEffects", "trapSuccess"), 1.5f);
                    return(true);
                }
                else
                {
                    // No empty gems, keep entity tethered to life - player is alerted so they know what's happening
                    currentHealth = 1;
                    DaggerfallUI.AddHUDText(TextManager.Instance.GetText("ClassicEffects", "trapNoneEmpty"));
                    return(false);
                }
            }
            else
            {
                // Trap failed
                DaggerfallUI.AddHUDText(TextManager.Instance.GetText("ClassicEffects", "trapFail"), 1.5f);
                return(true);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Decide whether or not to pursue enemy, based on perceived combat odds.
        /// </summary>
        void EvaluateMoveInForAttack()
        {
            // Classic always attacks
            if (!DaggerfallUnity.Settings.EnhancedCombatAI)
            {
                moveInForAttack = true;
                return;
            }

            // No retreat from unseen opponent
            if (!senses.TargetInSight)
            {
                moveInForAttack = true;
                return;
            }

            // No retreat if enemy is paralyzed
            if (entityBehaviour.Target != null)
            {
                EntityEffectManager targetEffectManager = entityBehaviour.Target.GetComponent <EntityEffectManager>();
                if (targetEffectManager.FindIncumbentEffect <MagicAndEffects.MagicEffects.Paralyze>() != null)
                {
                    moveInForAttack = true;
                    return;
                }

                // No retreat if enemy's back is turned
                if (senses.TargetHasBackTurned())
                {
                    moveInForAttack = true;
                    return;
                }

                // No retreat if enemy is player with bow or weapon not out
                if (entityBehaviour.Target == GameManager.Instance.PlayerEntityBehaviour &&
                    GameManager.Instance.WeaponManager.ScreenWeapon &&
                    (GameManager.Instance.WeaponManager.ScreenWeapon.WeaponType == WeaponTypes.Bow ||
                     !GameManager.Instance.WeaponManager.ScreenWeapon.ShowWeapon))
                {
                    moveInForAttack = true;
                    return;
                }
            }
            else
            {
                return;
            }

            const float retreatDistanceBaseMult = 2.25f;

            // Level difference affects likelihood of backing away.
            moveInForAttackTimer = Random.Range(1, 3);
            int levelMod = (entity.Level - entityBehaviour.Target.Entity.Level) / 2;

            if (levelMod > 4)
            {
                levelMod = 4;
            }
            if (levelMod < -4)
            {
                levelMod = -4;
            }

            int roll = Random.Range(0 + levelMod, 10 + levelMod);

            moveInForAttack = roll > 4;

            // Chose to retreat
            if (!moveInForAttack)
            {
                retreatDistanceMultiplier = (float)(retreatDistanceBaseMult + (retreatDistanceBaseMult * (0.25 * (2 - roll))));
            }
        }