Example #1
0
 public bool ChangeState(IActionState state)
 {
     state.Session = this;
     CurrentState  = state;
     logger.Debug("состояние изменилось, новое {0}", state);
     return(true);
 }
        public IActionState GetState(string state)
        {
            IActionState actionState = null;

            if (_states.ContainsKey(state))
            {
                actionState = _states[state];
            }
            else
            {
                switch (state)
                {
                case "Moving":
                    actionState = new MovingState();
                    break;

                case "Idle":
                    actionState = new IdleState();
                    break;

                case "Shooting":
                    actionState = new ShootingState();
                    break;
                }
                _states.Add(state, actionState);
            }

            return(actionState);
        }
Example #3
0
        void Update()
        {
#if UNITY_EDITOR
            if (isDummy)
            {
                return;
            }
            if (actorController == null)
            {
                return;                 // prevents error spam after editing a script
            }
#endif

            actorController.UpdateCommands();

            ActionStateType nextAction = actionState.UpdateState();
            if (nextAction != ActionStateType.NONE)
            {
                if (!actionStateLookup.TryGetValue(nextAction, out IActionState newAction))
                {
                    Debug.Log(this.name + " could not find actionState for " + nextAction.ToString());
                }
                else
                {
                    ActionStateType prevAction = actionState.ExitState(nextAction);
                    actionState = newAction;
                    actionState.EnterState(prevAction);
                    currentActionState = nextAction;
                }
            }
        }
Example #4
0
 private void OnActionStateChanged()
 {
     if (PrivateState.CurrentActionState != null)
     {
         // Action was started.
         lastActionState = PrivateState.CurrentActionState;
         if (lastActionState is BottleRefillAction bottleRefillAction)
         {
             usedItem              = bottleRefillAction.ItemEmptyBottle;
             waitingForServer      = true;
             fillingActionDuration = 0.0;
         }
     }
     else
     {
         if (lastActionState is BottleRefillAction bottleRefillAction)
         {
             if (!IsWaterNearby() ||
                 bottleRefillAction.IsCancelled || bottleRefillAction.IsCancelledByServer)
             {
                 // Action failed: no water nearby or cancelled on server.
                 usedItem         = null;
                 waitingForServer = false;
             }
         }
         else
         {
             // Other action finished - reset waiting status just in case.
             usedItem         = null;
             waitingForServer = false;
         }
     }
 }
        public void SwitchState(int id)
        {
            if (id == stateEnd)
            {
                End();
                return;
            }

            IActionState newState = null;

            if (id >= 0 && id < states.Count)
            {
                newState = states[id];
            }
            currentStateId = id;

            if (newState == currentState)
            {
                return;
            }

            if (currentState != null)
            {
                currentState.Cleanup();
            }

            currentState = newState;

            if (currentState != null)
            {
                currentState.SetAction(this);
                currentState.Setup();
            }
        }
Example #6
0
        /// <summary>
        /// Returns the ActionState from the first failed icf's of the given set, the ActionState from the last successfull icf if all of them succeeded, or the given <paramref name="fallbackValue"/>.
        /// </summary>
        public static IActionState GetFirstFailureOrAllSuccessState(this IClientFacet[] actionSetArray, IActionState fallbackValue = null)
        {
            int          numThatHaveNotCompleted = 0;
            IActionState lastSuccess             = null;

            foreach (var icf in actionSetArray)
            {
                var actionState = icf.ActionState;

                if (!actionState.IsComplete)
                {
                    numThatHaveNotCompleted++;
                }
                else if (actionState.Failed)
                {
                    return(actionState);
                }
                else
                {
                    lastSuccess = actionState;
                }
            }

            if (numThatHaveNotCompleted == 0)
            {
                return(lastSuccess);
            }

            return(fallbackValue);
        }
