private GameObject GetBiomePrefab(int chunk, BiomeConfig biome, bool startNode) { PredictableRandom.SetSeed((uint)chunk, 0u); BiomeVariations biomeVariations = BindingManager.Instance.BiomeList.Biomes[biome.BiomeIndex]; if (startNode) { if (Singleton <TournamentRunner> .Instance.TournamentActive.Value && biomeVariations.TournamentBiomes[0] != null) { List <int> value = TournamentChunk.Value; value.Add(chunk); TournamentChunk.SetValueAndForceNotify(value); return(biomeVariations.TournamentBiomes[PredictableRandom.GetNextRangeInt(0, biomeVariations.TournamentBiomes.Length)]); } return(biomeVariations.StartBiomes[PredictableRandom.GetNextRangeInt(0, biomeVariations.StartBiomes.Length)]); } if (chunk % 3 == 0 && Singleton <TournamentRunner> .Instance.TournamentActive.Value && biomeVariations.TournamentBiomes[0] != null) { List <int> value2 = TournamentChunk.Value; value2.Add(chunk); TournamentChunk.SetValueAndForceNotify(value2); return(biomeVariations.TournamentBiomes[PredictableRandom.GetNextRangeInt(0, biomeVariations.TournamentBiomes.Length)]); } return(biomeVariations.InsertBiomes[PredictableRandom.GetNextRangeInt(0, biomeVariations.InsertBiomes.Length)]); }
private void LateUpdate() { if (destroyed) { return; } if (random == null) { random = new PredictableRandom(Seed); } UpdateTracer(); (Vector2 newPos, Vector2 newDir) = Step(transform.position, Direction, Time.deltaTime * Speed * SpeedMultiplier); transform.position = newPos; this.Direction = newDir; if (PathTraceEnabled) { LogPath(); } UpdateTracer(); transform.localEulerAngles = new Vector3(0f, 0f, this.Direction.ToAngle()); }
protected void OnEnable() { int num = Mathf.CeilToInt((float)PlayerData.Instance.MainChunk.Value / 40f) + 7; if (num != m_lastNumChapters) { base.transform.DestroyChildrenWithImmediate <MapRunnerContext>(); PredictableRandom.SetSeed((uint)PlayerData.Instance.LifetimePrestiges.Value, 3737u); Dictionary <string, object> dictionary = new Dictionary <string, object>(); for (int num2 = num - 1; num2 >= 0; num2--) { dictionary.Clear(); dictionary.Add("Chapter", num2); GameObject gameObject = Singleton <PropertyManager> .Instance.InstantiateSetParent(GetChapterPrefab(num2), dictionary, base.transform); gameObject.GetComponent <Canvas>().worldCamera = BindingManager.Instance.MapCamera.GetComponent <Camera>(); } m_lastNumChapters = num; Singleton <PropertyManager> .Instance.InstantiateFromResourcesSetParent("Map/MapBasecamp", Vector3.zero, Quaternion.identity, null, base.transform); Singleton <PropertyManager> .Instance.InstantiateFromResourcesSetParent("Map/Boundaries", Vector3.zero, Quaternion.identity, null, base.transform); GameObject gameObject2 = Singleton <PropertyManager> .Instance.InstantiateFromResourcesSetParent("Map/Boundaries", Vector3.zero, Quaternion.identity, null, base.transform); gameObject2.transform.SetAsFirstSibling(); } }
protected void Start() { MapNodeRunner mapNodeRunner = (MapNodeRunner)Singleton <PropertyManager> .Instance.GetContext("MapNodeRunner", base.transform); PredictableRandom.SetSeed((uint)(mapNodeRunner.NodeIndex + 125), (uint)(PlayerData.Instance.LifetimePrestiges.Value + 125)); int nextRangeInt = PredictableRandom.GetNextRangeInt(0, 3); Singleton <PropertyManager> .Instance.InstantiateSetParent(BindingManager.Instance.BiomeList.Biomes[mapNodeRunner.GetBiomeIndex()].MapNodeProfile[nextRangeInt], Vector3.zero, Quaternion.identity, null, base.transform); }
private GameObject GetChapterPrefab(int chapter) { if (chapter >= BindingManager.Instance.ChapterList.Chapters.Length) { chapter = BindingManager.Instance.ChapterList.Chapters.Length - 1; } ChapterVariations chapterVariations = BindingManager.Instance.ChapterList.Chapters[chapter]; return(chapterVariations.ChapterVariants[PredictableRandom.GetNextRangeInt(0, chapterVariations.ChapterVariants.Length)]); }
public void PredictableRandomNextThrowsOn1And6() { PredictableRandom random = new PredictableRandom(0); Assert.ThrowsException <ArgumentException>(() => random.Next(1, 6)); // TestTools Code UnitTest test = Factory.CreateTest(); TestVariable <PredictableRandom> _random = test.CreateVariable <PredictableRandom>(); test.Arrange(_random, Expr(() => new PredictableRandom(0))); test.Assert.ThrowsExceptionOn <ArgumentException>(Expr(_random, r => r.Next(1, 6))); test.Execute(); }
public void PredictableRandomNextReturns4C() { PredictableRandom random = new PredictableRandom(4); Assert.AreEqual(4, random.Next(1, 6)); // TestTools Code UnitTest test = Factory.CreateTest(); TestVariable <PredictableRandom> _random = test.CreateVariable <PredictableRandom>(); test.Arrange(_random, Expr(() => new PredictableRandom(4))); test.Assert.AreEqual(Const(4), Expr(_random, r => r.Next(1, 6))); test.Execute(); }
private void RandomizeDamageMesh(float scale, int seed) { if (m_verticesOrig == null) { m_verticesOrig = m_damageMesh.mesh.vertices; m_verticesNew = m_damageMesh.mesh.vertices; } for (int i = 0; i < m_verticesOrig.Length; i++) { Vector3 vector = m_verticesOrig[i]; PredictableRandom.SetSeed((uint)(vector.x * 100f * (float)seed), (uint)(vector.y * 100f + vector.z)); m_verticesNew[i] = m_verticesOrig[i] + new Vector3(PredictableRandom.GetNextRangeFloat((0f - scale) * 0.1f, scale * 0.1f), PredictableRandom.GetNextRangeFloat((0f - scale) * 0.1f, scale * 0.1f), 0f); } m_damageMesh.mesh.vertices = m_verticesNew; }
public void DieRollReturns5() { PredictableRandom random = new PredictableRandom(5); Die die = new Die(random, 6); Assert.AreEqual(5, die.Roll()); // TestTools Code UnitTest test = Factory.CreateTest(); TestVariable <PredictableRandom> _random = test.CreateVariable <PredictableRandom>(); TestVariable <Die> _die = test.CreateVariable <Die>(); test.Arrange(_random, Expr(() => new PredictableRandom(5))); test.Arrange(_die, Expr(_random, (r) => new Die(r, 6))); test.Assert.AreEqual(Const(5), Expr(_die, d => d.Roll())); test.Execute(); }
public static A PredictableAllotObject <A>(this List <WeightedObject <A> > weights) { float num = 0f; for (int i = 0; i < weights.Count; i++) { num += weights[i].Weight; } float num2 = PredictableRandom.GetNextRangeFloat(0f, num); for (int j = 0; j < weights.Count; j++) { WeightedObject <A> weightedObject = weights[j]; num2 -= weightedObject.Weight; if (num2 <= 0f) { return(weightedObject.Value); } } return(weights[weights.Count - 1].Value); }
private void UponDespawn() { random = null; CancelInvoke("Kill"); }
public static void GenerateFromConfig(Vector3 pos, int chunk, int prestige, int retryNumber, Transform container, bool bossFight) { int[] array = new int[13] { 50, 70, 50, 30, 20, 10, 5, 3, 0, 0, 0, 0, 0 }; ChunkGeneratingConfig chunkGeneratingConfig = Singleton <EconomyHelpers> .Instance.GetChunkGeneratingConfig(chunk, bossFight); int num = chunkGeneratingConfig.MaxBlocks; if (!bossFight) { Singleton <ChunkRunner> .Instance.BlocksInChunk.SetValueAndForceNotify(num); } else { Singleton <ChunkRunner> .Instance.BlocksInChunk.SetValueAndForceNotify(num - 64); } int num2 = (int)((float)chunkGeneratingConfig.GoldBlockAverage * (PredictableRandom.GetNextRangeFloat(0f, 0.5f) + 0.75f)); Singleton <ChunkRunner> .Instance.GoldBlocks.SetValueAndForceNotify(num2); PredictableRandom.SetSeed((uint)chunk, (uint)(prestige + retryNumber)); List <BlockSpawnPoint> list = new List <BlockSpawnPoint>(); int[] array2 = new int[5]; List <WeightedObject <int[]> > list2 = new List <WeightedObject <int[]> >(); if (bossFight) { list2.AddRange(PersistentSingleton <Economies> .Instance.ChunkMaps[0].ChunkMapClone()); list2 = RemoveSpawnLocationsForBossFight(list2); } else { list2.AddRange(PersistentSingleton <Economies> .Instance.ChunkMaps[chunk % 5].ChunkMapClone()); } int nextRangeInt = PredictableRandom.GetNextRangeInt(chunkGeneratingConfig.FourBlockMin, chunkGeneratingConfig.FourBlockMax + 1); for (int num3 = nextRangeInt; num3 > 0; num3--) { List <WeightedObject <int[]> > list3 = list2.FindAll((WeightedObject <int[]> x) => x.Value[3] >= 4); if (list3.Count <= 0) { break; } int nextRangeInt2 = PredictableRandom.GetNextRangeInt(0, list3.Count); int[] spawnSpot = list3[nextRangeInt2].Value; BlockType blockType = chunkGeneratingConfig.Materials.PredictableAllotObject(); string prefabPath = GetPrefabPath(blockType, 4); if (list.Count <= 0 && bossFight) { spawnSpot = new int[5] { 0, 0, 1, 4, 1 }; blockType = BlockType.Invalid; prefabPath = ((!Singleton <DrJellyRunner> .Instance.DrJellyBattle.Value) ? "Blocks/BigBossCube_4x4" : "Blocks/DrJelly"); } Vector3 coordinates = new Vector3(spawnSpot[0], spawnSpot[1] + 2, spawnSpot[2]) + pos; list.Add(new BlockSpawnPoint(blockType, prefabPath, coordinates)); int i; for (i = -4; i <= 3; i++) { int j; for (j = -4; j <= 3; j++) { int num4 = list2.FindIndex((WeightedObject <int[]> x) => x.Value[0] == spawnSpot[0] + i && x.Value[2] == spawnSpot[2] + j); if (num4 == -1) { continue; } WeightedObject <int[]> weightedObject = list2[num4]; if (-2 <= i && i <= 1 && -2 <= j && j <= 1) { weightedObject.Value[1] += 4; weightedObject.Weight = array[weightedObject.Value[1]]; } if (i == 0 && j == 0) { if (weightedObject.Value[1] > 4) { weightedObject.Value[3] = 2; } } else if (-1 <= i && i <= 1 && -1 <= j && j <= 1) { weightedObject.Value[3] = 2; } else if (-2 <= i && i <= 2 && -2 <= j && j <= 2) { weightedObject.Value[3] = 1; } else { if (weightedObject.Value[3] == 4) { weightedObject.Value[3] = 2; } if (-3 <= i && i <= 2 && -3 <= j && j <= 2) { weightedObject.Weight = array[1]; } else { weightedObject.Weight = array[0]; } } list2[num4] = weightedObject; } } num -= 64; } int nextRangeInt3 = PredictableRandom.GetNextRangeInt(chunkGeneratingConfig.TwoBlockMin, chunkGeneratingConfig.TwoBlockMax + 1); float num5 = (float)(nextRangeInt3 * 8) / (float)num; int num6 = Mathf.RoundToInt((float)num2 * num5 / 9f); for (int num7 = 0; num7 < nextRangeInt3; num7++) { array2[(int)chunkGeneratingConfig.Materials.PredictableAllotObject()]++; } int num8 = 0; if (PredictableRandom.GetNextRangeFloat(0f, 1f) < chunkGeneratingConfig.TNTChance) { num8 = PredictableRandom.GetNextRangeInt(chunkGeneratingConfig.TNTMin, chunkGeneratingConfig.TNTMax + 1); } nextRangeInt3 += num8; for (int num9 = nextRangeInt3; num9 > 0; num9--) { List <WeightedObject <int[]> > list4 = list2.FindAll((WeightedObject <int[]> x) => x.Value[3] >= 2); if (list4.Count <= 0) { break; } int[] spawnSpot2 = list4.PredictableAllotObject(); BlockType blockType2 = BlockType.Gold; for (int num10 = array2.Length - 1; num10 >= 0; num10--) { if (num8 > 0) { blockType2 = BlockType.TNT; num8--; break; } if (num6 > 0) { blockType2 = BlockType.Gold; num6--; num2 -= 9; break; } if (array2[num10] > 0) { blockType2 = (BlockType)num10; array2[num10]--; break; } } string prefabPath2 = GetPrefabPath(blockType2, 2); Vector3 coordinates2 = new Vector3(spawnSpot2[0], spawnSpot2[1] + 1, spawnSpot2[2]) + pos; list.Add(new BlockSpawnPoint(blockType2, prefabPath2, coordinates2)); int k; for (k = -2; k <= 1; k++) { int l; for (l = -2; l <= 1; l++) { int num11 = list2.FindIndex((WeightedObject <int[]> x) => x.Value[0] == spawnSpot2[0] + k && x.Value[2] == spawnSpot2[2] + l); if (num11 == -1) { continue; } WeightedObject <int[]> weightedObject2 = list2[num11]; if (-1 <= k && k <= 0 && -1 <= l && l <= 0) { weightedObject2.Value[1] += 2; } if (-1 <= k && k <= 1 && -1 <= l && l <= 1) { if (weightedObject2.Value[1] >= 10) { weightedObject2.Value[3] = 0; } else { weightedObject2.Value[3] = 1; if (k == 0 && l == 0) { weightedObject2.Value[3] = 2; } } } weightedObject2.Weight = array[weightedObject2.Value[1]]; list2[num11] = weightedObject2; } } num -= 8; } int num12 = 0; if (PredictableRandom.GetNextRangeFloat(0f, 1f) < chunkGeneratingConfig.DiamondChance) { num12 = PredictableRandom.GetNextRangeInt(chunkGeneratingConfig.DiamondMin, chunkGeneratingConfig.DiamondMax + 1); } for (int num13 = 0; num13 < num - num12 - num2; num13++) { array2[(int)chunkGeneratingConfig.Materials.PredictableAllotObject()]++; } List <WeightedObject <int[]> > list5 = list2.FindAll((WeightedObject <int[]> x) => x.Value[3] >= 1); for (int num14 = num; num14 > 0; num14--) { if (list5.Count > 0) { int[] spawnSpot3 = list5.PredictableAllotObject(); BlockType type = BlockType.Diamond; for (int num15 = array2.Length - 1; num15 >= 0; num15--) { if (num12 > 0) { type = BlockType.Diamond; num12--; break; } if (num2 > 0) { type = BlockType.Gold; num2--; break; } if (array2[num15] > 0) { type = (BlockType)num15; array2[num15]--; break; } } Vector3 coordinates3 = new Vector3((float)spawnSpot3[0] + 0.5f, (float)spawnSpot3[1] + 0.5f, (float)spawnSpot3[2] + 0.5f) + pos; list.Add(new BlockSpawnPoint(type, string.Empty, coordinates3)); int m; for (m = -1; m <= 1; m++) { int n; for (n = -1; n <= 1; n++) { WeightedObject <int[]> weightedObject3 = list5.Find((WeightedObject <int[]> x) => x.Value[0] == spawnSpot3[0] + m && x.Value[2] == spawnSpot3[2] + n); if (weightedObject3 != null) { if (m == 0 && n == 0) { weightedObject3.Value[1]++; } if (weightedObject3.Value[1] >= 10) { list5.Remove(weightedObject3); } else { weightedObject3.Weight = array[weightedObject3.Value[1]]; } } } } } } List <BlockSpawnPoint> blocks = list.FindAll((BlockSpawnPoint x) => x.PrefabPath == string.Empty); for (int num16 = -5; num16 <= 4; num16++) { for (int num17 = -7; num17 <= 8; num17++) { List <BlockSpawnPoint> blocksNearCoordinates = GetBlocksNearCoordinates(blocks, (float)num16 + 0.5f + pos.x, (float)num17 + 0.5f + pos.z); BlockType blockType3 = BlockType.Invalid; if (blocksNearCoordinates.Count <= 0) { continue; } for (int num18 = blocksNearCoordinates.Count - 1; num18 >= 0; num18--) { string empty = string.Empty; BlockType num19 = blockType3; BlockSpawnPoint blockSpawnPoint = blocksNearCoordinates[num18]; if (num19 != blockSpawnPoint.Type) { BlockSpawnPoint blockSpawnPoint2 = blocksNearCoordinates[num18]; empty = GetPrefabPath(blockSpawnPoint2.Type, 1, BlockAlignment.Top); } else if (num18 - 1 >= 0) { BlockSpawnPoint blockSpawnPoint3 = blocksNearCoordinates[num18]; BlockType type2 = blockSpawnPoint3.Type; BlockSpawnPoint blockSpawnPoint4 = blocksNearCoordinates[num18 - 1]; if (type2 == blockSpawnPoint4.Type) { BlockSpawnPoint blockSpawnPoint5 = blocksNearCoordinates[num18]; empty = GetPrefabPath(blockSpawnPoint5.Type, 1, BlockAlignment.Middle); } else { BlockSpawnPoint blockSpawnPoint6 = blocksNearCoordinates[num18]; empty = GetPrefabPath(blockSpawnPoint6.Type, 1, BlockAlignment.Bottom); } } else { BlockSpawnPoint blockSpawnPoint7 = blocksNearCoordinates[num18]; empty = GetPrefabPath(blockSpawnPoint7.Type, 1, BlockAlignment.Bottom); } BlockSpawnPoint blockSpawnPoint8 = blocksNearCoordinates[num18]; blockType3 = blockSpawnPoint8.Type; List <BlockSpawnPoint> list6 = list; int index = list.IndexOf(blocksNearCoordinates[num18]); BlockSpawnPoint blockSpawnPoint9 = blocksNearCoordinates[num18]; BlockType type3 = blockSpawnPoint9.Type; string prefabPath3 = empty; BlockSpawnPoint blockSpawnPoint10 = blocksNearCoordinates[num18]; list6[index] = new BlockSpawnPoint(type3, prefabPath3, blockSpawnPoint10.Coordinates); } } } for (int num20 = 0; num20 < list.Count; num20++) { EntityPoolManager instance = Singleton <EntityPoolManager> .Instance; BlockSpawnPoint blockSpawnPoint11 = list[num20]; GameObject orCreateGameObject = instance.GetOrCreateGameObject(blockSpawnPoint11.PrefabPath); BlockController component = orCreateGameObject.GetComponent <BlockController>(); if (component != null) { BlockController blockController = component; BlockSpawnPoint blockSpawnPoint12 = list[num20]; blockController.Init(blockSpawnPoint12.Type); } else { BossBlockController component2 = orCreateGameObject.GetComponent <BossBlockController>(); if (component2 != null) { component2.Init(); } } Transform transform = orCreateGameObject.transform; BlockSpawnPoint blockSpawnPoint13 = list[num20]; transform.position = blockSpawnPoint13.Coordinates; orCreateGameObject.transform.rotation = Quaternion.identity; if (orCreateGameObject.transform.parent == null) { orCreateGameObject.transform.SetParent(container, worldPositionStays: true); } } }