Core Concept:
You want the Blade of Chance to have random enchantments every time it is crafted or initialized.
A D20 roll is used to decide how many enchantments will be applied to the weapon, with a chance for either 0, 1, 2, or 3 enchantments.
Details of the Randomization:
D20 Roll System:
You roll a 20-sided die (using the function Utility.RandomInt(1, 20)), and based on the result of that roll, the number of enchantments to be applied is decided.
You have divided the D20 roll into 4 groups:
Group 1 (3 enchantments): If the roll is 8, the weapon gets 3 random enchantments.
Group 2 (2 enchantments): If the roll is 2, 9, 14, the weapon gets 2 random enchantments.
Group 3 (1 enchantment): If the roll is 1, 3, 4, 5, 6, 10, 11, 18, the weapon gets 1 random enchantment.
Group 4 (no enchantment): If the roll is 7, 12, 13, 15, 16, 17, 19, 20, no enchantments are applied.
Array of Enchantments:
You have created an array of 11 base enchantments (such as Fire, Frost, Shock, Absorb Health, etc.) that the script will choose from.
The script shuffles this array to randomize the selection of enchantments.
Shuffling the Array:
The script randomly rearranges the elements in the array so that the enchantments are not always in the same order.
Applying Enchantments:
Based on the result of the D20 roll, the script applies the appropriate number of enchantments from the shuffled array to the Blade of Chance.
If 1 enchantment is to be applied, the first element of the shuffled array is used.
If 2 enchantments are to be applied, the first two elements of the shuffled array are used, and so on.
Desired Outcome:
The weapon's enchantments will vary each time it is crafted, making each version of the Blade of Chance unique. Depending on the D20 roll:
The player may get a powerful version of the blade with 3 enchantments.
They might get a weaker version with only 1 or 2 enchantments.
Or they might get an unenchanted version (if the roll lands in Group 4).
This randomness aligns with the "chance" theme of the weapon, giving it a different power level and functionality each time it is acquired.