Example #7
0
 private void OnActionStateChanged()
 {
     if (PrivateState.CurrentActionState != null)
     {
         // Action was started.
         readyForInteraction = false;
         openedLootContainer = null;
         lastActionState     = PrivateState.CurrentActionState;
     }
     else
     {
         // Action is finished.
         // Check if we opened a loot container.
         if (lastActionState != null &&
             lastActionState.IsCompleted &&
             !lastActionState.IsCancelled && !lastActionState.IsCancelledByServer &&
             lastActionState.TargetWorldObject?.ProtoGameObject is ProtoObjectLootContainer)
         {
             openedLootContainer = lastActionState.TargetWorldObject;
         }
         else
         {
             readyForInteraction = true;
         }
     }
 }
Example #8
0
 //Jump -> fall, jump, run, walk
 public void IdleStateTransition()
 {
     if (PreviousState is WalkingState || PreviousState is RunningState)
     {
         PreviousState = new IdleState(peach);                                                                 // let go of key midair
     }
     return;
 }
Example #9
0
 void Awake()
 {
     rigidbody2D      = GetComponent <Rigidbody2D>();
     mySpriteRenderer = GetComponent <SpriteRenderer>();
     sideJumpForce    = jumpForce * 1.2f;
     stamina          = GetComponent <IStamina>();
     actionState      = GetComponent <IActionState>();
 }
Example #10
0
 public void Jump()
 {
     if (!(this.actionState is CrouchingState))
     {
         this.Velocity.Y = -this.jumpSpeed;
     }
     this.actionState = this.actionState.Jump();
     OnJump();
 }
        protected int AddState(IActionState state)
        {
            int id = states.Count;

            states.Add(state);
            state.SetId(id);

            return(id);
        }
Example #12
0
 public void MoveRight()
 {
     if (!leftFacing)
     {
         this.Velocity.X = horizontalSpeed;
     }
     this.actionState = this.actionState.MoveRight(ref leftFacing);
     support          = false;
 }
Example #13
0
 public void CollideHorizontal(ICollidable collidable)
 {
     Debug.WriteLine("Horrizontal collision is occurring at " + this.Position + "and bottom is at " + (this.Position.Y + this.BoundingBox.Height));
     Debug.WriteLine("box's spot is " + collidable.BoundingBox);
     this.actionState = IdlingState.Instance;
     this.Velocity.X  = 0;
     Gravity(support);
     support = false;
 }
Example #14
0
 /// <summary>
 /// Stop everything.
 /// </summary>
 public override void Stop()
 {
     if (interactionQueue?.Count > 0)
     {
         interactionQueue.Clear();
         InteractionCheckerSystem.CancelCurrentInteraction(CurrentCharacter);
     }
     readyForInteraction = true;
     lastActionState     = null;
 }
Example #15
0
 public void StopCrouch()
 {
     /* if(!(this.powerupState is StandardState)){
      *   this.actionState = this.actionState.Jump();
      * }*/
     if (!(CurrentPowerupState is MarioStandardState))
     {
         this.actionState = this.actionState.Jump();
         Position         = new Vector2(Position.X, Position.Y - 15);
     }
 }
Example #16
0
 public void StopRight()
 {
     if (this.Velocity.X == horizontalSpeed)
     {
         this.Velocity.X = 0;
         if (this.Velocity.Y != -jumpSpeed)
         {
             this.actionState = this.actionState.MoveLeft(ref leftFacing);
         }
     }
 }
Example #17
0
 /// <summary>
 /// Stop everything.
 /// </summary>
 public override void Stop()
 {
     if (interactionQueue?.Count > 0)
     {
         interactionQueue.Clear();
         InteractionCheckerSystem.SharedAbortCurrentInteraction(CurrentCharacter);
     }
     readyForInteraction = true;
     lastActionState     = null;
     openedLootContainer = null;
 }
Example #18
0
 void Awake()
 {
     timeState         = TimeState.Ready;
     positionArray     = new ArrayList();
     stamina           = GetComponent <IStamina>();
     rigidbody2D       = GetComponent <Rigidbody2D>();
     actionState       = GetComponent <IActionState>();
     invulnerableState = GetComponent <IHealth>();
     positionArray.Add(new PositionArray(this.transform.position));
     SpawnTracerObject();
 }
