Example #1
0
 //===========================================
 //  Methods
 //===========================================
 /// <summary>
 /// Helper function to make an entity run the specified task.
 /// Will not replace a running task!
 /// Tasks are run interlocked with the script processing and game processing, and characters can run tasks at the same time.
 /// </summary>
 /// <param name="ent">Entity which will run the task.</param>
 /// <param name="fn">Task coroutine.</param>
 /// <returns>Returns whether the task could be set or not</returns>
 public GroundScriptedTask StartEntityTask(GroundEntity ent, LuaFunction fn)
 {
     try
     {
         if (ent == null || fn == null)
         {
             DiagManager.Instance.LogInfo(String.Format("ScriptTask.StartEntityTask(): Got null entity or function pointer!"));
             return(null);
         }
         if (ent.GetType().IsSubclassOf(typeof(BaseTaskUser)))
         {
             BaseTaskUser       tu   = (BaseTaskUser)ent;
             GroundScriptedTask task = new GroundScriptedTask(fn);
             if (tu.SetTask(task))
             {
                 return(task);
             }
         }
     }
     catch (Exception ex)
     {
         DiagManager.Instance.LogInfo(String.Format("ScriptTask.StartEntityTask(): Got exception :\n{0}", ex.Message));
     }
     return(null);
 }
Example #2
0
 /// <summary>
 /// Helper function to force stop an entity's current task!
 /// </summary>
 /// <param name="ent">Entity running the task to stop.</param>
 public void StopEntityTask(GroundEntity ent)
 {
     try
     {
         if (ent.GetType().IsSubclassOf(typeof(BaseTaskUser)))
         {
             BaseTaskUser tu   = (BaseTaskUser)ent;
             GroundTask   task = tu.CurrentTask();
             if (task != null)
             {
                 task.ForceStop();
             }
         }
     }
     catch (Exception ex)
     {
         DiagManager.Instance.LogInfo(String.Format("ScriptTask.StopEntityTask(): Got exception :\n{0}", ex.Message));
     }
 }
Example #3
0
 /// <summary>
 /// Helper function to invoke the Wait() function of the current task of the specified entity.
 /// </summary>
 /// <param name="ent">Entity which task we'll wait on.</param>
 /// <returns></returns>
 public Coroutine _WaitEntityTask(GroundEntity ent)
 {
     try
     {
         if (ent.GetType().IsSubclassOf(typeof(BaseTaskUser)))
         {
             BaseTaskUser tu = (BaseTaskUser)ent;
             if (tu.CurrentTask() != null)
             {
                 return(tu.CurrentTask().Wait());
             }
         }
     }
     catch (Exception ex)
     {
         DiagManager.Instance.LogInfo(String.Format("ScriptTask._WaitEntityTask(): Got exception :\n{0}", ex.Message));
     }
     return(new Coroutine(LuaEngine._DummyWait()));
 }
Example #4
0
 /// <summary>
 /// Same as StartEntityTask, but this one blocks until the task is set
 /// </summary>
 /// <param name="ent"></param>
 /// <param name="fn"></param>
 public Coroutine _WaitStartEntityTask(GroundEntity ent, LuaFunction fn)
 {
     try
     {
         if (ent == null || fn == null)
         {
             DiagManager.Instance.LogInfo(String.Format("ScriptTask._WaitStartEntityTask(): Got null entity or function pointer!"));
         }
         if (ent.GetType().IsSubclassOf(typeof(BaseTaskUser)))
         {
             BaseTaskUser tu = (BaseTaskUser)ent;
             return(new Coroutine(tu.WaitSetTask(new GroundScriptedTask(fn))));
         }
     }
     catch (Exception ex)
     {
         DiagManager.Instance.LogInfo(String.Format("ScriptTask._WaitStartEntityTask(): Got exception :\n{0}", ex.Message));
     }
     return(new Coroutine(LuaEngine._DummyWait()));
 }