Skip to content

Commit

Permalink
uodate: 优化领取宝箱逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
TiyoSheng committed Nov 1, 2023
1 parent 914273e commit 9fc8d29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
5 changes: 4 additions & 1 deletion packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { ClientComponents } from "./createClientComponents";
import { SetupNetworkResult } from "./setupNetwork";
import { singletonEntity, encodeEntity } from "@latticexyz/store-sync/recs";
import { message } from 'antd';
import { get } from "http";

export type SystemCalls = ReturnType<typeof createSystemCalls>;

export function createSystemCalls(
{ worldContract, waitForTransaction }: SetupNetworkResult,
ClientComponents
) {
const { Counter, Player, LootList1, LootList2 } = ClientComponents;
const { Counter, Player, LootList1, LootList2, BoxList } = ClientComponents;
const increment = async () => {
const tx = await worldContract.write.increment();
await waitForTransaction(tx);
Expand Down Expand Up @@ -133,6 +134,7 @@ export function createSystemCalls(
try {
const tx = await worldContract.write.revealBox([boxId]);
await waitForTransaction(tx);
return getComponentValue(BoxList, encodeEntity({ boxId: "uint256" }, { boxId: boxId}));
} catch (error) {
message.error(error.cause.reason);
}
Expand All @@ -143,6 +145,7 @@ export function createSystemCalls(
const tx = await worldContract.write.getCollections([boxId, oreAmount, treasureAmount]);
await waitForTransaction(tx);
} catch (error) {
console.log('getCollections', error);
message.error(error.cause.reason);
}
}
Expand Down
20 changes: 6 additions & 14 deletions packages/client/src/pages/game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import { triggerVertexUpdate } from '@/utils/map';
import { bfs, simplifyMapData } from '@/utils/map';
import useMerkel from '@/hooks/useMerkel';
import { ethers } from 'ethers';

let boxId = ''
import { get } from "http";

const toObject = (obj) => {
return JSON.parse(JSON.stringify(obj, (key, value) =>
Expand Down Expand Up @@ -150,7 +149,7 @@ const Game = () => {
}

const getCollectionsFun = (box: any) => {
boxId = ''
console.log(box);
setContent(
<div className={'mi-modal-content-wrapper'}>
<div className="mi-modal-content">
Expand All @@ -163,7 +162,6 @@ const Game = () => {
<div className="mi-modal-footer">
<button className="mi-btn" onClick={async () => {
await getCollections(box.id, box.oreBalance, box.treasureBalance);
boxId = ''
close();
}}>OK</button>
</div>
Expand All @@ -177,7 +175,7 @@ const Game = () => {
const box:any = getComponentValue(BoxList, entity)
box.id = id.boxId.toString()
return box;
}).filter(e => e.opened == false || (e.opened && (e.oreBalance || e.treasureBalance)));;
}).filter(e => e.opened == false || (e.opened && (e.oreBalance || e.treasureBalance)));

const getBalance = async () => {
const balance = await network.publicClient.getBalance({
Expand All @@ -196,13 +194,6 @@ const Game = () => {
getBalance()
}, []);

useEffect(() => {
if (boxId) {
const box = boxs.find((item) => item.id === boxId);
getCollectionsFun(box);
}
}, [boxs]);


const finishBattle = (e: any) => {
console.log(e);
Expand Down Expand Up @@ -311,8 +302,9 @@ const Game = () => {
console.log(currentBlockNumber, blockNumber, 'currentBlockNumber')
if (currentBlockNumber - blockNumber >= 2) {
clearInterval(interval)
await revealBox(id)
boxId = id
let boxData = await revealBox(id)
boxData.id = id
getCollectionsFun(boxData);
}
}, 1000)
}
Expand Down

0 comments on commit 9fc8d29

Please sign in to comment.