public void OnDeactivate(IMovementStyle nextStyle, bool stateIsStacking)
 {
     if (!stateIsStacking)
     {
         Object.Destroy(this);
     }
 }
        public void PurgeStackedState(IMovementStyle style)
        {
            if (object.ReferenceEquals(style, null))
            {
                throw new System.ArgumentNullException("style");
            }

            if (_styleStack.Count > 0)
            {
                if (object.ReferenceEquals(_current, style))
                {
                    this.PopState();
                }
                else
                {
                    int index = _styleStack.IndexOf(style);
                    if (index > 0)
                    {
                        _styleStack.RemoveAt(index);
                        style.OnPurgedFromStack();
                    }
                }
            }
            else if (object.ReferenceEquals(_current, style))
            {
                this.ChangeStateToNull(float.NegativeInfinity);
            }
        }
示例#3
0
 public void OnDeactivate(IMovementStyle nextStyle, ActivationReason reason)
 {
     if (reason == ActivationReason.Standard)
     {
         Object.Destroy(this);
     }
 }
        private void SwapStateOut(IMovementStyle style)
        {
            if (object.Equals(style, _current))
            {
                return;
            }

            var oldState = _current;

            _current = style;

            if (oldState != null)
            {
                oldState.OnDeactivate(style, _stackingState ? ActivationReason.Stacking : ActivationReason.Standard);
            }
            if (style != null)
            {
                style.OnActivate(oldState, _stackingState ? ActivationReason.Stacking : ActivationReason.Standard);
            }

            //if (this.StateChanged != null) this.StateChanged(this, new StateChangedEventArgs<IMovementStyle>(oldState, style));
            if (this.StyleChanged != null)
            {
                this.StyleChanged(this, new StyleChangedEventArgs(oldState, style, _stackingState));
            }
        }
示例#5
0
 public Character(AnimatedSprite sprite, Vector2 pos, float angle = 0.0f)
     : base(sprite, pos, angle)
 {
     ai = new PatrolMovementStyle();
     Health = 0;
     MOVEMENT_SPEED = 120;
     PhysicsBody.UserData = this;
 }
示例#6
0
 void IMovementStyle.OnActivate(IMovementStyle lastStyle, ActivationReason reason)
 {
     if (_mode == UpdateMode.Inactive)
     {
         this.DetermineUpdateMode();
     }
     _activeStatus = true;
     this.OnActivate(lastStyle, reason);
 }
 void IMovementStyle.OnActivate(IMovementStyle lastStyle, bool stateIsStacking)
 {
     if (_mode == UpdateMode.Inactive)
     {
         this.DetermineUpdateMode();
     }
     _activeStatus = true;
     this.OnActivate(lastStyle, stateIsStacking);
 }
 void IMovementStyle.OnDeactivate(IMovementStyle nextStyle, bool stateIsStacking)
 {
     if (_paused)
     {
         this.Pause(false);
     }
     this.OnDeactivate(nextStyle, stateIsStacking);
     _activeStatus = false;
 }
示例#9
0
 void IMovementStyle.OnDeactivate(IMovementStyle nextStyle, ActivationReason reason)
 {
     if (_paused)
     {
         this.Pause(false);
     }
     this.OnDeactivate(nextStyle, reason);
     _activeStatus = false;
 }
        public IMovementStyle ChangeState(IMovementStyle style, float precedence = 0)
        {
            if (!object.ReferenceEquals(style, null) && !this.Contains(style))
            {
                throw new System.ArgumentException("MovementStyle '" + style.GetType().Name + "' is not a member of the state machine.", "style");
            }

            this.ChangeState_Imp(style, precedence, true);
            return(style);
        }
 void IMovementStyle.OnDeactivate(IMovementStyle nextStyle, bool stateIsStacking)
 {
     if (_paused)
     {
         this.Pause(false);
     }
     this.OnDeactivate(nextStyle, stateIsStacking);
     _activeStatus = false;
     if (_controller != null)
     {
         _controller.MovementControllerHit -= this.OnControllerHitHandler;
     }
 }
