Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
fix(trade): Trigger doesn't respect catpower
Browse files Browse the repository at this point in the history
Previous trading behavior was confusing. When trades were "limited" and considered profitable, KS might trade on almost every tick of the game. Only when the trade was _unlimited_ (confusingly) would gold be taken into account. Catpower was always ignored, which conflicts with potential trading goals of the player.
  • Loading branch information
oliversalzburg committed Sep 21, 2022
1 parent 8b427d0 commit fbd3ba7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/userscript/source/TradeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ export class TradeManager {
}

autoTrade(cacheManager?: CacheManager) {
const catpower = this._workshopManager.getResource("manpower");
const gold = this._workshopManager.getResource("gold");
const requireTrigger = this._host.options.auto.trade.trigger;

// We should only trade if catpower and gold hit the trigger value.
// Trades can additionally require specific resources. We will check for those later.
if (
catpower.value / catpower.maxValue < requireTrigger ||
gold.value / gold.maxValue < requireTrigger
) {
return;
}

this.manager.render();

// If we can't make any trades, bail out.
Expand All @@ -29,8 +42,6 @@ export class TradeManager {
// The races we might want to trade with during this frame.
const trades: Array<Race> = [];

const gold = this._workshopManager.getResource("gold");
const requireTrigger = this._host.options.auto.trade.trigger;
const season = this._host.gamePage.calendar.getCurSeason().name;

// Determine how many races we will trade with this cycle.
Expand All @@ -50,7 +61,7 @@ export class TradeManager {
}

// Determine which resource the race requires for trading, if any.
const require = !trade.require ? false : this._workshopManager.getResource(trade.require);
const require = trade.require ? this._workshopManager.getResource(trade.require) : false;

// Check if this trade would be profitable.
const profitable = this.getProfitability(name);
Expand All @@ -61,8 +72,8 @@ export class TradeManager {
// If this trade is not limited, it must either not require anything, or
// the required resource must be over the trigger value.
// Additionally, gold must also be over the trigger value.
(!require || requireTrigger <= require.value / require.maxValue) &&
requireTrigger <= gold.value / gold.maxValue
!require ||
requireTrigger <= require.value / require.maxValue
) {
trades.push(name);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/userscript/source/options/TradingSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export type TradingSettingsItem = SettingToggle & {
spring: boolean;
$spring?: JQuery<HTMLElement>;

/**
* A resource that is required to trade with the race.
*/
require: Requirement;
};

Expand Down

0 comments on commit fbd3ba7

Please sign in to comment.