Exemplo n.º 1
0
        /// <summary>
        /// Wraps the execution of the task
        /// Automatically sets the execution status.
        /// </summary>
        /// <param name="ent">Entity running the task.</param>
        /// <returns></returns>
        public virtual IEnumerator <YieldInstruction> Run(GroundEntity ent)
        {
            Status = EStatus.Running;
            var       process = CreateTaskEnumerator(ent);
            bool      running = false;
            Exception curex   = null;

            do
            {
                //Process move next, break and keep exception if there's one.
                //! #NOTE: We can't have "yield return" inside a "try" block!
                try { running = process.MoveNext(); }
                catch (Exception ex) { curex = ex; break; }
                if (running)
                {
                    yield return(process.Current);
                }
            } while (running && !m_bInteruptTask); //Stop if MoveNext returns false, or the task is interrupted!

            if (curex != null)
            {
                DiagManager.Instance.LogInfo(String.Format("GroundTask.Run(): Task \"{0}\" threw an exception!\n{1}", TaskName(), curex.Message));
                Status = EStatus.Failed;
            }
            else if (m_bInteruptTask)
            {
                Status = EStatus.Interupted;
            }
            else
            {
                Status = EStatus.Completed;
            }
            yield break;
        }
Exemplo n.º 2
0
 protected GroundEntity(GroundEntity other)
 {
     EntEnabled  = other.EntEnabled;
     Collider    = other.Collider;
     EntName     = other.EntName;
     Direction   = other.Direction;
     triggerType = other.triggerType;
 }
Exemplo n.º 3
0
        public override IEnumerator <YieldInstruction> Interact(GroundEntity activator) //PSY: Set this value to get the entity that touched us/activated us
        {
            if (!EntEnabled)
            {
                yield break;
            }

            //Run script events
            if (GetTriggerType() == EEntityTriggerTypes.Action)
            {
                yield return(CoroutineManager.Instance.StartCoroutine(RunEvent(LuaEngine.EEntLuaEventTypes.Action, activator)));
            }
            else if (GetTriggerType() == EEntityTriggerTypes.Touch)
            {
                yield return(CoroutineManager.Instance.StartCoroutine(RunEvent(LuaEngine.EEntLuaEventTypes.Touch, activator)));
            }
        }
Exemplo n.º 4
0
        public override IEnumerator <YieldInstruction> Interact(GroundEntity activator)
        {
            if (!activator.EntEnabled)
            {
                yield break;
            }

            //Cast the entity to its actual type before passing it, so lua can use it properly
            var ent = activator.GetEntityType() == EEntTypes.Character ? (GroundChar)activator :
                      (activator.GetEntityType() == EEntTypes.Object) ? (GroundObject)activator : activator;

            //Run script event
            if (GetTriggerType() == EEntityTriggerTypes.Action)
            {
                IsInteracting = true;
                yield return(CoroutineManager.Instance.StartCoroutine(RunEvent(LuaEngine.EEntLuaEventTypes.Action, ent)));

                IsInteracting = false;
            }
        }
Exemplo n.º 5
0
 //!#NOTE: Ideally, when/if we have more a single interaction per object, we could add extra parameters to this.
 /// <summary>
 /// When something tries to interact with this entity, this method is called.
 /// </summary>
 /// <param name="activator"></param>
 public virtual IEnumerator <YieldInstruction> Interact(GroundEntity activator)
 {
     //default does nothing
     yield break;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Create the enumerator to be run by the Run function.
 /// </summary>
 /// <returns></returns>
 protected abstract IEnumerator <YieldInstruction> CreateTaskEnumerator(GroundEntity ent);
Exemplo n.º 7
0
 protected override IEnumerator <YieldInstruction> CreateTaskEnumerator(GroundEntity ent)
 {
     return(Task.Apply(ent));
 }