Skip to content

Commit

Permalink
Add /level & /promote commands
Browse files Browse the repository at this point in the history
need re-enter the game
  • Loading branch information
Sycamore0 committed Oct 6, 2024
1 parent df730de commit ec19d5e
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/cli/commands/avatarCommands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import equipCommand from './equipCommand'
import godCommand from './godCommand'
import guidCommand from './guidCommand'
import healCommand from './healCommand'
import levelCommand from './levelCommand'
import promoteCommand from './promoteCommand'
import rechargeCommand from './rechargeCommand'
import setcsCommand from './setcsCommand'
import talentCommand from './talentCommand'
Expand All @@ -11,10 +13,12 @@ import fpCommand from './fpCommand'
const avatarCommands: CommandDefinition[] = [
godCommand,
healCommand,
levelCommand,
promoteCommand,
rechargeCommand,
guidCommand,
equipCommand,
fpCommand, // setfp getfp listfp,3 in 1
fpCommand, // setfp getfp listfp, 3 in 1
setcsCommand,
talentCommand
]
Expand Down
42 changes: 42 additions & 0 deletions src/cli/commands/avatarCommands/levelCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import translate from '@/translate'
import { CommandDefinition } from '..'

const levelCommand: CommandDefinition = {
name: 'level',
usage: 2,
args: [
{ name: 'lv', type: 'num' },
{ name: 'uidInput', type: 'str', optional: true }
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const [lv, 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 { currentAvatar } = player
if (!currentAvatar) return printError(translate('generic.playerNoCurAvatar'))

const targetLv = parseInt(lv)
if (targetLv >= 1 && targetLv <= 90) {
currentAvatar.level = targetLv
print(translate('cli.commands.level.info.level', currentAvatar.avatarId, currentAvatar.level))
} else {
printError(translate('cli.commands.level.error.invalidLv', currentAvatar.level))
}
}
}

export default levelCommand
42 changes: 42 additions & 0 deletions src/cli/commands/avatarCommands/promoteCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import translate from '@/translate'
import { CommandDefinition } from '..'

const promoteCommand: CommandDefinition = {
name: 'promote',
usage: 2,
args: [
{ name: 'promotion', type: 'num' },
{ name: 'uidInput', type: 'str', optional: true }
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const [promotion, 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 { currentAvatar } = player
if (!currentAvatar) return printError(translate('generic.playerNoCurAvatar'))

const targetPromotion = parseInt(promotion)
if (targetPromotion >= 0 && targetPromotion <= 6) {
currentAvatar.promoteLevel = targetPromotion
print(translate('cli.commands.promote.info.promote', currentAvatar.avatarId, currentAvatar.promoteLevel))
} else {
printError(translate('cli.commands.promote.error.invalidPromotion', currentAvatar.promoteLevel))
}
}
}

export default promoteCommand
21 changes: 21 additions & 0 deletions src/kcpServer/game/entity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getStringHash } from '@/utils/hash'
import EntityProps from './entityProps'
import FightProp, { FightPropChangeReason } from './fightProps'
import Motion from './motion'
import SceneEntityAppear from '#/packets/SceneEntityAppear'

export default class Entity extends BaseClass {
manager?: EntityManager
Expand Down Expand Up @@ -140,8 +141,28 @@ export default class Entity extends BaseClass {
get level() {
return this.props.get(PlayerPropEnum.PROP_LEVEL)
}

set level(v: number) {
this.props.set(PlayerPropEnum.PROP_LEVEL, v)
// promotion
if (v >= 1 && v <= 20) {
this.promoteLevel = 0
} else if (v > 20 && v <= 40) {
this.promoteLevel = 1
} else if (v > 40 && v <= 50) {
this.promoteLevel = 2
} else if (v > 50 && v <= 60) {
this.promoteLevel = 3
} else if (v > 60 && v <= 70) {
this.promoteLevel = 4
} else if (v > 70 && v <= 80) {
this.promoteLevel = 5
} else if (v > 80 && v <= 90) {
this.promoteLevel = 6
} else {
// do nothing
}
SceneEntityAppear.sendNotify
}

get exp() {
Expand Down
4 changes: 3 additions & 1 deletion src/kcpServer/game/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import ActivityManager from './manager/activityManager'
import { ChatManager } from './manager/chatManager'
import ShopManager from './manager/shopManager'

const logger = new Logger('GAME')

export default class Game {
server: KcpServer

Expand Down Expand Up @@ -98,7 +100,7 @@ export default class Game {
// login
await this.playerLogin(player.context)
} catch (err) {
console.log('Failed to create server player:', err)
logger.error('Failed to create server player:', err)
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/translate/data/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,32 @@
"heal": "Healed all avatar."
}
},
"level": {
"desc": "Set current avatar level",
"usage": {
"0": "level <lv> <uidInput> - Set player's current avatar level",
"1": "level <lv> - (In game) Set current avatar level"
},
"info": {
"level": "Avatar(id: %0) level set to %1."
},
"error": {
"invalidLv": "Invalid level: %0, it should be 1~90."
}
},
"promote": {
"desc": "Set current avatar promote level",
"usage": {
"0": "promote <promotion> <uidInput> - Set player's current avatar promote level",
"1": "promote <promotion> - (In game) Set current avatar promote level"
},
"info": {
"promote": "Avatar(id: %0) promote level set to %1."
},
"error": {
"invalidpromotion": "Invalid promote level: %0, it should be 0~6."
}
},
"recharge": {
"desc": "Recharge all avatar in current team",
"usage": {
Expand Down
26 changes: 26 additions & 0 deletions src/translate/data/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,32 @@
"heal": "已治疗所有角色."
}
},
"level": {
"desc": "设置当前角色的等级",
"usage": {
"0": "level <lv> <uidInput> - 设置玩家当前角色的等级",
"1": "level <lv> - (游戏中)设置当前角色的等级"
},
"info": {
"level": "角色(id: %0) 等级设置为 %1."
},
"error": {
"invalidLv": "无效的等级: %0, 应当为1~90的任意整数."
}
},
"promote": {
"desc": "设置当前角色的突破等级",
"usage": {
"0": "promote <promotion> <uidInput> - 设置玩家当前角色的突破等级",
"1": "promote <promotion> - (游戏中)设置当前角色的突破等级"
},
"info": {
"promote": "角色(id: %0) 突破等级设置为 %1."
},
"error": {
"invalidpromotion": "无效的突破等级: %0, 应当为0~6的任意整数."
}
},
"recharge": {
"desc": "为当前团队中的所有角色充能",
"usage": {
Expand Down
26 changes: 26 additions & 0 deletions src/translate/data/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,32 @@
"heal": "已治療所有角色."
}
},
"level": {
"desc": "設置當前角色的等級",
"usage": {
"0": "level <lv> <uidInput> - 設置玩家當前角色的等級",
"1": "level <lv> - (遊戲中)設置當前角色的等級"
},
"info": {
"level": "角色(id: %0) 等級設置為 %1."
},
"error": {
"invalidLv": "無效的等級: %0, 應當為1~90的任意整數."
}
},
"promote": {
"desc": "設置當前角色的突破等級",
"usage": {
"0": "promote <promotion> <uidInput> - 设置玩家当前角色的突破等级",
"1": "promote <promotion> - (遊戲中)設置當前角色的突破等級"
},
"info": {
"promote": "角色(id: %0) 突破等級設置為 %1."
},
"error": {
"invalidpromotion": "無效的突破等級: %0, 應當為0~6的任意整數."
}
},
"recharge": {
"desc": "為當前團隊中的所有角色充能",
"usage": {
Expand Down

0 comments on commit ec19d5e

Please sign in to comment.