Skip to content

Commit

Permalink
Fix logical error when updating some statusPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
adefee committed Feb 11, 2024
1 parent 83dbd66 commit 825f5e3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adefee/palworld-save-editor",
"version": "2.0.10",
"version": "2.0.11",
"description": "Comprehensive and extensible save editor and reporting tool for Palworld",
"main": "dist/index.js",
"type": "commonjs",
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,6 @@ const saveEditorMain = async () => {
playerChangesToMake,
});

console.info('modified', modifiedPlayerJson)

if (changeErrorsForThisPlayer.length > 0) {
warnings = [
...warnings,
Expand Down
11 changes: 7 additions & 4 deletions src/lib/getFieldMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ export const getPlayerFieldMapByFile = (filename: string, enableGuardrails = tru
currentHP: fieldMapAliasedValues.currentHp,
maxHp: fieldMapAliasedValues.maxHp,
maxHP: fieldMapAliasedValues.maxHp,
maxHealth: fieldMapAliasedValues.maxHp,
maxSp: fieldMapAliasedValues.maxSp,
maxSP: fieldMapAliasedValues.maxSp,
maxStamina: fieldMapAliasedValues.maxSp,
hunger: fieldMapAliasedValues.hunger,
fullStomach: fieldMapAliasedValues.hunger,
sanityValue: fieldMapAliasedValues.sanityValue,
Expand Down Expand Up @@ -241,8 +243,8 @@ export const getPlayerFieldMapByFile = (filename: string, enableGuardrails = tru
statusPoints: {
info: "This is the parent property for status point settings. By default, you receive an new `unusedStatusPoint` every level, which can be spent here. These will be added to your base stats (hp, weight, stamina, etc). The ingame default is 0 for all values.",
followChildren: true, // tell iterator to follow the children keys instead of just this key
maxHp: {
paverId: 'statusPoints.maxHp',
health: {
paverId: 'statusPoints.health',
parameterId: null,
targetKey: 'GotStatusPointList.value.values',
targetFilteredKey: 'StatusPoint.value',
Expand All @@ -252,8 +254,8 @@ export const getPlayerFieldMapByFile = (filename: string, enableGuardrails = tru
validate: (val) => Number.isInteger(val) && val >= 0,
validationError: 'statusPoints.maxHp should be an integer greater than 0.',
},
maxSp: {
paverId: 'statusPoints.maxSp',
stamina: {
paverId: 'statusPoints.stamina',
parameterId: null,
targetKey: 'GotStatusPointList.value.values',
targetFilteredKey: 'StatusPoint.value',
Expand Down Expand Up @@ -286,6 +288,7 @@ export const getPlayerFieldMapByFile = (filename: string, enableGuardrails = tru
validationError: 'statusPoints.weight should be an integer greater than 0.',
},
captureRate: {
paverId: 'statusPoints.captureRate',
parameterId: null,
targetKey: 'GotStatusPointList.value.values',
targetFilteredKey: 'StatusPoint.value',
Expand Down
34 changes: 25 additions & 9 deletions src/lib/write/editPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ export const editPlayerInLevelSav = ({
if (thisSubFieldMapEntry) {
recursivelyMakeChanges(subKey, thisSubChangeValue, thisSubFieldMapEntry);
} else {
if (process.env.DEBUG) {
console.log('updatePlayerLevelSavData(): Invalid field name:', subKey);
}
console.log('updatePlayerLevelSavData(): Invalid field name:', subKey);
}
});

return;
} else {
if (process.env.DEBUG) {
console.info("No followChildren flag found for", keyName)
}
}

if (singleFieldMapEntry?.whatDoesThiDo) {
Expand Down Expand Up @@ -175,8 +177,13 @@ export const editPlayerInLevelSav = ({
* This would be defined in field map and would be useful for things like status points, where changing the status points would also change the maxHp, maxSp, etc.
*/

// User wants to adjust status point on maxHp
if (singleFieldMapEntry?.paverId === 'statusPoints.maxHp') {
// User wants to adjust status point on health
// Only make these changes if they haven't already been defined in the changes to make.
if (
singleFieldMapEntry?.paverId === 'statusPoints.health' &&
!playerChangesToMake.maxHp &&
!playerChangesToMake.maxHealth
) {
let tempNewAmount = 500000 + (newValue * 100000); // Work speed should be the base amt + (status points * 100)
const tempRefFieldMapEntry = fieldMap['maxHp'];
if (tempRefFieldMapEntry) {
Expand Down Expand Up @@ -211,9 +218,14 @@ export const editPlayerInLevelSav = ({
}
}

// User wants to adjust status point on maxSp
if (singleFieldMapEntry?.paverId === 'statusPoints.maxSp') {
let tempNewAmount = 100 + (newValue * 10); // Work speed should be the base amt + (status points * 10)
// User wants to adjust status point on stamina
// Only make these changes if they haven't already been defined in the changes to make.
if (
singleFieldMapEntry?.paverId === 'statusPoints.stamina' &&
!playerChangesToMake.maxSp &&
!playerChangesToMake.maxStamina
) {
let tempNewAmount = 100 + (newValue * 10); // New value should be the base amt + (status points * 10)
const tempRefFieldMapEntry = fieldMap['maxSp'];
if (tempRefFieldMapEntry) {
const tempNewChangeLog: IChangelogEntry = {
Expand Down Expand Up @@ -252,7 +264,11 @@ export const editPlayerInLevelSav = ({
*/

// User wants to adjust status point on work speed
if (singleFieldMapEntry?.paverId === 'statusPoints.workSpeed') {
// Only make these changes if they haven't already been defined in the changes to make.
if (
singleFieldMapEntry?.paverId === 'statusPoints.workSpeed' &&
!playerChangesToMake.workSpeed
) {
const newWorkSpeedAmt = 100 + (newValue * 50); // Work speed should be the base amt + (status points * 50)
const workSpeedFieldMapEntry = fieldMap['workSpeed'];
if (workSpeedFieldMapEntry) {
Expand Down
8 changes: 6 additions & 2 deletions src/types/Paver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ export interface IPaverConfigPlayerChanges {
],
relicsInPossession?: 0,
currentHp?: number,
// @deprecated
maxHp?: number,
maxHealth?: number,
// @deprecated
maxSp?: number,
maxStamina?: number,
hunger?: number,
sanityValue?: number,
isPlayer?: true,
workSpeed?: number,
support?: number,
unusedStatusPoint?: number,
statusPoints?: {
maxHp?: number,
maxSp?: number,
health?: number,
stamina?: number,
attack?: number,
weight?: number,
catchRate?: number,
Expand Down

0 comments on commit 825f5e3

Please sign in to comment.