Пример #1
0
        static void RetriggerEffectsForArea(GameEffectCollection effects, DynamicObject caster, Vector3 origin, float radius, LayerMask mask, bool checkLOSOnRadiusCast, bool isCast)
        {
            HashSet <DynamicObject> handledObjects = new HashSet <DynamicObject>();

            Collider[] colliders = Physics.OverlapSphere(origin, radius, mask, QueryTriggerInteraction.Ignore);

            foreach (Collider c in colliders)
            {
                DynamicObject obj = c.GetComponentInParent <DynamicObject>();
                if (obj == null)
                {
                    continue;
                }
                if (handledObjects.Contains(obj))
                {
                    continue;
                }

                if (!RaycastToCollider(checkLOSOnRadiusCast, c, origin, radius, mask, out Vector3 pos))
                {
                    continue;
                }

                handledObjects.Add(obj);
                TriggerEffects(effects, caster, pos, obj, isCast, true);
            }
        }
Пример #2
0
        // only workds for radius
        public static void TriggerEffectsAtPosition(GameEffectCollection effects, DynamicObject caster, Vector3 pos)
        {
            if (effects.cast.radius <= 0)
            {
                Debug.LogError(effects.name + " effects collection cant be triggered at position wihtout a target, radius <= 0");
                return;
            }

            TriggerEffects(effects, caster, pos, null, true);
        }
Пример #3
0
        string GetDescription(GameEffectCollection effects)
        {
            string           d           = effects.description + ":\n";
            List <GEUpdater> updaterList = updaters[effects];

            for (int i = 0; i < updaterList.Count; i++)
            {
                string description = updaterList[i].GetDescription();
                if (!string.IsNullOrEmpty(description))
                {
                    d += "\t" + updaterList[i].GetDescription() + "\n";
                }
            }
            return(d);
        }
Пример #4
0
        public void AddEffectsToList(GameEffectCollection collection, DynamicObject caster, List <GameEffect> effects, List <float> magnitudes, List <float> durations)
        {
            if (updaters.ContainsKey(collection))
            {
                Debug.LogWarning(name + " is already being affected by effect colleciton " + collection.name);
                return;
            }

            List <GEUpdater> u = new List <GEUpdater>();

            for (int i = 0; i < effects.Count; i++)
            {
                u.Add(new GEUpdater(caster, effects[i], magnitudes[i], durations[i]));
            }

            updaters[collection] = u;
        }
Пример #5
0
 public bool IsAffectedBy(GameEffectCollection collection)
 {
     return(updaters.ContainsKey(collection));
 }
Пример #6
0
 public static void TriggerEffectsOnObject(GameEffectCollection effects, DynamicObject caster, Vector3 pos, DynamicObject obj)
 {
     TriggerEffects(effects, caster, pos, obj, true);
 }
Пример #7
0
 public static void TriggerEffectsOnObject(GameEffectCollection effects, DynamicObject caster, DynamicObject obj)
 {
     TriggerEffectsOnObject(effects, caster, obj.GetPosition(), obj);
 }
Пример #8
0
 public static void TriggerEffectsOnSelf(GameEffectCollection effects, DynamicObject caster, Vector3 pos)
 {
     TriggerEffectsOnObject(effects, caster, pos, caster);
 }
Пример #9
0
 public static void TriggerEffectsOnSelf(GameEffectCollection effects, DynamicObject caster)
 {
     TriggerEffectsOnSelf(effects, caster, caster.transform.position);
 }
