Exemple #1
0
        protected override ActionResult OnTick(IAIController ai)
        {
            if (this.StateMachine == null)
            {
                return(ActionResult.Failed);
            }

            if (_waitOn != null && _waitOn.Length > 0)
            {
                IAIAction a;
                for (int i = 0; i < _waitOn.Length; i++)
                {
                    a = _waitOn[i] as IAIAction;
                    if (a != null && a.ActionState == ActionResult.Waiting)
                    {
                        return(ActionResult.Waiting);
                    }
                }
            }

            if (_state == null)
            {
                this.StateMachine.ChangeState((IAIState)null);
                return(ActionResult.Success);
            }
            else if (this.StateMachine.Contains(_state))
            {
                this.StateMachine.ChangeState(_state);
                return(ActionResult.Success);
            }
            else
            {
                return(ActionResult.Failed);
            }
        }
Exemple #2
0
        public override void OnAwake()
        {
            BaseMonoAnimatorEntity component = base.GetComponent <BaseMonoAnimatorEntity>();

            if (component is BaseMonoAvatar)
            {
                this._aiEntity          = (BaseMonoAvatar)component;
                this.moveSpeedKey.Value = "AvatarSpeed(FIXED)";
                this._speed             = 0f;
            }
            else if (component is BaseMonoMonster)
            {
                this._aiEntity = (BaseMonoMonster)component;
                this._speed    = (component as BaseMonoMonster).GetOriginMoveSpeed(this.moveSpeedKey.Value);
            }
            this._aiController = this._aiEntity.GetActiveAIController();
            this._monster      = this._aiEntity as BaseMonoMonster;
            if (this.failMoveTime <= 0f)
            {
                this._usefailMoveTime = false;
            }
            else
            {
                this._usefailMoveTime = true;
                this._failMoveTimer   = this.failMoveTime;
            }
        }
Exemple #3
0
 protected override void Tick(IAIController ai)
 {
     if (_stateMachine.Current != null)
     {
         _stateMachine.Current.Tick(ai);
     }
 }
Exemple #4
0
    public void Initialise(int newMaxHealth, IAIController newOwner)
    {
        MaxHealth = newMaxHealth;

        CurrHealth = MaxHealth;

        owner = newOwner;
    }
        protected override ActionResult OnTick(IAIController ai)
        {
            if (_actions == null || _actions.Length == 0)
            {
                return(ActionResult.Success);
            }

            if (_currentActionIndex < 0)
            {
                _currentActionIndex = 0;
            }

            var result = ActionResult.Success;
            var a      = _actions[_currentActionIndex];

            while (a != null)
            {
                if (!a.Enabled)
                {
                    _currentActionIndex++;
                    if (_currentActionIndex < _actions.Length)
                    {
                        a = _actions[_currentActionIndex];
                    }
                    else
                    {
                        a = null;
                        _currentActionIndex = -1;
                    }
                    continue;
                }

                result = a.Tick(ai);
                if (result == ActionResult.Success)
                {
                    _currentActionIndex++;
                    if (_currentActionIndex < _actions.Length)
                    {
                        a = _actions[_currentActionIndex];
                    }
                    else
                    {
                        a = null;
                        _currentActionIndex = -1;
                    }
                }
                else if (result == ActionResult.Failed)
                {
                    _currentActionIndex = -1;
                    break;
                }
                else
                {
                    break;
                }
            }
            return(result);
        }
