Skip to content

Commit

Permalink
Merge branch 'command-update' into useless-packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Sycamore0 committed Oct 5, 2024
2 parents a789517 + 845271b commit 673eaf9
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 7 deletions.
57 changes: 57 additions & 0 deletions src/cli/commands/worldCommands/dungeonCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import SceneData from '$/gameData/data/SceneData'
import DungeonData from '$/gameData/data/DungeonData'
import Vector from '$/utils/vector'
import translate from '@/translate'
import { SceneEnterReasonEnum, SceneEnterTypeEnum } from '@/types/proto/enum'
import { CommandDefinition } from '..'

const dungeonCommand: CommandDefinition = {
name: 'dungeon',
usage: 2,
args: [
{ name: 'id', type: 'int' },
{ name: 'uidInput', type: 'str', optional: true }
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const [id, uidInput] = args

let uid;
if (uidInput === '@s' || uidInput === undefined) {
uid = sender?.uid;
} else if (!isNaN(parseInt(uidInput))) {
uid = parseInt(uidInput);
} else {
return printError(translate('generic.invalidTarget'));
}

const player = kcpServer.game.getPlayerByUid(uid || sender?.uid)
if (!player) return printError(translate('generic.playerNotFound'))

const { currentWorld, currentScene, context } = player
if (!currentWorld) return printError(translate('generic.notInWorld'))

const sceneId = await DungeonData.getSceneByDungeon(id)

const scene = await currentWorld.getScene(sceneId)
const sceneData = await SceneData.getScene(sceneId)
if (!scene || !sceneData) return printError(translate('cli.commands.dungeon.error.sceneNotFound'))
if (currentScene === scene) return printError(translate('cli.commands.dungeon.error.sameScene'))

print(translate('cli.commands.dungeon.info.changeScene', id, scene.id))

const { BornPos, BornRot } = sceneData

const pos = new Vector()
const rot = new Vector()

pos.setData(BornPos)
rot.setData(BornRot)

scene.join(context, pos, rot, SceneEnterTypeEnum.ENTER_DUNGEON, SceneEnterReasonEnum.DUNGEON_ENTER)
}
}

export default dungeonCommand
4 changes: 3 additions & 1 deletion src/cli/commands/worldCommands/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CommandDefinition } from '..'
import coopCommand from './coopCommand'
import dungeonCommand from './dungeonCommand'
import posCommand from './posCommand'
import sceneCommand from './sceneCommand'
import tpCommand from './tpCommand'
Expand All @@ -8,7 +9,8 @@ const worldCommands: CommandDefinition[] = [
posCommand,
sceneCommand,
tpCommand,
coopCommand
coopCommand,
dungeonCommand
]

export default worldCommands
4 changes: 4 additions & 0 deletions src/kcpServer/game/gameData/data/DungeonData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class DungeonDataLoader extends Loader {
return (await this.getDungeonList()).find(data => data.SceneId === sceneId)
}

async getSceneByDungeon(id: number): Promise<number> {
return (await this.getDungeon(id))?.SceneId
}

async getDungeonList(): Promise<DungeonData[]> {
return (await this.getData())?.Dungeon || []
}
Expand Down
79 changes: 77 additions & 2 deletions src/kcpServer/packets/GmTalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import Packet, { PacketContext, PacketInterface } from '#/packet'
import Monster from '$/entity/monster'
import Vector from '$/utils/vector'
import { ClientStateEnum } from '@/types/enum'
import { ChangeHpReasonEnum, PlayerDieTypeEnum, ProtEntityTypeEnum, RetcodeEnum } from '@/types/proto/enum'
import { ChangeHpReasonEnum, PlayerDieTypeEnum, ProtEntityTypeEnum, RetcodeEnum, SceneEnterReasonEnum, SceneEnterTypeEnum } from '@/types/proto/enum'
import Logger from '@/logger'
import Gadget from '$/entity/gadget'
import SceneData from '$/gameData/data/SceneData'
import DungeonData from '$/gameData/data/DungeonData'
const logger = new Logger('GMTALK')

