feat: earning intrinsics #872

Merged
Sainan merged 1 commits from earn-intrinsics into main 2025-01-31 08:03:15 -08:00
2 changed files with 8 additions and 1 deletions
Showing only changes of commit cfacfcefbe - Show all commits

View File

@ -150,6 +150,11 @@ export const addMissionInventoryUpdates = (
addFocusXpIncreases(inventory, value);
break;
}
case "PlayerSkillGains": {
inventory.PlayerSkills.LPP_SPACE += value.LPP_SPACE;
inventory.PlayerSkills.LPP_DRIFTER += value.LPP_DRIFTER;
break;
}
coderabbitai[bot] commented 2025-01-31 00:17:09 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Add null checks and validation for PlayerSkills.

The current implementation has potential issues:

  1. No null check for inventory.PlayerSkills
  2. No validation of input values
  3. No error handling for potential overflow

Apply this diff to add safety checks:

 case "PlayerSkillGains": {
+    if (!inventory.PlayerSkills) {
+        inventory.PlayerSkills = { LPP_SPACE: 0, LPP_DRIFTER: 0 };
+    }
+    // Ensure input values are non-negative
+    const spaceGains = Math.max(0, value.LPP_SPACE || 0);
+    const drifterGains = Math.max(0, value.LPP_DRIFTER || 0);
+    // Prevent overflow
+    inventory.PlayerSkills.LPP_SPACE = Math.min(
+        Number.MAX_SAFE_INTEGER,
+        inventory.PlayerSkills.LPP_SPACE + spaceGains
+    );
+    inventory.PlayerSkills.LPP_DRIFTER = Math.min(
+        Number.MAX_SAFE_INTEGER,
+        inventory.PlayerSkills.LPP_DRIFTER + drifterGains
+    );
-    inventory.PlayerSkills.LPP_SPACE += value.LPP_SPACE;
-    inventory.PlayerSkills.LPP_DRIFTER += value.LPP_DRIFTER;
     break;
 }
📝 Committable suggestion

‼️ 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.

            case "PlayerSkillGains": {
                if (!inventory.PlayerSkills) {
                    inventory.PlayerSkills = { LPP_SPACE: 0, LPP_DRIFTER: 0 };
                }
                // Ensure input values are non-negative
                const spaceGains = Math.max(0, value.LPP_SPACE || 0);
                const drifterGains = Math.max(0, value.LPP_DRIFTER || 0);
                // Prevent overflow
                inventory.PlayerSkills.LPP_SPACE = Math.min(
                    Number.MAX_SAFE_INTEGER,
                    inventory.PlayerSkills.LPP_SPACE + spaceGains
                );
                inventory.PlayerSkills.LPP_DRIFTER = Math.min(
                    Number.MAX_SAFE_INTEGER,
                    inventory.PlayerSkills.LPP_DRIFTER + drifterGains
                );
                break;
            }
_:warning: Potential issue_ **Add null checks and validation for PlayerSkills.** The current implementation has potential issues: 1. No null check for `inventory.PlayerSkills` 2. No validation of input values 3. No error handling for potential overflow Apply this diff to add safety checks: ```diff case "PlayerSkillGains": { + if (!inventory.PlayerSkills) { + inventory.PlayerSkills = { LPP_SPACE: 0, LPP_DRIFTER: 0 }; + } + // Ensure input values are non-negative + const spaceGains = Math.max(0, value.LPP_SPACE || 0); + const drifterGains = Math.max(0, value.LPP_DRIFTER || 0); + // Prevent overflow + inventory.PlayerSkills.LPP_SPACE = Math.min( + Number.MAX_SAFE_INTEGER, + inventory.PlayerSkills.LPP_SPACE + spaceGains + ); + inventory.PlayerSkills.LPP_DRIFTER = Math.min( + Number.MAX_SAFE_INTEGER, + inventory.PlayerSkills.LPP_DRIFTER + drifterGains + ); - inventory.PlayerSkills.LPP_SPACE += value.LPP_SPACE; - inventory.PlayerSkills.LPP_DRIFTER += value.LPP_DRIFTER; break; } ``` <!-- 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 case "PlayerSkillGains": { if (!inventory.PlayerSkills) { inventory.PlayerSkills = { LPP_SPACE: 0, LPP_DRIFTER: 0 }; } // Ensure input values are non-negative const spaceGains = Math.max(0, value.LPP_SPACE || 0); const drifterGains = Math.max(0, value.LPP_DRIFTER || 0); // Prevent overflow inventory.PlayerSkills.LPP_SPACE = Math.min( Number.MAX_SAFE_INTEGER, inventory.PlayerSkills.LPP_SPACE + spaceGains ); inventory.PlayerSkills.LPP_DRIFTER = Math.min( Number.MAX_SAFE_INTEGER, inventory.PlayerSkills.LPP_DRIFTER + drifterGains ); break; } ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
default:
// Equipment XP updates
if (equipmentKeys.includes(key as TEquipmentKey)) {

View File

@ -11,7 +11,8 @@ import {
TSolarMapRegion,
TEquipmentKey,
IFusionTreasure,
IQuestKeyClient
IQuestKeyClient,
IPlayerSkills
} from "./inventoryTypes/inventoryTypes";
export interface IThemeUpdateRequest {
@ -73,6 +74,7 @@ export type IMissionInventoryUpdateRequest = {
FpsSamples: number;
EvolutionProgress?: IEvolutionProgress[];
FocusXpIncreases?: number[];
PlayerSkillGains: IPlayerSkills;
} & {
[K in TEquipmentKey]?: IEquipmentClient[];
};