Implement PlayerMoveEvent

This commit is contained in:
KingRainbow44 2022-07-15 12:43:49 -04:00
parent aa31851e77
commit 80e75fd023
3 changed files with 147 additions and 71 deletions

View File

@ -30,6 +30,7 @@ import emu.grasscutter.net.proto.SceneAvatarInfoOuterClass.SceneAvatarInfo;
import emu.grasscutter.net.proto.SceneEntityAiInfoOuterClass.SceneEntityAiInfo; import emu.grasscutter.net.proto.SceneEntityAiInfoOuterClass.SceneEntityAiInfo;
import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo; import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
import emu.grasscutter.net.proto.VectorOuterClass.Vector; import emu.grasscutter.net.proto.VectorOuterClass.Vector;
import emu.grasscutter.server.event.player.PlayerMoveEvent;
import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketEntityFightPropChangeReasonNotify; import emu.grasscutter.server.packet.send.PacketEntityFightPropChangeReasonNotify;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
@ -41,22 +42,22 @@ import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
public class EntityAvatar extends GameEntity { public class EntityAvatar extends GameEntity {
private final Avatar avatar; private final Avatar avatar;
private PlayerDieType killedType; private PlayerDieType killedType;
private int killedBy; private int killedBy;
public EntityAvatar(Scene scene, Avatar avatar) { public EntityAvatar(Scene scene, Avatar avatar) {
super(scene); super(scene);
this.avatar = avatar; this.avatar = avatar;
this.avatar.setCurrentEnergy(); this.avatar.setCurrentEnergy();
this.id = getScene().getWorld().getNextEntityId(EntityIdType.AVATAR); this.id = getScene().getWorld().getNextEntityId(EntityIdType.AVATAR);
GameItem weapon = this.getAvatar().getWeapon(); GameItem weapon = this.getAvatar().getWeapon();
if (weapon != null) { if (weapon != null) {
weapon.setWeaponEntityId(getScene().getWorld().getNextEntityId(EntityIdType.WEAPON)); weapon.setWeaponEntityId(getScene().getWorld().getNextEntityId(EntityIdType.WEAPON));
} }
} }
public EntityAvatar(Avatar avatar) { public EntityAvatar(Avatar avatar) {
super(null); super(null);
this.avatar = avatar; this.avatar = avatar;
@ -71,7 +72,7 @@ public class EntityAvatar extends GameEntity {
public Position getPosition() { public Position getPosition() {
return getPlayer().getPos(); return getPlayer().getPos();
} }
@Override @Override
public Position getRotation() { public Position getRotation() {
return getPlayer().getRotation(); return getPlayer().getRotation();
@ -80,11 +81,11 @@ public class EntityAvatar extends GameEntity {
public Avatar getAvatar() { public Avatar getAvatar() {
return avatar; return avatar;
} }
public int getKilledBy() { public int getKilledBy() {
return killedBy; return killedBy;
} }
public PlayerDieType getKilledType() { public PlayerDieType getKilledType() {
return killedType; return killedType;
} }
@ -93,12 +94,12 @@ public class EntityAvatar extends GameEntity {
public boolean isAlive() { public boolean isAlive() {
return this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) > 0f; return this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) > 0f;
} }
@Override @Override
public Int2FloatOpenHashMap getFightProperties() { public Int2FloatOpenHashMap getFightProperties() {
return getAvatar().getFightProperties(); return getAvatar().getFightProperties();
} }
public int getWeaponEntityId() { public int getWeaponEntityId() {
if (getAvatar().getWeapon() != null) { if (getAvatar().getWeapon() != null) {
return getAvatar().getWeapon().getWeaponEntityId(); return getAvatar().getWeapon().getWeaponEntityId();
@ -118,20 +119,20 @@ public class EntityAvatar extends GameEntity {
this.killedBy = killerId; this.killedBy = killerId;
clearEnergy(ChangeEnergyReason.CHANGE_ENERGY_REASON_NONE); clearEnergy(ChangeEnergyReason.CHANGE_ENERGY_REASON_NONE);
} }
@Override @Override
public float heal(float amount) { public float heal(float amount) {
float healed = super.heal(amount); float healed = super.heal(amount);
if (healed > 0f) { if (healed > 0f) {
getScene().broadcastPacket( getScene().broadcastPacket(
new PacketEntityFightPropChangeReasonNotify(this, FightProperty.FIGHT_PROP_CUR_HP, healed, PropChangeReason.PROP_CHANGE_REASON_ABILITY, ChangeHpReason.CHANGE_HP_REASON_CHANGE_HP_ADD_ABILITY) new PacketEntityFightPropChangeReasonNotify(this, FightProperty.FIGHT_PROP_CUR_HP, healed, PropChangeReason.PROP_CHANGE_REASON_ABILITY, ChangeHpReason.CHANGE_HP_REASON_CHANGE_HP_ADD_ABILITY)
); );
} }
return healed; return healed;
} }
public void clearEnergy(ChangeEnergyReason reason) { public void clearEnergy(ChangeEnergyReason reason) {
// Fight props. // Fight props.
FightProperty curEnergyProp = this.getAvatar().getSkillDepot().getElementType().getCurEnergyProp(); FightProperty curEnergyProp = this.getAvatar().getSkillDepot().getElementType().getCurEnergyProp();
@ -150,7 +151,7 @@ public class EntityAvatar extends GameEntity {
this.getScene().broadcastPacket(new PacketEntityFightPropChangeReasonNotify(this, curEnergyProp, -maxEnergy, reason)); this.getScene().broadcastPacket(new PacketEntityFightPropChangeReasonNotify(this, curEnergyProp, -maxEnergy, reason));
} }
} }
public void addEnergy(float amount, PropChangeReason reason) { public void addEnergy(float amount, PropChangeReason reason) {
this.addEnergy(amount, reason, false); this.addEnergy(amount, reason, false);
} }
@ -161,7 +162,7 @@ public class EntityAvatar extends GameEntity {
float curEnergy = this.getFightProperty(curEnergyProp); float curEnergy = this.getFightProperty(curEnergyProp);
float maxEnergy = this.getFightProperty(maxEnergyProp); float maxEnergy = this.getFightProperty(maxEnergyProp);
// Get energy recharge. // Get energy recharge.
float energyRecharge = this.getFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY); float energyRecharge = this.getFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY);
@ -172,16 +173,16 @@ public class EntityAvatar extends GameEntity {
// Determine the new energy value. // Determine the new energy value.
float newEnergy = Math.min(curEnergy + amount, maxEnergy); float newEnergy = Math.min(curEnergy + amount, maxEnergy);
// Set energy and notify. // Set energy and notify.
if (newEnergy != curEnergy) { if (newEnergy != curEnergy) {
this.avatar.setCurrentEnergy(curEnergyProp, newEnergy); this.avatar.setCurrentEnergy(curEnergyProp, newEnergy);
this.getScene().broadcastPacket(new PacketAvatarFightPropUpdateNotify(this.getAvatar(), curEnergyProp)); this.getScene().broadcastPacket(new PacketAvatarFightPropUpdateNotify(this.getAvatar(), curEnergyProp));
this.getScene().broadcastPacket(new PacketEntityFightPropChangeReasonNotify(this, curEnergyProp, newEnergy, reason)); this.getScene().broadcastPacket(new PacketEntityFightPropChangeReasonNotify(this, curEnergyProp, newEnergy, reason));
} }
} }
public SceneAvatarInfo getSceneAvatarInfo() { public SceneAvatarInfo getSceneAvatarInfo() {
SceneAvatarInfo.Builder avatarInfo = SceneAvatarInfo.newBuilder() SceneAvatarInfo.Builder avatarInfo = SceneAvatarInfo.newBuilder()
.setUid(this.getPlayer().getUid()) .setUid(this.getPlayer().getUid())
@ -198,7 +199,7 @@ public class EntityAvatar extends GameEntity {
.setWearingFlycloakId(this.getAvatar().getFlyCloak()) .setWearingFlycloakId(this.getAvatar().getFlyCloak())
.setCostumeId(this.getAvatar().getCostume()) .setCostumeId(this.getAvatar().getCostume())
.setBornTime(this.getAvatar().getBornTime()); .setBornTime(this.getAvatar().getBornTime());
for (GameItem item : avatar.getEquips().values()) { for (GameItem item : avatar.getEquips().values()) {
if (item.getItemData().getEquipType() == EquipType.EQUIP_WEAPON) { if (item.getItemData().getEquipType() == EquipType.EQUIP_WEAPON) {
avatarInfo.setWeapon(item.createSceneWeaponInfo()); avatarInfo.setWeapon(item.createSceneWeaponInfo());
@ -207,7 +208,7 @@ public class EntityAvatar extends GameEntity {
} }
avatarInfo.addEquipIdList(item.getItemId()); avatarInfo.addEquipIdList(item.getItemId());
} }
return avatarInfo.build(); return avatarInfo.build();
} }
@ -219,7 +220,7 @@ public class EntityAvatar extends GameEntity {
.setAiInfo(SceneEntityAiInfo.newBuilder().setIsAiOpen(true).setBornPos(Vector.newBuilder())) .setAiInfo(SceneEntityAiInfo.newBuilder().setIsAiOpen(true).setBornPos(Vector.newBuilder()))
.setBornPos(Vector.newBuilder()) .setBornPos(Vector.newBuilder())
.build(); .build();
SceneEntityInfo.Builder entityInfo = SceneEntityInfo.newBuilder() SceneEntityInfo.Builder entityInfo = SceneEntityInfo.newBuilder()
.setEntityId(getId()) .setEntityId(getId())
.setEntityType(ProtEntityType.PROT_ENTITY_TYPE_AVATAR) .setEntityType(ProtEntityType.PROT_ENTITY_TYPE_AVATAR)
@ -229,11 +230,11 @@ public class EntityAvatar extends GameEntity {
.setLastMoveSceneTimeMs(this.getLastMoveSceneTimeMs()) .setLastMoveSceneTimeMs(this.getLastMoveSceneTimeMs())
.setLastMoveReliableSeq(this.getLastMoveReliableSeq()) .setLastMoveReliableSeq(this.getLastMoveReliableSeq())
.setLifeState(this.getLifeState().getValue()); .setLifeState(this.getLifeState().getValue());
if (this.getScene() != null) { if (this.getScene() != null) {
entityInfo.setMotionInfo(this.getMotionInfo()); entityInfo.setMotionInfo(this.getMotionInfo());
} }
for (Int2FloatMap.Entry entry : getFightProperties().int2FloatEntrySet()) { for (Int2FloatMap.Entry entry : getFightProperties().int2FloatEntrySet()) {
if (entry.getIntKey() == 0) { if (entry.getIntKey() == 0) {
continue; continue;
@ -241,23 +242,23 @@ public class EntityAvatar extends GameEntity {
FightPropPair fightProp = FightPropPair.newBuilder().setPropType(entry.getIntKey()).setPropValue(entry.getFloatValue()).build(); FightPropPair fightProp = FightPropPair.newBuilder().setPropType(entry.getIntKey()).setPropValue(entry.getFloatValue()).build();
entityInfo.addFightPropList(fightProp); entityInfo.addFightPropList(fightProp);
} }
PropPair pair = PropPair.newBuilder() PropPair pair = PropPair.newBuilder()
.setType(PlayerProperty.PROP_LEVEL.getId()) .setType(PlayerProperty.PROP_LEVEL.getId())
.setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, getAvatar().getLevel())) .setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, getAvatar().getLevel()))
.build(); .build();
entityInfo.addPropList(pair); entityInfo.addPropList(pair);
entityInfo.setAvatar(this.getSceneAvatarInfo()); entityInfo.setAvatar(this.getSceneAvatarInfo());
return entityInfo.build(); return entityInfo.build();
} }
public AbilityControlBlock getAbilityControlBlock() { public AbilityControlBlock getAbilityControlBlock() {
AvatarData data = this.getAvatar().getAvatarData(); AvatarData data = this.getAvatar().getAvatarData();
AbilityControlBlock.Builder abilityControlBlock = AbilityControlBlock.newBuilder(); AbilityControlBlock.Builder abilityControlBlock = AbilityControlBlock.newBuilder();
int embryoId = 0; int embryoId = 0;
// Add avatar abilities // Add avatar abilities
if (data.getAbilities() != null) { if (data.getAbilities() != null) {
for (int id : data.getAbilities()) { for (int id : data.getAbilities()) {
@ -269,7 +270,7 @@ public class EntityAvatar extends GameEntity {
abilityControlBlock.addAbilityEmbryoList(emb); abilityControlBlock.addAbilityEmbryoList(emb);
} }
} }
// Add default abilities // Add default abilities
for (int id : GameConstants.DEFAULT_ABILITY_HASHES) { for (int id : GameConstants.DEFAULT_ABILITY_HASHES) {
AbilityEmbryo emb = AbilityEmbryo.newBuilder() AbilityEmbryo emb = AbilityEmbryo.newBuilder()
.setAbilityId(++embryoId) .setAbilityId(++embryoId)
@ -278,7 +279,7 @@ public class EntityAvatar extends GameEntity {
.build(); .build();
abilityControlBlock.addAbilityEmbryoList(emb); abilityControlBlock.addAbilityEmbryoList(emb);
} }
// Add team resonances // Add team resonances
for (int id : this.getPlayer().getTeamManager().getTeamResonancesConfig()) { for (int id : this.getPlayer().getTeamManager().getTeamResonancesConfig()) {
AbilityEmbryo emb = AbilityEmbryo.newBuilder() AbilityEmbryo emb = AbilityEmbryo.newBuilder()
.setAbilityId(++embryoId) .setAbilityId(++embryoId)
@ -310,8 +311,25 @@ public class EntityAvatar extends GameEntity {
abilityControlBlock.addAbilityEmbryoList(emb); abilityControlBlock.addAbilityEmbryoList(emb);
} }
} }
// //
return abilityControlBlock.build(); return abilityControlBlock.build();
} }
/**
* Move this entity to a new position.
* Additionally invoke player move event.
* @param newPosition The new position.
* @param rotation The new rotation.
*/
@Override public void move(Position newPosition, Position rotation) {
// Invoke player move event.
PlayerMoveEvent event = new PlayerMoveEvent(
this.getPlayer(), PlayerMoveEvent.MoveType.PLAYER,
this.getPosition(), newPosition
); event.call();
// Set position and rotation.
super.move(event.getDestination(), rotation);
}
} }

View File

@ -24,32 +24,32 @@ public abstract class GameEntity {
protected int id; protected int id;
private final Scene scene; private final Scene scene;
private SpawnDataEntry spawnEntry; private SpawnDataEntry spawnEntry;
private int blockId; private int blockId;
private int configId; private int configId;
private int groupId; private int groupId;
private MotionState moveState; private MotionState moveState;
private int lastMoveSceneTimeMs; private int lastMoveSceneTimeMs;
private int lastMoveReliableSeq; private int lastMoveReliableSeq;
// Abilities // Abilities
private Map<String, Float> metaOverrideMap; private Map<String, Float> metaOverrideMap;
private Int2ObjectMap<String> metaModifiers; private Int2ObjectMap<String> metaModifiers;
public GameEntity(Scene scene) { public GameEntity(Scene scene) {
this.scene = scene; this.scene = scene;
this.moveState = MotionState.MOTION_STATE_NONE; this.moveState = MotionState.MOTION_STATE_NONE;
} }
public int getId() { public int getId() {
return this.id; return this.id;
} }
public int getEntityType() { public int getEntityType() {
return getId() >> 24; return getId() >> 24;
} }
public World getWorld() { public World getWorld() {
return this.getScene().getWorld(); return this.getScene().getWorld();
} }
@ -57,7 +57,7 @@ public abstract class GameEntity {
public Scene getScene() { public Scene getScene() {
return this.scene; return this.scene;
} }
public boolean isAlive() { public boolean isAlive() {
return true; return true;
} }
@ -65,14 +65,14 @@ public abstract class GameEntity {
public LifeState getLifeState() { public LifeState getLifeState() {
return isAlive() ? LifeState.LIFE_ALIVE : LifeState.LIFE_DEAD; return isAlive() ? LifeState.LIFE_ALIVE : LifeState.LIFE_DEAD;
} }
public Map<String, Float> getMetaOverrideMap() { public Map<String, Float> getMetaOverrideMap() {
if (this.metaOverrideMap == null) { if (this.metaOverrideMap == null) {
this.metaOverrideMap = new HashMap<>(); this.metaOverrideMap = new HashMap<>();
} }
return this.metaOverrideMap; return this.metaOverrideMap;
} }
public Int2ObjectMap<String> getMetaModifiers() { public Int2ObjectMap<String> getMetaModifiers() {
if (this.metaModifiers == null) { if (this.metaModifiers == null) {
this.metaModifiers = new Int2ObjectOpenHashMap<>(); this.metaModifiers = new Int2ObjectOpenHashMap<>();
@ -81,11 +81,11 @@ public abstract class GameEntity {
} }
public abstract Int2FloatOpenHashMap getFightProperties(); public abstract Int2FloatOpenHashMap getFightProperties();
public abstract Position getPosition(); public abstract Position getPosition();
public abstract Position getRotation(); public abstract Position getRotation();
public MotionState getMotionState() { public MotionState getMotionState() {
return moveState; return moveState;
} }
@ -109,23 +109,23 @@ public abstract class GameEntity {
public void setLastMoveReliableSeq(int lastMoveReliableSeq) { public void setLastMoveReliableSeq(int lastMoveReliableSeq) {
this.lastMoveReliableSeq = lastMoveReliableSeq; this.lastMoveReliableSeq = lastMoveReliableSeq;
} }
public void setFightProperty(FightProperty prop, float value) { public void setFightProperty(FightProperty prop, float value) {
this.getFightProperties().put(prop.getId(), value); this.getFightProperties().put(prop.getId(), value);
} }
private void setFightProperty(int id, float value) { private void setFightProperty(int id, float value) {
this.getFightProperties().put(id, value); this.getFightProperties().put(id, value);
} }
public void addFightProperty(FightProperty prop, float value) { public void addFightProperty(FightProperty prop, float value) {
this.getFightProperties().put(prop.getId(), getFightProperty(prop) + value); this.getFightProperties().put(prop.getId(), getFightProperty(prop) + value);
} }
public float getFightProperty(FightProperty prop) { public float getFightProperty(FightProperty prop) {
return getFightProperties().getOrDefault(prop.getId(), 0f); return getFightProperties().getOrDefault(prop.getId(), 0f);
} }
public void addAllFightPropsToEntityInfo(SceneEntityInfo.Builder entityInfo) { public void addAllFightPropsToEntityInfo(SceneEntityInfo.Builder entityInfo) {
for (Int2FloatMap.Entry entry : getFightProperties().int2FloatEntrySet()) { for (Int2FloatMap.Entry entry : getFightProperties().int2FloatEntrySet()) {
if (entry.getIntKey() == 0) { if (entry.getIntKey() == 0) {
@ -135,7 +135,7 @@ public abstract class GameEntity {
entityInfo.addFightPropList(fightProp); entityInfo.addFightPropList(fightProp);
} }
} }
public int getBlockId() { public int getBlockId() {
return blockId; return blockId;
} }
@ -143,7 +143,7 @@ public abstract class GameEntity {
public void setBlockId(int blockId) { public void setBlockId(int blockId) {
this.blockId = blockId; this.blockId = blockId;
} }
public int getConfigId() { public int getConfigId() {
return configId; return configId;
} }
@ -151,7 +151,7 @@ public abstract class GameEntity {
public void setConfigId(int configId) { public void setConfigId(int configId) {
this.configId = configId; this.configId = configId;
} }
public int getGroupId() { public int getGroupId() {
return groupId; return groupId;
} }
@ -159,7 +159,7 @@ public abstract class GameEntity {
public void setGroupId(int groupId) { public void setGroupId(int groupId) {
this.groupId = groupId; this.groupId = groupId;
} }
protected MotionInfo getMotionInfo() { protected MotionInfo getMotionInfo() {
MotionInfo proto = MotionInfo.newBuilder() MotionInfo proto = MotionInfo.newBuilder()
.setPos(getPosition().toProto()) .setPos(getPosition().toProto())
@ -167,7 +167,7 @@ public abstract class GameEntity {
.setSpeed(Vector.newBuilder()) .setSpeed(Vector.newBuilder())
.setState(this.getMotionState()) .setState(this.getMotionState())
.build(); .build();
return proto; return proto;
} }
@ -178,7 +178,7 @@ public abstract class GameEntity {
public void setSpawnEntry(SpawnDataEntry spawnEntry) { public void setSpawnEntry(SpawnDataEntry spawnEntry) {
this.spawnEntry = spawnEntry; this.spawnEntry = spawnEntry;
} }
public float heal(float amount) { public float heal(float amount) {
if (this.getFightProperties() == null) { if (this.getFightProperties() == null) {
return 0f; return 0f;
@ -186,62 +186,73 @@ public abstract class GameEntity {
float curHp = getFightProperty(FightProperty.FIGHT_PROP_CUR_HP); float curHp = getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
float maxHp = getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); float maxHp = getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
if (curHp >= maxHp) { if (curHp >= maxHp) {
return 0f; return 0f;
} }
float healed = Math.min(maxHp - curHp, amount); float healed = Math.min(maxHp - curHp, amount);
this.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, healed); this.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, healed);
getScene().broadcastPacket(new PacketEntityFightPropUpdateNotify(this, FightProperty.FIGHT_PROP_CUR_HP)); getScene().broadcastPacket(new PacketEntityFightPropUpdateNotify(this, FightProperty.FIGHT_PROP_CUR_HP));
return healed; return healed;
} }
public void damage(float amount) { public void damage(float amount) {
damage(amount, 0); damage(amount, 0);
} }
public void damage(float amount, int killerId) { public void damage(float amount, int killerId) {
// Sanity check // Sanity check
if (getFightProperties() == null) { if (getFightProperties() == null) {
return; return;
} }
// Lose hp // Lose hp
addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, -amount); addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, -amount);
// Check if dead // Check if dead
boolean isDead = false; boolean isDead = false;
if (getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) <= 0f) { if (getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) <= 0f) {
setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 0f); setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 0f);
isDead = true; isDead = true;
} }
// Packets // Packets
this.getScene().broadcastPacket(new PacketEntityFightPropUpdateNotify(this, FightProperty.FIGHT_PROP_CUR_HP)); this.getScene().broadcastPacket(new PacketEntityFightPropUpdateNotify(this, FightProperty.FIGHT_PROP_CUR_HP));
// Check if dead // Check if dead
if (isDead) { if (isDead) {
getScene().killEntity(this, killerId); getScene().killEntity(this, killerId);
} }
} }
/**
* Move this entity to a new position.
* @param position The new position.
* @param rotation The new rotation.
*/
public void move(Position position, Position rotation) {
// Set the position and rotation.
this.getPosition().set(position);
this.getRotation().set(rotation);
}
/** /**
* Called when this entity is added to the world * Called when this entity is added to the world
*/ */
public void onCreate() { public void onCreate() {
} }
/** /**
* Called when this entity dies * Called when this entity dies
* @param killerId Entity id of the entity that killed this entity * @param killerId Entity id of the entity that killed this entity
*/ */
public void onDeath(int killerId) { public void onDeath(int killerId) {
} }
public abstract SceneEntityInfo toProto(); public abstract SceneEntityInfo toProto();
} }

View File

@ -0,0 +1,47 @@
package emu.grasscutter.server.event.player;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.event.Cancellable;
import emu.grasscutter.server.event.types.PlayerEvent;
import emu.grasscutter.utils.Position;
/**
* TODO: Allow plugins to change the position of the player.
*/
public final class PlayerMoveEvent extends PlayerEvent implements Cancellable {
private final MoveType type;
private final Position from;
private final Position to;
public PlayerMoveEvent(Player player, MoveType type, Position from, Position to) {
super(player);
this.type = type;
this.from = from;
this.to = to;
}
public MoveType getMoveType() {
return this.type;
}
public Position getSource() {
return this.from;
}
public Position getDestination() {
return this.to;
}
public enum MoveType {
/**
* The player has sent a combat invocation to move.
*/
PLAYER,
/**
* The server has requested that the player moves.
*/
SERVER
}
}