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 Nov 11, 2023
2 parents dfdbc7f + 40a95fa commit 6728535
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 167 deletions.
50 changes: 25 additions & 25 deletions packages/contracts/out/IWorld.sol/IWorld.json
Original file line number Diff line number Diff line change
Expand Up @@ -3912,16 +3912,16 @@
119088,
119076,
71348,
130431,
130340,
130324,
130327,
130379,
174089,
130369,
130358,
130436,
130345,
130329,
130332,
130384,
174094,
130374,
130363,
64435,
127597,
127602,
64393,
64426,
64399,
Expand All @@ -3932,22 +3932,22 @@
"nameLocation": "798:6:169",
"scope": 119346,
"usedErrors": [
127562,
127568,
127570,
127572,
127578,
127584,
127590,
127596,
174058,
174062,
174068,
174072,
174076,
174080,
174084,
174088
127567,
127573,
127575,
127577,
127583,
127589,
127595,
127601,
174063,
174067,
174073,
174077,
174081,
174085,
174089,
174093
]
}
],
Expand Down
32 changes: 16 additions & 16 deletions packages/contracts/out/Loot.sol/MLoot.json

Large diffs are not rendered by default.

86 changes: 43 additions & 43 deletions packages/contracts/out/Plugin.sol/MPlugin.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions packages/contracts/out/User.sol/MUser.json

Large diffs are not rendered by default.

Empty file.
2 changes: 2 additions & 0 deletions packages/contracts/src/systems/BattleForceSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {Position} from "./Common.sol";

