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 Oct 31, 2023
2 parents 5f8842a + 9e339ed commit a08502b
Show file tree
Hide file tree
Showing 64 changed files with 213 additions and 139 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Binary file modified packages/client/public/assets/img/duck/Head/Crown.png
Diff not rendered.
Binary file removed packages/client/public/assets/img/duck/Head/Idea.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
17 changes: 10 additions & 7 deletions packages/client/src/components/UserInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ export interface IUserInfo {
clothes: string;
handheld: string;
gem?: number;
userUrl?: string;
lootUrl?: string;
player?: any;
}

const UserInfo = (props: IUserInfo) => {

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

Expand Down Expand Up @@ -41,27 +44,27 @@ const UserInfo = (props: IUserInfo) => {
<div className={`user-attr-wrapper ${lootHasLoaded ? 'loaded' : ''}`}>
<dl>
<dt>HP</dt>
<dd><span className="base-attr">{lootHasLoaded ? 100 : 0}</span><span className="extra-attr">100</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>
<dd><span className="base-attr">{lootHasLoaded ? 20 : 0}</span><span className="extra-attr">1</span></dd>
<dd><span className="base-attr">{lootHasLoaded ? player?.attack?.toString() : 0}</span><span className="extra-attr">{lootHasLoaded ? player?.attack?.toString() : ''}</span></dd>
</dl>
<dl>
<dt>AttackRange</dt>
<dd><span className="base-attr">{lootHasLoaded ? 5 : 0}</span><span className="extra-attr">1</span></dd>
<dd><span className="base-attr">{lootHasLoaded ? player?.attackRange?.toString() : 0}</span><span className="extra-attr">{lootHasLoaded ? player?.attackRange?.toString() : ''}</span></dd>
</dl>
<dl>
<dt>Speed</dt>
<dd><span className="base-attr">{lootHasLoaded ? 2 : 0}</span><span className="extra-attr">2</span></dd>
<dd><span className="base-attr">{lootHasLoaded ? player?.speed?.toString() : 0}</span><span className="extra-attr">{lootHasLoaded ? player?.speed?.toString() : ''}</span></dd>
</dl>
<dl>
<dt>Strength</dt>
<dd><span className="base-attr">{lootHasLoaded ? 20 : 0}</span><span className="extra-attr">1</span></dd>
<dd><span className="base-attr">{lootHasLoaded ? player?.strength?.toString() : 0}</span><span className="extra-attr">{lootHasLoaded ?player?.strength?.toString() : ''}</span></dd>
</dl>
<dl>
<dt>Space</dt>
<dd><span className="base-attr">{lootHasLoaded ? 10 : 0}</span><span className="extra-attr">1</span></dd>
<dd><span className="base-attr">{lootHasLoaded ? player?.space?.toString() : 0}</span><span className="extra-attr">{lootHasLoaded ? player?.space?.toString() : ''}</span></dd>
</dl>
</div>
</div>
Expand Down
143 changes: 107 additions & 36 deletions packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
import { getComponentValue } from "@latticexyz/recs";
import { ClientComponents } from "./createClientComponents";
import { SetupNetworkResult } from "./setupNetwork";
import { singletonEntity } from "@latticexyz/store-sync/recs";
import { singletonEntity, encodeEntity } from "@latticexyz/store-sync/recs";
import { message } from 'antd';

export type SystemCalls = ReturnType<typeof createSystemCalls>;

export function createSystemCalls(
{ worldContract, waitForTransaction }: SetupNetworkResult,
ClientComponents
) {
const { Counter, Player } = ClientComponents;

console.log(ClientComponents, 'ClientComponents')
const { Counter, Player, LootList1, LootList2 } = ClientComponents;
const increment = async () => {
const tx = await worldContract.write.increment();
await waitForTransaction(tx);
return getComponentValue(Counter, singletonEntity);
};

const move = async (steps: any) => {
console.log(worldContract)
try {
const tx = await worldContract.write.move([steps]);
await waitForTransaction(tx);
return {
type: 'success'
}
} catch (error) {
return {
type: 'error',
message: error.cause.reason
}
message.error(error.cause.reason);
}

// return getComponentValue(Player, singletonEntity);
Expand All @@ -39,59 +31,135 @@ export function createSystemCalls(
const getPosition = async (address) => {
const tx = await worldContract.read.getPosition([address]);
const result = await waitForTransaction(tx);
console.log(result);
// return getComponentValue(GameSystem, singletonEntity);
await waitForTransaction(tx);
};

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

const transfer = async (addr: any, transferData: any) => {
const tx = await worldContract.write.transfer([addr, ...transferData]);
await waitForTransaction(tx);
try {
const tx = await worldContract.write.transfer([addr, ...transferData]);
await waitForTransaction(tx);
} catch (error) {
message.error(error.cause.reason);
}
}

const battleInvitation = async (addr: any, steps: any) => {
const tx = await worldContract.write.battleInvitation([addr, steps]);
await waitForTransaction(tx);
try {
const tx = await worldContract.write.battleInvitation([addr, steps]);
await waitForTransaction(tx);
} catch (error) {
message.error(error.cause.reason);
}
}

const confirmBattle = async (buffHash: any, battleId: any) => {
const tx = await worldContract.write.confirmBattle([buffHash, battleId]);
await waitForTransaction(tx);
try {
const tx = await worldContract.write.confirmBattle([buffHash, battleId]);
await waitForTransaction(tx);
} catch (error) {
message.error(error.cause.reason);
}

}

const revealBattle = async (battleId: any, action: any, arg: any, nonce: any) => {
const tx = await worldContract.write.revealBattle([battleId, action, arg, nonce]);
await waitForTransaction(tx);
try {
const tx = await worldContract.write.revealBattle([battleId, action, arg, nonce]);
await waitForTransaction(tx);
} catch (error) {
message.error(error.cause.reason);
}
}

const selectUserNft = async (tokenId: any) => {
const tx = await worldContract.write.selectUserNft([tokenId]);
await waitForTransaction(tx);
const selectUserNft = async (tokenId: any, address: any, nonce: any) => {
try {
const tx = await worldContract.write.selectUserNft([tokenId], {nonce});
await waitForTransaction(tx);
return getComponentValue(Player, encodeEntity({ addr: "address" }, { addr: address}));
} catch (error) {
console.log('selectUserNft', error);
message.error(error.cause.reason);
}
}

const selectLootNFT = async (tokenId: any, address: any, nonce: any) => {
try {
const tx = await worldContract.write.selectLootNFT([tokenId], {nonce});
await waitForTransaction(tx);
let LootList1Data = getComponentValue(LootList1, encodeEntity({ addr: "address" }, { addr: address}));
// let LootList2Data = getComponentValue(LootList2, encodeEntity({ addr: "address" }, { addr: address}));
return LootList1Data
} catch (error) {
console.log('selectLootNFT', error);
message.error(error.cause.reason);
}
}

const openBox = async (boxId: any) => {
const tx = await worldContract.write.openBox([boxId]);
await waitForTransaction(tx);
try {
const tx = await worldContract.write.openBox([boxId]);
await waitForTransaction(tx);
} catch (error) {
message.error(error.cause.reason);
}
}

const revealBox = async (boxId: any) => {
const tx = await worldContract.write.revealBox([boxId]);
await waitForTransaction(tx);
try {
const tx = await worldContract.write.revealBox([boxId]);
await waitForTransaction(tx);
} catch (error) {
message.error(error.cause.reason);
}
}

const getCollections = async (boxId: any, oreAmount: any, treasureAmount: any) => {
const tx = await worldContract.write.getCollections([boxId, oreAmount, treasureAmount]);
await waitForTransaction(tx);
try {
const tx = await worldContract.write.getCollections([boxId, oreAmount, treasureAmount]);
await waitForTransaction(tx);
} catch (error) {
message.error(error.cause.reason);
}
}

const CreateBox = async (x: any, y: any) => {
const tx = await worldContract.write.CreateBox([x, y]);
await waitForTransaction(tx);
try {
const tx = await worldContract.write.CreateBox([x, y]);
await waitForTransaction(tx);
} catch (error) {
message.error(error.cause.reason);
}
}

const setInfo = async (name: any, url: any) => {
try {
const tx = await worldContract.write.setInfo([name, url]);
await waitForTransaction(tx);
return tx
} catch (error) {
message.error(error.cause.reason);
}
}

const initUserInfo = async () => {
try {
const tx = await worldContract.write.initUserInfo();
await waitForTransaction(tx);
return tx
} catch (error) {
message.error(error.cause.reason);
}
}

const getBattlePlayerHp = async (battleId: any, addr: any) => {
Expand All @@ -107,11 +175,14 @@ export function createSystemCalls(
battleInvitation,
confirmBattle,
selectUserNft,
selectLootNFT,
revealBattle,
openBox,
getCollections,
revealBox,
CreateBox,
getBattlePlayerHp
getBattlePlayerHp,
setInfo,
initUserInfo
};
}
33 changes: 16 additions & 17 deletions packages/client/src/pages/game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,30 @@ const Game = () => {

const LootList1Data = useEntityQuery([Has(LootList1)]).map((entity) => {
const loot = getComponentValue(LootList1, entity);
const address = decodeEntity({ addr: "address" }, entity)?.addr?.toLocaleLowerCase() || ''
loot.addr = address
return loot;
})

const LootList2Data = useEntityQuery([Has(LootList2)]).map((entity) => {
const loot = getComponentValue(LootList2, entity);
return loot;
})

console.log(LootList1Data, LootList2Data, 'LootList1Data')
console.log(LootList1Data, 'LootList1Data')

const players = useEntityQuery([Has(Player)]).map((entity) => {
const address = decodeEntity({ addr: "address" }, entity)?.addr?.toLocaleLowerCase() || ''
const player = getComponentValue(Player, entity);
player.addr = address
if (address.toLocaleLowerCase() === account.toLocaleLowerCase()) {
player.equip = {
clothes,
handheld,
head,
player.username = player.name;
LootList1Data.forEach((item) => {
if (item.addr.toLocaleLowerCase() === address.toLocaleLowerCase()) {
let clothes = item.chest.replace(/"(.*?)"/, '').split(' of')[0].replace(/^\s+|\s+$/g,"")
let handheld = item.weapon.replace(/"(.*?)"/, '').split(' of')[0].replace(/^\s+|\s+$/g,"")
let head = item.head.replace(/"(.*?)"/, '').split(' of')[0].replace(/^\s+|\s+$/g,"")
player.equip = {
clothes,
handheld,
head,
}
}
player.username = username;
}
})
return player;
}).filter(e => e.state != 1);
console.log(players, 'players')
Expand Down Expand Up @@ -216,10 +218,7 @@ const Game = () => {
}
}
}, 300);
let result = await move(merkelData);
if (result.type === 'error') {
message.error(result.message);
}
move(merkelData);
};

const showUserInfo = (player) => {
Expand Down
Loading

0 comments on commit a08502b

Please sign in to comment.