Exemple #1
0
 public static void Postfix(SeaTreaderSounds __instance, List <BreakableResource.RandomPrefab> __state)
 {
     if (__state != null)
     {
         var breakableResource = __instance.stepChunkPrefab.GetComponent <BreakableResource>();
         breakableResource.defaultPrefab = __state[__state.Count - 1].prefab;
         __state.RemoveAt(__state.Count - 1);
         breakableResource.prefabList = __state;
     }
     return;
 }
Exemple #2
0
 public static void Prefix(SeaTreaderSounds __instance, ref List <BreakableResource.RandomPrefab> __state)
 {
     if (!spawnDataInitialized)  // Needs to add the extra materials to the entropy lists, otherwise they can't come from chunks
     {
         PlayerEntropy component = Player.main.gameObject.GetComponent <PlayerEntropy>();
         if (component != null)
         {
             spawnDataInitialized = true;
             float totalChance = techList.Sum(x => x.chance);
             // Load the prefabs later to avoid conflicts with other mods
             defPrefab = CraftData.GetPrefabForTechType(techList.Last().tech);
             prefabs   = new List <BreakableResource.RandomPrefab>();
             for (int i = 0; i < techList.Length; i++)
             {
                 // Adds the prefab and calculated chance to the list
                 if (i < techList.Length - 1)
                 {
                     prefabs.Add(new BreakableResource.RandomPrefab()
                     {
                         prefab = CraftData.GetPrefabForTechType(techList[i].tech), chance = techList[i].chance / totalChance
                     });
                     totalChance -= techList[i].chance;
                 }
                 // Add the TechType to the entropy lists
                 bool exists = false;
                 for (int j = 0; j < component.randomizers.Count; j++)
                 {
                     if (component.randomizers[j].techType == techList[i].tech)
                     {
                         exists = true;
                     }
                 }
                 if (!exists)
                 {
                     component.randomizers.Add(new PlayerEntropy.TechEntropy()
                     {
                         techType = techList[i].tech, entropy = new FairRandomizer()
                         {
                             entropy = 0
                         }
                     });
                 }
             }
         }
     }
     if (__instance.stepChunkPrefab != null)  // Change the spawn list for the seatreader's chunk
     {
         var breakableResource = __instance.stepChunkPrefab.GetComponent <BreakableResource>();
         __state = breakableResource.prefabList;
         __state.Add(new BreakableResource.RandomPrefab()
         {
             prefab = breakableResource.defaultPrefab
         });
         breakableResource.prefabList    = prefabs;
         breakableResource.defaultPrefab = defPrefab;
     }
     else
     {
         __state = null;
     }
     return;
 }