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); }
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; } } }
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(); } }
/// <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); }
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; } } }
//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; }
void Awake() { rigidbody2D = GetComponent <Rigidbody2D>(); mySpriteRenderer = GetComponent <SpriteRenderer>(); sideJumpForce = jumpForce * 1.2f; stamina = GetComponent <IStamina>(); actionState = GetComponent <IActionState>(); }
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); }
public void MoveRight() { if (!leftFacing) { this.Velocity.X = horizontalSpeed; } this.actionState = this.actionState.MoveRight(ref leftFacing); support = false; }
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; }
/// <summary> /// Stop everything. /// </summary> public override void Stop() { if (interactionQueue?.Count > 0) { interactionQueue.Clear(); InteractionCheckerSystem.CancelCurrentInteraction(CurrentCharacter); } readyForInteraction = true; lastActionState = null; }
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); } }
public void StopRight() { if (this.Velocity.X == horizontalSpeed) { this.Velocity.X = 0; if (this.Velocity.Y != -jumpSpeed) { this.actionState = this.actionState.MoveLeft(ref leftFacing); } } }
/// <summary> /// Stop everything. /// </summary> public override void Stop() { if (interactionQueue?.Count > 0) { interactionQueue.Clear(); InteractionCheckerSystem.SharedAbortCurrentInteraction(CurrentCharacter); } readyForInteraction = true; lastActionState = null; openedLootContainer = null; }
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(); }
// 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); }
private void OnActionStateChanged() { if (PrivateState.CurrentActionState != null) { // Action was started. readyForInteraction = false; lastActionState = PrivateState.CurrentActionState; } else { readyForInteraction = true; } }
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); }
/// <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; } }
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); }
/// <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)); }
/// <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; } }
/// <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; } }
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; } }
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 }
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."); } }
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); }