Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
055da209
Commit
055da209
authored
Apr 19, 2022
by
Melledy
Committed by
GitHub
Apr 19, 2022
Browse files
Merge pull request #20 from SpikeHD/char-command
Give character command
parents
2d43ae81
ed448a9f
Changes
3
Show whitespace changes
Inline
Side-by-side
README.md
View file @
055da209
...
@@ -49,6 +49,8 @@ There is a dummy user named "Server" in every player's friends list that you can
...
@@ -49,6 +49,8 @@ There is a dummy user named "Server" in every player's friends list that you can
`!give [item id] [amount]`
`!give [item id] [amount]`
`!givechar [avatar id] [level]`
`!drop [item id] [amount]`
`!drop [item id] [amount]`
`!killall`
`!killall`
...
...
src/main/java/emu/grasscutter/commands/PlayerCommands.java
View file @
055da209
...
@@ -3,6 +3,8 @@ package emu.grasscutter.commands;
...
@@ -3,6 +3,8 @@ package emu.grasscutter.commands;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.data.def.AvatarData
;
import
emu.grasscutter.data.def.AvatarSkillDepotData
;
import
emu.grasscutter.data.def.MonsterData
;
import
emu.grasscutter.data.def.MonsterData
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.World
;
import
emu.grasscutter.game.World
;
...
@@ -177,6 +179,133 @@ public final class PlayerCommands {
...
@@ -177,6 +179,133 @@ public final class PlayerCommands {
}
}
}
}
@Command
(
label
=
"givechar"
,
aliases
=
{
"givec"
},
usage
=
"Usage: givechar <playerId> <avatarId> [level]"
)
public
static
class
GiveCharCommand
implements
CommandHandler
{
@Override
public
void
execute
(
GenshinPlayer
player
,
List
<
String
>
args
)
{
int
target
,
avatarID
,
level
=
1
,
ascension
=
1
;
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendMessage
(
null
,
"Usage: givechar <player> <avatarId> [level]"
);
return
;
}
switch
(
args
.
size
())
{
default
:
CommandHandler
.
sendMessage
(
null
,
"Usage: givechar <player> <avatarId> [level]"
);
return
;
case
1
:
try
{
avatarID
=
Integer
.
parseInt
(
args
.
get
(
0
));
target
=
player
.
getAccount
().
getPlayerId
();
}
catch
(
NumberFormatException
ignored
)
{
// TODO: Parse from avatar name using GM Handbook.
CommandHandler
.
sendMessage
(
player
,
"Invalid avatar id."
);
return
;
}
break
;
case
2
:
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerById
(
target
)
==
null
)
{
target
=
player
.
getId
();
level
=
Integer
.
parseInt
(
args
.
get
(
1
));
avatarID
=
Integer
.
parseInt
(
args
.
get
(
0
));
}
else
{
avatarID
=
Integer
.
parseInt
(
args
.
get
(
1
));
}
}
catch
(
NumberFormatException
ignored
)
{
// TODO: Parse from avatar name using GM Handbook.
CommandHandler
.
sendMessage
(
player
,
"Invalid avatar or player ID."
);
return
;
}
break
;
case
3
:
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerById
(
target
)
==
null
)
{
CommandHandler
.
sendMessage
(
player
,
"Invalid player ID."
);
return
;
}
avatarID
=
Integer
.
parseInt
(
args
.
get
(
1
));
level
=
Integer
.
parseInt
(
args
.
get
(
2
));
}
catch
(
NumberFormatException
ignored
)
{
// TODO: Parse from avatar name using GM Handbook.
CommandHandler
.
sendMessage
(
player
,
"Invalid avatar or player ID."
);
return
;
}
break
;
}
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerById
(
target
);
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
}
AvatarData
avatarData
=
GenshinData
.
getAvatarDataMap
().
get
(
avatarID
);
if
(
avatarData
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid avatar id."
);
return
;
}
// Calculate ascension level.
if
(
level
<=
40
)
{
ascension
=
(
int
)
Math
.
ceil
(
level
/
20
);
}
else
if
(
level
>
20
)
{
ascension
=
(
int
)
Math
.
ceil
(
level
/
10
)
-
3
;
}
GenshinAvatar
avatar
=
new
GenshinAvatar
(
avatarID
);
avatar
.
setLevel
(
level
);
avatar
.
setPromoteLevel
(
ascension
);
// This will handle stats and talents
avatar
.
recalcStats
();
targetPlayer
.
addAvatar
(
avatar
);
}
@Override
public
void
execute
(
List
<
String
>
args
)
{
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendMessage
(
null
,
"Usage: givechar <player> <itemId|itemName> [amount]"
);
return
;
}
try
{
int
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
int
avatarID
=
Integer
.
parseInt
(
args
.
get
(
1
));
int
level
=
1
;
if
(
args
.
size
()
>
2
)
level
=
Integer
.
parseInt
(
args
.
get
(
2
));
int
ascension
=
1
;
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerById
(
target
);
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Player not found."
);
return
;
}
AvatarData
avatarData
=
GenshinData
.
getAvatarDataMap
().
get
(
avatarID
);
if
(
avatarData
==
null
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid avatar id."
);
return
;
}
// Calculate ascension level.
if
(
level
<=
40
)
{
ascension
=
(
int
)
Math
.
ceil
(
level
/
20
);
}
else
if
(
level
>
20
)
{
ascension
=
(
int
)
Math
.
ceil
(
level
/
10
)
-
3
;
}
GenshinAvatar
avatar
=
new
GenshinAvatar
(
avatarID
);
avatar
.
setLevel
(
level
);
avatar
.
setPromoteLevel
(
ascension
);
// This will handle stats and talents
avatar
.
recalcStats
();
targetPlayer
.
addAvatar
(
avatar
);
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
null
,
"Invalid item or player ID."
);
}
}
}
@Command
(
label
=
"spawn"
,
execution
=
Command
.
Execution
.
PLAYER
,
@Command
(
label
=
"spawn"
,
execution
=
Command
.
Execution
.
PLAYER
,
usage
=
"Usage: spawn <entityId|entityName> [level] [amount]"
)
usage
=
"Usage: spawn <entityId|entityName> [level] [amount]"
)
public
static
class
SpawnCommand
implements
CommandHandler
{
public
static
class
SpawnCommand
implements
CommandHandler
{
...
...
src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java
View file @
055da209
...
@@ -510,6 +510,21 @@ public class GenshinAvatar {
...
@@ -510,6 +510,21 @@ public class GenshinAvatar {
}
}
}
}
// Add proud skills and unlock them if needed
AvatarSkillDepotData
skillDepot
=
GenshinData
.
getAvatarSkillDepotDataMap
().
get
(
this
.
getSkillDepotId
());
this
.
getProudSkillList
().
clear
();
for
(
InherentProudSkillOpens
openData
:
skillDepot
.
getInherentProudSkillOpens
())
{
if
(
openData
.
getProudSkillGroupId
()
==
0
)
{
continue
;
}
if
(
openData
.
getNeedAvatarPromoteLevel
()
<=
this
.
getPromoteLevel
())
{
int
proudSkillId
=
(
openData
.
getProudSkillGroupId
()
*
100
)
+
1
;
if
(
GenshinData
.
getProudSkillDataMap
().
containsKey
(
proudSkillId
))
{
this
.
getProudSkillList
().
add
(
proudSkillId
);
}
}
}
// Proud skills
// Proud skills
for
(
int
proudSkillId
:
this
.
getProudSkillList
())
{
for
(
int
proudSkillId
:
this
.
getProudSkillList
())
{
ProudSkillData
proudSkillData
=
GenshinData
.
getProudSkillDataMap
().
get
(
proudSkillId
);
ProudSkillData
proudSkillData
=
GenshinData
.
getProudSkillDataMap
().
get
(
proudSkillId
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment