示例#1
0
        public bool Proceed()
        {
            if (entrance == null || exit == null)
            {
                throw new MissingComponentException();
            }
            if (!isActivated)
            {
                return(false);
            }

            bool resultFromExit = false;

            if (state == TaskProgressState.Idle)
            {
                if (entrance.CheckPassive())
                {
                    state            = TaskProgressState.Started;
                    startingTime     = new TimeState(TimeState.GetGlobalTimer());
                    cantSkipInterval = GlobalConstraint.TASK_CANT_SKIP_INTERVAL;
                    entrance.Deactivate();
                    exit.ActivateAndStartMonitoring();
                }
            }
            else if (state == TaskProgressState.Started)
            {
                for (int i = 0; i < instructions.Count; i++)
                {
                    instructions[i].Proceed();
                    if (!instructions[i].isAudioInstructionEnded())
                    {
                        cantSkipInterval--;
                    }
                }
                resultFromExit = exit.CheckPassive();
                if (resultFromExit && cantSkipInterval < 0)
                {
                    TaskEndState evaluateResult = Evaluate();
                    if (evaluateResult == TaskEndState.Correct)
                    {
                        state = TaskProgressState.Ended;
                        for (int i = 0; i < instructions.Count; i++)
                        {
                            instructions[i].WrapUp();
                        }
                        MoveNext(evaluateResult);
                    }
                }
            }
            return(resultFromExit);
        }
示例#2
0
        private bool HandleVariableDistanceState(Condition cond, State state, TimeState timeState)
        {
            VariableDistanceState var1 = cond.endConditionState as VariableDistanceState;

            if ((state as VariableState) != null)
            {
                VariableState var2 = state as VariableState;
                if (VariableState.IsSameVariable(var1.stateVar1, var2))
                {
                    return(Check(new VariableDistanceState(var1, var2), cond.comparison, cond.endConditionState, timeState));
                }
            }
            return(false);
        }
示例#3
0
        private bool HandleDistanceState(Condition cond, State state, TimeState timeState)
        {
            DistanceState var1 = cond.endConditionState as DistanceState;
            MoveState     var2 = state as MoveState;

            if ((state as MoveState) != null)
            {
                if (var1.hasMoveStateFromSameTerminus(var2))
                {
                    return(Check(var1.GetUpdated(var2), cond.comparison, cond.endConditionState, timeState));
                }
            }
            return(false);
        }
示例#4
0
 public bool Check(State state, TimeState timeState = null)
 {
     if (!hasMultipleConditions)
     {
         //Debug.Log(endConditionState);
         //Debug.Log(state);
         if (endConditionState.GetType() == typeof(TimeState))
         {
             return(HandleTimeState(this));
         }
         else if (endConditionState.GetType() == typeof(TaskState))
         {
             return(HandleTaskState(this));
         }
         else if (endConditionState.GetType() == typeof(VariableDistanceState) && state.GetType().IsSubclassOf(typeof(VariableState)))
         {
             return(HandleVariableDistanceState(this, state, timeState));
         }
         else if (endConditionState.GetType() == typeof(DistanceState))
         {
             return(HandleDistanceState(this, state, timeState));
         }
         else
         {
             return(Check(state, endConditionState, comparison, timeState));
         }
     }
     else
     {
         isSatisfied = false;
         //Debug.Log("Condition1 : " + condition1.Check(state, timeState));
         //Debug.Log("Condition2 : " + condition2.Check(state, timeState));
         if (interRelationship == LogicalOperator.And)
         {
             isSatisfied = condition1.Check(state, timeState) && condition2.Check(state, timeState);
         }
         else if (interRelationship == LogicalOperator.Or)
         {
             isSatisfied = condition1.Check(state, timeState) && condition2.Check(state, timeState);
         }
         else
         {
             throw new Exception("No logical operator set.");
         }
         return(isSatisfied);
     }
 }
 public override bool CheckActive(State state, TimeState timeState = null)
 {
     isSatisfied = false;
     if (relationship == LogicalOperator.And)
     {
         isSatisfied = condition1.CheckActive(state, timeState) && condition2.CheckActive(state, timeState);
     }
     else if (relationship == LogicalOperator.Or)
     {
         isSatisfied = condition1.CheckActive(state, timeState) || condition2.CheckActive(state, timeState);
     }
     else
     {
         throw new Exception("No logical operator set.");
     }
     return(isSatisfied);
 }
