Esempio n. 1
0
        public static void Postfix(Player __instance)
        {
            foreach (KeyValuePair <TechType, Dictionary <TechType, float> > breakable in Main.config.Breakables)
            {
                foreach (KeyValuePair <TechType, float> pair in breakable.Value)
                {
                    PlayerEntropy             entropy     = __instance.gameObject.GetComponent <PlayerEntropy>();
                    PlayerEntropy.TechEntropy techEntropy = entropy.randomizers.Find((x) => x.techType == pair.Key);

                    if (techEntropy is null)
                    {
                        entropy.randomizers.Add(new PlayerEntropy.TechEntropy()
                        {
                            entropy = new FairRandomizer(), techType = pair.Key
                        });
                    }

                    CoroutineHost.StartCoroutine(GetPrefabForList(breakable.Key, pair.Key, pair.Value));
                }
            }
        }
Esempio n. 2
0
        public GameObject ChooseRandomResource()
        {
            GameObject result = null;

            for (int i = 0; i < resources.Length; i++)
            {
                Drillable.ResourceType resourceType = resources[i];
                if (resourceType.chance >= 1f)
                {
                    result = CraftData.GetPrefabForTechType(resourceType.techType, true);
                    break;
                }
                PlayerEntropy component = Player.main.gameObject.GetComponent <PlayerEntropy>();
                if (component.CheckChance(resourceType.techType, resourceType.chance))
                {
                    result = CraftData.GetPrefabForTechType(resourceType.techType, true);
                    break;
                }
            }
            return(result);
        }
Esempio n. 3
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;
 }