/// <summary> /// Moves the entity in a direction. /// </summary> /// <param name="entity"></param> /// <param name="source"></param> /// <param name="destination"></param> public static void Move(Living entity, Tile source, Tile destination) { ComponentSelectable sLocation = source.GetExactComponent <ComponentSelectable>(); ComponentSelectable dLocation = destination.GetExactComponent <ComponentSelectable>(); Direction direction = DetermineMovementDirection(sLocation.MapLocation, dLocation.MapLocation); float xMove = 0; float yMove = 0; AnimatedTexture animated = (AnimatedTexture)entity.Visual; switch (direction) { case Direction.North: yMove = -1; animated.StartSequence(Human.UpSequence); break; case Direction.South: yMove = 1; animated.StartSequence(Human.DownSequence); break; case Direction.East: xMove = 1; animated.StartSequence(Human.RightSequence); break; case Direction.West: xMove = -1; animated.StartSequence(Human.LeftSequence); break; case Direction.NorthWest: xMove = -1; yMove = -1; break; case Direction.NorthEast: xMove = 1; yMove = -1; break; case Direction.SouthWest: xMove = -1; yMove = 1; break; case Direction.SouthEast: xMove = 1; yMove = 1; break; default: throw new InvalidOperationException("Unexpected value for direction: " + direction.ToString()); } ComponentMovement movementComponent = entity.GetExactComponent <ComponentMovement>(); xMove *= (float)movementComponent.Movement.GetValue(); yMove *= (float)movementComponent.Movement.GetValue(); float movementPenalty = (float)Math.Abs(CalculateMovementReduction(xMove, yMove)) * -1; if (MathUtil.GetDistance(movementComponent.TileLocation, dLocation.MapLocation) > movementComponent.Movement.GetValue()) { //The character fell short of reaching the next tile movementComponent.TileLocation = new Point2DDouble((float)movementComponent.TileLocation.X + xMove, (float)movementComponent.TileLocation.Y + yMove); FootStepSound(entity, source); } else { //The character made it to the next tile. entity.GetExactComponent <ComponentSelectable>().MapLocation = dLocation.MapLocation; movementComponent.TileLocation = new DataTypes.Point2DDouble(dLocation.MapLocation.X, dLocation.MapLocation.Y); movementComponent.QueuedMovement.Dequeue(); movementPenalty = (float)MathUtil.GetDistance(movementComponent.TileLocation, dLocation.MapLocation); FootStepSound(entity, destination); //If this entity is the current client's and therefore that clients responsibility to report about if (entity.PlayerID == SettingsManager.PlayerSettings.Settings.PlayerID) { ClientSendRecieve.Send(new WorldModifierMessage(new LivingLocationModifier(entity.ID, sLocation.MapLocation, dLocation.MapLocation, entity.Dimension))); } } movementComponent.Movement.AddModifier(new ModifierDouble(movementPenalty, new TimeRemoveCondition(1), Lang.NormalMovement)); }
/// <summary> /// Moves the entity in a direction. /// </summary> /// <param name="entity"></param> /// <param name="source"></param> /// <param name="destination"></param> public static void Move(Living entity, Tile source, Tile destination) { Direction direction = DetermineMovementDirection(source.MapLocation, destination.MapLocation); float xMove = 0; float yMove = 0; AnimatedTexture animated = (AnimatedTexture)entity.Visual; switch (direction) { case Direction.North: yMove = -1; animated.StartSequence(Human.UpSequence); break; case Direction.South: yMove = 1; animated.StartSequence(Human.DownSequence); break; case Direction.East: xMove = 1; animated.StartSequence(Human.RightSequence); break; case Direction.West: xMove = -1; animated.StartSequence(Human.LeftSequence); break; case Direction.NorthWest: xMove = -1; yMove = -1; break; case Direction.NorthEast: xMove = 1; yMove = -1; break; case Direction.SouthWest: xMove = -1; yMove = 1; break; case Direction.SouthEast: xMove = 1; yMove = 1; break; default: throw new UnexpectedEnumMemberException(); } xMove *= entity.Movement.GetValue(); yMove *= entity.Movement.GetValue(); float movementPenalty = (float)Math.Abs(CalculateMovementReduction(xMove, yMove)) * -1; if (MathUtil.GetDistance(entity.TileLocation, destination.MapLocation) > entity.Movement.GetValue()) { //The character fell short of reaching the next tile entity.TileLocation = new DataTypes.Point2DFloat(entity.TileLocation.X + xMove, entity.TileLocation.Y + yMove); FootStepSound(entity, source); } else { Log.Debug("Made it to the next tile!"); //The character made it to the next tile. entity.MapLocation = destination.MapLocation; entity.TileLocation = new DataTypes.Point2DFloat(destination.MapLocation.X, destination.MapLocation.Y); entity.QueuedMovement.Dequeue(); movementPenalty = MathUtil.GetDistance(entity.TileLocation, destination.MapLocation); FootStepSound(entity, destination); //If this entity is the current client's and therefore that clients responsibility to report about if (entity.PlayerID == MagicalLifeSettings.Storage.Player.Default.PlayerID) { ClientSendRecieve.Send(new WorldModifierMessage(new LivingLocationModifier(entity.ID, source.MapLocation, destination.MapLocation, entity.Dimension))); } } entity.Movement.AddModifier(new ModifierFloat(movementPenalty, new TimeRemoveCondition(1), "Normal Movement")); }