Merge remote-tracking branch 'upstream/main'

This commit is contained in:
Benjamin Elsdon 2022-04-19 19:34:02 +08:00
commit 058d322238
66 changed files with 842 additions and 469 deletions

7
run.bat Normal file
View File

@ -0,0 +1,7 @@
@echo off
::This will not work if your java is in a different location, plugin as necessary
::this just saves you from changing your PATH
"C:\Program Files\Java\jdk1.8.0_202\bin\java.exe" -jar ./grasscutter.jar

View File

@ -43,6 +43,13 @@ public final class Config {
}
public static class ServerOptions {
public int InventoryLimitWeapon = 2000;
public int InventoryLimitRelic = 2000;
public int InventoryLimitMaterial = 2000;
public int InventoryLimitFurniture = 2000;
public int InventoryLimitAll = 30000;
public int MaxAvatarsInTeam = 4;
public int MaxAvatarsInTeamMultiplayer = 4;
public int MaxEntityLimit = 1000; // Max entity limit per world. // TODO: Enforce later.
public int[] WelcomeEmotes = {2007, 1002, 4010};
public String WelcomeMotd = "Welcome to Grasscutter emu";

View File

@ -9,14 +9,6 @@ public final class GenshinConstants {
public static String VERSION = "2.6.0";
public static final int MAX_TEAMS = 4;
public static final int MAX_AVATARS_IN_TEAM = 4;
public static final int LIMIT_WEAPON = 2000;
public static final int LIMIT_RELIC = 2000;
public static final int LIMIT_MATERIAL = 2000;
public static final int LIMIT_FURNITURE = 2000;
public static final int LIMIT_ALL = 30000;
public static final int MAIN_CHARACTER_MALE = 10000005;
public static final int MAIN_CHARACTER_FEMALE = 10000007;
public static final Position START_POSITION = new Position(2747, 194, -1719);

View File

@ -42,6 +42,7 @@ public final class Grasscutter {
// Load server configuration.
Grasscutter.loadConfig();
// Check server structure.
Utils.startupCheck();
}

View File

@ -7,6 +7,7 @@ import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.AvatarSkillDepotData;
import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.World;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.entity.EntityAvatar;
@ -54,8 +55,9 @@ public final class PlayerCommands {
case 2:
try {
target = Integer.parseInt(args.get(0));
if(Grasscutter.getGameServer().getPlayerById(target) == null) {
target = player.getId(); amount = Integer.parseInt(args.get(1));
if(Grasscutter.getGameServer().getPlayerByUid(target) == null) {
target = player.getUid(); amount = Integer.parseInt(args.get(1));
item = Integer.parseInt(args.get(0));
} else {
item = Integer.parseInt(args.get(1));
@ -69,7 +71,8 @@ public final class PlayerCommands {
case 3:
try {
target = Integer.parseInt(args.get(0));
if(Grasscutter.getGameServer().getPlayerById(target) == null) {
if(Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(player, "Invalid player ID."); return;
}
@ -83,7 +86,8 @@ public final class PlayerCommands {
break;
}
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if(targetPlayer == null) {
CommandHandler.sendMessage(player, "Player not found."); return;
}
@ -110,7 +114,8 @@ public final class PlayerCommands {
int item = Integer.parseInt(args.get(1));
int amount = 1; if(args.size() > 2) amount = Integer.parseInt(args.get(2));
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if(targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return;
}
@ -167,12 +172,12 @@ public final class PlayerCommands {
float range = (5f + (.1f * amount));
for (int i = 0; i < amount; i++) {
Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2));
EntityItem entity = new EntityItem(player.getWorld(), player, itemData, pos, 1);
player.getWorld().addEntity(entity);
EntityItem entity = new EntityItem(player.getScene(), player, itemData, pos, 1);
player.getScene().addEntity(entity);
}
} else {
EntityItem entity = new EntityItem(player.getWorld(), player, itemData, player.getPos().clone().addY(3f), amount);
player.getWorld().addEntity(entity);
EntityItem entity = new EntityItem(player.getScene(), player, itemData, player.getPos().clone().addY(3f), amount);
player.getScene().addEntity(entity);
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(player, "Invalid item or player ID.");
@ -208,8 +213,8 @@ public final class PlayerCommands {
case 2:
try {
target = Integer.parseInt(args.get(0));
if(Grasscutter.getGameServer().getPlayerById(target) == null) {
target = player.getId(); level = Integer.parseInt(args.get(1));
if(Grasscutter.getGameServer().getPlayerByUid(target) == null) {
target = player.getUid(); level = Integer.parseInt(args.get(1));
avatarID = Integer.parseInt(args.get(0));
} else {
avatarID = Integer.parseInt(args.get(1));
@ -223,7 +228,7 @@ public final class PlayerCommands {
case 3:
try {
target = Integer.parseInt(args.get(0));
if(Grasscutter.getGameServer().getPlayerById(target) == null) {
if(Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(player, "Invalid player ID."); return;
}
@ -237,7 +242,7 @@ public final class PlayerCommands {
break;
}
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if(targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return;
}
@ -277,7 +282,7 @@ public final class PlayerCommands {
int level = 1; if(args.size() > 2) level = Integer.parseInt(args.get(2));
int ascension = 1;
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if(targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return;
}
@ -307,7 +312,7 @@ public final class PlayerCommands {
}
}
}
@Command(label = "spawn", execution = Command.Execution.PLAYER,
usage = "spawn <entityId|entityName> [level] [amount]", description = "Spawns an entity near you", permission = "server.spawn")
public static class SpawnCommand implements CommandHandler {
@ -332,8 +337,8 @@ public final class PlayerCommands {
float range = (5f + (.1f * amount));
for (int i = 0; i < amount; i++) {
Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2));
EntityMonster monster = new EntityMonster(player.getWorld(), entityData, pos, level);
player.getWorld().addEntity(monster);
EntityMonster monster = new EntityMonster(player.getScene(), entityData, pos, level);
player.getScene().addEntity(monster);
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid item or player ID.");
@ -342,29 +347,46 @@ public final class PlayerCommands {
}
@Command(label = "killall",
usage = "killall [sceneId]", description = "Kill all entities", permission = "server.killall")
usage = "killall [playerUid] [sceneId]", description = "Kill all entities", permission = "server.killall")
public static class KillAllCommand implements CommandHandler {
@Override
public void execute(GenshinPlayer player, List<String> args) {
World world = player.getWorld();
world.getEntities().values().stream()
GenshinScene scene = player.getScene();
scene.getEntities().values().stream()
.filter(entity -> entity instanceof EntityMonster)
.forEach(entity -> world.killEntity(entity, 0));
.forEach(entity -> scene.killEntity(entity, 0));
CommandHandler.sendMessage(null, "Killing all monsters in scene " + scene.getId());
}
@Override
public void execute(List<String> args) {
if(args.size() < 1) {
CommandHandler.sendMessage(null, "Usage: killall [sceneId]"); return;
if(args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]"); return;
}
try {
int sceneId = Integer.parseInt(args.get(0));
CommandHandler.sendMessage(null, "Killing all monsters in scene " + sceneId);
// TODO: Implement getting worlds by scene ID.
int playerUid = Integer.parseInt(args.get(0));
int sceneId = Integer.parseInt(args.get(1));
GenshinPlayer player = Grasscutter.getGameServer().getPlayerByUid(playerUid);
if (player == null) {
CommandHandler.sendMessage(null, "Player not found or offline.");
return;
}
GenshinScene scene = player.getWorld().getSceneById(sceneId);
if (scene == null) {
CommandHandler.sendMessage(null, "Scene not found in player world");
return;
}
scene.getEntities().values().stream()
.filter(entity -> entity instanceof EntityMonster)
.forEach(entity -> scene.killEntity(entity, 0));
CommandHandler.sendMessage(null, "Killing all monsters in scene " + scene.getId());
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid scene id.");
CommandHandler.sendMessage(null, "Invalid arguments.");
}
}
}
@ -464,7 +486,6 @@ public final class PlayerCommands {
usage = "clearartifacts", execution = Command.Execution.PLAYER, permission = "player.clearartifacts",
description = "Deletes all unequipped and unlocked level 0 artifacts, including yellow rarity ones from your inventory")
public static class ClearArtifactsCommand implements CommandHandler {
@Override
public void execute(GenshinPlayer player, List<String> args) {
Inventory playerInventory = player.getInventory();
@ -476,6 +497,31 @@ public final class PlayerCommands {
}
}
@Command(label = "changescene", aliases = {"scene"},
usage = "changescene <scene id>", description = "Changes your scene", permission = "player.changescene", execution = Command.Execution.PLAYER)
public static class ChangeSceneCommand implements CommandHandler {
@Override
public void execute(GenshinPlayer player, List<String> args) {
if(args.size() < 1) {
CommandHandler.sendMessage(null, "Usage: changescene <scene id>"); return;
}
int sceneId = 0;
try {
sceneId = Integer.parseInt(args.get(0));
} catch (Exception e) {
return;
}
boolean result = player.getWorld().transferPlayerToScene(player, sceneId, player.getPos());
if (!result) {
CommandHandler.sendMessage(null, "Scene does not exist or you are already in it");
}
}
}
@Command(label = "sendservermessage", aliases = {"sendservmsg"},
usage = "sendservermessage <player> <message>", description = "Sends a message to a player as the server",
execution = Command.Execution.PLAYER, permission = "server.sendmessage")
@ -490,7 +536,7 @@ public final class PlayerCommands {
int target = Integer.parseInt(args.get(0));
String message = String.join(" ", args.subList(1, args.size()));
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if(targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return;
}

View File

@ -114,7 +114,8 @@ public final class ServerCommands {
int target = Integer.parseInt(args.get(0));
String message = String.join(" ", args.subList(1, args.size()));
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if(targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return;
}
@ -136,7 +137,8 @@ public final class ServerCommands {
int target = Integer.parseInt(args.get(0));
String message = String.join(" ", args.subList(1, args.size()));
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerById(target);
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if(targetPlayer == null) {
CommandHandler.sendMessage(player, "Player not found."); return;
}

View File

@ -51,6 +51,8 @@ public class GenshinData {
private static final Int2ObjectMap<AvatarCostumeData> avatarCostumeDataMap = new Int2ObjectLinkedOpenHashMap<>();
private static final Int2ObjectMap<AvatarCostumeData> avatarCostumeDataItemIdMap = new Int2ObjectLinkedOpenHashMap<>();
private static final Int2ObjectMap<SceneData> sceneDataMap = new Int2ObjectLinkedOpenHashMap<>();
public static Int2ObjectMap<?> getMapByResourceDef(Class<?> resourceDefinition) {
Int2ObjectMap<?> map = null;
@ -209,4 +211,8 @@ public class GenshinData {
public static Int2ObjectMap<AvatarCostumeData> getAvatarCostumeDataItemIdMap() {
return avatarCostumeDataItemIdMap;
}
public static Int2ObjectMap<SceneData> getSceneDataMap() {
return sceneDataMap;
}
}

View File

@ -48,6 +48,7 @@ public class ItemData extends GenshinResource {
private int WeaponBaseExp;
private int StoryId;
private int AvatarPromoteId;
private int AwakenMaterial;
private int[] AwakenCosts;
private int[] SkillAffix;
private WeaponProperty[] WeaponProp;
@ -160,6 +161,10 @@ public class ItemData extends GenshinResource {
return WeaponBaseExp;
}
public int getAwakenMaterial() {
return AwakenMaterial;
}
public int[] getAwakenCosts() {
return AwakenCosts;
}
@ -250,4 +255,4 @@ public class ItemData extends GenshinResource {
}
}
}
}

View 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() {
}
}

View File

@ -124,13 +124,13 @@ public class DatabaseHelper {
int id = 0;
if (reservedId > 0 && !checkPlayerExists(reservedId)) {
id = reservedId;
character.setId(id);
character.setUid(id);
} else {
do {
id = DatabaseManager.getNextId(character);
}
while (checkPlayerExists(id));
character.setId(id);
character.setUid(id);
}
// Save to database
DatabaseManager.getDatastore().save(character);
@ -160,7 +160,7 @@ public class DatabaseHelper {
}
public static List<GenshinAvatar> getAvatars(GenshinPlayer player) {
Query<GenshinAvatar> query = DatabaseManager.getDatastore().createQuery(GenshinAvatar.class).filter("ownerId", player.getId());
Query<GenshinAvatar> query = DatabaseManager.getDatastore().createQuery(GenshinAvatar.class).filter("ownerId", player.getUid());
return query.find().toList();
}
@ -174,16 +174,16 @@ public class DatabaseHelper {
}
public static List<GenshinItem> getInventoryItems(GenshinPlayer player) {
Query<GenshinItem> query = DatabaseManager.getDatastore().createQuery(GenshinItem.class).filter("ownerId", player.getId());
Query<GenshinItem> query = DatabaseManager.getDatastore().createQuery(GenshinItem.class).filter("ownerId", player.getUid());
return query.find().toList();
}
public static List<Friendship> getFriends(GenshinPlayer player) {
Query<Friendship> query = DatabaseManager.getDatastore().createQuery(Friendship.class).filter("ownerId", player.getId());
Query<Friendship> query = DatabaseManager.getDatastore().createQuery(Friendship.class).filter("ownerId", player.getUid());
return query.find().toList();
}
public static List<Friendship> getReverseFriends(GenshinPlayer player) {
Query<Friendship> query = DatabaseManager.getDatastore().createQuery(Friendship.class).filter("friendId", player.getId());
Query<Friendship> query = DatabaseManager.getDatastore().createQuery(Friendship.class).filter("friendId", player.getUid());
return query.find().toList();
}

View File

@ -78,6 +78,7 @@ public class GenshinPlayer {
@Transient private long nextGuid = 0;
@Transient private int peerId;
@Transient private World world;
@Transient private GenshinScene scene;
@Transient private GameSession session;
@Transient private AvatarStorage avatars;
@Transient private Inventory inventory;
@ -155,17 +156,17 @@ public class GenshinPlayer {
this.getRotation().set(0, 307, 0);
}
public int getId() {
public int getUid() {
return id;
}
public void setId(int id) {
public void setUid(int id) {
this.id = id;
}
public long getNextGuid() {
public long getNextGenshinGuid() {
long nextId = ++this.nextGuid;
return ((long) this.getId() << 32) + nextId;
return ((long) this.getUid() << 32) + nextId;
}
public Account getAccount() {
@ -174,7 +175,7 @@ public class GenshinPlayer {
public void setAccount(Account account) {
this.account = account;
this.account.setPlayerId(getId());
this.account.setPlayerId(getUid());
}
public GameSession getSession() {
@ -201,6 +202,14 @@ public class GenshinPlayer {
this.world = world;
}
public GenshinScene getScene() {
return scene;
}
public void setScene(GenshinScene scene) {
this.scene = scene;
}
public int getGmLevel() {
return 1;
}
@ -551,7 +560,7 @@ public class GenshinPlayer {
}
public void dropMessage(Object message) {
this.sendPacket(new PacketPrivateChatNotify(GenshinConstants.SERVER_CONSOLE_UID, getId(), message.toString()));
this.sendPacket(new PacketPrivateChatNotify(GenshinConstants.SERVER_CONSOLE_UID, getUid(), message.toString()));
}
/**
@ -560,18 +569,18 @@ public class GenshinPlayer {
* @param message The message to send.
*/
public void sendMessage(GenshinPlayer sender, Object message) {
this.sendPacket(new PacketPrivateChatNotify(sender.getId(), this.getId(), message.toString()));
this.sendPacket(new PacketPrivateChatNotify(sender.getUid(), this.getUid(), message.toString()));
}
public void interactWith(int gadgetEntityId) {
GenshinEntity entity = getWorld().getEntityById(gadgetEntityId);
GenshinEntity entity = getScene().getEntityById(gadgetEntityId);
if (entity == null) {
return;
}
// Delete
entity.getWorld().removeEntity(entity);
entity.getScene().removeEntity(entity);
// Handle
if (entity instanceof EntityItem) {
@ -605,7 +614,7 @@ public class GenshinPlayer {
public OnlinePlayerInfo getOnlinePlayerInfo() {
OnlinePlayerInfo.Builder onlineInfo = OnlinePlayerInfo.newBuilder()
.setUid(this.getId())
.setUid(this.getUid())
.setNickname(this.getNickname())
.setPlayerLevel(this.getLevel())
.setMpSettingType(this.getMpSetting())
@ -624,7 +633,7 @@ public class GenshinPlayer {
public SocialDetail.Builder getSocialDetail() {
SocialDetail.Builder social = SocialDetail.newBuilder()
.setUid(this.getId())
.setUid(this.getUid())
.setAvatar(HeadImage.newBuilder().setAvatarId(this.getHeadImage()))
.setNickname(this.getNickname())
.setSignature(this.getSignature())
@ -640,7 +649,7 @@ public class GenshinPlayer {
public PlayerLocationInfo getPlayerLocationInfo() {
return PlayerLocationInfo.newBuilder()
.setUid(this.getId())
.setUid(this.getUid())
.setPos(this.getPos().toProto())
.setRot(this.getRotation().toProto())
.build();
@ -690,7 +699,7 @@ public class GenshinPlayer {
// Check if player object exists in server
// TODO - optimize
GenshinPlayer exists = this.getServer().getPlayerById(getId());
GenshinPlayer exists = this.getServer().getPlayerByUid(getUid());
if (exists != null) {
exists.getSession().close();
}

View File

@ -0,0 +1,333 @@
package emu.grasscutter.game;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import emu.grasscutter.data.def.SceneData;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.entity.EntityClientGadget;
import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.entity.GenshinEntity;
import emu.grasscutter.game.props.ClimateType;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.LifeState;
import emu.grasscutter.game.props.SceneType;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult;
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify;
import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify;
import emu.grasscutter.server.packet.send.PacketSceneEntityDisappearNotify;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class GenshinScene {
private final World world;
private final SceneData sceneData;
private final List<GenshinPlayer> players;
private final Int2ObjectMap<GenshinEntity> entities;
private int time;
private ClimateType climate;
public GenshinScene(World world, SceneData sceneData) {
this.world = world;
this.sceneData = sceneData;
this.players = Collections.synchronizedList(new ArrayList<>());
this.entities = new Int2ObjectOpenHashMap<>();
this.time = 8 * 60;
this.climate = ClimateType.CLIMATE_SUNNY;
}
public int getId() {
return sceneData.getId();
}
public World getWorld() {
return world;
}
public SceneData getSceneData() {
return this.sceneData;
}
public SceneType getSceneType() {
return getSceneData().getSceneType();
}
public List<GenshinPlayer> getPlayers() {
return players;
}
public int getPlayerCount() {
return this.getPlayers().size();
}
public Int2ObjectMap<GenshinEntity> getEntities() {
return entities;
}
public GenshinEntity getEntityById(int id) {
return this.entities.get(id);
}
public int getTime() {
return time;
}
public void changeTime(int time) {
this.time = time % 1440;
}
public ClimateType getClimate() {
return climate;
}
public void setClimate(ClimateType climate) {
this.climate = climate;
}
public boolean isInScene(GenshinEntity entity) {
return this.entities.containsKey(entity.getId());
}
public void addPlayer(GenshinPlayer player) {
// Check if player already in
if (getPlayers().contains(player)) {
return;
}
// Remove player from prev scene
if (player.getScene() != null) {
player.getScene().removePlayer(player);
}
// Add
getPlayers().add(player);
player.setSceneId(this.getId());
player.setScene(this);
this.setupPlayerAvatars(player);
}
public void removePlayer(GenshinPlayer player) {
// Remove player from scene
getPlayers().remove(player);
player.setScene(null);
// Remove player avatars
this.removePlayerAvatars(player);
// Remove player gadgets
for (EntityGadget gadget : player.getTeamManager().getGadgets()) {
this.removeEntity(gadget);
}
// Deregister scene if not in use
if (this.getEntities().size() <= 0) {
this.getWorld().deregisterScene(this);
}
}
private void setupPlayerAvatars(GenshinPlayer player) {
// Clear entities from old team
player.getTeamManager().getActiveTeam().clear();
// Add new entities for player
TeamInfo teamInfo = player.getTeamManager().getCurrentTeamInfo();
for (int avatarId : teamInfo.getAvatars()) {
EntityAvatar entity = new EntityAvatar(player.getScene(), player.getAvatars().getAvatarById(avatarId));
player.getTeamManager().getActiveTeam().add(entity);
}
// Limit character index in case its out of bounds
if (player.getTeamManager().getCurrentCharacterIndex() >= player.getTeamManager().getActiveTeam().size() || player.getTeamManager().getCurrentCharacterIndex() < 0) {
player.getTeamManager().setCurrentCharacterIndex(player.getTeamManager().getCurrentCharacterIndex() - 1);
}
}
private void removePlayerAvatars(GenshinPlayer player) {
Iterator<EntityAvatar> it = player.getTeamManager().getActiveTeam().iterator();
while (it.hasNext()) {
this.removeEntity(it.next(), VisionType.VisionRemove);
it.remove();
}
}
public void spawnPlayer(GenshinPlayer player) {
if (this.isInScene(player.getTeamManager().getCurrentAvatarEntity())) {
return;
}
if (player.getTeamManager().getCurrentAvatarEntity().getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) <= 0f) {
player.getTeamManager().getCurrentAvatarEntity().setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 1f);
}
this.addEntity(player.getTeamManager().getCurrentAvatarEntity());
}
private void addEntityDirectly(GenshinEntity entity) {
getEntities().put(entity.getId(), entity);
}
public synchronized void addEntity(GenshinEntity entity) {
this.addEntityDirectly(entity);
this.broadcastPacket(new PacketSceneEntityAppearNotify(entity));
}
public synchronized void addEntities(Collection<GenshinEntity> entities) {
for (GenshinEntity entity : entities) {
this.addEntityDirectly(entity);
}
this.broadcastPacket(new PacketSceneEntityAppearNotify(entities, VisionType.VisionBorn));
}
private GenshinEntity removeEntityDirectly(GenshinEntity entity) {
return getEntities().remove(entity.getId());
}
public void removeEntity(GenshinEntity entity) {
this.removeEntity(entity, VisionType.VisionDie);
}
public synchronized void removeEntity(GenshinEntity entity, VisionType visionType) {
GenshinEntity removed = this.removeEntityDirectly(entity);
if (removed != null) {
this.broadcastPacket(new PacketSceneEntityDisappearNotify(removed, visionType));
}
}
public synchronized void replaceEntity(EntityAvatar oldEntity, EntityAvatar newEntity) {
this.removeEntityDirectly(oldEntity);
this.addEntityDirectly(newEntity);
this.broadcastPacket(new PacketSceneEntityDisappearNotify(oldEntity, VisionType.VisionReplace));
this.broadcastPacket(new PacketSceneEntityAppearNotify(newEntity, VisionType.VisionReplace, oldEntity.getId()));
}
public void showOtherEntities(GenshinPlayer player) {
List<GenshinEntity> entities = new LinkedList<>();
GenshinEntity currentEntity = player.getTeamManager().getCurrentAvatarEntity();
for (GenshinEntity entity : this.getEntities().values()) {
if (entity == currentEntity) {
continue;
}
entities.add(entity);
}
player.sendPacket(new PacketSceneEntityAppearNotify(entities, VisionType.VisionMeet));
}
public void handleAttack(AttackResult result) {
//GenshinEntity attacker = getEntityById(result.getAttackerId());
GenshinEntity target = getEntityById(result.getDefenseId());
if (target == null) {
return;
}
// Godmode check
if (target instanceof EntityAvatar) {
if (((EntityAvatar) target).getPlayer().inGodmode()) {
return;
}
}
// Lose hp
target.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, -result.getDamage());
// Check if dead
boolean isDead = false;
if (target.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) <= 0f) {
target.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 0f);
isDead = true;
}
// Packets
this.broadcastPacket(new PacketEntityFightPropUpdateNotify(target, FightProperty.FIGHT_PROP_CUR_HP));
// Check if dead
if (isDead) {
this.killEntity(target, result.getAttackerId());
}
}
public void killEntity(GenshinEntity target, int attackerId) {
// Packet
this.broadcastPacket(new PacketLifeStateChangeNotify(attackerId, target, LifeState.LIFE_DEAD));
this.removeEntity(target);
// Death event
target.onDeath(attackerId);
}
// Gadgets
public void onPlayerCreateGadget(EntityClientGadget gadget) {
// Directly add
this.addEntityDirectly(gadget);
// Add to owner's gadget list
gadget.getOwner().getTeamManager().getGadgets().add(gadget);
// Optimization
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == gadget.getOwner()) {
return;
}
this.broadcastPacketToOthers(gadget.getOwner(), new PacketSceneEntityAppearNotify(gadget));
}
public void onPlayerDestroyGadget(int entityId) {
GenshinEntity entity = getEntities().get(entityId);
if (entity == null || !(entity instanceof EntityClientGadget)) {
return;
}
// Get and remove entity
EntityClientGadget gadget = (EntityClientGadget) entity;
this.removeEntityDirectly(gadget);
// Remove from owner's gadget list
gadget.getOwner().getTeamManager().getGadgets().remove(gadget);
// Optimization
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == gadget.getOwner()) {
return;
}
this.broadcastPacketToOthers(gadget.getOwner(), new PacketSceneEntityDisappearNotify(gadget, VisionType.VisionDie));
}
// Broadcasting
public void broadcastPacket(GenshinPacket packet) {
// Send to all players - might have to check if player has been sent data packets
for (GenshinPlayer player : this.getPlayers()) {
player.getSession().send(packet);
}
}
public void broadcastPacketToOthers(GenshinPlayer excludedPlayer, GenshinPacket packet) {
// Optimization
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == excludedPlayer) {
return;
}
// Send to all players - might have to check if player has been sent data packets
for (GenshinPlayer player : this.getPlayers()) {
if (player == excludedPlayer) {
continue;
}
// Send
player.getSession().send(packet);
}
}
}

View File

@ -46,12 +46,12 @@ public class InvokeHandler<T> {
try {
if (entryListForwardAll.size() > 0) {
GenshinPacket packet = packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardAll);
player.getWorld().broadcastPacket(packet);
player.getScene().broadcastPacket(packet);
this.entryListForwardAll.clear();
}
if (entryListForwardAllExceptCur.size() > 0) {
GenshinPacket packet = packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardAllExceptCur);
player.getWorld().broadcastPacketToOthers(player, packet);
player.getScene().broadcastPacketToOthers(player, packet);
this.entryListForwardAllExceptCur.clear();
}
if (entryListForwardHost.size() > 0) {

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.avatar.GenshinAvatar;
public class TeamInfo {
@ -12,7 +13,7 @@ public class TeamInfo {
public TeamInfo() {
this.name = "";
this.avatars = new ArrayList<>(GenshinConstants.MAX_AVATARS_IN_TEAM);
this.avatars = new ArrayList<>(Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeam);
}
public String getName() {
@ -36,7 +37,7 @@ public class TeamInfo {
}
public boolean addAvatar(GenshinAvatar avatar) {
if (size() >= GenshinConstants.MAX_AVATARS_IN_TEAM || contains(avatar)) {
if (size() >= Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeam || contains(avatar)) {
return false;
}
@ -56,7 +57,7 @@ public class TeamInfo {
}
public void copyFrom(TeamInfo team) {
copyFrom(team, GenshinConstants.MAX_AVATARS_IN_TEAM);
copyFrom(team, Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeam);
}
public void copyFrom(TeamInfo team, int maxTeamSize) {

View File

@ -10,6 +10,7 @@ import java.util.Set;
import dev.morphia.annotations.Transient;
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.def.AvatarSkillDepotData;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.entity.EntityAvatar;
@ -158,17 +159,18 @@ public class TeamManager {
}
public boolean isSpawned() {
return getPlayer().getWorld() != null && getPlayer().getWorld().getEntities().containsKey(getCurrentAvatarEntity().getId());
return getPlayer().getScene() != null && getPlayer().getScene().getEntities().containsKey(getCurrentAvatarEntity().getId());
}
public int getMaxTeamSize() {
if (getPlayer().isInMultiplayer()) {
int max = Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeamMultiplayer;
if (getPlayer().getWorld().getHost() == this.getPlayer()) {
return Math.max(1, (int) Math.ceil(GenshinConstants.MAX_AVATARS_IN_TEAM / (double) getWorld().getPlayerCount()));
return Math.max(1, (int) Math.ceil(max / (double) getWorld().getPlayerCount()));
}
return Math.max(1, (int) Math.floor(GenshinConstants.MAX_AVATARS_IN_TEAM / (double) getWorld().getPlayerCount()));
return Math.max(1, (int) Math.floor(max / (double) getWorld().getPlayerCount()));
}
return GenshinConstants.MAX_AVATARS_IN_TEAM;
return Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeam;
}
// Methods
@ -233,7 +235,7 @@ public class TeamManager {
prevSelectedAvatarIndex = i;
}
} else {
entity = new EntityAvatar(getPlayer().getWorld(), getPlayer().getAvatars().getAvatarById(avatarId));
entity = new EntityAvatar(getPlayer().getScene(), getPlayer().getAvatars().getAvatarById(avatarId));
}
this.getActiveTeam().add(entity);
@ -241,7 +243,7 @@ public class TeamManager {
// Unload removed entities
for (EntityAvatar entity : existingAvatars.values()) {
getPlayer().getWorld().removeEntity(entity);
getPlayer().getScene().removeEntity(entity);
entity.getAvatar().save();
}
@ -266,7 +268,7 @@ public class TeamManager {
// Check if character changed
if (currentEntity != getCurrentAvatarEntity()) {
// Remove and Add
getWorld().replaceEntity(currentEntity, getCurrentAvatarEntity());
getPlayer().getScene().replaceEntity(currentEntity, getCurrentAvatarEntity());
}
}
@ -396,7 +398,7 @@ public class TeamManager {
oldEntity.setMotionState(MotionState.MotionStandby);
// Remove and Add
getWorld().replaceEntity(oldEntity, newEntity);
getPlayer().getScene().replaceEntity(oldEntity, newEntity);
getPlayer().sendPacket(new PacketChangeAvatarRsp(guid));
}
@ -426,7 +428,7 @@ public class TeamManager {
} else {
// Set index and spawn replacement member
this.setCurrentCharacterIndex(replaceIndex);
getWorld().addEntity(replacement);
getPlayer().getScene().addEntity(replacement);
}
// Response packet

View File

@ -14,6 +14,8 @@ import emu.grasscutter.game.props.EnterReason;
import emu.grasscutter.game.props.EntityIdType;
import emu.grasscutter.game.props.FightProperty;
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.entity.EntityAvatar;
import emu.grasscutter.game.entity.EntityClientGadget;
@ -33,24 +35,21 @@ import emu.grasscutter.server.packet.send.PacketSyncScenePlayTeamEntityNotify;
import emu.grasscutter.server.packet.send.PacketSyncTeamEntityNotify;
import emu.grasscutter.server.packet.send.PacketWorldPlayerInfoNotify;
import emu.grasscutter.server.packet.send.PacketWorldPlayerRTTNotify;
import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class World implements Iterable<GenshinPlayer> {
private final GenshinPlayer owner;
private final List<GenshinPlayer> players;
private final Int2ObjectMap<GenshinScene> scenes;
private int levelEntityId;
private int nextEntityId = 0;
private int nextPeerId = 0;
private final Int2ObjectMap<GenshinEntity> entities;
private int worldLevel;
private int sceneId;
private int time;
private ClimateType climate;
private boolean isMultiplayer;
private boolean isDungeon;
public World(GenshinPlayer player) {
this(player, false);
@ -59,11 +58,9 @@ public class World implements Iterable<GenshinPlayer> {
public World(GenshinPlayer player, boolean isMultiplayer) {
this.owner = player;
this.players = Collections.synchronizedList(new ArrayList<>());
this.entities = new Int2ObjectOpenHashMap<>();
this.scenes = new Int2ObjectOpenHashMap<>();
this.levelEntityId = getNextEntityId(EntityIdType.MPLEVEL);
this.sceneId = player.getSceneId();
this.time = 8 * 60;
this.climate = ClimateType.CLIMATE_SUNNY;
this.worldLevel = player.getWorldLevel();
this.isMultiplayer = isMultiplayer;
}
@ -87,22 +84,6 @@ public class World implements Iterable<GenshinPlayer> {
return ++this.nextPeerId;
}
public int getSceneId() {
return sceneId;
}
public void setSceneId(int sceneId) {
this.sceneId = sceneId;
}
public int getTime() {
return time;
}
public void changeTime(int time) {
this.time = time % 1440;
}
public int getWorldLevel() {
return worldLevel;
}
@ -111,46 +92,44 @@ public class World implements Iterable<GenshinPlayer> {
this.worldLevel = worldLevel;
}
public ClimateType getClimate() {
return climate;
}
public void setClimate(ClimateType climate) {
this.climate = climate;
}
public List<GenshinPlayer> getPlayers() {
return players;
}
public Int2ObjectMap<GenshinScene> getScenes() {
return this.scenes;
}
public GenshinScene getSceneById(int sceneId) {
// 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.registerScene(scene);
return scene;
}
return null;
}
public int getPlayerCount() {
return getPlayers().size();
}
public Int2ObjectMap<GenshinEntity> getEntities() {
return this.entities;
}
public boolean isInWorld(GenshinEntity entity) {
return this.entities.containsKey(entity.getId());
}
public boolean isMultiplayer() {
return isMultiplayer;
}
public boolean isDungeon() {
return isDungeon;
}
public int getNextEntityId(EntityIdType idType) {
return (idType.getId() << 24) + ++this.nextEntityId;
}
public GenshinEntity getEntityById(int id) {
return this.entities.get(id);
}
public synchronized void addPlayer(GenshinPlayer player) {
// Check if player already in
if (getPlayers().contains(player)) {
@ -165,13 +144,21 @@ public class World implements Iterable<GenshinPlayer> {
// Register
player.setWorld(this);
getPlayers().add(player);
// Set player variables
player.setPeerId(this.getNextPeerId());
player.getTeamManager().setEntityId(getNextEntityId(EntityIdType.TEAM));
// Setup team avatars
this.setupPlayerAvatars(player);
// Copy main team to mp team
if (this.isMultiplayer()) {
player.getTeamManager().getMpTeam().copyFrom(player.getTeamManager().getCurrentSinglePlayerTeamInfo(), player.getTeamManager().getMaxTeamSize());
player.getTeamManager().setCurrentCharacterIndex(0);
}
// Add to scene
GenshinScene scene = this.getSceneById(player.getSceneId());
scene.addPlayer(player);
// Info packet for other players
if (this.getPlayers().size() > 1) {
this.updatePlayerInfos(player);
@ -191,18 +178,15 @@ public class World implements Iterable<GenshinPlayer> {
getPlayers().remove(player);
player.setWorld(null);
this.removePlayerAvatars(player);
// Remove from scene
GenshinScene scene = this.getSceneById(player.getSceneId());
scene.removePlayer(player);
// Info packet for other players
if (this.getPlayers().size() > 0) {
this.updatePlayerInfos(player);
}
// Remove player gadgets
for (EntityGadget gadget : player.getTeamManager().getGadgets()) {
this.removeEntity(gadget);
}
// Disband world if host leaves
if (getHost() == player) {
List<GenshinPlayer> kicked = new ArrayList<>(this.getPlayers());
@ -210,11 +194,37 @@ public class World implements Iterable<GenshinPlayer> {
World world = new World(victim);
world.addPlayer(victim);
victim.sendPacket(new PacketPlayerEnterSceneNotify(victim, EnterType.EnterSelf, EnterReason.TeamKick, victim.getWorld().getSceneId(), victim.getPos()));
victim.sendPacket(new PacketPlayerEnterSceneNotify(victim, EnterType.EnterSelf, EnterReason.TeamKick, victim.getSceneId(), victim.getPos()));
}
}
}
public void registerScene(GenshinScene scene) {
this.getScenes().put(scene.getId(), scene);
}
public void deregisterScene(GenshinScene scene) {
this.getScenes().remove(scene.getId());
}
public boolean transferPlayerToScene(GenshinPlayer player, int sceneId, Position pos) {
if (player.getScene().getId() == sceneId || GenshinData.getSceneDataMap().get(sceneId) == null) {
return false;
}
if (player.getScene() != null) {
player.getScene().removePlayer(player);
}
GenshinScene scene = this.getSceneById(sceneId);
scene.addPlayer(player);
player.getPos().set(pos);
// Teleport packet
player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterType.EnterSelf, EnterReason.TransPoint, sceneId, pos));
return true;
}
private void updatePlayerInfos(GenshinPlayer paramPlayer) {
for (GenshinPlayer player : getPlayers()) {
// Dont send packets if player is loading in and filter out joining player
@ -239,185 +249,6 @@ public class World implements Iterable<GenshinPlayer> {
}
}
private void addEntityDirectly(GenshinEntity entity) {
getEntities().put(entity.getId(), entity);
}
public synchronized void addEntity(GenshinEntity entity) {
this.addEntityDirectly(entity);
this.broadcastPacket(new PacketSceneEntityAppearNotify(entity));
}
public synchronized void addEntities(Collection<GenshinEntity> entities) {
for (GenshinEntity entity : entities) {
this.addEntityDirectly(entity);
}
this.broadcastPacket(new PacketSceneEntityAppearNotify(entities, VisionType.VisionBorn));
}
private GenshinEntity removeEntityDirectly(GenshinEntity entity) {
return getEntities().remove(entity.getId());
}
public void removeEntity(GenshinEntity entity) {
this.removeEntity(entity, VisionType.VisionDie);
}
public synchronized void removeEntity(GenshinEntity entity, VisionType visionType) {
GenshinEntity removed = this.removeEntityDirectly(entity);
if (removed != null) {
this.broadcastPacket(new PacketSceneEntityDisappearNotify(removed, visionType));
}
}
public synchronized void replaceEntity(EntityAvatar oldEntity, EntityAvatar newEntity) {
this.removeEntityDirectly(oldEntity);
this.addEntityDirectly(newEntity);
this.broadcastPacket(new PacketSceneEntityDisappearNotify(oldEntity, VisionType.VisionReplace));
this.broadcastPacket(new PacketSceneEntityAppearNotify(newEntity, VisionType.VisionReplace, oldEntity.getId()));
}
private void setupPlayerAvatars(GenshinPlayer player) {
// Copy main team to mp team
if (this.isMultiplayer()) {
player.getTeamManager().getMpTeam().copyFrom(player.getTeamManager().getCurrentSinglePlayerTeamInfo(), player.getTeamManager().getMaxTeamSize());
}
// Clear entities from old team
player.getTeamManager().getActiveTeam().clear();
// Add new entities for player
TeamInfo teamInfo = player.getTeamManager().getCurrentTeamInfo();
for (int avatarId : teamInfo.getAvatars()) {
EntityAvatar entity = new EntityAvatar(this, player.getAvatars().getAvatarById(avatarId));
player.getTeamManager().getActiveTeam().add(entity);
}
// Limit character index in case its out of bounds
if (player.getTeamManager().getCurrentCharacterIndex() >= player.getTeamManager().getActiveTeam().size() || player.getTeamManager().getCurrentCharacterIndex() < 0) {
player.getTeamManager().setCurrentCharacterIndex(player.getTeamManager().getCurrentCharacterIndex() - 1);
}
}
private void removePlayerAvatars(GenshinPlayer player) {
Iterator<EntityAvatar> it = player.getTeamManager().getActiveTeam().iterator();
while (it.hasNext()) {
this.removeEntity(it.next(), VisionType.VisionRemove);
it.remove();
}
}
public void spawnPlayer(GenshinPlayer player) {
if (isInWorld(player.getTeamManager().getCurrentAvatarEntity())) {
return;
}
if (player.getTeamManager().getCurrentAvatarEntity().getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) <= 0f) {
player.getTeamManager().getCurrentAvatarEntity().setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 1f);
}
this.addEntity(player.getTeamManager().getCurrentAvatarEntity());
}
public void showOtherEntities(GenshinPlayer player) {
List<GenshinEntity> entities = new LinkedList<>();
GenshinEntity currentEntity = player.getTeamManager().getCurrentAvatarEntity();
for (GenshinEntity entity : this.getEntities().values()) {
if (entity == currentEntity) {
continue;
}
entities.add(entity);
}
player.sendPacket(new PacketSceneEntityAppearNotify(entities, VisionType.VisionMeet));
}
public void handleAttack(AttackResult result) {
//GenshinEntity attacker = getEntityById(result.getAttackerId());
GenshinEntity target = getEntityById(result.getDefenseId());
if (target == null) {
return;
}
// Godmode check
if (target instanceof EntityAvatar) {
if (((EntityAvatar) target).getPlayer().inGodmode()) {
return;
}
}
// Lose hp
target.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, -result.getDamage());
// Check if dead
boolean isDead = false;
if (target.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) <= 0f) {
target.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 0f);
isDead = true;
}
// Packets
this.broadcastPacket(new PacketEntityFightPropUpdateNotify(target, FightProperty.FIGHT_PROP_CUR_HP));
// Check if dead
if (isDead) {
this.killEntity(target, result.getAttackerId());
}
}
public void killEntity(GenshinEntity target, int attackerId) {
// Packet
this.broadcastPacket(new PacketLifeStateChangeNotify(attackerId, target, LifeState.LIFE_DEAD));
this.removeEntity(target);
// Death event
target.onDeath(attackerId);
}
// Gadgets
public void onPlayerCreateGadget(EntityClientGadget gadget) {
// Directly add
this.addEntityDirectly(gadget);
// Add to owner's gadget list
gadget.getOwner().getTeamManager().getGadgets().add(gadget);
// Optimization
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == gadget.getOwner()) {
return;
}
this.broadcastPacketToOthers(gadget.getOwner(), new PacketSceneEntityAppearNotify(gadget));
}
public void onPlayerDestroyGadget(int entityId) {
GenshinEntity entity = getEntities().get(entityId);
if (entity == null || !(entity instanceof EntityClientGadget)) {
return;
}
// Get and remove entity
EntityClientGadget gadget = (EntityClientGadget) entity;
this.removeEntityDirectly(gadget);
// Remove from owner's gadget list
gadget.getOwner().getTeamManager().getGadgets().remove(gadget);
// Optimization
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == gadget.getOwner()) {
return;
}
this.broadcastPacketToOthers(gadget.getOwner(), new PacketSceneEntityDisappearNotify(gadget, VisionType.VisionDie));
}
// Broadcasting
public void broadcastPacket(GenshinPacket packet) {
// Send to all players - might have to check if player has been sent data packets
for (GenshinPlayer player : this.getPlayers()) {
@ -425,21 +256,6 @@ public class World implements Iterable<GenshinPlayer> {
}
}
public void broadcastPacketToOthers(GenshinPlayer excludedPlayer, GenshinPacket packet) {
// Optimization
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == excludedPlayer) {
return;
}
// Send to all players - might have to check if player has been sent data packets
for (GenshinPlayer player : this.getPlayers()) {
if (player == excludedPlayer) {
continue;
}
// Send
player.getSession().send(packet);
}
}
public void close() {
}

View File

@ -122,7 +122,7 @@ public class AvatarStorage implements Iterable<GenshinAvatar> {
entity = new EntityAvatar(avatar);
getPlayer().sendPacket(new PacketAvatarChangeCostumeNotify(entity));
} else {
getPlayer().getWorld().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity));
getPlayer().getScene().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity));
}
// Done

View File

@ -148,8 +148,8 @@ public class GenshinAvatar {
public void setOwner(GenshinPlayer player) {
this.owner = player;
this.ownerId = player.getId();
this.guid = player.getNextGuid();
this.ownerId = player.getUid();
this.guid = player.getNextGenshinGuid();
}
public int getSatiation() {

View File

@ -5,6 +5,7 @@ import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.AvatarSkillDepotData;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.World;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.inventory.EquipType;
@ -39,14 +40,14 @@ public class EntityAvatar extends GenshinEntity {
private PlayerDieType killedType;
private int killedBy;
public EntityAvatar(World world, GenshinAvatar avatar) {
super(world);
public EntityAvatar(GenshinScene scene, GenshinAvatar avatar) {
super(scene);
this.avatar = avatar;
this.id = world.getNextEntityId(EntityIdType.AVATAR);
this.id = getScene().getWorld().getNextEntityId(EntityIdType.AVATAR);
GenshinItem weapon = this.getAvatar().getWeapon();
if (weapon != null) {
weapon.setWeaponEntityId(world.getNextEntityId(EntityIdType.WEAPON));
weapon.setWeaponEntityId(getScene().getWorld().getNextEntityId(EntityIdType.WEAPON));
}
}
@ -106,7 +107,7 @@ public class EntityAvatar extends GenshinEntity {
public SceneAvatarInfo getSceneAvatarInfo() {
SceneAvatarInfo.Builder avatarInfo = SceneAvatarInfo.newBuilder()
.setPlayerId(this.getPlayer().getId())
.setPlayerId(this.getPlayer().getUid())
.setAvatarId(this.getAvatar().getAvatarId())
.setGuid(this.getAvatar().getGuid())
.setPeerId(this.getPlayer().getPeerId())
@ -152,7 +153,7 @@ public class EntityAvatar extends GenshinEntity {
.setLastMoveReliableSeq(this.getLastMoveReliableSeq())
.setLifeState(this.getLifeState().getValue());
if (this.getWorld() != null) {
if (this.getScene() != null) {
entityInfo.setMotionInfo(this.getMotionInfo());
}

View File

@ -1,6 +1,7 @@
package emu.grasscutter.game.entity;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.World;
import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo;
@ -34,8 +35,8 @@ public class EntityClientGadget extends EntityGadget {
private int targetEntityId;
private boolean asyncLoad;
public EntityClientGadget(World world, GenshinPlayer player, EvtCreateGadgetNotify notify) {
super(world);
public EntityClientGadget(GenshinScene scene, GenshinPlayer player, EvtCreateGadgetNotify notify) {
super(scene);
this.owner = player;
this.id = notify.getEntityId();
this.pos = new Position(notify.getInitPos());

View File

@ -1,11 +1,12 @@
package emu.grasscutter.game.entity;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.World;
public abstract class EntityGadget extends GenshinEntity {
public EntityGadget(World world) {
super(world);
public EntityGadget(GenshinScene scene) {
super(scene);
}
public abstract int getGadgetId();

View File

@ -2,6 +2,7 @@ package emu.grasscutter.game.entity;
import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.World;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.game.props.EntityIdType;
@ -30,12 +31,12 @@ public class EntityItem extends EntityGadget {
private final GenshinItem item;
private final long guid;
public EntityItem(World world, GenshinPlayer player, ItemData itemData, Position pos, int count) {
super(world);
this.id = world.getNextEntityId(EntityIdType.GADGET);
public EntityItem(GenshinScene scene, GenshinPlayer player, ItemData itemData, Position pos, int count) {
super(scene);
this.id = getScene().getWorld().getNextEntityId(EntityIdType.GADGET);
this.pos = new Position(pos);
this.rot = new Position();
this.guid = player.getNextGuid();
this.guid = player.getNextGenshinGuid();
this.item = new GenshinItem(itemData, count);
}

View File

@ -4,6 +4,7 @@ import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.common.PropGrowCurve;
import emu.grasscutter.data.def.MonsterCurveData;
import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.World;
import emu.grasscutter.game.props.EntityIdType;
import emu.grasscutter.game.props.FightProperty;
@ -36,9 +37,9 @@ public class EntityMonster extends GenshinEntity {
private final int level;
private int weaponEntityId;
public EntityMonster(World world, MonsterData monsterData, Position pos, int level) {
super(world);
this.id = world.getNextEntityId(EntityIdType.MONSTER);
public EntityMonster(GenshinScene scene, MonsterData monsterData, Position pos, int level) {
super(scene);
this.id = getWorld().getNextEntityId(EntityIdType.MONSTER);
this.monsterData = monsterData;
this.fightProp = new Int2FloatOpenHashMap();
this.pos = new Position(pos);
@ -48,7 +49,7 @@ public class EntityMonster extends GenshinEntity {
// Monster weapon
if (getMonsterWeaponId() > 0) {
this.weaponEntityId = world.getNextEntityId(EntityIdType.WEAPON);
this.weaponEntityId = getWorld().getNextEntityId(EntityIdType.WEAPON);
}
this.recalcStats();

View File

@ -1,5 +1,6 @@
package emu.grasscutter.game.entity;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.World;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.LifeState;
@ -12,23 +13,27 @@ import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
public abstract class GenshinEntity {
protected int id;
private final World world;
private final GenshinScene scene;
private MotionState moveState;
private int lastMoveSceneTimeMs;
private int lastMoveReliableSeq;
public GenshinEntity(World world) {
this.world = world;
public GenshinEntity(GenshinScene scene) {
this.scene = scene;
this.moveState = MotionState.MotionNone;
}
public int getId() {
return this.id;
}
public World getWorld() {
return world;
return this.getScene().getWorld();
}
public GenshinScene getScene() {
return this.scene;
}
public boolean isAlive() {

View File

@ -79,11 +79,11 @@ public class FriendsList {
}
// Make sure asker cant do anything
if (myFriendship.getAskerId() == this.getPlayer().getId()) {
if (myFriendship.getAskerId() == this.getPlayer().getUid()) {
return;
}
GenshinPlayer target = getPlayer().getSession().getServer().forceGetPlayerById(targetUid);
GenshinPlayer target = getPlayer().getSession().getServer().getPlayerByUid(targetUid, true);
if (target == null) {
return; // Should never happen
}
@ -91,7 +91,7 @@ public class FriendsList {
// Get target's friendship
Friendship theirFriendship = null;
if (target.isOnline()) {
theirFriendship = target.getFriendsList().getPendingFriendById(this.getPlayer().getId());
theirFriendship = target.getFriendsList().getPendingFriendById(this.getPlayer().getUid());
} else {
theirFriendship = DatabaseHelper.getReverseFriendship(myFriendship);
}
@ -112,7 +112,7 @@ public class FriendsList {
this.addFriend(myFriendship);
if (target.isOnline()) {
target.getFriendsList().getPendingFriends().remove(this.getPlayer().getId());
target.getFriendsList().getPendingFriends().remove(this.getPlayer().getUid());
target.getFriendsList().addFriend(theirFriendship);
}
@ -124,7 +124,7 @@ public class FriendsList {
myFriendship.delete();
// Delete from target uid
if (target.isOnline()) {
theirFriendship = target.getFriendsList().getPendingFriendById(this.getPlayer().getId());
theirFriendship = target.getFriendsList().getPendingFriendById(this.getPlayer().getUid());
}
theirFriendship.delete();
}
@ -146,7 +146,7 @@ public class FriendsList {
GenshinPlayer friend = myFriendship.getFriendProfile().getPlayer();
if (friend != null) {
// Friend online
theirFriendship = friend.getFriendsList().getFriendById(this.getPlayer().getId());
theirFriendship = friend.getFriendsList().getFriendById(this.getPlayer().getUid());
if (theirFriendship != null) {
friend.getFriendsList().getFriends().remove(theirFriendship.getFriendId());
theirFriendship.delete();
@ -165,7 +165,7 @@ public class FriendsList {
}
public synchronized void sendFriendRequest(int targetUid) {
GenshinPlayer target = getPlayer().getSession().getServer().forceGetPlayerById(targetUid);
GenshinPlayer target = getPlayer().getSession().getServer().getPlayerByUid(targetUid, true);
if (target == null || target == this.getPlayer()) {
return;
@ -220,14 +220,14 @@ public class FriendsList {
friendship.setOwner(getPlayer());
// Check if friend is online
GenshinPlayer friend = getPlayer().getSession().getServer().getPlayerById(friendship.getFriendProfile().getId());
GenshinPlayer friend = getPlayer().getSession().getServer().getPlayerByUid(friendship.getFriendProfile().getId());
if (friend != null) {
// Set friend to online mode
friendship.setFriendProfile(friend);
// Update our status on friend's client if theyre online
if (friend.getFriendsList().hasLoaded()) {
Friendship theirFriendship = friend.getFriendsList().getFriendshipById(getPlayer().getId());
Friendship theirFriendship = friend.getFriendsList().getFriendshipById(getPlayer().getUid());
if (theirFriendship != null) {
// Update friend profile
theirFriendship.setFriendProfile(getPlayer());

View File

@ -27,10 +27,10 @@ public class Friendship {
public Friendship(GenshinPlayer owner, GenshinPlayer friend, GenshinPlayer asker) {
this.setOwner(owner);
this.ownerId = owner.getId();
this.friendId = friend.getId();
this.ownerId = owner.getUid();
this.friendId = friend.getUid();
this.profile = friend.getProfile();
this.askerId = asker.getId();
this.askerId = asker.getUid();
}
public GenshinPlayer getOwner() {
@ -70,7 +70,7 @@ public class Friendship {
}
public void setFriendProfile(GenshinPlayer character) {
if (character == null || this.friendId != character.getId()) return;
if (character == null || this.friendId != character.getUid()) return;
this.profile = character.getProfile();
}

View File

@ -22,7 +22,7 @@ public class PlayerProfile {
public PlayerProfile() { }
public PlayerProfile(GenshinPlayer player) {
this.id = player.getId();
this.id = player.getUid();
this.syncWithCharacter(player);
}

View File

@ -125,8 +125,8 @@ public class GenshinItem {
}
public void setOwner(GenshinPlayer player) {
this.ownerId = player.getId();
this.guid = player.getNextGuid();
this.ownerId = player.getUid();
this.guid = player.getNextGenshinGuid();
}
public int getItemId() {
return itemId;

View File

@ -6,6 +6,7 @@ import java.util.LinkedList;
import java.util.List;
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.def.AvatarCostumeData;
import emu.grasscutter.data.def.AvatarData;
@ -36,10 +37,10 @@ public class Inventory implements Iterable<GenshinItem> {
this.store = new Long2ObjectOpenHashMap<>();
this.inventoryTypes = new Int2ObjectOpenHashMap<>();
this.createInventoryTab(ItemType.ITEM_WEAPON, new EquipInventoryTab(GenshinConstants.LIMIT_WEAPON));
this.createInventoryTab(ItemType.ITEM_RELIQUARY, new EquipInventoryTab(GenshinConstants.LIMIT_RELIC));
this.createInventoryTab(ItemType.ITEM_MATERIAL, new MaterialInventoryTab(GenshinConstants.LIMIT_MATERIAL));
this.createInventoryTab(ItemType.ITEM_FURNITURE, new MaterialInventoryTab(GenshinConstants.LIMIT_FURNITURE));
this.createInventoryTab(ItemType.ITEM_WEAPON, new EquipInventoryTab(Grasscutter.getConfig().getServerOptions().InventoryLimitWeapon));
this.createInventoryTab(ItemType.ITEM_RELIQUARY, new EquipInventoryTab(Grasscutter.getConfig().getServerOptions().InventoryLimitRelic));
this.createInventoryTab(ItemType.ITEM_MATERIAL, new MaterialInventoryTab(Grasscutter.getConfig().getServerOptions().InventoryLimitMaterial));
this.createInventoryTab(ItemType.ITEM_FURNITURE, new MaterialInventoryTab(Grasscutter.getConfig().getServerOptions().InventoryLimitFurniture));
}
public GenshinPlayer getPlayer() {

View File

@ -36,14 +36,14 @@ public class ChatManager {
}
// Get target
GenshinPlayer target = getServer().getPlayerById(targetUid);
GenshinPlayer target = getServer().getPlayerByUid(targetUid);
if (target == null) {
return;
}
// Create chat packet
GenshinPacket packet = new PacketPrivateChatNotify(player.getId(), target.getId(), message);
GenshinPacket packet = new PacketPrivateChatNotify(player.getUid(), target.getUid(), message);
player.sendPacket(packet);
target.sendPacket(packet);
@ -51,14 +51,14 @@ public class ChatManager {
public void sendPrivateMessage(GenshinPlayer player, int targetUid, int emote) {
// Get target
GenshinPlayer target = getServer().getPlayerById(targetUid);
GenshinPlayer target = getServer().getPlayerByUid(targetUid);
if (target == null) {
return;
}
// Create chat packet
GenshinPacket packet = new PacketPrivateChatNotify(player.getId(), target.getId(), emote);
GenshinPacket packet = new PacketPrivateChatNotify(player.getUid(), target.getUid(), emote);
player.sendPacket(packet);
target.sendPacket(packet);

View File

@ -438,8 +438,14 @@ public class InventoryManager {
return;
}
if (weapon.getItemType() != ItemType.ITEM_WEAPON || weapon.getItemId() != feed.getItemId()) {
return;
if (weapon.getItemData().getAwakenMaterial() == 0) {
if (weapon.getItemType() != ItemType.ITEM_WEAPON || weapon.getItemId() != feed.getItemId()) {
return;
}
} else {
if (weapon.getItemType() != ItemType.ITEM_WEAPON || weapon.getItemData().getAwakenMaterial() != feed.getItemId()) {
return;
}
}
if (weapon.getRefinement() >= 4 || weapon.getAffixes() == null || weapon.getAffixes().size() == 0) {

View File

@ -24,7 +24,7 @@ public class MultiplayerManager {
}
public void applyEnterMp(GenshinPlayer player, int targetUid) {
GenshinPlayer target = getServer().getPlayerById(targetUid);
GenshinPlayer target = getServer().getPlayerByUid(targetUid);
if (target == null) {
player.sendPacket(new PacketPlayerApplyEnterMpResultNotify(targetUid, "", false, PlayerApplyEnterMpReason.PlayerCannotEnterMp));
return;
@ -35,13 +35,15 @@ public class MultiplayerManager {
return;
}
/*
if (target.getWorld().isDungeon()) {
player.sendPacket(new PacketPlayerApplyEnterMpResultNotify(targetUid, "", false, PlayerApplyEnterMpReason.SceneCannotEnter));
return;
}
*/
// Get request
CoopRequest request = target.getCoopRequests().get(player.getId());
CoopRequest request = target.getCoopRequests().get(player.getUid());
if (request != null && !request.isExpired()) {
// Join request already exists
@ -50,31 +52,31 @@ public class MultiplayerManager {
// Put request in
request = new CoopRequest(player);
target.getCoopRequests().put(player.getId(), request);
target.getCoopRequests().put(player.getUid(), request);
// Packet
target.sendPacket(new PacketPlayerApplyEnterMpNotify(player));
}
public void applyEnterMpReply(GenshinPlayer player, int applyUid, boolean isAgreed) {
public void applyEnterMpReply(GenshinPlayer hostPlayer, int applyUid, boolean isAgreed) {
// Checks
CoopRequest request = player.getCoopRequests().get(applyUid);
CoopRequest request = hostPlayer.getCoopRequests().get(applyUid);
if (request == null || request.isExpired()) {
return;
}
// Remove now that we are handling it
GenshinPlayer requester = request.getRequester();
player.getCoopRequests().remove(applyUid);
hostPlayer.getCoopRequests().remove(applyUid);
// Sanity checks - Dont let player join if already in multiplayer
// Sanity checks - Dont let the requesting player join if they are already in multiplayer
if (requester.getWorld().isMultiplayer()) {
request.getRequester().sendPacket(new PacketPlayerApplyEnterMpResultNotify(player, false, PlayerApplyEnterMpReason.PlayerCannotEnterMp));
request.getRequester().sendPacket(new PacketPlayerApplyEnterMpResultNotify(hostPlayer, false, PlayerApplyEnterMpReason.PlayerCannotEnterMp));
return;
}
// Response packet
request.getRequester().sendPacket(new PacketPlayerApplyEnterMpResultNotify(player, isAgreed, PlayerApplyEnterMpReason.PlayerJudge));
request.getRequester().sendPacket(new PacketPlayerApplyEnterMpResultNotify(hostPlayer, isAgreed, PlayerApplyEnterMpReason.PlayerJudge));
// Declined
if (!isAgreed) {
@ -82,24 +84,27 @@ public class MultiplayerManager {
}
// Success
if (!player.getWorld().isMultiplayer()) {
if (!hostPlayer.getWorld().isMultiplayer()) {
// Player not in multiplayer, create multiplayer world
World world = new World(player, true);
World world = new World(hostPlayer, true);
// Add
world.addPlayer(player);
world.addPlayer(hostPlayer);
// Rejoin packet
player.sendPacket(new PacketPlayerEnterSceneNotify(player, player, EnterType.EnterSelf, EnterReason.HostFromSingleToMp, player.getWorld().getSceneId(), player.getPos()));
hostPlayer.sendPacket(new PacketPlayerEnterSceneNotify(hostPlayer, hostPlayer, EnterType.EnterSelf, EnterReason.HostFromSingleToMp, hostPlayer.getScene().getId(), hostPlayer.getPos()));
}
// Make requester join
player.getWorld().addPlayer(requester);
// Set scene pos and id of requester to the host player's
requester.getPos().set(hostPlayer.getPos());
requester.getRotation().set(hostPlayer.getRotation());
requester.setSceneId(hostPlayer.getSceneId());
// Make requester join
hostPlayer.getWorld().addPlayer(requester);
// Packet
requester.sendPacket(new PacketPlayerEnterSceneNotify(requester, player, EnterType.EnterOther, EnterReason.TeamJoin, player.getWorld().getSceneId(), player.getPos()));
requester.getPos().set(player.getPos());
requester.getRotation().set(player.getRotation());
requester.sendPacket(new PacketPlayerEnterSceneNotify(requester, hostPlayer, EnterType.EnterOther, EnterReason.TeamJoin, hostPlayer.getScene().getId(), hostPlayer.getPos()));
}
public boolean leaveCoop(GenshinPlayer player) {
@ -120,7 +125,7 @@ public class MultiplayerManager {
world.addPlayer(player);
// Packet
player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterType.EnterSelf, EnterReason.TeamBack, player.getWorld().getSceneId(), player.getPos()));
player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterType.EnterSelf, EnterReason.TeamBack, player.getScene().getId(), player.getPos()));
return true;
}
@ -132,7 +137,7 @@ public class MultiplayerManager {
}
// Get victim and sanity checks
GenshinPlayer victim = player.getServer().getPlayerById(targetUid);
GenshinPlayer victim = player.getServer().getPlayerByUid(targetUid);
if (victim == null || victim == player) {
return false;
@ -147,7 +152,7 @@ public class MultiplayerManager {
World world = new World(victim);
world.addPlayer(victim);
victim.sendPacket(new PacketPlayerEnterSceneNotify(victim, EnterType.EnterSelf, EnterReason.TeamKick, victim.getWorld().getSceneId(), victim.getPos()));
victim.sendPacket(new PacketPlayerEnterSceneNotify(victim, EnterType.EnterSelf, EnterReason.TeamKick, victim.getScene().getId(), victim.getPos()));
return true;
}
}

View 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);
}
}

View File

@ -958,6 +958,7 @@ public class PacketOpcodes {
public static final int SceneTimeNotify = 229;
public static final int SceneTransToPointReq = 256;
public static final int SceneTransToPointRsp = 283;
public static final int SceneUnlockInfoNotify = 3386;
public static final int SceneWeatherForcastReq = 3167;
public static final int SceneWeatherForcastRsp = 3023;
public static final int SeaLampCoinNotify = 2028;

View File

@ -104,21 +104,25 @@ public final class GameServer extends MihoyoKcpServer {
}
public void registerPlayer(GenshinPlayer player) {
getPlayers().put(player.getId(), player);
getPlayers().put(player.getUid(), player);
}
public GenshinPlayer getPlayerById(int id) {
return this.getPlayers().get(id);
public GenshinPlayer getPlayerByUid(int id) {
return this.getPlayerByUid(id, false);
}
public GenshinPlayer forceGetPlayerById(int id) {
public GenshinPlayer getPlayerByUid(int id, boolean allowOfflinePlayers) {
// Console check
if (id == GenshinConstants.SERVER_CONSOLE_UID) {
return null;
}
// Get from online players
GenshinPlayer player = this.getPlayerById(id);
GenshinPlayer player = this.getPlayers().get(id);
if (!allowOfflinePlayers) {
return player;
}
// Check database if character isnt here
if (player == null) {
@ -128,9 +132,9 @@ public final class GameServer extends MihoyoKcpServer {
return player;
}
public SocialDetail.Builder getSocialDetailById(int id) {
public SocialDetail.Builder getSocialDetailByUid(int id) {
// Get from online players
GenshinPlayer player = this.forceGetPlayerById(id);
GenshinPlayer player = this.getPlayerByUid(id, true);
if (player == null) {
return null;

View File

@ -123,7 +123,7 @@ public class GameSession extends MihoyoKcpChannel {
// Save
getPlayer().onLogout();
// Remove from gameserver
getServer().getPlayers().remove(getPlayer().getId());
getServer().getPlayers().remove(getPlayer().getUid());
}
}

View File

@ -14,8 +14,8 @@ public class HandlerChangeGameTimeReq extends PacketHandler {
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
ChangeGameTimeReq req = ChangeGameTimeReq.parseFrom(payload);
session.getPlayer().getWorld().changeTime(req.getGameTime());
session.getPlayer().sendPacket(new PacketChangeGameTimeRsp(session.getPlayer().getWorld()));
session.getPlayer().getScene().changeTime(req.getGameTime());
session.getPlayer().sendPacket(new PacketChangeGameTimeRsp(session.getPlayer()));
}
}

View File

@ -22,12 +22,12 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
case CombatEvtBeingHit:
// Handle damage
EvtBeingHitInfo hitInfo = EvtBeingHitInfo.parseFrom(entry.getCombatData());
session.getPlayer().getWorld().handleAttack(hitInfo.getAttackResult());
session.getPlayer().getScene().handleAttack(hitInfo.getAttackResult());
break;
case EntityMove:
// Handle movement
EntityMoveInfo moveInfo = EntityMoveInfo.parseFrom(entry.getCombatData());
GenshinEntity entity = session.getPlayer().getWorld().getEntityById(moveInfo.getEntityId());
GenshinEntity entity = session.getPlayer().getScene().getEntityById(moveInfo.getEntityId());
if (entity != null) {
entity.getPosition().set(moveInfo.getMotionInfo().getPos());
entity.getRotation().set(moveInfo.getMotionInfo().getRot());

View File

@ -24,10 +24,10 @@ public class HandlerEnterSceneDoneReq extends PacketHandler {
session.send(new PacketPlayerTimeNotify(session.getPlayer())); // Probably not the right place
// Spawn player in world
session.getPlayer().getWorld().spawnPlayer(session.getPlayer());
session.getPlayer().getScene().spawnPlayer(session.getPlayer());
// Spawn other entites already in world
session.getPlayer().getWorld().showOtherEntities(session.getPlayer());
session.getPlayer().getScene().showOtherEntities(session.getPlayer());
// Locations
session.send(new PacketWorldPlayerLocationNotify(session.getPlayer().getWorld()));

View File

@ -15,7 +15,7 @@ public class HandlerEntityAiSyncNotify extends PacketHandler {
EntityAiSyncNotify notify = EntityAiSyncNotify.parseFrom(payload);
if (notify.getLocalAvatarAlertedMonsterListCount() > 0) {
session.getPlayer().getWorld().broadcastPacket(new PacketEntityAiSyncNotify(notify));
session.getPlayer().getScene().broadcastPacket(new PacketEntityAiSyncNotify(notify));
}
}

View File

@ -20,13 +20,13 @@ public class HandlerEvtCreateGadgetNotify extends PacketHandler {
}
// Sanity check - dont add duplicate entities
if (session.getPlayer().getWorld().getEntityById(notify.getEntityId()) != null) {
if (session.getPlayer().getScene().getEntityById(notify.getEntityId()) != null) {
return;
}
// Create entity and summon in world
EntityClientGadget gadget = new EntityClientGadget(session.getPlayer().getWorld(), session.getPlayer(), notify);
session.getPlayer().getWorld().onPlayerCreateGadget(gadget);
EntityClientGadget gadget = new EntityClientGadget(session.getPlayer().getScene(), session.getPlayer(), notify);
session.getPlayer().getScene().onPlayerCreateGadget(gadget);
}
}

View File

@ -18,7 +18,7 @@ public class HandlerEvtDestroyGadgetNotify extends PacketHandler {
return;
}
session.getPlayer().getWorld().onPlayerDestroyGadget(notify.getEntityId());
session.getPlayer().getScene().onPlayerDestroyGadget(notify.getEntityId());
}
}

View File

@ -15,7 +15,7 @@ public class HandlerGetPlayerSocialDetailReq extends PacketHandler {
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
GetPlayerSocialDetailReq req = GetPlayerSocialDetailReq.parseFrom(payload);
SocialDetail.Builder detail = session.getServer().getSocialDetailById(req.getUid());
SocialDetail.Builder detail = session.getServer().getSocialDetailByUid(req.getUid());
if (detail != null) {
detail.setIsFriend(session.getPlayer().getFriendsList().isFriendsWith(req.getUid()));

View File

@ -1,12 +1,16 @@
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.World;
import emu.grasscutter.game.props.EnterReason;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType;
import emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq;
import emu.grasscutter.net.proto.OperationOuterClass.Operation;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketPlayerEnterSceneNotify;
import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify;
@Opcodes(PacketOpcodes.MarkMapReq)
@ -19,14 +23,18 @@ public class HandlerMarkMapReq extends PacketHandler {
if (req.getOp() != Operation.Add) {
return;
}
session.getPlayer().getPos().setX(req.getMark().getPos().getX());
session.getPlayer().getPos().setZ(req.getMark().getPos().getZ());
session.getPlayer().getPos().setY(300);
Grasscutter.getLogger().info("Player [" + session.getPlayer().getId() + ":" + session.getPlayer().getNickname() + "] tp to " + session.getPlayer().getPos());
Grasscutter.getLogger().info("Player [" + session.getPlayer().getUid() + ":" + session.getPlayer().getNickname() + "] tp to " + session.getPlayer().getPos() + " Scene id: " + req.getMark().getSceneId());
session.getPlayer().getWorld().broadcastPacket(new PacketSceneEntityAppearNotify(session.getPlayer()));
if (req.getMark().getSceneId() != session.getPlayer().getSceneId()) {
session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), req.getMark().getSceneId(), session.getPlayer().getPos());
} else {
session.getPlayer().getScene().broadcastPacket(new PacketSceneEntityAppearNotify(session.getPlayer()));
}
}
}

View File

@ -14,6 +14,7 @@ import emu.grasscutter.server.packet.send.PacketSceneInitFinishRsp;
import emu.grasscutter.server.packet.send.PacketScenePlayerInfoNotify;
import emu.grasscutter.server.packet.send.PacketSceneTeamUpdateNotify;
import emu.grasscutter.server.packet.send.PacketSceneTimeNotify;
import emu.grasscutter.server.packet.send.PacketSceneUnlockInfoNotify;
import emu.grasscutter.server.packet.send.PacketServerTimeNotify;
import emu.grasscutter.server.packet.send.PacketSyncScenePlayTeamEntityNotify;
import emu.grasscutter.server.packet.send.PacketSyncTeamEntityNotify;
@ -29,13 +30,14 @@ public class HandlerSceneInitFinishReq extends PacketHandler {
session.send(new PacketServerTimeNotify());
session.send(new PacketWorldPlayerInfoNotify(session.getPlayer().getWorld()));
session.send(new PacketWorldDataNotify(session.getPlayer().getWorld()));
session.send(new PacketSceneUnlockInfoNotify());
session.send(new GenshinPacket(PacketOpcodes.SceneForceUnlockNotify));
session.send(new PacketHostPlayerNotify(session.getPlayer().getWorld()));
session.send(new PacketSceneTimeNotify(session.getPlayer()));
session.send(new PacketPlayerGameTimeNotify(session.getPlayer().getWorld(), session.getPlayer()));
session.send(new PacketPlayerGameTimeNotify(session.getPlayer()));
session.send(new PacketPlayerEnterSceneInfoNotify(session.getPlayer()));
session.send(new PacketSceneAreaWeatherNotify(session.getPlayer().getWorld(), session.getPlayer()));
session.send(new PacketSceneAreaWeatherNotify(session.getPlayer()));
session.send(new PacketScenePlayerInfoNotify(session.getPlayer().getWorld()));
session.send(new PacketSceneTeamUpdateNotify(session.getPlayer()));

View File

@ -57,7 +57,7 @@ public class HandlerSetPlayerBornDataReq extends PacketHandler {
}
// Save account
session.getAccount().setPlayerId(player.getId());
session.getAccount().setPlayerId(player.getUid());
session.getAccount().save();
// Set character

View File

@ -1,5 +1,6 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.World;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
@ -7,11 +8,11 @@ import emu.grasscutter.net.proto.ChangeGameTimeRspOuterClass.ChangeGameTimeRsp;
public class PacketChangeGameTimeRsp extends GenshinPacket {
public PacketChangeGameTimeRsp(World world) {
public PacketChangeGameTimeRsp(GenshinPlayer player) {
super(PacketOpcodes.ChangeGameTimeRsp);
ChangeGameTimeRsp proto = ChangeGameTimeRsp.newBuilder()
.setCurGameTime(world.getTime())
.setCurGameTime(player.getScene().getTime())
.build();
this.setData(proto);

View File

@ -14,7 +14,7 @@ public class PacketGetPlayerAskFriendListRsp extends GenshinPacket {
GetPlayerAskFriendListRsp.Builder proto = GetPlayerAskFriendListRsp.newBuilder();
for (Friendship friendship : player.getFriendsList().getPendingFriends().values()) {
if (friendship.getAskerId() == player.getId()) {
if (friendship.getAskerId() == player.getUid()) {
continue;
}
proto.addAskFriendList(friendship.toProto());

View File

@ -37,7 +37,7 @@ public class PacketGetPlayerFriendListRsp extends GenshinPacket {
proto.addFriendList(friendship.toProto());
}
for (Friendship friendship : player.getFriendsList().getPendingFriends().values()) {
if (friendship.getAskerId() == player.getId()) {
if (friendship.getAskerId() == player.getUid()) {
continue;
}
proto.addAskFriendList(friendship.toProto());

View File

@ -16,8 +16,8 @@ public class PacketGetSceneAreaRsp extends GenshinPacket {
this.buildHeader(0);
GetSceneAreaRsp p = GetSceneAreaRsp.newBuilder()
.setSceneId(3)
.addAllAreaIdList(Arrays.stream(new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19}).boxed().collect(Collectors.toList()))
.setSceneId(sceneId)
.addAllAreaIdList(Arrays.stream(new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19,100,101,102,103,200,210,300}).boxed().collect(Collectors.toList()))
.addCityInfoList(CityInfo.newBuilder().setCityId(1).setLevel(1).build())
.addCityInfoList(CityInfo.newBuilder().setCityId(2).setLevel(1).build())
.addCityInfoList(CityInfo.newBuilder().setCityId(3).setLevel(1).build())

View File

@ -11,7 +11,7 @@ public class PacketHostPlayerNotify extends GenshinPacket {
super(PacketOpcodes.HostPlayerNotify);
HostPlayerNotify proto = HostPlayerNotify.newBuilder()
.setHostUid(world.getHost().getId())
.setHostUid(world.getHost().getUid())
.setHostPeerId(world.getHost().getPeerId())
.build();

View File

@ -12,7 +12,7 @@ public class PacketPlayerApplyEnterMpResultNotify extends GenshinPacket {
super(PacketOpcodes.PlayerApplyEnterMpResultNotify);
PlayerApplyEnterMpResultNotify proto = PlayerApplyEnterMpResultNotify.newBuilder()
.setTargetUid(target.getId())
.setTargetUid(target.getUid())
.setTargetNickname(target.getNickname())
.setIsAgreed(isAgreed)
.setReason(reason)

View File

@ -14,7 +14,7 @@ public class PacketPlayerChatNotify extends GenshinPacket {
ChatInfo info = ChatInfo.newBuilder()
.setTime((int) (System.currentTimeMillis() / 1000))
.setUid(sender.getId())
.setUid(sender.getUid())
.setText(message)
.build();
@ -31,7 +31,7 @@ public class PacketPlayerChatNotify extends GenshinPacket {
ChatInfo info = ChatInfo.newBuilder()
.setTime((int) (System.currentTimeMillis() / 1000))
.setUid(sender.getId())
.setUid(sender.getUid())
.setIcon(emote)
.build();
@ -48,7 +48,7 @@ public class PacketPlayerChatNotify extends GenshinPacket {
ChatInfo info = ChatInfo.newBuilder()
.setTime((int) (System.currentTimeMillis() / 1000))
.setUid(sender.getId())
.setUid(sender.getUid())
.setSystemHint(systemHint)
.build();

View File

@ -24,17 +24,13 @@ public class PacketPlayerEnterSceneNotify extends GenshinPacket {
.setPos(player.getPos().toProto())
.setSceneBeginTime(System.currentTimeMillis())
.setType(EnterType.EnterSelf)
.setTargetUid(player.getId())
.setTargetUid(player.getUid())
.setEnterSceneToken(player.getEnterSceneToken())
.setWorldLevel(player.getWorldLevel())
.setEnterReason(EnterReason.Login.getValue())
.setIsFirstLoginEnterScene(player.isFirstLoginEnterScene())
.addSceneTagIdList(102)
.addSceneTagIdList(107)
.addSceneTagIdList(113)
.addSceneTagIdList(117)
.setUnk1(1)
.setUnk2("3-" + player.getId() + "-" + (int) (System.currentTimeMillis() / 1000) + "-" + 18402)
.setUnk2("3-" + player.getUid() + "-" + (int) (System.currentTimeMillis() / 1000) + "-" + 18402)
.build();
this.setData(proto);
@ -57,7 +53,7 @@ public class PacketPlayerEnterSceneNotify extends GenshinPacket {
.setPos(newPos.toProto())
.setSceneBeginTime(System.currentTimeMillis())
.setType(EnterType.EnterSelf)
.setTargetUid(target.getId())
.setTargetUid(target.getUid())
.setEnterSceneToken(player.getEnterSceneToken())
.setWorldLevel(target.getWorld().getWorldLevel())
.setEnterReason(reason.getValue())
@ -66,7 +62,7 @@ public class PacketPlayerEnterSceneNotify extends GenshinPacket {
.addSceneTagIdList(113)
.addSceneTagIdList(117)
.setUnk1(1)
.setUnk2(newScene + "-" + target.getId() + "-" + (int) (System.currentTimeMillis() / 1000) + "-" + 18402)
.setUnk2(newScene + "-" + target.getUid() + "-" + (int) (System.currentTimeMillis() / 1000) + "-" + 18402)
.build();
this.setData(proto);

View File

@ -8,12 +8,12 @@ import emu.grasscutter.net.proto.PlayerGameTimeNotifyOuterClass.PlayerGameTimeNo
public class PacketPlayerGameTimeNotify extends GenshinPacket {
public PacketPlayerGameTimeNotify(World world, GenshinPlayer player) {
public PacketPlayerGameTimeNotify(GenshinPlayer player) {
super(PacketOpcodes.PlayerGameTimeNotify);
PlayerGameTimeNotify proto = PlayerGameTimeNotify.newBuilder()
.setGameTime(world.getTime())
.setUid(player.getId())
.setGameTime(player.getScene().getTime())
.setUid(player.getUid())
.build();
this.setData(proto);

View File

@ -1,6 +1,7 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.net.packet.GenshinPacket;
@ -18,7 +19,7 @@ public class PacketPlayerStoreNotify extends GenshinPacket {
PlayerStoreNotify.Builder p = PlayerStoreNotify.newBuilder()
.setStoreType(StoreType.StorePack)
.setWeightLimit(GenshinConstants.LIMIT_ALL);
.setWeightLimit(Grasscutter.getConfig().getServerOptions().InventoryLimitAll);
for (GenshinItem item : player.getInventory()) {
Item itemProto = item.toProto();

View File

@ -21,7 +21,7 @@ public class PacketPullRecentChatRsp extends GenshinPacket {
ChatInfo welcomeEmote = ChatInfo.newBuilder()
.setTime((int) (System.currentTimeMillis() / 1000))
.setUid(GenshinConstants.SERVER_CONSOLE_UID)
.setToUid(player.getId())
.setToUid(player.getUid())
.setIcon(serverOptions.WelcomeEmotes[Utils.randomRange(0, serverOptions.WelcomeEmotes.length - 1)])
.build();
@ -32,7 +32,7 @@ public class PacketPullRecentChatRsp extends GenshinPacket {
ChatInfo welcomeMotd = ChatInfo.newBuilder()
.setTime((int) (System.currentTimeMillis() / 1000))
.setUid(GenshinConstants.SERVER_CONSOLE_UID)
.setToUid(player.getId())
.setToUid(player.getUid())
.setText(Grasscutter.getConfig().getServerOptions().WelcomeMotd)
.build();

View File

@ -8,12 +8,12 @@ import emu.grasscutter.net.proto.SceneAreaWeatherNotifyOuterClass.SceneAreaWeath
public class PacketSceneAreaWeatherNotify extends GenshinPacket {
public PacketSceneAreaWeatherNotify(World world, GenshinPlayer player) {
public PacketSceneAreaWeatherNotify(GenshinPlayer player) {
super(PacketOpcodes.SceneAreaWeatherNotify);
SceneAreaWeatherNotify proto = SceneAreaWeatherNotify.newBuilder()
.setWeatherAreaId(1)
.setClimateType(world.getClimate().getValue())
.setClimateType(player.getScene().getClimate().getValue())
.build();
this.setData(proto);

View File

@ -18,10 +18,10 @@ public class PacketScenePlayerInfoNotify extends GenshinPacket {
GenshinPlayer p = world.getPlayers().get(i);
ScenePlayerInfo pInfo = ScenePlayerInfo.newBuilder()
.setUid(p.getId())
.setUid(p.getUid())
.setPeerId(p.getPeerId())
.setName(p.getNickname())
.setSceneId(world.getSceneId())
.setSceneId(p.getSceneId())
.setOnlinePlayerInfo(p.getOnlinePlayerInfo())
.build();

View File

@ -19,7 +19,7 @@ public class PacketSceneTeamUpdateNotify extends GenshinPacket {
for (GenshinPlayer p : player.getWorld().getPlayers()) {
for (EntityAvatar entityAvatar : p.getTeamManager().getActiveTeam()) {
SceneTeamAvatar.Builder avatarProto = SceneTeamAvatar.newBuilder()
.setPlayerId(p.getId())
.setPlayerId(p.getUid())
.setAvatarGuid(entityAvatar.getAvatar().getGuid())
.setSceneId(p.getSceneId())
.setEntityId(entityAvatar.getId())

View File

@ -0,0 +1,24 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SceneUnlockInfoNotifyOuterClass.SceneUnlockInfoNotify;
import emu.grasscutter.net.proto.SceneUnlockInfoOuterClass.SceneUnlockInfo;
public class PacketSceneUnlockInfoNotify extends GenshinPacket {
public PacketSceneUnlockInfoNotify() {
super(PacketOpcodes.SceneUnlockInfoNotify); // Rename opcode later
SceneUnlockInfoNotify proto = SceneUnlockInfoNotify.newBuilder()
.addUnlockInfos(SceneUnlockInfo.newBuilder().setSceneId(1))
.addUnlockInfos(SceneUnlockInfo.newBuilder().setSceneId(3))
.addUnlockInfos(SceneUnlockInfo.newBuilder().setSceneId(4))
.addUnlockInfos(SceneUnlockInfo.newBuilder().setSceneId(5))
.addUnlockInfos(SceneUnlockInfo.newBuilder().setSceneId(6))
.addUnlockInfos(SceneUnlockInfo.newBuilder().setSceneId(7))
.build();
this.setData(proto);
}
}

View File

@ -1,6 +1,6 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.StoreTypeOuterClass.StoreType;
@ -13,11 +13,11 @@ public class PacketStoreWeightLimitNotify extends GenshinPacket {
StoreWeightLimitNotify p = StoreWeightLimitNotify.newBuilder()
.setStoreType(StoreType.StorePack)
.setWeightLimit(GenshinConstants.LIMIT_ALL)
.setWeaponCountLimit(GenshinConstants.LIMIT_WEAPON)
.setReliquaryCountLimit(GenshinConstants.LIMIT_RELIC)
.setMaterialCountLimit(GenshinConstants.LIMIT_MATERIAL)
.setFurnitureCountLimit(GenshinConstants.LIMIT_FURNITURE)
.setWeightLimit(Grasscutter.getConfig().getServerOptions().InventoryLimitAll)
.setWeaponCountLimit(Grasscutter.getConfig().getServerOptions().InventoryLimitWeapon)
.setReliquaryCountLimit(Grasscutter.getConfig().getServerOptions().InventoryLimitRelic)
.setMaterialCountLimit(Grasscutter.getConfig().getServerOptions().InventoryLimitMaterial)
.setFurnitureCountLimit(Grasscutter.getConfig().getServerOptions().InventoryLimitFurniture)
.build();
this.setData(p);

View File

@ -17,7 +17,7 @@ public class PacketWorldPlayerInfoNotify extends GenshinPacket {
GenshinPlayer p = world.getPlayers().get(i);
proto.addPlayerInfoList(p.getOnlinePlayerInfo());
proto.addPlayerUidList(p.getId());
proto.addPlayerUidList(p.getUid());
}
this.setData(proto.build());

View File

@ -17,7 +17,7 @@ public class PacketWorldPlayerRTTNotify extends GenshinPacket {
for (GenshinPlayer player : world.getPlayers()) {
proto.addPlayerRttList(
PlayerRTTInfo.newBuilder()
.setUid(player.getId())
.setUid(player.getUid())
.setRtt(10) // TODO - put player ping here
);
}

View File

@ -20,6 +20,7 @@ import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.data.def.SceneData;
public final class Tools {
@ -63,6 +64,17 @@ public final class Tools {
writer.println();
writer.println("// Scenes");
list = new ArrayList<>(GenshinData.getSceneDataMap().keySet());
Collections.sort(list);
for (Integer id : list) {
SceneData data = GenshinData.getSceneDataMap().get(id);
writer.println(data.getId() + " : " + data.getScriptData());
}
writer.println();
writer.println("// Monsters");
list = new ArrayList<>(GenshinData.getMonsterDataMap().keySet());
Collections.sort(list);

View File

@ -165,8 +165,6 @@ public final class Utils {
// Check for game data.
if(!fileExists(dataFolder))
createFolder(dataFolder);
if(!fileExists(dataFolder + "AbilityEmbryos.json"))
copyFromResources("data/AbilityEmbryos.json", dataFolder);
if(exit) System.exit(1);
}