Beispiel #1
0
		/// <summary>
		/// Teleports the owner to the given position in the given map.
		/// </summary>
		/// <param name="map">the target <see cref="Map" /></param>
		/// <param name="pos">the target <see cref="Vector3">position</see></param>
		/// <param name="orientation">the target orientation</param>
		public void TeleportTo(Map map, ref Vector3 pos, float? orientation)
		{
			var ownerMap = m_Map;
			if (map.IsDisposed)
				return;

			// must not be moving or logging out when being teleported
			CancelMovement();
			CancelAllActions();
			if (this is Character)
			{
				((Character)this).CancelLogout();
			}

			if (ownerMap == map)
			{
				if (Map.MoveObject(this, ref pos))
				{
					if (orientation.HasValue)
						Orientation = orientation.Value;

					if (this is Character)
					{
						var chr = ((Character)this);
						chr.LastPosition = pos;

						MovementHandler.SendMoved(chr);
					}
				}
			}
			else
			{
				if (ownerMap != null && !ownerMap.IsInContext)
				{
					var position = pos;
					ownerMap.AddMessage(new Message(() => TeleportTo(map, ref position, orientation)));
				}
				else if (map.TransferObjectLater(this, pos))
				{
					if (orientation.HasValue)
					{
						Orientation = orientation.Value;
					}

					if (this is Character)
					{
						var chr = ((Character)this);
						chr.LastPosition = pos;

						MovementHandler.SendNewWorld(chr.Client, map.Id, ref pos, Orientation);
					}
				}
				else
				{
					// apparently, the target map has a colliding entity ID. this should NEVER 
					// happen for any kind of Unit

					log.Error("ERROR: Tried to teleport object, but failed to add player to the new map - " + this);
				}
			}
		}