From 84a8b6d6b09b79bbb4cfe1ec43f009bedef8bfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Mor=C3=A1n?= Date: Mon, 12 Apr 2021 13:19:22 +0200 Subject: [PATCH 1/7] Rookie scale started --- src/common/types.ts | 1 + src/ui/views/Settings.tsx | 8 +++ src/worker/core/draft/getRookieSalaries.ts | 76 +++------------------- 3 files changed, 19 insertions(+), 66 deletions(-) diff --git a/src/common/types.ts b/src/common/types.ts index d9716599cb..81339c316d 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -415,6 +415,7 @@ export type GameAttributesLeague = { numTeams: number; playerMoodTraits: boolean; pointsFormula: string; + rookieScale: number[][]; spectator: boolean; otl: boolean; otherTeamsWantToHire: boolean; diff --git a/src/ui/views/Settings.tsx b/src/ui/views/Settings.tsx index 11d8f2e2fb..753c064ff7 100644 --- a/src/ui/views/Settings.tsx +++ b/src/ui/views/Settings.tsx @@ -86,6 +86,7 @@ type Key = | "challengeThanosMode" | "realPlayerDeterminism" | "repeatSeason" + | "rookieScale" | "ties" | "otl" | "spectator" @@ -721,6 +722,13 @@ export const options: { godModeRequired: "always", type: "bool", }, + { + category: "Contracts", + key: "rookieScale", + name: "Rookie scale", + godModeRequired: "existingLeagueOnly", + type: "bool", + }, { category: "Contracts", key: "playerMoodTraits", diff --git a/src/worker/core/draft/getRookieSalaries.ts b/src/worker/core/draft/getRookieSalaries.ts index a1ecab1349..23555e0159 100644 --- a/src/worker/core/draft/getRookieSalaries.ts +++ b/src/worker/core/draft/getRookieSalaries.ts @@ -33,76 +33,16 @@ const getRookieSalaries = (): number[] => { } // Default for first round - const firstRoundRookieSalaries = [ - 5000, - 4500, - 4000, - 3500, - 3000, - 2750, - 2500, - 2250, - 2000, - 1900, - 1800, - 1700, - 1600, - 1500, - 1400, - 1300, - 1200, - 1100, - 1000, - 1000, - 1000, - 1000, - 1000, - 1000, - 1000, - 1000, - 1000, - 1000, - 1000, - 1000, - ]; + const firstRoundRookieSalaries = g.get("rookieScale")[0]; // Default for all subsequent rounds - const otherRoundRookieSalaries = [ - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - 500, - ]; + const otherRoundRookieSalaries = g.get("rookieScale")[1]; while (g.get("numActiveTeams") > firstRoundRookieSalaries.length) { //add first round contracts on to end of first round - firstRoundRookieSalaries.push(1000); + firstRoundRookieSalaries.push( + firstRoundRookieSalaries[firstRoundRookieSalaries.length - 1], + ); } while (g.get("numActiveTeams") < firstRoundRookieSalaries.length) { @@ -115,7 +55,11 @@ const getRookieSalaries = (): number[] => { otherRoundRookieSalaries.length ) { // Add min contracts on to end - otherRoundRookieSalaries.push(500); + otherRoundRookieSalaries.push( + otherRoundRookieSalaries[ + otherRoundRookieSalaries[otherRoundRookieSalaries.length - 1] + ], + ); } while ( From 46f53060ccccf2d4397bf623bcb96719c214e880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Mor=C3=A1n?= Date: Thu, 15 Apr 2021 10:26:53 +0200 Subject: [PATCH 2/7] RookieScale applied --- src/common/constants.ts | 2 +- src/common/types.ts | 5 +- src/ui/views/Settings/SettingsForm.tsx | 71 ++++++++++++++-- src/ui/views/Settings/settings.tsx | 80 +++++++++++++++++- src/ui/views/Settings/types.ts | 7 +- src/worker/core/draft/getRookieSalaries.ts | 34 +++----- src/worker/core/draft/selectPlayer.ts | 4 +- .../core/league/createGameAttributes.ts | 68 +++++++++++++++ src/worker/db/connectLeague.ts | 84 +++++++++++++++++++ src/worker/views/settings.ts | 4 + 10 files changed, 325 insertions(+), 34 deletions(-) diff --git a/src/common/constants.ts b/src/common/constants.ts index 2dd545ed08..57ba4d9e86 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -21,7 +21,7 @@ const DIFFICULTY = { Insane: 1, }; -const MAX_SUPPORTED_LEAGUE_VERSION = 43; +const MAX_SUPPORTED_LEAGUE_VERSION = 44; const NO_LOTTERY_DRAFT_TYPES: DraftType[] = [ "freeAgents", diff --git a/src/common/types.ts b/src/common/types.ts index 34340cf9ff..fc27a6ccb6 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -357,6 +357,7 @@ export type GameAttributesLeague = { aiTradesFactor: number; allStarGame: number | null; autoDeleteOldBoxScores: boolean; + automaticRookieScale: boolean; brotherRate: number; budget: boolean; challengeNoDraftPicks: boolean; @@ -415,7 +416,9 @@ export type GameAttributesLeague = { numTeams: number; playerMoodTraits: boolean; pointsFormula: string; - rookieScale: number[][]; + rookieScale: boolean; + rookieScaleMaxContract: number; + rookieScales: number[][]; spectator: boolean; otl: boolean; otherTeamsWantToHire: boolean; diff --git a/src/ui/views/Settings/SettingsForm.tsx b/src/ui/views/Settings/SettingsForm.tsx index 5b16504a84..5f955ecbf9 100644 --- a/src/ui/views/Settings/SettingsForm.tsx +++ b/src/ui/views/Settings/SettingsForm.tsx @@ -904,6 +904,56 @@ const encodeDecodeFunctions = { return parsed; }, }, + rookieScale: { + stringify: (value:number[][]) =>{ + var val = "{" + String(value[0]) + "};{"+ String(value[1]) + "}" + console.log(value) + console.log(val) + return val + }, + parse: (value: string) => { + console.log(value) + var values = value.split(";") + if(values.length != 2 || !value.match("\{.*\}\s*;\s*\{.*\}")){ + throw new Error("Must have two array with brackets separated by a ;. i.e. {1000,800};{1000;750}"); + } + + var val0 = values[0] + var val1 = values[1] + + var scale0 = (val0.match(/\{(.*?)\}/) || ["",""])[1].split(",").map((x,i) => { + if(i==0 && x==""){ + throw new Error("First round scale must have at least one number") + } + var num = Number(x); + if (Number.isNaN(num)){ + throw new Error(x + " is not a number. Rookie scales must be composed of numbers") + }else{ + return num; + } + }); + var scale1 = (val1.match(/\{(.*?)\}/) || ["",""])[1].split(",").map((x,i) => { + if(i==0 && x==""){ + throw new Error("Second round scale must have at least one number") + } + var num = Number(x); + if (Number.isNaN(num)){ + throw new Error(x + " is not a number. Rookie scales must be composed of numbers") + }else{ + return num; + } + }); + + if(scale0.length<1){ + throw new Error("Rookie scale of first round must have at least one value") + } + if(scale1.length<1){ + throw new Error("Rookie scale of second round must have at least one value") + } + + return [scale0,scale1]; + } + }, string: {}, jsonString: { stringify: (value: any) => JSON.stringify(value), @@ -1038,7 +1088,7 @@ const Input = ({ id: string; maxWidth?: true; name: string; - onChange: (event: ChangeEvent) => void; + onChange: (event: ChangeEvent) => void; type: FieldType; value: string; values?: Values; @@ -1077,6 +1127,11 @@ const Input = ({ ); + } else if (type === "rookieScale"){ + inputElement = ( +