Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grasscutter
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
ziqian zhang
Grasscutter
Commits
5f8011f0
Commit
5f8011f0
authored
3 years ago
by
ImmuState
Committed by
Melledy
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Added to ability to specify main and substats for /giveart via names instead of IDs.
parent
06f531fe
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/emu/grasscutter/command/commands/GiveArtifactCommand.java
+111
-5
111 additions, 5 deletions
...emu/grasscutter/command/commands/GiveArtifactCommand.java
with
111 additions
and
5 deletions
src/main/java/emu/grasscutter/command/commands/GiveArtifactCommand.java
+
111
−
5
View file @
5f8011f0
...
@@ -9,28 +9,109 @@ import emu.grasscutter.game.inventory.GameItem;
...
@@ -9,28 +9,109 @@ import emu.grasscutter.game.inventory.GameItem;
import
emu.grasscutter.game.inventory.ItemType
;
import
emu.grasscutter.game.inventory.ItemType
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.inventory.EquipType
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
static
java
.
util
.
Map
.
entry
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"giveart"
,
usage
=
"giveart <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]"
,
aliases
=
{
"gart"
},
permission
=
"player.giveart"
,
description
=
"commands.giveArtifact.description
"
)
@Command
(
label
=
"giveart"
,
usage
=
"giveart <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]"
,
description
=
"Gives the player a specified artifact"
,
aliases
=
{
"gart"
},
permission
=
"player.giveart
"
)
public
final
class
GiveArtifactCommand
implements
CommandHandler
{
public
final
class
GiveArtifactCommand
implements
CommandHandler
{
private
static
final
Map
<
String
,
Map
<
EquipType
,
Integer
>>
mainPropMap
=
Map
.
ofEntries
(
entry
(
"hp"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_BRACER
,
14001
))),
entry
(
"hp%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_SHOES
,
10980
),
entry
(
EquipType
.
EQUIP_RING
,
50980
),
entry
(
EquipType
.
EQUIP_DRESS
,
30980
))),
entry
(
"atk"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_NECKLACE
,
12001
))),
entry
(
"atk%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_SHOES
,
10990
),
entry
(
EquipType
.
EQUIP_RING
,
50990
),
entry
(
EquipType
.
EQUIP_DRESS
,
30990
))),
entry
(
"def%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_SHOES
,
10970
),
entry
(
EquipType
.
EQUIP_RING
,
50970
),
entry
(
EquipType
.
EQUIP_DRESS
,
30970
))),
entry
(
"er"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_SHOES
,
10960
))),
entry
(
"em"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_SHOES
,
10950
),
entry
(
EquipType
.
EQUIP_RING
,
50880
),
entry
(
EquipType
.
EQUIP_DRESS
,
30930
))),
entry
(
"hb"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_DRESS
,
30940
))),
entry
(
"cdmg"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_DRESS
,
30950
))),
entry
(
"cr"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_DRESS
,
30960
))),
entry
(
"phys%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_RING
,
50890
))),
entry
(
"dendro%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_RING
,
50900
))),
entry
(
"geo%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_RING
,
50910
))),
entry
(
"anemo%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_RING
,
50920
))),
entry
(
"hydro%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_RING
,
50930
))),
entry
(
"cryo%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_RING
,
50940
))),
entry
(
"electro%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_RING
,
50950
))),
entry
(
"pyro%"
,
Map
.
ofEntries
(
entry
(
EquipType
.
EQUIP_RING
,
50960
)))
);
private
static
final
Map
<
String
,
String
>
appendPropMap
=
Map
.
ofEntries
(
entry
(
"hp"
,
"0102"
),
entry
(
"hp%"
,
"0103"
),
entry
(
"atk"
,
"0105"
),
entry
(
"atk%"
,
"0106"
),
entry
(
"def"
,
"0108"
),
entry
(
"def%"
,
"0109"
),
entry
(
"er"
,
"0123"
),
entry
(
"em"
,
"0124"
),
entry
(
"cr"
,
"0120"
),
entry
(
"cdmg"
,
"0122"
)
);
private
int
getAppendPropId
(
String
substatText
,
ItemData
itemData
)
{
int
res
;
// If the given substat text is an integer, we just use that
// as the append prop ID.
try
{
res
=
Integer
.
parseInt
(
substatText
);
return
res
;
}
catch
(
NumberFormatException
ignores
)
{
// No need to handle this here. We just continue with the
// possibility of the argument being a substat string.
}
// If the argument was not an integer, we try to determine
// the append prop ID from the given text + artifact information.
// A substat string has the format `substat_tier`.
String
[]
substatArgs
=
substatText
.
split
(
"_"
);
if
(
substatArgs
.
length
!=
2
)
{
throw
new
IllegalArgumentException
();
}
String
substatType
=
substatArgs
[
0
];
int
substatTier
=
Integer
.
parseInt
(
substatArgs
[
1
]);
// Check if the specified tier is legal for the artifact rarity.
if
(
substatTier
<
1
||
substatTier
>
4
)
{
throw
new
IllegalArgumentException
();
}
if
(
itemData
.
getRankLevel
()
==
1
&&
substatTier
>
2
)
{
throw
new
IllegalArgumentException
();
}
if
(
itemData
.
getRankLevel
()
==
2
&&
substatTier
>
3
)
{
throw
new
IllegalArgumentException
();
}
// Check if the given substat type string is a legal stat.
if
(!
appendPropMap
.
containsKey
(
substatType
))
{
throw
new
IllegalArgumentException
();
}
// Build the append prop ID.
return
Integer
.
parseInt
(
Integer
.
toString
(
itemData
.
getRankLevel
())
+
appendPropMap
.
get
(
substatType
)
+
Integer
.
toString
(
substatTier
));
}
@Override
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
// Sanity checks
if
(
targetPlayer
==
null
)
{
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.execution.need_target"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.execution.need_target"
));
return
;
return
;
}
}
if
(
args
.
size
()
<
2
)
{
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.giveArtifact.usage"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.giveArtifact.usage"
));
return
;
return
;
}
}
// Get the artifact piece ID from the arguments.
int
itemId
;
int
itemId
;
try
{
try
{
itemId
=
Integer
.
parseInt
(
args
.
remove
(
0
));
itemId
=
Integer
.
parseInt
(
args
.
remove
(
0
));
...
@@ -38,20 +119,35 @@ public final class GiveArtifactCommand implements CommandHandler {
...
@@ -38,20 +119,35 @@ public final class GiveArtifactCommand implements CommandHandler {
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.giveArtifact.id_error"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.giveArtifact.id_error"
));
return
;
return
;
}
}
ItemData
itemData
=
GameData
.
getItemDataMap
().
get
(
itemId
);
ItemData
itemData
=
GameData
.
getItemDataMap
().
get
(
itemId
);
if
(
itemData
.
getItemType
()
!=
ItemType
.
ITEM_RELIQUARY
)
{
if
(
itemData
.
getItemType
()
!=
ItemType
.
ITEM_RELIQUARY
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.giveArtifact.id_error"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.giveArtifact.id_error"
));
return
;
return
;
}
}
// Get the main stat from the arguments.
// If the given argument is an integer, we use that.
// If not, we check if the argument string is in the main prop map.
String
mainPropIdString
=
args
.
remove
(
0
);
int
mainPropId
;
int
mainPropId
;
try
{
try
{
mainPropId
=
Integer
.
parseInt
(
args
.
remove
(
0
)
);
mainPropId
=
Integer
.
parseInt
(
mainPropIdString
);
}
catch
(
NumberFormatException
ignored
)
{
}
catch
(
NumberFormatException
ignored
)
{
mainPropId
=
-
1
;
}
if
(
mainPropMap
.
containsKey
(
mainPropIdString
)
&&
mainPropMap
.
get
(
mainPropIdString
).
containsKey
(
itemData
.
getEquipType
()))
{
mainPropId
=
mainPropMap
.
get
(
mainPropIdString
).
get
(
itemData
.
getEquipType
());
}
if
(
mainPropId
==
-
1
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.generic.execution.argument_error"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.generic.execution.argument_error"
));
return
;
return
;
}
}
// Get the level from the arguments.
int
level
=
1
;
int
level
=
1
;
try
{
try
{
int
last
=
Integer
.
parseInt
(
args
.
get
(
args
.
size
()-
1
));
int
last
=
Integer
.
parseInt
(
args
.
get
(
args
.
size
()-
1
));
...
@@ -62,9 +158,13 @@ public final class GiveArtifactCommand implements CommandHandler {
...
@@ -62,9 +158,13 @@ public final class GiveArtifactCommand implements CommandHandler {
}
catch
(
NumberFormatException
ignored
)
{
// Could be a stat,times string so no need to panic
}
catch
(
NumberFormatException
ignored
)
{
// Could be a stat,times string so no need to panic
}
}
List
<
Integer
>
appendPropIdList
=
new
ArrayList
<>();
// Get substats.
ArrayList
<
Integer
>
appendPropIdList
=
new
ArrayList
<>();
try
{
try
{
// Every remaining argument is a substat.
args
.
forEach
(
it
->
{
args
.
forEach
(
it
->
{
// The substat syntax permits specifying a number of rolls for the given
// substat. Split the string into stat and number if that is the case here.
String
[]
arr
;
String
[]
arr
;
int
n
=
1
;
int
n
=
1
;
if
((
arr
=
it
.
split
(
","
)).
length
==
2
)
{
if
((
arr
=
it
.
split
(
","
)).
length
==
2
)
{
...
@@ -74,13 +174,19 @@ public final class GiveArtifactCommand implements CommandHandler {
...
@@ -74,13 +174,19 @@ public final class GiveArtifactCommand implements CommandHandler {
n
=
200
;
n
=
200
;
}
}
}
}
appendPropIdList
.
addAll
(
Collections
.
nCopies
(
n
,
Integer
.
parseInt
(
it
)));
// Determine the substat ID.
int
appendPropId
=
getAppendPropId
(
it
,
itemData
);
// Add the current substat.
appendPropIdList
.
addAll
(
Collections
.
nCopies
(
n
,
appendPropId
));
});
});
}
catch
(
Exception
ignored
)
{
}
catch
(
Exception
ignored
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.execution.argument_error"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.execution.argument_error"
));
return
;
return
;
}
}
// Create item for the artifact.
GameItem
item
=
new
GameItem
(
itemData
);
GameItem
item
=
new
GameItem
(
itemData
);
item
.
setLevel
(
level
);
item
.
setLevel
(
level
);
item
.
setMainPropId
(
mainPropId
);
item
.
setMainPropId
(
mainPropId
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment