-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lewis
committed
Nov 1, 2023
1 parent
094bba6
commit 0e530d8
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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 } from "../codegen/Types.sol"; | ||
import { GameConfig, BattleConfig, BattleList, BattleListData, Player, | ||
PlayerData, PlayerLocationLock } from "../codegen/Tables.sol"; | ||
import { BattleUtils } from "./library/BattleUtils.sol"; | ||
import { CommonUtils } from "./library/CommonUtils.sol"; | ||
import { GAME_CONFIG_KEY, BATTLE_CONFIG_KEY } from "../Constants.sol"; | ||
import {Position} from "./Common.sol"; | ||
|
||
contract BattleForceSystem is System { | ||
function forceEnd(uint256 _battleId) external { | ||
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"); | ||
require(battle.isEnd == false, "battle already end"); | ||
|
||
BattleState oppositeState = _msgSender() == battle.attacker ? battle.defenderState : battle.attackerState; | ||
BattleState playerState = _msgSender() == battle.attacker ? battle.attackerState : battle.defenderState; | ||
console.log("battle attacker ", battle.attacker); | ||
|
||
address oppositer = _msgSender() == battle.attacker ? battle.defender : battle.attacker; | ||
console.log(" opposite state ", uint(oppositeState)); | ||
console.log(" player state ", uint(playerState)); | ||
require(oppositeState == BattleState.Inited && playerState == BattleState.Confirmed, "battle state not correct"); | ||
|
||
Player.setState(battle.attacker, PlayerState.Exploring); | ||
Player.setState(battle.defender, PlayerState.Exploring); | ||
|
||
BattleList.setDefenderState(_battleId, BattleState.Revealed); | ||
BattleList.setAttackerState(_battleId, BattleState.Revealed); | ||
BattleList.setIsEnd(_battleId, true); | ||
BattleList.setWinner(_battleId, _msgSender()); | ||
|
||
|
||
BattleUtils.outBattlefield(oppositer); | ||
} | ||
} |