Example #19
0
    // Use this for initialization
    void Awake()
    {
        // Set up references.
        rigidbody2D      = GetComponent <Rigidbody2D>();
        mySpriteRenderer = GetComponent <SpriteRenderer>();
        stamina          = GetComponent <IStamina>();
        actionState      = GetComponent <IActionState>();

        //Create own definitions for left and right
        vector2Right = new Vector2(1f, rigidbody2D.velocity.y);
        vector2Left  = new Vector2(-1f, rigidbody2D.velocity.y);
    }
Example #20
0
 private void OnActionStateChanged()
 {
     if (PrivateState.CurrentActionState != null)
     {
         // Action was started.
         readyForInteraction = false;
         lastActionState     = PrivateState.CurrentActionState;
     }
     else
     {
         readyForInteraction = true;
     }
 }
Example #21
0
    void Awake()
    {
        //Set the rigidbody and invulnerable components.
        rigidbody2D       = GetComponent <Rigidbody2D>();
        invulnerableState = GetComponent <IHealth>();
        actionState       = GetComponent <IActionState>();

        //Setup for all four different directions
        boostSpeedRight = new Vector2(boostSpeed, 0);
        boostSpeedLeft  = new Vector2(-boostSpeed, 0);
        boostSpeedUp    = new Vector2(0, boostSpeed);
        boostSpeedDown  = new Vector2(0, -boostSpeed);
    }
Example #22
0
        /// <summary>
        /// Init on component enabled.
        /// </summary>
        public override void Start(ClientComponent parentComponent)
        {
            base.Start(parentComponent);

            ContainerHotbar.ItemRemoved      += ContainerHotbarOnItemRemoved;
            ContainerHotbar.ItemCountChanged += ContainerHotbarOnItemCountChanged;

            // Check if there an action in progress.
            if (PrivateState.CurrentActionState != null)
            {
                lastActionState = PrivateState.CurrentActionState;
            }
        }
Example #23
0
 protected Enemy(IPathFinding pathFinder, IWeapon weapon, IPlayer player, double lifePoints, Vector2 position, Texture2D texture, IActionState state, IMap map)
 {
     PathFinder   = pathFinder;
     Weapon       = weapon;
     LifePoints   = lifePoints;
     Position     = position;
     Texture      = texture;
     CurrentState = state;
     _player      = player;
     Map          = map;
     _player.AttachObserver(this);
     Alive = true;
     Send(EnemySpawned);
 }
Example #24
0
        /// <summary>
        /// Returns true if the given actionState has the same contents as the given rhs.
        /// </summary>
        public static bool IsEqualTo(this IActionState actionState, IActionState rhs, bool compareTimestamps = true)
        {
            if (Object.ReferenceEquals(actionState, rhs) || (actionState == null && rhs == null))
            {
                return(true);
            }

            if (actionState == null || rhs == null)
            {
                return(false);
            }

            return(actionState.Equals(rhs, compareTimestamps: compareTimestamps));
        }
Example #25
0
        /// <summary>
        /// A hack to get button input in the elevator.
        /// </summary>
        public void EnterElevator()
        {
            ActionStateType nextAction = ActionStateType.ELEVATOR;

            if (!actionStateLookup.TryGetValue(nextAction, out IActionState newAction))
            {
                Debug.Log(this.name + " could not find actionState for " + nextAction.ToString());
            }
            else
            {
                ActionStateType prevAction = actionState.ExitState(nextAction);
                actionState = newAction;
                actionState.EnterState(prevAction);
                currentActionState = nextAction;
            }
        }
