forked from Wangsheng-Funeral-Parlor/HuTao-GS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Sycamore0/command-update
Command update
- Loading branch information
Showing
48 changed files
with
973 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.