Skip to content

Commit

Permalink
fix(tools): 🐛 event pt calc wrong bonus rate
Browse files Browse the repository at this point in the history
forget to calculate master rank bonus and pure vs w/o support unit bonus

fix #353
  • Loading branch information
DNARoma authored and dnaroma committed Dec 29, 2021
1 parent e47b08e commit 63daf95
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 33 deletions.
24 changes: 14 additions & 10 deletions src/components/blocks/TeamBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ import { useCharaName } from "../../utils/i18n";
import { attrIconMap } from "../../utils/resources";
import { useRootStore } from "../../stores/root";
import { observer } from "mobx-react-lite";
import { ISekaiProfile, ISekaiCardTeam } from "../../stores/sekai";
import {
ISekaiProfile,
ISekaiCardTeam,
ISekaiCardState,
} from "../../stores/sekai";
import { autorun } from "mobx";

const useStyle = makeStyles((theme) => ({
Expand All @@ -78,10 +82,10 @@ const useStyle = makeStyles((theme) => ({

const TeamBuilder: React.FC<{
teamCards: number[];
teamCardsStates: ITeamCardState[];
teamCardsStates: ISekaiCardState[];
teamTotalPower: number;
setTeamCards: React.Dispatch<React.SetStateAction<number[]>>;
setTeamCardsStates: React.Dispatch<React.SetStateAction<ITeamCardState[]>>;
setTeamCardsStates: React.Dispatch<React.SetStateAction<ISekaiCardState[]>>;
setTeamTotalPower: React.Dispatch<React.SetStateAction<number>>;
}> = observer(
({
Expand Down Expand Up @@ -135,7 +139,7 @@ const TeamBuilder: React.FC<{
useState<boolean>(false);
const [addCardDialogVisible, setAddCardDialogVisible] =
useState<boolean>(false);
const [editingCard, setEditingCard] = useState<ITeamCardState>();
const [editingCard, setEditingCard] = useState<ISekaiCardState>();
const [isSyncCardState, setIsSyncCardState] = useLocalStorage(
"team-build-use-sekai-card-state",
false
Expand Down Expand Up @@ -252,7 +256,7 @@ const TeamBuilder: React.FC<{
);

const handleClick = useCallback(
(event: React.MouseEvent<HTMLDivElement>, card: ITeamCardState) => {
(event: React.MouseEvent<HTMLDivElement>, card: ISekaiCardState) => {
setAnchorEl(event.currentTarget);
setEditingCard(card);
},
Expand Down Expand Up @@ -671,7 +675,7 @@ const TeamBuilder: React.FC<{
<Grid key={`team-card-${cardId}`} item xs={4} md={2}>
<CardThumbMedium
cardId={cardId}
trained={teamCardsStates[index].trained}
trained={!!teamCardsStates[index].trained}
level={teamCardsStates[index].level}
masterRank={teamCardsStates[index].masterRank}
style={{ cursor: "pointer" }}
Expand Down Expand Up @@ -1118,7 +1122,7 @@ const TeamBuilder: React.FC<{
>
<CardThumb
cardId={cardId}
trained={team.teamCardsStates[0].trained}
trained={!!team.teamCardsStates[0].trained}
/>
</Grid>
))}
Expand Down Expand Up @@ -1220,7 +1224,7 @@ const TeamBuilder: React.FC<{
{editingCard.trainable && (
<Grid item>
<FormControlLabel
control={<Switch checked={editingCard.trained} />}
control={<Switch checked={!!editingCard.trained} />}
label={t("card:trained") as string}
onChange={(e, checked) =>
handleChange(checked, "trained")
Expand All @@ -1230,7 +1234,7 @@ const TeamBuilder: React.FC<{
)}
<Grid item>
<FormControlLabel
control={<Switch checked={editingCard.story1Unlock} />}
control={<Switch checked={!!editingCard.story1Unlock} />}
label={t("card:sideStory1Unlocked") as string}
onChange={(e, checked) =>
handleChange(checked, "story1Unlock")
Expand All @@ -1239,7 +1243,7 @@ const TeamBuilder: React.FC<{
</Grid>
<Grid item>
<FormControlLabel
control={<Switch checked={editingCard.story2Unlock} />}
control={<Switch checked={!!editingCard.story2Unlock} />}
label={t("card:sideStory2Unlocked") as string}
onChange={(e, checked) =>
handleChange(checked, "story2Unlock")
Expand Down
59 changes: 42 additions & 17 deletions src/pages/EventPointCalc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
IEventCard,
IEventDeckBonus,
IEventInfo,
IEventRarityBonusRate,
IGameCharaUnit,
IMusicInfo,
IMusicMeta,
Expand All @@ -48,6 +49,8 @@ import { useDurationI18n } from "../utils/i18nDuration";
import { useScoreCalc } from "../utils/scoreCalc";
import { ContentTrans } from "../components/helpers/ContentTrans";
import TeamBuilder from "../components/blocks/TeamBuilder";
import { ISekaiCardState } from "../stores/sekai";
import { useCurrentEvent } from "../utils/apiClient";

const difficulties: Record<number, string> = {
0: "Easy",
Expand Down Expand Up @@ -87,9 +90,13 @@ const EventPointCalc: React.FC<{}> = () => {
const [events] = useCachedData<IEventInfo>("events");
const [eventCards] = useCachedData<IEventCard>("eventCards");
const [eventDeckBonuses] = useCachedData<IEventDeckBonus>("eventDeckBonuses");
const [eventRarityBonusRates] = useCachedData<IEventRarityBonusRate>(
"eventRarityBonusRates"
);
const [gameCharacterUnits] =
useCachedData<IGameCharaUnit>("gameCharacterUnits");
const [metas] = useMusicMeta();
const { currEvent } = useCurrentEvent();

const {
getCardSkillRates,
Expand All @@ -104,7 +111,7 @@ const EventPointCalc: React.FC<{}> = () => {

const [activeStep, setActiveStep] = useState<number>(0);
const [teamCards, setTeamCards] = useState<number[]>([]);
const [teamCardsStates, setTeamCardsStates] = useState<ITeamCardState[]>([]);
const [teamCardsStates, setTeamCardsStates] = useState<ISekaiCardState[]>([]);
const [teamTotalPower, setTeamTotalPower] = useState<number>(0);
const [selectedSong, setSelectedSong] =
useState<{ id: number; name: string }>();
Expand Down Expand Up @@ -158,20 +165,22 @@ const EventPointCalc: React.FC<{}> = () => {
}, [metas, musics]);

useEffect(() => {
if (events && !selectedEvent)
if (currEvent && !selectedEvent) {
setSelectedEvent({
name: getTranslated(
`event_name:${events[events.length - 1].id}`,
events[events.length - 1].name
`event_name:${currEvent.eventId}`,
currEvent.eventJson.name
),
id: events[events.length - 1].id,
id: currEvent.eventId,
});
setSelectedEventId(currEvent.eventId);
}
if (musics && !selectedSong)
setSelectedSong({
name: getTranslated(`music_titles:${musics[0].id}`, musics[0].title),
id: musics[0].id,
});
}, [events, getTranslated, musics, selectedEvent, selectedSong]);
}, [currEvent, events, getTranslated, musics, selectedEvent, selectedSong]);

useEffect(() => {
if (
Expand All @@ -182,6 +191,7 @@ const EventPointCalc: React.FC<{}> = () => {
gameCharacterUnits &&
selectedEventMode === "existed"
) {
console.log("triggered");
const eventBonuses = eventDeckBonuses
.filter((edb) => edb.eventId === selectedEventId)!
.map((edb) => {
Expand Down Expand Up @@ -243,18 +253,33 @@ const EventPointCalc: React.FC<{}> = () => {
const cardBonus = eventCardBonuses.find(
(ecb) => ecb.cardId === card.id
);
// console.log(cardBonus);
let rarityBonus;
if (eventRarityBonusRates)
rarityBonus = eventRarityBonusRates.find(
(erbr) =>
erbr.cardRarityType === card.cardRarityType &&
erbr.masterRank === teamCard.masterRank
);
// console.log(teamCard, bonus, cardBonus, rarityBonus);
if (!bonus) return sum;
else if (cardBonus)
return sum + bonus.bonusRate + cardBonus.bonusRate;
else return sum + bonus.bonusRate;
else sum += bonus.bonusRate;
if (cardBonus && cardBonus.bonusRate) sum += cardBonus.bonusRate;
if (
!cardBonus &&
card.characterId >= 21 &&
card.supportUnit === "none"
)
sum += 15; // pure VS card bonus
if (rarityBonus) sum += rarityBonus.bonusRate;
return sum;
}, 0)
);
}
}, [
cards,
eventCards,
eventDeckBonuses,
eventRarityBonusRates,
events,
gameCharacterUnits,
selectedEventId,
Expand Down Expand Up @@ -528,12 +553,12 @@ const EventPointCalc: React.FC<{}> = () => {
<FormControlLabel
value="existed"
control={<Radio />}
label={t("event_calc:eventMode.existed")}
label={t("event_calc:eventMode.existed") as string}
/>
<FormControlLabel
value="custom"
control={<Radio />}
label={t("event_calc:eventMode.custom")}
label={t("event_calc:eventMode.custom") as string}
/>
</RadioGroup>
</FormControl>
Expand Down Expand Up @@ -666,17 +691,17 @@ const EventPointCalc: React.FC<{}> = () => {
<FormControlLabel
value="solo"
control={<Radio />}
label={t("music_recommend:modeSelect.solo")}
label={t("music_recommend:modeSelect.solo") as string}
/>
<FormControlLabel
value="multi"
control={<Radio />}
label={t("music_recommend:modeSelect.multi")}
label={t("music_recommend:modeSelect.multi") as string}
/>
<FormControlLabel
value="challenge_live"
control={<Radio />}
label={t("common:challengeLive")}
label={t("common:challengeLive") as string}
/>
</RadioGroup>
</FormControl>
Expand Down Expand Up @@ -727,12 +752,12 @@ const EventPointCalc: React.FC<{}> = () => {
<FormControlLabel
value="all_songs"
control={<Radio />}
label={t("event_calc:songMode.all_songs")}
label={t("event_calc:songMode.all_songs") as string}
/>
<FormControlLabel
value="only_one"
control={<Radio />}
label={t("event_calc:songMode.only_one")}
label={t("event_calc:songMode.only_one") as string}
/>
</RadioGroup>
</FormControl>
Expand Down
13 changes: 10 additions & 3 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ISekaiUserProfileHonor } from "./stores/sekai";
import { ISekaiCardState, ISekaiUserProfileHonor } from "./stores/sekai";

export type ContentTransModeType = "original" | "translated" | "both";
export type DisplayModeType = "dark" | "light" | "auto";
Expand Down Expand Up @@ -529,7 +529,7 @@ export interface ITeamCardState {
export interface ITeamBuild {
id?: number;
teamCards: number[];
teamCardsStates: ITeamCardState[];
teamCardsStates: ISekaiCardState[];
teamTotalPower: number;
}

Expand Down Expand Up @@ -1033,7 +1033,7 @@ export interface IEventCard {
id: number;
cardId: number;
eventId: number;
bonusRate: number;
bonusRate?: number;
}

export interface IGachaCeilItem {
Expand Down Expand Up @@ -1379,3 +1379,10 @@ export interface IBondsReward {
resourceBoxId: number;
description: string;
}

export interface IEventRarityBonusRate {
id: number;
cardRarityType: string;
masterRank: number;
bonusRate: number;
}
2 changes: 2 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
IBondsHonorWord,
IBond,
IBondsReward,
IEventRarityBonusRate,
} from "./../types.d";
import { useAssetI18n, useCharaName } from "./i18n";
import { useLocation } from "react-router-dom";
Expand Down Expand Up @@ -143,6 +144,7 @@ export function useCachedData<
| IBondsHonorWord
| IBond
| IBondsReward
| IEventRarityBonusRate
>(name: string): [T[] | undefined, boolean, any] {
// const [cached, cachedRef, setCached] = useRefState<T[]>([]);
const { region } = useRootStore();
Expand Down
11 changes: 8 additions & 3 deletions src/utils/scoreCalc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useCallback } from "react";
import { sortWithIndices } from ".";
import { ISekaiCardState } from "../stores/sekai";
import {
EventType,
ICardInfo,
IMusicMeta,
ISkillInfo,
ITeamCardState,
// ITeamCardState,
} from "../types";

const boostRate: Record<number, number> = {
Expand All @@ -24,7 +25,7 @@ const boostRate: Record<number, number> = {

export function useScoreCalc() {
const getCardSkillRate = useCallback(
(cards: ICardInfo[], skills: ISkillInfo[], teamCard: ITeamCardState) => {
(cards: ICardInfo[], skills: ISkillInfo[], teamCard: ISekaiCardState) => {
let skillId = cards.filter((it) => it.id === teamCard.cardId)[0].skillId;
let skill = skills.filter((it) => it.id === skillId)[0];
let scoreSkill = skill.skillEffects.filter((it) =>
Expand All @@ -38,7 +39,11 @@ export function useScoreCalc() {
[]
);
const getCardSkillRates = useCallback(
(cards: ICardInfo[], skills: ISkillInfo[], teamCards: ITeamCardState[]) => {
(
cards: ICardInfo[],
skills: ISkillInfo[],
teamCards: ISekaiCardState[]
) => {
let skillRates: number[] = [];
teamCards.forEach((it) => {
skillRates.push(getCardSkillRate(cards, skills, it));
Expand Down

0 comments on commit 63daf95

Please sign in to comment.