Example #26
0
        /// <summary>
        /// Init on component enabled.
        /// </summary>
        public override void Start(ClientComponent parentComponent)
        {
            base.Start(parentComponent);

            // Check if there an action in progress.
            if (PrivateState.CurrentActionState != null)
            {
                readyForInteraction = false;
                lastActionState     = PrivateState.CurrentActionState;
            }

            // Check if we opened loot container before enabling component.
            var currentInteractionObject = InteractionCheckerSystem.SharedGetCurrentInteraction(CurrentCharacter);

            if (currentInteractionObject?.ProtoWorldObject is ProtoObjectLootContainer)
            {
                readyForInteraction = false;
            }
        }
Example #27
0
 private void OnActionStateChanged()
 {
     if (PrivateState.CurrentActionState != null)
     {
         readyForInteraction = false;
         openedLootContainer = null;
         lastActionState     = PrivateState.CurrentActionState;
     }
     else
     {
         if (lastActionState.IsCompleted &&
             !lastActionState.IsCancelled && !lastActionState.IsCancelledByServer &&
             lastActionState.TargetWorldObject.ProtoGameObject is ProtoObjectLootContainer lootContainer)
         {
             openedLootContainer = lootContainer;
         }
         readyForInteraction = true;
     }
 }
Example #28
0
 public void Crouch()
 {
     if (canMoveDown)
     {
         if (this.Velocity.Y == jumpSpeed)
         {
             this.Velocity.Y = 0;
         }
         else
         {
             this.Velocity.Y = jumpSpeed;
         }
     }
     if (!(CurrentPowerupState is MarioStandardState))
     {
         Position = new Vector2(Position.X, Position.Y + 15);
     }
     this.actionState = this.actionState.Crouch(/*this.powerupState*/ CurrentPowerupState);
     //this stop method is just the Jump method
 }
Example #29
0
        public void UpdateJump(bool stoping)
        {
            int maxJumpHeight = 150;

            if (heightJumped > maxJumpHeight || stoping)
            {
                //Debug.WriteLine(this.heightJumped + " height jumped after stop");
                this.Velocity.Y = 0;
                heightJumped    = 0;
                //this needs to change to falling once I get that implemented correctly
                if (this.actionState is JumpingState)
                {
                    this.actionState = this.actionState.Crouch(/*this.powerupState*/ CurrentPowerupState);
                }
                support = false;
                Gravity(support);
            }
            else
            {
                this.heightJumped = this.heightJumped + jumpSpeed;
                //Debug.WriteLine( this.heightJumped + " heightJumped and " + maxJumpHeight + " maxJumpHeight.");
            }
        }
Example #30
0
        public PlayerContext(int sWidth, int sHeight, Vector2 loc)
        {
            //Instantiate power states
            loc.Y     += MarioSpriteFactory.BIG_MARIO_HEIGHT - MarioSpriteFactory.SMALL_MARIO_HEIGHT;
            Location   = loc;
            fireMario  = new FireMario(this);
            smallMario = new SmallMario(this);
            superMario = new SuperMario(this);
            deadMario  = new DeadMario(this);

            //Instantiate action states
            idleMario      = new IdleMario(this);
            runningMario   = new RunningMario(this);
            jumpingMario   = new JumpingMario(this);
            fallingMario   = new FallingMario(this);
            crouchingMario = new CrouchingMario(this);

            screenWidth  = sWidth;
            screenHeight = sHeight;

            //Set initial states
            PowerState = smallMario;

            ActionState = idleMario;

            currentState = MarioState.Small;

            currentFrame = MarioFrame.Idle;

            WidthHeight = new Vector2(MarioSpriteFactory.SMALL_MARIO_WIDTH, MarioSpriteFactory.SMALL_MARIO_HEIGHT);

            Mario      = new MarioSprite(Location, sWidth, sHeight, MarioState.Small, MarioColor.Red, MarioFrame.Idle, facingLeft, IsBounded);
            playerRect = new Rectangle((int)Location.X, (int)Location.Y, MarioSpriteFactory.SMALL_MARIO_WIDTH, MarioSpriteFactory.SMALL_MARIO_HEIGHT);
            EntityType = TileMapInterpreter.Entities.PLAYER;
            Velocity   = new Vector2(horizontalMovementFactor, verticalMovementFactor);
        }