diff --git a/src/js/core/config.js b/src/js/core/config.js index b4f36af5..a4793384 100644 --- a/src/js/core/config.js +++ b/src/js/core/config.js @@ -72,8 +72,8 @@ export const globalConfig = { readerAnalyzeIntervalSeconds: 10, - goalAcceptorMinimumDurationSeconds: 5, - goalAcceptorsPerProducer: 4.5, + goalAcceptorItemsRequired: 10, + goalAcceptorsPerProducer: 5, puzzleModeSpeed: 3, puzzleMinBoundsSize: 2, puzzleMaxBoundsSize: 20, diff --git a/src/js/game/components/goal_acceptor.js b/src/js/game/components/goal_acceptor.js index 87c55501..485f385b 100644 --- a/src/js/game/components/goal_acceptor.js +++ b/src/js/game/components/goal_acceptor.js @@ -31,19 +31,26 @@ export class GoalAcceptorComponent extends Component { clear() { // the last items we delivered - /** @type {{ item: BaseItem; time: number; }[]} */ - this.deliveryHistory = []; + /** @type {{ item: BaseItem; time: number; }} */ + this.lastDelivery = null; + + this.currentDeliveredItems = 0; // Used for animations this.displayPercentage = 0; } - getRequiredDeliveryHistorySize() { + // clears items but doesn't instantly reset the progress bar + clearItems() { + this.lastDelivery = null; + + this.currentDeliveredItems = 0; + } + + getRequiredSecondsPerItem() { return ( - (globalConfig.puzzleModeSpeed * - globalConfig.goalAcceptorMinimumDurationSeconds * - globalConfig.beltSpeedItemsPerSecond) / - globalConfig.goalAcceptorsPerProducer + globalConfig.goalAcceptorsPerProducer / + (globalConfig.puzzleModeSpeed * globalConfig.beltSpeedItemsPerSecond) ); } } diff --git a/src/js/game/hud/parts/puzzle_editor_review.js b/src/js/game/hud/parts/puzzle_editor_review.js index 68f5360c..727006d6 100644 --- a/src/js/game/hud/parts/puzzle_editor_review.js +++ b/src/js/game/hud/parts/puzzle_editor_review.js @@ -216,8 +216,8 @@ export class HUDPuzzleEditorReview extends BaseHUDPart { if (!goalComp.item) { return T.puzzleMenu.validation.goalAcceptorNoItem; } - const required = goalComp.getRequiredDeliveryHistorySize(); - if (goalComp.deliveryHistory.length < required) { + const required = globalConfig.goalAcceptorItemsRequired; + if (goalComp.currentDeliveredItems < required) { return T.puzzleMenu.validation.goalAcceptorRateNotMet; } } diff --git a/src/js/game/systems/goal_acceptor.js b/src/js/game/systems/goal_acceptor.js index ff3f08f3..f7ac16a6 100644 --- a/src/js/game/systems/goal_acceptor.js +++ b/src/js/game/systems/goal_acceptor.js @@ -24,13 +24,15 @@ export class GoalAcceptorSystem extends GameSystemWithFilter { const entity = this.allEntities[i]; const goalComp = entity.components.GoalAcceptor; - // filter the ones which are no longer active, or which are not the same - goalComp.deliveryHistory = goalComp.deliveryHistory.filter( - d => - now - d.time < globalConfig.goalAcceptorMinimumDurationSeconds && d.item === goalComp.item - ); + if (!goalComp.lastDelivery) { + continue; + } + + if (now - goalComp.lastDelivery.time > goalComp.getRequiredSecondsPerItem()) { + goalComp.clearItems(); + } - if (goalComp.deliveryHistory.length < goalComp.getRequiredDeliveryHistorySize()) { + if (goalComp.currentDeliveredItems < globalConfig.goalAcceptorItemsRequired) { allAccepted = false; } } @@ -64,8 +66,8 @@ export class GoalAcceptorSystem extends GameSystemWithFilter { const staticComp = contents[i].components.StaticMapEntity; const item = goalComp.item; - const requiredItemsForSuccess = goalComp.getRequiredDeliveryHistorySize(); - const percentage = clamp(goalComp.deliveryHistory.length / requiredItemsForSuccess, 0, 1); + const requiredItemsForSuccess = globalConfig.goalAcceptorItemsRequired; + const percentage = clamp(goalComp.currentDeliveredItems / requiredItemsForSuccess, 0, 1); const center = staticComp.getTileSpaceBounds().getCenter().toWorldSpace(); if (item) { @@ -78,7 +80,7 @@ export class GoalAcceptorSystem extends GameSystemWithFilter { ); } - const isValid = item && goalComp.deliveryHistory.length >= requiredItemsForSuccess; + const isValid = item && goalComp.currentDeliveredItems >= requiredItemsForSuccess; parameters.context.translate(center.x, center.y); parameters.context.rotate((staticComp.rotation / 180) * Math.PI); @@ -90,7 +92,7 @@ export class GoalAcceptorSystem extends GameSystemWithFilter { // progress arc - goalComp.displayPercentage = lerp(goalComp.displayPercentage, percentage, 0.3); + goalComp.displayPercentage = lerp(goalComp.displayPercentage, percentage, 0.2); const startAngle = Math.PI * 0.595; const maxAngle = Math.PI * 1.82; diff --git a/src/js/game/systems/item_processor.js b/src/js/game/systems/item_processor.js index e06d4a21..3794473f 100644 --- a/src/js/game/systems/item_processor.js +++ b/src/js/game/systems/item_processor.js @@ -1,3 +1,4 @@ +import { globalConfig } from "../../core/config"; import { BaseItem } from "../base_item"; import { enumColorMixingResults, enumColors } from "../colors"; import { @@ -572,23 +573,23 @@ export class ItemProcessorSystem extends GameSystemWithFilter { const item = payload.items[0].item; const now = this.root.time.now(); + if (goalComp.item && !item.equals(goalComp.item)) { + goalComp.clearItems(); + } else { + goalComp.currentDeliveredItems = Math.min( + goalComp.currentDeliveredItems + 1, + globalConfig.goalAcceptorItemsRequired + ); + } + if (this.root.gameMode.getIsEditor()) { // while playing in editor, assign the item goalComp.item = payload.items[0].item; - goalComp.deliveryHistory.push({ - item, - time: now, - }); - } else { - // otherwise, make sure it is the same, otherwise reset - if (item.equals(goalComp.item)) { - goalComp.deliveryHistory.push({ - item, - time: now, - }); - } else { - goalComp.deliveryHistory = []; - } } + + goalComp.lastDelivery = { + item, + time: now, + }; } }