void AttempToMove(Vector2 position) { MDTile tile = MapManager.shared.map.GetTileAt((int)position.x, (int)position.y); MDObject obj = MapManager.shared.map.GetObjectAt(position); MDUnit unit = MapManager.shared.map.GetUnitAt(position); if (tile == null || tile.solid || (tile.liquid && !onBoat)) { Debug.Log("Solid surface!"); } else if (obj != null && obj.solid) { Interact(obj); } else if (unit != null) { if (unit.friendly) { Talk(unit); } else { Attack(unit); } } else { _transform.position = position; MapManager.shared.UpdateChunks(); } }
// Установить объект по координатам public bool SetObjectAt(Vector2 position, MDObject obj) { if (objects.ContainsKey(position)) { return(false); } else { objects.Add(position, obj); return(true); } }
static void MakeRoom(int left = 0, int bottom = 0, int width = 0, int height = 0) { if (left == 0) { left = Random.Range(1, map.width - 3); } if (bottom == 0) { bottom = Random.Range(1, map.height - 3); } if (width == 0) { width = Random.Range(3, map.width - left); } if (height == 0) { height = Random.Range(3, map.height - bottom); } int x, y; Border doorSide = (Border)Random.Range(0, 4); var side = Border.Bottom; for (x = 0; x < width; x++) { for (y = 0; y < height; y++) { if (x == 0 || x == width - 1 || y == 0 || y == height - 1) { if (x == 0) { side = Border.Left; } else if (x == width - 1) { side = Border.Right; } else if (y == 0) { side = Border.Bottom; } else if (x == height - 1) { side = Border.Top; } if (side == doorSide && (x == width / 2 || y == height / 2)) { map.SetTileAt(left + x, bottom + y, new MDTile("floor")); map.SetObjectAt(new Vector2(left + x, bottom + y), new MDObject(OBJECTS.DOOR)); } else { map.SetTileAt(left + x, bottom + y, new MDTile(((Random.Range(0, 5) < 1))? "window" : "wall")); } } else { map.SetTileAt(left + x, bottom + y, new MDTile("floor")); } } } MDObject[] interier = new MDObject[3]; interier[0] = new MDObject(OBJECTS.BED); interier[1] = new MDObject(OBJECTS.BOX); interier[2] = new MDObject(OBJECTS.TERMINAL); for (int i = 0; i < interier.Length; i++) { Vector2 position = Vector2.zero; while (map.GetObjectAt(position) != null || position == Vector2.zero) { position = new Vector2(Random.Range(left + 1, left + width - 1), Random.Range(bottom + 1, bottom + height - 1)); } map.SetObjectAt(position, interier[0]); } }
void Interact(MDObject obj) { Debug.Log("Interact!"); }