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
f3410092
Commit
f3410092
authored
May 06, 2022
by
KingRainbow44
Browse files
Merge remote-tracking branch 'origin/development' into development
parents
2c1cc36c
a65823d2
Changes
7
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/Grasscutter.java
View file @
f3410092
...
@@ -70,13 +70,21 @@ public final class Grasscutter {
...
@@ -70,13 +70,21 @@ public final class Grasscutter {
Crypto
.
loadKeys
();
// Load keys from buffers.
Crypto
.
loadKeys
();
// Load keys from buffers.
// Parse arguments.
// Parse arguments.
boolean
exitEarly
=
false
;
for
(
String
arg
:
args
)
{
for
(
String
arg
:
args
)
{
switch
(
arg
.
toLowerCase
())
{
switch
(
arg
.
toLowerCase
())
{
case
"-handbook"
->
Tools
.
createGmHandbook
();
case
"-handbook"
->
{
case
"-gachamap"
->
Tools
.
createGachaMapping
(
"./gacha-mapping.js"
);
Tools
.
createGmHandbook
();
exitEarly
=
true
;
}
case
"-gachamap"
->
{
Tools
.
createGachaMapping
(
"./gacha-mapping.js"
);
exitEarly
=
true
;
}
}
}
}
}
// Exit early if argument sets it.
if
(
exitEarly
)
System
.
exit
(
0
);
// Initialize server.
// Initialize server.
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.status.starting"
));
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.status.starting"
));
...
@@ -88,14 +96,13 @@ public final class Grasscutter {
...
@@ -88,14 +96,13 @@ public final class Grasscutter {
// Database
// Database
DatabaseManager
.
initialize
();
DatabaseManager
.
initialize
();
// Create plugin manager instance.
pluginManager
=
new
PluginManager
();
// Create server instances.
// Create server instances.
dispatchServer
=
new
DispatchServer
();
dispatchServer
=
new
DispatchServer
();
gameServer
=
new
GameServer
();
gameServer
=
new
GameServer
();
// Create a server hook instance with both servers.
// Create a server hook instance with both servers.
new
ServerHook
(
gameServer
,
dispatchServer
);
new
ServerHook
(
gameServer
,
dispatchServer
);
// Create plugin manager instance.
pluginManager
=
new
PluginManager
();
// Start servers.
// Start servers.
if
(
getConfig
().
RunMode
==
ServerRunMode
.
HYBRID
)
{
if
(
getConfig
().
RunMode
==
ServerRunMode
.
HYBRID
)
{
...
...
src/main/java/emu/grasscutter/game/managers/MovementManager/MovementManager.java
View file @
f3410092
...
@@ -268,7 +268,7 @@ public class MovementManager {
...
@@ -268,7 +268,7 @@ public class MovementManager {
if
(
Grasscutter
.
getConfig
().
OpenStamina
)
{
if
(
Grasscutter
.
getConfig
().
OpenStamina
)
{
boolean
moving
=
isPlayerMoving
();
boolean
moving
=
isPlayerMoving
();
if
(
moving
||
(
getCurrentStamina
()
<
getMaximumStamina
()))
{
if
(
moving
||
(
getCurrentStamina
()
<
getMaximumStamina
()))
{
Grasscutter
.
getLogger
().
debug
(
"Player moving: "
+
moving
+
", stamina full: "
+
(
getCurrentStamina
()
>=
getMaximumStamina
())
+
", recalculate stamina"
);
//
Grasscutter.getLogger().debug("Player moving: " + moving + ", stamina full: " + (getCurrentStamina() >= getMaximumStamina()) + ", recalculate stamina");
Consumption
consumption
=
Consumption
.
None
;
Consumption
consumption
=
Consumption
.
None
;
// TODO: refactor these conditions.
// TODO: refactor these conditions.
...
@@ -306,14 +306,16 @@ public class MovementManager {
...
@@ -306,14 +306,16 @@ public class MovementManager {
}
else
if
(
MotionStatesCategorized
.
get
(
"RUN"
).
contains
(
currentState
))
{
}
else
if
(
MotionStatesCategorized
.
get
(
"RUN"
).
contains
(
currentState
))
{
// RUN, DASH and WALK
// RUN, DASH and WALK
// DASH
// DASH
if
(
currentState
==
MotionState
.
MOTION_DASH
)
{
if
(
currentState
==
MotionState
.
MOTION_DASH_BEFORE_SHAKE
)
{
if
(
previousState
==
MotionState
.
MOTION_DASH
)
{
consumption
=
Consumption
.
SPRINT
;
}
else
{
// cost more to start dashing
consumption
=
Consumption
.
DASH
;
consumption
=
Consumption
.
DASH
;
if
(
previousState
==
MotionState
.
MOTION_DASH_BEFORE_SHAKE
)
{
// only charge once
consumption
=
Consumption
.
SPRINT
;
}
}
}
}
if
(
currentState
==
MotionState
.
MOTION_DASH
)
{
consumption
=
Consumption
.
SPRINT
;
}
// RUN
// RUN
if
(
currentState
==
MotionState
.
MOTION_RUN
)
{
if
(
currentState
==
MotionState
.
MOTION_RUN
)
{
consumption
=
Consumption
.
RUN
;
consumption
=
Consumption
.
RUN
;
...
@@ -347,14 +349,13 @@ public class MovementManager {
...
@@ -347,14 +349,13 @@ public class MovementManager {
staminaRecoverDelay
=
0
;
staminaRecoverDelay
=
0
;
}
}
if
(
consumption
.
amount
>
0
)
{
if
(
consumption
.
amount
>
0
)
{
if
(
staminaRecoverDelay
<
5
)
{
if
(
staminaRecoverDelay
<
10
)
{
staminaRecoverDelay
++;
staminaRecoverDelay
++;
consumption
=
Consumption
.
None
;
consumption
=
Consumption
.
None
;
}
}
}
}
int
newStamina
=
updateStamina
(
cachedSession
,
consumption
.
amount
);
int
newStamina
=
updateStamina
(
cachedSession
,
consumption
.
amount
);
cachedSession
.
send
(
new
PacketPlayerPropNotify
(
player
,
PlayerProperty
.
PROP_CUR_PERSIST_STAMINA
));
cachedSession
.
send
(
new
PacketPlayerPropNotify
(
player
,
PlayerProperty
.
PROP_CUR_PERSIST_STAMINA
));
Grasscutter
.
getLogger
().
debug
(
player
.
getProperty
(
PlayerProperty
.
PROP_CUR_PERSIST_STAMINA
)
+
"/"
+
player
.
getProperty
(
PlayerProperty
.
PROP_MAX_STAMINA
)
+
"\t"
+
currentState
+
"\t"
+
"isMoving: "
+
isPlayerMoving
()
+
"\t"
+
consumption
+
"("
+
consumption
.
amount
+
")"
);
Grasscutter
.
getLogger
().
debug
(
player
.
getProperty
(
PlayerProperty
.
PROP_CUR_PERSIST_STAMINA
)
+
"/"
+
player
.
getProperty
(
PlayerProperty
.
PROP_MAX_STAMINA
)
+
"\t"
+
currentState
+
"\t"
+
"isMoving: "
+
isPlayerMoving
()
+
"\t"
+
consumption
+
"("
+
consumption
.
amount
+
")"
);
}
}
}
}
...
...
src/main/java/emu/grasscutter/server/game/GameServer.java
View file @
f3410092
...
@@ -29,6 +29,9 @@ import java.net.InetSocketAddress;
...
@@ -29,6 +29,9 @@ import java.net.InetSocketAddress;
import
java.time.OffsetDateTime
;
import
java.time.OffsetDateTime
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
...
@@ -80,19 +83,6 @@ public final class GameServer extends KcpServer {
...
@@ -80,19 +83,6 @@ public final class GameServer extends KcpServer {
this
.
expeditionManager
=
new
ExpeditionManager
(
this
);
this
.
expeditionManager
=
new
ExpeditionManager
(
this
);
this
.
combineManger
=
new
CombineManger
(
this
);
this
.
combineManger
=
new
CombineManger
(
this
);
// Schedule game loop.
Timer
gameLoop
=
new
Timer
();
gameLoop
.
scheduleAtFixedRate
(
new
TimerTask
()
{
@Override
public
void
run
()
{
try
{
onTick
();
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
translate
(
"messages.game.game_update_error"
),
e
);
}
}
},
new
Date
(),
1000L
);
// Hook into shutdown event.
// Hook into shutdown event.
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
this
::
onServerShutdown
));
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
this
::
onServerShutdown
));
}
}
...
@@ -229,6 +219,24 @@ public final class GameServer extends KcpServer {
...
@@ -229,6 +219,24 @@ public final class GameServer extends KcpServer {
}
}
@Override
public
synchronized
void
start
()
{
// Schedule game loop.
Timer
gameLoop
=
new
Timer
();
gameLoop
.
scheduleAtFixedRate
(
new
TimerTask
()
{
@Override
public
void
run
()
{
try
{
onTick
();
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
translate
(
"messages.game.game_update_error"
),
e
);
}
}
},
new
Date
(),
1000L
);
super
.
start
();
}
@Override
@Override
public
void
onStartFinish
()
{
public
void
onStartFinish
()
{
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.status.free_software"
));
Grasscutter
.
getLogger
().
info
(
translate
(
"messages.status.free_software"
));
...
...
src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java
View file @
f3410092
...
@@ -14,6 +14,7 @@ import emu.grasscutter.server.game.GameSession.SessionState;
...
@@ -14,6 +14,7 @@ import emu.grasscutter.server.game.GameSession.SessionState;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
;
@SuppressWarnings
(
"unchecked"
)
public
class
GameServerPacketHandler
{
public
class
GameServerPacketHandler
{
private
final
Int2ObjectMap
<
PacketHandler
>
handlers
;
private
final
Int2ObjectMap
<
PacketHandler
>
handlers
;
...
...
src/main/java/emu/grasscutter/tools/Tools.java
View file @
f3410092
...
@@ -93,7 +93,6 @@ public final class Tools {
...
@@ -93,7 +93,6 @@ public final class Tools {
}
}
Grasscutter
.
getLogger
().
info
(
"GM Handbook generated!"
);
Grasscutter
.
getLogger
().
info
(
"GM Handbook generated!"
);
System
.
exit
(
0
);
}
}
@SuppressWarnings
(
"deprecation"
)
@SuppressWarnings
(
"deprecation"
)
...
@@ -183,6 +182,5 @@ public final class Tools {
...
@@ -183,6 +182,5 @@ public final class Tools {
}
}
Grasscutter
.
getLogger
().
info
(
"Mappings generated!"
);
Grasscutter
.
getLogger
().
info
(
"Mappings generated!"
);
System
.
exit
(
0
);
}
}
}
}
src/main/java/emu/grasscutter/utils/Language.java
View file @
f3410092
...
@@ -40,7 +40,7 @@ public final class Language {
...
@@ -40,7 +40,7 @@ public final class Language {
@Nullable
JsonObject
languageData
=
null
;
@Nullable
JsonObject
languageData
=
null
;
try
{
try
{
InputStream
file
=
Grasscutter
.
class
.
getResourceAsStream
(
"/lang/"
+
fileName
);
InputStream
file
=
Grasscutter
.
class
.
getResourceAsStream
(
"/lang
uages
/"
+
fileName
);
languageData
=
Grasscutter
.
getGsonFactory
().
fromJson
(
Utils
.
readFromInputStream
(
file
),
JsonObject
.
class
);
languageData
=
Grasscutter
.
getGsonFactory
().
fromJson
(
Utils
.
readFromInputStream
(
file
),
JsonObject
.
class
);
}
catch
(
Exception
exception
)
{
}
catch
(
Exception
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Failed to load language file: "
+
fileName
,
exception
);
Grasscutter
.
getLogger
().
error
(
"Failed to load language file: "
+
fileName
,
exception
);
...
...
src/main/java/emu/grasscutter/utils/Utils.java
View file @
f3410092
...
@@ -5,6 +5,8 @@ import java.nio.file.Files;
...
@@ -5,6 +5,8 @@ import java.nio.file.Files;
import
java.nio.file.StandardCopyOption
;
import
java.nio.file.StandardCopyOption
;
import
java.time.*
;
import
java.time.*
;
import
java.time.temporal.TemporalAdjusters
;
import
java.time.temporal.TemporalAdjusters
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.Random
;
import
emu.grasscutter.Config
;
import
emu.grasscutter.Config
;
...
@@ -260,4 +262,41 @@ public final class Utils {
...
@@ -260,4 +262,41 @@ public final class Utils {
Grasscutter
.
getLogger
().
warn
(
"Failed to read from input stream."
);
Grasscutter
.
getLogger
().
warn
(
"Failed to read from input stream."
);
}
return
stringBuilder
.
toString
();
}
return
stringBuilder
.
toString
();
}
}
/**
* Switch properties from upper case to lower case?
*/
public
static
Map
<
String
,
Object
>
switchPropertiesUpperLowerCase
(
Map
<
String
,
Object
>
objMap
,
Class
<?>
cls
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
objMap
.
size
());
for
(
String
key
:
objMap
.
keySet
())
{
try
{
char
c
=
key
.
charAt
(
0
);
if
(
c
>=
'a'
&&
c
<=
'z'
)
{
try
{
cls
.
getDeclaredField
(
key
);
map
.
put
(
key
,
objMap
.
get
(
key
));
}
catch
(
NoSuchFieldException
e
)
{
String
s1
=
String
.
valueOf
(
c
).
toUpperCase
();
String
after
=
key
.
length
()
>
1
?
s1
+
key
.
substring
(
1
)
:
s1
;
cls
.
getDeclaredField
(
after
);
map
.
put
(
after
,
objMap
.
get
(
key
));
}
}
else
if
(
c
>=
'A'
&&
c
<=
'Z'
)
{
try
{
cls
.
getDeclaredField
(
key
);
map
.
put
(
key
,
objMap
.
get
(
key
));
}
catch
(
NoSuchFieldException
e
)
{
String
s1
=
String
.
valueOf
(
c
).
toLowerCase
();
String
after
=
key
.
length
()
>
1
?
s1
+
key
.
substring
(
1
)
:
s1
;
cls
.
getDeclaredField
(
after
);
map
.
put
(
after
,
objMap
.
get
(
key
));
}
}
}
catch
(
NoSuchFieldException
e
)
{
map
.
put
(
key
,
objMap
.
get
(
key
));
}
}
return
map
;
}
}
}
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