示例#12
0
 void IMovementStyle.OnDeactivate(IMovementStyle nextStyle, ActivationReason reason)
 {
     if (_paused)
     {
         this.Pause(false);
     }
     this.OnDeactivate(nextStyle, reason);
     _activeStatus = false;
     if (_controller != null)
     {
         _controller.MovementControllerHit -= this.OnControllerHitHandler;
     }
 }
        private void ChangeState_Imp(IMovementStyle style, float precedence, bool dumpStack)
        {
            if (_inUpdateSequence)
            {
                //test if we should replace the last ChangeStyle call... test if null so that one can ChangeStyle with a NegativeInfinity precendance
                if (precedence >= _changeStyleDelayedPrecedence || _changeStyleDelayed == null)
                {
                    _changeStyleDelayedPrecedence = precedence;
                    _changeStyleDelayed           = delegate()
                    {
                        if (dumpStack)
                        {
                            var e = _styleStack.GetEnumerator();
                            while (e.MoveNext())
                            {
                                if (e.Current != null & e.Current != style)
                                {
                                    e.Current.OnPurgedFromStack();
                                }
                            }
                            _styleStack.Clear();
                        }

                        this.SwapStateOut(style);
                    };
                }
            }
            else
            {
                if (dumpStack)
                {
                    var e = _styleStack.GetEnumerator();
                    while (e.MoveNext())
                    {
                        if (e.Current != null && e.Current != style)
                        {
                            e.Current.OnPurgedFromStack();
                        }
                    }
                    _styleStack.Clear();
                }

                this.SwapStateOut(style);
            }
        }
        public void PurgeStackedState(IMovementStyle style)
        {
            if (object.ReferenceEquals(style, null))
            {
                throw new System.ArgumentNullException("style");
            }
            if (_styleStack.Count == 0)
            {
                return;
            }

            int index = _styleStack.IndexOf(style);

            if (index > 0)
            {
                _styleStack.RemoveAt(index);
                style.OnPurgedFromStack();
            }
            //we don't purge if the stack doesn't contain the style, or if it's the bottom entry... the bottom entry can only be swapped out
        }
        public void ChangeCurrentUnstackedState(IMovementStyle style)
        {
            if (_styleStack.Count > 0)
            {
                var oldStyle = _styleStack[0];
                if (oldStyle == style)
                {
                    return;
                }

                _styleStack[0] = style;
                if (oldStyle != null)
                {
                    oldStyle.OnPurgedFromStack();
                }
            }
            else
            {
                this.ChangeState(style);
            }
        }
        public IMovementStyle StackState(IMovementStyle style, float precedence = 0)
        {
            if (!object.ReferenceEquals(style, null) && !this.Contains(style))
            {
                throw new System.ArgumentException("MovementStyle '" + style.GetType().Name + "' is not a member of the state machine.", "style");
            }

            if (_inUpdateSequence)
            {
                //test if we should replace the last ChangeStyle call... test if null so that one can ChangeStyle with a NegativeInfinity precendance
                if (precedence >= _changeStyleDelayedPrecedence || _changeStyleDelayed == null)
                {
                    _stackStyleDelayed.Add(() =>
                    {
                        if (this.Current == style)
                        {
                            return;
                        }
                        _styleStack.Push(this.Current);
                        _stackingState = true;
                        this.ChangeState_Imp(style, precedence, false);
                        _stackingState = false;
                    }, precedence);
                }
            }
            else
            {
                if (this.Current == style)
                {
                    return(style);
                }
                _styleStack.Push(this.Current);
                _styleStack.Push(style);
                _stackingState = true;
                this.ChangeState_Imp(style, precedence, false);
                _stackingState = false;
            }

            return(style);
        }
 public void OnActivate(IMovementStyle lastStyle, bool stateIsStacking)
 {
 }
 public bool Contains(IMovementStyle state)
 {
     return(state.gameObject == this.gameObject);
 }
示例#19
0
 public void OnActivate(IMovementStyle lastStyle, ActivationReason reason)
 {
 }
 protected virtual void OnDeactivate(IMovementStyle nextStyle, bool stateIsStacking)
 {
 }
 protected virtual void OnActivate(IMovementStyle lastStyle, bool stateIsStacking)
 {
 }
示例#22
0
 protected virtual void OnDeactivate(IMovementStyle nextStyle, ActivationReason reason)
 {
 }
 public StyleChangedEventArgs(IMovementStyle oldStyle, IMovementStyle newStyle, bool currentStateIsStacking)
 {
     _oldStyle = oldStyle;
     _newStyle = newStyle;
     _currentStateIsStacking = currentStateIsStacking;
 }
示例#24
0
 protected virtual void OnActivate(IMovementStyle lastStyle, ActivationReason reason)
 {
 }