Skip to content

Commit

Permalink
Merge pull request #1 from Sycamore0/command-update
Browse files Browse the repository at this point in the history
Command update
  • Loading branch information
Sycamore0 authored Oct 5, 2024
2 parents d21b28c + 845271b commit a3c3a91
Show file tree
Hide file tree
Showing 48 changed files with 973 additions and 407 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"pkg": "^5.8.0",
"resedit": "^1.6.0",
"typescript": "^4.8.3",
"tsc-alias": "^1.8.10",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2",
"webpack-obfuscator": "^3.5.1"
Expand Down
18 changes: 14 additions & 4 deletions src/cli/commands/avatarCommands/equipCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,34 @@ const equipCommand: CommandDefinition = {
usage: 2,
args: [
{ name: 'guid', type: 'str' },
{ name: 'uid', type: 'int', optional: true }
{ name: 'uidInput', type: 'str', optional: true }
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const player = kcpServer.game.getPlayerByUid(args[1] || sender?.uid)
const [guid, 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 equip = player.getEquip(BigInt(args[0] || 0))
const equip = player.getEquip(BigInt(guid || 0))
if (!equip) return printError(translate('cli.commands.equip.error.noEquip'))

await currentAvatar.equip(equip)
print(translate('cli.commands.equip.info.equip', args[0]))
print(translate('cli.commands.equip.info.equip', guid))
}
}

Expand Down
82 changes: 82 additions & 0 deletions src/cli/commands/avatarCommands/fpCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import translate from '@/translate'
import { FightPropEnum } from '@/types/enum'
import { CommandDefinition } from '..'

const fpCommand: CommandDefinition = {
name: 'fp',
usage: 6,
args: [
{ name: 'mode', type: 'str', values: ['list', 'get', 'set'] },
{ name: 'uidInput', type: 'str', optional: true },
{ name: 'fightProp', type: 'str', optional: true },
{ name: 'value', type: 'num', optional: true }
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const [mode, uidInput, fightProp, value] = 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'))

async function listfp(currentAvatar) {
let propsList = translate('cli.commands.fp.info.listHead')
for (const [propName, propValue] of Object.entries(FightPropEnum)) {
if (typeof propValue === 'number' && isNaN(Number(propName)) && propName !== 'FIGHT_PROP_NONE') {
try {
const currentValue = await currentAvatar.getProp(propValue)
propsList += translate('cli.commands.fp.info.list', propName, propValue, currentValue)
} catch (error) {
propsList += translate('cli.commands.fp.error.failedGet', propName, propValue, error)
}
}
}
print(propsList)
}

async function getfp(currentAvatar, fightProp) {
const prop = isNaN(parseInt(fightProp)) ? FightPropEnum[<string>fightProp] : fightProp
if (FightPropEnum[prop] == null) return printError(translate('cli.commands.fp.error.invalidFightProp'))

const value = await currentAvatar.getProp(prop)
print(translate('cli.commands.fp.info.get', FightPropEnum[prop], prop, value))
}

async function setfp(currentAvatar, fightProp, value) {
const prop = isNaN(parseInt(fightProp)) ? FightPropEnum[<string>fightProp] : fightProp
if (FightPropEnum[prop] == null) return printError(translate('cli.commands.fp.error.invalidFightProp'))
await currentAvatar.setProp(prop, value, true)
print(translate('cli.commands.fp.info.set', FightPropEnum[prop], prop, value))
}

switch (mode) {
case 'list':
listfp(currentAvatar)
break;
case 'get':
getfp(currentAvatar, fightProp)
break;
case 'set':
setfp(currentAvatar, fightProp, value)
break;
default:
print(translate('cli.commands.fp.info.invalidMode', mode)) // Never use
break;
}
}
};

export default fpCommand;
14 changes: 12 additions & 2 deletions src/cli/commands/avatarCommands/godCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ const godCommand: CommandDefinition = {
name: 'god',
usage: 2,
args: [
{ name: 'uid', type: 'int', optional: true }
{ name: 'uidInput', type: 'str', optional: true },
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const player = kcpServer.game.getPlayerByUid(args[0] || sender?.uid)
const [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'))

player.godMode = !player.godMode
Expand Down
14 changes: 12 additions & 2 deletions src/cli/commands/avatarCommands/guidCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ const guidCommand: CommandDefinition = {
name: 'guid',
usage: 2,
args: [
{ name: 'uid', type: 'int', optional: true }
{ name: 'uidInput', type: 'str', optional: true }
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const player = kcpServer.game.getPlayerByUid(args[0] || sender?.uid)
const [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
Expand Down
14 changes: 12 additions & 2 deletions src/cli/commands/avatarCommands/healCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ const healCommand: CommandDefinition = {
name: 'heal',
usage: 2,
args: [
{ name: 'uid', type: 'int', optional: true }
{ name: 'uidInput', type: 'str', optional: true }
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const player = kcpServer.game.getPlayerByUid(args[0] || sender?.uid)
const [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 avatarList = player.teamManager.getTeam()?.avatarList || []
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/avatarCommands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import guidCommand from './guidCommand'
import healCommand from './healCommand'
import rechargeCommand from './rechargeCommand'
import setcsCommand from './setcsCommand'
import setfpCommand from './setfpCommand'
import talentCommand from './talentCommand'
import fpCommand from './fpCommand'

const avatarCommands: CommandDefinition[] = [
godCommand,
healCommand,
rechargeCommand,
guidCommand,
equipCommand,
fpCommand, // setfp getfp listfp,3 in 1
setcsCommand,
setfpCommand,
talentCommand
]

Expand Down
14 changes: 12 additions & 2 deletions src/cli/commands/avatarCommands/rechargeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ const rechargeCommand: CommandDefinition = {
name: 'recharge',
usage: 2,
args: [
{ name: 'uid', type: 'int', optional: true }
{ name: 'uidInput', type: 'str', optional: true }
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const player = kcpServer.game.getPlayerByUid(args[0] || sender?.uid)
const [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 avatarList = player.teamManager.getTeam()?.avatarList || []
Expand Down
18 changes: 14 additions & 4 deletions src/cli/commands/avatarCommands/setcsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@ const setcsCommand: CommandDefinition = {
usage: 2,
args: [
{ name: 'id', type: 'num' },
{ name: 'uid', type: 'int', optional: true }
{ name: 'uidInput', type: 'str', optional: true }
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const player = kcpServer.game.getPlayerByUid(args[1] || sender?.uid)
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 { currentAvatar } = player
if (!currentAvatar) return printError(translate('generic.playerNoCurAvatar'))

if (await currentAvatar.skillManager.setCandSkillId(args[0])) {
print(translate('cli.commands.setcs.info.setSkill', args[0]))
if (await currentAvatar.skillManager.setCandSkillId(id)) {
print(translate('cli.commands.setcs.info.setSkill', id))
} else {
printError(translate('cli.commands.setcs.error.noSkill'))
}
Expand Down
32 changes: 0 additions & 32 deletions src/cli/commands/avatarCommands/setfpCommand.ts

This file was deleted.

13 changes: 11 additions & 2 deletions src/cli/commands/avatarCommands/talentCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ const talentCommand: CommandDefinition = {
usage: 6,
args: [
{ name: 'mode', type: 'str', values: ['unlock', 'lock', 'list'] },
{ name: 'uid', type: 'int', optional: true }
{ name: 'uidInput', type: 'str', optional: true }
],
allowPlayer: true,
exec: async (cmdInfo) => {
const { args, sender, cli, kcpServer } = cmdInfo
const { print, printError } = cli
const [mode, uid] = args
const [mode, 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'))
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/configCommands/createConfigCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const createConfigCommand: CommandDefinition = {
exec: async (cmdInfo) => {
const { args, cli } = cmdInfo
const { print, printError } = cli
const [name] = args

const configName = args[0] || 'default'
const configName = name || 'default'
const allConfigs = getJson('config.json', {})

if (configName === 'current') return printError(translate('cli.commands.createConfig.error.invalidName', configName))
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/configCommands/deleteConfigCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const deleteConfigCommand: CommandDefinition = {
exec: async (cmdInfo) => {
const { args, cli } = cmdInfo
const { print, printError } = cli
const [name] = args

const configName = args[0] || 'default'
const configName = name || 'default'
const allConfigs = getJson('config.json', {})

if (configName === 'current') return printError(translate('cli.commands.deleteConfig.error.invalidName', configName))
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/configCommands/loadConfigCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ const loadConfigCommand: CommandDefinition = {
exec: async (cmdInfo) => {
const { args, cli, server } = cmdInfo as { args: string[], cli: CLI, server: Server }
const { print, printError } = cli
const [name] = args

const configName = args[0] || 'default'
const configName = name || 'default'
const allConfigs = getJson('config.json', {})

if (configName === 'current') return printError(translate('cli.commands.loadConfig.error.invalidName', configName))
Expand Down
Loading

0 comments on commit a3c3a91

Please sign in to comment.