Refactor: Centralisation des constantes de configuration
**Motivations:** - Éviter la duplication de code pour la lecture des configurations - Centraliser les valeurs par défaut **Root causes:** - Code dupliqué dans bot-zoo.js et trade.js **Correctifs:** - N/A **Evolutions:** - Ajout de `getUpgradeMaxLevels` dans bot-zoo.js - Ajout de `getSaleListingDefaults` dans trade.js - Mise à jour de la documentation `centralisations-mutualisations.md` **Pages affectées:** - web/js/bot-zoo.js - web/js/trade.js - docs/features/centralisations-mutualisations.md
This commit is contained in:
@@ -15,6 +15,18 @@ import { getEffectiveProfileId, getProfileParams, LEGACY_PROFILE_TO_ID } from ".
|
||||
|
||||
const PROFILE_OPTIONS = ["fast", "slow", "balanced"];
|
||||
|
||||
/**
|
||||
* Max levels for plot, conveyor/school, and truck from config.
|
||||
* @returns {{ plotMax: number, skillMax: number, truckMax: number }}
|
||||
*/
|
||||
function getUpgradeMaxLevels() {
|
||||
return {
|
||||
plotMax: GameConfig.Plot?.MaxLevel ?? 8,
|
||||
skillMax: GameConfig.Conveyor?.MaxLevel ?? 8,
|
||||
truckMax: (GameConfig.Truck && GameConfig.Truck.MaxLevel) ?? 5,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {import("./types.js").BotState}
|
||||
*/
|
||||
@@ -146,12 +158,10 @@ export function ensureBotState(zoo, isPlayer) {
|
||||
function botDecideUpgrade(state, zoo, opts) {
|
||||
const { b, rng, params } = opts;
|
||||
const { spendThreshold, upgradeChance } = params;
|
||||
const { plotMax, skillMax, truckMax } = getUpgradeMaxLevels();
|
||||
const plotCost = getPlotUpgradeCost(b.plotLevel);
|
||||
const plotMax = GameConfig.Plot?.MaxLevel ?? 8;
|
||||
const skillCost = getSchoolUpgradeCost(b.conveyorLevel);
|
||||
const skillMax = GameConfig.Conveyor?.MaxLevel ?? 8;
|
||||
const truckCost = getTruckUpgradeCost(b.truckLevel);
|
||||
const truckMax = (GameConfig.Truck && GameConfig.Truck.MaxLevel) ?? 5;
|
||||
const canUpgradePlot = b.plotLevel < plotMax && b.coins >= plotCost * spendThreshold;
|
||||
const canUpgradeSkill = b.conveyorLevel < skillMax && b.coins >= skillCost * spendThreshold;
|
||||
const canUpgradeTruck = b.truckLevel < truckMax && b.coins >= truckCost * spendThreshold;
|
||||
@@ -287,12 +297,10 @@ const PLAYER_AUTO_MAX_INTERVAL = 28;
|
||||
*/
|
||||
function playerAutoDoOneUpgrade(state, params, rng) {
|
||||
const { spendThreshold, upgradeChance } = params;
|
||||
const { plotMax, skillMax, truckMax } = getUpgradeMaxLevels();
|
||||
const plotCost = getPlotUpgradeCost(state.plotLevel ?? 1);
|
||||
const plotMax = GameConfig.Plot?.MaxLevel ?? 8;
|
||||
const skillCost = getConveyorUpgradeCost(state.conveyorLevel ?? 1);
|
||||
const skillMax = GameConfig.Conveyor?.MaxLevel ?? 8;
|
||||
const truckCost = getTruckUpgradeCost(state.truckLevel ?? 1);
|
||||
const truckMax = (GameConfig.Truck && GameConfig.Truck.MaxLevel) ?? 5;
|
||||
const canPlot = (state.plotLevel ?? 1) < plotMax && state.coins >= plotCost * spendThreshold;
|
||||
const canSkill = (state.conveyorLevel ?? 1) < skillMax && state.coins >= skillCost * spendThreshold;
|
||||
const canTruck = (state.truckLevel ?? 1) < truckMax && state.coins >= truckCost * spendThreshold;
|
||||
|
||||
Reference in New Issue
Block a user