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
a8293102
Commit
a8293102
authored
Jun 07, 2022
by
Melledy
Committed by
GitHub
Jun 07, 2022
Browse files
Merge branch 'development' into stable
parents
304b9cb8
ecf7a81a
Changes
410
Expand all
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/TeamCommand.java
0 → 100644
View file @
a8293102
package
emu.grasscutter.command.commands
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.server.packet.send.PacketChangeMpTeamAvatarRsp
;
import
java.util.List
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
static
emu
.
grasscutter
.
Configuration
.*;
@Command
(
label
=
"team"
,
usage
=
"team <add|remove|set> [avatarId,...] [index|first|last|index-index,...]"
,
permission
=
"player.team"
,
permissionTargeted
=
"player.team.others"
,
description
=
"commands.team.description"
)
public
final
class
TeamCommand
implements
CommandHandler
{
private
static
final
int
BASE_AVATARID
=
10000000
;
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
isEmpty
())
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.usage"
);
return
;
}
switch
(
args
.
get
(
0
))
{
case
"add"
:
if
(!
addCommand
(
sender
,
targetPlayer
,
args
))
return
;
break
;
case
"remove"
:
if
(!
removeCommand
(
sender
,
targetPlayer
,
args
))
return
;
break
;
case
"set"
:
if
(!
setCommand
(
sender
,
targetPlayer
,
args
))
return
;
break
;
default
:
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.invalid_usage"
);
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.usage"
);
return
;
}
targetPlayer
.
getTeamManager
().
updateTeamEntities
(
new
PacketChangeMpTeamAvatarRsp
(
targetPlayer
,
targetPlayer
.
getTeamManager
().
getCurrentTeamInfo
()));
}
private
boolean
addCommand
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.invalid_usage"
);
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.add_usage"
);
return
false
;
}
int
index
=
-
1
;
if
(
args
.
size
()
>
2
)
{
try
{
index
=
Integer
.
parseInt
(
args
.
get
(
2
))
-
1
;
if
(
index
<
0
)
index
=
0
;
}
catch
(
Exception
e
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.invalid_index"
);
return
false
;
}
}
var
avatarIds
=
args
.
get
(
1
).
split
(
","
);
var
currentTeamAvatars
=
targetPlayer
.
getTeamManager
().
getCurrentTeamInfo
().
getAvatars
();
if
(
currentTeamAvatars
.
size
()
+
avatarIds
.
length
>
GAME_OPTIONS
.
avatarLimits
.
singlePlayerTeam
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.add_too_much"
,
GAME_OPTIONS
.
avatarLimits
.
singlePlayerTeam
);
return
false
;
}
for
(
var
avatarId:
avatarIds
)
{
int
id
=
Integer
.
parseInt
(
avatarId
);
var
success
=
addAvatar
(
sender
,
targetPlayer
,
id
,
index
);
if
(
index
>
0
)
++
index
;
}
return
true
;
}
private
boolean
removeCommand
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
<
2
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.invalid_usage"
);
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.remove_usage"
);
return
false
;
}
var
currentTeamAvatars
=
targetPlayer
.
getTeamManager
().
getCurrentTeamInfo
().
getAvatars
();
var
avatarCount
=
currentTeamAvatars
.
size
();
var
metaIndexList
=
args
.
get
(
1
).
split
(
","
);
var
indexes
=
new
HashSet
<
Integer
>();
var
ignoreList
=
new
ArrayList
<
Integer
>();
for
(
var
metaIndex:
metaIndexList
)
{
// step 1: parse metaIndex to indexes
var
subIndexes
=
transformToIndexes
(
metaIndex
,
avatarCount
);
if
(
subIndexes
==
null
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.failed_to_parse_index"
,
metaIndex
);
continue
;
}
// step 2: get all of the avatar id through indexes
for
(
var
avatarIndex:
subIndexes
)
{
try
{
indexes
.
add
(
currentTeamAvatars
.
get
(
avatarIndex
-
1
));
}
catch
(
Exception
e
)
{
ignoreList
.
add
(
avatarIndex
);
continue
;
}
}
}
// step 3: check if user remove all of the avatar
if
(
indexes
.
size
()
>=
avatarCount
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.remove_too_much"
);
return
false
;
}
// step 4: hint user for ignore index
if
(!
ignoreList
.
isEmpty
())
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.ignore_index"
,
ignoreList
);
}
// step 5: remove
currentTeamAvatars
.
removeAll
(
indexes
);
return
true
;
}
private
boolean
setCommand
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
args
.
size
()
<
3
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.invalid_usage"
);
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.set_usage"
);
return
false
;
}
var
currentTeamAvatars
=
targetPlayer
.
getTeamManager
().
getCurrentTeamInfo
().
getAvatars
();
int
index
;
try
{
index
=
Integer
.
parseInt
(
args
.
get
(
1
))
-
1
;
if
(
index
<
0
)
index
=
0
;
}
catch
(
Exception
e
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.failed_to_parse_index"
,
args
.
get
(
1
));
return
false
;
}
if
(
index
+
1
>
currentTeamAvatars
.
size
())
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.index_out_of_range"
);
return
false
;
}
int
avatarId
;
try
{
avatarId
=
Integer
.
parseInt
(
args
.
get
(
2
));
}
catch
(
Exception
e
)
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.failed_parse_avatar_id"
,
args
.
get
(
2
));
return
false
;
}
if
(
avatarId
<
BASE_AVATARID
)
{
avatarId
+=
BASE_AVATARID
;
}
if
(
currentTeamAvatars
.
contains
(
avatarId
))
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.avatar_already_in_team"
,
avatarId
);
return
false
;
}
if
(!
targetPlayer
.
getAvatars
().
hasAvatar
(
avatarId
))
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.avatar_not_found"
,
avatarId
);
return
false
;
}
currentTeamAvatars
.
set
(
index
,
avatarId
);
return
true
;
}
private
boolean
addAvatar
(
Player
sender
,
Player
targetPlayer
,
int
avatarId
,
int
index
)
{
if
(
avatarId
<
BASE_AVATARID
)
{
avatarId
+=
BASE_AVATARID
;
}
var
currentTeamAvatars
=
targetPlayer
.
getTeamManager
().
getCurrentTeamInfo
().
getAvatars
();
if
(
currentTeamAvatars
.
contains
(
avatarId
))
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.avatar_already_in_team"
,
avatarId
);
return
false
;
}
if
(!
targetPlayer
.
getAvatars
().
hasAvatar
(
avatarId
))
{
CommandHandler
.
sendTranslatedMessage
(
sender
,
"commands.team.avatar_not_found"
,
avatarId
);
return
false
;
}
if
(
index
<
0
)
{
currentTeamAvatars
.
add
(
avatarId
);
}
else
{
currentTeamAvatars
.
add
(
index
,
avatarId
);
}
return
true
;
}
private
List
<
Integer
>
transformToIndexes
(
String
metaIndexes
,
int
listLength
)
{
// step 1: check if metaIndexes is a special constants
if
(
metaIndexes
.
equals
(
"first"
))
{
return
List
.
of
(
1
);
}
else
if
(
metaIndexes
.
equals
(
"last"
))
{
return
List
.
of
(
listLength
);
}
// step 2: check if metaIndexes is a range
if
(
metaIndexes
.
contains
(
"-"
))
{
var
range
=
metaIndexes
.
split
(
"-"
);
if
(
range
.
length
<
2
)
{
return
null
;
}
int
min
,
max
;
try
{
min
=
switch
(
range
[
0
])
{
case
"first"
->
1
;
case
"last"
->
listLength
;
default
->
Integer
.
parseInt
(
range
[
0
]);
};
max
=
switch
(
range
[
1
])
{
case
"first"
->
1
;
case
"last"
->
listLength
;
default
->
Integer
.
parseInt
(
range
[
1
]);
};
}
catch
(
Exception
e
)
{
return
null
;
}
if
(
min
>
max
)
{
min
^=
max
;
max
^=
min
;
min
^=
max
;
}
var
indexes
=
new
ArrayList
<
Integer
>();
for
(
int
i
=
min
;
i
<=
max
;
++
i
)
{
indexes
.
add
(
i
);
}
return
indexes
;
}
// step 3: index is a value, simply return
try
{
int
index
=
Integer
.
parseInt
(
metaIndexes
);
return
List
.
of
(
index
);
}
catch
(
Exception
e
)
{
return
null
;
}
}
}
src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java
View file @
a8293102
...
...
@@ -10,18 +10,13 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"tpall"
,
usage
=
"tpall"
,
description
=
"Teleports all players in your world to your position"
,
permission
=
"player.tpall"
)
@Command
(
label
=
"tpall"
,
usage
=
"tpall"
,
permission
=
"player.tpall"
,
permissionTargeted
=
"player.tpall.others"
,
description
=
"commands.teleportAll.description"
)
public
final
class
TeleportAllCommand
implements
CommandHandler
{
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.execution.need_target"
));
return
;
}
if
(!
targetPlayer
.
getWorld
().
isMultiplayer
())
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.teleportAll.error"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleportAll.error"
));
return
;
}
...
...
@@ -33,6 +28,6 @@ public final class TeleportAllCommand implements CommandHandler {
player
.
getWorld
().
transferPlayerToScene
(
player
,
targetPlayer
.
getSceneId
(),
pos
);
}
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.teleportAll.success"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleportAll.success"
));
}
}
src/main/java/emu/grasscutter/command/commands/TeleportCommand.java
View file @
a8293102
...
...
@@ -10,8 +10,7 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"teleport"
,
usage
=
"teleport <x> <y> <z> [scene id]"
,
aliases
=
{
"tp"
},
description
=
"Change the player's position."
,
permission
=
"player.teleport"
)
@Command
(
label
=
"teleport"
,
usage
=
"teleport <x> <y> <z> [sceneId]"
,
aliases
=
{
"tp"
},
permission
=
"player.teleport"
,
permissionTargeted
=
"player.teleport.others"
,
description
=
"commands.teleport.description"
)
public
final
class
TeleportCommand
implements
CommandHandler
{
private
float
parseRelative
(
String
input
,
Float
current
)
{
// TODO: Maybe this will be useful elsewhere later
...
...
@@ -27,11 +26,6 @@ public final class TeleportCommand implements CommandHandler {
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.execution.need_target"
));
return
;
}
Position
pos
=
targetPlayer
.
getPos
();
float
x
=
pos
.
getX
();
float
y
=
pos
.
getY
();
...
...
@@ -43,7 +37,7 @@ public final class TeleportCommand implements CommandHandler {
try
{
sceneId
=
Integer
.
parseInt
(
args
.
get
(
3
));
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.execution.argument_error"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.execution.argument_error"
));
}
// Fallthrough
case
3
:
try
{
...
...
@@ -51,20 +45,20 @@ public final class TeleportCommand implements CommandHandler {
y
=
parseRelative
(
args
.
get
(
1
),
y
);
z
=
parseRelative
(
args
.
get
(
2
),
z
);
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.teleport.invalid_position"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleport.invalid_position"
));
}
break
;
default
:
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.teleport.usage"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleport.usage"
));
return
;
}
Position
target_pos
=
new
Position
(
x
,
y
,
z
);
boolean
result
=
targetPlayer
.
getWorld
().
transferPlayerToScene
(
targetPlayer
,
sceneId
,
target_pos
);
if
(!
result
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.teleport.invalid_position"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleport.invalid_position"
));
}
else
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.teleport.success"
,
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.teleport.success"
,
targetPlayer
.
getNickname
(),
Float
.
toString
(
x
),
Float
.
toString
(
y
),
Float
.
toString
(
z
),
Integer
.
toString
(
sceneId
))
);
...
...
src/main/java/emu/grasscutter/command/commands/UnlimitEnergyCommand.java
0 → 100644
View file @
a8293102
package
emu.grasscutter.command.commands
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.managers.EnergyManager.EnergyManager
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.TeamManager
;
import
emu.grasscutter.game.props.ElementType
;
import
emu.grasscutter.net.proto.PropChangeReasonOuterClass
;
import
emu.grasscutter.utils.Position
;
import
java.util.List
;
import
static
emu
.
grasscutter
.
Configuration
.
GAME_OPTIONS
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"unlimitenergy"
,
usage
=
"unlimitenergy [on|off|toggle]"
,
aliases
=
{
"ule"
},
permission
=
"player.unlimitenergy"
,
permissionTargeted
=
"player.unlimitenergy.others"
,
description
=
"commands.unlimitenergy.description"
)
public
final
class
UnlimitEnergyCommand
implements
CommandHandler
{
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(!
GAME_OPTIONS
.
energyUsage
){
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.unlimitenergy.config_error"
));
return
;
}
Boolean
status
=
targetPlayer
.
getEnergyManager
().
getEnergyUsage
();
if
(
args
.
size
()
==
1
)
{
switch
(
args
.
get
(
0
).
toLowerCase
())
{
case
"on"
:
status
=
true
;
break
;
case
"off"
:
status
=
false
;
break
;
default
:
status
=
!
status
;
break
;
}
}
EnergyManager
energyManager
=
targetPlayer
.
getEnergyManager
();
energyManager
.
setEnergyUsage
(!
status
);
// if unlimitEnergy is enable , make currentActiveTeam's Avatar full-energy
if
(
status
)
{
for
(
EntityAvatar
entityAvatar
:
targetPlayer
.
getTeamManager
().
getActiveTeam
())
{
entityAvatar
.
addEnergy
(
1000
,
PropChangeReasonOuterClass
.
PropChangeReason
.
PROP_CHANGE_REASON_GM
,
true
);
}
}
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.unlimitenergy.success"
,
(
status
?
translate
(
sender
,
"commands.status.enabled"
)
:
translate
(
sender
,
"commands.status.disabled"
)),
targetPlayer
.
getNickname
()));
}
}
src/main/java/emu/grasscutter/command/commands/UnlockTowerCommand.java
0 → 100644
View file @
a8293102
package
emu.grasscutter.command.commands
;
import
emu.grasscutter.command.Command
;
import
emu.grasscutter.command.CommandHandler
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.tower.TowerLevelRecord
;
import
java.util.List
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"unlocktower"
,
usage
=
"unlocktower"
,
aliases
=
{
"ut"
},
description
=
"commands.unlocktower.description"
,
permission
=
"player.tower"
)
public
class
UnlockTowerCommand
implements
CommandHandler
{
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
unlockFloor
(
targetPlayer
,
targetPlayer
.
getServer
().
getTowerScheduleManager
()
.
getCurrentTowerScheduleData
().
getEntranceFloorId
());
unlockFloor
(
targetPlayer
,
targetPlayer
.
getServer
().
getTowerScheduleManager
()
.
getScheduleFloors
());
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.unlocktower.success"
));
}
public
void
unlockFloor
(
Player
player
,
List
<
Integer
>
floors
){
floors
.
stream
()
.
filter
(
id
->
!
player
.
getTowerManager
().
getRecordMap
().
containsKey
(
id
))
.
forEach
(
id
->
player
.
getTowerManager
().
getRecordMap
().
put
(
id
,
new
TowerLevelRecord
(
id
)));
}
}
src/main/java/emu/grasscutter/command/commands/WeatherCommand.java
View file @
a8293102
...
...
@@ -11,17 +11,11 @@ import java.util.List;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"weather"
,
usage
=
"weather <weatherId> [climateId]"
,
description
=
"Changes the weather."
,
aliases
=
{
"w"
},
permission
=
"player.weather"
)
@Command
(
label
=
"weather"
,
usage
=
"weather <climate type(weatherId)> <weather type(climateId)>"
,
aliases
=
{
"w"
},
permission
=
"player.weather"
,
permissionTargeted
=
"player.weather.others"
,
description
=
"commands.weather.description"
)
public
final
class
WeatherCommand
implements
CommandHandler
{
@Override
public
void
execute
(
Player
sender
,
Player
targetPlayer
,
List
<
String
>
args
)
{
if
(
targetPlayer
==
null
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.execution.need_target"
));
return
;
}
int
weatherId
=
0
;
int
climateId
=
1
;
switch
(
args
.
size
())
{
...
...
@@ -29,17 +23,17 @@ public final class WeatherCommand implements CommandHandler {
try
{
climateId
=
Integer
.
parseInt
(
args
.
get
(
1
));
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.weather.invalid_id"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.weather.invalid_id"
));
}
case
1
:
try
{
weatherId
=
Integer
.
parseInt
(
args
.
get
(
0
));
}
catch
(
NumberFormatException
ignored
)
{
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.weather.invalid_id"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.weather.invalid_id"
));
}
break
;
default
:
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.weather.usage"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.weather.usage"
));
return
;
}
...
...
@@ -48,6 +42,6 @@ public final class WeatherCommand implements CommandHandler {
targetPlayer
.
getScene
().
setWeather
(
weatherId
);
targetPlayer
.
getScene
().
setClimate
(
climate
);
targetPlayer
.
getScene
().
broadcastPacket
(
new
PacketSceneAreaWeatherNotify
(
targetPlayer
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
"commands.weather.success"
,
Integer
.
toString
(
weatherId
),
Integer
.
toString
(
climateId
)));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.weather.success"
,
Integer
.
toString
(
weatherId
),
Integer
.
toString
(
climateId
)));
}
}
src/main/java/emu/grasscutter/data/DataLoader.java
0 → 100644
View file @
a8293102
package
emu.grasscutter.data
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.server.http.handlers.GachaHandler
;
import
emu.grasscutter.tools.Tools
;
import
emu.grasscutter.utils.FileUtils
;
import
emu.grasscutter.utils.Utils
;
import
java.io.*
;
import
java.nio.file.FileSystems
;
import
java.nio.file.Path
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
static
emu
.
grasscutter
.
Configuration
.
DATA
;
public
class
DataLoader
{
/**
* Load a data file by its name. If the file isn't found within the /data directory then it will fallback to the default within the jar resources
* @see #load(String, boolean)
* @param resourcePath The path to the data file to be loaded.
* @return InputStream of the data file.
* @throws FileNotFoundException
*/
public
static
InputStream
load
(
String
resourcePath
)
throws
FileNotFoundException
{
return
load
(
resourcePath
,
true
);
}
/**
* Load a data file by its name.
* @param resourcePath The path to the data file to be loaded.
* @param useFallback If the file does not exist in the /data directory, should it use the default file in the jar?
* @return InputStream of the data file.
* @throws FileNotFoundException
*/
public
static
InputStream
load
(
String
resourcePath
,
boolean
useFallback
)
throws
FileNotFoundException
{
if
(
Utils
.
fileExists
(
DATA
(
resourcePath
)))
{
// Data is in the resource directory
return
new
FileInputStream
(
DATA
(
resourcePath
));
}
else
{
if
(
useFallback
)
{
return
FileUtils
.
readResourceAsStream
(
"/defaults/data/"
+
resourcePath
);
}
}
return
null
;
}
public
static
void
CheckAllFiles
()
{
try
{
List
<
Path
>
filenames
=
FileUtils
.
getPathsFromResource
(
"/defaults/data/"
);
if
(
filenames
==
null
)
{
Grasscutter
.
getLogger
().
error
(
"We were unable to locate your default data files."
);
}
for
(
Path
file
:
filenames
)
{
String
relativePath
=
String
.
valueOf
(
file
).
split
(
"defaults[\\\\\\/]data[\\\\\\/]"
)[
1
];
CheckAndCopyData
(
relativePath
);
}
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"An error occurred while trying to check the data folder."
,
e
);
}
GenerateGachaMappings
();
}
private
static
void
CheckAndCopyData
(
String
name
)
{
String
filePath
=
Utils
.
toFilePath
(
DATA
(
name
));
if
(!
Utils
.
fileExists
(
filePath
))
{
// Check if file is in subdirectory
if
(
name
.
indexOf
(
"/"
)
!=
-
1
)
{
String
[]
path
=
name
.
split
(
"/"
);
String
folder
=
""
;
for
(
int
i
=
0
;
i
<
(
path
.
length
-
1
);
i
++)
{
folder
+=
path
[
i
]
+
"/"
;
// Make sure the current folder exists
String
folderToCreate
=
Utils
.
toFilePath
(
DATA
(
folder
));
if
(!
Utils
.
fileExists
(
folderToCreate
))
{
Grasscutter
.
getLogger
().
info
(
"Creating data folder '"
+
folder
+
"'"
);
Utils
.
createFolder
(
folderToCreate
);
}
}
}
Grasscutter
.
getLogger
().
info
(
"Creating default '"
+
name
+
"' data"
);
FileUtils
.
copyResource
(
"/defaults/data/"
+
name
,
filePath
);
}
}
private
static
void
GenerateGachaMappings
()
{
if
(!
Utils
.
fileExists
(
GachaHandler
.
gachaMappings
))
{
try
{
Grasscutter
.
getLogger
().
info
(
"Creating default '"
+
GachaHandler
.
gachaMappings
+
"' data"
);
Tools
.
createGachaMapping
(
GachaHandler
.
gachaMappings
);
}
catch
(
Exception
exception
)
{
Grasscutter
.
getLogger
().
warn
(
"Failed to create gacha mappings. \n"
+
exception
);
}
}
}
}
src/main/java/emu/grasscutter/data/GameData.java
View file @
a8293102
...
...
@@ -8,10 +8,12 @@ import java.util.Map;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.data.custom.AbilityEmbryoEntry
;
import
emu.grasscutter.data.custom.OpenConfigEntry
;
import
emu.grasscutter.data.custom.ScenePointEntry
;
import
emu.grasscutter.data.def.*
;
import
emu.grasscutter.data.binout.AbilityEmbryoEntry
;
import
emu.grasscutter.data.binout.AbilityModifierEntry
;
import
emu.grasscutter.data.binout.MainQuestData
;
import
emu.grasscutter.data.binout.OpenConfigEntry
;
import
emu.grasscutter.data.binout.ScenePointEntry
;
import
emu.grasscutter.data.excels.*
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
;
...
...
@@ -22,8 +24,10 @@ public class GameData {
// BinOutputs
private
static
final
Int2ObjectMap
<
String
>
abilityHashes
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Map
<
String
,
AbilityEmbryoEntry
>
abilityEmbryos
=
new
HashMap
<>();
private
static
final
Map
<
String
,
AbilityModifierEntry
>
abilityModifiers
=
new
HashMap
<>();
private
static
final
Map
<
String
,
OpenConfigEntry
>
openConfigEntries
=
new
HashMap
<>();
private
static
final
Map
<
String
,
ScenePointEntry
>
scenePointEntries
=
new
HashMap
<>();
private
static
final
Int2ObjectMap
<
MainQuestData
>
mainQuestData
=
new
Int2ObjectOpenHashMap
<>();
// ExcelConfigs
private
static
final
Int2ObjectMap
<
PlayerLevelData
>
playerLevelDataMap
=
new
Int2ObjectOpenHashMap
<>();
...
...
@@ -47,7 +51,8 @@ public class GameData {
private
static
final
Int2ObjectMap
<
WeaponPromoteData
>
weaponPromoteDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
WeaponCurveData
>
weaponCurveDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
EquipAffixData
>
equipAffixDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
EnvAnimalGatherConfigData
>
envAnimalGatherConfigDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
MonsterData
>
monsterDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
NpcData
>
npcDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
GadgetData
>
gadgetDataMap
=
new
Int2ObjectOpenHashMap
<>();
...
...
@@ -60,16 +65,28 @@ public class GameData {
private
static
final
Int2ObjectMap
<
SceneData
>
sceneDataMap
=
new
Int2ObjectLinkedOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
FetterData
>
fetterDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
CodexQuestData
>
codexQuestDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
CodexQuestData
>
codexQuestDataIdMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
CodexAnimalData
>
codexAnimalDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
CodexWeaponData
>
codexWeaponDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
CodexWeaponData
>
codexWeaponDataIdMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
CodexMaterialData
>
codexMaterialDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
CodexMaterialData
>
codexMaterialDataIdMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
CodexReliquaryData
>
codexReliquaryDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
CodexReliquaryData
>
codexReliquaryDataIdMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
ArrayList
<
CodexReliquaryData
>
codexReliquaryArrayList
=
new
ArrayList
<>();
private
static
final
Int2ObjectMap
<
FetterCharacterCardData
>
fetterCharacterCardDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
RewardData
>
rewardDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
WorldLevelData
>
worldLevelDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
DailyDungeonData
>
dailyDungeonDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
DungeonData
>
dungeonDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
QuestData
>
questDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
ShopGoodsData
>
shopGoodsDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
CombineData
>
combineDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
RewardPreviewData
>
rewardPreviewDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
TowerFloorData
>
towerFloorDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
TowerLevelData
>
towerLevelDataMap
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Int2ObjectMap
<
TowerScheduleData
>
towerScheduleDataMap
=
new
Int2ObjectOpenHashMap
<>();
// Cache
private
static
Map
<
Integer
,
List
<
Integer
>>
fetters
=
new
HashMap
<>();
...
...
@@ -101,6 +118,10 @@ public class GameData {
return
abilityEmbryos
;
}
public
static
Map
<
String
,
AbilityModifierEntry
>
getAbilityModifiers
()
{
return
abilityModifiers
;
}
public
static
Map
<
String
,
OpenConfigEntry
>
getOpenConfigEntries
()
{
return
openConfigEntries
;
}
...
...
@@ -114,6 +135,10 @@ public class GameData {
return
getScenePointEntries
().
get
(
sceneId
+
"_"
+
pointId
);
}
public
static
Int2ObjectMap
<
MainQuestData
>
getMainQuestDataMap
()
{
return
mainQuestData
;
}
public
static
Int2ObjectMap
<
AvatarData
>
getAvatarDataMap
()
{
return
avatarDataMap
;
}
...
...
@@ -216,6 +241,9 @@ public class GameData {
public
static
Int2ObjectMap
<
MonsterData
>
getMonsterDataMap
()
{
return
monsterDataMap
;
}
public
static
Int2ObjectMap
<
EnvAnimalGatherConfigData
>
getEnvAnimalGatherConfigDataMap
()
{
return
envAnimalGatherConfigDataMap
;
}
public
static
Int2ObjectMap
<
NpcData
>
getNpcDataMap
()
{
return
npcDataMap
;
...
...
@@ -278,6 +306,18 @@ public class GameData {
return
fetters
;
}
public
static
Int2ObjectMap
<
CodexQuestData
>
getCodexQuestDataIdMap
(){
return
codexQuestDataIdMap
;}
public
static
Int2ObjectMap
<
CodexAnimalData
>
getCodexAnimalDataMap
(){
return
codexAnimalDataMap
;}
public
static
Int2ObjectMap
<
CodexWeaponData
>
getCodexWeaponDataIdMap
(){
return
codexWeaponDataIdMap
;}
public
static
Int2ObjectMap
<
CodexMaterialData
>
getCodexMaterialDataIdMap
(){
return
codexMaterialDataIdMap
;}
public
static
Int2ObjectMap
<
CodexReliquaryData
>
getcodexReliquaryIdMap
(){
return
codexReliquaryDataIdMap
;}
public
static
ArrayList
<
CodexReliquaryData
>
getcodexReliquaryArrayList
(){
return
codexReliquaryArrayList
;}
public
static
Int2ObjectMap
<
WorldLevelData
>
getWorldLevelDataMap
()
{
return
worldLevelDataMap
;
}
...
...
@@ -320,4 +360,11 @@ public class GameData {
public
static
Int2ObjectMap
<
TowerLevelData
>
getTowerLevelDataMap
(){
return
towerLevelDataMap
;
}
public
static
Int2ObjectMap
<
TowerScheduleData
>
getTowerScheduleDataMap
(){
return
towerScheduleDataMap
;
}
public
static
Int2ObjectMap
<
QuestData
>
getQuestDataMap
()
{
return
questDataMap
;
}
}
src/main/java/emu/grasscutter/data/GameDepot.java
View file @
a8293102
...
...
@@ -7,8 +7,8 @@ import org.danilopianini.util.FlexibleQuadTree;
import
org.danilopianini.util.SpatialIndex
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.
def
.ReliquaryAffixData
;
import
emu.grasscutter.data.
def
.ReliquaryMainPropData
;
import
emu.grasscutter.data.
excels
.ReliquaryAffixData
;
import
emu.grasscutter.data.
excels
.ReliquaryMainPropData
;
import
emu.grasscutter.game.world.SpawnDataEntry
;
import
emu.grasscutter.game.world.SpawnDataEntry.SpawnGroupEntry
;
import
emu.grasscutter.utils.WeightedList
;
...
...
src/main/java/emu/grasscutter/data/ResourceLoader.java
View file @
a8293102
This diff is collapsed.
Click to expand it.
src/main/java/emu/grasscutter/data/
custom
/AbilityEmbryoEntry.java
→
src/main/java/emu/grasscutter/data/
binout
/AbilityEmbryoEntry.java
View file @
a8293102
package
emu.grasscutter.data.
custom
;
package
emu.grasscutter.data.
binout
;
public
class
AbilityEmbryoEntry
{
private
String
name
;
...
...
src/main/java/emu/grasscutter/data/binout/AbilityModifier.java
0 → 100644
View file @
a8293102
package
emu.grasscutter.data.binout
;
import
java.util.Map
;
public
class
AbilityModifier
{
public
AbilityModifierAction
[]
onAdded
;
public
AbilityModifierAction
[]
onThinkInterval
;
public
AbilityModifierAction
[]
onRemoved
;
public
static
class
AbilityConfigData
{
public
AbilityData
Default
;
}
public
static
class
AbilityData
{
public
String
abilityName
;
public
Map
<
String
,
AbilityModifier
>
modifiers
;
}
public
static
class
AbilityModifierAction
{
public
String
$type
;
public
AbilityModifierActionType
type
;
public
String
target
;
public
AbilityModifierValue
amount
;
public
AbilityModifierValue
amountByTargetCurrentHPRatio
;
}
public
static
class
AbilityModifierValue
{
public
boolean
isFormula
;
public
boolean
isDynamic
;
public
String
dynamicKey
;
}
public
enum
AbilityModifierActionType
{
HealHP
,
ApplyModifier
,
LoseHP
;
}
}
src/main/java/emu/grasscutter/data/binout/AbilityModifierEntry.java
0 → 100644
View file @
a8293102
package
emu.grasscutter.data.binout
;
import
java.util.ArrayList
;
import
java.util.List
;
import
emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction
;
public
class
AbilityModifierEntry
{
private
String
name
;
// Custom value
public
List
<
AbilityModifierAction
>
onModifierAdded
;
public
List
<
AbilityModifierAction
>
onThinkInterval
;
public
List
<
AbilityModifierAction
>
onRemoved
;
public
AbilityModifierEntry
(
String
name
)
{
this
.
name
=
name
;
this
.
onModifierAdded
=
new
ArrayList
<>();
this
.
onThinkInterval
=
new
ArrayList
<>();
this
.
onRemoved
=
new
ArrayList
<>();
}
public
String
getName
()
{
return
name
;
}
public
List
<
AbilityModifierAction
>
getOnAdded
()
{
return
onModifierAdded
;
}
public
List
<
AbilityModifierAction
>
getOnThinkInterval
()
{
return
onThinkInterval
;
}
public
List
<
AbilityModifierAction
>
getOnRemoved
()
{
return
onRemoved
;
}
}
src/main/java/emu/grasscutter/data/binout/MainQuestData.java
0 → 100644
View file @
a8293102
package
emu.grasscutter.data.binout
;
import
emu.grasscutter.game.quest.enums.LogicType
;
import
emu.grasscutter.game.quest.enums.QuestTrigger
;
import
emu.grasscutter.game.quest.enums.QuestType
;
public
class
MainQuestData
{
private
int
id
;
private
int
series
;
private
QuestType
type
;
private
long
titleTextMapHash
;
private
int
[]
suggestTrackMainQuestList
;
private
int
[]
rewardIdList
;
private
SubQuestData
[]
subQuests
;
public
int
getId
()
{
return
id
;
}
public
int
getSeries
()
{
return
series
;
}
public
QuestType
getType
()
{
return
type
;
}
public
long
getTitleTextMapHash
()
{
return
titleTextMapHash
;
}
public
int
[]
getSuggestTrackMainQuestList
()
{
return
suggestTrackMainQuestList
;
}
public
int
[]
getRewardIdList
()
{
return
rewardIdList
;
}
public
SubQuestData
[]
getSubQuests
()
{
return
subQuests
;
}
public
static
class
SubQuestData
{
private
int
subId
;
public
int
getSubId
()
{
return
subId
;
}
}
}
src/main/java/emu/grasscutter/data/
custom
/OpenConfigEntry.java
→
src/main/java/emu/grasscutter/data/
binout
/OpenConfigEntry.java
View file @
a8293102
package
emu.grasscutter.data.
custom
;
package
emu.grasscutter.data.
binout
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
src/main/java/emu/grasscutter/data/
custom
/ScenePointEntry.java
→
src/main/java/emu/grasscutter/data/
binout
/ScenePointEntry.java
View file @
a8293102
package
emu.grasscutter.data.
custom
;
import
emu.grasscutter.data.common.PointData
;
public
class
ScenePointEntry
{
private
String
name
;
private
PointData
pointData
;
public
ScenePointEntry
(
String
name
,
PointData
pointData
)
{
this
.
name
=
name
;
this
.
pointData
=
pointData
;
}
public
String
getName
()
{
return
name
;
}
public
PointData
getPointData
()
{
return
pointData
;
}
}
package
emu.grasscutter.data.
binout
;
import
emu.grasscutter.data.common.PointData
;
public
class
ScenePointEntry
{
private
String
name
;
private
PointData
pointData
;
public
ScenePointEntry
(
String
name
,
PointData
pointData
)
{
this
.
name
=
name
;
this
.
pointData
=
pointData
;
}
public
String
getName
()
{
return
name
;
}
public
PointData
getPointData
()
{
return
pointData
;
}
}
src/main/java/emu/grasscutter/data/common/CurveInfo.java
View file @
a8293102
package
emu.grasscutter.data.common
;
public
class
CurveInfo
{
private
String
T
ype
;
private
String
A
rith
;
private
float
V
alue
;
private
String
t
ype
;
private
String
a
rith
;
private
float
v
alue
;
public
String
getType
()
{
return
T
ype
;
return
t
ype
;
}
public
String
getArith
()
{
return
A
rith
;
return
a
rith
;
}
public
float
getValue
()
{
return
V
alue
;
return
v
alue
;
}
}
src/main/java/emu/grasscutter/data/common/FightPropData.java
View file @
a8293102
...
...
@@ -3,16 +3,16 @@ package emu.grasscutter.data.common;
import
emu.grasscutter.game.props.FightProperty
;
public
class
FightPropData
{
private
String
P
ropType
;
private
String
p
ropType
;
private
FightProperty
prop
;
private
float
V
alue
;
private
float
v
alue
;
public
String
getPropType
()
{
return
P
ropType
;
return
p
ropType
;
}
public
float
getValue
()
{
return
V
alue
;
return
v
alue
;
}
public
FightProperty
getProp
()
{
...
...
@@ -20,6 +20,6 @@ public class FightPropData {
}
public
void
onLoad
()
{
this
.
prop
=
FightProperty
.
getPropByName
(
P
ropType
);
this
.
prop
=
FightProperty
.
getPropByName
(
p
ropType
);
}
}
\ No newline at end of file
src/main/java/emu/grasscutter/data/common/ItemParamData.java
View file @
a8293102
package
emu.grasscutter.data.common
;
import
com.google.gson.annotations.SerializedName
;
public
class
ItemParamData
{
private
int
Id
;
private
int
Count
;
@SerializedName
(
value
=
"id"
,
alternate
={
"itemId"
})
private
int
id
;
@SerializedName
(
value
=
"count"
,
alternate
={
"itemCount"
})
private
int
count
;
public
ItemParamData
()
{}
public
ItemParamData
(
int
id
,
int
count
)
{
this
.
I
d
=
id
;
this
.
C
ount
=
count
;
this
.
i
d
=
id
;
this
.
c
ount
=
count
;
}
public
int
getId
()
{
return
Id
;
return
id
;
}
public
int
getItemId
()
{
return
id
;
}
public
int
getCount
()
{
return
Count
;
return
count
;
}
public
int
getItemCount
()
{
return
count
;
}
}
src/main/java/emu/grasscutter/data/common/ItemParamStringData.java
View file @
a8293102
package
emu.grasscutter.data.common
;
public
class
ItemParamStringData
{
private
int
I
d
;
private
String
C
ount
;
private
int
i
d
;
private
String
c
ount
;
public
ItemParamStringData
()
{}
public
int
getId
()
{
return
I
d
;
return
i
d
;
}
public
String
getCount
()
{
return
C
ount
;
return
c
ount
;
}
public
ItemParamData
toItemParamData
()
{
if
(
C
ount
.
contains
(
";"
))
{
String
[]
split
=
C
ount
.
split
(
";"
);
C
ount
=
C
ount
.
split
(
";"
)[
split
.
length
-
1
];
}
else
if
(
C
ount
.
contains
(
"."
))
{
return
new
ItemParamData
(
I
d
,
(
int
)
Math
.
ceil
(
Double
.
parseDouble
(
C
ount
)));
if
(
c
ount
.
contains
(
";"
))
{
String
[]
split
=
c
ount
.
split
(
";"
);
c
ount
=
c
ount
.
split
(
";"
)[
split
.
length
-
1
];
}
else
if
(
c
ount
.
contains
(
"."
))
{
return
new
ItemParamData
(
i
d
,
(
int
)
Math
.
ceil
(
Double
.
parseDouble
(
c
ount
)));
}
return
new
ItemParamData
(
I
d
,
Integer
.
parseInt
(
C
ount
));
return
new
ItemParamData
(
i
d
,
Integer
.
parseInt
(
c
ount
));
}
}
Prev
1
2
3
4
5
6
7
8
…
21
Next
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