Skip to content

Commit

Permalink
Support level & break GM commands
Browse files Browse the repository at this point in the history
fix `monster` command
  • Loading branch information
Sycamore0 committed Oct 6, 2024
1 parent ec19d5e commit 92c99d5
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions src/kcpServer/packets/GmTalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,31 @@ class GmTalkPacket extends Packet implements PacketInterface {
private async gmtHp(context: PacketContext, amount: number) {
const { player, seqId } = context
const { currentAvatar } = player
if (amount > 0) await currentAvatar.heal(amount, true, ChangeHpReasonEnum.CHANGE_HP_ADD_GM, seqId)
else await currentAvatar.takeDamage(0, -amount, true, ChangeHpReasonEnum.CHANGE_HP_SUB_GM, seqId)
if (amount > 0) {
logger.info(`[${player.uid}]Player's current avatar(id: ${currentAvatar.avatarId}) hp add ${amount}.`)
await currentAvatar.heal(amount, true, ChangeHpReasonEnum.CHANGE_HP_ADD_GM, seqId)
}
else {
logger.info(`[${player.uid}]Player's current avatar(id: ${currentAvatar.avatarId}) hp sub ${amount}.`)
await currentAvatar.takeDamage(0, -amount, true, ChangeHpReasonEnum.CHANGE_HP_SUB_GM, seqId)
}
}

private async gmtMonster(context: PacketContext, id: number, count: number, lvl: number, x?: number, y?: number, z?: number) {
private async gmtMonster(context: PacketContext, id: number, count: number, lvl?: number, pose?: number, x?: number, y?: number, z?: number) {
const { player } = context
const { currentScene, pos: playerPos } = player
const { entityManager } = currentScene

const pos = (x == null || y == null || z == null) ? playerPos.clone() : new Vector(x, y, z)

for (let i = 0; i < count; i++) {
logger.info(`[${player.uid}]Summon monster(id: ${id}, lvl: ${lvl}) in [${x}, ${y}, ${z}].`)
const entity = new Monster(id, player)

entity.motion.pos.copy(pos)
entity.bornPos.copy(pos)

await entity.initNew(lvl)
await entity.initNew(lvl || 1)
await entityManager.add(entity)
}
}
Expand All @@ -61,6 +68,7 @@ class GmTalkPacket extends Packet implements PacketInterface {
switch (type) { // NOSONAR
case 'MONSTER':
entityType = ProtEntityTypeEnum.PROT_ENTITY_MONSTER
logger.info(`[${player.uid}]Killing all monsters.`)
break
default:
return
Expand All @@ -85,23 +93,27 @@ class GmTalkPacket extends Packet implements PacketInterface {
private async gmtGod(context: PacketContext, enable: boolean, type?: string) {
const { player } = context
if (type == null) player.godMode = enable
logger.info(`[${player.uid}]GodMode set to ${enable}.`)
}

// new
private async gmtTp(context: PacketContext, x: number, y: number, z: number) {
const { player } = context
const { currentScene } = player
logger.info(`[${player.uid}]Teleporting to [${x}, ${y}, ${z}].`)
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)
logger.info(`[${player.uid}]Add scoin(amount: ${amount}).`)
}

private async gmtGadget(context: PacketContext, id: number, lv: number) {
const { player } = context
const gadget = new Gadget(id)
logger.info(`[${player.uid}]Summon gadget(id: ${id}, lvl: ${lv}) in [${player.pos.x}, ${player.pos.y}, ${player.pos.z}].`)

gadget.motion.pos.copy(player.pos)
gadget.bornPos.copy(player.pos)

Expand All @@ -127,6 +139,7 @@ class GmTalkPacket extends Packet implements PacketInterface {
const scene = await player.currentWorld.getScene(id)
const { pos, rot } = await this.getSceneData(id)

logger.info(`[${player.uid}]Teleporting to [${pos}] in scene ${id}.`)
scene.join(context, pos, rot, SceneEnterTypeEnum.ENTER_JUMP, SceneEnterReasonEnum.TRANS_POINT)
}

Expand All @@ -137,9 +150,23 @@ class GmTalkPacket extends Packet implements PacketInterface {
const scene = await player.currentWorld.getScene(sceneId)
const { pos, rot } = await this.getSceneData(sceneId)

logger.info(`[${player.uid}]Teleporting to [${pos}] in dungeon ${id}(scene ${sceneId}).`)

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

private async gmtLevel(context: PacketContext, level: number) {
const { player } = context
player.currentAvatar.level = level
logger.info(`[${player.uid}]Current avatar level set to ${level}.`)
}

private async gmtBreak(context: PacketContext, promoteLevel: number) {
const { player } = context
player.currentAvatar.promoteLevel = promoteLevel
logger.info(`[${player.uid}]Current avatar promote level set to ${promoteLevel}.`)
}

async request(context: PacketContext, data: GmTalkReq): Promise<void> {
const { msg } = data
const cmd = msg?.split(' ')?.[0]?.toLowerCase()
Expand Down Expand Up @@ -175,8 +202,14 @@ class GmTalkPacket extends Packet implements PacketInterface {
case 'dungeon':
await this.gmtDungeon(context, Number(args[0]))
break
case 'level':
await this.gmtLevel(context, Number(args[0]))
break
case 'break':
await this.gmtBreak(context, Number(args[0]))
break
default:
logger.warn(`Unsupported GM command: ${msg}`)
logger.warn(`[${context.player.uid}]Unsupported GM command: ${msg}`)
await this.response(context, { retcode: RetcodeEnum.RET_UNKNOWN_ERROR })
return
}
Expand Down

0 comments on commit 92c99d5

Please sign in to comment.