contract BattleForceSystem is System {
function forceEnd(uint256 _battleId) external {
require(!BattleList.getIsEnd(_battleId),"battel already end");

BattleListData memory battle = BattleList.get(_battleId);
require(_msgSender() == battle.attacker || _msgSender() == battle.defender, "not in battle");
require(block.timestamp - battle.endTimestamp > BattleConfig.getMaxTimeLimit(BATTLE_CONFIG_KEY), "battle not timeout");
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/systems/BattlePrepareSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ contract BattlePrepareSystem is System {

function confirmBattle(bytes32 _buffHash, uint256 _battleId) external {
// 战斗是否有用户,用户是否在当前战斗//战斗是否结束//是否已超时
require(!BattleList.getIsEnd(_battleId),"battel already end");


BattleListData memory battle = BattleList.get(_battleId);
Expand Down
107 changes: 43 additions & 64 deletions packages/contracts/src/systems/BattleSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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(!BattleList.getIsEnd(_battleId),"battel already end");
require(_action == bytes32("attack") || _action == bytes32("escape"), "invalid action");
// check battle
BattleListData memory battle = BattleList.get(_battleId);
Expand Down Expand Up @@ -56,19 +57,25 @@ contract BattleSystem is System {
if (battle.attackerAction == bytes32("attack") && battle.defenderAction == bytes32("attack")) {
allAttack(_battleId, battle, attackerBuff, defenderBuff, attackerFirepower, defenderFirepower);
} else if (battle.attackerAction == bytes32("escape") && battle.defenderAction == bytes32("escape")) {
allEscape(_battleId,battle);
} else if (battle.attackerAction == bytes32("escape") && battle.defenderAction == bytes32("attack")) {
attackerEscapeDenfenderAttack(_battleId, battle, attackerBuff, defenderBuff, defenderFirepower);
} else if (battle.attackerAction == bytes32("attack") && battle.defenderAction == bytes32("escape")) {
attackerAttackDenfenderEscape(_battleId, battle, attackerBuff, defenderBuff, attackerFirepower);
}

allEscape(_battleId, battle);
} else {
escapeAndAttack(_battleId, battle);
}
if (!BattleList.getIsEnd(_battleId)) {
// console.log(" round end ");
// emit BattleEnd(_battleId, BattleEndType.RoundEnd, address(0));
// 如果战斗还没结束
BattleList.setDefenderState(_battleId, BattleState.Inited);
BattleList.setAttackerState(_battleId, BattleState.Inited);
}
if (BattleList.getAttackerHP(_battleId) == 0 || BattleList.getDefenderHP(_battleId) == 0) {
address winner = BattleList.getDefenderHP(_battleId) == 0 ? battle.attacker : battle.defender;
address looser = winner == battle.attacker ? battle.defender : battle.attacker;

BattleUtils.endGame(looser, winner, _battleId);
}
} else {
// 战斗已经结束
emit BattleEnd(_battleId, BattleEndType.NormalEnd, BattleList.getWinner(_battleId));
}

BattleList.setEndTimestamp(_battleId, block.timestamp);
}

Expand All @@ -86,16 +93,9 @@ contract BattleSystem is System {

BattleList.setAttackerHP(_battleId, BattleUtils.getAttackResult(battle.attackerHP, defenderAttackPower));
BattleList.setDefenderHP(_battleId, BattleUtils.getAttackResult(battle.defenderHP, attackerAttackPower));
if (BattleList.getAttackerHP(_battleId) == 0 || BattleList.getDefenderHP(_battleId) == 0) {
address winner = BattleList.getDefenderHP(_battleId) == 0 ? battle.attacker : battle.defender;
address looser = winner == battle.attacker ? battle.defender : battle.attacker;

BattleUtils.endGame(looser, winner,_battleId);
}
}

function allEscape(uint _battleId,BattleListData memory _battle) internal {

function allEscape(uint _battleId, BattleListData memory _battle) internal {
Player.setState(_battle.attacker, PlayerState.Exploring);
Player.setState(_battle.defender, PlayerState.Exploring);
Player.setHp(_battle.attacker, BattleList.getAttackerHP(_battleId));
Expand All @@ -104,58 +104,37 @@ contract BattleSystem is System {
BattleList.setWinner(_battleId, address(0));
}

function attackerEscapeDenfenderAttack(
uint _battleId,
BattleListData memory battle,
Buff attackerBuff,
Buff defenderBuff,
uint defenderFirepower
) internal {
if (BattleUtils.compareBuff(attackerBuff, defenderBuff) >= 1) {
// escape success
//

function escapeAndAttack(uint _battleId, BattleListData memory battle) internal {
address escaper = battle.attackerAction == bytes32("escape") ? battle.attacker : battle.defender;
address other = battle.attackerAction == bytes32("escape") ? battle.defender : battle.attacker;
Buff escaperBuff = battle.attackerAction == bytes32("escape") ? Buff(battle.attackerArg) : Buff(battle.defenderArg);
Buff otherBuff = battle.attackerAction == bytes32("escape") ? Buff(battle.defenderArg) : Buff(battle.attackerArg);
if(BattleUtils.compareBuff(escaperBuff,otherBuff)>=1){
// 逃跑成功
// 胜利方为0,双方explowing,双方设定hp,一方锁定
BattleList.setWinner(_battleId, battle.defender);
BattleList.setIsEnd(_battleId, true);
// escaper will lock a while
PlayerLocationLock.set(battle.defender, block.timestamp);
} else {
// escape fail, cause hurt
uint256 defenderAttackPower = BattleUtils.getAttackPower(defenderBuff, attackerBuff, defenderFirepower);
BattleList.setAttackerHP(_battleId, BattleUtils.getAttackResult(battle.attackerHP, defenderAttackPower));
if (BattleList.getAttackerHP(_battleId) == 0) {
BattleList.setWinner(_battleId, battle.defender);
BattleList.setIsEnd(_battleId, true);

// emit BattleEnd(_battleId, BattleEndType.NormalEnd, battle.defender);
Player.setState(battle.attacker, PlayerState.Exploring);
Player.setHp(battle.attacker, BattleList.getAttackerHP(_battleId));
// console.log(" defender escape success");
Player.setState(battle.defender, PlayerState.Exploring);
Player.setHp(battle.defender, BattleList.getDefenderHP(_battleId));

}else{
// 逃跑失败
uint256 attack = Player.getAttack(other);
uint256 attackPower = (attack*15)/10;
if(battle.attacker==escaper){
BattleList.setAttackerHP(_battleId,BattleUtils.getAttackResult(battle.attackerHP,attackPower));
}else{
BattleList.setDefenderHP(_battleId,BattleUtils.getAttackResult(battle.defenderHP,attackPower));
}
}
}

function attackerAttackDenfenderEscape(
uint _battleId,
BattleListData memory battle,
Buff attackerBuff,
Buff defenderBuff,
uint attackerFirepower
) internal {
if (BattleUtils.compareBuff(defenderBuff, attackerBuff) >= 1) {
// escape success
BattleList.setWinner(_battleId, battle.attacker);
BattleList.setIsEnd(_battleId, true);
// escaper will lock a while
PlayerLocationLock.set(battle.attacker, block.timestamp);

// console.log(" attacker escape success");
// emit BattleEnd(_battleId, BattleEndType.NormalEnd, battle.attacker);
} else {
// escape fail, cause hurt
uint256 attackerAttackPower = BattleUtils.getAttackPower(attackerBuff, defenderBuff, attackerFirepower);
BattleList.setAttackerHP(_battleId, BattleUtils.getAttackResult(battle.attackerHP, attackerAttackPower));
if (BattleList.getDefenderHP(_battleId) == 0) {
BattleList.setWinner(_battleId, battle.attacker);
BattleList.setIsEnd(_battleId, true);

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

}
6 changes: 3 additions & 3 deletions packages/contracts/worlds.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"blockNumber": 29582781
},
"31337": {
"address": "0x1D3EDBa836caB11C26A186873abf0fFeB8bbaE63"
"address": "0x06C1aAfcE623554950bc49c28B64398D0Eb5fa34"
},
"33784": {
"address": "0xFe29941C54C015B042994D0384F2b35BD7fb3f7a",
"blockNumber": 284838
"address": "0x97D9A81b61bE843968a68fB75aeF2196cB636AbD",
"blockNumber": 337282
},
"421613": {
"address": "0x2Bc1034975c3df48D6f3026802f372677844b85d",
Expand Down

0 comments on commit 6728535

Please sign in to comment.