Skip to content

Commit

Permalink
Merge branch 'feat-mvp' of github.com:Mississippi-Labs/mississippi in…
Browse files Browse the repository at this point in the history
…to feat-mvp
  • Loading branch information
LidamaoHub committed Nov 7, 2023
2 parents d9f7c05 + 38a1bb3 commit eb1dbee
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 71 deletions.
19 changes: 10 additions & 9 deletions packages/client/src/components/Battle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import btnBg from "@/assets/img/battle/btn-bg.svg";
import Appearance from '@/components/Appearance';
import "./styles.scss";
import { useEntityQuery } from "@latticexyz/react";
import { Has, getComponentValue, NotValue } from '@latticexyz/recs';
import { Has, getComponentValue, NotValue, HasValue } from '@latticexyz/recs';
import { useMUD } from '@/mud/MUDContext';
import { decodeEntity } from "@latticexyz/store-sync/recs";
import { getRandomStr } from '@/utils/utils';
Expand Down Expand Up @@ -63,8 +63,9 @@ export default function Battle(props) {
if (!timeout) {
timeout = setTimeout(async () => {
let resultBattle:any = await forceEnd(battle.id)
console.log(resultBattle)
if (resultBattle.isEnd && resultBattle.winner) {
props.finishBattle(battle.winner, battle.attacker, battle.defender)
props.finishBattle(resultBattle.winner, resultBattle.attacker, resultBattle.defender)
return
}
}, 23000)
Expand All @@ -85,18 +86,18 @@ export default function Battle(props) {
// }
}

const battles = useEntityQuery([Has(BattleList), NotValue(BattleList, {isEnd: true})]).map((entity) => {
const battles = useEntityQuery([Has(BattleList), HasValue(BattleList, {isEnd: false})]).map((entity) => {
let id = decodeEntity({ battleId: "uint256" }, entity);
let battle:any = getComponentValue(BattleList, entity)
battle.id = id.battleId.toString()
return battle;
});
if (battles.length) {
let battleTemp:any = battles.filter((item:any) => (item.attacker.toLocaleLowerCase() == props?.curPlayer?.addr.toLocaleLowerCase() || item.defender.toLocaleLowerCase() == props?.curPlayer?.addr.toLocaleLowerCase()))[0]
if (battleTemp) {
battle = battleTemp
initBattle()
}
let battleTemp:any = battles?.filter((item:any) => (item.attacker.toLocaleLowerCase() == props?.curPlayer?.addr.toLocaleLowerCase() || item.defender.toLocaleLowerCase() == props?.curPlayer?.addr.toLocaleLowerCase()))[0]
if (battleTemp) {
battle = battleTemp
initBattle()
} else {
props.finishBattle()
}

useEffect(() => {
Expand Down
3 changes: 0 additions & 3 deletions packages/client/src/components/UserAddress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const UserAddress = (props: IProps) => {
<CopyToClipboard text={address} onCopy={onCopy}>
<div className="user-address">{addressTxt}</div>
</CopyToClipboard>
<CopyToClipboard text={address} onCopy={onCopy}>
<img src={copyImg} alt="" className="copy-icon"/>
</CopyToClipboard>
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/components/UserAddress/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

.user-address {
padding: 0 20px;
cursor: pointer;
}

.copy-icon {
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/components/UserInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const UserInfo = (props: IUserInfo) => {

const { handheld, head, clothes, gem = 0, userUrl, lootUrl, player } = props;
const lootHasLoaded = (handheld && head && clothes) || (player?.equip?.handheld && player?.equip?.head && player?.equip?.clothes);
console.log(handheld, head, clothes, lootHasLoaded);

return (
<div className={'mi-userinfo-wrapper'}>
Expand All @@ -44,7 +43,7 @@ const UserInfo = (props: IUserInfo) => {
<div className={`user-attr-wrapper ${lootHasLoaded ? 'loaded' : ''}`}>
<dl>
<dt>HP</dt>
<dd><span className="base-attr">{lootHasLoaded ? player?.maxHp : 0}</span><span className="extra-attr">{lootHasLoaded ? player?.maxHp?.toString() : ''}</span></dd>
<dd><span className="base-attr">{lootHasLoaded ? player?.maxHp.toString() : 0}</span><span className="extra-attr">{lootHasLoaded ? player?.maxHp?.toString() : ''}</span></dd>
</dl>
<dl>
<dt>Attack</dt>
Expand All @@ -71,10 +70,11 @@ const UserInfo = (props: IUserInfo) => {
</div>
<div className="right-main-content">
<UserPackage
gem={gem}
gem={player?.oreBalance}
title={'User Package'}
/>
<UserPackage
gem={player?.seasonOreBalance}
title={'Season Package'}
/>
</div>
Expand Down
7 changes: 0 additions & 7 deletions packages/client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ setup().then(async (result) => {
</MUDProvider>
);
const { mount: mountDevTools } = await import("@latticexyz/dev-tools");
const comp = [];
network.world.components.forEach((c) => {
if (comp.findIndex((item) => item.id === c.id) === -1) {
comp.push(c);
}
});
network.world.components = comp;
mountDevTools({
config: mudConfig,
publicClient: network.publicClient,
Expand Down
17 changes: 15 additions & 2 deletions packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function createSystemCalls(
const tx = await worldContract.write.battleInvitation([addr, steps]);
await waitForTransaction(tx);
console.log('battleInvitation success', new Date().getTime(), tx);
return tx
} catch (error) {
console.log('battleInvitation', error);
message.error(error.cause.reason || error.cause.details);
Expand Down Expand Up @@ -239,7 +240,7 @@ export function createSystemCalls(
return getComponentValue(BattleList, encodeEntity({ battleId: "uint256" }, { battleId: battleId}))
} catch (error) {
console.log('forceEnd', error);
message.error(error.cause.reason || error.cause.details);
// message.error(error.cause.reason || error.cause.details);
}
}

Expand All @@ -256,6 +257,17 @@ export function createSystemCalls(
}
}

const submitGem = async () => {
try {
const tx = await worldContract.write.submitGem();
await waitForTransaction(tx);
return tx
} catch (error) {
console.log('submitGem', error);
message.error(error.cause.reason || error.cause.details);
}
}

const getBattlePlayerHp = async (battleId: any, addr: any) => {
const data = await worldContract.read.getBattlePlayerHp([battleId, addr]);
return data
Expand All @@ -280,6 +292,7 @@ export function createSystemCalls(
initUserInfo,
selectBothNFT,
forceEnd,
unlockUserLocation
unlockUserLocation,
submitGem
};
}
4 changes: 2 additions & 2 deletions packages/client/src/mud/getNetworkConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const worlds = worldsJson as Partial<Record<string, { address: string; blockNumb

export async function getNetworkConfig() {
const params = new URLSearchParams(window.location.search);
const chainId = Number(params.get("chainId") || params.get("chainid") || (import.meta.env.DEV ? import.meta.env.TEST_CHAIN_ID : import.meta.env.VITE_CHAIN_ID) || 31337);
// const chainId = 46508363;
// const chainId = Number(params.get("chainId") || params.get("chainid") || (import.meta.env.DEV ? import.meta.env.TEST_CHAIN_ID : import.meta.env.VITE_CHAIN_ID) || 31337);
const chainId = 33784;
// const chainId = 421613;
// console.log(supportedChains);
if (import.meta.env.DEV) {
Expand Down
19 changes: 18 additions & 1 deletion packages/client/src/mud/supportedChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,22 @@ import { sepolia, arbitrumGoerli } from 'viem/chains'
arbitrumGoerli.rpcUrls.default.http = ['https://arbitrum-goerli.infura.io/v3/5ca372516740427e97512d4dfefd9c47'];
arbitrumGoerli.rpcUrls.default.webSocket = [ 'wss://arbitrum-goerli.infura.io/ws/v3/5ca372516740427e97512d4dfefd9c47'];

const testnet = {
name: "Lidamao Testnet",
id: 33784,
network: "lidamao-testnet",
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
rpcUrls: {
default: {
http: ["https://rpc.0xmssp.xyz"],
webSocket: ["https://rpc.0xmssp.xyz"],
},
public: {
http: ["https://rpc.0xmssp.xyz"],
webSocket: ["https://rpc.0xmssp.xyz"],
},
}
}

// If you are deploying to chains other than anvil or Lattice testnet, add them here
export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet, sepolia, arbitrumGoerli];
export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet, sepolia, arbitrumGoerli, testnet];
Loading

0 comments on commit eb1dbee

Please sign in to comment.