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
02ef9d84
Commit
02ef9d84
authored
Apr 24, 2022
by
BaiSugar
Browse files
Added command to get all items
parent
f536da0c
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java
0 → 100644
View file @
02ef9d84
package
emu.grasscutter.command.commands
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.def.AvatarData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.avatar.GenshinAvatar
;
import
emu.grasscutter.game.inventory.GenshinItem
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.server.packet.send.PacketItemAddHintNotify
;
import
java.util.LinkedList
;
import
java.util.List
;
@Command
(
label
=
"giveall"
,
usage
=
"giveall [player] <amount>"
,
description
=
"Gives All item to you or the specified player"
,
aliases
=
{
"givea"
},
permission
=
"player.giveall"
)
public
class
GiveAllCommand
implements
CommandHandler
{
@Override
public
void
execute
(
GenshinPlayer
sender
,
List
<
String
>
args
)
{
int
target
,
amount
=
99999
;
switch
(
args
.
size
())
{
default
:
// giveall *no args*
target
=
sender
.
getUid
();
break
;
case
1
:
//[player]
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerByUid
(
target
)
==
null
)
{
CommandHandler
.
sendMessage
(
sender
,
"Invalid player ID."
);
return
;
}
}
catch
(
NumberFormatException
ignored
){
CommandHandler
.
sendMessage
(
sender
,
"Invalid amount or player ID."
);
return
;
}
break
;
case
2
:
//[player] [amount]
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerByUid
(
target
)
==
null
&&
sender
!=
null
)
{
target
=
sender
.
getUid
();
amount
=
Integer
.
parseInt
(
args
.
get
(
0
));
}
else
{
amount
=
Integer
.
parseInt
(
args
.
get
(
1
));
}
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
sender
,
"Invalid amount or player ID."
);
return
;
}
break
;
}
GenshinPlayer
targetPlayer
=
Grasscutter
.
getGameServer
().
getPlayerByUid
(
target
);
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
sender
,
"Player not found."
);
return
;
}
this
.
GetAllItem
(
targetPlayer
,
amount
);
CommandHandler
.
sendMessage
(
sender
,
String
.
format
(
"Get All Items Done."
));
}
public
void
GetAllItem
(
GenshinPlayer
player
,
int
amount
){
CommandHandler
.
sendMessage
(
player
,
"Get All Items..."
);
for
(
ItemData
itemdata:
GenshinData
.
getItemDataMap
().
values
())
{
if
(
itemdata
.
getId
()
>
1000
&&
itemdata
.
getId
()
<=
2000
)
continue
;
//is avatar
if
(
itemdata
.
isEquip
())
{
List
<
GenshinItem
>
items
=
new
LinkedList
<>();
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
items
.
add
(
new
GenshinItem
(
itemdata
));
}
player
.
getInventory
().
addItems
(
items
);
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
items
,
ActionReason
.
SubfieldDrop
));
}
else
{
GenshinItem
genshinItem
=
new
GenshinItem
(
itemdata
);
genshinItem
.
setCount
(
amount
);
player
.
getInventory
().
addItem
(
genshinItem
);
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
genshinItem
,
ActionReason
.
SubfieldDrop
));
}
}
for
(
AvatarData
avatarData:
GenshinData
.
getAvatarDataMap
().
values
())
{
int
ascension
;
int
level
=
90
;
// Calculate ascension level.
if
(
level
<=
40
)
{
ascension
=
(
int
)
Math
.
ceil
(
90
/
20
f
);
}
else
{
ascension
=
(
int
)
Math
.
ceil
(
90
/
10
f
)
-
3
;
}
GenshinAvatar
avatar
=
new
GenshinAvatar
(
avatarData
);
avatar
.
setLevel
(
level
);
avatar
.
setPromoteLevel
(
ascension
);
for
(
int
i
=
1
;
i
<=
6
;
i
++){
avatar
.
getTalentIdList
().
add
((
avatar
.
getAvatarId
()-
10000000
)*
10
+
i
);
//(10000058-10000000)*10+i
}
// This will handle stats and talents
avatar
.
recalcStats
();
player
.
addAvatar
(
avatar
);
}
}
}
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