Exemple #6
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.propertyType != SerializedPropertyType.String)
            {
                SPEditorGUI.DefaultPropertyField(position, property, label);
                return;
            }

            var tr = GameObjectUtil.GetTransformFromSource(property.serializedObject.targetObject);

            if (tr == null)
            {
                SPEditorGUI.DefaultPropertyField(position, property, label);
                return;
            }

            IAIController controller = tr.GetComponentInParent <IAIController>() ?? tr.FindComponent <IAIController>();

            if (controller == null)
            {
                SPEditorGUI.DefaultPropertyField(position, property, label);
                return;
            }

            var names = (controller.Variables == null) ? ArrayUtil.Empty <string>() : controller.Variables.Names.ToArray();

            /*
             * var guiNames = (from n in names select EditorHelper.TempContent(n)).Append(EditorHelper.TempContent("Custom...")).ToArray();
             * int index = names.IndexOf(property.stringValue);
             * if (index < 0) index = names.Length;
             * if(index == names.Length)
             * {
             *  var fw = position.width - EditorGUIUtility.labelWidth;
             *  var wl = EditorGUIUtility.labelWidth + (fw / 4f);
             *  var wr = position.width - wl - 1f;
             *
             *  var rl = new Rect(position.xMin, position.yMin, wl, EditorGUIUtility.singleLineHeight);
             *  var rr = new Rect(rl.xMax + 1f, rl.yMin, wr, EditorGUIUtility.singleLineHeight);
             *
             *  index = EditorGUI.Popup(rl, label, index, guiNames);
             *  if (index >= 0 && index < names.Length)
             *  {
             *      property.stringValue = names[index];
             *  }
             *  else
             *  {
             *      property.stringValue = EditorGUI.TextField(rr, property.stringValue);
             *  }
             * }
             * else
             * {
             *  index = EditorGUI.Popup(position, label, index, guiNames);
             *  property.stringValue = (index >= 0 && index < names.Length) ? names[index] : null;
             * }
             */
            property.stringValue = SPEditorGUI.OptionPopupWithCustom(position, label, property.stringValue, names);
        }
        protected override ActionResult EvaluateTrap(IAIController ai)
        {
            if (_machine == null)
            {
                return(ActionResult.Failed);
            }

            return((System.Array.IndexOf(_component, _machine.Current) >= 0) ? ActionResult.Success : ActionResult.Failed);
        }
Exemple #8
0
        protected override ActionResult OnTick(IAIController ai)
        {
            if (string.IsNullOrEmpty(_variable))
            {
                return(ActionResult.Failed);
            }

            ai.Variables[_variable] = _value.Value;
            return(ActionResult.Success);
        }
Exemple #9
0
 protected override ActionResult OnTick(IAIController ai)
 {
     if (_stateMachine != null && _stateMachine.Current != null)
     {
         return(_stateMachine.Current.Tick(ai));
     }
     else
     {
         return(ActionResult.Success);
     }
 }
        protected override ActionResult OnTick(IAIController ai)
        {
            if (_currentAction == null)
            {
                if (_actions == null)
                {
                    return(ActionResult.Success);
                }
                this.Reset();

                if (_weightSupplier != null)
                {
                    _currentAction = _actions.PickRandom((a) =>
                    {
                        return(_weightSupplier.GetWeight(a));
                    });
                }
                else
                {
                    _currentAction = _actions.PickRandom();
                }
                if (_currentAction == null)
                {
                    return(ActionResult.Success);
                }
            }

            if (!_currentAction.Enabled)
            {
                _currentAction = null;
                return(ActionResult.Failed);
            }

            var result = _currentAction.Tick(ai);

            if (result != ActionResult.Waiting)
            {
                if (_weightSupplier != null)
                {
                    switch (result)
                    {
                    case ActionResult.Failed:
                        _weightSupplier.OnActionFailure(_currentAction);
                        break;

                    case ActionResult.Success:
                        _weightSupplier.OnActionSuccess(_currentAction);
                        break;
                    }
                }
                _currentAction = null;
            }
            return(result);
        }
Exemple #11
0
        protected override ActionResult OnStart(IAIController ai)
        {
            var ts = _timeSupplier.TimeSupplier;

            if (ts == null)
            {
                return(ActionResult.Failed);
            }

            _startTime = ts.Total;
            return(ActionResult.None);
        }
 ActionResult IAINode.Tick(IAIController ai)
 {
     if (_isActive)
     {
         this.Tick(ai);
         return(ActionResult.Waiting);
     }
     else
     {
         return(ActionResult.None);
     }
 }
Exemple #13
0
        protected override ActionResult OnTick(IAIController ai)
        {
            var ts = _timeSupplier.TimeSupplier;

            if (ts == null)
            {
                return(ActionResult.Failed);
            }

            var t = ts.Total - _startTime;

            return((t >= _duration) ? ActionResult.Success : ActionResult.Waiting);
        }
Exemple #14
0
        public override void OnAwake()
        {
            BaseMonoAnimatorEntity component = base.GetComponent <BaseMonoAnimatorEntity>();

            if (component is BaseMonoAvatar)
            {
                this._aiEntity = (BaseMonoAvatar)component;
            }
            else if (component is BaseMonoMonster)
            {
                this._aiEntity = (BaseMonoMonster)component;
            }
            this._aiController = this._aiEntity.GetActiveAIController();
        }
