mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 05:44:36 +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.chat.ChatManager;
|
||||
import emu.lunarcore.game.chat.ChatMessage;
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.gacha.PlayerGachaInfo;
|
||||
import emu.lunarcore.game.inventory.Inventory;
|
||||
import emu.lunarcore.game.scene.Scene;
|
||||
import emu.lunarcore.game.scene.entity.EntityProp;
|
||||
import emu.lunarcore.game.scene.entity.GameEntity;
|
||||
import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync;
|
||||
import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon;
|
||||
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.send.PacketEnterSceneByServerScNotify;
|
||||
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
||||
import emu.lunarcore.server.packet.send.PacketRevcMsgScNotify;
|
||||
import emu.lunarcore.server.packet.send.PacketSceneEntityMoveScNotify;
|
||||
import emu.lunarcore.util.Position;
|
||||
|
||||
@@ -321,11 +322,39 @@ public class Player {
|
||||
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() {
|
||||
// Sanity
|
||||
if (this.getScene() == null) {
|
||||
return;
|
||||
}
|
||||
if (this.getScene() == null) return;
|
||||
|
||||
boolean anchorRange = false;
|
||||
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
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.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
import emu.lunarcore.server.packet.send.PacketInteractPropScRsp;
|
||||
|
||||
@Opcodes(CmdId.InteractPropCsReq)
|
||||
public class HandlerInteractPropCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||
// TODO implement properly
|
||||
session.send(CmdId.InteractPropScRsp);
|
||||
var req = InteractPropCsReq.parseFrom(data);
|
||||
|
||||
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