public void RemoveEntity(IEntity entity) { this.entitiesArea.Remove(entity); ILandChunk lEntityChunk = this.entitiesToChunks[entity]; lEntityChunk.EntitiesInChunk.Remove(entity); this.entitiesToChunks.Remove(entity); if (this.entitiesToBooking.ContainsKey(entity)) { BookingEntity bookingEntity = this.entitiesToBooking[entity]; if (this.entitiesToChunks[bookingEntity] != lEntityChunk) { this.RemoveEntity(this.entitiesToBooking[entity]); } } if (entity is BookingEntity) { BookingEntity bookingEntity = entity as BookingEntity; this.entitiesToBooking.Remove(bookingEntity.Owner); } this.NotifyEntityRemoved(lEntityChunk, entity); entity.Dispose(); }
public bool BookPositionForEntity(LandWorld world, IEntity entity, int x, int y, int z) { if (this.entitiesToBooking.ContainsKey(entity) == false) { ILandChunk landChunk = world.GetLandChunkAt(x, y); if (landChunk != null) { BookingEntity bookingEntity = new BookingEntity(entity, x, y, z); this.entitiesToBooking.Add(entity, bookingEntity); this.AddEntity(entity, landChunk); return(true); } } return(false); }
public bool MoveEntity(IEntity entity, int x, int y, int z) { if (this.entitiesToBooking.ContainsKey(entity)) { BookingEntity bookingEntity = this.entitiesToBooking[entity]; ILandChunk landChunkFrom = this.entitiesToChunks[entity]; ILandChunk landChunkTo = this.entitiesToChunks[bookingEntity]; if (landChunkFrom == null || landChunkTo == null) { throw new Exception("Error during entity moving, chunk from or to is null"); } this.RemoveEntity(bookingEntity); if (landChunkFrom != landChunkTo) { landChunkFrom.EntitiesInChunk.Remove(entity); landChunkTo.EntitiesInChunk.Add(entity); this.entitiesToChunks.Remove(entity); this.entitiesToChunks.Add(entity, landChunkTo); this.NotifyEntityChunkChanged(landChunkFrom, landChunkTo, entity); } entity.SetPosition(x, y, z); this.entitiesArea.Move(entity); this.NotifyEntityCaseChanged(entity); return(true); } return(false); }