### Spawn Obstacle using ProbabilityList - C# Source: https://docs.rngneeds.com/documentation/testing-outcomes Demonstrates how to use the `ProbabilityList` to pick a random obstacle and spawn it. This example assumes an `ObstacleSpawner` MonoBehaviour and requires the RNGNeeds library for `ProbabilityList` and `TryPickValue` functionality. ```csharp public class ObstacleSpawner : MonoBehaviour { public ProbabilityList obstacles; public void SpawnObstacle() { if (obstacles.TryPickValue(out var obstacle)) { // Spawn Obstacle } } } ``` -------------------------------- ### C# - TryPickValueFrom Method Example Source: https://docs.rngneeds.com/documentation/nesting-lists Demonstrates using the TryPickValueFrom method in C# to select a single value from a list by index or name. It shows how to check if the list was found and if a value was successfully picked, with considerations for value types. ```csharp var result = myCollection.TryPickValueFrom(0, out var value); result.ListFound // Indicates whether the list was found result.ValuePicked // Indicates whether the value was picked if (myCollection.TryPickValueFrom("My List", out var value).ValuePicked) { // Value was picked, therefore list was found and not empty } else { // Value was not picked - the selection was unsuccessful // could also mean the list was not found or was empty } ``` -------------------------------- ### Access Pick History Details - C# Source: https://docs.rngneeds.com/documentation/pick-history Demonstrates how to access the PickHistory object and retrieve the list of HistoryEntries. It shows how to get the latest entry and log its index and timestamp. This requires an initialized ProbabilityList object. ```csharp // Access the PickHistory object PickHistory pickHistory = myProbabilityList.PickHistory; // The History property contains the List of HistoryEntries List historyEntries = pickHistory.History; HistoryEntry latestEntry = historyEntries[0]; Debug.Log($"Last Picked Index was {latestEntry.Index}, picked at {latestEntry.Time}"); ``` -------------------------------- ### Deplete Resource Deposit by Mining Attempts (C#) Source: https://docs.rngneeds.com/guides/guide-depletable-list-examples This C# code snippet demonstrates how to deplete a resource deposit after a fixed number of mining attempts. It increments a mining counter with each call to MineDeposit() and disables the deposit when maxMiningAttempts is reached. This example uses the RNGNeeds library for probability-based resource picking. ```csharp using System.Collections.Generic; using RNGNeeds; using UnityEngine; public class ResourceDeposit : MonoBehaviour { public ProbabilityList resourceDeposit; public int miningAttempts = 0; public int maxMiningAttempts = 5; public List MineDeposit() { miningAttempts++; if (miningAttempts >= maxMiningAttempts) { // Here, we would typically disable the depleted resource deposit // For example, disable this GameObject or make it non-interactable } return resourceDeposit.PickValues(); } } ``` -------------------------------- ### Define Probability List for Die Roll (C#) Source: https://docs.rngneeds.com/user-guide/getting-started This C# code snippet demonstrates how to define a `ScriptableObject` in Unity that includes a `ProbabilityList` for creating a custom die. It shows the necessary using directives and the structure for adding items and their probabilities. ```csharp using UnityEngine; using RNGNeeds; [CreateAssetMenu(fileName = "dXX", menuName = "My Die")] public class Die : ScriptableObject { public ProbabilityList die; } ``` -------------------------------- ### Weapon Component Initialization (C#) Source: https://docs.rngneeds.com/guides/guide-probability-influence Initializes the critical strike probability list by clearing existing items, adding 'true' and 'false' outcomes with their respective probabilities and influence settings. It configures the influence provider and spread for both outcomes, including inverting influence for the 'false' outcome. ```csharp private void Start() { criticalStrike.ClearList(); var trueItem = criticalStrike.AddItem(true, baseCriticalStrikeChance); var falseItem = criticalStrike.AddItem(false); trueItem.InfluenceProvider = this; trueItem.InfluenceSpread = baseInfluenceSpread; falseItem.InfluenceProvider = this; falseItem.InfluenceSpread = new Vector2(1f - baseInfluenceSpread.y, 1f - baseInfluenceSpread.x); falseItem.InvertInfluence = true; } ``` -------------------------------- ### Iterating Over History - C# Example Source: https://docs.rngneeds.com/documentation/pick-history This C# code snippet demonstrates how to draw values from the history of a ProbabilityList. It includes populating the history, maintaining a draw index, and retrieving a specified count of values from the history. The `DrawFromHistory` method ensures that values are drawn sequentially without repetition. ```csharp public ProbabilityList myProbabilityList; // First, pick values to populate the history myProbabilityList.PickValues(1000); private int historyDrawIndex = 0; // Counter to keep track of where we left off // A method to draw a specified range of values from the history public List DrawFromHistory(int countToDraw) { List drawnValues = new List(); int remainingHistory = myProbabilityList.PickHistory.History.Count - historyDrawIndex; countToDraw = Mathf.Min(countToDraw, remainingHistory); for (int i = 0; i < countToDraw; i++) { var drawnIndex = myProbabilityList.PickHistory.History[historyDrawIndex + i].Index; drawnValues.Add(myProbabilityList.GetProbabilityItem(drawnIndex).Value); } historyDrawIndex += countToDraw; return drawnValues; } ``` -------------------------------- ### Get List - C# Source: https://docs.rngneeds.com/documentation/change-log Shows the updated `GetList` method signature in `PLCollection`. It now returns the `ProbabilityList` object directly, simplifying access compared to the previous `IProbabilityList` interface return type. ```csharp ProbabilityList GetList(int index) ``` -------------------------------- ### Dynamic Monster Spawning Based on Music Volume (C#) Source: https://docs.rngneeds.com/guides/guide-probability-influence This C# code implements a mechanic for dynamic monster spawning influenced by music volume. It uses a ProbabilityList and an Audio Manager implementing IProbabilityInfluenceProvider to increase spawn rates as music volume increases, creating a more intense gameplay experience. ```csharp private void Start() { InvokeRepeating(nameof(SpawnMonster), 1f, 1f); } public void SpawnMonster() { if (shouldSpawnMonster.PickValue()) { // Code to spawn the monster } } ``` -------------------------------- ### Checking Hacking Success with PickValue() (C#) Source: https://docs.rngneeds.com/guides/guide-probability-influence This C# code snippet demonstrates how to use the .PickValue() method from the RNGNeeds library to determine the outcome of a player's hacking attempt. It evaluates the success based on dynamically influenced probabilities, reflecting the player's current skill level. ```csharp if(hackingSuccess.PickValue()) { // Successful system breach } ``` -------------------------------- ### Create and Roll a Die with RNGNeeds in C# Source: https://docs.rngneeds.com/user-guide/getting-started Defines a ScriptableObject 'Die' that uses RNGNeeds' ProbabilityList to store integer values and their associated probabilities. The 'Roll' method returns a randomly selected integer based on the defined distribution. ```csharp using UnityEngine; using RNGNeeds; [CreateAssetMenu(fileName = "DXX", menuName = "My Die")] public class Die : ScriptableObject { public ProbabilityList die; public int Roll() { return die.PickValue(); } } ``` -------------------------------- ### Implement IProbabilityItemColorProvider and InfoProvider (C#) Source: https://docs.rngneeds.com/documentation/customizing-lists Illustrates implementing both IProbabilityItemColorProvider and IProbabilityItemInfoProvider interfaces within a ScriptableObject. This allows for custom colors and text information to be displayed for item rarities. ```csharp using UnityEngine; [CreateAssetMenu(fileName = "New Item Rarity", menuName = "RNGNeeds/Treasure Chest/Item Rarity")] public class ItemRarity : ScriptableObject, IProbabilityItemColorProvider, IProbabilityItemInfoProvider { public string title; public Color rarityColor; public Color ItemColor => rarityColor; public string ItemInfo => title; } ``` -------------------------------- ### Implement IProbabilityItemInfoProvider for Custom Info (C#) Source: https://docs.rngneeds.com/documentation/customizing-lists Demonstrates implementing the IProbabilityItemInfoProvider interface to supply custom string information for a serializable class. This custom info is then displayed in the Probability List. ```csharp using UnityEngine; [System.Serializable] public class MyCustomType : IProbabilityItemInfoProvider { public string ItemInfo => customInfo; public string customInfo; public Vector3 somePosition; public bool someBool; } ``` -------------------------------- ### Implement IProbabilityItemInfoProvider with Vector3 Output (C#) Source: https://docs.rngneeds.com/documentation/customizing-lists Shows an alternative implementation of IProbabilityItemInfoProvider where the 'ItemInfo' property returns the string representation of a Vector3 field. This allows dynamic display of positional data. ```csharp using UnityEngine; [System.Serializable] public class MyCustomType : IProbabilityItemInfoProvider { public string ItemInfo => somePosition.ToString(); public Vector3 somePosition; public bool someBool; } ``` -------------------------------- ### Warm-up HistoryEntry Pool - C# Source: https://docs.rngneeds.com/documentation/pick-history Demonstrates how to pre-populate the HistoryEntry object pool for immediate efficiency gains. This method ensures that a sufficient number of HistoryEntry objects are available for reuse, minimizing memory allocations during subsequent operations. ```csharp RNGNeedsCore.WarmupHistoryEntries(10000); ``` -------------------------------- ### Declare PLCollection in C# for Unity Source: https://docs.rngneeds.com/documentation/nesting-lists Declare a PLCollection in your MonoBehaviour or ScriptableObject script to start organizing lists. This is similar to declaring a standard ProbabilityList. ```csharp using UnityEngine; using RNGNeeds; public class MyScript : MonoBehaviour { public PLCollection myCollection; } ``` -------------------------------- ### Conditionally Implement Provider Interfaces in Editor (C#) Source: https://docs.rngneeds.com/documentation/customizing-lists Demonstrates how to conditionally implement IProbabilityItemColorProvider and IProbabilityItemInfoProvider only in the Unity Editor using preprocessor directives. This prevents these editor-specific interfaces from being included in runtime builds. ```csharp using UnityEngine; public class MyComponent : MonoBehaviour #if UNITY_EDITOR , IProbabilityItemColorProvider, IProbabilityItemInfoProvider #endif { #if UNITY_EDITOR public Color ItemColor => customColor; public string ItemInfo => customInfo; public string customInfo; public Color customColor; #endif // runtime relevant code } ``` -------------------------------- ### Set Item Influence Spread - C# Source: https://docs.rngneeds.com/documentation/change-log Provides an example of `SetItemInfluenceSpread`, a convenience method for `ProbabilityList`. This method allows setting the influence spread for a specific item using its index, controlling the range of probability adjustments. ```csharp .SetItemInfluenceSpread(int index, Vector2 spread) ``` -------------------------------- ### Access History Entries by Reference - C# Source: https://docs.rngneeds.com/documentation/pick-history Illustrates accessing the latest history entries, either individually or as a list, by reference to internal lists for efficiency. It also shows methods designed to populate a provided list with history records. ```csharp // Methods that return a reference to a private list HistoryEntry latestEntryRef = myProbabilityList.PickHistory.LatestEntry; List latestEntriesRef = myProbabilityList.PickHistory.GetLatestEntries(5); // Methods designed to fill a provided list List latestPicksFill = new List(); myProbabilityList.PickHistory.GetLatestPicks(latestPicksFill, 5); List latestEntriesFill = new List(); myProbabilityList.PickHistory.GetLatestEntries(latestEntriesFill, 5); ``` -------------------------------- ### Monster Spawner Script - C# Source: https://docs.rngneeds.com/samples/monster-spawner The MonsterSpawner script controls the dynamic spawning of monsters. It uses Probability Lists to pick monster types, levels, and spawn locations, then instantiates the monster prefab and sets its initial stats based on player proximity and level. It requires Monster, SpawnLocation, and MonsterController scripts. ```csharp public class MonsterSpawner : MonoBehaviour { // non-relevant code was omitted public Transform playerLocation; public ProbabilityList monsterTypes; public ProbabilityList monsterLevels; public ProbabilityList spawnLocations; private void Start() { InvokeRepeating(nameof(SpawnMonster), .5f, .5f); } public void SpawnMonster() { Monster monster = monsterTypes.PickValue(); if (spawnLocations.TryPickValue(out var location) == false) return; var monsterObject = location.Spawn(monster.monsterPrefab); var monsterController = monsterObject.GetComponent(); monsterController.SetStatsByLevel(monsterLevels.PickValue(), playerLocation); } } ``` -------------------------------- ### Setting a Custom Seed Value (C#) Source: https://docs.rngneeds.com/documentation/seeding-options This C# example demonstrates how to set a custom seed value for a ProbabilityList in RNGNeeds after enabling the 'Keep Seed' option. This allows for precise control over the random number sequence. ```csharp myProbabilityList.KeepSeed = true; myProbabilityList.Seed = 1337; ``` -------------------------------- ### Declare ProbabilityList in C# Source: https://docs.rngneeds.com/guides/guide-probability-influence This C# snippet demonstrates how to declare a ProbabilityList of booleans, which can be used to set base probabilities for game events like hacking success. It's a fundamental step in utilizing dynamic probability. ```csharp public ProbabilityList hackingSuccess; ``` -------------------------------- ### Coder-Controlled Dice Roll Selection (C#) Source: https://docs.rngneeds.com/documentation/selecting-values Demonstrates how a coder can override the default setup of a ProbabilityList for dice rolls. This includes picking a specific number of values, manually setting pick counts, or specifying a range for the number of values to pick. ```csharp public ProbabilityList dice; // This will pick only one value int sumOfRolls = dice.PickValues(1).Sum(); // and is equivalent to this int result = dice.PickValue(); // This will configure the list to randomly select 2 to 4 values dice.LinkPickCounts = false; dice.PickCountMin = 2; dice.PickCountMax = 4; int sumOfRolls = dice.PickValues().Sum(); // and is equivalent to this, without the need to configure pick counts manually int sumOfRolls = dice.PickValues(2, 4).Sum(); ``` -------------------------------- ### ProbabilityList Convenience Methods (C#) Source: https://docs.rngneeds.com/documentation/change-log Provides methods to efficiently manage the enabled and locked states of all items within a ProbabilityList. These methods allow bulk updates, simplifying the process of configuring multiple items at once. They are part of the ProbabilityList class. ```csharp public void SetAllItemsEnabled(bool enabled) public void SetAllItemsLocked(bool locked) ``` -------------------------------- ### Select Values from Probability List (C#) Source: https://docs.rngneeds.com/documentation/selecting-values Initiates the value selection process from a ProbabilityList. The selection is based on the list's current setup, including pick counts, selection method, and repeat prevention. This is the default method for picking values. ```csharp public ProbabilityList myProbabilityList; List results = myProbabilityList.PickValues(); ``` -------------------------------- ### Weapon Component Fields and Properties (C#) Source: https://docs.rngneeds.com/guides/guide-probability-influence Defines the core fields and properties for the Weapon component, including damage, critical strike chance, durability, and proficiency. It also implements IProbabilityInfluenceProvider to dynamically calculate and provide influence values for critical strikes. ```csharp using RNGNeeds; using StarphaseTools.Core; using UnityEngine; public class Weapon : MonoBehaviour, IProbabilityInfluenceProvider { [Header("Weapon Setup")] public float damage; public float criticalMultiplier; [Range(0f, 1f)] public float baseCriticalStrikeChance; public Vector2 baseInfluenceSpread; [Header("Weapon Stats")] [Range(0f, 1f)] public float durability = 1f; [Range(0f, 1f)] public float weaponProficiency; public ProbabilityList criticalStrike; private float Effectiveness => weaponProficiency * durability; // Interface Implementation public string InfluenceInfo => $"Effectiveness = Proficiency {weaponProficiency:F4} x Durability {durability:F3}\n=> Current: {Effectiveness:F2} = {ProbabilityInfluence:F2} Influence."; public float ProbabilityInfluence => Effectiveness.Remap(0f, 1f, -1f, 1f); } ``` -------------------------------- ### Retrieve Latest Picks and Values - C# Source: https://docs.rngneeds.com/documentation/pick-history Shows how to retrieve the latest picked index, a list of the latest picks, and the corresponding values directly from the Probability List or its PickHistory. This offers simplified access to recent selection data. ```csharp int latestIndex = myProbabilityList.PickHistory.LatestIndex; List latestIndices = myProbabilityList.PickHistory.GetLatestPicks(5); // The same data can also be accessed directly from the Probability List int latestIndexDirect = myProbabilityList.LastPickedIndex; List latestIndicesDirect = myProbabilityList.LastPickedIndices; // The Probability List further simplifies the process by mapping indices to values automatically string latestValue = myProbabilityList.LastPickedValue; List latestValues = myProbabilityList.LastPickedValues; ``` -------------------------------- ### Implement Custom Seed Provider (C#) Source: https://docs.rngneeds.com/documentation/seeding-options This C# code demonstrates how to create a custom seed provider by implementing the ISeedProvider interface. It defines a NewSeed property that returns a custom generated seed based on the current UTC time ticks. This allows for more control over the seeding mechanics. ```csharp using System; using RNGNeeds; public class MySeedProvider : ISeedProvider { public uint NewSeed { get { // Replace this with your custom seed generation logic return (uint)(DateTime.UtcNow.Ticks % uint.MaxValue); } } } ``` -------------------------------- ### Select Values Directly from PLCollection List (C#) Source: https://docs.rngneeds.com/documentation/nesting-lists Shows how to retrieve a list from a PLCollection by index or name and then select a value from that individual list. Assumes the existence of a standard Probability List class with a PickValue method. ```csharp // Retrieving list from collection var list = myCollection.GetList(0); // Get list at index 0 if (myCollection.GetList("MyList", out var list)) // Get list by name "MyList" { var value = list.PickValue(); } ``` -------------------------------- ### Weapon Component Attack Logic (C#) Source: https://docs.rngneeds.com/guides/guide-probability-influence Implements the Attack method for the Weapon component. It uses the criticalStrike probability list to determine if an attack is critical. Based on the outcome, it adjusts weapon proficiency and durability, returning the calculated damage and a boolean indicating if the hit was critical. ```csharp public (float damage, bool critical) Attack() { if (criticalStrike.PickValue()) { weaponProficiency += 0.001f; // Slightly increase proficiency with each attack durability -= 0.005f; // Decrease durability with each critical hit return (damage * criticalMultiplier, true); // Return increased damage for critical hits } weaponProficiency += 0.0001f; // Minimal proficiency increase for normal hits return (damage, false); // Return normal damage for non-critical hits } ``` -------------------------------- ### Play Randomized AudioClip with ProbabilityList in Unity C# Source: https://docs.rngneeds.com/samples/random-audio Demonstrates how to use a ProbabilityList of AudioClips to randomly select and play an audio clip using an AudioSource component in Unity. This is useful for randomizing unit responses, dialogue, or ambient sounds. Ensure an AudioClip is assigned to the randomAudio ProbabilityList and an AudioSource component is attached to the GameObject. ```csharp public ProbabilityList randomAudio; if(audioSource.isPlaying == false) audioSource.PlayOneShot(randomAudio.PickValue()); ``` -------------------------------- ### Player Manager Scriptable Object for Probability Influence (C#) Source: https://docs.rngneeds.com/guides/guide-probability-influence This C# script defines a Scriptable Object that acts as a probability influence provider. It allows game designers to set a hacking skill level, which then influences a probability range from -1 to 1. The InfluenceInfo property provides a human-readable explanation for designers. ```csharp using RNGNeeds; using StarphaseTools.Core; using UnityEngine; [CreateAssetMenu(fileName = "Player Manager", menuName = "RNGNeeds/Probability Influence Guides/Player Manager")] public class PlayerManager : ScriptableObject, IProbabilityInfluenceProvider { [Range(1, 30)] public int hackingSkillLevel; public float ProbabilityInfluence => ((float)hackingSkillLevel).Remap(1, 30, -1, 1); public string InfluenceInfo => $"Increase by Hacking Skill Level\nCurrent: {hackingSkillLevel} LVL = {ProbabilityInfluence:F2} Influence"; } ``` -------------------------------- ### Iterate ProbabilityList with foreach (C#) Source: https://docs.rngneeds.com/documentation/change-log Illustrates how to use a `foreach` loop to iterate directly over a `ProbabilityList` instance, made possible by its `IEnumerable` implementation. This simplifies accessing each item within the list. ```csharp using System.Collections.Generic; // Assuming 'myProbabilityList' is an instance of ProbabilityList foreach (var item in myProbabilityList) { // Process each item in the list // For example, print the item's value Console.WriteLine(item); } ``` -------------------------------- ### Deplete Resource Deposit by Resource Availability (C#) Source: https://docs.rngneeds.com/guides/guide-depletable-list-examples This C# code snippet shows how to disable a resource deposit when a specific resource within it becomes depleted. It checks the 'IsDepleted' status of a designated resource after each mining attempt and disables the deposit if the condition is met. This allows game designers to control depletion based on individual item availability using the RNGNeeds library. ```csharp public Resource checkForDepletedResource; public ProbabilityList resourceDeposit; public List MineDeposit() { var minedResources = resourceDeposit.PickValues(); if (resourceDeposit.TryGetProbabilityItem(checkForDepletedResource, out var depositResource)) { if(depositResource.IsDepleted) { // disable the depleted resource deposit } } return minedResources; } ``` -------------------------------- ### Ensure Correct Namespace for Script Compilation Source: https://docs.rngneeds.com/user-guide/faq If your scripts fail to compile after following the documentation, it's likely due to missing namespaces in code snippets. Ensure you include the necessary 'using RNGNeeds;' directive at the beginning of your script to resolve compilation issues. ```csharp using RNGNeeds; // Your script code here... ```