mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-15 14:54:43 +01:00
Chests can now be opened
This commit is contained in:
@@ -22,10 +22,12 @@ import emu.lunarcore.game.avatar.HeroPath;
|
|||||||
import emu.lunarcore.game.battle.Battle;
|
import emu.lunarcore.game.battle.Battle;
|
||||||
import emu.lunarcore.game.chat.ChatManager;
|
import emu.lunarcore.game.chat.ChatManager;
|
||||||
import emu.lunarcore.game.chat.ChatMessage;
|
import emu.lunarcore.game.chat.ChatMessage;
|
||||||
|
import emu.lunarcore.game.enums.PropState;
|
||||||
import emu.lunarcore.game.gacha.PlayerGachaInfo;
|
import emu.lunarcore.game.gacha.PlayerGachaInfo;
|
||||||
import emu.lunarcore.game.inventory.Inventory;
|
import emu.lunarcore.game.inventory.Inventory;
|
||||||
import emu.lunarcore.game.scene.Scene;
|
import emu.lunarcore.game.scene.Scene;
|
||||||
import emu.lunarcore.game.scene.entity.EntityProp;
|
import emu.lunarcore.game.scene.entity.EntityProp;
|
||||||
|
import emu.lunarcore.game.scene.entity.GameEntity;
|
||||||
import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync;
|
import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync;
|
||||||
import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon;
|
import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon;
|
||||||
import emu.lunarcore.proto.PlayerBasicInfoOuterClass.PlayerBasicInfo;
|
import emu.lunarcore.proto.PlayerBasicInfoOuterClass.PlayerBasicInfo;
|
||||||
@@ -35,7 +37,6 @@ import emu.lunarcore.server.packet.BasePacket;
|
|||||||
import emu.lunarcore.server.packet.SessionState;
|
import emu.lunarcore.server.packet.SessionState;
|
||||||
import emu.lunarcore.server.packet.send.PacketEnterSceneByServerScNotify;
|
import emu.lunarcore.server.packet.send.PacketEnterSceneByServerScNotify;
|
||||||
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
||||||
import emu.lunarcore.server.packet.send.PacketRevcMsgScNotify;
|
|
||||||
import emu.lunarcore.server.packet.send.PacketSceneEntityMoveScNotify;
|
import emu.lunarcore.server.packet.send.PacketSceneEntityMoveScNotify;
|
||||||
import emu.lunarcore.util.Position;
|
import emu.lunarcore.util.Position;
|
||||||
|
|
||||||
@@ -321,11 +322,39 @@ public class Player {
|
|||||||
this.battle = battle;
|
this.battle = battle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityProp interactWithProp(int propEntityId) {
|
||||||
|
// Sanity
|
||||||
|
if (this.getScene() == null) return null;
|
||||||
|
|
||||||
|
// Get entity so we can cast it to a prop
|
||||||
|
GameEntity entity = getScene().getEntityById(propEntityId);
|
||||||
|
|
||||||
|
EntityProp prop = null;
|
||||||
|
if (entity instanceof EntityProp) {
|
||||||
|
prop = (EntityProp) entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle prop interaction action
|
||||||
|
switch (prop.getExcel().getPropType()) {
|
||||||
|
case PROP_TREASURE_CHEST -> {
|
||||||
|
if (prop.getState() == PropState.ChestClosed) {
|
||||||
|
// Open chest
|
||||||
|
prop.setState(PropState.ChestUsed);
|
||||||
|
// TODO handle drops
|
||||||
|
return prop;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void onMove() {
|
public void onMove() {
|
||||||
// Sanity
|
// Sanity
|
||||||
if (this.getScene() == null) {
|
if (this.getScene() == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean anchorRange = false;
|
boolean anchorRange = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,23 @@
|
|||||||
package emu.lunarcore.server.packet.recv;
|
package emu.lunarcore.server.packet.recv;
|
||||||
|
|
||||||
|
import emu.lunarcore.game.scene.entity.EntityProp;
|
||||||
|
import emu.lunarcore.proto.InteractPropCsReqOuterClass.InteractPropCsReq;
|
||||||
import emu.lunarcore.server.game.GameSession;
|
import emu.lunarcore.server.game.GameSession;
|
||||||
import emu.lunarcore.server.packet.CmdId;
|
import emu.lunarcore.server.packet.CmdId;
|
||||||
import emu.lunarcore.server.packet.Opcodes;
|
import emu.lunarcore.server.packet.Opcodes;
|
||||||
import emu.lunarcore.server.packet.PacketHandler;
|
import emu.lunarcore.server.packet.PacketHandler;
|
||||||
|
import emu.lunarcore.server.packet.send.PacketInteractPropScRsp;
|
||||||
|
|
||||||
@Opcodes(CmdId.InteractPropCsReq)
|
@Opcodes(CmdId.InteractPropCsReq)
|
||||||
public class HandlerInteractPropCsReq extends PacketHandler {
|
public class HandlerInteractPropCsReq extends PacketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||||
// TODO implement properly
|
var req = InteractPropCsReq.parseFrom(data);
|
||||||
session.send(CmdId.InteractPropScRsp);
|
|
||||||
|
EntityProp prop = session.getPlayer().interactWithProp(req.getPropEntityId());
|
||||||
|
|
||||||
|
session.send(new PacketInteractPropScRsp(prop));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package emu.lunarcore.server.packet.send;
|
||||||
|
|
||||||
|
import emu.lunarcore.game.scene.entity.EntityProp;
|
||||||
|
import emu.lunarcore.proto.InteractPropScRspOuterClass.InteractPropScRsp;
|
||||||
|
import emu.lunarcore.server.packet.BasePacket;
|
||||||
|
import emu.lunarcore.server.packet.CmdId;
|
||||||
|
|
||||||
|
public class PacketInteractPropScRsp extends BasePacket {
|
||||||
|
|
||||||
|
public PacketInteractPropScRsp(EntityProp prop) {
|
||||||
|
super(CmdId.InteractPropScRsp);
|
||||||
|
|
||||||
|
var data = InteractPropScRsp.newInstance();
|
||||||
|
|
||||||
|
if (prop != null) {
|
||||||
|
data.setPropEntityId(prop.getEntityId());
|
||||||
|
data.setPropState(prop.getState().getVal());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setData(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user