Commit 4db1724d authored by KingRainbow44's avatar KingRainbow44
Browse files

Merge branch 'development' into api

# Conflicts:
#	src/main/java/emu/grasscutter/Grasscutter.java
parents d359e511 92b1ba7a
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.dungeons.DungeonChallenge;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DungeonChallengeFinishNotifyOuterClass.DungeonChallengeFinishNotify;
public class PacketDungeonChallengeFinishNotify extends BasePacket {
public PacketDungeonChallengeFinishNotify(DungeonChallenge challenge) {
super(PacketOpcodes.DungeonChallengeFinishNotify);
DungeonChallengeFinishNotify proto = DungeonChallengeFinishNotify.newBuilder()
.setChallengeIndex(challenge.getChallengeIndex())
.setIsSuccess(challenge.isSuccess())
.setUnk1(challenge.getChallengeId())
.setUnk2(30)
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import java.util.Arrays;
import emu.grasscutter.data.common.PointData;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.DungeonEntryInfoOuterClass.DungeonEntryInfo;
import emu.grasscutter.net.proto.DungeonEntryInfoRspOuterClass.DungeonEntryInfoRsp;
public class PacketDungeonEntryInfoRsp extends BasePacket {
public PacketDungeonEntryInfoRsp(Player player, PointData pointData) {
super(PacketOpcodes.DungeonEntryInfoRsp);
DungeonEntryInfoRsp.Builder proto = DungeonEntryInfoRsp.newBuilder()
.setPointId(pointData.getId());
for (int dungeonId : pointData.getDungeonIds()) {
DungeonEntryInfo info = DungeonEntryInfo.newBuilder().setDungeonId(dungeonId).build();
proto.addDungeonEntryList(info);
}
this.setData(proto);
}
public PacketDungeonEntryInfoRsp() {
super(PacketOpcodes.DungeonEntryInfoRsp);
DungeonEntryInfoRsp proto = DungeonEntryInfoRsp.newBuilder()
.setRetcode(1)
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.EvtAvatarLockChairReqOuterClass.EvtAvatarLockChairReq;
import emu.grasscutter.net.proto.EvtAvatarLockChairRspOuterClass.EvtAvatarLockChairRsp;
import emu.grasscutter.net.proto.RetcodeOuterClass;
public class PacketEvtAvatarLockChairRsp extends BasePacket {
public PacketEvtAvatarLockChairRsp(int clientSequence, EntityAvatar entityAvatar, EvtAvatarLockChairReq lockChairReq) {
super(PacketOpcodes.EvtAvatarLockChairRsp);
EvtAvatarLockChairRsp p = EvtAvatarLockChairRsp.newBuilder()
.setRetcode(RetcodeOuterClass.Retcode.RET_SUCC_VALUE)
.setEntityId(entityAvatar.getId())
.setPosition(lockChairReq.getPosition())
.setChairId(lockChairReq.getChairId())
.build();
this.setData(p);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.EvtAvatarStandUpNotifyOuterClass.EvtAvatarStandUpNotify;
public class PacketEvtAvatarStandUpNotify extends BasePacket {
public PacketEvtAvatarStandUpNotify(EvtAvatarStandUpNotify notify) {
super(PacketOpcodes.EvtAvatarStandUpNotify);
EvtAvatarStandUpNotify proto = EvtAvatarStandUpNotify.newBuilder()
.setEntityId(notify.getEntityId())
.setDirection(notify.getDirection())
.setPerformID(notify.getPerformID())
.setChairId(notify.getChairId())
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.entity.EntityGadget; import emu.grasscutter.game.entity.EntityBaseGadget;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GadgetInteractRspOuterClass.GadgetInteractRsp; import emu.grasscutter.net.proto.GadgetInteractRspOuterClass.GadgetInteractRsp;
...@@ -8,7 +8,7 @@ import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType; ...@@ -8,7 +8,7 @@ import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType;
import emu.grasscutter.net.proto.RetcodeOuterClass; import emu.grasscutter.net.proto.RetcodeOuterClass;
public class PacketGadgetInteractRsp extends BasePacket { public class PacketGadgetInteractRsp extends BasePacket {
public PacketGadgetInteractRsp(EntityGadget gadget, InteractType interact) { public PacketGadgetInteractRsp(EntityBaseGadget gadget, InteractType interact) {
super(PacketOpcodes.GadgetInteractRsp); super(PacketOpcodes.GadgetInteractRsp);
GadgetInteractRsp proto = GadgetInteractRsp.newBuilder() GadgetInteractRsp proto = GadgetInteractRsp.newBuilder()
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GadgetStateNotifyOuterClass.GadgetStateNotify;
public class PacketGadgetStateNotify extends BasePacket {
public PacketGadgetStateNotify(EntityGadget gadget, int newState) {
super(PacketOpcodes.GadgetStateNotify);
GadgetStateNotify proto = GadgetStateNotify.newBuilder()
.setGadgetEntityId(gadget.getId())
.setGadgetState(newState)
.setIsEnableInteract(true)
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GetOnlinePlayerListReqOuterClass;
import emu.grasscutter.net.proto.GetOnlinePlayerListRspOuterClass.*;
import emu.grasscutter.net.proto.MpSettingTypeOuterClass;
import emu.grasscutter.net.proto.OnlinePlayerInfoOuterClass.OnlinePlayerInfo;
import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class PacketGetOnlinePlayerListRsp extends BasePacket {
public PacketGetOnlinePlayerListRsp(Player session){
super(PacketOpcodes.GetOnlinePlayerListRsp);
Map<Integer, Player> playersMap = Grasscutter.getGameServer().getPlayers();
GetOnlinePlayerListRsp.Builder proto = GetOnlinePlayerListRsp.newBuilder();
if(playersMap.size() != 0){
List<OnlinePlayerInfo> playerInfoList = new ArrayList<>();
for(Player player:playersMap.values()){
ProfilePicture.Builder picture = ProfilePicture.newBuilder();
OnlinePlayerInfo.Builder playerInfo = OnlinePlayerInfo.newBuilder();
if(player.getUid() == session.getUid())continue;
picture.setAvatarId(player.getProfile().getAvatarId())
.build();
System.out.println(player.getHeadImage());
playerInfo.setUid(player.getUid())
.setNickname(player.getNickname())
.setPlayerLevel(player.getLevel())
.setMpSettingType(MpSettingTypeOuterClass.MpSettingType.MP_SETTING_ENTER_AFTER_APPLY)
.setCurPlayerNumInWorld(player.getWorld().getPlayerCount())
.setWorldLevel(player.getWorldLevel())
.setNameCardId(player.getNameCardId())
.setProfilePicture(picture);
if(!Objects.equals(player.getSignature(), "")){
playerInfo.setSignature(player.getSignature());
}
playerInfoList.add(playerInfo.build());
}
for (OnlinePlayerInfo onlinePlayerInfo : playerInfoList) {
proto.addPlayerInfoList(onlinePlayerInfo).build();
}
}
this.setData(proto);
}
}
...@@ -7,7 +7,5 @@ public class PacketPathfindingEnterSceneRsp extends BasePacket { ...@@ -7,7 +7,5 @@ public class PacketPathfindingEnterSceneRsp extends BasePacket {
public PacketPathfindingEnterSceneRsp(int clientSequence) { public PacketPathfindingEnterSceneRsp(int clientSequence) {
super(PacketOpcodes.PathfindingEnterSceneRsp); super(PacketOpcodes.PathfindingEnterSceneRsp);
this.buildHeader(clientSequence);
} }
} }
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.PlayerEnterDungeonRspOuterClass.PlayerEnterDungeonRsp;
public class PacketPlayerEnterDungeonRsp extends BasePacket {
public PacketPlayerEnterDungeonRsp(int pointId, int dungeonId) {
super(PacketOpcodes.PlayerEnterDungeonRsp);
PlayerEnterDungeonRsp proto = PlayerEnterDungeonRsp.newBuilder()
.setPointId(pointId)
.setDungeonId(dungeonId)
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SelectWorktopOptionRspOuterClass.SelectWorktopOptionRsp;
public class PacketSelectWorktopOptionRsp extends BasePacket {
public PacketSelectWorktopOptionRsp(int entityId, int optionId) {
super(PacketOpcodes.SelectWorktopOptionRsp);
SelectWorktopOptionRsp proto = SelectWorktopOptionRsp.newBuilder()
.setGadgetEntityId(entityId)
.setOptionId(optionId)
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.entity.EntityVehicle;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.entity.GameEntity; import emu.grasscutter.game.entity.GameEntity;
...@@ -17,16 +18,49 @@ public class PacketVehicleInteractRsp extends BasePacket { ...@@ -17,16 +18,49 @@ public class PacketVehicleInteractRsp extends BasePacket {
VehicleInteractRsp.Builder proto = VehicleInteractRsp.newBuilder(); VehicleInteractRsp.Builder proto = VehicleInteractRsp.newBuilder();
GameEntity vehicle = player.getScene().getEntityById(entityId); GameEntity vehicle = player.getScene().getEntityById(entityId);
if(vehicle != null) {
if(vehicle instanceof EntityVehicle) {
proto.setEntityId(vehicle.getId()); proto.setEntityId(vehicle.getId());
proto.setInteractType(interactType);
VehicleMember vehicleMember = VehicleMember.newBuilder() VehicleMember vehicleMember = VehicleMember.newBuilder()
.setUid(player.getUid()) .setUid(player.getUid())
.setAvatarGuid(player.getTeamManager().getCurrentCharacterGuid()) .setAvatarGuid(player.getTeamManager().getCurrentCharacterGuid())
.build(); .build();
proto.setInteractType(interactType);
proto.setMember(vehicleMember); proto.setMember(vehicleMember);
switch(interactType){
case VEHICLE_INTERACT_IN -> {
((EntityVehicle) vehicle).getVehicleMembers().add(vehicleMember);
}
case VEHICLE_INTERACT_OUT -> {
((EntityVehicle) vehicle).getVehicleMembers().remove(vehicleMember);
}
default -> {}
}
}
this.setData(proto.build());
}
public PacketVehicleInteractRsp(EntityVehicle vehicle, VehicleMember vehicleMember, VehicleInteractType interactType) {
super(PacketOpcodes.VehicleInteractRsp);
VehicleInteractRsp.Builder proto = VehicleInteractRsp.newBuilder();
if(vehicle != null) {
proto.setEntityId(vehicle.getId());
proto.setInteractType(interactType);
proto.setMember(vehicleMember);
switch(interactType){
case VEHICLE_INTERACT_IN -> {
vehicle.getVehicleMembers().add(vehicleMember);
}
case VEHICLE_INTERACT_OUT -> {
vehicle.getVehicleMembers().remove(vehicleMember);
}
default -> {}
}
} }
this.setData(proto.build()); this.setData(proto.build());
} }
......
...@@ -8,10 +8,16 @@ import emu.grasscutter.game.entity.GameEntity; ...@@ -8,10 +8,16 @@ import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.VehicleMemberOuterClass.VehicleMember;
import emu.grasscutter.net.proto.VehicleSpawnRspOuterClass.VehicleSpawnRsp; import emu.grasscutter.net.proto.VehicleSpawnRspOuterClass.VehicleSpawnRsp;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import java.util.List;
import static emu.grasscutter.net.proto.VehicleInteractTypeOuterClass.VehicleInteractType.VEHICLE_INTERACT_OUT;
public class PacketVehicleSpawnRsp extends BasePacket { public class PacketVehicleSpawnRsp extends BasePacket {
...@@ -19,6 +25,23 @@ public class PacketVehicleSpawnRsp extends BasePacket { ...@@ -19,6 +25,23 @@ public class PacketVehicleSpawnRsp extends BasePacket {
super(PacketOpcodes.VehicleSpawnRsp); super(PacketOpcodes.VehicleSpawnRsp);
VehicleSpawnRsp.Builder proto = VehicleSpawnRsp.newBuilder(); VehicleSpawnRsp.Builder proto = VehicleSpawnRsp.newBuilder();
// Eject vehicle members and Kill previous vehicles if there are any
List<GameEntity> previousVehicles = player.getScene().getEntities().values().stream()
.filter(entity -> entity instanceof EntityVehicle
&& ((EntityVehicle) entity).getGadgetId() == vehicleId
&& ((EntityVehicle) entity).getOwner().equals(player))
.toList();
previousVehicles.stream().forEach(entity -> {
List<VehicleMember> vehicleMembers = ((EntityVehicle) entity).getVehicleMembers().stream().toList();
vehicleMembers.stream().forEach(vehicleMember -> {
player.getScene().broadcastPacket(new PacketVehicleInteractRsp(((EntityVehicle) entity), vehicleMember, VEHICLE_INTERACT_OUT));
});
player.getScene().killEntity(entity, 0);
});
EntityVehicle vehicle = new EntityVehicle(player.getScene(), player, vehicleId, pointId, pos, rot); EntityVehicle vehicle = new EntityVehicle(player.getScene(), player, vehicleId, pointId, pos, rot);
switch (vehicleId) { switch (vehicleId) {
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WorktopOptionNotifyOuterClass.WorktopOptionNotify;
public class PacketWorktopOptionNotify extends BasePacket {
public PacketWorktopOptionNotify(EntityGadget gadget) {
super(PacketOpcodes.WorktopOptionNotify);
WorktopOptionNotify.Builder proto = WorktopOptionNotify.newBuilder()
.setGadgetEntityId(gadget.getId());
if (gadget.getWorktopOptions() != null) {
proto.addAllOptionList(gadget.getWorktopOptions());
}
this.setData(proto);
}
}
...@@ -67,6 +67,7 @@ public final class Utils { ...@@ -67,6 +67,7 @@ public final class Utils {
private static final char[] HEX_ARRAY = "0123456789abcdef".toCharArray(); private static final char[] HEX_ARRAY = "0123456789abcdef".toCharArray();
public static String bytesToHex(byte[] bytes) { public static String bytesToHex(byte[] bytes) {
if (bytes == null) return "";
char[] hexChars = new char[bytes.length * 2]; char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) { for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF; int v = bytes[j] & 0xFF;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment