diff --git a/packages/client/src/components/Battle/index.tsx b/packages/client/src/components/Battle/index.tsx index 82faeeb9..bfbf5c9d 100644 --- a/packages/client/src/components/Battle/index.tsx +++ b/packages/client/src/components/Battle/index.tsx @@ -59,16 +59,17 @@ export default function Battle(props) { const initBattle = (id: any) => { let battle:any = battles.filter((item:any) => item.id.toString() == id)[0] - console.log(battle, id) + if (battle.isEnd && battle.winner) { + clearTimeout(timeout) + props.finishBattle(battle.winner) + return + } if (((battle.attackerState == 1 && battle.defenderState == 0) || (battle.attackerState == 0 && battle.defenderState == 1))) { if (!timeout) { timeout = setTimeout(async () => { let resultBattle:any = await forceEnd(battle.id) console.log(resultBattle) - if (resultBattle.isEnd && resultBattle.winner) { - props.finishBattle(resultBattle.winner) - } - }, 120000) + }, 23000) } } else if (((battle.attackerState == 1 && battle.defenderState == 1) || (battle.attackerState == 2 && battle.defenderState == 1) || (battle.attackerState == 1 && battle.defenderState == 2)) && battleState <= 1) { diff --git a/packages/client/src/pages/game/index.tsx b/packages/client/src/pages/game/index.tsx index 0478a5f3..2791f5cc 100644 --- a/packages/client/src/pages/game/index.tsx +++ b/packages/client/src/pages/game/index.tsx @@ -231,10 +231,8 @@ const Game = () => { if (curPlayer.waiting) { return; } - let txFinished = false; clearInterval(moveInterval.current); let pathIndex = 0; - const timeInterval = ~~(1500 / Number(curPlayer.speed)) moveInterval.current = setInterval(() => { setVertexCoordinate(triggerVertexUpdate(paths[pathIndex], curPlayer, mapDataRef.current, vertexCoordinate)); updatePlayerPosition(curPlayer, paths[pathIndex]); @@ -242,9 +240,6 @@ const Game = () => { pathIndex++; if (pathIndex === paths.length) { clearInterval(moveInterval.current); - if (!txFinished) { - curPlayer.waiting = true; - } const target = paths[pathIndex - 1]; const isDelivery = DELIVERY.x === target.x && DELIVERY.y === target.y; if (isDelivery) { @@ -252,9 +247,9 @@ const Game = () => { submitGem(); } } - }, timeInterval); + }, 300); + curPlayer.waiting = true; const result = await move(merkelData); - txFinished = true; curPlayer.waiting = false; if (result?.type === 'error') { message.error(result.message); diff --git a/packages/client/src/pages/home/index.tsx b/packages/client/src/pages/home/index.tsx index 048c2856..647de925 100644 --- a/packages/client/src/pages/home/index.tsx +++ b/packages/client/src/pages/home/index.tsx @@ -1,10 +1,10 @@ import React, { useEffect, useRef, useState } from 'react'; import Header from '@/pages/home/header'; import './styles.scss'; - +import useModal from '@/hooks/useModal'; import Loading from '@/components/Loading'; import MintList from '@/config/mint'; -import { message, Modal } from 'antd'; +import { message } from 'antd'; import UserInfo from '@/components/UserInfo'; import { UserAddress } from '@/mock/data'; import { UserAddressKey } from '@/config'; @@ -17,14 +17,10 @@ import { Has, getComponentValue } from '@latticexyz/recs'; import { decodeEntity } from "@latticexyz/store-sync/recs"; import { ethers } from 'ethers'; -import useStore from '@/hooks/useStore'; - import lootAbi from '../../../../contracts/out/Loot.sol/MLoot.abi.json' import userAbi from '../../../../contracts/out/User.sol/MUser.abi.json' import pluginAbi from '../../../../contracts/out/Plugin.sol/MPlugin.abi.json' -console.log(pluginAbi, userAbi) - let userContract: any let lootContract: any let pluginContract: any @@ -34,21 +30,19 @@ let lootTokenIds: any const Home = () => { const [messageApi, contextHolder] = message.useMessage(); - const { players } = useStore(); const { components: { GlobalConfig, Player }, systemCalls: { selectBothNFT, joinBattlefield, setInfo, initUserInfo }, network } = useMUD(); - console.log(network, 'network') - const [walletAddress, setWalletAddress] = useState(''); const [walletBalance, setWalletBalance] = useState(''); const [step, setStep] = useState('play'); const usernameRef = useRef(); - const [modalVisible, setModalVisible] = useState(false); - + const { Modal, open, close, setContent } = useModal({ + title: '', + }); const [minting, setMinting] = useState(false); @@ -70,6 +64,13 @@ const Home = () => { const [lootUrl, setLootUrl] = useState(); const [player, setPlayer] = useState(); + const players = useEntityQuery([Has(Player)]).map((entity) => { + const address = decodeEntity({ addr: "address" }, entity)?.addr?.toLocaleLowerCase() || '' + const player = getComponentValue(Player, entity); + player.addr = address + return player; + }) + const curPlayer = players.find(player => player.addr.toLocaleLowerCase() == network?.account.toLocaleLowerCase()); const GlobalConfigData = useEntityQuery([Has(GlobalConfig)]).map((entity) => getComponentValue(GlobalConfig, entity)); @@ -80,7 +81,6 @@ const Home = () => { let rpc = network.walletClient?.chain?.rpcUrls?.default?.http[0] || 'http://127.0.0.1:8545' let provider = new ethers.providers.JsonRpcProvider(rpc) let wallet = new ethers.Wallet(privateKey, provider) - console.log(wallet) let userContractAddress = GlobalConfigData[0].userContract userContract = new ethers.Contract(userContractAddress, userAbi, wallet) userContract?.getUserTokenIdList().then(res => { @@ -110,7 +110,18 @@ const Home = () => { } const createWallet = () => { - setModalVisible(true); + setContent( +
+
+ You have successfully created a wallet.Name your character and start your journey! +
+
+ + +
+
+ ); + open(); } const toMint = async () => { @@ -119,7 +130,7 @@ const Home = () => { return; } setUsername(usernameRef.current.value); - setModalVisible(false); + close(); setStep('mint'); } @@ -136,7 +147,6 @@ const Home = () => { let tokenIds = await Promise.all([userContract.getUserTokenIdList(), lootContract.getUserTokenIdList()]) userTokenIds = tokenIds[0] lootTokenIds = tokenIds[1] - console.log(userTokenIds, lootTokenIds, 'userTokenIds, lootTokenIds') let revealres = await pluginContract.multRevealNFT(lootTokenIds[lootTokenIds.length - 1].toString(), userTokenIds[userTokenIds.length - 1].toString()) await revealres.wait() resolve('success') @@ -213,7 +223,6 @@ const Home = () => { message.error('waiting for wallet connection'); return; } - console.log(curPlayer, 'curPlayer') if (curPlayer && curPlayer.state != 1 && curPlayer.state != 0) { navigate('/game', { state: { @@ -281,22 +290,7 @@ const Home = () => { ) } - setModalVisible(false)} - > -
-
- You have successfully created a wallet.Name your character and start your journey! -
-
- - -
-
-
+ ); }; diff --git a/packages/contracts/worlds.json b/packages/contracts/worlds.json index 36859fe3..f001cf21 100644 --- a/packages/contracts/worlds.json +++ b/packages/contracts/worlds.json @@ -4,7 +4,7 @@ "blockNumber": 29122003 }, "31337": { - "address": "0x144e1475E1ed33B444Ca0E76a1EB7faC245bc16F" + "address": "0x68e44d106b5178b4C79201A8283c0f3e4619505d" }, "421613": { "address": "0x2Bc1034975c3df48D6f3026802f372677844b85d",