示例#6
0
        public override bool Check(State state, TimeState timeState = null)
        {
            if (endConditionState == null)
            {
                throw new MissingComponentException();
            }

            if (endConditionState.GetType() == typeof(TimeState))
            {
                return(Check(TimeState.GlobalTimer, comparison, endConditionState));
            }
            else if (endConditionState.GetType() == typeof(TaskState))
            {
                TaskState taskState = endConditionState as TaskState;
                //Debug.Log("HandleTaskState : " + Check(new TaskState(taskState.task), cond.endConditionState, cond.comparison));
                return(Check(new TaskState(taskState.task), comparison, endConditionState));
            }
            else if (endConditionState.GetType() == typeof(VariableDistanceState) && state.GetType().IsSubclassOf(typeof(VariableState)))
            {
                VariableDistanceState var1 = endConditionState as VariableDistanceState;
                if ((state as VariableState) != null)
                {
                    VariableState var2 = state as VariableState;
                    return(VariableState.IsSameVariable(var1.stateVar1, var2) ? Check(new VariableDistanceState(var1, var2), comparison, endConditionState, timeState) : false);
                }
                return(false);
            }
            else if (endConditionState.GetType() == typeof(DistanceState))
            {
                DistanceState var1 = endConditionState as DistanceState;
                MoveState     var2 = state as MoveState;
                if ((state as MoveState) != null)
                {
                    return(var1.hasMoveStateFromSameTerminus(var2) ? Check(var1.GetUpdated(var2), comparison, endConditionState, timeState) : false);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(Check(state, comparison, endConditionState, timeState));
            }
        }
示例#7
0
        public bool Proceed(List <Interface> interfaces)
        {
            if (entrance == null || exit == null)
            {
                throw new MissingComponentException();
            }

            if (!isActivated)
            {
                return(false);
            }
            if (state == TaskProgressState.Idle)
            {
                if (entrance.Check())
                {
                    state            = TaskProgressState.Started;
                    startingTime     = new TimeState(TimeState.GetGlobalTimer());
                    cantSkipInterval = GlobalConstraint.TASK_CANT_SKIP_INTERVAL;
                    entrance.Deactivate();
                    exit.ActivateAndStartMonitoring();
                }
            }
            else if (state == TaskProgressState.Started)
            {
                if (interfaces.Count > 0)
                {
                    instruction.Proceed(interfaces);
                    if (!instruction.isAudioInstructionEnded())
                    {
                        cantSkipInterval--;
                    }
                }
                if (exit.Check())// && cantSkipInterval < 0)
                {
                    state = TaskProgressState.Ended;
                    MoveNext(Evaluate());
                }
            }
            return(exit.isSatisfied);
        }
示例#8
0
 public override bool CheckActive(State state, TimeState timeState = null)
 {
     if (endConditionState.GetType() == typeof(TimeState))
     {
         return(HandleTimeState(this));
     }
     else if (endConditionState.GetType() == typeof(TaskState))
     {
         return(HandleTaskState(this));
     }
     else if (endConditionState.GetType() == typeof(VariableDistanceState) && state.GetType().IsSubclassOf(typeof(VariableState)))
     {
         return(HandleVariableDistanceState(this, state, timeState));
     }
     else if (endConditionState.GetType() == typeof(DistanceState))
     {
         return(HandleDistanceState(this, state, timeState));
     }
     else
     {
         return(Check(state, comparison, endConditionState, timeState));
     }
 }
示例#9
0
 private void StateChangeHandler(State newState)
 {
     Debug.Log(TimeState.GetGlobalTimer() + "\tTask: " + name + "\tTaskProgressState: " + newState.ToString());
     ConditionPublisher.Instance.Send(new TaskState(this, newState as TaskProgressState));
 }
示例#10
0
 protected abstract bool Check(State state1, Operator ope, State state2, TimeState timeState = null);
示例#11
0
 public abstract bool Check(State state, TimeState timeState = null);
示例#12
0
 public Condition(State _endCondition, RelationalOperator _comparison, TimeState _elapsedState) : this(_endCondition, _comparison)
 {
     holdingTimer = _elapsedState;
 }
示例#13
0
        protected override bool Check(State state1, Operator ope, State state2, TimeState timeState = null)
        {
            if (isSatisfied)
            {
                return(true);
            }
            bool result = false;

            // unwrapping autovariable state: we convert it to the specific varible state inside of the AutoVariableState.
            if (state1.GetType() == typeof(AutoVariableState))
            {
                state1 = (state1 as AutoVariableState).GetVariableState();
            }
            if (state2.GetType() == typeof(AutoVariableState))
            {
                state2 = (state2 as AutoVariableState).GetVariableState();
            }

            if (state1.GetType() == state2.GetType())
            {
                //Debug.Log("Check: " + state1.ToString() + "\t" + state2.ToString());
                //Debug.Log(state1.CompareTo(state2));
                if (ope == RelationalOperator.Larger)
                {
                    result = state1.CompareTo(state2) > 0;
                }
                else if (ope == RelationalOperator.LargerOrEqual)
                {
                    result = state1.CompareTo(state2) > 0 || state1.Equals(state2);
                }
                else if (ope == RelationalOperator.Equal)
                {
                    result = state1.Equals(state2);
                }
                else if (ope == RelationalOperator.SmallerOrEqual)
                {
                    result = state1.CompareTo(state2) < 0 || state1.Equals(state2);
                }
                else if (ope == RelationalOperator.Smaller)
                {
                    result = state1.CompareTo(state2) < 0;
                }
                else if (ope == RelationalOperator.NotEqual)
                {
                    result = state1 != state2;
                }
            }
            if (holdingTimer != null)
            {
                if (result)
                {
                    if (holdingCount < 30)
                    {
                        holdingCount += 1;
                    }
                    if (!holdingTimer.IsTimerOn())
                    {
                        holdingTimer.StartTimer();
                    }
                }
                else
                {
                    if (holdingCount > 0)
                    {
                        holdingCount -= 1;
                    }
                    else
                    {
                        holdingTimer.StopTimer();
                    }
                }
                if (holdingTimer.IsOver())
                {
                    isSatisfied = true;
                }
            }
            else
            {
                isSatisfied = result;
            }
            return(isSatisfied);
        }
 protected override bool Check(State state1, Operator ope, State state2, TimeState timeState = null)
 {
     throw new NotImplementedException();
 }
示例#15
0
 // Update is called once per frame
 void Update()
 {
     TimeState.UpdateGlobalTimer();
 }
示例#16
0
 public int CompareTo(TimeState other)
 {
     //UnityEngine.Debug.Log(value.GetValue().ToString());
     //UnityEngine.Debug.Log(other.value.GetValue().ToString());
     return(value.CompareTo(other.value));
 }