From f07aa9a2a7ff995b9e37d7883bb9f1f71217b877 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com>
Date: Thu, 15 Aug 2024 14:06:57 -0500
Subject: [PATCH] fix: variable most optimal shell
---
.../[id]/components/Characteristics/index.tsx | 2 +-
src/core/blitzkit/resolveDpm.ts | 24 ++++++++++++-------
src/core/blitzkit/tankCharacteristics.ts | 19 +++++++++++----
3 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx b/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx
index 77eb8e3f5..426af6b45 100644
--- a/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx
+++ b/src/app/tools/tankopedia/[id]/components/Characteristics/index.tsx
@@ -193,7 +193,7 @@ export function Characteristics() {
{gun.type === 'autoReloader' ? (
<>
- {stats.mostOptimalShellIndex}
+ {stats.mostOptimalShellIndex! + 1}
{stats.shellReloads!.map((reload, index) => (
diff --git a/src/core/blitzkit/resolveDpm.ts b/src/core/blitzkit/resolveDpm.ts
index c9956f5c3..2cf3ad9e5 100644
--- a/src/core/blitzkit/resolveDpm.ts
+++ b/src/core/blitzkit/resolveDpm.ts
@@ -18,15 +18,21 @@ export function resolveDpm(
(gun.reload * reloadCoefficient +
(gun.count - 1) * gun.intraClip * intraClipCoefficient);
} else {
- if (gun.reload[0] < gun.reload[1] + gun.intraClip) {
- // first shell's the best
- dps = alpha / (gun.reload[0] * reloadCoefficient);
- } else {
- dps =
- alpha /
- (gun.reload.at(-1)! * reloadCoefficient +
- gun.intraClip * intraClipCoefficient);
- }
+ const mostOptimalShell = gun.reload.reduce((current, reloadRaw, index) => {
+ const reload =
+ reloadRaw * reloadCoefficient +
+ (index > 0 ? gun.intraClip * intraClipCoefficient : 0);
+
+ if (current === null || reload < current.reload) {
+ return { index, reload };
+ }
+ return current;
+ }, null)!;
+
+ dps = alpha / mostOptimalShell?.reload;
}
return dps * 60;
diff --git a/src/core/blitzkit/tankCharacteristics.ts b/src/core/blitzkit/tankCharacteristics.ts
index 314366b21..5eee4c6bf 100644
--- a/src/core/blitzkit/tankCharacteristics.ts
+++ b/src/core/blitzkit/tankCharacteristics.ts
@@ -330,11 +330,22 @@ export function tankCharacteristics(
reloadCoefficient,
intraClipCoefficient,
);
+ const intraClip =
+ gun.type === 'regular' ? undefined : gun.intraClip * intraClipCoefficient;
const mostOptimalShellIndex =
gun.type === 'autoReloader'
- ? gun.reload[0] + gun.intraClip < gun.reload[1]
- ? 1
- : gun.reload.length
+ ? gun.reload.reduce(
+ (current, reloadRaw, index) => {
+ const reload =
+ reloadRaw * reloadCoefficient + (index > 0 ? intraClip! : 0);
+
+ if (current === null || reload < current.reload) {
+ return { index, reload };
+ }
+ return current;
+ },
+ null,
+ )!.index
: undefined;
const damage = shell.damage.armor * damageCoefficient;
const dpmEffective =
@@ -366,8 +377,6 @@ export function tankCharacteristics(
: undefined;
const shellReload =
gun.type === 'autoReloader' ? undefined : gun.reload * reloadCoefficient;
- const intraClip =
- gun.type === 'regular' ? undefined : gun.intraClip * intraClipCoefficient;
const caliber = shell.caliber;
const penetration =
resolveNearPenetration(shell.penetration) * penetrationCoefficient;