public static RarityType GetRandomRarityRange(RarityType minRarity, RarityType maxRarity) { if (minRarity >= maxRarity) { throw new Exception("minRarity must < maxRarity"); } float normalizedRandom = RandomGen.NextNormalizedFloat(); int i = 0; float weightSum = 0; for (i = 0; i < AllRarities.Length; i++) { if (AllRarities[i] >= minRarity && AllRarities[i] <= maxRarity) { weightSum += rarityTypeToWeight[AllRarities[i]]; } } float weightSumRecip = 1f / weightSum; RarityType output = minRarity; for (i = AllRarities.Length - 1; i >= 0; i--) { if (AllRarities[i] >= minRarity && AllRarities[i] <= maxRarity) { float normalizedWeight = rarityTypeToWeight[AllRarities[i]] * weightSumRecip; if (normalizedRandom <= normalizedWeight) { output = AllRarities[i]; break; } } } return(output); }
private int getAbilityAmountWithStatMods(CombatantModel combatantModel, int abilityAmount, bool isAbilitySpellBased, out bool isCrit) { StatModifiersDeltas statModifiersDeltas = combatantModel.StatModifiersDeltas; int moddedAmount = abilityAmount; isCrit = false; if (isAbilitySpellBased) { moddedAmount += statModifiersDeltas.SpellDamageStatModifiersDelta; isCrit = RandomGen.NextNormalizedFloat() < (combatantModel.SpellCritChanceNormalized + statModifiersDeltas.SpellCritStatModifiersDelta); } else { moddedAmount += statModifiersDeltas.MeleeDamageStatModifiersDelta; isCrit = RandomGen.NextNormalizedFloat() < (combatantModel.MeleeCritChanceNormalized + statModifiersDeltas.MeleeDamageStatModifiersDelta); } if (isCrit) { moddedAmount = (int)((float)moddedAmount * CRITICAL_STRIKE_MULTIPLIER); } return(moddedAmount); }
private Bundle buildBundleFromNPCs(ServerNpcModel[] serverNPCModels) { ItemModel[] rewardItemModels = new ItemModel[serverNPCModels.Length]; for (int n = 0; n < serverNPCModels.Length; n++) { rewardItemModels[n] = serverNPCModels[n].DropTableModel.GetRandomItem(RandomGen.NextNormalizedFloat()); } // TODO: for now award 1 gold and xp on zone completion and multiply by 2 if final zone. int goldAmount = 1; int xpAmount = 1; if (isFinalZone) { goldAmount *= 2; xpAmount *= 2; } CurrencySymbol[] currencySymbols = new CurrencySymbol[] { CurrencySymbol.GC, CurrencySymbol.XP }; int[] currencyValues = new int[] { goldAmount, xpAmount }; return(new Bundle(rewardItemModels, currencySymbols, currencyValues)); }