(0);
+
+ const gachaKit = useMemo(() => {
+ return poolData
+ ? new GenshinGachaKit(util.poolStructureConverter(poolData))
+ : null;
+ }, [poolData]);
+ const handleGacha = useCallback(
+ (num) => {
+ if (!gachaKit) {
+ return;
+ }
+
+ const res = gachaKit.multiWish(num);
+ showToasts('抽卡结果: ' + res.map((item) => item.name).join(','));
+
+ setGachaCount(gachaKit.getCounter('total') as number);
+ setGachaResult(JSON.parse(JSON.stringify(gachaKit.getResult())));
+ },
+ [gachaKit]
+ );
+
+ return { handleGacha, gachaResult, gachaCount };
+}
+
export const GachaPool: React.FC<{
gachaId: string;
}> = React.memo((props) => {
const { value: poolData } = useAsync(() => {
return util.getGachaData(props.gachaId);
}, [props.gachaId]);
+ const { handleGacha, gachaResult, gachaCount } = useWish(poolData);
if (!poolData) {
return Loading...
;
@@ -42,6 +89,31 @@ export const GachaPool: React.FC<{
+
+
+
+
+
+ {gachaCount > 0 && (
+
+
已抽: {gachaCount} 次
+
+
+ 5星:
+
+
+ 4星:
+
+
+ 3星:
+
+
+ )}
+
diff --git a/web/plugins/com.msgbyte.genshin/src/GenshinPanel/utils.ts b/web/plugins/com.msgbyte.genshin/src/GenshinPanel/utils.ts
new file mode 100644
index 00000000..d6fe3801
--- /dev/null
+++ b/web/plugins/com.msgbyte.genshin/src/GenshinPanel/utils.ts
@@ -0,0 +1,9 @@
+import type { AppGachaItem } from 'genshin-gacha-kit';
+
+export function getAppGachaItemText(item: AppGachaItem) {
+ if (item.count >= 2) {
+ return `${item.name}(${item.count})`;
+ } else {
+ return item.name;
+ }
+}