Exemplo n.º 1
0
        public void AddSubtask(Task subTask)
        {
            if (this.GetTask(subTask.Id) != null)
            {
                var message = string.Format("Subtask {0} already exists in Task {1}.", subTask.Id, this.Id);
                throw new EntityAlreadyExistsException(message);
            }

            this.Subtasks.Add(subTask);
        }
Exemplo n.º 2
0
        public void DoTask( Task task, bool toQueue )
        {
            if( toQueue && currentTask.Type == Task.Types.Stop && tasks.Count == 0 )
                toQueue = false;

            if( !toQueue )
            {
                ClearTaskList();
                DoTaskInternal( task );
            }
            else
            {
                if( task.Entity != null )
                    SubscribeToDeletionEvent( task.Entity );
                tasks.Add( task );
            }
        }
        public void DoTask(Task task, bool toQueue)
        {
            if (ControlledObject == null)
                return;

            if (toQueue && tasks.Count == 0 && currentTask is IdleTask)
                toQueue = false;

            if (!toQueue)
            {
                ClearTaskQueue();
                DoTaskInternal(task);
            }
            else
            {
                //add task to queue
                if (task.TaskEntity != null)
                    SubscribeToDeletionEvent(task.TaskEntity);
                tasks.Enqueue(task);
            }
        }
        private void DoTaskInternal(Task task)
        {
            if (currentTask.TaskEntity != null)
                UnsubscribeToDeletionEvent(currentTask.TaskEntity);

            currentTask = task;

            if (currentTask.TaskEntity != null)
                SubscribeToDeletionEvent(currentTask.TaskEntity);
            currentTask._Begin();
        }
        protected override bool OnLoad(TextBlock block)
        {
            if (!base.OnLoad(block))
                return false;

            //currentTask
            {
                TextBlock taskBlock = block.FindChild("currentTask");
                if (taskBlock != null)
                {
                    Task task = CreateTaskByClassName(taskBlock.GetAttribute("class"));
                    if (task._Load(taskBlock))
                        currentTask = task;
                }
            }

            //tasks
            TextBlock tasksBlock = block.FindChild("tasks");
            if (tasksBlock != null)
            {
                foreach (TextBlock taskBlock in tasksBlock.Children)
                {
                    if (taskBlock.Name == "item")
                    {
                        Task task = CreateTaskByClassName(taskBlock.GetAttribute("class"));
                        if (task._Load(taskBlock))
                            tasks.Enqueue(task);
                    }
                }
            }

            return true;
        }
        private string GetTaskClassName(Task task)
        {
            if (task is IdleTask)
                return "IdleTask";
            if (task is MoveTask)
                return "MoveTask";
            if (task is AttackTask)
                return "AttackTask";

            Log.Fatal("GameCharacterAI: GetTaskClassName: Unknown task class.");
            return "";
        }
 public GameCharacterAI()
 {
     currentTask = new IdleTask(this);
     tasksReadOnly = new ReadOnlyQueue<Task>(tasks);
 }
Exemplo n.º 8
0
 public UserControlPanelTask( Task task, bool active, bool enable )
 {
     this.task = task;
     this.active = active;
     this.enable = enable;
 }
Exemplo n.º 9
0
 public UserControlPanelTask( Task task )
 {
     this.task = task;
     this.active = true;
     this.enable = true;
 }
Exemplo n.º 10
0
        protected virtual void DoTaskInternal( Task task )
        {
            if( currentTask.Entity != null )
                UnsubscribeToDeletionEvent( currentTask.Entity );

            currentTask = task;

            if( currentTask.Entity != null )
                SubscribeToDeletionEvent( currentTask.Entity );

            //Stop
            if( task.Type == Task.Types.Stop )
            {
                if( ControlledObject != null )
                    ControlledObject.Stop();
            }

            //SelfDestroy
            if( task.Type == Task.Types.SelfDestroy )
            {
                ControlledObject.Die();
            }
        }