void OnSceneLoaded(Scene scene, LoadSceneMode mode)
        {
            string sceneName = scene.name;

            if (GameManager.IsMainMenuScene(sceneName))
            {
                return;
            }


            if (movingPlayer)
            {
                if (GameManager.playerExists)
                {
                    MoveDynamicObjectToTransform(GameManager.player, movePlayerTarget.position, movePlayerTarget.rotation, false);
                }
                movingPlayer = false;
            }

            // tODO: objects that are pre placed already alias refed might be copy if
            // existing state already has loaded object
            // e.g. (maybe a companion traveled with player back to where it was originally placed in editor)

            // get all the active objects that are default in the current scene
            List <DynamicObject> editorPlacedObjects = FilterObjectsForScene(sceneName, DynamicObject.GetInstancesThatNeedID());

            // get reference to all states that were pre defined programatically for this scene...
            // (before we add the states for the manually placed ones)
            List <DynamicObjectState> states = GetStatesForScene(sceneName);

            if (scenesAlreadyLoaded.Contains(sceneName))
            {
                // add them to the pool for availablity
                for (int i = 0; i < editorPlacedObjects.Count; i++)
                {
                    // if it needs a guid it comes with the scene... so this shouldnt matter (maybe...)
                    editorPlacedObjects[i].gameObject.SetActive(false);
                }
            }

            // scene loaded for the first time
            // create object states and id's for default placed objects
            else
            {
                scenesAlreadyLoaded.Add(sceneName);

                // give id's and states for those default objects
                for (int i = 0; i < editorPlacedObjects.Count; i++)
                {
                    string id = null;
                    if (editorPlacedObjects[i].usesAlias)
                    {
                        id = editorPlacedObjects[i].GetID();
                        if (!string.IsNullOrEmpty(id))
                        {
                            DynamicObjectState aliasedState = GetStateByID(id);

                            // if our aliased state is untouched then we use this object
                            if (aliasedState.isUntouched)
                            {
                                // dotn load in this scene again, just in case we were trying to
                                if (states.Contains(aliasedState))
                                {
                                    states.Remove(aliasedState);
                                }

                                editorPlacedObjects[i].AdjustState(aliasedState, sceneName, editorPlacedObjects[i].transform.position, editorPlacedObjects[i].transform.rotation.eulerAngles, false);

                                aliasedState.isUntouched = false;
                            }

                            // we've adjusted the state, disable this object and use the state
                            else
                            {
                                editorPlacedObjects[i].gameObject.SetActive(false);
                            }

                            // if our aliased state scene is this one,
                            continue;
                        }
                    }

                    id = GetNewGUID();
                    id2ObjectState.Add(id, editorPlacedObjects[i].AdjustState(new DynamicObjectState(id, sceneName, editorPlacedObjects[i].prefabRef, false), sceneName, editorPlacedObjects[i].transform.position, editorPlacedObjects[i].transform.rotation.eulerAngles, false));
                    editorPlacedObjects[i].SetID(id);
                }
            }

            for (int i = 0; i < states.Count; i++)
            {
                LoadNewDynamicObjectWithState(states[i], !states[i].isUntouched);
            }
        }
 public static void MoveObject(DynamicObject key, string alias)
 {
     MoveObject(key, LocationAliases.GetLocationKey(alias));
 }
 public static void MoveObject(DynamicObject key, Location location)
 {
     MoveObject(key, location.GetKey());
 }
 protected override bool EffectValid(DynamicObject caster, DynamicObject obj)
 {
     return(obj.GetObjectScript <GameEffectsHandler>() != null);
 }
 protected override bool OnEffectStart(DynamicObject caster, DynamicObject obj, float magnitude, float duration)
 {
     obj.GetObjectScript <GameEffectsHandler>().RemoveEffects(keywords);
     return(true);
 }
Example #6
0
 protected abstract bool EffectValid(DynamicObject caster, DynamicObject obj);
 protected override void OnEffectUpdate(DynamicObject caster, DynamicObject obj, float deltaTime, float timeAdded, float currentTime, float magnitude, float duration, out bool removeEffect)
 {
     removeEffect = false;
 }
Example #8
0
 public static void TriggerEffectsOnObject(GameEffectCollection effects, DynamicObject caster, DynamicObject obj)
 {
     TriggerEffectsOnObject(effects, caster, obj.GetPosition(), obj);
 }
Example #9
0
 public static void TriggerEffectsOnObject(GameEffectCollection effects, DynamicObject caster, Vector3 pos, DynamicObject obj)
 {
     TriggerEffects(effects, caster, pos, obj, true);
 }
Example #10
0
 public static void TriggerEffectsOnSelf(GameEffectCollection effects, DynamicObject caster)
 {
     TriggerEffectsOnSelf(effects, caster, caster.transform.position);
 }
Example #11
0
 public static void TriggerEffectsOnSelf(GameEffectCollection effects, DynamicObject caster, Vector3 pos)
 {
     TriggerEffectsOnObject(effects, caster, pos, caster);
 }
Example #12
0
 public abstract void OnEffectRemove(DynamicObject caster, DynamicObject obj, float magnitude, float duration);
Example #13
0
 protected abstract void OnEffectUpdate(DynamicObject caster, DynamicObject obj, float deltaTime, float timeAdded, float currentTime, float magnitude, float duration, out bool removeEffect);
Example #14
0
 protected abstract bool OnEffectStart(DynamicObject caster, DynamicObject obj, float magnitude, float duration);
 public void UpdateEffect(DynamicObject obj, float deltaTime, float currentTime, out bool removeEffect)
 {
     effect.UpdateEffect(caster, obj, deltaTime, timeAdded, currentTime, magnitude, duration, out removeEffect);
 }
 public override void OnEffectRemove(DynamicObject caster, DynamicObject obj, float magnitude, float duration)
 {
 }
 public void OnEffectRemove(DynamicObject obj)
 {
     effect.OnEffectRemove(caster, obj, magnitude, duration);
 }
Example #18
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);
                }
            }
        }