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 25, 2023
2 parents 0d13ed5 + eec7b99 commit 132ac4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
5 changes: 5 additions & 0 deletions packages/contracts/src/systems/BattleInfoSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ contract BattleInfoSystem is System {
require(battle.attacker == addr || battle.defender == addr, "not the battle player");
return battle.attacker == addr ? battle.attackerHP : battle.defenderHP;
}


function raisePlayerHp(uint256 _targetHP, uint256 _percent, address _player) public {
Player.setHp(_player, (_targetHP * _percent) / 100);
}
}
16 changes: 3 additions & 13 deletions packages/contracts/src/systems/BattleSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ contract BattleSystem is System {
if (BattleList.getAttackerState(_battleId) == BattleState.Revealed
&& BattleList.getDefenderState(_battleId) == BattleState.Revealed) {
// reveal
// console.log("reveal battle");
// revert("asdfasfd");
revealWinner(_battleId);
}
emit BattleReveal(_battleId, _msgSender());
Expand All @@ -64,7 +66,7 @@ contract BattleSystem is System {
}

if (!battle.isEnd) {
console.log(" round end");
console.log(" round end ");
emit BattleEnd(_battleId, BattleEndType.RoundEnd, address(0));
} else {
// set explore state
Expand Down Expand Up @@ -150,18 +152,6 @@ contract BattleSystem is System {
}
}

function getAttackResult(uint256 _hp, uint256 _attackPower) internal pure returns (uint256) {
// TODO 后期添加防御力抵消对方的攻击力
if (_attackPower > _hp) {
return 0;
}
return _hp - _attackPower;
}

function raisePlayerHp(uint256 _targetHP, uint256 _percent, address _player) public {
Player.setHp(_player, (_targetHP * _percent) / 100);
}

function loseGame(address _looser, address _winner) internal {
// lose game; will go home and hp will full.
// TODO bag system, baozang system
Expand Down
17 changes: 14 additions & 3 deletions packages/contracts/test/BattleTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/ge
import { IWorld } from "../src/codegen/world/IWorld.sol";
import { Position } from "../src/systems/Common.sol";
import { GAME_CONFIG_KEY } from "../src/Constants.sol";
import { Player, GameConfig, BattleList } from "../src/codegen/Tables.sol";
import { Player, GameConfig, BattleList, BattleListData } from "../src/codegen/Tables.sol";
import { Buff, BattleState } from "../src/codegen/Types.sol";

contract BattleTest is MudTest {
Expand Down Expand Up @@ -115,12 +115,23 @@ contract BattleTest is MudTest {
world.revealBattle(1, action2, arg2, nonce2);
vm.stopPrank();

// vm.startPrank(vm.addr(vm.envUint("PRIVATE_KEY")));
// BattleState attackerState = BattleList.getAttackerState(1);
vm.startPrank(vm.addr(vm.envUint("PRIVATE_KEY")));
BattleListData memory battle = BattleList.get(1);
console.log("attacker hp: ", battle.attackerHP);
console.log("attacker hp: ", battle.defenderHP);
vm.stopPrank();


vm.startPrank(alice);
uint hp = world.getBattlePlayerHp(1, alice);
console.log("alice hp: ", hp);
vm.stopPrank();
// BattleState defenderState = BattleList.getDefenderState(1);
// console.logUint(uint(attackerState));
// console.logUint(uint(defenderState));
// vm.stopPrank();


}


Expand Down

0 comments on commit 132ac4d

Please sign in to comment.