Initial commit
This commit is contained in:
parent
1af2b57c1c
commit
eebf00988e
30 changed files with 1883 additions and 21 deletions
90
DunGenPlus/DunGenPlus/Generation/DoorwaySistersRule.cs
Normal file
90
DunGenPlus/DunGenPlus/Generation/DoorwaySistersRule.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
using DunGen;
|
||||
using DunGenPlus.Components;
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DunGenPlus.Generation {
|
||||
|
||||
internal static class DoorwaySistersRule {
|
||||
|
||||
public class Data {
|
||||
public DoorwaySisters info;
|
||||
public List<DoorwayProxy> proxies;
|
||||
}
|
||||
|
||||
public static Dictionary<Doorway, Data> doorwayDictionary;
|
||||
public static Dictionary<DoorwayProxy, Data> doorwayProxyDictionary;
|
||||
|
||||
public static void UpdateCache(IEnumerable<DoorwayProxy> list){
|
||||
if (!DunGenPlusGenerator.Active || !DunGenPlusGenerator.Properties.UseDoorwaySisters) return;
|
||||
|
||||
Plugin.logger.LogInfo("Updating DoorwayProxy cache for DoorwaySistersRule");
|
||||
doorwayDictionary = new Dictionary<Doorway, Data>();
|
||||
doorwayProxyDictionary = new Dictionary<DoorwayProxy, Data>();
|
||||
|
||||
foreach(var a in list){
|
||||
|
||||
var doorway = a.DoorwayComponent;
|
||||
if (doorwayDictionary.TryGetValue(doorway, out var data)){
|
||||
|
||||
data.proxies.Add(a);
|
||||
doorwayProxyDictionary.Add(a, data);
|
||||
|
||||
} else {
|
||||
|
||||
var proxies = new List<DoorwayProxy>();
|
||||
proxies.Add(a);
|
||||
var item = new Data {
|
||||
info = doorway.GetComponent<DoorwaySisters>(),
|
||||
proxies = proxies
|
||||
};
|
||||
|
||||
doorwayProxyDictionary.Add(a, item);
|
||||
doorwayDictionary.Add(a.DoorwayComponent, item);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CanDoorwaysConnect(bool result, TileProxy tileA, TileProxy tileB, DoorwayProxy doorwayA, DoorwayProxy doorwayB){
|
||||
|
||||
if (!result) return false;
|
||||
if (!DunGenPlusGenerator.Active || !DunGenPlusGenerator.Properties.UseDoorwaySisters) return true;
|
||||
|
||||
var infoA = doorwayProxyDictionary[doorwayA].info;
|
||||
var infoB = doorwayProxyDictionary[doorwayB].info;
|
||||
|
||||
// deny if any sister doorway is already in use
|
||||
// cause it feels like dumb otherwise
|
||||
if (CheckIfSisterActive(infoA, tileB)){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CheckIfSisterActive(infoB, tileA)){
|
||||
return false;
|
||||
}
|
||||
|
||||
// allow like normal
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CheckIfSisterActive(DoorwaySisters info, TileProxy targetTile){
|
||||
if (info == null || info.sisters == null) return false;
|
||||
|
||||
foreach(var sis in info.sisters){
|
||||
var proxies = doorwayDictionary[sis].proxies;
|
||||
foreach(var proxy in proxies){
|
||||
var result = proxy.ConnectedDoorway != null && proxy.ConnectedDoorway.TileProxy == targetTile;
|
||||
if (result) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue