From 185fac6f1990c657ed73672204f28dd2f0f51e3f Mon Sep 17 00:00:00 2001 From: Shaun Date: Sat, 30 Apr 2022 15:47:12 +0200 Subject: [PATCH] modding #1933: Allow beforeGatherResourceComplete to modify the gather chance of fishing nodes --- src/server/components/gatherer.js | 2 +- src/server/world/resourceSpawner.js | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/server/components/gatherer.js b/src/server/components/gatherer.js index e26061be..66d0d4c1 100644 --- a/src/server/components/gatherer.js +++ b/src/server/components/gatherer.js @@ -116,7 +116,7 @@ module.exports = { this.obj.syncer.set(false, 'gatherer', 'progress', 100); if (isFish) { - let catchChance = 40 + this.obj.stats.values.catchChance; + const catchChance = gatherResult.blueprint.gatherChance + this.obj.stats.values.catchChance; if (~~(Math.random() * 100) >= catchChance) { this.sendAnnouncement('The fish got away'); this.gathering = null; diff --git a/src/server/world/resourceSpawner.js b/src/server/world/resourceSpawner.js index 09b5ff03..7141ca82 100644 --- a/src/server/world/resourceSpawner.js +++ b/src/server/world/resourceSpawner.js @@ -1,5 +1,10 @@ let herbs = require('../config/herbs'); +const defaultGatherChance = { + herb: 100, + fish: 40 +}; + module.exports = { nodes: [], @@ -22,7 +27,7 @@ module.exports = { }, register: function (name, blueprint) { - let exists = this.nodes.find(n => (n.blueprint.name === name)); + const exists = this.nodes.find(n => (n.blueprint.name === name)); if (exists) { if (!exists.blueprint.positions) { exists.blueprint.positions = [{ @@ -47,21 +52,23 @@ module.exports = { name: name }); - let max = blueprint.max; + const max = blueprint.max; delete blueprint.max; - let chance = blueprint.chance; + const chance = blueprint.chance; delete blueprint.chance; - let cdMax = blueprint.cdMax; + const cdMax = blueprint.cdMax; delete blueprint.cdMax; + blueprint.gatherChance = blueprint.gatherChance ?? defaultGatherChance[blueprint.type]; + this.nodes.push({ cd: 0, - max: max, - chance: chance, - cdMax: cdMax, - blueprint: blueprint, + max, + chance, + cdMax, + blueprint, spawns: [] }); },