public bool TileInteraction(NewPackets.TileInteraction parameters) { // Verify index range if (parameters.entityIndex >= Entities.Length || parameters.entityIndex < 0) { return(false); } // This entity is the actor // TODO: reduce casting Entity subject = Entities[parameters.entityIndex] as Entity; if (subject == null) { Debug.Log("ERROR: Entity does not exist!"); return(false); } ByteVector2 tile = new ByteVector2(parameters.tileX, parameters.tileY); // If the entity is `close` to the tile and the tile is solid if (MapManager.Map[parameters.tileX, parameters.tileY] != Tile.Empty && ByteVector2.ManhattanDistance(subject.GetPosition(), tile) <= 1) { // Try to dig with that entity IDigger digger = subject as IDigger; if (digger != null) { digger.Dig(tile); } } // If the entity isn't on that tile else if (ByteVector2.ManhattanDistance(subject.GetPosition(), tile) > 0) { IMover mover = subject as IMover; if (mover != null) { mover.Move(tile); } } return(true); }
public void AddDigger(IDigger digger) { Diggers.Add(digger); }