Exemple #15
0
        public ActionResult Tick(IAIController ai)
        {
            if (_internalState == OperationalState.CompleteAndWaitingToReset)
            {
                this.Reset();
                _actionState = this.OnStart(ai);
                if (_actionState > ActionResult.Waiting)
                {
                    return(_actionState);
                }
            }
            else if (_actionState == ActionResult.None)
            {
                _actionState = this.OnStart(ai);
                if (_actionState > ActionResult.Waiting)
                {
                    return(_actionState);
                }
            }

            _internalState = OperationalState.Active;
            _actionState   = this.OnTick(ai);
            if (_internalState == OperationalState.Inactive)
            {
                //Reset was called during tick, probably by a 'ChangeState' call on a parent state machine.
                //exit cleanly
                _actionState = ActionResult.None;
                return(_actionState);
            }

            if (_actionState > ActionResult.Waiting)
            {
                _internalState = OperationalState.CompleteAndWaitingToReset;

                this.OnComplete(ai);
                if (_repeat != RepeatMode.Never && (int)_repeat != (int)_actionState)
                {
                    _actionState = ActionResult.Waiting;
                }

                if (_alwaysSucceed && _actionState == ActionResult.Failed)
                {
                    _actionState = ActionResult.Success;
                }
            }

            return(_actionState);
        }
Exemple #16
0
        public override void OnAwake()
        {
            BaseMonoAnimatorEntity component = base.GetComponent <BaseMonoAnimatorEntity>();

            if (component is BaseMonoAvatar)
            {
                this._aiEntity = (BaseMonoAvatar)component;
            }
            else if (component is BaseMonoMonster)
            {
                this._aiEntity = (BaseMonoMonster)component;
            }
            this._aiController  = this._aiEntity.GetActiveAIController();
            this._abilityEntity = component;
            this._levelAIPlugin = Singleton <LevelManager> .Instance.levelActor.GetPlugin <LevelAIPlugin>();
        }
        public ActionResult Tick(IAIController ai)
        {
            if (_blocking != null)
            {
                if (_blocking.IsComplete)
                {
                    _blocking = null;
                    _state    = ActionResult.Success;
                }
                else
                {
                    _state = ActionResult.Waiting;
                }
            }
            else if (_mechanism != null)
            {
                _state = ActionResult.Success;
                if (_mechanism.CanTrigger)
                {
                    if (_mechanism is IBlockingTriggerableMechanism)
                    {
                        var obj = BlockingTriggerYieldInstruction.Create();
                        (_mechanism as IBlockingTriggerableMechanism).Trigger(ai, ai, obj);
                        if (obj.Count > 0)
                        {
                            _state    = ActionResult.Waiting;
                            _blocking = obj;
                        }
                        else
                        {
                            (obj as System.IDisposable).Dispose();
                        }
                    }
                    else
                    {
                        _mechanism.Trigger(ai, ai);
                    }
                }
            }
            else
            {
                _state = ActionResult.Failed;
            }

            return(_state);
        }
Exemple #18
0
        protected override ActionResult OnTick(IAIController ai)
        {
            if (_sensor.IsNullOrDestroyed())
            {
                return(ActionResult.Failed);
            }

            if (string.IsNullOrEmpty(_variable))
            {
                return(ActionResult.Failed);
            }

            var aspect = ai.Variables[_variable] as IAspect;

            if (aspect.IsNullOrDestroyed())
            {
                return(ActionResult.Success);
            }

            if (_sensor.Visible(aspect))
            {
                return(ActionResult.Waiting);
            }
            else
            {
                switch (_variableUpdateParams)
                {
                case VariableUpdateOptions.SetNullOnExit:
                    ai.Variables[_variable] = null;
                    break;

                case VariableUpdateOptions.SetLastPositionOnExit:
                    ai.Variables[_variable] = (aspect.IsAlive()) ? (object)aspect.transform.position : null;
                    break;
                }

                return(ActionResult.Success);
            }
        }
        ActionResult IAINode.Tick(IAIController ai)
        {
            switch (_trapState)
            {
            case ActionResult.None:
            case ActionResult.Waiting:
            {
                _trapState = this.EvaluateTrap(ai);
                switch (_trapState)
                {
                case ActionResult.None:
                case ActionResult.Waiting:
                    return(_trapState);

                case ActionResult.Success:
                    if (_onSucceed.ActionCount > 0)
                    {
                        return(_onSucceed.Tick(ai));
                    }
                    else
                    {
                        return(_trapState);
                    }

                case ActionResult.Failed:
                default:
                    return(ActionResult.Failed);
                }
            }

            case ActionResult.Success:
                return(_onSucceed.Tick(ai));

            case ActionResult.Failed:
            default:
                return(ActionResult.Failed);
            }
        }
