Ejemplo n.º 1
0
        public override void Update(Dwarf d, float dt)
        {
            if (_currentTask == null)
            {
                if (_currentTask == null)
                    return;
                _currentBehavior = _currentTask.ActivateBehavior(d);
            }

            _currentBehavior.Execute(d, dt);
            if (_currentBehavior.State == TaskState.Success)
            {
                Stop();
                Update(d, dt);
            }
            else if (_currentBehavior.State == TaskState.Fail)
            {
                Stop();
                Update(d, dt);
            }
            else if (_currentBehavior.State == TaskState.SmallFail)
            {
                Stop();
                Update(d, dt);
            }
            else if (_currentBehavior.State == TaskState.Absolete)
            {
                Stop();
                Update(d, dt);
            }

            base.Update(d, dt);
        }
Ejemplo n.º 2
0
 public void MoveToPasture(PastureSim pasture)
 {
     _pasture = pasture;
     _currentTask = new MoveToPositionTask(pasture.GetRandomFreeSpace());
     _currentBehavior = null;
     _inPasture = true;
 }
Ejemplo n.º 3
0
        public override void Update(Dwarf d, float dt)
        {
            if (_currentBehavior == null)
            {
                _currentBehavior = _currentTask.ActivateBehavior(d);
            }
            _currentBehavior.Execute(d, dt);

            if (_leaving && d.Position == new Vector3(1, 1, 5))
                d.Destroyy();

            base.Update(d, dt);
        }
Ejemplo n.º 4
0
        public override void Update(Dwarf d, float dt)
        {
            if (_currentBehavior == null && _currentTask != null)
                _currentBehavior = _currentTask.ActivateBehavior(d);

            // If not in pasture, move around randomly
            if (_inPasture == false)
            {
                if (_waitTime == 0)
                    _waitTime = (float)DwarfRandom.GetRandomInt(4000, 15000);

                _timeWaited += dt;

                if (_timeWaited >= _waitTime)
                {
                    MoveRandom(d);
                    _timeWaited = 0;
                }
            }
            // If in pasture, move around randomly inside pasture
            if (_inPasture == true && _currentTask == null)
            {
                if (_waitTime == 0)
                    _waitTime = (float)DwarfRandom.GetRandomInt(4000, 15000);

                _timeWaited += dt;

                if (_timeWaited >= _waitTime)
                {
                    MoveRandomInPasture(d);
                    _timeWaited = 0;
                }
            }

            if (_currentBehavior != null)
            {
                if (_currentBehavior.Execute(d, dt) == TaskState.Success)
                {
                    _currentTask = null;
                    _currentBehavior = null;
                }
            }

            base.Update(d, dt);
        }
Ejemplo n.º 5
0
 public void AddSelector(Selector selector)
 {
     Nodes.Add(selector);
 }
Ejemplo n.º 6
0
 public void Leave()
 {
     _currentTask = new MoveToPositionTask(new Microsoft.Xna.Framework.Vector2(1, 1));
     _currentBehavior = null;
     _leaving = true;
 }
Ejemplo n.º 7
0
 private void Stop()
 {
     _currentTask = null;
     _currentBehavior = null;
 }
Ejemplo n.º 8
0
        public override void Update(Dwarf d, float dt)
        {
            if (_currentTask == null)
            {
                _prevTask = _currentTask;
                _currentTask = TaskManager.GetTask(d);
                if (_currentTask == null)
                    return;
                _currentBehavior = _currentTask.ActivateBehavior(d);
            }

            _currentBehavior.Execute(d, dt);
            if (_currentBehavior.State == TaskState.Success)
            {
                DwarfConsole.WriteLine("Task: " + _currentTask.ToString() + " is success " + _currentTask.Id, ConsoleColor.Gray);
                //TaskManager.PrintOutTasks();
                TaskManager.FinishTask(_currentTask);
                Stop();
                Update(d, dt);
                d.PersonalSkiped();
            }
            else if (_currentBehavior.State == TaskState.Fail)
            {
                //DwarfConsole.WriteLine("Task failed: " + _currentTask.TaskType, ConsoleColor.Red);

                TaskManager.TaskFailed(_currentTask);
                Stop();
                Update(d, dt);
            }
            else if (_currentBehavior.State == TaskState.SmallFail)
            {
                DwarfConsole.WriteLine("Task small failed: " + _currentTask.TaskType + " - ", ConsoleColor.Magenta);
                TaskManager.TaskSmallFail(_currentTask);
                Stop();
                Update(d, dt);
            }
            else if (_currentBehavior.State == TaskState.Absolete)
            {
                TaskManager.TaskAbsolete(_currentTask);
                Stop();
                Update(d, dt);
            }
            else if (_currentBehavior.State == TaskState.PersonalSuccess)
            {
                DwarfConsole.WriteLine("Task: " + _currentTask.ToString() + " is success", ConsoleColor.DarkCyan);
                Stop();
                Update(d, dt);
            }
            else if (_currentBehavior.State == TaskState.PersonalFail)
            {
                d.SkipPersonal();
                Stop();
            }
            else if (_currentBehavior.State == TaskState.PersonalFailTryTaskAgain)
            {
                // Restart task
                _currentBehavior = _currentTask.ActivateBehavior(d);
            }
            else if (_currentBehavior.State == TaskState.PersonalFailTryBehaviorAgain)
            {

            }
        }
Ejemplo n.º 9
0
 public void Attack(Minion d)
 {
     Building b = WorldMap.Instance.GetBuildings(Buildings.BuildingType.Depot)[0];
     _currentTask = new MoveToFortressTask(b);
     _currentBehavior = _currentTask.ActivateBehavior(d);
 }
Ejemplo n.º 10
0
        private void MoveRandom(Dwarf d)
        {
            Vector2 moveTo = Vector2.Zero;

            int ran = DwarfRandom.GetRandomInt(1, 4);

            if (ran == 1 && WorldMap.Instance.GetMapElement((int)d.Position.X + 1, (int)d.Position.Y, 5) == null)
            {
                moveTo = new Vector2(d.Position.X + 1, d.Position.Y);
            }
            if (ran == 2 && WorldMap.Instance.GetMapElement((int)d.Position.X - 1, (int)d.Position.Y, 5) == null)
            {
                moveTo = new Vector2(d.Position.X - 1, d.Position.Y);
            }
            if (ran == 3 && WorldMap.Instance.GetMapElement((int)d.Position.X, (int)d.Position.Y + 1, 5) == null)
            {
                moveTo = new Vector2(d.Position.X, d.Position.Y+1);
            }
            if (ran == 4 && WorldMap.Instance.GetMapElement((int)d.Position.X, (int)d.Position.Y - 1, 5) == null)
            {
                moveTo = new Vector2(d.Position.X, d.Position.Y-1);
            }

            if (moveTo == Vector2.Zero)
                return;
            else
            {
                _currentTask = new MoveToPositionTask(moveTo);
                _currentBehavior = _currentTask.ActivateBehavior(d);
            }
        }
Ejemplo n.º 11
0
 private void MoveRandomInPasture(Dwarf d)
 {
     _currentTask = new MoveToPositionTask(_pasture.GetRandomFreeSpace());
     _currentBehavior = _currentTask.ActivateBehavior(d);
 }