export interface GmTalkReq {
msg: string
Expand Down Expand Up @@ -82,11 +87,66 @@ class GmTalkPacket extends Packet implements PacketInterface {
if (type == null) player.godMode = enable
}

// new
private async gmtTp(context: PacketContext, x: number, y: number, z: number) {
const { player } = context
const { currentScene } = player
currentScene.join(context, new Vector(x, y, z), new Vector(), SceneEnterTypeEnum.ENTER_GOTO, SceneEnterReasonEnum.TRANS_POINT)
}

private async gmtScoin(context: PacketContext, amount: number) {
const { player } = context
player.addMora(amount, true)
}

private async gmtGadget(context: PacketContext, id: number, lv: number) {
const { player } = context
const gadget = new Gadget(id)
gadget.motion.pos.copy(player.pos)
gadget.bornPos.copy(player.pos)

await gadget.initNew(lv)
await player.currentScene.entityManager.add(gadget)
}

private async getSceneData(sceneId: number) {
const sceneData = await SceneData.getScene(sceneId)

const { BornPos, BornRot } = sceneData
const pos = new Vector()
const rot = new Vector()
pos.setData(BornPos)
rot.setData(BornRot)

return { pos, rot }
}

private async gmtJump(context: PacketContext, id: number) {
const { player } = context

const scene = await player.currentWorld.getScene(id)
const { pos, rot } = await this.getSceneData(id)

scene.join(context, pos, rot, SceneEnterTypeEnum.ENTER_JUMP, SceneEnterReasonEnum.TRANS_POINT)
}

private async gmtDungeon(context: PacketContext, id: number) {
const { player } = context
const sceneId = await DungeonData.getSceneByDungeon(id)

const scene = await player.currentWorld.getScene(sceneId)
const { pos, rot } = await this.getSceneData(sceneId)

scene.join(context, pos, rot, SceneEnterTypeEnum.ENTER_DUNGEON, SceneEnterReasonEnum.DUNGEON_ENTER)
}

async request(context: PacketContext, data: GmTalkReq): Promise<void> {
const { msg } = data
const cmd = msg?.split(' ')?.[0]?.toLowerCase()
const args = msg?.split(' ')?.slice(1) || []

logger.info(`[${context.player.uid}] ${msg}`)

switch (cmd) {
case 'hp':
await this.gmtHp(context, Number(args[0]))
Expand All @@ -100,8 +160,23 @@ class GmTalkPacket extends Packet implements PacketInterface {
case 'wudi':
await this.gmtGod(context, args.slice(-1)[0] === 'ON', args.length > 1 ? args[0] : undefined)
break
case 'goto':
await this.gmtTp(context, Number(args[0]), Number(args[1]), Number(args[2]))
break
case 'scoin':
await this.gmtScoin(context, Number(args[0]))
break
case 'gadget':
await this.gmtGadget(context, Number(args[0]), Number(args[1]))
break
case 'jump':
await this.gmtJump(context, Number(args[0]))
break
case 'dungeon':
await this.gmtDungeon(context, Number(args[0]))
break
default:
console.log('GmTalk:', msg)
logger.warn(`Unsupported GM command: ${msg}`)
await this.response(context, { retcode: RetcodeEnum.RET_UNKNOWN_ERROR })
return
}
Expand Down
14 changes: 14 additions & 0 deletions src/translate/data/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,20 @@
"sameScene": "Same scene."
}
},
"dungeon": {
"desc": "Enter dungeon",
"usage": {
"0": "dungeon <id> <uidInput> - Enter dungeon for player",
"1": "dungeon <id> - (In game) Enter dungeon for yourself"
},
"info": {
"changeScene": "Enter dungeon: %0(Scene: %1)"
},
"error": {
"sceneNotFound": "Scene not found.",
"sameScene": "Same scene."
}
},
"tp": {
"desc": "Teleport to location",
"usage": {
Expand Down
16 changes: 15 additions & 1 deletion src/translate/data/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@
}
},
"scene": {
"desc": "改变场景",
"desc": "进入场景",
"usage": {
"0": "scene <id> <uidInput> - 将该玩家传送到该场景",
"1": "scene <id> - (游戏中)改变自己所在的场景"
Expand All @@ -585,6 +585,20 @@
"sameScene": "处于同一场景中."
}
},
"dungeon": {
"desc": "进入秘境",
"usage": {
"0": "dungeon <id> <uidInput> - 将该玩家传送到该秘境",
"1": "dungeon <id> - (游戏中)改变自己所在的秘境"
},
"info": {
"changeScene": "传送到秘境: %0(场景: %1)"
},
"error": {
"sceneNotFound": "该场景未找到.",
"sameScene": "处于同一场景中."
}
},
"tp": {
"desc": "传送到某位置",
"usage": {
Expand Down
20 changes: 17 additions & 3 deletions src/translate/data/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,17 +572,31 @@
}
},
"scene": {
"desc": "場景改變",
"desc": "進入場景",
"usage": {
"0": "scene <id> <uidInput> - 將該玩家傳送到該場景",
"1": "scene <id> - (遊戲中)為自己改變場景"
"1": "scene <id> - (遊戲中)改變自己所在的場景"
},
"info": {
"changeScene": "修改場景到: %0"
},
"error": {
"sceneNotFound": "該場景未找到.",
"sameScene": "相同的場景."
"sameScene": "處於同一場景中."
}
},
"dungeon": {
"desc": "進入秘境",
"usage": {
"0": "dungeon <id> <uidInput> - 將該玩家傳送到該秘境",
"1": "dungeon <id> - (遊戲中)改變自己所在的秘境"
},
"info": {
"changeScene": "傳送到秘境: %0(場景: %1)"
},
"error": {
"sceneNotFound": "該場景未找到.",
"sameScene": "處於同一場景中."
}
},
"tp": {
Expand Down

0 comments on commit 673eaf9

Please sign in to comment.