Skip to content

Commit

Permalink
add delay
Browse files Browse the repository at this point in the history
  • Loading branch information
TiyoSheng committed Dec 11, 2023
1 parent c527517 commit 1081b38
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
8 changes: 8 additions & 0 deletions packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { SetupNetworkResult } from "./setupNetwork";
import eventEmitter from '../utils/eventEmitter';
import { message } from 'antd';

import { delay } from '../utils/delay';

export type SystemCalls = ReturnType<typeof createSystemCalls>;

let wait = false;
Expand Down Expand Up @@ -78,6 +80,7 @@ export function createSystemCalls(
try {
const tx = await worldContract.write.selectBothNFT([userTokenId, lootTokenId]);
await waitForTransaction(tx);
await delay(300)
return {
playerData: useStore.getState().getValue(tables.PlayerParams, { addr: address }),
lootData: useStore.getState().getValue(tables.LootList1, { addr: address })
Expand Down Expand Up @@ -176,6 +179,7 @@ export function createSystemCalls(
eventEmitter.emit('log', log)
console.log('revealBox success', new Date().getTime(), tx);
wait = false
await delay(300)
return useStore.getState().getValue(tables.BoxList, { boxId })
} catch (error) {
console.log(error)
Expand All @@ -201,6 +205,7 @@ export function createSystemCalls(
log.block = await getBlockNumber(tx)
eventEmitter.emit('log', log)
wait = false
await delay(300)
return {
type: 'success'
}
Expand Down Expand Up @@ -256,6 +261,7 @@ export function createSystemCalls(
log.block = await getBlockNumber(tx)
eventEmitter.emit('log', log)
wait = false
await delay(300)
return {
type: 'success',
data: useStore.getState().getValue(tables.BattleList, { battleId })
Expand Down Expand Up @@ -288,6 +294,7 @@ export function createSystemCalls(
log.block = await getBlockNumber(tx)
eventEmitter.emit('log', log)
wait = false
await delay(300)
return {
type: 'success',
data: useStore.getState().getValue(tables.BattleList, { battleId })
Expand Down Expand Up @@ -320,6 +327,7 @@ export function createSystemCalls(
log.block = await getBlockNumber(tx)
eventEmitter.emit('log', log)
wait = false
await delay(300)
return useStore.getState().getValue(tables.BattleList, { battleId })
} catch (error) {
log.type = 'error'
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/pages/game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Loading from '@/components/Loading';
import {BLOCK_TIME} from '@/config/chain';
import discordImg from '@/assets/img/discord.png';
import { TALK_MAIN } from '@/config/talk';
import { delay } from '../../utils/delay';

const toObject = (obj) => {
return JSON.parse(JSON.stringify(obj, (key, value) =>
Expand Down Expand Up @@ -91,6 +92,7 @@ const Game = () => {
let lootContractAddress = GlobalConfigData[0].lootContract
userContract = new ethers.Contract(userContractAddress, userAbi, wallet)
lootContract = new ethers.Contract(lootContractAddress, lootAbi, wallet)
percentage = 100
}

const LootList1Data = useStore((state: any) => {
Expand Down Expand Up @@ -156,8 +158,6 @@ const Game = () => {
})
});

if (PlayersData.length && PlayersData[0].hp) percentage = 100

const curPlayer = PlayersData.find((player: any) => player.addr.toLocaleLowerCase() == account.toLocaleLowerCase());
if (curPlayer && curPlayer.state == 0 && percentage == 100) {
navigate('/');
Expand Down
20 changes: 10 additions & 10 deletions packages/client/src/pages/test/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,11 @@ const Test = () => {
{
players.map((item, index) => (<div key={index}>
<h6>用户信息 {item.isMe ? '(自己)' : ''}</h6>
<div style={{ marginTop: '8px' }}>addr: {item.addr}</div>
<div style={{ marginTop: '8px' }}>hp: {item.hp.toString()}</div>
<div style={{ marginTop: '8px' }}>attack: {item.attack.toString()}</div>
<div style={{ marginTop: '8px' }}>oreBalance: {item.oreBalance.toString()}</div>
<div style={{ marginTop: '8px' }}>treasureBalance: {item.treasureBalance.toString()}</div>
<div style={{ marginTop: '8px' }}>addr: {item?.addr}</div>
<div style={{ marginTop: '8px' }}>hp: {item?.hp?.toString()}</div>
<div style={{ marginTop: '8px' }}>attack: {item?.attack?.toString()}</div>
<div style={{ marginTop: '8px' }}>oreBalance: {item?.oreBalance?.toString()}</div>
<div style={{ marginTop: '8px' }}>treasureBalance: {item?.treasureBalance?.toString()}</div>
<div style={{ marginTop: '8px' }}>state:{item?.state}</div>
<div style={{ marginTop: '8px' }}>坐标:{item?.x || 0}{item?.y || 0}</div>
</div>))
Expand All @@ -415,11 +415,11 @@ const Test = () => {
{
boxs.map((item, index) => (<div key={index} style={{marginBottom: '20px'}}>
<h6>宝箱信息</h6>
<div style={{ marginTop: '8px' }}>id: {item.id}</div>
<div style={{ marginTop: '8px' }}>opened: {item.opened.toString()}</div>
<div style={{ marginTop: '8px' }}>owner: {item.owner}</div>
<div style={{ marginTop: '8px' }}>oreBalance: {item.opened ? item.oreBalance : '--'}</div>
<div style={{ marginTop: '8px' }}>treasureBalance: {item.opened ? item.treasureBalance : '--'}</div>
<div style={{ marginTop: '8px' }}>id: {item?.id}</div>
<div style={{ marginTop: '8px' }}>opened: {item?.opened.toString()}</div>
<div style={{ marginTop: '8px' }}>owner: {item?.owner}</div>
<div style={{ marginTop: '8px' }}>oreBalance: {item?.opened ? item?.oreBalance : '--'}</div>
<div style={{ marginTop: '8px' }}>treasureBalance: {item?.opened ? item?.treasureBalance : '--'}</div>
<div style={{ marginTop: '8px' }}>坐标:{item?.x || 0}{item?.y || 0}</div>
</div>))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/worlds.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"31337": {
"address": "0x6e9474e9c83676b9a71133ff96db43e7aa0a4342"
"address": "0xe233198863b75acc6e1af43daff3f5918e35875e"
},
"33784": {
"address": "0xe233198863b75acc6e1af43daff3f5918e35875e",
Expand Down

0 comments on commit 1081b38

Please sign in to comment.