Beispiel #1
0
        public void MoveEntity(Coordinate coordinate, Entity entity)
        {
            if (GetPositionOfEntity(entity.Id) != null)
            {
                // Remove from old coordinate
                Coordinate oldCoordinate = m_EntityIdToCoordinate[entity.Id];
                m_CoordinateToMapTile[oldCoordinate].entities.Remove(entity);

                //Add to new coordinate
                m_EntityIdToCoordinate[entity.Id] = coordinate;
                m_CoordinateToMapTile[coordinate].entities.Add(entity);

                EntityMoved?.Invoke(this, new EntityMovedArgs()
                {
                    previousCoordinate = oldCoordinate,
                    coordinate         = coordinate,
                    entity             = entity
                });
            }
        }
Beispiel #2
0
        /// <summary>
        /// Moves an entity to a certain position
        /// </summary>
        /// <param name="entity">Entity to move</param>
        /// <param name="position">Position to move the entity to</param>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="UnknownEnumValueException"/>
        public bool MoveEntity(Entity entity, Position position)
        {
            entity.ThrowIfNull(nameof(entity));

            EntityAboutToMove?.Invoke(this, new EntityMovementEventArgs(entity, null));

            var targetTile = printer[position] as Tile;

            if (targetTile == null || !(
                    targetTile.Type.HasFlag(TileType.Walkable) &&
                    position.InsideBounds(printer.PrintableBounds)))
            {
                return(false);
            }

            EditEntities(entity, EditOperation.Delete);
            entity.Position = position;
            EditEntities(entity, EditOperation.UpdateOrCreate);

            EntityMoved?.Invoke(this, new EntityMovementEventArgs(entity, targetTile));

            return(true);
        }
Beispiel #3
0
 private void OnPlayerMoved(object sender, MoveEventArgs args)
 {
     EntityMoved?.Invoke(sender, args);
 }
 public void FireEntityMove(int id, string path)
 {
     EntityMoved?.Invoke(id, path);
 }
Beispiel #5
0
 internal void OnEntityMove(Entity val)
 {
     EntityMoved?.Invoke(val);
 }
Beispiel #6
0
 public void HandleMove()
 {
     EntityMoved?.Invoke(this);
     SendOwn = false;
 }