Add & implement EntityMoveEvent

This commit is contained in:
KingRainbow44 2022-06-24 01:21:41 -04:00
parent 13c2037899
commit a5620e4632
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,31 @@
package emu.grasscutter.server.event.entity;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState;
import emu.grasscutter.server.event.types.EntityEvent;
import emu.grasscutter.utils.Position;
public final class EntityMoveEvent extends EntityEvent {
private final Position position, rotation;
private final MotionState motionState;
public EntityMoveEvent(GameEntity entity, Position position, Position rotation, MotionState motionState) {
super(entity);
this.position = position;
this.rotation = rotation;
this.motionState = motionState;
}
public Position getPosition() {
return this.position;
}
public Position getRotation() {
return this.rotation;
}
public MotionState getMotionState() {
return this.motionState;
}
}

View File

@ -13,8 +13,11 @@ import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo;
import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState;
import emu.grasscutter.net.proto.PlayerDieTypeOuterClass;
import emu.grasscutter.server.event.entity.EntityMoveEvent;
import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import emu.grasscutter.utils.Position;
@Opcodes(PacketOpcodes.CombatInvocationsNotify)
public class HandlerCombatInvocationsNotify extends PacketHandler {
@ -41,11 +44,18 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
if (entity != null) {
// Move player
MotionInfo motionInfo = moveInfo.getMotionInfo();
MotionState motionState = motionInfo.getState();
// Call entity move event.
EntityMoveEvent event = new EntityMoveEvent(
entity, new Position(motionInfo.getPos()),
new Position(motionInfo.getRot()), motionState);
event.call();
entity.getPosition().set(motionInfo.getPos());
entity.getRotation().set(motionInfo.getRot());
entity.setLastMoveSceneTimeMs(moveInfo.getSceneTime());
entity.setLastMoveReliableSeq(moveInfo.getReliableSeq());
MotionState motionState = motionInfo.getState();
entity.setMotionState(motionState);
session.getPlayer().getStaminaManager().handleCombatInvocationsNotify(session, moveInfo, entity);