Added forced tile generation
Changed RandomGuaranteedScrapSpawn to use the item's weight Added some tooltips/XML
This commit is contained in:
parent
c7f604494e
commit
383c879b96
12 changed files with 171 additions and 21 deletions
|
@ -10,8 +10,8 @@ namespace DunGenPlus.Components.Props
|
|||
{
|
||||
public class SpawnSyncedObjectCycle : MonoBehaviour, IDungeonCompleteReceiver {
|
||||
|
||||
public static int cycle;
|
||||
public static Dictionary<int, int> cycleDictionary;
|
||||
internal static int cycle;
|
||||
internal static Dictionary<int, int> cycleDictionary;
|
||||
|
||||
[Tooltip("The SpawnSyncedObject reference.\n\nWhen the dungeon generation finishes, the spawnPrefab of the referenced SpawnSyncedObject will change to one of the Props based on a cycle. The starting value is random.\n\nThis is designed for the scenario where you have multiple very similar networked gameobjects that serve the same purpose, and you just want them all to spawn equally for diversity sake.")]
|
||||
public SpawnSyncedObject Spawn;
|
||||
|
@ -24,13 +24,13 @@ namespace DunGenPlus.Components.Props
|
|||
Spawn = GetComponent<SpawnSyncedObject>();
|
||||
}
|
||||
|
||||
public static void UpdateCycle(int value){
|
||||
internal static void UpdateCycle(int value){
|
||||
Plugin.logger.LogInfo($"Updating SpawnSyncedObject start cycle to {value}");
|
||||
cycle = value;
|
||||
cycleDictionary = new Dictionary<int, int>();
|
||||
}
|
||||
|
||||
public int GetCycle(int id){
|
||||
internal int GetCycle(int id){
|
||||
if (!cycleDictionary.TryGetValue(id, out var value)){
|
||||
value = cycle;
|
||||
cycleDictionary.Add(id, value);
|
||||
|
|
|
@ -10,24 +10,38 @@ namespace DunGenPlus.Components.Scrap {
|
|||
public class RandomGuaranteedScrapSpawn : MonoBehaviour {
|
||||
|
||||
|
||||
[Tooltip("Chance for the loot to even spawn.")]
|
||||
[Range(0f, 1f)]
|
||||
public float spawnChance = 1f;
|
||||
[Tooltip("Minimum scrap value of the scrap item.")]
|
||||
public int minimumScrapValue = 0;
|
||||
|
||||
public static Dictionary<int, IEnumerable<Item>> scrapItemCache;
|
||||
internal static Dictionary<int, IEnumerable<SpawnableItemWithRarity>> scrapItemRarityCache;
|
||||
|
||||
public static void ResetCache(){
|
||||
scrapItemCache = new Dictionary<int, IEnumerable<Item>>();
|
||||
internal static void ResetCache(){
|
||||
scrapItemRarityCache = new Dictionary<int, IEnumerable<SpawnableItemWithRarity>>();
|
||||
}
|
||||
|
||||
public static IEnumerable<Item> GetCachedItemList(List<SpawnableItemWithRarity> allMoonItems, int scrapValue) {
|
||||
if (!scrapItemCache.TryGetValue(scrapValue, out var list)){
|
||||
list = allMoonItems.Select(i => i.spawnableItem).Where(i => i.minValue >= scrapValue).ToArray();
|
||||
scrapItemCache.Add(scrapValue, list);
|
||||
internal static IEnumerable<SpawnableItemWithRarity> GetCachedItemList(List<SpawnableItemWithRarity> allMoonItems, int scrapValue) {
|
||||
if (!scrapItemRarityCache.TryGetValue(scrapValue, out var list)){
|
||||
list = allMoonItems.Where(i => i.spawnableItem.minValue >= scrapValue).ToArray();
|
||||
scrapItemRarityCache.Add(scrapValue, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public (NetworkObject itemReference, int scrapValue) CreateItem(RoundManager roundManager, List<SpawnableItemWithRarity> allMoonItems){
|
||||
internal static Item GetRandomItem(IEnumerable<SpawnableItemWithRarity> list) {
|
||||
var weightList = new int[list.Count()];
|
||||
for(var i = 0; i < weightList.Length; ++i) {
|
||||
weightList[i] = list.ElementAt(i).rarity;
|
||||
}
|
||||
|
||||
var randomIndex = RoundManager.Instance.GetRandomWeightedIndex(weightList);
|
||||
return list.ElementAt(randomIndex).spawnableItem;
|
||||
|
||||
}
|
||||
|
||||
internal (NetworkObject itemReference, int scrapValue) CreateItem(RoundManager roundManager, List<SpawnableItemWithRarity> allMoonItems){
|
||||
var anomalyRandom = roundManager.AnomalyRandom;
|
||||
if (anomalyRandom.NextDouble() >= spawnChance) return (null, 0);
|
||||
|
||||
|
@ -35,7 +49,7 @@ namespace DunGenPlus.Components.Scrap {
|
|||
var itemListCount = itemList.Count();
|
||||
if (itemListCount == 0) return (null, 0);
|
||||
|
||||
var randomItem = itemList.ElementAt(anomalyRandom.Next(itemListCount));
|
||||
var randomItem = GetRandomItem(itemList);
|
||||
var randomValue = (int)(anomalyRandom.Next(randomItem.minValue, randomItem.maxValue) * roundManager.scrapValueMultiplier);
|
||||
|
||||
var gameObject = Instantiate(randomItem.spawnPrefab, transform.position, Quaternion.identity, roundManager.spawnedScrapContainer);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue