mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-26 00:18:02 +00:00
Merge remote-tracking branch 'origin/development' into development
This commit is contained in:
commit
f34100924e
@ -70,12 +70,20 @@ 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 {
|
|||||||
// 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) {
|
||||||
|
@ -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 {
|
|||||||
} 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 {
|
|||||||
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 + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
|||||||
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 {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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"));
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Grasscutter.getLogger().info("Mappings generated!");
|
Grasscutter.getLogger().info("Mappings generated!");
|
||||||
System.exit(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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("/languages/" + 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);
|
||||||
|
@ -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 {
|
|||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user