feat: rerolling rivens #806
@ -57,8 +57,10 @@ const randomiseStats = (randomModType: string, fingerprint: IUnveiledRivenFinger
|
|||||||
|
|||||||
const numBuffs = 2 + Math.trunc(Math.random() * 2); // 2 or 3
|
const numBuffs = 2 + Math.trunc(Math.random() * 2); // 2 or 3
|
||||||
const buffEntries = meta.upgradeEntries!.filter(x => x.canBeBuff);
|
const buffEntries = meta.upgradeEntries!.filter(x => x.canBeBuff);
|
||||||
for (let i = 0; i != numBuffs; ++i) {
|
for (let i = 0; i != numBuffs; ++i) {
|
||||||
const entry = getRandomElement(buffEntries);
|
const buffIndex = Math.trunc(Math.random() * buffEntries.length);
|
||||||
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Similar to the previous case, the code uses the null assertion operator Apply this diff to add null checks:
📝 Committable suggestion
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Similar to the previous case, the code uses the null assertion operator `!` without checking if the upgrade exists. This may lead to runtime errors if the upgrade is not found.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId)!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
if (!upgrade) {
return res.status(404).json({ error: "Upgrade not found in inventory." });
}
if (request.CommitReroll) {
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting curses. Similarly, if none of the Apply this diff to check for curseable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting curses.**
Similarly, if none of the `meta.upgradeEntries` have `canBeCurse` set to `true`, the `while` loop will result in an infinite loop. Ensure that there is at least one entry that can be a curse before entering the loop.
Apply this diff to check for curseable entries:
```diff
+ const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
+ if (curseableEntries.length === 0) {
+ // It's acceptable for an upgrade to have no curses
+ break;
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(curseableEntries);
- while (!entry.canBeCurse) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
if (curseableEntries.length === 0) {
// It's acceptable for an upgrade to have no curses
break;
}
let entry = getRandomElement(curseableEntries);
fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting buffs. If none of the Apply this diff to check for buffable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting buffs.**
If none of the `meta.upgradeEntries` have `canBeBuff` set to `true`, the `while` loop will result in an infinite loop. To prevent this, ensure that there is at least one entry that can be a buff before entering the loop.
Apply this diff to check for buffable entries:
```diff
+ const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
+ if (buffableEntries.length === 0) {
+ throw new Error("No available buffs for this upgrade type.");
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(buffableEntries);
- while (!entry.canBeBuff) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
if (buffableEntries.length === 0) {
throw new Error("No available buffs for this upgrade type.");
}
let entry = getRandomElement(buffableEntries);
fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
}
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Currently, the code uses the null assertion operator Apply this diff to add null checks:
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Currently, the code uses the null assertion operator `!` when accessing the upgrade in the inventory without checking if it exists. If the upgrade is not found, this will cause a runtime error. It's important to add a null check to handle cases where the upgrade may not exist.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0])!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0]);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Similar to the previous case, the code uses the null assertion operator Apply this diff to add null checks:
📝 Committable suggestion
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Similar to the previous case, the code uses the null assertion operator `!` without checking if the upgrade exists. This may lead to runtime errors if the upgrade is not found.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId)!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
if (!upgrade) {
return res.status(404).json({ error: "Upgrade not found in inventory." });
}
if (request.CommitReroll) {
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting curses. Similarly, if none of the Apply this diff to check for curseable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting curses.**
Similarly, if none of the `meta.upgradeEntries` have `canBeCurse` set to `true`, the `while` loop will result in an infinite loop. Ensure that there is at least one entry that can be a curse before entering the loop.
Apply this diff to check for curseable entries:
```diff
+ const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
+ if (curseableEntries.length === 0) {
+ // It's acceptable for an upgrade to have no curses
+ break;
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(curseableEntries);
- while (!entry.canBeCurse) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
if (curseableEntries.length === 0) {
// It's acceptable for an upgrade to have no curses
break;
}
let entry = getRandomElement(curseableEntries);
fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting buffs. If none of the Apply this diff to check for buffable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting buffs.**
If none of the `meta.upgradeEntries` have `canBeBuff` set to `true`, the `while` loop will result in an infinite loop. To prevent this, ensure that there is at least one entry that can be a buff before entering the loop.
Apply this diff to check for buffable entries:
```diff
+ const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
+ if (buffableEntries.length === 0) {
+ throw new Error("No available buffs for this upgrade type.");
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(buffableEntries);
- while (!entry.canBeBuff) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
if (buffableEntries.length === 0) {
throw new Error("No available buffs for this upgrade type.");
}
let entry = getRandomElement(buffableEntries);
fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
}
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Currently, the code uses the null assertion operator Apply this diff to add null checks:
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Currently, the code uses the null assertion operator `!` when accessing the upgrade in the inventory without checking if it exists. If the upgrade is not found, this will cause a runtime error. It's important to add a null check to handle cases where the upgrade may not exist.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0])!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0]);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
|
const entry = buffEntries[buffIndex];
|
||||||
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Similar to the previous case, the code uses the null assertion operator Apply this diff to add null checks:
📝 Committable suggestion
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Similar to the previous case, the code uses the null assertion operator `!` without checking if the upgrade exists. This may lead to runtime errors if the upgrade is not found.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId)!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
if (!upgrade) {
return res.status(404).json({ error: "Upgrade not found in inventory." });
}
if (request.CommitReroll) {
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting curses. Similarly, if none of the Apply this diff to check for curseable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting curses.**
Similarly, if none of the `meta.upgradeEntries` have `canBeCurse` set to `true`, the `while` loop will result in an infinite loop. Ensure that there is at least one entry that can be a curse before entering the loop.
Apply this diff to check for curseable entries:
```diff
+ const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
+ if (curseableEntries.length === 0) {
+ // It's acceptable for an upgrade to have no curses
+ break;
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(curseableEntries);
- while (!entry.canBeCurse) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
if (curseableEntries.length === 0) {
// It's acceptable for an upgrade to have no curses
break;
}
let entry = getRandomElement(curseableEntries);
fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting buffs. If none of the Apply this diff to check for buffable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting buffs.**
If none of the `meta.upgradeEntries` have `canBeBuff` set to `true`, the `while` loop will result in an infinite loop. To prevent this, ensure that there is at least one entry that can be a buff before entering the loop.
Apply this diff to check for buffable entries:
```diff
+ const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
+ if (buffableEntries.length === 0) {
+ throw new Error("No available buffs for this upgrade type.");
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(buffableEntries);
- while (!entry.canBeBuff) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
if (buffableEntries.length === 0) {
throw new Error("No available buffs for this upgrade type.");
}
let entry = getRandomElement(buffableEntries);
fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
}
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Currently, the code uses the null assertion operator Apply this diff to add null checks:
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Currently, the code uses the null assertion operator `!` when accessing the upgrade in the inventory without checking if it exists. If the upgrade is not found, this will cause a runtime error. It's important to add a null check to handle cases where the upgrade may not exist.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0])!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0]);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Check for undefined It's possible that Apply this diff to add a null check:
📝 Committable suggestion
_:warning: Potential issue_
**Check for undefined `meta` when accessing `ExportUpgrades[randomModType]`.**
It's possible that `randomModType` is not a key in `ExportUpgrades`, resulting in `meta` being `undefined`. Accessing `meta.upgradeEntries` would then cause a runtime error. It's important to check if `meta` exists before proceeding.
Apply this diff to add a null check:
```diff
const meta = ExportUpgrades[randomModType];
+ if (!meta) {
+ throw new Error(`No upgrade data found for mod type: ${randomModType}`);
+ }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const meta = ExportUpgrades[randomModType];
if (!meta) {
throw new Error(`No upgrade data found for mod type: ${randomModType}`);
}
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
|
fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
|
||||||
|
buffEntries.splice(buffIndex, 1);
|
||||||
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Similar to the previous case, the code uses the null assertion operator Apply this diff to add null checks:
📝 Committable suggestion
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Similar to the previous case, the code uses the null assertion operator `!` without checking if the upgrade exists. This may lead to runtime errors if the upgrade is not found.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId)!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
if (!upgrade) {
return res.status(404).json({ error: "Upgrade not found in inventory." });
}
if (request.CommitReroll) {
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting curses. Similarly, if none of the Apply this diff to check for curseable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting curses.**
Similarly, if none of the `meta.upgradeEntries` have `canBeCurse` set to `true`, the `while` loop will result in an infinite loop. Ensure that there is at least one entry that can be a curse before entering the loop.
Apply this diff to check for curseable entries:
```diff
+ const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
+ if (curseableEntries.length === 0) {
+ // It's acceptable for an upgrade to have no curses
+ break;
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(curseableEntries);
- while (!entry.canBeCurse) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
if (curseableEntries.length === 0) {
// It's acceptable for an upgrade to have no curses
break;
}
let entry = getRandomElement(curseableEntries);
fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting buffs. If none of the Apply this diff to check for buffable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting buffs.**
If none of the `meta.upgradeEntries` have `canBeBuff` set to `true`, the `while` loop will result in an infinite loop. To prevent this, ensure that there is at least one entry that can be a buff before entering the loop.
Apply this diff to check for buffable entries:
```diff
+ const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
+ if (buffableEntries.length === 0) {
+ throw new Error("No available buffs for this upgrade type.");
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(buffableEntries);
- while (!entry.canBeBuff) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
if (buffableEntries.length === 0) {
throw new Error("No available buffs for this upgrade type.");
}
let entry = getRandomElement(buffableEntries);
fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
}
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Currently, the code uses the null assertion operator Apply this diff to add null checks:
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Currently, the code uses the null assertion operator `!` when accessing the upgrade in the inventory without checking if it exists. If the upgrade is not found, this will cause a runtime error. It's important to add a null check to handle cases where the upgrade may not exist.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0])!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0]);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
|||||||
}
|
}
|
||||||
|
|
||||||
fingerprint.curses = [];
|
fingerprint.curses = [];
|
||||||
|
|||||||
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Similar to the previous case, the code uses the null assertion operator Apply this diff to add null checks:
📝 Committable suggestion
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Similar to the previous case, the code uses the null assertion operator `!` without checking if the upgrade exists. This may lead to runtime errors if the upgrade is not found.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId)!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
if (!upgrade) {
return res.status(404).json({ error: "Upgrade not found in inventory." });
}
if (request.CommitReroll) {
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting curses. Similarly, if none of the Apply this diff to check for curseable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting curses.**
Similarly, if none of the `meta.upgradeEntries` have `canBeCurse` set to `true`, the `while` loop will result in an infinite loop. Ensure that there is at least one entry that can be a curse before entering the loop.
Apply this diff to check for curseable entries:
```diff
+ const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
+ if (curseableEntries.length === 0) {
+ // It's acceptable for an upgrade to have no curses
+ break;
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(curseableEntries);
- while (!entry.canBeCurse) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
if (curseableEntries.length === 0) {
// It's acceptable for an upgrade to have no curses
break;
}
let entry = getRandomElement(curseableEntries);
fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting buffs. If none of the Apply this diff to check for buffable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting buffs.**
If none of the `meta.upgradeEntries` have `canBeBuff` set to `true`, the `while` loop will result in an infinite loop. To prevent this, ensure that there is at least one entry that can be a buff before entering the loop.
Apply this diff to check for buffable entries:
```diff
+ const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
+ if (buffableEntries.length === 0) {
+ throw new Error("No available buffs for this upgrade type.");
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(buffableEntries);
- while (!entry.canBeBuff) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
if (buffableEntries.length === 0) {
throw new Error("No available buffs for this upgrade type.");
}
let entry = getRandomElement(buffableEntries);
fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
}
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Currently, the code uses the null assertion operator Apply this diff to add null checks:
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Currently, the code uses the null assertion operator `!` when accessing the upgrade in the inventory without checking if it exists. If the upgrade is not found, this will cause a runtime error. It's important to add a null check to handle cases where the upgrade may not exist.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0])!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0]);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Similar to the previous case, the code uses the null assertion operator Apply this diff to add null checks:
📝 Committable suggestion
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Similar to the previous case, the code uses the null assertion operator `!` without checking if the upgrade exists. This may lead to runtime errors if the upgrade is not found.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId)!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemId);
if (!upgrade) {
return res.status(404).json({ error: "Upgrade not found in inventory." });
}
if (request.CommitReroll) {
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting curses. Similarly, if none of the Apply this diff to check for curseable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting curses.**
Similarly, if none of the `meta.upgradeEntries` have `canBeCurse` set to `true`, the `while` loop will result in an infinite loop. Ensure that there is at least one entry that can be a curse before entering the loop.
Apply this diff to check for curseable entries:
```diff
+ const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
+ if (curseableEntries.length === 0) {
+ // It's acceptable for an upgrade to have no curses
+ break;
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(curseableEntries);
- while (!entry.canBeCurse) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const curseableEntries = meta.upgradeEntries!.filter(entry => entry.canBeCurse);
if (curseableEntries.length === 0) {
// It's acceptable for an upgrade to have no curses
break;
}
let entry = getRandomElement(curseableEntries);
fingerprint.curses.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Prevent potential infinite loops when selecting buffs. If none of the Apply this diff to check for buffable entries:
📝 Committable suggestion
_:warning: Potential issue_
**Prevent potential infinite loops when selecting buffs.**
If none of the `meta.upgradeEntries` have `canBeBuff` set to `true`, the `while` loop will result in an infinite loop. To prevent this, ensure that there is at least one entry that can be a buff before entering the loop.
Apply this diff to check for buffable entries:
```diff
+ const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
+ if (buffableEntries.length === 0) {
+ throw new Error("No available buffs for this upgrade type.");
+ }
- let entry = getRandomElement(meta.upgradeEntries!);
+ let entry = getRandomElement(buffableEntries);
- while (!entry.canBeBuff) {
- entry = getRandomElement(meta.upgradeEntries!);
- }
```
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const buffableEntries = meta.upgradeEntries!.filter(entry => entry.canBeBuff);
if (buffableEntries.length === 0) {
throw new Error("No available buffs for this upgrade type.");
}
let entry = getRandomElement(buffableEntries);
fingerprint.buffs.push({ Tag: entry.tag, Value: Math.trunc(Math.random() * 0x40000000) });
}
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit -->
![]() ⚠️ Potential issue Handle potential null references when accessing inventory upgrades. Currently, the code uses the null assertion operator Apply this diff to add null checks:
_:warning: Potential issue_
**Handle potential null references when accessing inventory upgrades.**
Currently, the code uses the null assertion operator `!` when accessing the upgrade in the inventory without checking if it exists. If the upgrade is not found, this will cause a runtime error. It's important to add a null check to handle cases where the upgrade may not exist.
Apply this diff to add null checks:
```diff
- const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0])!;
+ const upgrade = inventory.Upgrades.find(x => x._id?.toString() == request.ItemIds[0]);
+ if (!upgrade) {
+ return res.status(404).json({ error: "Upgrade not found in inventory." });
+ }
```
> Committable suggestion skipped: line range outside the PR's diff.
<!-- This is an auto-generated comment by CodeRabbit -->
|
⚠️ Potential issue
Handle potential null references when accessing inventory upgrades.
Similar to the previous case, the code uses the null assertion operator
!
without checking if the upgrade exists. This may lead to runtime errors if the upgrade is not found.Apply this diff to add null checks:
📝 Committable suggestion
⚠️ Potential issue
Prevent potential infinite loops when selecting curses.
Similarly, if none of the
meta.upgradeEntries
havecanBeCurse
set totrue
, thewhile
loop will result in an infinite loop. Ensure that there is at least one entry that can be a curse before entering the loop.Apply this diff to check for curseable entries:
📝 Committable suggestion
⚠️ Potential issue
Prevent potential infinite loops when selecting buffs.
If none of the
meta.upgradeEntries
havecanBeBuff
set totrue
, thewhile
loop will result in an infinite loop. To prevent this, ensure that there is at least one entry that can be a buff before entering the loop.Apply this diff to check for buffable entries:
📝 Committable suggestion
⚠️ Potential issue
Handle potential null references when accessing inventory upgrades.
Currently, the code uses the null assertion operator
!
when accessing the upgrade in the inventory without checking if it exists. If the upgrade is not found, this will cause a runtime error. It's important to add a null check to handle cases where the upgrade may not exist.Apply this diff to add null checks:
⚠️ Potential issue
Handle potential null references when accessing inventory upgrades.
Similar to the previous case, the code uses the null assertion operator
!
without checking if the upgrade exists. This may lead to runtime errors if the upgrade is not found.Apply this diff to add null checks:
📝 Committable suggestion
⚠️ Potential issue
Prevent potential infinite loops when selecting curses.
Similarly, if none of the
meta.upgradeEntries
havecanBeCurse
set totrue
, thewhile
loop will result in an infinite loop. Ensure that there is at least one entry that can be a curse before entering the loop.Apply this diff to check for curseable entries:
📝 Committable suggestion
⚠️ Potential issue
Prevent potential infinite loops when selecting buffs.
If none of the
meta.upgradeEntries
havecanBeBuff
set totrue
, thewhile
loop will result in an infinite loop. To prevent this, ensure that there is at least one entry that can be a buff before entering the loop.Apply this diff to check for buffable entries:
📝 Committable suggestion
⚠️ Potential issue
Handle potential null references when accessing inventory upgrades.
Currently, the code uses the null assertion operator
!
when accessing the upgrade in the inventory without checking if it exists. If the upgrade is not found, this will cause a runtime error. It's important to add a null check to handle cases where the upgrade may not exist.Apply this diff to add null checks: