mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 06:31:26 +00:00
Update gradle + Work gacha reload (gs broken atm)
This commit is contained in:
parent
866941589b
commit
d59799ce55
24
build.gradle
24
build.gradle
@ -23,19 +23,21 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile fileTree(dir: 'lib', include: '*.jar')
|
implementation fileTree(dir: 'lib', include: ['*.jar'])
|
||||||
|
|
||||||
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.32'
|
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.32'
|
||||||
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.2.6'
|
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.6'
|
||||||
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.6'
|
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.6'
|
||||||
compile group: 'io.netty', name: 'netty-all', version: '4.1.69.Final'
|
implementation group: 'io.netty', name: 'netty-all', version: '4.1.69.Final'
|
||||||
|
|
||||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.8'
|
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.8'
|
||||||
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.18.1'
|
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.18.1'
|
||||||
|
|
||||||
compile group: 'org.reflections', name: 'reflections', version: '0.9.12'
|
implementation group: 'org.reflections', name: 'reflections', version: '0.9.12'
|
||||||
|
|
||||||
compile group: 'dev.morphia.morphia', name: 'core', version: '1.6.1'
|
implementation group: 'dev.morphia.morphia', name: 'core', version: '1.6.1'
|
||||||
|
|
||||||
|
implementation group: 'org.greenrobot', name: 'eventbus-java', version: '3.3.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
@ -51,9 +53,11 @@ jar {
|
|||||||
jar.baseName = 'grasscutter'
|
jar.baseName = 'grasscutter'
|
||||||
|
|
||||||
from {
|
from {
|
||||||
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
|
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||||
|
|
||||||
from('src/main/java') {
|
from('src/main/java') {
|
||||||
include '*.xml'
|
include '*.xml'
|
||||||
}
|
}
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -51,6 +51,7 @@ public final class Config {
|
|||||||
public int MaxAvatarsInTeam = 4;
|
public int MaxAvatarsInTeam = 4;
|
||||||
public int MaxAvatarsInTeamMultiplayer = 4;
|
public int MaxAvatarsInTeamMultiplayer = 4;
|
||||||
public int MaxEntityLimit = 1000; // Max entity limit per world. // TODO: Enforce later.
|
public int MaxEntityLimit = 1000; // Max entity limit per world. // TODO: Enforce later.
|
||||||
|
public boolean WatchGacha = false;
|
||||||
public int[] WelcomeEmotes = {2007, 1002, 4010};
|
public int[] WelcomeEmotes = {2007, 1002, 4010};
|
||||||
public String WelcomeMotd = "Welcome to Grasscutter emu";
|
public String WelcomeMotd = "Welcome to Grasscutter emu";
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package emu.grasscutter.game.gacha;
|
package emu.grasscutter.game.gacha;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
import java.nio.file.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -21,16 +23,22 @@ import emu.grasscutter.net.proto.GachaTransferItemOuterClass.GachaTransferItem;
|
|||||||
import emu.grasscutter.net.proto.GetGachaInfoRspOuterClass.GetGachaInfoRsp;
|
import emu.grasscutter.net.proto.GetGachaInfoRspOuterClass.GetGachaInfoRsp;
|
||||||
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
|
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
|
||||||
import emu.grasscutter.server.game.GameServer;
|
import emu.grasscutter.server.game.GameServer;
|
||||||
|
import emu.grasscutter.server.game.GameServerTickEvent;
|
||||||
import emu.grasscutter.server.packet.send.PacketDoGachaRsp;
|
import emu.grasscutter.server.packet.send.PacketDoGachaRsp;
|
||||||
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;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
|
||||||
|
|
||||||
public class GachaManager {
|
public class GachaManager {
|
||||||
private final GameServer server;
|
private final GameServer server;
|
||||||
private final Int2ObjectMap<GachaBanner> gachaBanners;
|
private final Int2ObjectMap<GachaBanner> gachaBanners;
|
||||||
private GetGachaInfoRsp cachedProto;
|
private GetGachaInfoRsp cachedProto;
|
||||||
|
WatchService watchService;
|
||||||
|
WatchKey watchKey;
|
||||||
|
|
||||||
private int[] yellowAvatars = new int[] {1003, 1016, 1042, 1035, 1041};
|
private int[] yellowAvatars = new int[] {1003, 1016, 1042, 1035, 1041};
|
||||||
private int[] yellowWeapons = new int[] {11501, 11502, 12501, 12502, 13502, 13505, 14501, 14502, 15501, 15502};
|
private int[] yellowWeapons = new int[] {11501, 11502, 12501, 12502, 13502, 13505, 14501, 14502, 15501, 15502};
|
||||||
@ -45,6 +53,7 @@ public class GachaManager {
|
|||||||
this.server = server;
|
this.server = server;
|
||||||
this.gachaBanners = new Int2ObjectOpenHashMap<>();
|
this.gachaBanners = new Int2ObjectOpenHashMap<>();
|
||||||
this.load();
|
this.load();
|
||||||
|
this.startWatcher(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameServer getServer() {
|
public GameServer getServer() {
|
||||||
@ -267,6 +276,39 @@ public class GachaManager {
|
|||||||
player.sendPacket(new PacketDoGachaRsp(banner, list));
|
player.sendPacket(new PacketDoGachaRsp(banner, list));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized void startWatcher(GameServer server) {
|
||||||
|
if(this.watchService == null) {
|
||||||
|
try {
|
||||||
|
this.watchService = FileSystems.getDefault().newWatchService();
|
||||||
|
Path path = new File(Grasscutter.getConfig().DATA_FOLDER).toPath();
|
||||||
|
path.register(watchService, ENTRY_MODIFY);
|
||||||
|
watchKey = watchService.take();
|
||||||
|
|
||||||
|
server.OnGameServerTick.register(this);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Grasscutter.getLogger().error("Unable to load the Gacha Manager Watch Service. If ServerOptions.watchGacha is true it will not auto-reload");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Grasscutter.getLogger().error("Cannot reinitialise watcher ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public synchronized void watchBannerJson(GameServerTickEvent tickEvent) {
|
||||||
|
try {
|
||||||
|
for (WatchEvent<?> event : watchKey.pollEvents()) {
|
||||||
|
final Path changed = (Path) event.context();
|
||||||
|
if (changed.endsWith("Banners.json")) {
|
||||||
|
Grasscutter.getLogger().info("Change detected with banners.json. Reloading gacha config");
|
||||||
|
this.load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized GetGachaInfoRsp createProto() {
|
private synchronized GetGachaInfoRsp createProto() {
|
||||||
GetGachaInfoRsp.Builder proto = GetGachaInfoRsp.newBuilder().setGachaRandom(12345);
|
GetGachaInfoRsp.Builder proto = GetGachaInfoRsp.newBuilder().setGachaRandom(12345);
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package emu.grasscutter.server.game;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import emu.grasscutter.GenshinConstants;
|
import emu.grasscutter.GenshinConstants;
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
@ -19,6 +20,8 @@ import emu.grasscutter.game.shop.ShopManager;
|
|||||||
import emu.grasscutter.net.packet.PacketHandler;
|
import emu.grasscutter.net.packet.PacketHandler;
|
||||||
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
|
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
|
||||||
import emu.grasscutter.netty.MihoyoKcpServer;
|
import emu.grasscutter.netty.MihoyoKcpServer;
|
||||||
|
import jdk.internal.event.Event;
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
public final class GameServer extends MihoyoKcpServer {
|
public final class GameServer extends MihoyoKcpServer {
|
||||||
private final InetSocketAddress address;
|
private final InetSocketAddress address;
|
||||||
@ -34,9 +37,14 @@ public final class GameServer extends MihoyoKcpServer {
|
|||||||
private final DungeonManager dungeonManager;
|
private final DungeonManager dungeonManager;
|
||||||
private final CommandMap commandMap;
|
private final CommandMap commandMap;
|
||||||
|
|
||||||
|
public EventBus OnGameServerTick;
|
||||||
|
public EventBus OnGameServerStop; // TODO
|
||||||
|
|
||||||
public GameServer(InetSocketAddress address) {
|
public GameServer(InetSocketAddress address) {
|
||||||
super(address);
|
super(address);
|
||||||
|
|
||||||
|
OnGameServerTick = EventBus.builder().throwSubscriberException(true).build();
|
||||||
|
|
||||||
this.setServerInitializer(new GameServerInitializer(this));
|
this.setServerInitializer(new GameServerInitializer(this));
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.packetHandler = new GameServerPacketHandler(PacketHandler.class);
|
this.packetHandler = new GameServerPacketHandler(PacketHandler.class);
|
||||||
@ -155,6 +163,8 @@ public final class GameServer extends MihoyoKcpServer {
|
|||||||
for (GenshinPlayer player : this.getPlayers().values()) {
|
for (GenshinPlayer player : this.getPlayers().values()) {
|
||||||
player.onTick();
|
player.onTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OnGameServerTick.post(new GameServerTickEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package emu.grasscutter.server.game;
|
||||||
|
|
||||||
|
public class GameServerTickEvent {
|
||||||
|
// Placeholder class for now, probably will get used later
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user