Skip to content

Commit

Permalink
Fix rate up calculation including guarantees
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinovantes committed Oct 2, 2024
1 parent e30432d commit 45ebcc4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
17 changes: 13 additions & 4 deletions src/main/ipc/WarpTracker/parseWarps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { Warp } from '@/main/db/models/Warp'

export type BannerWarp = Warp & {
pity: number
isLimited?: boolean
isGuaranteed?: boolean
}

export type BannerHistory = {
Expand All @@ -18,21 +20,28 @@ export type BannerHistory = {
export function parseWarps(warps: Array<Warp>): BannerHistory {
let star5Pity = 0
let star4Pity = 0
let nextIs5050 = true
let next5StarIs5050 = true
let next5StarIsGuaranteed = false
const bannerWarps = new Array<BannerWarp>()

for (const warp of warps.toReversed()) {
const bannerWarp = { ...warp, pity: 0 }
const bannerWarp: BannerWarp = { ...warp, pity: 0 }
bannerWarps.push(bannerWarp)

star5Pity++
star4Pity++

// Assume 4-star and 5-star have separate pity counters
if (warp.rarity === 5) {
const isLimited = isLimitedBanner5Star(warp.itemId)

bannerWarp.pity = star5Pity
bannerWarp.isLimited = isLimited
bannerWarp.isGuaranteed = next5StarIsGuaranteed

star5Pity = 0
nextIs5050 = isLimitedBanner5Star(warp.itemId)
next5StarIs5050 = isLimitedBanner5Star(warp.itemId)
next5StarIsGuaranteed = !next5StarIs5050
}
if (warp.rarity === 4) {
bannerWarp.pity = star4Pity
Expand All @@ -46,7 +55,7 @@ export function parseWarps(warps: Array<Warp>): BannerHistory {
return {
star5Pity,
star4Pity,
nextIs5050,
nextIs5050: next5StarIs5050,
warps: bannerWarps,
}
}
14 changes: 7 additions & 7 deletions src/renderer/client/pages/Banner/BannerPageStats.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { JADES_PER_WARP, GachaBannerType, isLimitedBanner5Star } from '@/common/StarRail'
import { JADES_PER_WARP, GachaBannerType } from '@/common/StarRail'
import { computed } from 'vue'
import { formatPercent } from './formatPercent'
import { BannerWarp } from '@/main/ipc/WarpTracker/parseWarps'
Expand All @@ -17,10 +17,10 @@ const num4Star = computed(() => props.bannerWarps.filter((warp) => warp.rarity =
const percent5StarStr = computed(() => formatPercent(num5Star.value, totalWarps.value))
const percent4StarStr = computed(() => formatPercent(num4Star.value, totalWarps.value))
const midpointWinRateStr = computed<string>(() => {
const star5Items = props.bannerWarps.filter((warp) => warp.rarity === 5)
const limitedCharacters = star5Items.filter((warp) => isLimitedBanner5Star(warp.itemId))
return formatPercent(limitedCharacters.length, star5Items.length)
const rateUpWinRateStr = computed<string>(() => {
const rateUpItems = props.bannerWarps.filter((warp) => warp.rarity === 5 && !warp.isGuaranteed)
const limitedItems = rateUpItems.filter((warp) => warp.isLimited)
return formatPercent(limitedItems.length, rateUpItems.length)
})
</script>

Expand All @@ -41,11 +41,11 @@ const midpointWinRateStr = computed<string>(() => {

<template v-if="props.bannerType === GachaBannerType.EventCharacter">
<strong>50/50 Win Rate</strong>
<span>{{ midpointWinRateStr }}</span>
<span>{{ rateUpWinRateStr }}</span>
</template>
<template v-if="props.bannerType === GachaBannerType.EventLightCone">
<strong>75/25 Win Rate</strong>
<span>{{ midpointWinRateStr }}</span>
<span>{{ rateUpWinRateStr }}</span>
</template>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/client/pages/Banner/WarpListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ const pityColor = computed(() => getPityCssColor(props.bannerWarp))
>
{{ bannerWarp.pity }}
</span>

<q-icon
v-if="bannerWarp.isLimited && !bannerWarp.isGuaranteed"
name="emoji_events"
title="Won Rate-Up"
/>
</h6>

<time
Expand Down Expand Up @@ -82,6 +88,7 @@ const pityColor = computed(() => getPityCssColor(props.bannerWarp))
h6{
display: flex;
align-items: center;
gap: math.div($padding, 2);
color: var(--rarity-color);
font-weight: normal;
Expand All @@ -99,7 +106,6 @@ const pityColor = computed(() => getPityCssColor(props.bannerWarp))
justify-content: center;
border-radius: 4px;
margin-left: math.div($padding, 2);
height: 26px; width: 26px;
}
}
Expand Down

0 comments on commit 45ebcc4

Please sign in to comment.