From e3f15bca4735f5ee0be4e3537933ccec914b99af Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Tue, 29 Aug 2023 23:35:58 -0400 Subject: [PATCH] Add `PlayerLevelStatueEvent` & `PlayerUseSkillEvent` --- .../game/ability/AbilityManager.java | 14 ++++++++-- .../game/managers/SotSManager.java | 4 +++ .../event/player/PlayerLevelStatueEvent.java | 20 +++++++++++++ .../event/player/PlayerUseSkillEvent.java | 28 +++++++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/main/java/emu/grasscutter/server/event/player/PlayerLevelStatueEvent.java create mode 100644 src/main/java/emu/grasscutter/server/event/player/PlayerUseSkillEvent.java diff --git a/src/main/java/emu/grasscutter/game/ability/AbilityManager.java b/src/main/java/emu/grasscutter/game/ability/AbilityManager.java index 07fb0dbbd..af4b74ed0 100644 --- a/src/main/java/emu/grasscutter/game/ability/AbilityManager.java +++ b/src/main/java/emu/grasscutter/game/ability/AbilityManager.java @@ -18,12 +18,14 @@ import emu.grasscutter.net.proto.AbilityMetaSetKilledStateOuterClass.AbilityMeta import emu.grasscutter.net.proto.AbilityScalarTypeOuterClass.AbilityScalarType; import emu.grasscutter.net.proto.AbilityScalarValueEntryOuterClass.AbilityScalarValueEntry; import emu.grasscutter.net.proto.ModifierActionOuterClass.ModifierAction; +import emu.grasscutter.server.event.player.PlayerUseSkillEvent; import io.netty.util.concurrent.FastThreadLocalThread; -import java.util.HashMap; -import java.util.concurrent.*; import lombok.Getter; import org.reflections.Reflections; +import java.util.HashMap; +import java.util.concurrent.*; + public final class AbilityManager extends BasePlayerManager { private static final HashMap actionHandlers = new HashMap<>(); @@ -263,7 +265,8 @@ public final class AbilityManager extends BasePlayerManager { } // Check if the caster matches the player. - if (player.getTeamManager().getCurrentAvatarEntity().getId() != casterId) { + var currentAvatar = player.getTeamManager().getCurrentAvatarEntity(); + if (currentAvatar == null || currentAvatar.getId() != casterId) { return; } @@ -272,6 +275,11 @@ public final class AbilityManager extends BasePlayerManager { return; } + // Invoke PlayerUseSkillEvent. + var event = new PlayerUseSkillEvent(player, + skillData, currentAvatar.getAvatar()); + if (!event.call()) return; + // Check if the skill is an elemental burst. if (skillData.getCostElemVal() <= 0) { return; diff --git a/src/main/java/emu/grasscutter/game/managers/SotSManager.java b/src/main/java/emu/grasscutter/game/managers/SotSManager.java index 3e05351e3..8c88fca3d 100644 --- a/src/main/java/emu/grasscutter/game/managers/SotSManager.java +++ b/src/main/java/emu/grasscutter/game/managers/SotSManager.java @@ -15,6 +15,7 @@ import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.quest.enums.QuestContent; import emu.grasscutter.net.proto.ChangeHpReasonOuterClass.ChangeHpReason; import emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason; +import emu.grasscutter.server.event.player.PlayerLevelStatueEvent; import emu.grasscutter.server.packet.send.PacketEntityFightPropChangeReasonNotify; import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketLevelupCityRsp; @@ -303,5 +304,8 @@ public class SotSManager extends BasePlayerManager { player.sendPacket( new PacketLevelupCityRsp( sceneId, cityInfo.getLevel(), cityId, cityInfo.getNumCrystal(), areaId, 0)); + + // Call PlayerLevelStatueEvent. + new PlayerLevelStatueEvent(this.getPlayer(), cityInfo, sceneId, areaId); } } diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerLevelStatueEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerLevelStatueEvent.java new file mode 100644 index 000000000..68cccf1d3 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerLevelStatueEvent.java @@ -0,0 +1,20 @@ +package emu.grasscutter.server.event.player; + +import emu.grasscutter.game.city.CityInfoData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.types.PlayerEvent; +import lombok.Getter; + +@Getter +public final class PlayerLevelStatueEvent extends PlayerEvent { + private final CityInfoData city; + private final int sceneId, areaId; + + public PlayerLevelStatueEvent(Player player, CityInfoData city, int sceneId, int areaId) { + super(player); + + this.city = city; + this.sceneId = sceneId; + this.areaId = areaId; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerUseSkillEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerUseSkillEvent.java new file mode 100644 index 000000000..07aada5b5 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerUseSkillEvent.java @@ -0,0 +1,28 @@ +package emu.grasscutter.server.event.player; + +import emu.grasscutter.data.excels.avatar.AvatarSkillData; +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.Cancellable; +import emu.grasscutter.server.event.types.PlayerEvent; +import lombok.Getter; + +@Getter +public final class PlayerUseSkillEvent extends PlayerEvent implements Cancellable { + private final AvatarSkillData skillData; + private final Avatar avatar; + + public PlayerUseSkillEvent(Player player, AvatarSkillData skillData, Avatar avatar) { + super(player); + + this.skillData = skillData; + this.avatar = avatar; + } + + /** + * @return {@code true} if the skill is an elemental burst. + */ + public boolean isElementalBurst() { + return this.getSkillData().getCostElemVal() <= 0; + } +}