Skip to content

Commit

Permalink
Update:add for upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
LidamaoHub committed Aug 9, 2024
1 parent 65e2390 commit 4deadbb
Show file tree
Hide file tree
Showing 18 changed files with 616 additions and 79 deletions.
294 changes: 279 additions & 15 deletions packages/contracts/out/IWorld.sol/IWorld.abi.json

Large diffs are not rendered by default.

294 changes: 279 additions & 15 deletions packages/contracts/out/IWorld.sol/IWorld.abi.json.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contracts/out/IWorld.sol/IWorld.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"deploy:opbnb": "pnpm run build && mud deploy --profile=opbnb",
"deploy:op-sepolia": "pnpm run build && mud deploy --profile=optimism-sepolia",
"deploy:arbitrum-sepolia": "pnpm run build && mud deploy --profile=arbitrum-sepolia",

"dev": "pnpm mud dev-contracts",
"lint": "pnpm run prettier && pnpm run solhint",
"prettier": "prettier --write 'src/**/*.sol'",
Expand All @@ -29,7 +28,8 @@
"@latticexyz/schema-type": "2.1.0",
"@latticexyz/store": "2.1.0",
"@latticexyz/world": "2.1.0",
"@latticexyz/world-modules": "2.1.0"
"@latticexyz/world-modules": "2.1.0",
"@openzeppelin/contracts": "^5.0.2"
},
"devDependencies": {
"@types/node": "^18.15.11",
Expand Down
10 changes: 5 additions & 5 deletions packages/contracts/script/GameConfigInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ library GameConfigInit {
function initGameConfig() internal {
console.log(" ========= initGameConfig");
// bytes32 merkleRoot = 0xa969691ad8c2e97e3d516e08f5b10ee4decd5f278a5f03ac4fa3532be181c854;
GameConfig.setBattleId(GAME_CONFIG_KEY,1);
GameConfig.setBattleId(1);
// GameConfig.set(
// GAME_CONFIG_KEY, //key
// GameConfigData({
Expand All @@ -29,13 +29,13 @@ library GameConfigInit {
}

function setInitPosition() internal {
GameConfig.setOriginX(GAME_CONFIG_KEY, 4);
GameConfig.setOriginY(GAME_CONFIG_KEY, 4);
GameConfig.setOriginX( 4);
GameConfig.setOriginY( 4);
}

function getPosition() internal view returns (uint256, uint256) {
uint256 x = GameConfig.getOriginX(GAME_CONFIG_KEY);
uint256 y = GameConfig.getOriginY(GAME_CONFIG_KEY);
uint256 x = GameConfig.getOriginX();
uint256 y = GameConfig.getOriginY();
return (x, y);
}
}
8 changes: 5 additions & 3 deletions packages/contracts/script/PostDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ contract PostDeploy is Script {

console.log(" ========== PostDeploy ========== ");

address muser = 0xEc30f284Ca8fD19967Ec2BbD07c2dc3B24A8D445;
address mloot = 0x621C0403Fc19272043119389F63dE68F493184D1;
address mplugin = 0x0B4aD32Cc29823FE7ff3A8E83BCe1B8689d13EB8;


address muser = 0x700b6A60ce7EaaEA56F065753d8dcB9653dbAD35;
address mloot = 0xA15BB66138824a1c7167f5E85b957d04Dd34E468;
address mplugin = 0xb19b36b1456E65E3A6D514D3F715f204BD59f431;

bytes32 merkleRoot = 0x5df91eca63323dbb115087ef262075c5bcea99b8eaf95f520efb8d48ff447499;

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/systems/BattleForceSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract BattleForceSystem is System {
BattleListData memory battle = BattleList.get(_battleId);
BattleList1Data memory battle1 = BattleList1.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(block.timestamp - battle.endTimestamp > BattleConfig.getMaxTimeLimit(), "battle not timeout");
require(battle.isEnd == false, "battle already end");
// 可以强制结束阶段为:confirmed, revealed

Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/src/systems/BattlePrepareSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ contract BattlePrepareSystem is System {
//实际上是送到原点
// TODO似乎可以直接通过indexer获取,就不需要再次插入了

Player.setX(player, GameConfig.getOriginX(GAME_CONFIG_KEY));
Player.setY(player, GameConfig.getOriginY(GAME_CONFIG_KEY));
Player.setX(player, GameConfig.getOriginX());
Player.setY(player, GameConfig.getOriginY());
Player.setState(player, PlayerState.Exploring);

}
Expand All @@ -32,7 +32,7 @@ contract BattlePrepareSystem is System {
PlayerData memory player = Player.get(_msgSender());
require(player.state == PlayerState.Exploring, "You should in exploring state");
require(
player.x == GameConfig.getOriginX(GAME_CONFIG_KEY) && player.y == GameConfig.getOriginY(GAME_CONFIG_KEY),
player.x == GameConfig.getOriginX() && player.y == GameConfig.getOriginY(),
"You are not in the origin point"
);
BattleUtils._goPreparing(_msgSender());
Expand All @@ -43,7 +43,7 @@ contract BattlePrepareSystem is System {
// 一个格子只能有一个人
// 判断对战双方的状态是否是Exploring
require(
positionList.length > 0 && positionList.length <= BattleConfig.getMaxAttackzDistance(BATTLE_CONFIG_KEY),
positionList.length > 0 && positionList.length <= BattleConfig.getMaxAttackzDistance(),
"invalid attack distance"
);
require(positionList.length <= PlayerParams.getAttackRange(_msgSender()), "exceed player attackRange"); //Todo: temp remove
Expand All @@ -67,14 +67,14 @@ contract BattlePrepareSystem is System {
// Player.setHp(_msgSender(), initPlayerHp(_msgSender()));
// Player.setHp(_targetAddress, initPlayerHp(_targetAddress)); //战斗结算才需要设置hp

uint256 battleId = GameConfig.getBattleId(GAME_CONFIG_KEY);
uint256 battleId = GameConfig.getBattleId();
BattleList.setAttacker(battleId, _msgSender());
BattleList.setDefender(battleId, _targetAddress);
BattleList.setAttackerHP(battleId, initPlayerHp(_msgSender()));
BattleList.setDefenderHP(battleId, initPlayerHp(_targetAddress));
// BattleList.setStartTimestamp(battleId, block.timestamp);
// BattleList.setEndTimestamp(battleId, block.timestamp); //结束时才需要设置
GameConfig.setBattleId(GAME_CONFIG_KEY, battleId + 1);
GameConfig.setBattleId( battleId + 1);

emit AttackStart(_msgSender(), _targetAddress);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/src/systems/BoxSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ contract BoxSystem is System {
BoxList.setOwner(_boxId, _msgSender());
}

uint256 randomId = GameConfig.getRandomId(GAME_CONFIG_KEY);
uint256 randomId = GameConfig.getRandomId();
BoxList.setRandomId(_boxId, randomId);
GameConfig.setRandomId(GAME_CONFIG_KEY, randomId + 1);
GameConfig.setRandomId( randomId + 1);

// RandomList.getAuthor(_randomId),
RandomList.set(randomId, block.number, _msgSender());
Expand Down Expand Up @@ -57,7 +57,7 @@ contract BoxSystem is System {

require(_box.opened == true, "Box is not opened");

if (block.timestamp < _box.openTime + BattleConfig.getMaxBoxBindTime(BATTLE_CONFIG_KEY)) {
if (block.timestamp < _box.openTime + BattleConfig.getMaxBoxBindTime()) {
require(msg.sender == _box.owner, "The box is waiting for its opener, please wait");
}

Expand Down
26 changes: 13 additions & 13 deletions packages/contracts/src/systems/GMSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@ contract GMSystem is System {

// season
function GetSeasonInfo() public view returns (uint256, uint256, uint256) {
uint256 start = Season.getStart(MAP_KEY);
uint256 end = Season.getEnd(MAP_KEY);
uint256 no = Season.getNo(MAP_KEY);
uint256 start = Season.getStart();
uint256 end = Season.getEnd();
uint256 no = Season.getNo();
return (start, end, no);
}

// set season info
function SetSeasonInfo(uint256 _start, uint256 _end) public {
require (_start < _end, "start must be less than end");

uint256 now_end = Season.getEnd(MAP_KEY);
uint256 now_end = Season.getEnd();
require (_start > now_end, "start must be more than prev end");

Season.setStart(MAP_KEY, _start);
Season.setEnd(MAP_KEY, _end);
uint256 no = Season.getNo(MAP_KEY);
Season.setNo(MAP_KEY, no+1);
Season.setStart( _start);
Season.setEnd( _end);
uint256 no = Season.getNo();
Season.setNo( no+1);
}

// merkle root
function SetMapMerkleRoot(bytes32 _root) public {
GameConfig.setMerkleRoot(GAME_CONFIG_KEY, _root);
GameConfig.setMerkleRoot( _root);
}

// create box
function CreateBox(uint16 _x, uint16 _y) public {
uint256 boxId = GameConfig.getBoxId(GAME_CONFIG_KEY);
uint256 boxId = GameConfig.getBoxId();
BoxList.setX(boxId, _x);
BoxList.setY(boxId, _y);
// BoxList.setDropTime(boxId, block.timestamp);
GameConfig.setBoxId(GAME_CONFIG_KEY, boxId + 1);
GameConfig.setBoxId(boxId + 1);
}

function multCreateBox(Coordinate[] memory cList) public {
Expand All @@ -52,11 +52,11 @@ contract GMSystem is System {

// set user contract address
function SetUserContract(address _user) public {
GlobalConfig.setUserContract(GLOBAL_CONFIG_KEY, _user);
GlobalConfig.setUserContract( _user);
}

function setGmaeOpen(bool _b) external{
GameConfig.setIsOpen(GAME_CONFIG_KEY, _b);
GameConfig.setIsOpen( _b);
}


Expand Down
10 changes: 5 additions & 5 deletions packages/contracts/src/systems/InitSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract InitSystem is System {
}

GameConfig.set(
GAME_CONFIG_KEY, //key
//key
GameConfigData({
merkleRoot: _merkleRoot, //merkleRoot
battleId: 1, //battleId,
Expand All @@ -30,23 +30,23 @@ contract InitSystem is System {
);
address[] memory players;
BattleConfig.set(
BATTLE_CONFIG_KEY, //key
//key
10, //maxAttackzDistance
15, //maxMoveDistance,
20, //maxTimeLimit,
10, //maxUserLocationLockTime,
10 //maxBoxBindTime
);
GlobalConfig.setUserContract(
GLOBAL_CONFIG_KEY, //key
//key
_userContract
);
GlobalConfig.setLootContract(
GLOBAL_CONFIG_KEY, //key
//key
_lootContract
);
GlobalConfig.setPluginContract(
GLOBAL_CONFIG_KEY, //key
//key
_pluginContract
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/systems/MoveSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract MoveSystem is System {
// 用户自行解锁
require(PlayerLocationLock.get(_msgSender()) != 0, "You are not locked");
require(
PlayerLocationLock.get(_msgSender()) + BattleConfig.getMaxUserLocationLockTime(BATTLE_CONFIG_KEY) <=
PlayerLocationLock.get(_msgSender()) + BattleConfig.getMaxUserLocationLockTime() <=
block.timestamp,
"You are locked"
);
Expand All @@ -28,7 +28,7 @@ contract MoveSystem is System {

function move(Position[] memory moveList) external {
require(
moveList.length > 0 && moveList.length <= BattleConfig.getMaxMoveDistance(BATTLE_CONFIG_KEY),
moveList.length > 0 && moveList.length <= BattleConfig.getMaxMoveDistance(),
"invalid move distance"
);
require(moveList.length <= PlayerParams.getSpeed(_msgSender()), "exceed player speed");
Expand Down
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,7 +40,7 @@ contract PlayerSystem is System {
function selectUserNft(uint256 _tokenId) public {
address sender = _msgSender();
// Player.selectNft(_msgSender(), tokenId);
address userAddress = GlobalConfig.getUserContract(GLOBAL_CONFIG_KEY);
address userAddress = GlobalConfig.getUserContract();
User user = User(userAddress);
require(user.ownerOf(_tokenId) == sender, "You are not the owner of this NFT");
(uint256 hp, uint256 attack, uint256 attackRange, uint256 speed, uint256 strength, uint256 space) = user
Expand All @@ -57,7 +57,7 @@ contract PlayerSystem is System {
}

function selectLootNFT(uint256 _tokenId) public {
address lootAddress = GlobalConfig.getLootContract(GLOBAL_CONFIG_KEY);
address lootAddress = GlobalConfig.getLootContract();
Loot loot = Loot(lootAddress);
address _sender = _msgSender();
require(loot.ownerOf(_tokenId) == _msgSender(), "You are not the owner of this NFT");
Expand Down Expand Up @@ -88,7 +88,7 @@ contract PlayerSystem is System {
}

function getUserInfo(uint256 tokenId) public view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
address userAddress = GlobalConfig.getUserContract(GLOBAL_CONFIG_KEY);
address userAddress = GlobalConfig.getUserContract();
User user = User(userAddress);
return user.getStructInfo(tokenId);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/systems/library/BattleUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ library BattleUtils {
BattleList.setIsEnd(_battleId, true);
// 处理战败方
// 爆装备
uint256 boxId = GameConfig.getBoxId(GAME_CONFIG_KEY);
uint256 boxId = GameConfig.getBoxId();
PlayerData memory losser = Player.get(_looser);
BoxListData memory box;
box.x = losser.x;
Expand All @@ -88,7 +88,7 @@ library BattleUtils {
Player.setOreBalance(_looser, 0);
Player.setTreasureBalance(_looser, 0);

GameConfig.setBoxId(GAME_CONFIG_KEY, boxId + 1);
GameConfig.setBoxId( boxId + 1);
// 回家
_goPreparing(_looser);

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/systems/library/CommonUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ library CommonUtils {
bytes32 leaf = keccak256(
abi.encodePacked(info.x, ",", info.y, ",", prefer)
);
bool isValidLeaf = MerkleProof.verify(info.proof, GameConfig.getMerkleRoot(GAME_CONFIG_KEY), leaf);
bool isValidLeaf = MerkleProof.verify(info.proof, GameConfig.getMerkleRoot(), leaf);
require(isValidLeaf, "Bad position");
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/systems/library/MRandom.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ library MRandom {
}

function requestRandom() external {
uint256 randomId = GameConfig.getRandomId(GAME_CONFIG_KEY);
uint256 randomId = GameConfig.getRandomId();
RandomList.setAuthor(randomId, msg.sender);
RandomList.setBlockNumber(randomId, block.number);

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/worlds.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"blockNumber": 3018802
},
"31337": {
"address": "0x6e9474e9c83676b9a71133ff96db43e7aa0a4342"
"address": "0xc7fbc007c077ccb92d40b5ddcc58182307776eb6"
},
"33784": {
"address": "0x6e9474e9c83676b9a71133ff96db43e7aa0a4342",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4deadbb

Please sign in to comment.