/// <summary> /// Initializes a new instance of the <see cref="ItemEntity"/> class. /// </summary> /// <param name="t">The item template to copy the initial values from.</param> /// <param name="pos">The world position of the item.</param> /// <param name="amount">The amount of the item.</param> /// <param name="map">The map the item is to spawn on.</param> public ItemEntity(IItemTemplateTable t, Vector2 pos, byte amount, MapBase map) : this(t, pos, amount) { // Since the item is spawning on a map, ensure that the position is valid for the map var validPos = ValidatePosition(map, pos); if (!IsDisposed) { Teleport(validPos); map.AddEntity(this); } }
/// <summary> /// Teleports the character to a new position and informs clients in the area of /// interest that the character has teleported. /// </summary> /// <param name="newMap">The new map to teleport to.</param> /// <param name="position">Position to teleport to.</param> public void Teleport(MapBase newMap, Vector2 position) { if (newMap != Map) { // Take the character off the old map, teleport, then put them on the new map if (Map != null) Map.RemoveEntity(this); _map = null; Teleport(position); if (newMap != null) { newMap.AddEntity(this); _spSync.ForceSynchronize(); } } else { // Just teleport since the map didn't change Teleport(position); } Debug.Assert(Map == newMap); }