From 85236f8300a2cb482ac45612e8d7bba2315ae007 Mon Sep 17 00:00:00 2001 From: lewis <71866430+xingxinglian@users.noreply.github.com> Date: Tue, 17 Oct 2023 11:56:42 +0800 Subject: [PATCH] chore: resolve conflict --- packages/contracts/mud.config.ts | 2 +- .../contracts/src/systems/BattleSystem.sol | 39 +++---------------- packages/contracts/src/systems/MoveSystem.sol | 6 +-- .../contracts/src/systems/PlayerSystem.sol | 6 +-- .../src/systems/library/Interface.sol | 4 +- packages/contracts/worlds.json | 4 +- 6 files changed, 15 insertions(+), 46 deletions(-) diff --git a/packages/contracts/mud.config.ts b/packages/contracts/mud.config.ts index f3dc8bde..b08c0675 100644 --- a/packages/contracts/mud.config.ts +++ b/packages/contracts/mud.config.ts @@ -56,9 +56,9 @@ export default mudConfig({ oreBalance: "uint16", treasureBalance: "uint16", state : "PlayerState", + lastBattleTime: "uint256", name: "string", url: "string", - lastBattleTime: "uint256", } }, Ownable: { diff --git a/packages/contracts/src/systems/BattleSystem.sol b/packages/contracts/src/systems/BattleSystem.sol index d9fa59e5..16158104 100644 --- a/packages/contracts/src/systems/BattleSystem.sol +++ b/packages/contracts/src/systems/BattleSystem.sol @@ -21,6 +21,7 @@ contract BattleSystem is System { require(!battle.isEnd, "Battle is end"); } + function confirmBattle(bytes32 _buffHash, uint256 _battleId) external { // 战斗是否有用户 //战斗是否结束 @@ -47,6 +48,8 @@ contract BattleSystem is System { emit BattleConfirmed(_battleId, _msgSender(), _buffHash); } + + function revealBattle(uint256 _battleId, bytes32 _action, uint256 _arg, bytes32 _nonce) external { // check battle BattleListData memory battle = BattleList.get(_battleId); @@ -199,7 +202,7 @@ contract BattleSystem is System { return _hp - _attackPower; } - function initPlayerHp(address _player) public returns (uint256) { + function initPlayerHp(address _player) public view returns (uint256) { uint256 time = Player.getLastBattleTime(_player); uint256 hp = Player.getHp(_player); @@ -209,7 +212,6 @@ contract BattleSystem is System { hp = hp + increase; return (hp > maxHp) ? maxHp : hp; - } function raisePlayerHp(uint256 _targetHP, uint256 _percent, address _player) public { @@ -251,42 +253,11 @@ contract BattleSystem is System { outBattlefield(_msgSender()); } - function getAttackPower(Buff _myBuff, Buff _targetBuff, uint256 _attackPower) internal pure returns (uint256) { - // TODO 后期添加防御力抵消对方的攻击力 - if (compareBuff(_myBuff, _targetBuff) == 0) { - return (_attackPower * 7) / 10; - } - if (compareBuff(_myBuff, _targetBuff) == 2) { - return (_attackPower * 13) / 10; - } - - return _attackPower; - } - - function compareBuff(Buff _myBuff, Buff _targetBuff) internal pure returns (uint256) { - // 0表示失败,1表示相当,2表示胜利 - if ( - (_myBuff == Buff.Water && _targetBuff == Buff.Fire) || - (_myBuff == Buff.Wind && _targetBuff == Buff.Water) || - (_myBuff == Buff.Fire && _targetBuff == Buff.Wind) - ) { - return 2; - } - if ( - (_myBuff == Buff.Fire && _targetBuff == Buff.Water) || - (_myBuff == Buff.Water && _targetBuff == Buff.Wind) || - (_myBuff == Buff.Wind && _targetBuff == Buff.Fire) - ) { - return 0; - } - return 1; - } - function outBattlefield(address _player) internal { // 脱离战区,则将用户血量回满,坐标不变,状态改为准备中 require(Player.getState(_player) == PlayerState.Exploring, "You should in exploring state"); - // Player.setHp(_player, initPlayerHp(_player)); Todo: setting to atacker or defender hp + Player.setHp(_player, initPlayerHp(_player)); //Todo: setting to atacker or defender hp for (uint256 i; i < BattleConfig.lengthBattlefieldPlayers(BATTLE_CONFIG_KEY); i++) { if (BattleConfig.getItemBattlefieldPlayers(BATTLE_CONFIG_KEY, i) == _player) { BattleConfig.updateBattlefieldPlayers( diff --git a/packages/contracts/src/systems/MoveSystem.sol b/packages/contracts/src/systems/MoveSystem.sol index e81aa996..275c0496 100644 --- a/packages/contracts/src/systems/MoveSystem.sol +++ b/packages/contracts/src/systems/MoveSystem.sol @@ -132,8 +132,6 @@ contract MoveSystem is System { Player.setX(_user, GameConfig.getOriginX(GAME_CONFIG_KEY)); Player.setY(_user, GameConfig.getOriginY(GAME_CONFIG_KEY)); // GameConfig.pushBattlefieldPlayers(GAME_CONFIG_KEY, _user); - // Player.setState(_user, PlayerState.Exploring); - } - - + Player.setState(_user, PlayerState.Exploring); + } } \ No newline at end of file diff --git a/packages/contracts/src/systems/PlayerSystem.sol b/packages/contracts/src/systems/PlayerSystem.sol index 4a3877f9..620134a5 100644 --- a/packages/contracts/src/systems/PlayerSystem.sol +++ b/packages/contracts/src/systems/PlayerSystem.sol @@ -40,9 +40,9 @@ contract PlayerSystem is System { address userAddress = GlobalConfig.getUserContract(GLOBAL_CONFIG_KEY); User user = User(userAddress); require(user.ownerOf(tokenId) == _msgSender(), "You are not the owner of this NFT"); - uint256 hp = user.getStructInfo(tokenId); - console.log("hp: ", hp); - Player.setHp(_msgSender(), hp); + // uint256 hp = user.getStructInfo(tokenId); + // console.log("hp: ", hp); + // Player.setHp(_msgSender(), hp); } function getUserInfo(uint256 tokenId) public view returns (uint256) { diff --git a/packages/contracts/src/systems/library/Interface.sol b/packages/contracts/src/systems/library/Interface.sol index 1e1ef1b9..17759982 100644 --- a/packages/contracts/src/systems/library/Interface.sol +++ b/packages/contracts/src/systems/library/Interface.sol @@ -3,13 +3,13 @@ pragma solidity >=0.8.0; // User interface User { - function getStructInfo(uint256 tokenId) external view returns (uint256); + function getStructInfo(uint256 tokenId) external view returns (uint256,uint256,uint256,uint256,uint256,uint256); function ownerOf(uint256 tokenId) external view returns (address); } // Loot interface Loot { - function balanceOf(address account) external view returns (uint256); + function getStructInfo(uint256 tokenId) external view returns (string memory,string memory,string memory,string memory,string memory,string memory,string memory,string memory); } diff --git a/packages/contracts/worlds.json b/packages/contracts/worlds.json index 16b4f385..60f1d1b3 100644 --- a/packages/contracts/worlds.json +++ b/packages/contracts/worlds.json @@ -1,7 +1,7 @@ { "4242": { - "address": "0x480f891A7b1AA7018Bb0cCb5Af558d82FA4A5501", - "blockNumber": 27733481 + "address": "0x2782b8cDD01d01871bcF4197955a0C1cFa296223", + "blockNumber": 27816101 }, "31337": { "address": "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0"