Esempio n. 1
0
        private Action TaskToAction(Task task, Character character)
        {
            Action action = null;
            if (task.Type == Task.TaskType.Move)
            {
                var isNormalMoving = MovingOffset.Instance.AllNormalDistanceCells.Contains(task.Cell);
                var fistMove = character.CurrentActionPoints >= character.MaxActionPoints;
                int price = 0;

                if (fistMove)
                {
                    price = isNormalMoving ? 5 : 10;
                    if (isNormalMoving)
                        action = new NormalMoveAction(character, new ActionPrice() {points = price}, task.Cell);
                    else
                        action = new SprintMoveAction(character, new ActionPrice() {points = price}, task.Cell);
                }
                else
                {
                    price = character.CurrentActionPoints;
                    action = new NormalMoveAction(character, new ActionPrice() { points = price }, task.Cell);
                }
            }
            return action;
        }
Esempio n. 2
0
        /// <summary>
        /// Setting a new action for current Character to do
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public IEnumerator SetTask(Task task)
        {
            var character = CurrentControlled;
            if (character == null)
                throw new InvalidOperationException("CurrentControlled is null");

            var action = TaskToAction(task, character);
            if (action == null)
                throw new InvalidOperationException("action is null");

            //waiting for the end current action of character
            while (character.IsBusy)
                yield return null;

            character.DoAction(action);
            character.ActionFinished += CurrentCharacterOnActionFinished;

            //waiting for the end if new action
            while (character.IsBusy)
                yield return null;
        }