Add PlayerLevelStatueEvent & PlayerUseSkillEvent

This commit is contained in:
KingRainbow44 2023-08-29 23:35:58 -04:00
parent 48439e7e5d
commit e3f15bca47
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
4 changed files with 63 additions and 3 deletions

View File

@ -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<AbilityModifierAction.Type, AbilityActionHandler> 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;

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}