Skip to content

Commit

Permalink
chore: resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
xingxinglian committed Oct 17, 2023
1 parent 1b9e8ae commit 85236f8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export default mudConfig({
oreBalance: "uint16",
treasureBalance: "uint16",
state : "PlayerState",
lastBattleTime: "uint256",
name: "string",
url: "string",
lastBattleTime: "uint256",
}
},
Ownable: {
Expand Down
39 changes: 5 additions & 34 deletions packages/contracts/src/systems/BattleSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ contract BattleSystem is System {
require(!battle.isEnd, "Battle is end");
}


function confirmBattle(bytes32 _buffHash, uint256 _battleId) external {
// 战斗是否有用户
//战斗是否结束
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions packages/contracts/src/systems/MoveSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions packages/contracts/src/systems/PlayerSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/systems/library/Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/worlds.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"4242": {
"address": "0x480f891A7b1AA7018Bb0cCb5Af558d82FA4A5501",
"blockNumber": 27733481
"address": "0x2782b8cDD01d01871bcF4197955a0C1cFa296223",
"blockNumber": 27816101
},
"31337": {
"address": "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0"
Expand Down

0 comments on commit 85236f8

Please sign in to comment.