mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 08:36:38 +00:00
Add SceneDatas
This commit is contained in:
parent
696647dbd1
commit
121f4675d7
@ -338,7 +338,11 @@ public class PlayerCommands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getWorld().transferPlayerToScene(player, sceneId, player.getPos());
|
boolean result = player.getWorld().transferPlayerToScene(player, sceneId, player.getPos());
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
player.dropMessage("Scene does not exist!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,8 @@ public class GenshinData {
|
|||||||
private static final Int2ObjectMap<AvatarCostumeData> avatarCostumeDataMap = new Int2ObjectLinkedOpenHashMap<>();
|
private static final Int2ObjectMap<AvatarCostumeData> avatarCostumeDataMap = new Int2ObjectLinkedOpenHashMap<>();
|
||||||
private static final Int2ObjectMap<AvatarCostumeData> avatarCostumeDataItemIdMap = new Int2ObjectLinkedOpenHashMap<>();
|
private static final Int2ObjectMap<AvatarCostumeData> avatarCostumeDataItemIdMap = new Int2ObjectLinkedOpenHashMap<>();
|
||||||
|
|
||||||
|
private static final Int2ObjectMap<SceneData> sceneDataMap = new Int2ObjectLinkedOpenHashMap<>();
|
||||||
|
|
||||||
public static Int2ObjectMap<?> getMapByResourceDef(Class<?> resourceDefinition) {
|
public static Int2ObjectMap<?> getMapByResourceDef(Class<?> resourceDefinition) {
|
||||||
Int2ObjectMap<?> map = null;
|
Int2ObjectMap<?> map = null;
|
||||||
|
|
||||||
@ -209,4 +211,8 @@ public class GenshinData {
|
|||||||
public static Int2ObjectMap<AvatarCostumeData> getAvatarCostumeDataItemIdMap() {
|
public static Int2ObjectMap<AvatarCostumeData> getAvatarCostumeDataItemIdMap() {
|
||||||
return avatarCostumeDataItemIdMap;
|
return avatarCostumeDataItemIdMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Int2ObjectMap<SceneData> getSceneDataMap() {
|
||||||
|
return sceneDataMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
32
src/main/java/emu/grasscutter/data/def/SceneData.java
Normal file
32
src/main/java/emu/grasscutter/data/def/SceneData.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package emu.grasscutter.data.def;
|
||||||
|
|
||||||
|
import emu.grasscutter.data.GenshinData;
|
||||||
|
import emu.grasscutter.data.GenshinResource;
|
||||||
|
import emu.grasscutter.data.ResourceType;
|
||||||
|
|
||||||
|
import emu.grasscutter.game.props.SceneType;
|
||||||
|
|
||||||
|
@ResourceType(name = "SceneExcelConfigData.json")
|
||||||
|
public class SceneData extends GenshinResource {
|
||||||
|
private int Id;
|
||||||
|
private SceneType SceneType;
|
||||||
|
private String ScriptData;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return this.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SceneType getSceneType() {
|
||||||
|
return SceneType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScriptData() {
|
||||||
|
return ScriptData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import java.util.Iterator;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import emu.grasscutter.data.def.SceneData;
|
||||||
import emu.grasscutter.game.entity.EntityAvatar;
|
import emu.grasscutter.game.entity.EntityAvatar;
|
||||||
import emu.grasscutter.game.entity.EntityClientGadget;
|
import emu.grasscutter.game.entity.EntityClientGadget;
|
||||||
import emu.grasscutter.game.entity.EntityGadget;
|
import emu.grasscutter.game.entity.EntityGadget;
|
||||||
@ -14,6 +15,7 @@ import emu.grasscutter.game.entity.GenshinEntity;
|
|||||||
import emu.grasscutter.game.props.ClimateType;
|
import emu.grasscutter.game.props.ClimateType;
|
||||||
import emu.grasscutter.game.props.FightProperty;
|
import emu.grasscutter.game.props.FightProperty;
|
||||||
import emu.grasscutter.game.props.LifeState;
|
import emu.grasscutter.game.props.LifeState;
|
||||||
|
import emu.grasscutter.game.props.SceneType;
|
||||||
import emu.grasscutter.net.packet.GenshinPacket;
|
import emu.grasscutter.net.packet.GenshinPacket;
|
||||||
import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult;
|
import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult;
|
||||||
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
|
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
|
||||||
@ -26,31 +28,39 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
|||||||
|
|
||||||
public class GenshinScene {
|
public class GenshinScene {
|
||||||
private final World world;
|
private final World world;
|
||||||
|
private final SceneData sceneData;
|
||||||
private final List<GenshinPlayer> players;
|
private final List<GenshinPlayer> players;
|
||||||
private final Int2ObjectMap<GenshinEntity> entities;
|
private final Int2ObjectMap<GenshinEntity> entities;
|
||||||
private final int id;
|
|
||||||
|
|
||||||
private int time;
|
private int time;
|
||||||
private ClimateType climate;
|
private ClimateType climate;
|
||||||
|
|
||||||
public GenshinScene(World world, int sceneId) {
|
public GenshinScene(World world, SceneData sceneData) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
this.sceneData = sceneData;
|
||||||
this.players = Collections.synchronizedList(new ArrayList<>());
|
this.players = Collections.synchronizedList(new ArrayList<>());
|
||||||
this.entities = new Int2ObjectOpenHashMap<>();
|
this.entities = new Int2ObjectOpenHashMap<>();
|
||||||
this.id = sceneId;
|
|
||||||
|
|
||||||
this.time = 8 * 60;
|
this.time = 8 * 60;
|
||||||
this.climate = ClimateType.CLIMATE_SUNNY;
|
this.climate = ClimateType.CLIMATE_SUNNY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return sceneData.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SceneData getSceneData() {
|
||||||
|
return this.sceneData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SceneType getSceneType() {
|
||||||
|
return getSceneData().getSceneType();
|
||||||
|
}
|
||||||
|
|
||||||
public List<GenshinPlayer> getPlayers() {
|
public List<GenshinPlayer> getPlayers() {
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ import emu.grasscutter.game.props.EnterReason;
|
|||||||
import emu.grasscutter.game.props.EntityIdType;
|
import emu.grasscutter.game.props.EntityIdType;
|
||||||
import emu.grasscutter.game.props.FightProperty;
|
import emu.grasscutter.game.props.FightProperty;
|
||||||
import emu.grasscutter.game.props.LifeState;
|
import emu.grasscutter.game.props.LifeState;
|
||||||
|
import emu.grasscutter.data.GenshinData;
|
||||||
|
import emu.grasscutter.data.def.SceneData;
|
||||||
import emu.grasscutter.game.GenshinPlayer.SceneLoadState;
|
import emu.grasscutter.game.GenshinPlayer.SceneLoadState;
|
||||||
import emu.grasscutter.game.entity.EntityAvatar;
|
import emu.grasscutter.game.entity.EntityAvatar;
|
||||||
import emu.grasscutter.game.entity.EntityClientGadget;
|
import emu.grasscutter.game.entity.EntityClientGadget;
|
||||||
@ -99,7 +101,21 @@ public class World implements Iterable<GenshinPlayer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GenshinScene getSceneById(int sceneId) {
|
public GenshinScene getSceneById(int sceneId) {
|
||||||
return getScenes().computeIfAbsent(sceneId, id -> new GenshinScene(this, id));
|
// Get scene normally
|
||||||
|
GenshinScene scene = getScenes().get(sceneId);
|
||||||
|
if (scene != null) {
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create scene from scene data if it doesnt exist
|
||||||
|
SceneData sceneData = GenshinData.getSceneDataMap().get(sceneId);
|
||||||
|
if (sceneData != null) {
|
||||||
|
scene = new GenshinScene(this, sceneData);
|
||||||
|
this.getScenes().put(sceneId, scene);
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPlayerCount() {
|
public int getPlayerCount() {
|
||||||
@ -182,9 +198,9 @@ public class World implements Iterable<GenshinPlayer> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void transferPlayerToScene(GenshinPlayer player, int sceneId, Position pos) {
|
public boolean transferPlayerToScene(GenshinPlayer player, int sceneId, Position pos) {
|
||||||
if (player.getScene().getId() == sceneId) {
|
if (player.getScene().getId() == sceneId || GenshinData.getSceneDataMap().get(sceneId) == null) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.getScene() != null) {
|
if (player.getScene() != null) {
|
||||||
@ -193,10 +209,11 @@ public class World implements Iterable<GenshinPlayer> {
|
|||||||
|
|
||||||
GenshinScene scene = this.getSceneById(sceneId);
|
GenshinScene scene = this.getSceneById(sceneId);
|
||||||
scene.addPlayer(player);
|
scene.addPlayer(player);
|
||||||
|
|
||||||
player.getPos().set(pos);
|
player.getPos().set(pos);
|
||||||
|
|
||||||
|
// Teleport packet
|
||||||
player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterType.EnterSelf, EnterReason.TransPoint, sceneId, pos));
|
player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterType.EnterSelf, EnterReason.TransPoint, sceneId, pos));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePlayerInfos(GenshinPlayer paramPlayer) {
|
private void updatePlayerInfos(GenshinPlayer paramPlayer) {
|
||||||
|
45
src/main/java/emu/grasscutter/game/props/SceneType.java
Normal file
45
src/main/java/emu/grasscutter/game/props/SceneType.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package emu.grasscutter.game.props;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
|
||||||
|
public enum SceneType {
|
||||||
|
SCENE_NONE (0),
|
||||||
|
SCENE_WORLD (1),
|
||||||
|
SCENE_DUNGEON (2),
|
||||||
|
SCENE_ROOM (3),
|
||||||
|
SCENE_HOME_WORLD (4),
|
||||||
|
SCENE_HOME_ROOM (5),
|
||||||
|
SCENE_ACTIVITY (6);
|
||||||
|
|
||||||
|
private final int value;
|
||||||
|
private static final Int2ObjectMap<SceneType> map = new Int2ObjectOpenHashMap<>();
|
||||||
|
private static final Map<String, SceneType> stringMap = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
Stream.of(values()).forEach(e -> {
|
||||||
|
map.put(e.getValue(), e);
|
||||||
|
stringMap.put(e.name(), e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private SceneType(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SceneType getTypeByValue(int value) {
|
||||||
|
return map.getOrDefault(value, SCENE_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SceneType getTypeByName(String name) {
|
||||||
|
return stringMap.getOrDefault(name, SCENE_NONE);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user