Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to modify or remove the 125% trade rule #403

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/defaultGameAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const defaultGameAttributes: GameAttributesLeagueWithHistory = {
numGames: 82, // per season
numGamesDiv: 16,
numGamesConf: 36,
tradeMatchingPercentage: 125,
otherTeamsWantToHire: false,
numPeriods: 4, // per game
quarterLength: 12, // [minutes]
Expand Down
6 changes: 2 additions & 4 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ export type GameAttributesLeague = {
numGames: number;
numGamesDiv: number | null;
numGamesConf: number | null;
tradeMatchingPercentage: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this down so it's in alphabetical order.

numGamesPlayoffSeries: number[];
numPeriods: number;
numPlayersDunk: number;
Expand Down Expand Up @@ -554,6 +555,7 @@ export type GameAttributesLeague = {
stopOnInjury: boolean;
stopOnInjuryGames: number;
tiebreakers: (keyof typeof TIEBREAKERS)[];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a new line here.

teamInfoCache: {
abbrev: string;
region: string;
Expand Down Expand Up @@ -1212,8 +1214,6 @@ export type Local = {
autoPlayUntil?: {
season: number;
phase: number;

// Time in milliseconds of the start of auto play
Comment on lines -1215 to -1216
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this back.

start: number;
};
autoSave: boolean;
Expand Down Expand Up @@ -1714,5 +1714,3 @@ export type HeadToHead = {
>
>;
};

export type GetCopyType = "noCopyCache";
Comment on lines -1717 to -1718
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this back.

19 changes: 19 additions & 0 deletions src/ui/views/Settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ export const settings: {
</p>
</>
),

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a new line here.

validator: value => {
if (value > 1) {
throw new Error("Value cannot be greater than 1");
Expand All @@ -1003,6 +1004,24 @@ export const settings: {
}
},
},
{
category: "Schedule",
key: "tradeMatchingPercentage",
name: "Trade Matching Percentage",
godModeRequired: "existingLeagueOnly",
type: "int",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch this to intOrNull so that blank is disabled, rather than 0. I think that's a little more straightforward.

descriptionLong: (
<>
<p>
Set this to whatever value you want for the trades to match
contract-wise. In real life, the percentage is 125%, but this allows
you to modify this.
</p>

<p>Set this to 0 to turn off the rule</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the text to:

<p>If you have the Hard Cap setting disabled, teams can make trades that increase their payroll beyond the salary cap. To limit the amount they can exceed the salary cap in a trade, their total incoming contracts must be less than X% of their outgoing contracts. By default this value is 125%.</p>
<p>Leave blank to disable this rule and allow any trades over the cap.</p>

</>
),
},
{
category: "Playoffs",
key: "playoffsByConf",
Expand Down
18 changes: 15 additions & 3 deletions src/worker/core/trade/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { team } from "..";
import { idb } from "../../db";
import { g, helpers } from "../../util";
import type { TradeSummary, TradeTeams } from "../../../common/types";
import { league } from "src/worker/core";
league.loadGameAttributes();
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete these lines, they are not necessary and will cause errors in some situations.


/**
* Create a summary of the trade, for eventual display to the user.
Expand Down Expand Up @@ -101,9 +103,13 @@ const summary = async (teams: TradeTeams): Promise<TradeSummary> => {
}
}),
);
if (g.get("tradeMatchingPercentage") === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it was changed to intOrNull, this should compare against null now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you return here, then the hardCapCondition code below never runs. To fix that, add && !g.get("hardCap") to this condition.

return s;
}
const softCapCondition =
!g.get("hardCap") &&
((ratios[0] > 125 && overCap[0]) || (ratios[1] > 125 && overCap[1]));
((ratios[0] > g.get("tradeMatchingPercentage") && overCap[0]) ||
(ratios[1] > g.get("tradeMatchingPercentage") && overCap[1]));

const overCapAndIncreasing = (i: 0 | 1) =>
overCap[i] && s.teams[i].payrollAfterTrade > s.teams[i].payrollBeforeTrade;
Expand All @@ -113,8 +119,14 @@ const summary = async (teams: TradeTeams): Promise<TradeSummary> => {

if (softCapCondition) {
// Which team is at fault?;
const j = ratios[0] > 125 ? 0 : 1;
s.warning = `The ${s.teams[j].name} are over the salary cap, so the players it receives must have a combined salary of less than 125% of the salaries of the players it trades away. Currently, that value is ${ratios[j]}%.`;
const j = ratios[0] > g.get("tradeMatchingPercentage") ? 0 : 1;
s.warning = `The ${
s.teams[j].name
} are over the salary cap, so the players it receives must have a combined salary of less than ${g.get(
"tradeMatchingPercentage",
)}% of the salaries of the players it trades away. Currently, that value is ${
ratios[j]
}%.`;
} else if (hardCapCondition) {
const j = overCapAndIncreasing(0) ? 0 : 1;
const amountIncrease =
Expand Down
2 changes: 2 additions & 0 deletions src/worker/views/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const keys = [
"stopOnInjury",
"stopOnInjuryGames",
"aiJerseyRetirement",
"tradeMatchingPercentage",
"numPeriods",
"tiebreakers",
"pointsFormula",
Expand Down Expand Up @@ -143,6 +144,7 @@ const updateSettings = async (inputs: unknown, updateEvents: UpdateEvents) => {
minContractLength: g.get("minContractLength"),
maxContractLength: g.get("maxContractLength"),
aiTradesFactor: g.get("aiTradesFactor"),
tradeMatchingPercentage: g.get("tradeMatchingPercentage"),
injuryRate: g.get("injuryRate"),
homeCourtAdvantage: g.get("homeCourtAdvantage"),
rookieContractLengths: g.get("rookieContractLengths"),
Expand Down