Beispiel #1
0
        /// <summary>
        /// Checks whether the target already is affected by all of the effects of the given spell.
        /// </summary>
        bool EffectsAlreadyOnTarget(EntityEffectBundle spell)
        {
            if (entityBehaviour.Target)
            {
                EntityEffectManager targetEffectManager = entityBehaviour.Target.GetComponent <EntityEffectManager>();
                LiveEffectBundle[]  bundles             = targetEffectManager.EffectBundles;

                for (int i = 0; i < spell.Settings.Effects.Length; i++)
                {
                    bool foundEffect = false;
                    // Get effect template
                    IEntityEffect effectTemplate = GameManager.Instance.EntityEffectBroker.GetEffectTemplate(spell.Settings.Effects[i].Key);
                    for (int j = 0; j < bundles.Length && !foundEffect; j++)
                    {
                        for (int k = 0; k < bundles[j].liveEffects.Count && !foundEffect; k++)
                        {
                            if (bundles[j].liveEffects[k].GetType() == effectTemplate.GetType())
                            {
                                foundEffect = true;
                            }
                        }
                    }

                    if (!foundEffect)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Clone an effect and its settings.
        /// </summary>
        /// <param name="effect">Effect to clone.</param>
        /// <returns>Interface to cloned effect.</returns>
        public IEntityEffect CloneEffect(IEntityEffect effect)
        {
            IEntityEffect clone = Activator.CreateInstance(effect.GetType()) as IEntityEffect;

            clone.Settings = effect.Settings;

            return(clone);
        }
        /// <summary>
        /// Creates a new instance of effect with specified settings.
        /// Use this to create a new effect with unique settings for actual use.
        /// </summary>
        /// <param name="key">Effect key.</param>
        /// <param name="settings">Effect settings.</param>
        /// <returns>Interface to new effect instance.</returns>
        public IEntityEffect InstantiateEffect(string key, EffectSettings settings)
        {
            if (!HasEffectTemplate(key))
            {
                return(null);
            }

            IEntityEffect effectTemplate = magicEffectTemplates[key];
            IEntityEffect effectInstance = Activator.CreateInstance(effectTemplate.GetType()) as IEntityEffect;

            effectInstance.Settings = settings;

            return(effectInstance);
        }