public Sprite Find(DungeonTile.Index index, bool isEdge, bool isBorder, out Color color) { foreach (var entry in _db) { if (entry.Index == index) { color = entry.Color; var options = (isEdge && entry.HasEdges) ? entry.EdgeSprites : ((isBorder && entry.HasBorders) ? entry.BorderSprites : entry.Sprites); var totalWeight = 0f; foreach (var option in options) { totalWeight += option.Weight; } var targetWeight = Random.Range(0, totalWeight); foreach (var option in options) { totalWeight -= option.Weight; if (targetWeight >= totalWeight) { return(option.Sprite); } } return(entry.Default); } } color = Color.white; return(default(Sprite)); }
public Sprite Find(DungeonTheme theme, DungeonTile.Index index, bool isEdge, bool isBorder, out Color color) { foreach (var db in _dbs) { if (db.Theme == theme) { return(db.Database.Find(index, isEdge, isBorder, out color)); } } color = Color.white; return(default(Sprite)); }
public static void CountIndexInDirection(Dungeon dungeon, int2 key, BuilderDirection direction, DungeonTile.Index indexType, ref int count) { if (dungeon.ValueMap.ContainsKey(key) == false) { return; } var index = dungeon.ValueMap[key].Index; if (index != indexType) { return; } count++; var adjacentKey = key; switch (direction) { case BuilderDirection.North: adjacentKey = new int2(key.x, key.y - 1); break; case BuilderDirection.East: adjacentKey = new int2(key.x + 1, key.y); break; case BuilderDirection.South: adjacentKey = new int2(key.x, key.y + 1); break; case BuilderDirection.West: adjacentKey = new int2(key.x - 1, key.y); break; } if (adjacentKey.x == key.x && adjacentKey.y == key.y) { return; } CountIndexInDirection(dungeon, adjacentKey, direction, indexType, ref count); }
/// <summary> /// The higher the count of tiles in a direction with the same index, the higher the chance is to covert private bool TryConvertIndexAtoB(Dungeon dungeon, int2 key, BuilderDirection direction, DungeonTile.Index a, DungeonTile.Index b, int maxCount) { var count = 0; CountIndexInDirection(dungeon, key, direction, a, ref count); count = Mathf.Min(count, maxCount); var chance = Mathf.Max((count / (float)maxCount) - 0.1f, 0); if (Random.value < chance) { dungeon.ValueMap[key].Theme = _meta.Theme; dungeon.ValueMap[key].Index = b; return(true); } return(false); }