fCraft.PlayerProximityTracker.MovePlayer C# (CSharp) Method

MovePlayer() public method

public MovePlayer ( Vector3I oldPos, Vector3I newPos, Player p ) : void
oldPos Vector3I
newPos Vector3I
p Player
return void
        public void MovePlayer( Vector3I oldPos, Vector3I newPos, Player p )
        {
            //the new pos is given as an argument (assumed from PlayerMoved event args) so that the new position would match the previous in the next moved event
            CheckCoords( ref oldPos );
            CheckCoords( ref newPos );
            if ( newPos.X == oldPos.X && newPos.Y == oldPos.Y ) //nothing to do?
                return;

            if ( null == _players[oldPos.X, oldPos.Y] || !_players[oldPos.X, oldPos.Y].Remove( p ) ) {//this is not a fatal error, the player, even when existing at some wrong position will not be returned by the find call looking around this wrong position
                Logger.Log( LogType.Error, "PlayerProximityTracker.MovePlayer: Player " + p.Name + " is not found at its previous position" );
            }
            AddPlayer( p, newPos );
        }

Usage Example

Example #1
0
 public void OnPlayerMoved(object sender, PlayerMovedEventArgs args)
 {
     lock ( _lock ) {
         if (args.Player.World != _world)    //he left....chicken
         //_tracker.RemovePlayer(args.Player); remove will not work since the guy definitely has different position now
         //he will be removed from book keeping later in PlayerProximityTracker.FindPlayersAtDistance
         {
             return;
         }
         _tracker.MovePlayer(args.OldPosition.ToBlockCoords(), args.NewPosition.ToBlockCoords(), args.Player);
     }
 }