From cd09589f2587c407f9d37bc565aea6a3fa36691c Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Fri, 1 Apr 2022 15:45:12 -0400 Subject: [PATCH] stanek-formula-rework --- src/CotMG/ActiveFragment.ts | 8 ++++---- src/CotMG/StaneksGift.ts | 20 ++++++++++++-------- src/CotMG/ui/FragmentInspector.tsx | 4 +--- src/DevMenu/ui/Stanek.tsx | 6 +++--- src/ScriptEditor/NetscriptDefinitions.d.ts | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/CotMG/ActiveFragment.ts b/src/CotMG/ActiveFragment.ts index b429abbc1..10ecc33df 100644 --- a/src/CotMG/ActiveFragment.ts +++ b/src/CotMG/ActiveFragment.ts @@ -10,7 +10,7 @@ export interface IActiveFragmentParams { export class ActiveFragment { id: number; - avgCharge: number; + highestCharge: number; numCharge: number; rotation: number; x: number; @@ -21,14 +21,14 @@ export class ActiveFragment { this.id = params.fragment.id; this.x = params.x; this.y = params.y; - this.avgCharge = 0; + this.highestCharge = 0; this.numCharge = 0; this.rotation = params.rotation; } else { this.id = -1; this.x = -1; this.y = -1; - this.avgCharge = -1; + this.highestCharge = -1; this.numCharge = -1; this.rotation = -1; } @@ -71,7 +71,7 @@ export class ActiveFragment { const fragment = FragmentById(this.id); if (fragment === null) throw new Error("ActiveFragment id refers to unknown Fragment."); const c = new ActiveFragment({ x: this.x, y: this.y, rotation: this.rotation, fragment: fragment }); - c.avgCharge = this.avgCharge; + c.highestCharge = this.highestCharge; c.numCharge = this.numCharge; return c; } diff --git a/src/CotMG/StaneksGift.ts b/src/CotMG/StaneksGift.ts index acca05d6d..04cde2e74 100644 --- a/src/CotMG/StaneksGift.ts +++ b/src/CotMG/StaneksGift.ts @@ -1,4 +1,4 @@ -import { FactionNames } from '../Faction/data/FactionNames'; +import { FactionNames } from "../Faction/data/FactionNames"; import { Fragment } from "./Fragment"; import { ActiveFragment } from "./ActiveFragment"; import { FragmentType } from "./FragmentType"; @@ -19,19 +19,23 @@ export class StaneksGift implements IStaneksGift { fragments: ActiveFragment[] = []; baseSize(): number { - return StanekConstants.BaseSize + BitNodeMultipliers.StaneksGiftExtraSize + Player.sourceFileLvl(13) + return StanekConstants.BaseSize + BitNodeMultipliers.StaneksGiftExtraSize + Player.sourceFileLvl(13); } width(): number { - return Math.min(Math.floor(this.baseSize() / 2 + 1),StanekConstants.MaxSize); + return Math.max(2, Math.min(Math.floor(this.baseSize() / 2 + 1), StanekConstants.MaxSize)); } height(): number { - return Math.min(Math.floor(this.baseSize() / 2 + 0.6),StanekConstants.MaxSize); + return Math.max(3, Math.min(Math.floor(this.baseSize() / 2 + 0.6), StanekConstants.MaxSize)); } charge(player: IPlayer, af: ActiveFragment, threads: number): void { - af.avgCharge = (af.numCharge * af.avgCharge + threads) / (af.numCharge + 1); - af.numCharge++; + if (threads > af.highestCharge) { + af.numCharge = (af.highestCharge * af.numCharge) / threads + 1; + af.highestCharge = threads; + } else { + af.numCharge += threads / af.highestCharge; + } const cotmg = Factions[FactionNames.ChurchOfTheMachineGod]; cotmg.playerReputation += (player.faction_rep_mult * (Math.pow(threads, 0.95) * (cotmg.favor + 100))) / 1000; @@ -66,7 +70,7 @@ export class StaneksGift implements IStaneksGift { for (const neighboor of neighboors) { boost *= neighboor.fragment().power; } - return CalculateEffect(fragment.avgCharge, fragment.numCharge, fragment.fragment().power, boost); + return CalculateEffect(fragment.highestCharge, fragment.numCharge, fragment.fragment().power, boost); } canPlace(rootX: number, rootY: number, rotation: number, fragment: Fragment): boolean { @@ -126,7 +130,7 @@ export class StaneksGift implements IStaneksGift { clearCharge(): void { this.fragments.forEach((f) => { - f.avgCharge = 0; + f.highestCharge = 0; f.numCharge = 0; }); } diff --git a/src/CotMG/ui/FragmentInspector.tsx b/src/CotMG/ui/FragmentInspector.tsx index 135ca2dc9..8ab8253de 100644 --- a/src/CotMG/ui/FragmentInspector.tsx +++ b/src/CotMG/ui/FragmentInspector.tsx @@ -48,9 +48,7 @@ export function FragmentInspector(props: IProps): React.ReactElement { } const f = props.fragment.fragment(); - let charge = `${numeralWrapper.formatStaneksGiftCharge(props.fragment.avgCharge)} avg. * ${ - props.fragment.numCharge - } times`; + let charge = numeralWrapper.formatStaneksGiftCharge(props.fragment.highestCharge * props.fragment.numCharge); let effect = "N/A"; // Boosters and cooling don't deal with heat. if ([FragmentType.Booster, FragmentType.None, FragmentType.Delete].includes(f.type)) { diff --git a/src/DevMenu/ui/Stanek.tsx b/src/DevMenu/ui/Stanek.tsx index 2a5d49c42..a97d61845 100644 --- a/src/DevMenu/ui/Stanek.tsx +++ b/src/DevMenu/ui/Stanek.tsx @@ -27,20 +27,20 @@ export function Stanek(): React.ReactElement { function addCharge(): void { staneksGift.fragments.forEach((f) => { - f.avgCharge = 1e21; + f.highestCharge = 1e21; f.numCharge = 1e21; }); } function modCharge(modify: number): (x: number) => void { return function (cycles: number): void { - staneksGift.fragments.forEach((f) => (f.avgCharge += cycles * modify)); + staneksGift.fragments.forEach((f) => (f.highestCharge += cycles * modify)); }; } function resetCharge(): void { staneksGift.fragments.forEach((f) => { - f.avgCharge = 0; + f.highestCharge = 0; f.numCharge = 0; }); } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 169b22aed..f91460336 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -4089,7 +4089,7 @@ export interface Fragment { */ export interface ActiveFragment { id: number; - avgCharge: number; + highestCharge: number; numCharge: number; rotation: number; x: number;