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
TiyoSheng committed Oct 25, 2023
2 parents ba737f3 + fcbe9e8 commit 7943fcf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/contracts/script/GlobalConfigInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ library GlobalConfigInit {
userContract
);
}
}
}
17 changes: 17 additions & 0 deletions packages/contracts/src/systems/BattleInfoSystem.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import { console } from "forge-std/console.sol";
import { System } from "@latticexyz/world/src/System.sol";
import { BattleState, Buff, PlayerState, BattleEndType } from "@codegen/Types.sol";
import { GameConfig, BattleConfig, BoxListData, BattleList, BattleListData, Player, PlayerData, PlayerLocationLock, BoxList } from "@codegen/Tables.sol";
import { BattleUtils } from "./library/BattleUtils.sol";
import { GAME_CONFIG_KEY, BATTLE_CONFIG_KEY } from "../Constants.sol";

contract BattleInfoSystem is System {
function getBattlePlayerHp(uint _battleId, address addr) public view returns (uint) {
BattleListData memory battle = BattleList.get(_battleId);
require(battle.attacker == addr || battle.defender == addr, "not the battle player");
return battle.attacker == addr ? battle.attackerHP : battle.defenderHP;
}
}
3 changes: 2 additions & 1 deletion packages/contracts/src/systems/BattleSystem.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

// import { console } from "forge-std/console.sol";
import { console } from "forge-std/console.sol";
import { System } from "@latticexyz/world/src/System.sol";
import { BattleState, Buff, PlayerState, BattleEndType } from "@codegen/Types.sol";
import { GameConfig, BattleConfig, BoxListData, BattleList, BattleListData, Player, PlayerData, PlayerLocationLock, BoxList } from "@codegen/Tables.sol";
Expand Down Expand Up @@ -64,6 +64,7 @@ contract BattleSystem is System {
}

if (!battle.isEnd) {
console.log(" round end");
emit BattleEnd(_battleId, BattleEndType.RoundEnd, address(0));
} else {
// set explore state
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/src/systems/PlayerSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ contract PlayerSystem is System {
User user = User(userAddress);
return user.getStructInfo(tokenId);
}
function initUserInfo() external {

function initUserInfo() external {
// !!仅用于测试
address _player = msg.sender;
Player.setX(_player, 0);
Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/test/BattleTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract BattleTest is MudTest {
// init bob property
Player.setMaxHp(bob, 200);
Player.setHp(bob, 200);
Player.setAttack(bob, 10);
Player.setAttack(bob, 36);
Player.setAttackRange(bob, 5);
Player.setSpeed(bob, 5);
Player.setStrength(bob, 5);
Expand All @@ -47,7 +47,7 @@ contract BattleTest is MudTest {
// init alice property
Player.setMaxHp(alice, 200);
Player.setHp(alice, 200);
Player.setAttack(alice, 10);
Player.setAttack(alice, 3);
Player.setAttackRange(alice, 5);
Player.setSpeed(alice, 5);
Player.setStrength(alice, 5);
Expand All @@ -72,7 +72,7 @@ contract BattleTest is MudTest {
vm.stopPrank();
}

/*

function testBattleNormalAttack() public {
GloabalInit();
PlayerInit();
Expand Down Expand Up @@ -122,7 +122,7 @@ contract BattleTest is MudTest {
// console.logUint(uint(defenderState));
// vm.stopPrank();
}
*/


/*
function testBattleNormalEndAttack() public {
Expand Down Expand Up @@ -259,6 +259,7 @@ contract BattleTest is MudTest {
}
*/

/*
function testBattleDefenderEscape() public {
GloabalInit();
PlayerInit();
Expand Down Expand Up @@ -299,8 +300,7 @@ contract BattleTest is MudTest {
world.revealBattle(1, action2, arg2, nonce2);
vm.stopPrank();
}


*/



Expand Down

0 comments on commit 7943fcf

Please sign in to comment.