Exemple #20
0
        public ActionResult Tick(IAIController ai)
        {
            if (_resetOnRepeat)
            {
                this.Reset();
            }
            _actionState = this.OnTick(ai);
            if (_actionState > ActionResult.Waiting)
            {
                _resetOnRepeat = true;

                if (_repeat != RepeatMode.Never && (int)_repeat != (int)_actionState)
                {
                    _actionState = ActionResult.Waiting;
                }

                if (_alwaysSucceed && _actionState == ActionResult.Failed)
                {
                    _actionState = ActionResult.Success;
                }
            }
            return(_actionState);
        }
Exemple #21
0
 protected override ActionResult OnTick(IAIController ai)
 {
     _trigger.ActivateTrigger(this, null);
     return(ActionResult.Success);
 }
 protected override ActionResult OnStart(IAIController ai)
 {
     return(RandomUtil.Standard.Bool(_oddsOfSuccess) ? ActionResult.Success : ActionResult.Failed);
 }
 ActionResult IAINode.Tick(IAIController ai)
 {
     return(ActionResult.Failed);
 }
        protected override ActionResult OnTick(IAIController ai)
        {
            if (_actions == null || _actions.Length == 0)
            {
                return(ActionResult.Success);
            }

            int cntFail = 0;
            int cntSucc = 0;
            int cntWait = 0;

            _inTick = true;
            for (int i = 0; i < _actions.Length; i++)
            {
                if (!_actions[i].Enabled)
                {
                    continue;
                }

                switch (_actions[i].Tick(ai))
                {
                case ActionResult.Success:
                    cntSucc++;
                    break;

                case ActionResult.Failed:
                    cntFail++;
                    break;

                case ActionResult.Waiting:
                    cntWait++;
                    break;
                }

                if (!_inTick)
                {
                    //an action cancelled us
                    return(ActionResult.Failed);
                }
            }
            _inTick = false;

            const ParallelPassOptions mask = ParallelPassOptions.SucceedOnAny | ParallelPassOptions.FailOnAny;

            if ((_passOption & mask) > 0)
            {
                if (_passOption.HasFlag(ParallelPassOptions.SucceedOnTie))
                {
                    if (_passOption.HasFlag(ParallelPassOptions.FailOnAny) && cntFail > 0)
                    {
                        return(ActionResult.Failed);
                    }
                    if (_passOption.HasFlag(ParallelPassOptions.SucceedOnAny) && cntSucc > 0)
                    {
                        return(ActionResult.Success);
                    }
                }
                else
                {
                    if (_passOption.HasFlag(ParallelPassOptions.SucceedOnAny) && cntSucc > 0)
                    {
                        return(ActionResult.Success);
                    }
                    if (_passOption.HasFlag(ParallelPassOptions.FailOnAny) && cntFail > 0)
                    {
                        return(ActionResult.Failed);
                    }
                }
            }

            if (cntWait > 0)
            {
                return(ActionResult.Waiting);
            }
            else if (cntFail == _actions.Length)
            {
                return(ActionResult.Failed);
            }
            else
            {
                return(ActionResult.Success);
            }
        }
 /// <summary>
 /// Returns true if the trap should evaluate its group, false if should fail.
 /// </summary>
 /// <returns></returns>
 protected abstract ActionResult EvaluateTrap(IAIController ai);
Exemple #26
0
 /// <summary>
 /// Return false if should cancel immediately
 /// </summary>
 /// <param name="ai"></param>
 /// <returns></returns>
 protected virtual ActionResult OnStart(IAIController ai)
 {
     return(ActionResult.None);
 }
 ActionResult IAINode.Tick(IAIController ai)
 {
     return(_stateMachine.Tick(ai));
 }
Exemple #28
0
 protected virtual ActionResult OnTick(IAIController ai)
 {
     return(ActionResult.Success);
 }
Exemple #29
0
 public override void OnAwake()
 {
     this._monster       = base.GetComponent <BaseMonoMonster>();
     this._controller    = this._monster.GetActiveAIController();
     this._levelAIPlugin = Singleton <LevelManager> .Instance.levelActor.GetPlugin <LevelAIPlugin>();
 }
Exemple #30
0
 protected virtual void OnComplete(IAIController ai)
 {
 }