92 lines
3.2 KiB
C#
92 lines
3.2 KiB
C#
using DunGen;
|
|
using DunGen.Graph;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DunGenPlus.Generation {
|
|
internal partial class DunGenPlusGenerator {
|
|
|
|
public static void AddForcedTiles(DungeonGenerator gen){
|
|
if (!Properties.UseForcedTiles) return;
|
|
|
|
var forcedTileSetLists = Properties.ForcedTileSets.ToList();
|
|
while(forcedTileSetLists.Count > 0){
|
|
var item = forcedTileSetLists[forcedTileSetLists.Count - 1];
|
|
|
|
// we have to check ALL tiles
|
|
var allTiles = gen.proxyDungeon.AllTiles
|
|
.Select(t => {
|
|
var depthValue = item.DepthWeightScale.Evaluate(t.Placement.NormalizedDepth);
|
|
var weight = t.Placement.IsOnMainPath ? item.MainPathWeight : item.BranchPathWeight;
|
|
return (t, depthValue * weight * gen.RandomStream.NextDouble());
|
|
})
|
|
.Where(pair => pair.Item2 > 0f)
|
|
.OrderBy(pair => pair.Item2);
|
|
|
|
// try every tile, if we somehow fail than man that sucks
|
|
foreach(var pair in allTiles){
|
|
var t = pair.t;
|
|
var tileProxy = gen.AddTile(t, item.Tilesets, t.Placement.NormalizedDepth, null, TilePlacementResult.None);
|
|
if (tileProxy == null) continue;
|
|
|
|
tileProxy.Placement.BranchDepth = t.Placement.BranchDepth;
|
|
tileProxy.Placement.NormalizedBranchDepth = t.Placement.NormalizedDepth;
|
|
tileProxy.Placement.GraphNode = t.Placement.GraphNode;
|
|
tileProxy.Placement.GraphLine = t.Placement.GraphLine;
|
|
|
|
Plugin.logger.LogDebug($"Forcefully added tile {tileProxy.Prefab.name}");
|
|
break;
|
|
}
|
|
|
|
forcedTileSetLists.RemoveAt(forcedTileSetLists.Count - 1);
|
|
}
|
|
|
|
Plugin.logger.LogDebug($"Forcefully added all tiles");
|
|
}
|
|
|
|
public static void RandomizeLineArchetypes(DungeonGenerator gen, bool randomizeMainPath){
|
|
if (!Properties.UseLineRandomizer) return;
|
|
|
|
var flow = Instance.DungeonFlow;
|
|
var lines = flow.Lines;
|
|
var tilesetsUsed = new Dictionary<TileSet, int>();
|
|
foreach(var t in Properties.LineRandomizerTileSets){
|
|
tilesetsUsed.Add(t, 0);
|
|
}
|
|
|
|
foreach(var a in Properties.LineRandomizerArchetypes) {
|
|
var tiles = randomizeMainPath ? a.TileSets : a.BranchCapTileSets;
|
|
RandomizeArchetype(gen, tiles, tilesetsUsed);
|
|
}
|
|
}
|
|
|
|
public static void RandomizeArchetype(DungeonGenerator gen, List<TileSet> targetTileSet, Dictionary<TileSet, int> tilesetsUsed){
|
|
// get 3 random
|
|
var newTiles = Properties.LineRandomizerTileSets
|
|
.OrderBy(t => tilesetsUsed[t] + gen.RandomStream.NextDouble())
|
|
.Take(Properties.LineRandomizerTakeCount);
|
|
|
|
var i = targetTileSet.Count - 1;
|
|
foreach(var n in newTiles){
|
|
targetTileSet[i] = n;
|
|
--i;
|
|
|
|
tilesetsUsed[n] += 1;
|
|
}
|
|
}
|
|
|
|
public static DungeonArchetype ModifyMainBranchNodeArchetype(DungeonArchetype archetype, GraphNode node, RandomStream randomStream){
|
|
if (!DunGenPlusGenerator.Active) return archetype;
|
|
|
|
if (Properties.AddArchetypesToNormalNodes && node.NodeType == NodeType.Normal) {
|
|
return Properties.GetRandomArchetype(node.Label, randomStream);;
|
|
}
|
|
return archetype;
|
|
}
|
|
|
|
}
|
|
}
|