private PossibleDirection GetIntendedDirection(Monster monster) { TilePos tp = monster.TilePosition; TilePos playerPosition = GlobalServices.GameState.Player.TilePosition; int yDiff = tp.Y - playerPosition.Y; // +ve and the monster is below, -ve and the monster is above int xDiff = tp.X - playerPosition.X; // +ve and the monster is to the right, -ve and the monster is to the left var orientation = this.CurrentDirection.Orientation(); if (orientation == Orientation.Horizontal) { if (yDiff > 0) { return(PossibleDirection.Up); } if (yDiff < 0) { return(PossibleDirection.Down); } } else if (orientation == Orientation.Vertical) { if (xDiff > 0) { return(PossibleDirection.Left); } if (xDiff < 0) { return(PossibleDirection.Right); } } return(MonsterMovement.RandomDirection()); }
public override ConfirmedDirection GetDirection() { IDirectionChosen directionTowardsPlayer = this.Monster.DetermineDirectionTowardsPlayer(); if (!(directionTowardsPlayer is ConfirmedDirection)) { bool notPossibleToGoInDirectionTowardsPlayer = !this.Monster.ConfirmDirectionToMoveIn(directionTowardsPlayer, out ConfirmedDirection feasibleDirection); if (notPossibleToGoInDirectionTowardsPlayer || feasibleDirection == Direction.None) { return(feasibleDirection); } } // we know at this point that we could move in DirectionTowardsPlayer HOWEVER we don't want to actually step onto the same tile as the player TilePos potentiallyMovingTowards = this.Monster.TilePosition.GetPositionAfterOneMove(directionTowardsPlayer.Direction); if (potentiallyMovingTowards != GlobalServices.GameState.Player.TilePosition) { // it's okay. we'll be closer to the player without actually touching the player return(directionTowardsPlayer.Confirm()); } var directionAwayFromPlayer = MonsterMovement.AlterDirectionByVeeringAway(directionTowardsPlayer.Direction); this.Monster.ConfirmDirectionToMoveIn(directionAwayFromPlayer, out ConfirmedDirection result); return(result); }
protected IDirectionChosen GetDesiredDirection() { if (this.CurrentDirection == Direction.None) { return(ShouldMonsterFollowPlayerIntoAnotherRoom() ? this.Monster.DetermineDirectionTowardsPlayer() : MonsterMovement.RandomDirection()); } bool shouldChangeDirection = GlobalServices.Randomness.Test(7); if (shouldChangeDirection) { return(ShouldMonsterFollowPlayerIntoAnotherRoom() ? this.Monster.DetermineDirectionTowardsPlayer() : MonsterMovement.AlterDirectionByVeeringAway(this.CurrentDirection)); } if (this.Monster.CanMoveInDirection(this.CurrentDirection)) { return(new ConfirmedDirection(this.CurrentDirection)); } var reversed = this.CurrentDirection.Reversed(); return(new PossibleDirection(reversed)); }
public override ConfirmedDirection GetDirection() { var result = ShouldMakeAnAggressiveMove(this.Monster) ? this.Monster.DetermineDirectionTowardsPlayer() : MonsterMovement.RandomDirection(); return(base.GetConfirmedDirection(result)); }
public static IDirectionChosen MoveTowardsPlayer(Monster monster) { bool shouldMoveRandomly = GlobalServices.Randomness.Test(7); IDirectionChosen result = shouldMoveRandomly ? MonsterMovement.RandomDirection() : monster.DetermineDirectionTowardsPlayer(); return(result); }
private static IDirectionChosen MoveAwayFromPlayer(Monster monster) { var awayFromPlayer = monster.DetermineDirectionAwayFromPlayer(); bool shouldDodgeWhilstFleeing = GlobalServices.Randomness.Test(3); if (shouldDodgeWhilstFleeing) { var alteredDirection = MonsterMovement.AlterDirectionByVeeringAway(awayFromPlayer.Direction); return(alteredDirection); } return(awayFromPlayer); }
private IDirectionChosen GetDesiredDirection() { if (this.Monster.ChangeRooms == ChangeRooms.FollowsPlayer && !this.Monster.IsPlayerInSameRoom() && this.Monster.IsPlayerNearby()) { var pursuitResult = CautiousPursuit.MoveTowardsPlayer(this.Monster); return(pursuitResult); } var result = MonsterMovement.RandomDirection(); return(result); }
private static PossibleDirection GetRandomPerpendicularDirection(Direction currentDirection) { if (currentDirection == Direction.None) { return(MonsterMovement.RandomDirection()); } bool whichWay = GlobalServices.Randomness.Next(2) == 0; var orientation = currentDirection.Orientation(); switch (orientation) { case Orientation.Horizontal: return(whichWay ? PossibleDirection.Up : PossibleDirection.Down); case Orientation.Vertical: return(whichWay ? PossibleDirection.Left : PossibleDirection.Right); } throw new InvalidOperationException(); }