mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 21:10:54 +00:00
Call checkSpawns from World instead of from Player
This commit is contained in:
parent
803ad40821
commit
b6300cafec
@ -695,10 +695,6 @@ public class GenshinPlayer {
|
|||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
if (this.getScene() != null && this.getSceneLoadState() == SceneLoadState.LOADED) {
|
|
||||||
this.getScene().checkSpawns(this);
|
|
||||||
}
|
|
||||||
// Ping
|
// Ping
|
||||||
if (this.getWorld() != null) {
|
if (this.getWorld() != null) {
|
||||||
// RTT notify - very important to send this often
|
// RTT notify - very important to send this often
|
||||||
|
@ -315,32 +315,31 @@ public class GenshinScene {
|
|||||||
target.onDeath(attackerId);
|
target.onDeath(attackerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Do not use yet
|
public void onTick() {
|
||||||
public synchronized void onTick() {
|
this.checkSpawns();
|
||||||
for (GenshinPlayer player : this.getPlayers()) {
|
|
||||||
this.checkSpawns(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - Test
|
// TODO - Test
|
||||||
public void checkSpawns(GenshinPlayer player) {
|
public void checkSpawns() {
|
||||||
SpatialIndex<SpawnGroupEntry> list = GenshinDepot.getSpawnListById(this.getId());
|
SpatialIndex<SpawnGroupEntry> list = GenshinDepot.getSpawnListById(this.getId());
|
||||||
Set<SpawnDataEntry> visible = new HashSet<>();
|
Set<SpawnDataEntry> visible = new HashSet<>();
|
||||||
|
|
||||||
int RANGE = 100;
|
for (GenshinPlayer player : this.getPlayers()) {
|
||||||
Collection<SpawnGroupEntry> entries = list.query(
|
int RANGE = 100;
|
||||||
new double[] {player.getPos().getX() - RANGE, player.getPos().getZ() - RANGE},
|
Collection<SpawnGroupEntry> entries = list.query(
|
||||||
new double[] {player.getPos().getX() + RANGE, player.getPos().getZ() + RANGE}
|
new double[] {player.getPos().getX() - RANGE, player.getPos().getZ() - RANGE},
|
||||||
);
|
new double[] {player.getPos().getX() + RANGE, player.getPos().getZ() + RANGE}
|
||||||
|
);
|
||||||
for (SpawnGroupEntry entry : entries) {
|
|
||||||
for (SpawnDataEntry spawnData : entry.getSpawns()) {
|
for (SpawnGroupEntry entry : entries) {
|
||||||
visible.add(spawnData);
|
for (SpawnDataEntry spawnData : entry.getSpawns()) {
|
||||||
|
visible.add(spawnData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// World level
|
// World level
|
||||||
WorldLevelData worldLevelData = GenshinData.getWorldLevelDataMap().get(player.getWorldLevel());
|
WorldLevelData worldLevelData = GenshinData.getWorldLevelDataMap().get(getWorld().getWorldLevel());
|
||||||
int worldLevelOverride = 0;
|
int worldLevelOverride = 0;
|
||||||
|
|
||||||
if (worldLevelData != null) {
|
if (worldLevelData != null) {
|
||||||
|
@ -37,6 +37,7 @@ import emu.grasscutter.server.packet.send.PacketWorldPlayerInfoNotify;
|
|||||||
import emu.grasscutter.server.packet.send.PacketWorldPlayerRTTNotify;
|
import emu.grasscutter.server.packet.send.PacketWorldPlayerRTTNotify;
|
||||||
import emu.grasscutter.utils.Position;
|
import emu.grasscutter.utils.Position;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
|
||||||
public class World implements Iterable<GenshinPlayer> {
|
public class World implements Iterable<GenshinPlayer> {
|
||||||
@ -58,11 +59,13 @@ public class World implements Iterable<GenshinPlayer> {
|
|||||||
public World(GenshinPlayer player, boolean isMultiplayer) {
|
public World(GenshinPlayer player, boolean isMultiplayer) {
|
||||||
this.owner = player;
|
this.owner = player;
|
||||||
this.players = Collections.synchronizedList(new ArrayList<>());
|
this.players = Collections.synchronizedList(new ArrayList<>());
|
||||||
this.scenes = new Int2ObjectOpenHashMap<>();
|
this.scenes = Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>());
|
||||||
|
|
||||||
this.levelEntityId = getNextEntityId(EntityIdType.MPLEVEL);
|
this.levelEntityId = getNextEntityId(EntityIdType.MPLEVEL);
|
||||||
this.worldLevel = player.getWorldLevel();
|
this.worldLevel = player.getWorldLevel();
|
||||||
this.isMultiplayer = isMultiplayer;
|
this.isMultiplayer = isMultiplayer;
|
||||||
|
|
||||||
|
this.owner.getServer().registerWorld(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenshinPlayer getHost() {
|
public GenshinPlayer getHost() {
|
||||||
@ -273,6 +276,12 @@ public class World implements Iterable<GenshinPlayer> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onTick() {
|
||||||
|
for (GenshinScene scene : this.getScenes().values()) {
|
||||||
|
scene.onTick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import emu.grasscutter.command.CommandMap;
|
|||||||
import emu.grasscutter.database.DatabaseHelper;
|
import emu.grasscutter.database.DatabaseHelper;
|
||||||
import emu.grasscutter.game.Account;
|
import emu.grasscutter.game.Account;
|
||||||
import emu.grasscutter.game.GenshinPlayer;
|
import emu.grasscutter.game.GenshinPlayer;
|
||||||
|
import emu.grasscutter.game.World;
|
||||||
import emu.grasscutter.game.dungeons.DungeonManager;
|
import emu.grasscutter.game.dungeons.DungeonManager;
|
||||||
import emu.grasscutter.game.gacha.GachaManager;
|
import emu.grasscutter.game.gacha.GachaManager;
|
||||||
import emu.grasscutter.game.managers.ChatManager;
|
import emu.grasscutter.game.managers.ChatManager;
|
||||||
@ -26,6 +27,7 @@ public final class GameServer extends MihoyoKcpServer {
|
|||||||
private final GameServerPacketHandler packetHandler;
|
private final GameServerPacketHandler packetHandler;
|
||||||
|
|
||||||
private final Map<Integer, GenshinPlayer> players;
|
private final Map<Integer, GenshinPlayer> players;
|
||||||
|
private final Set<World> worlds;
|
||||||
|
|
||||||
private final ChatManager chatManager;
|
private final ChatManager chatManager;
|
||||||
private final InventoryManager inventoryManager;
|
private final InventoryManager inventoryManager;
|
||||||
@ -50,6 +52,7 @@ public final class GameServer extends MihoyoKcpServer {
|
|||||||
this.address = address;
|
this.address = address;
|
||||||
this.packetHandler = new GameServerPacketHandler(PacketHandler.class);
|
this.packetHandler = new GameServerPacketHandler(PacketHandler.class);
|
||||||
this.players = new ConcurrentHashMap<>();
|
this.players = new ConcurrentHashMap<>();
|
||||||
|
this.worlds = Collections.synchronizedSet(new HashSet<>());
|
||||||
|
|
||||||
this.chatManager = new ChatManager(this);
|
this.chatManager = new ChatManager(this);
|
||||||
this.inventoryManager = new InventoryManager(this);
|
this.inventoryManager = new InventoryManager(this);
|
||||||
@ -84,6 +87,10 @@ public final class GameServer extends MihoyoKcpServer {
|
|||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<World> getWorlds() {
|
||||||
|
return worlds;
|
||||||
|
}
|
||||||
|
|
||||||
public ChatManager getChatManager() {
|
public ChatManager getChatManager() {
|
||||||
return chatManager;
|
return chatManager;
|
||||||
}
|
}
|
||||||
@ -161,12 +168,32 @@ public final class GameServer extends MihoyoKcpServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onTick() throws Exception {
|
public void onTick() throws Exception {
|
||||||
|
Iterator<World> it = this.getWorlds().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
World world = it.next();
|
||||||
|
|
||||||
|
if (world.getPlayerCount() == 0) {
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
world.onTick();
|
||||||
|
}
|
||||||
|
|
||||||
for (GenshinPlayer player : this.getPlayers().values()) {
|
for (GenshinPlayer player : this.getPlayers().values()) {
|
||||||
player.onTick();
|
player.onTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
OnGameServerTick.post(new GameServerTickEvent());
|
OnGameServerTick.post(new GameServerTickEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerWorld(World world) {
|
||||||
|
this.getWorlds().add(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deregisterWorld(World world) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartFinish() {
|
public void onStartFinish() {
|
||||||
|
Loading…
Reference in New Issue
Block a user