DLFCHOAE5EC4CW32LEGVN4ZAFSCI6464NUESLT6Q5JY5HEMSTGSAC
ZAELBVLBG3NBWAQGDXMTB7VODK2VUDIENBWTPBGWI5ZTAV4NGUMQC
LMYKP3NXNC7GOQOBBJI5PKDHPAVNS4G7D4WP23UW7DY6AEFBQ3SAC
FK4UWFPGA4N3YZFF2KRI3H5EVJB3IPF5I3MMTL2CLB4KAGTYIIKAC
FKXXRDR4KMJC5AJ7453GMNMPXZ5ANS3V3OXEK5NXNRUTP2B7IGLAC
WXZF76NH4QIML4LVC7WQKUN56A7SR6UPH5IAE2UVFTZUVK7BEP6AC
QDCUZEYTKURHBOP65DP5VYAPGHNXPTXIF3S3VTDZ3WGBZ3BI3DHQC
PZNEDCRDS5IBR7QDPHTW5HZRMQAZFIF7VB3IKWPZDC7IALHZKHWAC
AKJYQ7DS4ZQBUVXA4QOKL46X6MOZI4HK5HSDT6JZWDZHQ6UMPXFAC
DPJCZOPIKAKQIS4YRXETBSJA5ZTL2KQESSJE2TEZFLRQARXUVFXQC
BDMXIXECYJQDF66EF2TSVVHWIJ5CC22LUFOAOO2Y6YTZZPI3GOYQC
Z3JKY7LD67ZSXVTRHCWEQBMSL32YBBSG3S5GXG3FJMDGHG5MYXCAC
OAY5NOOTDF5QELB64LYDGSKANR33WIH4QKNRBO437TMUMAQ5CWRQC
Z5I5KK7NX6RS23QAB7ISLQCM5Z6TMVZK532NPSE7CO4MNXNKVKMAC
5ACOL4LAIQBXUKJS4FLNBTNEULQJDPNBQRPXTUON6AETQWQQHMMQC
ZYZ7V2E7EPQ6BE4KET2U3JJN2FM74DA7ZVVX7SUQDYNOUJETBBUAC
inputAmount: number | string;
inputTitle: string;
outputScore: number;
outputDescription: string;
// inputAmount: number | string;
// inputTitle: string;
// outputScore: number;
// outputDescription: string;
scoreAmount: number;
scoreReason: string;
function calculateQuestScoreReward(grade: Grade): QuestScoreReward {
const scoreComponents = [
{
scoreReason: 'Quest completed',
scoreAmount: 50,
},
{
scoreReason: `Efficiency: "${grade}"`,
scoreAmount: remapEfficiencyGradeToNumber(grade) * 25,
}
];
const total = scoreComponents.reduce((pv, cv) => pv + cv.scoreAmount, 0);
return {
total,
scoreComponents,
};
}
const [scoreDetails, setScoreDetails] = useState<QuestScoreDetails>({
total: 0,
scoreComponents: [],
});
/**
* activeQuest === undefined => no active quest, need to start quest
* isQuestComplete => can finish the quest to generate rewards
* rewards ready => can accept rewards to increment score; cannot generate a new quest
*/
function calculateQuestScoreDetails() {
const questScore: { scoreComponents: ScoreComponent[] } = {
scoreComponents: [],
};
questScore.scoreComponents.push({
inputAmount: 1,
inputTitle: "quest completed",
outputScore: 5,
outputDescription: "",
});
questScore.scoreComponents.push({
inputAmount: "",
inputTitle: "efficiency grade: " + efficiencyGrade,
outputScore: Math.floor(10 / (remapEfficiencyGradeToNumber(efficiencyGrade) + 1)),
outputDescription: "",
});
const total = questScore.scoreComponents.reduce(
(subtotal, prev) => subtotal + prev.outputScore,
0
);
console.log(total);
return { ...questScore, total };
}
const [didAcceptRewards, setDidAcceptRewards] = useState(true);
const [scoreReward, setScoreReward] = useState<QuestScoreReward | undefined>();
// function calculateQuestScoreReward() {
// const questScore: { scoreComponents: ScoreComponent[] } = {
// scoreComponents: [],
// };
// questScore.scoreComponents.push({
// inputAmount: 1,
// inputTitle: "quest completed",
// outputScore: 5,
// outputDescription: "",
// });
// questScore.scoreComponents.push({
// inputAmount: "",
// inputTitle: "efficiency grade: " + efficiencyGrade,
// outputScore: Math.floor(10 / (remapEfficiencyGradeToNumber(efficiencyGrade) + 1)),
// outputDescription: "",
// });
// const total = questScore.scoreComponents.reduce(
// (subtotal, prev) => subtotal + prev.outputScore,
// 0
// );
// console.log(total);
// return { ...questScore, total };
// }
const doClaimReward = () => {
const questScore = calculateQuestScoreDetails();
updaters.score.enqueueUpdate((lastScore) => {
// console.log({ score, lastScore, questScore });
// console.log("updating score");
return lastScore + questScore.total;
});
const handleStartQuest = () => {
// setOldPoints()
createQuestCb();
};
const doFinishQuest = () => {
// updaters.score.enqueueUpdate((lastScore) => {
// // console.log({ score, lastScore, questScore });
// // console.log("updating score");
// return lastScore + questScore.total;
// });
const handleStartQuest = () => {
// setOldPoints()
createQuestCb();
const doClaimRewards = () => {
if (scoreReward) {
updaters.score.enqueueUpdate((prev) => {
return prev + scoreReward.total;
});
setDidAcceptRewards(true);
// setScoreReward(undefined);
}
{isQuestComplete ? (
<>
<br></br>
<button
className="button"
onClick={() => {
doClaimReward();
}}
>
Finish quest
</button>
</>
) : (
<></>
)}
{isQuestComplete ? (
<>
<br></br>
<button className="button" onClick={doFinishQuest}>
Finish quest
</button>
</>
) : (
<></>
)}
const [didAcceptRewards, setDidAcceptRewards] = useState(true);
useEffect(() => {
// console.log({ scoreDetails });
if (!scoreDetails || scoreDetails.total === 0) return;
setDidAcceptRewards(false);
}, [scoreDetails]);
if (scoreReward === undefined) {
return (<> </>);
}
{!didAcceptRewards && (
<>
<h3>Quest Rewards</h3>
{!!(scoreDetails?.total) && (
<> +{scoreDetails?.total} to your score! </>
)}
<br></br>
{scoreDetails?.scoreComponents.map((scoreComponent) => {
return (
<React.Fragment key={scoreComponent.inputTitle}>
<br></br>
<div>
{scoreComponent.outputDescription &&
scoreComponent.outputDescription + ": "}
{formatDelta(scoreComponent.outputScore)} score for{" "}
{scoreComponent.inputAmount} {scoreComponent.inputTitle}
</div>
</React.Fragment>
);
})}
<br></br>
<button onClick={() => setDidAcceptRewards(true)}>Claim rewards!</button>
</>
<h3>Quest Rewards</h3>
<div>+{scoreReward.total} to your score! </div>
<br></br>
<table className={classnames({ table: true })}>
{scoreReward.scoreComponents.map((it) => (
<tr>
<td> +{it.scoreAmount} score </td>
<td> {it.scoreReason} </td>
</tr>))
}
</table>
<br></br>
{(
didAcceptRewards ? (<> </>) :
(
<button
className="button"
onClick={() => doClaimRewards()}>
Claim rewards!
</button>
)