From f4ca8366e2b66660a8cfdfe7cbf26da7439e5fca Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Fri, 17 Apr 2020 17:52:04 +0200 Subject: [PATCH] Handle contributions to the next level of a technology Fix research_sync sending out contribution events for the previous level of a researched technology and sending finished events for the wrong level when synchronizing technologies. Both of these issues are related to failing to accunt for the unlocked level being one less than the level stored when the researched property is false. --- plugins/research_sync/master.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/research_sync/master.js b/plugins/research_sync/master.js index 84a00db4..4e141be9 100644 --- a/plugins/research_sync/master.js +++ b/plugins/research_sync/master.js @@ -67,6 +67,17 @@ class MasterPlugin extends plugin.BaseMasterPlugin { return; } + // Handle contributon to the next level of a researched technology + if (tech.level === level - 1 && tech.researched) { + tech.researched = false; + tech.level = level; + } + + // Ignore contributions to higher levels + if (tech.level < level) { + return; + } + let newProgress = tech.progress + contribution; if (newProgress < 1) { tech.progress = newProgress; @@ -125,12 +136,15 @@ class MasterPlugin extends plugin.BaseMasterPlugin { } if (tech.level < level || researched) { + // Send update if the unlocked level is greater + if (level - !researched > tech.level - !tech.researched) { + for (let slaveConnection of this.master.slaveConnections.values()) { + this.info.messages.finished.send(slaveConnection, { name, level: level - !researched }); + } + } tech.level = level; tech.progress = progress; tech.researched = researched; - for (let slaveConnection of this.master.slaveConnections.values()) { - this.info.messages.finished.send(slaveConnection, { name, level }); - } if (progress) { this.progressToBroadcast.add(name);