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
d0ccc486
Commit
d0ccc486
authored
Apr 29, 2022
by
真心
Committed by
memetrollsXD
Apr 29, 2022
Browse files
Add 'refinement' option to 'give' command
parent
9892cd84
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/GiveCommand.java
View file @
d0ccc486
...
...
@@ -6,20 +6,20 @@ import emu.grasscutter.command.CommandHandler;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.def.ItemData
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.inventory.ItemType
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.server.packet.send.PacketItemAddHintNotify
;
import
java.util.LinkedList
;
import
java.util.List
;
@Command
(
label
=
"give"
,
usage
=
"give [player] <itemId|itemName> [amount] [level]"
,
description
=
"Gives an item to you or the specified player"
,
aliases
=
{
"g"
,
"item"
,
"giveitem"
},
permission
=
"player.give"
)
"g"
,
"item"
,
"giveitem"
},
permission
=
"player.give"
)
public
final
class
GiveCommand
implements
CommandHandler
{
@Override
public
void
execute
(
Player
sender
,
List
<
String
>
args
)
{
int
target
,
item
,
lvl
,
amount
=
1
;
int
target
,
item
,
lvl
,
amount
=
1
,
refinement
=
0
;
if
(
sender
==
null
&&
args
.
size
()
<
2
)
{
CommandHandler
.
sendMessage
(
null
,
"Usage: give <player> <itemId|itemName> [amount] [level]"
);
return
;
...
...
@@ -79,7 +79,28 @@ public final class GiveCommand implements CommandHandler {
return
;
}
break
;
case
4
:
// [player] <itemId|itemName> [amount] [level]
case
4
:
// [player] <itemId|itemName> [amount] [level] | <itemId|itemName> [amount] [level] [refinement]
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
if
(
Grasscutter
.
getGameServer
().
getPlayerByUid
(
target
)
==
null
&&
sender
!=
null
)
{
target
=
sender
.
getUid
();
item
=
Integer
.
parseInt
(
args
.
get
(
0
));
amount
=
Integer
.
parseInt
(
args
.
get
(
1
));
lvl
=
Integer
.
parseInt
(
args
.
get
(
2
));
refinement
=
Integer
.
parseInt
(
args
.
get
(
3
));
}
else
{
item
=
Integer
.
parseInt
(
args
.
get
(
1
));
amount
=
Integer
.
parseInt
(
args
.
get
(
2
));
lvl
=
Integer
.
parseInt
(
args
.
get
(
3
));
}
}
catch
(
NumberFormatException
ignored
)
{
// TODO: Parse from item name using GM Handbook.
CommandHandler
.
sendMessage
(
sender
,
"Invalid item or player ID."
);
return
;
}
break
;
case
5
:
// [player] <itemId|itemName> [amount] [level] [refinement]
try
{
target
=
Integer
.
parseInt
(
args
.
get
(
0
));
...
...
@@ -90,6 +111,7 @@ public final class GiveCommand implements CommandHandler {
item
=
Integer
.
parseInt
(
args
.
get
(
1
));
amount
=
Integer
.
parseInt
(
args
.
get
(
2
));
lvl
=
Integer
.
parseInt
(
args
.
get
(
3
));
refinement
=
Integer
.
parseInt
(
args
.
get
(
4
));
}
}
catch
(
NumberFormatException
ignored
)
{
// TODO: Parse from item name using GM Handbook.
...
...
@@ -111,44 +133,67 @@ public final class GiveCommand implements CommandHandler {
CommandHandler
.
sendMessage
(
sender
,
"Invalid item id."
);
return
;
}
if
(
refinement
!=
0
)
{
if
(
itemData
.
getItemType
()
==
ItemType
.
ITEM_WEAPON
)
{
if
(
refinement
<
1
||
refinement
>
5
)
{
CommandHandler
.
sendMessage
(
sender
,
"Refinement must be between 1 and 5."
);
return
;
}
}
else
{
CommandHandler
.
sendMessage
(
sender
,
"Refinement is only applicable to weapons."
);
return
;
}
}
this
.
item
(
targetPlayer
,
itemData
,
amount
,
lvl
);
this
.
item
(
targetPlayer
,
itemData
,
amount
,
lvl
,
refinement
);
if
(!
itemData
.
isEquip
())
if
(!
itemData
.
isEquip
())
{
CommandHandler
.
sendMessage
(
sender
,
String
.
format
(
"Given %s of %s to %s."
,
amount
,
item
,
target
));
else
}
else
if
(
itemData
.
getItemType
()
==
ItemType
.
ITEM_WEAPON
)
{
CommandHandler
.
sendMessage
(
sender
,
String
.
format
(
"Given %s with level %s, refinement %s %s times to %s"
,
item
,
lvl
,
refinement
,
amount
,
target
));
}
else
{
CommandHandler
.
sendMessage
(
sender
,
String
.
format
(
"Given %s with level %s %s times to %s"
,
item
,
lvl
,
amount
,
target
));
}
}
private
void
item
(
Player
player
,
ItemData
itemData
,
int
amount
,
int
lvl
)
{
private
boolean
item
(
Player
player
,
ItemData
itemData
,
int
amount
,
int
lvl
,
int
refinement
)
{
if
(
itemData
.
isEquip
())
{
List
<
GameItem
>
items
=
new
LinkedList
<>();
for
(
int
i
=
0
;
i
<
amount
;
i
++)
{
GameItem
item
=
new
GameItem
(
itemData
);
item
.
setCount
(
amount
);
item
.
setLevel
(
lvl
);
item
.
setPromoteLevel
(
0
);
if
(
lvl
>
20
)
{
// 20/40
if
(
lvl
>
20
&&
lvl
<
40
)
{
item
.
setPromoteLevel
(
1
);
}
else
if
(
lvl
>
40
)
{
// 40/50
}
else
if
(
lvl
>
40
&&
lvl
<=
50
)
{
item
.
setPromoteLevel
(
2
);
}
else
if
(
lvl
>
50
)
{
// 50/60
}
else
if
(
lvl
>
50
&&
lvl
<=
60
)
{
item
.
setPromoteLevel
(
3
);
}
else
if
(
lvl
>
60
)
{
// 60/70
}
else
if
(
lvl
>
60
&&
lvl
<=
70
)
{
item
.
setPromoteLevel
(
4
);
}
else
if
(
lvl
>
70
)
{
// 70/80
}
else
if
(
lvl
>
70
&&
lvl
<=
80
)
{
item
.
setPromoteLevel
(
5
);
}
else
if
(
lvl
>
80
)
{
// 80/90
}
else
if
(
lvl
>
80
&&
lvl
<=
90
)
{
item
.
setPromoteLevel
(
6
);
}
if
(
item
.
getItemType
()
==
ItemType
.
ITEM_WEAPON
)
{
if
(
refinement
>
0
)
{
item
.
setRefinement
(
refinement
-
1
);
}
else
{
item
.
setRefinement
(
0
);
}
}
items
.
add
(
item
);
}
player
.
getInventory
().
addItems
(
items
,
ActionReason
.
SubfieldDrop
);
return
true
;
}
else
{
GameItem
item
=
new
GameItem
(
itemData
);
item
.
setCount
(
amount
);
player
.
getInventory
().
addItem
(
item
,
ActionReason
.
SubfieldDrop
);
return
true
;
}
}
}
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