From 1ef1d62d8456a5631e961b99be1e5dc533b10316 Mon Sep 17 00:00:00 2001 From: LidamaoHub Date: Sat, 14 Oct 2023 23:14:19 +0800 Subject: [PATCH 01/13] Update:add mistery box --- packages/contracts/src/systems/GMSystem.sol | 2 ++ packages/contracts/src/systems/GameSystem.sol | 17 ----------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/packages/contracts/src/systems/GMSystem.sol b/packages/contracts/src/systems/GMSystem.sol index 97a2476c..07b5c507 100644 --- a/packages/contracts/src/systems/GMSystem.sol +++ b/packages/contracts/src/systems/GMSystem.sol @@ -32,5 +32,7 @@ contract GMSystem { GameConfig.setMerkleRoot(GAME_CONFIG_KEY, root); } + function airdrop() public {} + } \ No newline at end of file diff --git a/packages/contracts/src/systems/GameSystem.sol b/packages/contracts/src/systems/GameSystem.sol index ad916c23..298bffe1 100644 --- a/packages/contracts/src/systems/GameSystem.sol +++ b/packages/contracts/src/systems/GameSystem.sol @@ -14,15 +14,6 @@ contract GameSystem is System { event MoveEvent(address indexed player, uint16 x, uint16 y); event AttackStart(address player, address target); - - - - - - - - - function settleBattle() external {} function createLootBox() external {} @@ -31,12 +22,4 @@ contract GameSystem is System { function dropLoot() external {} - //------非战区空间部分 - - - - - - - } From 95d6018a67f02a9bbb5ca04622a78909f515de65 Mon Sep 17 00:00:00 2001 From: LidamaoHub Date: Mon, 16 Oct 2023 21:41:52 +0800 Subject: [PATCH 02/13] Update:add commit --- .../contracts/src/systems/BattleSystem.sol | 4 +++- packages/contracts/src/systems/BoxSystem.sol | 5 ++++- packages/contracts/src/systems/GMSystem.sol | 22 +++++++++++++++++-- packages/contracts/src/systems/MoveSystem.sol | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/contracts/src/systems/BattleSystem.sol b/packages/contracts/src/systems/BattleSystem.sol index 03252757..a95f5376 100644 --- a/packages/contracts/src/systems/BattleSystem.sol +++ b/packages/contracts/src/systems/BattleSystem.sol @@ -197,6 +197,7 @@ contract BattleSystem is System { } function initUserHP(address _user) public pure returns (uint256) { + // TODO通过loot和user生成 return 400; } @@ -272,8 +273,9 @@ contract BattleSystem is System { function outBattlefield(address _user) internal { // 脱离战区,则将用户血量回满,坐标不变,状态改为准备中 + // TODO,战败的时候判断state应该为fighting require(Player.getState(_user) == PlayerState.Exploring, "You should in exploring state"); - + // Player.setHP(_user, initUserHP(_user)); for (uint256 i; i < BattleConfig.lengthBattlefieldPlayers(BATTLE_CONFIG_KEY); i++) { diff --git a/packages/contracts/src/systems/BoxSystem.sol b/packages/contracts/src/systems/BoxSystem.sol index 6f7fd1c5..2e796df8 100644 --- a/packages/contracts/src/systems/BoxSystem.sol +++ b/packages/contracts/src/systems/BoxSystem.sol @@ -23,6 +23,7 @@ contract BoxSystem is System { function openBox(uint256 _boxId) external { // 宝箱打开时init内容物,根据自带randomId来实现随机 + // TODO开宝箱的时候用户定身 uint256 roomId = GameConfig.getRoomId(GAME_CONFIG_KEY); uint256 boxId = GameConfig.getBoxId(GAME_CONFIG_KEY); require(BoxList.getDropTime(roomId, _boxId) != 0, "Invalid box"); @@ -38,8 +39,10 @@ contract BoxSystem is System { BoxList.setOpened(roomId, boxId, true); BoxList.setOpenTime(roomId, boxId, block.timestamp); } - +// TODO 少了一个reveal Box +// 先开箱,再reveal,再view,弹出box的前端界面,最后collections function getCollections(uint256 _boxId, uint16 _oreAmount, uint16 _treasureAmount) internal { + // TODO 少了丢弃逻辑,不能超过容量 uint256 roomId = GameConfig.getRoomId(GAME_CONFIG_KEY); uint256 boxId = GameConfig.getBoxId(GAME_CONFIG_KEY); require(BoxList.getDropTime(roomId, _boxId) != 0, "Invalid box"); diff --git a/packages/contracts/src/systems/GMSystem.sol b/packages/contracts/src/systems/GMSystem.sol index 07b5c507..76df8a4f 100644 --- a/packages/contracts/src/systems/GMSystem.sol +++ b/packages/contracts/src/systems/GMSystem.sol @@ -12,7 +12,6 @@ contract GMSystem { uint256 start = Season.getStart(MAP_KEY); uint256 end = Season.getEnd(MAP_KEY); uint256 no = Season.getNo(MAP_KEY); - return (start, end, no); } @@ -32,7 +31,26 @@ contract GMSystem { GameConfig.setMerkleRoot(GAME_CONFIG_KEY, root); } - function airdrop() public {} + function startAirdrop() public { + // random r = randomList[randomId] + // r.author = msg.sender + // r.block = block.blocknumber + // randomId++; + // airdrop a = airdrop[airdropId]; + // airdropId++; + // a.randomId = randomId; + // a.state = pending; + } + + // function revealAirdrop(Move[] p) public { + // // airdrop a = airdrop[airdropId]; + // // randomid = a.randomId + // // // 通过函数获得真随机数 + // // // for循环空投3 + + + + // } } \ No newline at end of file diff --git a/packages/contracts/src/systems/MoveSystem.sol b/packages/contracts/src/systems/MoveSystem.sol index 54732077..bcf0bd41 100644 --- a/packages/contracts/src/systems/MoveSystem.sol +++ b/packages/contracts/src/systems/MoveSystem.sol @@ -126,7 +126,7 @@ contract MoveSystem is System { Player.setX(_user, GameConfig.getOriginX(GAME_CONFIG_KEY)); Player.setY(_user, GameConfig.getOriginY(GAME_CONFIG_KEY)); // GameConfig.pushBattlefieldPlayers(GAME_CONFIG_KEY, _user); - // Player.setState(_user, PlayerState.Exploring); + Player.setState(_user, PlayerState.Exploring); } From 46591eae5eb6a4aa6be64505c944f7ccda0aa307 Mon Sep 17 00:00:00 2001 From: vivomo <929992114@qq.com> Date: Wed, 18 Oct 2023 19:45:54 +0800 Subject: [PATCH 03/13] feat: map follow user's move --- packages/client/src/config/index.ts | 5 ++ packages/client/src/pages/game/index.tsx | 87 +++++++++++++++------- packages/client/src/pages/game/styles.scss | 1 + packages/client/src/pages/home/index.tsx | 2 +- 4 files changed, 69 insertions(+), 26 deletions(-) diff --git a/packages/client/src/config/index.ts b/packages/client/src/config/index.ts index 9d7aad61..3f2f7bad 100644 --- a/packages/client/src/config/index.ts +++ b/packages/client/src/config/index.ts @@ -1,4 +1,9 @@ export const MapConfig = { visualWidth: 24, visualHeight: 16, +} + +export const LimitSpace = { + x: ~~(MapConfig.visualWidth / 2), + y: ~~(MapConfig.visualHeight / 2) } \ No newline at end of file diff --git a/packages/client/src/pages/game/index.tsx b/packages/client/src/pages/game/index.tsx index 39c5fd39..eedfd0d8 100644 --- a/packages/client/src/pages/game/index.tsx +++ b/packages/client/src/pages/game/index.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useRef, useState } from 'react'; import { useComponentValue } from "@latticexyz/react"; -import { MapConfig } from '@/config'; +import { LimitSpace, MapConfig } from '@/config'; import { loadMapData } from '@/utils'; import Map from '@/components/Map'; import UserAvatar from '@/components/UserAvatar'; @@ -38,34 +38,35 @@ const Game = () => { const location = useLocation(); const { username = '', avatar = 'snake', roomId = '000000' } = location.state ?? {}; - const onKeyDown = (e) => { - const mapData = mapDataRef.current; - if (mapData.length === 0 || e.keyCode < 37 || e.keyCode > 40) { - return; - } - switch (e.keyCode) { - case 37: - vertexCoordinate.x = Math.max(0, vertexCoordinate.x - 1); - break; - case 38: - vertexCoordinate.y = Math.max(0, vertexCoordinate.y - 1); - break; - case 39: - vertexCoordinate.x = Math.min(mapData[0].length - 1 - MapConfig.visualWidth, vertexCoordinate.x + 1); - break; - case 40: - vertexCoordinate.y = Math.min(mapData.length - 1 - MapConfig.visualHeight, vertexCoordinate.y + 1); - break; - } - setVertexCoordinate({ - ...vertexCoordinate - }); - }; + // const onKeyDown = (e) => { + // const mapData = mapDataRef.current; + // if (mapData.length === 0 || e.keyCode < 37 || e.keyCode > 40) { + // return; + // } + // switch (e.keyCode) { + // case 37: + // vertexCoordinate.x = Math.max(0, vertexCoordinate.x - 1); + // break; + // case 38: + // vertexCoordinate.y = Math.max(0, vertexCoordinate.y - 1); + // break; + // case 39: + // vertexCoordinate.x = Math.min(mapData[0].length - 1 - MapConfig.visualWidth, vertexCoordinate.x + 1); + // break; + // case 40: + // vertexCoordinate.y = Math.min(mapData.length - 1 - MapConfig.visualHeight, vertexCoordinate.y + 1); + // break; + // } + // setVertexCoordinate({ + // ...vertexCoordinate + // }); + // }; const movePlayer = (paths, merkelData) => { let pathIndex = 0; const curPlayerIndex = players.findIndex(item => item.id === curPlayer!.id); const interval = setInterval(() => { + triggerVertexUpdate(paths[pathIndex], players[curPlayerIndex]); Object.assign(players[curPlayerIndex], paths[pathIndex]); pathIndex++; setPlayers([...players]); @@ -76,6 +77,41 @@ const Game = () => { // move(merkelData); } + const triggerVertexUpdate = (cur, before) => { + const xDegree = cur.x - before.x; + const yDegree = cur.y - before.y; + const mapData = mapDataRef.current; + if (xDegree === 1) { + const limitExceeded = cur.x - vertexCoordinate.x > LimitSpace.x; + const lessBoundary = vertexCoordinate.x + MapConfig.visualWidth < mapData[0].length - 1; + if (limitExceeded && lessBoundary) { + vertexCoordinate.x++; + } + } else if (xDegree === -1) { + const limitExceeded = cur.x - vertexCoordinate.x < LimitSpace.x; + const lessBoundary = vertexCoordinate.x > 0; + if (limitExceeded && lessBoundary) { + vertexCoordinate.x--; + } + } else if (yDegree === 1) { + const limitExceeded = cur.y - vertexCoordinate.y > LimitSpace.y; + const lessBoundary = vertexCoordinate.y + MapConfig.visualHeight < mapData.length - 1; + if (limitExceeded && lessBoundary) { + vertexCoordinate.y++; + } + } else if (yDegree === -1) { + const limitExceeded = cur.y - vertexCoordinate.y < LimitSpace.y; + const lessBoundary = vertexCoordinate.y > 0; + if (limitExceeded && lessBoundary) { + vertexCoordinate.y--; + } + } + + setVertexCoordinate({ + ...vertexCoordinate + }); + } + useEffect(() => { loadMapData().then((csv) => { setRenderMapData(csv); @@ -87,6 +123,7 @@ const Game = () => { // getPosition('0x35be872A3C94Bf581A9DA4c653CE734380b75B7D'); }, []); + return (
@@ -105,7 +142,7 @@ const Game = () => { data={RankMockData} curId={CurIdMockData} /> - + {/**/} { const [hasInit, setHasInit] = useState(false); const [walletAddress, setWalletAddress] = useState(''); - const [step, setStep] = useState('mint'); + const [step, setStep] = useState('play'); const { Modal, open, close, setContent } = useModal({ title: '', }); From 7a0db44b2868dd1a3d8a9130eec16a498b1d920c Mon Sep 17 00:00:00 2001 From: vivomo <929992114@qq.com> Date: Wed, 18 Oct 2023 19:46:26 +0800 Subject: [PATCH 04/13] feat: map follow user's move --- packages/client/src/pages/game/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/pages/game/index.tsx b/packages/client/src/pages/game/index.tsx index eedfd0d8..6f6397f6 100644 --- a/packages/client/src/pages/game/index.tsx +++ b/packages/client/src/pages/game/index.tsx @@ -125,7 +125,7 @@ const Game = () => { return ( -
+
Date: Wed, 18 Oct 2023 20:00:52 +0800 Subject: [PATCH 05/13] feat: fog follow user's move --- packages/client/src/components/Fog/styles.scss | 10 +++++----- packages/client/src/components/Map/index.tsx | 8 ++++++-- packages/client/src/components/MapCell/index.tsx | 9 +++++---- packages/client/src/components/Player/index.tsx | 5 +++++ packages/client/src/pages/game/styles.scss | 1 + 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/client/src/components/Fog/styles.scss b/packages/client/src/components/Fog/styles.scss index 0848cbb5..8e6b9a01 100644 --- a/packages/client/src/components/Fog/styles.scss +++ b/packages/client/src/components/Fog/styles.scss @@ -1,10 +1,10 @@ .mi-map-fog { position: absolute; z-index: 10; - left: 0; - right: 0; - top: 0; - bottom: 0; - background: radial-gradient(circle closest-side at 50% 50%, #00000000 200px, #000000ff 80%); + left: -150vw; + top: -150vh; + width: 300vw; + height: 300vh; + background: radial-gradient(circle closest-side at 50% 50%, #00000000 200px, #000000ff 24%); pointer-events: none; } \ No newline at end of file diff --git a/packages/client/src/components/Map/index.tsx b/packages/client/src/components/Map/index.tsx index 7193b0a2..2818b5b2 100644 --- a/packages/client/src/components/Map/index.tsx +++ b/packages/client/src/components/Map/index.tsx @@ -35,7 +35,11 @@ const Map = (props: IProps) => { const playerData = useMemo(() => { const obj = {}; players.forEach((player) => { - obj[`${player.x}-${player.y}`] = player; + if (obj[`${player.x}-${player.y}`]) { + obj[`${player.x}-${player.y}`].push(player) + } else { + obj[`${player.x}-${player.y}`] = [player]; + } }); return obj; }, [players]); @@ -73,7 +77,7 @@ const Map = (props: IProps) => { }} mapData={data} cellClassCache={cellClassCache.current} - player={playerData[`${x}-${y}`]} + players={playerData[`${x}-${y}`]} onMoveTo={onMoveTo} /> ) diff --git a/packages/client/src/components/MapCell/index.tsx b/packages/client/src/components/MapCell/index.tsx index 16409276..dc02937c 100644 --- a/packages/client/src/components/MapCell/index.tsx +++ b/packages/client/src/components/MapCell/index.tsx @@ -27,12 +27,12 @@ interface IProps { coordinate: ICoordinate, mapData: number[][]; cellClassCache: ICellClassCache; - player?: IPlayer; + players?: IPlayer[]; onMoveTo: (ICoordinate) => void; } const MapCell = (props: IProps) => { - const { coordinate: { x, y}, mapData, cellClassCache, player, onMoveTo } = props; + const { coordinate: { x, y}, mapData, cellClassCache, players, onMoveTo } = props; if (!cellClassCache[`${y}-${x}`]) { cellClassCache[`${y}-${x}`] = getCellClass(mapData, { x, y}); } @@ -42,7 +42,7 @@ const MapCell = (props: IProps) => { const onContextMenu = (e) => { e.preventDefault(); const curMapDataType = mapData[y][x]; - if (isMovable(curMapDataType) && !player) { + if (isMovable(curMapDataType)) { onMoveTo({ x, y}); } @@ -67,8 +67,9 @@ const MapCell = (props: IProps) => { }) }
+ { - player && + players && players.map((player) => ) }
); diff --git a/packages/client/src/components/Player/index.tsx b/packages/client/src/components/Player/index.tsx index d1bfa875..a82df1d7 100644 --- a/packages/client/src/components/Player/index.tsx +++ b/packages/client/src/components/Player/index.tsx @@ -1,5 +1,7 @@ import React from 'react'; import './styles.scss'; +import { CurIdMockData } from '@/mock/data'; +import Fog from '@/components/Fog'; export interface IPlayer { x: number; @@ -13,6 +15,9 @@ const Player = (props: IPlayer) => {
{props.username}
+ { + props.id === CurIdMockData && + }
); }; diff --git a/packages/client/src/pages/game/styles.scss b/packages/client/src/pages/game/styles.scss index 6b31ff16..4b11f2d0 100644 --- a/packages/client/src/pages/game/styles.scss +++ b/packages/client/src/pages/game/styles.scss @@ -4,6 +4,7 @@ height: 100vh; align-items: center; justify-content: center; + overflow: hidden; //background: url("../../assets/wall/wall_5.png"); .mi-game-user-avatar { From cd7d636d93f7846dc154031dabe57e65d68570aa Mon Sep 17 00:00:00 2001 From: vivomo <929992114@qq.com> Date: Wed, 18 Oct 2023 20:05:19 +0800 Subject: [PATCH 06/13] feat: update map style --- packages/client/src/components/Map/styles.scss | 1 - packages/client/src/pages/game/styles.scss | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/client/src/components/Map/styles.scss b/packages/client/src/components/Map/styles.scss index d83d4621..46a88032 100644 --- a/packages/client/src/components/Map/styles.scss +++ b/packages/client/src/components/Map/styles.scss @@ -7,7 +7,6 @@ height: 100%; .mi-map-content { - border: 1px solid; width: $cellSize * 24; } diff --git a/packages/client/src/pages/game/styles.scss b/packages/client/src/pages/game/styles.scss index 4b11f2d0..aaea1079 100644 --- a/packages/client/src/pages/game/styles.scss +++ b/packages/client/src/pages/game/styles.scss @@ -5,7 +5,7 @@ align-items: center; justify-content: center; overflow: hidden; - //background: url("../../assets/wall/wall_5.png"); + background: url("../../assets/wall/wall_5.png"); .mi-game-user-avatar { position: absolute; From 44c4e328e5aae7ff5075cb5aa624572c0f215522 Mon Sep 17 00:00:00 2001 From: vivomo <929992114@qq.com> Date: Wed, 18 Oct 2023 21:06:09 +0800 Subject: [PATCH 07/13] feat: use menu --- packages/client/src/components/Map/index.tsx | 6 +- .../client/src/components/MapCell/index.tsx | 83 ++++++++++++++++++- .../client/src/components/MapCell/styles.scss | 39 +++++++++ packages/client/src/mock/data.ts | 14 +++- packages/client/src/pages/game/index.tsx | 1 - 5 files changed, 137 insertions(+), 6 deletions(-) diff --git a/packages/client/src/components/Map/index.tsx b/packages/client/src/components/Map/index.tsx index 2818b5b2..53caf9df 100644 --- a/packages/client/src/components/Map/index.tsx +++ b/packages/client/src/components/Map/index.tsx @@ -1,4 +1,4 @@ -import React, { useMemo, useRef } from 'react'; +import React, { useMemo, useRef, useState } from 'react'; import { IPlayer } from '../Player'; import MapCell, { ICellClassCache, ICoordinate } from '../MapCell'; import './styles.scss'; @@ -22,6 +22,8 @@ const Map = (props: IProps) => { const { width, height, vertexCoordinate, data = [], players, curId, onPlayerMove } = props; const { x: startX, y: startY } = vertexCoordinate; + const [prevActionCoordinate, setPrevActionCoordinate] = useState({ x: -1, y: -1}); + const staticData = useMemo(() => { return Array(height).fill(0).map(() => Array(width).fill(0)); }, [width, height]); @@ -75,6 +77,8 @@ const Map = (props: IProps) => { x, y }} + prevActionCoordinate={prevActionCoordinate} + onExeAction={setPrevActionCoordinate} mapData={data} cellClassCache={cellClassCache.current} players={playerData[`${x}-${y}`]} diff --git a/packages/client/src/components/MapCell/index.tsx b/packages/client/src/components/MapCell/index.tsx index dc02937c..b3ace795 100644 --- a/packages/client/src/components/MapCell/index.tsx +++ b/packages/client/src/components/MapCell/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { CellType } from '../../constants'; import { getCellClass, isMovable } from '@/utils'; import './styles.scss'; @@ -29,10 +29,16 @@ interface IProps { cellClassCache: ICellClassCache; players?: IPlayer[]; onMoveTo: (ICoordinate) => void; + prevActionCoordinate: ICoordinate; + onExeAction: (ICoordinate) => void; } const MapCell = (props: IProps) => { - const { coordinate: { x, y}, mapData, cellClassCache, players, onMoveTo } = props; + const { coordinate: { x, y}, mapData, cellClassCache, players, onMoveTo, onExeAction, prevActionCoordinate } = props; + + const [menuVisible, setMenuVisible] = useState(false); + const [activePlayerId, setActivePlayerId] = useState(-1); + if (!cellClassCache[`${y}-${x}`]) { cellClassCache[`${y}-${x}`] = getCellClass(mapData, { x, y}); } @@ -40,16 +46,49 @@ const MapCell = (props: IProps) => { const { transforms, classList } = cellClassCache[`${y}-${x}`]; const onContextMenu = (e) => { + onExeAction({ x, y}); e.preventDefault(); const curMapDataType = mapData[y][x]; if (isMovable(curMapDataType)) { onMoveTo({ x, y}); } + } + const onClick = () => { + onExeAction({ x, y}); + if (!players || players?.length === 0) { + return; + } + setMenuVisible(true); + setActivePlayerId(players[0].id) } + const exeAction = (e, action) => { + e.stopPropagation(); + setMenuVisible(false); + switch (action) { + case 'move': + onMoveTo({x, y}); + break; + case 'info': + break; + case 'attack': + break; + } + } + + useEffect(() => { + if (prevActionCoordinate.x !== x || prevActionCoordinate.y !== y) { + setMenuVisible(false); + } + }, [prevActionCoordinate.x, prevActionCoordinate.y]) + return ( -
+
{ classList.map((item, index) => { @@ -71,6 +110,44 @@ const MapCell = (props: IProps) => { { players && players.map((player) => ) } + { + menuVisible && ( +
+ { + players?.length > 1 && ( +
    + { + players?.slice(0, 3).map((player) => { + return ( +
  • { + setActivePlayerId(player.id); + e.stopPropagation(); + }} + >{player.username}
  • + ) + }) + } +
+ ) + } + +
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+ ) + }
); }; diff --git a/packages/client/src/components/MapCell/styles.scss b/packages/client/src/components/MapCell/styles.scss index 312a34a9..7df77bae 100644 --- a/packages/client/src/components/MapCell/styles.scss +++ b/packages/client/src/components/MapCell/styles.scss @@ -13,4 +13,43 @@ background: url("/src/assets/wall/wall_#{$i}.png") no-repeat center 100% / cover; } } + + .mi-cell-user-menu { + position: absolute; + z-index: 20; + left: 100%; + top: 0; + display: flex; + + li { + margin-bottom: 4px; + } + + .mi-cell-username-list { + margin-right: 10px; + + li { + padding-left: 10px; + width: 144px; + height: 44px; + font-size: 24px; + line-height: 42px; + color: #fff; + background: rgba(0, 0, 0, 0.8); + border-radius: 5px; + + &.active { + text-shadow: #000 1px 0 0, #000 0 1px 0, #000 -1px 0 0, #000 0 -1px 0; + border: 1px solid #000; + background: #FED982; + } + } + } + + .mi-btn { + font-size: 24px; + width: 136px; + height: 46px; + } + } } \ No newline at end of file diff --git a/packages/client/src/mock/data.ts b/packages/client/src/mock/data.ts index 2ec559a2..8302e53c 100644 --- a/packages/client/src/mock/data.ts +++ b/packages/client/src/mock/data.ts @@ -36,7 +36,19 @@ export const PlayersMockData: IPlayer[] = [ username: 'other', x: 18, y: 10, - } + }, + { + id: 6, + username: 'other2', + x: 18, + y: 13, + }, + { + id: 8, + username: 'other3', + x: 18, + y: 13, + }, ]; export const CurIdMockData = 3; \ No newline at end of file diff --git a/packages/client/src/pages/game/index.tsx b/packages/client/src/pages/game/index.tsx index 6f6397f6..2b2b94ad 100644 --- a/packages/client/src/pages/game/index.tsx +++ b/packages/client/src/pages/game/index.tsx @@ -12,7 +12,6 @@ import { IPlayer } from '@/components/Player'; import { uploadUserMove } from '@/service/user'; import { useMUD } from '@/mud/MUDContext'; import { getComponentValue } from "@latticexyz/recs"; -import Fog from '@/components/Fog'; const Game = () => { const [renderMapData, setRenderMapData] = useState([]); From 3c5662fb332bced83316e74f898e231970c6dc48 Mon Sep 17 00:00:00 2001 From: lewis <71866430+xingxinglian@users.noreply.github.com> Date: Wed, 18 Oct 2023 21:14:13 +0800 Subject: [PATCH 08/13] chore: temp remove speed --- packages/contracts/src/systems/MoveSystem.sol | 2 +- packages/contracts/worlds.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/contracts/src/systems/MoveSystem.sol b/packages/contracts/src/systems/MoveSystem.sol index 66d21942..8248637e 100644 --- a/packages/contracts/src/systems/MoveSystem.sol +++ b/packages/contracts/src/systems/MoveSystem.sol @@ -31,7 +31,7 @@ contract MoveSystem is System { moveList.length > 0 && moveList.length <= BattleConfig.getMaxMoveDistance(BATTLE_CONFIG_KEY), "invalid move distance" ); - require(moveList.length <= Player.getSpeed(_msgSender()), "exceed player speed"); + // require(moveList.length <= Player.getSpeed(_msgSender()), "exceed player speed"); // check player lock require(PlayerLocationLock.get(_msgSender()) == 0, "You are locked"); // check continuity diff --git a/packages/contracts/worlds.json b/packages/contracts/worlds.json index 98e6e3d2..e9146703 100644 --- a/packages/contracts/worlds.json +++ b/packages/contracts/worlds.json @@ -1,7 +1,7 @@ { "4242": { - "address": "0x480f891A7b1AA7018Bb0cCb5Af558d82FA4A5501", - "blockNumber": 27830588 + "address": "0x2b50622F55780b14C08a288E41A08b2e2368bA4f", + "blockNumber": 27941048 }, "31337": { "address": "0x74Df809b1dfC099E8cdBc98f6a8D1F5c2C3f66f8" From 022356570ed485d87a76cf10db494fa0b1a5286b Mon Sep 17 00:00:00 2001 From: lewis <71866430+xingxinglian@users.noreply.github.com> Date: Wed, 18 Oct 2023 21:18:03 +0800 Subject: [PATCH 09/13] chore: remove space limit --- packages/contracts/src/systems/BattlePrepareSystem.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contracts/src/systems/BattlePrepareSystem.sol b/packages/contracts/src/systems/BattlePrepareSystem.sol index 538dfc33..63ec628f 100644 --- a/packages/contracts/src/systems/BattlePrepareSystem.sol +++ b/packages/contracts/src/systems/BattlePrepareSystem.sol @@ -41,7 +41,7 @@ contract BattlePrepareSystem is System { moveList.length > 0 && moveList.length <= BattleConfig.getMaxAttackzDistance(BATTLE_CONFIG_KEY), "invalid attack distance" ); - require(moveList.length <= Player.getSpace(_msgSender()), "exceed player space"); + // require(moveList.length <= Player.getSpace(_msgSender()), "exceed player space"); //Todo: temp remove require( Player.getState(_msgSender()) == PlayerState.Exploring && From 87f9d40b8cfda9f9eafcba64563e720497b5a84b Mon Sep 17 00:00:00 2001 From: LidamaoHub Date: Wed, 18 Oct 2023 21:36:36 +0800 Subject: [PATCH 10/13] Update:ignore --- packages/contracts/src/systems/PlayerSystem.sol | 1 + packages/contracts/src/systems/library/MRandom.sol | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contracts/src/systems/PlayerSystem.sol b/packages/contracts/src/systems/PlayerSystem.sol index 96cd025d..d8d8153c 100644 --- a/packages/contracts/src/systems/PlayerSystem.sol +++ b/packages/contracts/src/systems/PlayerSystem.sol @@ -40,4 +40,5 @@ contract PlayerSystem is System { + } \ No newline at end of file diff --git a/packages/contracts/src/systems/library/MRandom.sol b/packages/contracts/src/systems/library/MRandom.sol index a1d33eaa..19ae1844 100644 --- a/packages/contracts/src/systems/library/MRandom.sol +++ b/packages/contracts/src/systems/library/MRandom.sol @@ -37,7 +37,6 @@ library MRandom { function choice(uint8 rand, string[] memory sourceArray) internal pure returns (string memory) { string memory output = sourceArray[rand % sourceArray.length]; - return output; } } From c6858eb532b559208818b45ea0948aeea1608251 Mon Sep 17 00:00:00 2001 From: lewis <> Date: Wed, 18 Oct 2023 23:49:15 +0800 Subject: [PATCH 11/13] fix: comfirm inited logic --- packages/contracts/script/BattleConfigInit.sol | 2 +- packages/contracts/script/PostDeploy.s.sol | 4 +++- packages/contracts/src/systems/BattlePrepareSystem.sol | 2 +- packages/contracts/worlds.json | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/contracts/script/BattleConfigInit.sol b/packages/contracts/script/BattleConfigInit.sol index ba4803a2..6751b7c0 100644 --- a/packages/contracts/script/BattleConfigInit.sol +++ b/packages/contracts/script/BattleConfigInit.sol @@ -7,7 +7,7 @@ import {BattleConfig} from "../src/codegen/Tables.sol"; import { BATTLE_CONFIG_KEY } from "../src/Constants.sol"; library BattleConfigInit { - function initGameConfig(IWorld _world) internal { + function initBattleConfig(IWorld _world) internal { address[] memory players; BattleConfig.set( _world, diff --git a/packages/contracts/script/PostDeploy.s.sol b/packages/contracts/script/PostDeploy.s.sol index b2b4262a..7c61b6dd 100644 --- a/packages/contracts/script/PostDeploy.s.sol +++ b/packages/contracts/script/PostDeploy.s.sol @@ -6,6 +6,7 @@ import { console } from "forge-std/console.sol"; import { IWorld } from "../src/codegen/world/IWorld.sol"; import { GameConfigInit } from "./GameConfigInit.sol"; import { BattleConfigInit } from "./BattleConfigInit.sol"; +import { GlobalConfigInit } from "./GlobalConfigInit.sol"; import { console } from "forge-std/console.sol"; contract PostDeploy is Script { @@ -20,7 +21,8 @@ contract PostDeploy is Script { // ------------------ INIT ------------------ GameConfigInit.initGameConfig(IWorld(worldAddress)); - BattleConfigInit.initGameConfig(IWorld(worldAddress)); + BattleConfigInit.initBattleConfig(IWorld(worldAddress)); + GlobalConfigInit.initGlobalConfig(IWorld(worldAddress)); vm.stopBroadcast(); diff --git a/packages/contracts/src/systems/BattlePrepareSystem.sol b/packages/contracts/src/systems/BattlePrepareSystem.sol index 538dfc33..4ba9e6dd 100644 --- a/packages/contracts/src/systems/BattlePrepareSystem.sol +++ b/packages/contracts/src/systems/BattlePrepareSystem.sol @@ -78,7 +78,7 @@ contract BattlePrepareSystem is System { //是否已超时 BattleListData memory battle = BattleList.get(_battleId); - BattleUtils.checkBattlePlayer(battle, _msgSender(), BattleState.Confirmed); + BattleUtils.checkBattlePlayer(battle, _msgSender(), BattleState.Inited); require(block.timestamp - battle.timestamp < BattleConfig.getMaxTimeLimit(BATTLE_CONFIG_KEY), "Battle is timeout"); // 战斗是否已经选择buff diff --git a/packages/contracts/worlds.json b/packages/contracts/worlds.json index 98e6e3d2..367411a2 100644 --- a/packages/contracts/worlds.json +++ b/packages/contracts/worlds.json @@ -1,7 +1,7 @@ { "4242": { - "address": "0x480f891A7b1AA7018Bb0cCb5Af558d82FA4A5501", - "blockNumber": 27830588 + "address": "0x037451EB237700458Af435ffF1CeFcac037247aD", + "blockNumber": 27950347 }, "31337": { "address": "0x74Df809b1dfC099E8cdBc98f6a8D1F5c2C3f66f8" From b49499614dea37e975dd757d2705b0b66d94d14c Mon Sep 17 00:00:00 2001 From: LidamaoHub Date: Thu, 19 Oct 2023 00:05:18 +0800 Subject: [PATCH 12/13] Update:add todo --- packages/contracts/src/systems/BattleSystem.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/contracts/src/systems/BattleSystem.sol b/packages/contracts/src/systems/BattleSystem.sol index f77f68a1..66bf12f8 100644 --- a/packages/contracts/src/systems/BattleSystem.sol +++ b/packages/contracts/src/systems/BattleSystem.sol @@ -10,6 +10,7 @@ import { GAME_CONFIG_KEY, BATTLE_CONFIG_KEY } from "../Constants.sol"; contract BattleSystem is System { function revealBattle(uint256 _battleId, bytes32 _action, uint256 _arg, bytes32 _nonce) external { // check battle + // TODO 揭示后全局event提示已经揭示(battle_id,address) BattleListData memory battle = BattleList.get(_battleId); BattleUtils.checkBattlePlayer(battle, _msgSender(), BattleState.Confirmed); @@ -37,7 +38,9 @@ contract BattleSystem is System { } function revealWinner(uint256 _battleId) public { - // 结算战斗 + // 结算战斗TODO revealWinner之后event + // TODO 战斗全局结束后有event + // TODO 战斗结束后如果没有人战败,也发一个event,表示当前局战斗结束了,但是整场战斗没有结束 BattleListData memory battle = BattleList.get(_battleId); BattleUtils.checkBattlePlayer(battle, _msgSender(), BattleState.Revealed); From 61544e2fed84a66fe8233bbc667333aa46e3333d Mon Sep 17 00:00:00 2001 From: lewis <> Date: Thu, 19 Oct 2023 00:10:46 +0800 Subject: [PATCH 13/13] chore: add global config init --- packages/contracts/script/GlobalConfigInit.sol | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 packages/contracts/script/GlobalConfigInit.sol diff --git a/packages/contracts/script/GlobalConfigInit.sol b/packages/contracts/script/GlobalConfigInit.sol new file mode 100644 index 00000000..9d1e759a --- /dev/null +++ b/packages/contracts/script/GlobalConfigInit.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +import {console} from "forge-std/console.sol"; +import {IWorld} from "../src/codegen/world/IWorld.sol"; +import {GlobalConfig} from "../src/codegen/Tables.sol"; +import { GLOBAL_CONFIG_KEY } from "../src/Constants.sol"; + +library GlobalConfigInit { + function initGlobalConfig(IWorld _world) internal { + address userContract = 0x09aDeA780C664D100374fcdE48dF82290270f4D2; + GlobalConfig.setUserContract( + _world, + GLOBAL_CONFIG_KEY, //key + userContract + ); + } +} \ No newline at end of file