Пример #10
0
        public static void TriggerEffects(GameEffectCollection effects, DynamicObject caster, Vector3 pos, DynamicObject obj, bool isCast, bool isFromRadiusRecast = false)
        {
            ModifierEntryPoints casterEntryPoints = null;

            if (caster != null)
            {
                casterEntryPoints = caster.GetObjectScript <ModifierEntryPoints>();
            }

            EffectContext context = isCast ? effects.cast : effects.dispell;

            float radius = context.radius;

            if (!isFromRadiusRecast && radius > 0)
            {
                if (casterEntryPoints != null)
                {
                    radius = casterEntryPoints.ModifyValue("EffectRadius", radius, new Dictionary <string, object>()
                    {
                        { "Caster", caster }, { "EffectCollection", effects }
                    });
                }

                RetriggerEffectsForArea(effects, caster, pos, radius, context.mask, context.checkLOSOnRadiusCast, isCast);
                return;
            }

            if (obj == null)
            {
                return;
            }

            GameEffectsHandler targetEffectsHandler = obj.GetObjectScript <GameEffectsHandler>();

            if (targetEffectsHandler != null && targetEffectsHandler.IsAffectedBy(effects))
            {
                return;
            }

            Dictionary <string, object> epRunSubjects = new Dictionary <string, object>()
            {
                { "Caster", caster }, { "AffectedObject", obj }, { "EffectCollection", effects }, { "Effect", null }
            };
            Dictionary <string, object> runSubjects = new Dictionary <string, object>()
            {
                { "Caster", caster }, { "AffectedObject", obj }
            };

            List <GameEffect> effectsToHold = new List <GameEffect>();
            List <float>      magnitudes    = new List <float>();
            List <float>      durations     = new List <float>();

            for (int i = 0; i < context.effects.Length; i++)
            {
                GameEffectItem effectItem = context.effects[i];
                GameEffect     effect     = effectItem.effect;

                if (effect.PlayerOnly() && !obj.isPlayer)
                {
                    continue;
                }

                bool needsToBeAdded = effect.AddToEffectsList();

                if (needsToBeAdded)
                {
                    if (isCast)
                    {
                        if (targetEffectsHandler == null)
                        {
                            Debug.LogWarning("'" + obj.name + "' Doesnt have a GameEffectsHandler, and game effect '" + effect.name + " Needs To Be Kept In An Effect Handler List");
                            continue;
                        }
                    }
                    else
                    {
                        Debug.LogWarning("Game effect '" + effect.name + " Needs To Be Kept In An Effect Handler List, So It Cant Be Used As a Dispell Effect....");
                        continue;
                    }
                }
                if (!effect.EffectValid(caster, obj))
                {
                    continue;
                }

                if (!Conditions.ConditionsMet(effectItem.conditions, runSubjects))
                {
                    continue;
                }
                if (!Conditions.ConditionsMet(effect.conditions, runSubjects))
                {
                    continue;
                }

                float magnitude = effectItem.magnitude;
                float duration  = effectItem.duration;
                if (casterEntryPoints != null)
                {
                    epRunSubjects["Effect"] = effectItem.effect;
                    magnitude = casterEntryPoints.ModifyValue("EffectMagnitude", magnitude, epRunSubjects);
                    if (duration > 0)
                    {
                        duration = casterEntryPoints.ModifyValue("EffectDuration", duration, epRunSubjects);
                    }
                }


                /*
                 *  TODO: figure out garbage created by create copy
                 */
                // if dispell we should already be out by now if needsToBeAdded...
                if (needsToBeAdded && effect.CreateCopy())
                {
                    effect = Object.Instantiate(effect);
                }

                // in case there was a problem with the effect start
                // return out before we add the effect possibly
                if (!effect.OnEffectStart(caster, obj, magnitude, duration))
                {
                    continue;
                }

                if (needsToBeAdded)
                {
                    effectsToHold.Add(effect);
                    magnitudes.Add(magnitude);
                    durations.Add(duration);
                }
            }

            if (effectsToHold.Count > 0)
            {
                targetEffectsHandler.AddEffectsToList(effects, caster, effectsToHold, magnitudes, durations);
            }

            // TODO: choose scheme for msg...
            if (obj.isPlayer)
            {
                if (!string.IsNullOrEmpty(context.message))
                {
                    UIEvents.ShowMessage(0, context.message, false, UIColorScheme.Normal, false);
                }
            }
        }