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
Vivomo committed Oct 26, 2023
2 parents a7b9068 + 17e7806 commit ebe2e4a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export function createSystemCalls(
await waitForTransaction(tx);
}

const transfer = async (transferData: any) => {
const tx = await worldContract.write.transfer([...transferData]);
const transfer = async (addr: any, transferData: any) => {
const tx = await worldContract.write.transfer([addr, ...transferData]);
await waitForTransaction(tx);
}

Expand Down
21 changes: 10 additions & 11 deletions packages/client/src/pages/test/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import { getRandomStr } from '../../utils/utils';
import './index.scss';

const abi = [{"inputs":[{"internalType":"uint256","name":"_waitBlockCount","type":"uint256"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_notRevealedInfo","type":"string"},{"internalType":"string","name":"_revealedDesc","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"randomId","type":"uint256"},{"indexed":false,"internalType":"address","name":"author","type":"address"}],"name":"NewRandom","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"randomId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"randomList","outputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"address","name":"author","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"revealNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"userList","outputs":[{"internalType":"uint256","name":"randomId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"HP","type":"uint256"},{"internalType":"uint256","name":"Attack","type":"uint256"},{"internalType":"uint256","name":"AttackRange","type":"uint256"},{"internalType":"uint256","name":"Speed","type":"uint256"},{"internalType":"uint256","name":"Strength","type":"uint256"},{"internalType":"uint256","name":"Space","type":"uint256"},{"internalType":"enum MRandom.RandomState","name":"state","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"waitBlockCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
const contractAddress = '0x5FbDB2315678afecb367f032d93F642f64180aa3'
const rpc = 'http://127.0.0.1:8545'

const Test = () => {
const [stepData, setStepData] = useState([]);
const [transferData, setTransferData] = useState([]);
const [battleData, setBattleData] = useState([]);
const [confirmBattleData, setConfirmBattleData] = useState(['Attack', 1]);
const [confirmBattleData, setConfirmBattleData] = useState(['attack', 1]);
const [battlesData, setBattlesData] = useState([]);
const [boxData, setBoxData] = useState([]);
const [boxId, setBoxId] = useState([]);
Expand Down Expand Up @@ -99,10 +97,10 @@ const Test = () => {

const mintFun = () => {
let privateKey = network.privateKey
let provider = new ethers.providers.JsonRpcProvider(rpc)
let provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545')
let wallet = new ethers.Wallet(privateKey, provider)
console.log(wallet)
let userContractAddress = contractAddress
let userContractAddress = '0x2498e8059929e18e2a2cED4e32ef145fa2F4a744'
let userContract = new ethers.Contract(userContractAddress, abi, wallet)
console.log(userContract)
userContract.mint().then(async res => {
Expand All @@ -116,10 +114,10 @@ const Test = () => {

const revealNFTFun = () => {
let privateKey = network.privateKey
let provider = new ethers.providers.JsonRpcProvider(rpc)
let provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545')
let wallet = new ethers.Wallet(privateKey, provider)
console.log(wallet)
let userContractAddress = contractAddress
let userContractAddress = '0x2498e8059929e18e2a2cED4e32ef145fa2F4a744'
let userContract = new ethers.Contract(userContractAddress, abi, wallet)
userContract.revealNFT(revealNFTData).then(async res => {
console.log(res)
Expand Down Expand Up @@ -194,7 +192,7 @@ const Test = () => {

const transferPlayer = () => {
console.log(transferData, 'transfer')
transfer(transferData);
transfer(account, transferData);
}

const battleInvitationFun = () => {
Expand Down Expand Up @@ -289,6 +287,7 @@ const Test = () => {
<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' }}>坐标:{item?.x || 0}{item?.y || 0}</div>
Expand Down Expand Up @@ -388,9 +387,9 @@ const Test = () => {
<div className="title">攻击策略</div>
<div className="input">
<select onChange={(e) => confirmBattleChange(e, 0)}>
<option value="Attack">Attack</option>
<option value="Escape">Escape</option>
<option value="Props">Props</option>
<option value="attack">Attack</option>
<option value="escape">Escape</option>
<option value="props">Props</option>
</select>
<select onChange={(e) => confirmBattleChange(e, 1)}>
<option value="1">Fire</option>
Expand Down
3 changes: 1 addition & 2 deletions packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export default mudConfig({
},
GMSystem: {
name: "gm",
openAccess: false,
accessList: [],
openAccess: true,
},
PlayerSystem: {
name: "player",
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/systems/BattlePrepareSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract BattlePrepareSystem is System {
positionList.length > 0 && positionList.length <= BattleConfig.getMaxAttackzDistance(BATTLE_CONFIG_KEY),
"invalid attack distance"
);
// require(positionList.length <= Player.getSpace(_msgSender()), "exceed player space"); //Todo: temp remove
require(positionList.length <= Player.getSpace(_msgSender()), "exceed player space"); //Todo: temp remove

require(
Player.getState(_msgSender()) == PlayerState.Exploring &&
Expand Down
26 changes: 14 additions & 12 deletions packages/contracts/src/systems/BattleSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contract BattleSystem is System {
event BattleEnd(uint256 battleId, BattleEndType endType, address winner);

function revealBattle(uint256 _battleId, bytes32 _action, uint256 _arg, bytes32 _nonce) external {
require(_action == bytes32("attack") || _action == bytes32("escape"), "invalid action");
// check battle
BattleListData memory battle = BattleList.get(_battleId);
BattleUtils.checkBattlePlayer(battle, _msgSender(), BattleState.Confirmed);
Expand All @@ -39,10 +40,9 @@ contract BattleSystem is System {
&& BattleList.getDefenderState(_battleId) == BattleState.Revealed) {
// reveal
// console.log("reveal battle");
// revert("asdfasfd");
revealWinner(_battleId);
}
emit BattleReveal(_battleId, _msgSender());
// emit BattleReveal(_battleId, _msgSender());
}

function revealWinner(uint256 _battleId) public {
Expand All @@ -64,17 +64,19 @@ contract BattleSystem is System {
attackerAttackDenfenderEscape(_battleId, battle, attackerBuff, defenderBuff, attackerFirepower);
}

if (!battle.isEnd) {
if (!BattleList.getIsEnd(_battleId)) {
console.log(" round end ");
emit BattleEnd(_battleId, BattleEndType.RoundEnd, address(0));
// emit BattleEnd(_battleId, BattleEndType.RoundEnd, address(0));
BattleList.setDefenderState(_battleId, BattleState.Inited);
BattleList.setAttackerState(_battleId, BattleState.Inited);


} else {
// set explore state
Player.setState(battle.attacker, PlayerState.Exploring);
Player.setState(battle.defender, PlayerState.Exploring);
if (Player.getState(battle.attacker) == PlayerState.Attacking) {
Player.setState(battle.attacker, PlayerState.Exploring);
}
if (Player.getState(battle.defender) == PlayerState.Attacking) {
Player.setState(battle.defender, PlayerState.Exploring);
}
}
}

Expand All @@ -96,14 +98,14 @@ contract BattleSystem is System {
BattleList.setIsEnd(_battleId, true);
loseGame(looser, winner);

emit BattleEnd(_battleId, BattleEndType.NormalEnd, winner);
// emit BattleEnd(_battleId, BattleEndType.NormalEnd, winner);
}
}

function allEscape(uint _battleId) internal {
BattleList.setIsEnd(_battleId, true);
BattleList.setWinner(_battleId, address(0));
emit BattleEnd(_battleId, BattleEndType.AllEscape, address(0));
// emit BattleEnd(_battleId, BattleEndType.AllEscape, address(0));
}

function attackerEscapeDenfenderAttack(uint _battleId, BattleListData memory battle, Buff attackerBuff,
Expand All @@ -117,7 +119,7 @@ contract BattleSystem is System {
PlayerLocationLock.set(battle.attacker, block.timestamp);
// console.log(" escape --- 2");

emit BattleEnd(_battleId, BattleEndType.NormalEnd, battle.defender);
// emit BattleEnd(_battleId, BattleEndType.NormalEnd, battle.defender);
} else {
// escape fail, cause hurt
uint256 attackerAttackPower = BattleUtils.getAttackPower(attackerBuff, defenderBuff, attackerFirepower);
Expand All @@ -126,7 +128,7 @@ contract BattleSystem is System {
BattleList.setWinner(_battleId, battle.defender);
BattleList.setIsEnd(_battleId, true);

emit BattleEnd(_battleId, BattleEndType.NormalEnd, battle.defender);
// emit BattleEnd(_battleId, BattleEndType.NormalEnd, battle.defender);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/systems/MoveSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract MoveSystem is System {
moveList.length > 0 && moveList.length <= BattleConfig.getMaxMoveDistance(BATTLE_CONFIG_KEY),
"invalid move distance"
);
// require(moveList.length <= Player.getSpeed(_msgSender()), "exceed player speed");
require(moveList.length <= Player.getSpeed(_msgSender()), "exceed player speed");
// check player lock
require(PlayerLocationLock.get(_msgSender()) == 0, "You are locked");
// check continuity
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/worlds.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"blockNumber": 27950347
},
"31337": {
"address": "0x0b27a79cb9C0B38eE06Ca3d94DAA68e0Ed17F953"
"address": "0x492844c46CEf2d751433739fc3409B7A4a5ba9A7"
},
"421613": {
"address": "0x2Bc1034975c3df48D6f3026802f372677844b85d",
Expand Down

0 comments on commit ebe2e4a

Please sign in to comment.