chore: note that random element functions could return undefined (#1910)
We should be explicit about the fact that we expect the arrays to not be empty. Reviewed-on: #1910 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
parent
ab9cc685eb
commit
1cf7b41d3f
@ -17,7 +17,7 @@ export const activateRandomModController: RequestHandler = async (req, res) => {
|
|||||||
ItemCount: -1
|
ItemCount: -1
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
const rivenType = getRandomElement(rivenRawToRealWeighted[request.ItemType]);
|
const rivenType = getRandomElement(rivenRawToRealWeighted[request.ItemType])!;
|
||||||
const fingerprint = createVeiledRivenFingerprint(ExportUpgrades[rivenType]);
|
const fingerprint = createVeiledRivenFingerprint(ExportUpgrades[rivenType]);
|
||||||
const upgradeIndex =
|
const upgradeIndex =
|
||||||
inventory.Upgrades.push({
|
inventory.Upgrades.push({
|
||||||
|
@ -28,7 +28,7 @@ export const artifactTransmutationController: RequestHandler = async (req, res)
|
|||||||
});
|
});
|
||||||
|
|
||||||
const rawRivenType = getRandomRawRivenType();
|
const rawRivenType = getRandomRawRivenType();
|
||||||
const rivenType = getRandomElement(rivenRawToRealWeighted[rawRivenType]);
|
const rivenType = getRandomElement(rivenRawToRealWeighted[rawRivenType])!;
|
||||||
const fingerprint = createVeiledRivenFingerprint(ExportUpgrades[rivenType]);
|
const fingerprint = createVeiledRivenFingerprint(ExportUpgrades[rivenType]);
|
||||||
|
|
||||||
const upgradeIndex =
|
const upgradeIndex =
|
||||||
|
@ -141,7 +141,7 @@ const getModularWeaponSale = (
|
|||||||
getItemType: (parts: string[]) => string
|
getItemType: (parts: string[]) => string
|
||||||
): IModularWeaponSaleInfo => {
|
): IModularWeaponSaleInfo => {
|
||||||
const rng = new CRng(day);
|
const rng = new CRng(day);
|
||||||
const parts = partTypes.map(partType => rng.randomElement(partTypeToParts[partType]));
|
const parts = partTypes.map(partType => rng.randomElement(partTypeToParts[partType])!);
|
||||||
let partsCost = 0;
|
let partsCost = 0;
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
partsCost += ExportWeapons[part].premiumPrice!;
|
partsCost += ExportWeapons[part].premiumPrice!;
|
||||||
|
@ -31,7 +31,7 @@ export interface IFingerprintStat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const createVeiledRivenFingerprint = (meta: IUpgrade): IVeiledRivenFingerprint => {
|
export const createVeiledRivenFingerprint = (meta: IUpgrade): IVeiledRivenFingerprint => {
|
||||||
const challenge = getRandomElement(meta.availableChallenges!);
|
const challenge = getRandomElement(meta.availableChallenges!)!;
|
||||||
const fingerprintChallenge: IRivenChallenge = {
|
const fingerprintChallenge: IRivenChallenge = {
|
||||||
Type: challenge.fullName,
|
Type: challenge.fullName,
|
||||||
Progress: 0,
|
Progress: 0,
|
||||||
@ -54,11 +54,11 @@ export const createVeiledRivenFingerprint = (meta: IUpgrade): IVeiledRivenFinger
|
|||||||
|
|
||||||
export const createUnveiledRivenFingerprint = (meta: IUpgrade): IUnveiledRivenFingerprint => {
|
export const createUnveiledRivenFingerprint = (meta: IUpgrade): IUnveiledRivenFingerprint => {
|
||||||
const fingerprint: IUnveiledRivenFingerprint = {
|
const fingerprint: IUnveiledRivenFingerprint = {
|
||||||
compat: getRandomElement(meta.compatibleItems!),
|
compat: getRandomElement(meta.compatibleItems!)!,
|
||||||
lim: 0,
|
lim: 0,
|
||||||
lvl: 0,
|
lvl: 0,
|
||||||
lvlReq: getRandomInt(8, 16),
|
lvlReq: getRandomInt(8, 16),
|
||||||
pol: getRandomElement(["AP_ATTACK", "AP_DEFENSE", "AP_TACTIC"]),
|
pol: getRandomElement(["AP_ATTACK", "AP_DEFENSE", "AP_TACTIC"])!,
|
||||||
buffs: [],
|
buffs: [],
|
||||||
curses: []
|
curses: []
|
||||||
};
|
};
|
||||||
@ -81,7 +81,7 @@ export const randomiseRivenStats = (meta: IUpgrade, fingerprint: IUnveiledRivenF
|
|||||||
if (Math.random() < 0.5) {
|
if (Math.random() < 0.5) {
|
||||||
const entry = getRandomElement(
|
const entry = getRandomElement(
|
||||||
meta.upgradeEntries!.filter(x => x.canBeCurse && !fingerprint.buffs.find(y => y.Tag == x.tag))
|
meta.upgradeEntries!.filter(x => x.canBeCurse && !fingerprint.buffs.find(y => y.Tag == x.tag))
|
||||||
);
|
)!;
|
||||||
fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
|
fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1798,7 +1798,7 @@ export const addKeyChainItems = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const createLibraryDailyTask = (): ILibraryDailyTaskInfo => {
|
export const createLibraryDailyTask = (): ILibraryDailyTaskInfo => {
|
||||||
const enemyTypes = getRandomElement(libraryDailyTasks);
|
const enemyTypes = getRandomElement(libraryDailyTasks)!;
|
||||||
const enemyAvatar = ExportEnemies.avatars[enemyTypes[0]];
|
const enemyAvatar = ExportEnemies.avatars[enemyTypes[0]];
|
||||||
const scansRequired = getRandomInt(2, 4);
|
const scansRequired = getRandomInt(2, 4);
|
||||||
return {
|
return {
|
||||||
@ -1944,22 +1944,22 @@ export const giveNemesisPetRecipe = (inventory: TInventoryDatabaseDocument, neme
|
|||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartHeadA",
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartHeadA",
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartHeadB",
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartHeadB",
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartHeadC"
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartHeadC"
|
||||||
]);
|
])!;
|
||||||
const body = getRandomElement([
|
const body = getRandomElement([
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartBodyA",
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartBodyA",
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartBodyB",
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartBodyB",
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartBodyC"
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartBodyC"
|
||||||
]);
|
])!;
|
||||||
const legs = getRandomElement([
|
const legs = getRandomElement([
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartLegsA",
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartLegsA",
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartLegsB",
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartLegsB",
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartLegsC"
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartLegsC"
|
||||||
]);
|
])!;
|
||||||
const tail = getRandomElement([
|
const tail = getRandomElement([
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartTailA",
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartTailA",
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartTailB",
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartTailB",
|
||||||
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartTailC"
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetParts/ZanukaPetPartTailC"
|
||||||
]);
|
])!;
|
||||||
const recipeType = Object.entries(ExportRecipes).find(arr => arr[1].resultType == head)![0];
|
const recipeType = Object.entries(ExportRecipes).find(arr => arr[1].resultType == head)![0];
|
||||||
addRecipes(inventory, [
|
addRecipes(inventory, [
|
||||||
{
|
{
|
||||||
|
@ -102,7 +102,7 @@ const getRandomLoginReward = (rng: CRng, day: number, inventory: TInventoryDatab
|
|||||||
// This account has all applicable warframes and weapons already mastered (filthy cheater), need a different reward.
|
// This account has all applicable warframes and weapons already mastered (filthy cheater), need a different reward.
|
||||||
return getRandomLoginReward(rng, day, inventory);
|
return getRandomLoginReward(rng, day, inventory);
|
||||||
}
|
}
|
||||||
reward.StoreItemType = toStoreItem(rng.randomElement(eligibleRecipes));
|
reward.StoreItemType = toStoreItem(rng.randomElement(eligibleRecipes)!);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
//_id: toOid(new Types.ObjectId()),
|
//_id: toOid(new Types.ObjectId()),
|
||||||
|
@ -930,7 +930,7 @@ export const addMissionRewards = async (
|
|||||||
|
|
||||||
if (rewardInfo.useVaultManifest) {
|
if (rewardInfo.useVaultManifest) {
|
||||||
MissionRewards.push({
|
MissionRewards.push({
|
||||||
StoreItem: getRandomElement(corruptedMods),
|
StoreItem: getRandomElement(corruptedMods)!,
|
||||||
ItemCount: 1
|
ItemCount: 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,12 @@ export const createGarden = (): IGardeningDatabase => {
|
|||||||
Name: "Garden0",
|
Name: "Garden0",
|
||||||
Plants: [
|
Plants: [
|
||||||
{
|
{
|
||||||
PlantType: getRandomElement(plantTypes),
|
PlantType: getRandomElement(plantTypes)!,
|
||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
PlotIndex: 0
|
PlotIndex: 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
PlantType: getRandomElement(plantTypes),
|
PlantType: getRandomElement(plantTypes)!,
|
||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
PlotIndex: 1
|
PlotIndex: 1
|
||||||
}
|
}
|
||||||
@ -62,12 +62,12 @@ export const createGarden = (): IGardeningDatabase => {
|
|||||||
Name: "Garden1",
|
Name: "Garden1",
|
||||||
Plants: [
|
Plants: [
|
||||||
{
|
{
|
||||||
PlantType: getRandomElement(plantTypes),
|
PlantType: getRandomElement(plantTypes)!,
|
||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
PlotIndex: 0
|
PlotIndex: 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
PlantType: getRandomElement(plantTypes),
|
PlantType: getRandomElement(plantTypes)!,
|
||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
PlotIndex: 1
|
PlotIndex: 1
|
||||||
}
|
}
|
||||||
@ -77,12 +77,12 @@ export const createGarden = (): IGardeningDatabase => {
|
|||||||
Name: "Garden2",
|
Name: "Garden2",
|
||||||
Plants: [
|
Plants: [
|
||||||
{
|
{
|
||||||
PlantType: getRandomElement(plantTypes),
|
PlantType: getRandomElement(plantTypes)!,
|
||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
PlotIndex: 0
|
PlotIndex: 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
PlantType: getRandomElement(plantTypes),
|
PlantType: getRandomElement(plantTypes)!,
|
||||||
EndTime: endTime,
|
EndTime: endTime,
|
||||||
PlotIndex: 1
|
PlotIndex: 1
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ export interface IRngResult {
|
|||||||
probability: number;
|
probability: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getRandomElement = <T>(arr: T[]): T => {
|
export const getRandomElement = <T>(arr: T[]): T | undefined => {
|
||||||
return arr[Math.floor(Math.random() * arr.length)];
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ export class CRng {
|
|||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
randomElement<T>(arr: T[]): T {
|
randomElement<T>(arr: T[]): T | undefined {
|
||||||
return arr[Math.floor(this.random() * arr.length)];
|
return arr[Math.floor(this.random() * arr.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ export class SRng {
|
|||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
randomElement<T>(arr: T[]): T {
|
randomElement<T>(arr: T[]): T | undefined {
|
||||||
return arr[this.randomInt(0, arr.length - 1)];
|
return arr[this.randomInt(0, arr.length - 1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ const generateVendorManifest = (vendorInfo: IGeneratableVendorInfo): IVendorMani
|
|||||||
while (processed.ItemManifest.length + offersToAdd.length < numItemsTarget) {
|
while (processed.ItemManifest.length + offersToAdd.length < numItemsTarget) {
|
||||||
// TODO: Consider per-bin item limits
|
// TODO: Consider per-bin item limits
|
||||||
// TODO: Consider item probability weightings
|
// TODO: Consider item probability weightings
|
||||||
offersToAdd.push(rng.randomElement(manifest.items));
|
offersToAdd.push(rng.randomElement(manifest.items)!);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let binThisCycle;
|
let binThisCycle;
|
||||||
@ -256,7 +256,7 @@ const generateVendorManifest = (vendorInfo: IGeneratableVendorInfo): IVendorMani
|
|||||||
for (let i = 0; i != rawItem.numRandomItemPrices; ++i) {
|
for (let i = 0; i != rawItem.numRandomItemPrices; ++i) {
|
||||||
let itemPrice: { type: string; count: IRange };
|
let itemPrice: { type: string; count: IRange };
|
||||||
do {
|
do {
|
||||||
itemPrice = rng.randomElement(manifest.randomItemPricesPerBin![rawItem.bin]);
|
itemPrice = rng.randomElement(manifest.randomItemPricesPerBin![rawItem.bin])!;
|
||||||
} while (item.ItemPrices.find(x => x.ItemType == itemPrice.type));
|
} while (item.ItemPrices.find(x => x.ItemType == itemPrice.type));
|
||||||
item.ItemPrices.push({
|
item.ItemPrices.push({
|
||||||
ItemType: itemPrice.type,
|
ItemType: itemPrice.type,
|
||||||
|
@ -225,7 +225,7 @@ const pushSortieIfRelevant = (worldState: IWorldState, day: number): void => {
|
|||||||
const seed = new CRng(day).randomInt(0, 0xffff);
|
const seed = new CRng(day).randomInt(0, 0xffff);
|
||||||
const rng = new CRng(seed);
|
const rng = new CRng(seed);
|
||||||
|
|
||||||
const boss = rng.randomElement(sortieBosses);
|
const boss = rng.randomElement(sortieBosses)!;
|
||||||
|
|
||||||
const modifiers = [
|
const modifiers = [
|
||||||
"SORTIE_MODIFIER_LOW_ENERGY",
|
"SORTIE_MODIFIER_LOW_ENERGY",
|
||||||
@ -302,7 +302,7 @@ const pushSortieIfRelevant = (worldState: IWorldState, day: number): void => {
|
|||||||
|
|
||||||
missionIndex = ExportRegions[node].missionIndex;
|
missionIndex = ExportRegions[node].missionIndex;
|
||||||
if (missionIndex != 28) {
|
if (missionIndex != 28) {
|
||||||
missionIndex = rng.randomElement(availableMissionIndexes);
|
missionIndex = rng.randomElement(availableMissionIndexes)!;
|
||||||
}
|
}
|
||||||
} while (
|
} while (
|
||||||
specialMissionTypes.indexOf(missionIndex) != -1 &&
|
specialMissionTypes.indexOf(missionIndex) != -1 &&
|
||||||
@ -312,7 +312,7 @@ const pushSortieIfRelevant = (worldState: IWorldState, day: number): void => {
|
|||||||
|
|
||||||
if (i == 2 && rng.randomInt(0, 2) == 2) {
|
if (i == 2 && rng.randomInt(0, 2) == 2) {
|
||||||
const filteredModifiers = modifiers.filter(mod => mod !== "SORTIE_MODIFIER_MELEE_ONLY");
|
const filteredModifiers = modifiers.filter(mod => mod !== "SORTIE_MODIFIER_MELEE_ONLY");
|
||||||
const modifierType = rng.randomElement(filteredModifiers);
|
const modifierType = rng.randomElement(filteredModifiers)!;
|
||||||
|
|
||||||
if (boss == "SORTIE_BOSS_PHORID") {
|
if (boss == "SORTIE_BOSS_PHORID") {
|
||||||
selectedNodes.push({
|
selectedNodes.push({
|
||||||
@ -346,7 +346,7 @@ const pushSortieIfRelevant = (worldState: IWorldState, day: number): void => {
|
|||||||
? modifiers.filter(mod => mod != "SORTIE_MODIFIER_HAZARD_RADIATION")
|
? modifiers.filter(mod => mod != "SORTIE_MODIFIER_HAZARD_RADIATION")
|
||||||
: modifiers;
|
: modifiers;
|
||||||
|
|
||||||
const modifierType = rng.randomElement(filteredModifiers);
|
const modifierType = rng.randomElement(filteredModifiers)!;
|
||||||
|
|
||||||
selectedNodes.push({
|
selectedNodes.push({
|
||||||
missionType,
|
missionType,
|
||||||
@ -389,7 +389,7 @@ const getSeasonDailyChallenge = (day: number): ISeasonChallenge => {
|
|||||||
Daily: true,
|
Daily: true,
|
||||||
Activation: { $date: { $numberLong: dayStart.toString() } },
|
Activation: { $date: { $numberLong: dayStart.toString() } },
|
||||||
Expiry: { $date: { $numberLong: dayEnd.toString() } },
|
Expiry: { $date: { $numberLong: dayEnd.toString() } },
|
||||||
Challenge: rng.randomElement(dailyChallenges)
|
Challenge: rng.randomElement(dailyChallenges)!
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -408,7 +408,7 @@ const getSeasonWeeklyChallenge = (week: number, id: number): ISeasonChallenge =>
|
|||||||
_id: { $oid: "67e1bb2d9d00cb47" + challengeId.toString().padStart(8, "0") },
|
_id: { $oid: "67e1bb2d9d00cb47" + challengeId.toString().padStart(8, "0") },
|
||||||
Activation: { $date: { $numberLong: weekStart.toString() } },
|
Activation: { $date: { $numberLong: weekStart.toString() } },
|
||||||
Expiry: { $date: { $numberLong: weekEnd.toString() } },
|
Expiry: { $date: { $numberLong: weekEnd.toString() } },
|
||||||
Challenge: rng.randomElement(weeklyChallenges)
|
Challenge: rng.randomElement(weeklyChallenges)!
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -425,7 +425,7 @@ const getSeasonWeeklyHardChallenge = (week: number, id: number): ISeasonChalleng
|
|||||||
_id: { $oid: "67e1bb2d9d00cb47" + challengeId.toString().padStart(8, "0") },
|
_id: { $oid: "67e1bb2d9d00cb47" + challengeId.toString().padStart(8, "0") },
|
||||||
Activation: { $date: { $numberLong: weekStart.toString() } },
|
Activation: { $date: { $numberLong: weekStart.toString() } },
|
||||||
Expiry: { $date: { $numberLong: weekEnd.toString() } },
|
Expiry: { $date: { $numberLong: weekEnd.toString() } },
|
||||||
Challenge: rng.randomElement(weeklyHardChallenges)
|
Challenge: rng.randomElement(weeklyHardChallenges)!
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1196,7 +1196,7 @@ export const getLiteSortie = (week: number): ILiteSortie => {
|
|||||||
"MT_EXTERMINATION",
|
"MT_EXTERMINATION",
|
||||||
"MT_SABOTAGE",
|
"MT_SABOTAGE",
|
||||||
"MT_RESCUE"
|
"MT_RESCUE"
|
||||||
]),
|
])!,
|
||||||
node: firstNode
|
node: firstNode
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1206,8 +1206,8 @@ export const getLiteSortie = (week: number): ILiteSortie => {
|
|||||||
"MT_ARTIFACT",
|
"MT_ARTIFACT",
|
||||||
"MT_EXCAVATE",
|
"MT_EXCAVATE",
|
||||||
"MT_SURVIVAL"
|
"MT_SURVIVAL"
|
||||||
]),
|
])!,
|
||||||
node: rng.randomElement(nodes)
|
node: rng.randomElement(nodes)!
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
missionType: "MT_ASSASSINATION",
|
missionType: "MT_ASSASSINATION",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user