mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-14 16:04:40 +01:00
Add a method to be invoked on skill perform and end
This commit is contained in:
@@ -17,43 +17,84 @@ import emu.grasscutter.net.proto.AbilityMetaReInitOverrideMapOuterClass.AbilityM
|
|||||||
import emu.grasscutter.net.proto.AbilityMixinCostStaminaOuterClass.AbilityMixinCostStamina;
|
import emu.grasscutter.net.proto.AbilityMixinCostStaminaOuterClass.AbilityMixinCostStamina;
|
||||||
import emu.grasscutter.net.proto.AbilityScalarValueEntryOuterClass.AbilityScalarValueEntry;
|
import emu.grasscutter.net.proto.AbilityScalarValueEntryOuterClass.AbilityScalarValueEntry;
|
||||||
import emu.grasscutter.net.proto.ModifierActionOuterClass.ModifierAction;
|
import emu.grasscutter.net.proto.ModifierActionOuterClass.ModifierAction;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
public class AbilityManager extends BasePlayerManager {
|
public final class AbilityManager extends BasePlayerManager {
|
||||||
HealAbilityManager healAbilityManager;
|
HealAbilityManager healAbilityManager;
|
||||||
|
|
||||||
|
@Getter private boolean abilityInvulnerable = false;
|
||||||
|
|
||||||
public AbilityManager(Player player) {
|
public AbilityManager(Player player) {
|
||||||
super(player);
|
super(player);
|
||||||
this.healAbilityManager = new HealAbilityManager(player);
|
this.healAbilityManager = new HealAbilityManager(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception {
|
public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception {
|
||||||
healAbilityManager.healHandler(invoke);
|
this.healAbilityManager.healHandler(invoke);
|
||||||
|
|
||||||
//Grasscutter.getLogger().info(invoke.getArgumentType() + " (" + invoke.getArgumentTypeValue() + "): " + Utils.bytesToHex(invoke.toByteArray()));
|
//Grasscutter.getLogger().info(invoke.getArgumentType() + " (" + invoke.getArgumentTypeValue() + "): " + Utils.bytesToHex(invoke.toByteArray()));
|
||||||
switch (invoke.getArgumentType()) {
|
switch (invoke.getArgumentType()) {
|
||||||
case ABILITY_INVOKE_ARGUMENT_META_OVERRIDE_PARAM:
|
case ABILITY_INVOKE_ARGUMENT_META_OVERRIDE_PARAM -> this.handleOverrideParam(invoke);
|
||||||
handleOverrideParam(invoke);
|
case ABILITY_INVOKE_ARGUMENT_META_REINIT_OVERRIDEMAP -> this.handleReinitOverrideMap(invoke);
|
||||||
break;
|
case ABILITY_INVOKE_ARGUMENT_META_MODIFIER_CHANGE -> this.handleModifierChange(invoke);
|
||||||
case ABILITY_INVOKE_ARGUMENT_META_REINIT_OVERRIDEMAP:
|
case ABILITY_INVOKE_ARGUMENT_MIXIN_COST_STAMINA -> this.handleMixinCostStamina(invoke);
|
||||||
handleReinitOverrideMap(invoke);
|
case ABILITY_INVOKE_ARGUMENT_ACTION_GENERATE_ELEM_BALL -> this.handleGenerateElemBall(invoke);
|
||||||
break;
|
default -> {}
|
||||||
case ABILITY_INVOKE_ARGUMENT_META_MODIFIER_CHANGE:
|
}
|
||||||
handleModifierChange(invoke);
|
}
|
||||||
break;
|
|
||||||
case ABILITY_INVOKE_ARGUMENT_MIXIN_COST_STAMINA:
|
/**
|
||||||
handleMixinCostStamina(invoke);
|
* Invoked when a player starts a skill.
|
||||||
break;
|
* @param player The player who started the skill.
|
||||||
case ABILITY_INVOKE_ARGUMENT_ACTION_GENERATE_ELEM_BALL:
|
* @param skillId The skill ID.
|
||||||
handleGenerateElemBall(invoke);
|
* @param casterId The caster ID.
|
||||||
break;
|
*/
|
||||||
default:
|
public void onSkillStart(Player player, int skillId, int casterId) {
|
||||||
break;
|
// Check if the player matches this player.
|
||||||
|
if (player.getUid() != this.player.getUid()) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the caster matches the player.
|
||||||
|
if(player.getTeamManager().getCurrentAvatarEntity().getId() != casterId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var skillData = GameData.getAvatarSkillDataMap().get(skillId);
|
||||||
|
if (skillData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the skill is an elemental burst.
|
||||||
|
if(skillData.getCostElemVal() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the player as invulnerable.
|
||||||
|
this.abilityInvulnerable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked when a player ends a skill.
|
||||||
|
* @param player The player who started the skill.
|
||||||
|
*/
|
||||||
|
public void onSkillEnd(Player player) {
|
||||||
|
// Check if the player matches this player.
|
||||||
|
if (player.getUid() != this.player.getUid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the player is invulnerable.
|
||||||
|
if(!this.abilityInvulnerable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the player as not invulnerable.
|
||||||
|
this.abilityInvulnerable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleOverrideParam(AbilityInvokeEntry invoke) throws Exception {
|
private void handleOverrideParam(AbilityInvokeEntry invoke) throws Exception {
|
||||||
GameEntity entity = player.getScene().getEntityById(invoke.getEntityId());
|
GameEntity entity = this.player.getScene().getEntityById(invoke.getEntityId());
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return;
|
return;
|
||||||
@@ -65,7 +106,7 @@ public class AbilityManager extends BasePlayerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleReinitOverrideMap(AbilityInvokeEntry invoke) throws Exception {
|
private void handleReinitOverrideMap(AbilityInvokeEntry invoke) throws Exception {
|
||||||
GameEntity entity = player.getScene().getEntityById(invoke.getEntityId());
|
GameEntity entity = this.player.getScene().getEntityById(invoke.getEntityId());
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return;
|
return;
|
||||||
@@ -80,7 +121,7 @@ public class AbilityManager extends BasePlayerManager {
|
|||||||
|
|
||||||
private void handleModifierChange(AbilityInvokeEntry invoke) throws Exception {
|
private void handleModifierChange(AbilityInvokeEntry invoke) throws Exception {
|
||||||
// Sanity checks
|
// Sanity checks
|
||||||
GameEntity target = player.getScene().getEntityById(invoke.getEntityId());
|
GameEntity target = this.player.getScene().getEntityById(invoke.getEntityId());
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -104,7 +145,7 @@ public class AbilityManager extends BasePlayerManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameEntity sourceEntity = player.getScene().getEntityById(data.getApplyEntityId());
|
GameEntity sourceEntity = this.player.getScene().getEntityById(data.getApplyEntityId());
|
||||||
if (sourceEntity == null) {
|
if (sourceEntity == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -117,7 +158,7 @@ public class AbilityManager extends BasePlayerManager {
|
|||||||
|
|
||||||
if (modifier != null && modifier.getOnAdded().size() > 0) {
|
if (modifier != null && modifier.getOnAdded().size() > 0) {
|
||||||
for (AbilityModifierAction action : modifier.getOnAdded()) {
|
for (AbilityModifierAction action : modifier.getOnAdded()) {
|
||||||
invokeAction(action, target, sourceEntity);
|
this.invokeAction(action, target, sourceEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +174,7 @@ public class AbilityManager extends BasePlayerManager {
|
|||||||
|
|
||||||
if (modifier != null && modifier.getOnRemoved().size() > 0) {
|
if (modifier != null && modifier.getOnRemoved().size() > 0) {
|
||||||
for (AbilityModifierAction action : modifier.getOnRemoved()) {
|
for (AbilityModifierAction action : modifier.getOnRemoved()) {
|
||||||
invokeAction(action, target, sourceEntity);
|
this.invokeAction(action, target, sourceEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +186,7 @@ public class AbilityManager extends BasePlayerManager {
|
|||||||
|
|
||||||
private void handleMixinCostStamina(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
|
private void handleMixinCostStamina(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
|
||||||
AbilityMixinCostStamina costStamina = AbilityMixinCostStamina.parseFrom((invoke.getAbilityData()));
|
AbilityMixinCostStamina costStamina = AbilityMixinCostStamina.parseFrom((invoke.getAbilityData()));
|
||||||
getPlayer().getStaminaManager().handleMixinCostStamina(costStamina.getIsSwim());
|
this.getPlayer().getStaminaManager().handleMixinCostStamina(costStamina.getIsSwim());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGenerateElemBall(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
|
private void handleGenerateElemBall(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
|
||||||
|
|||||||
Reference in New Issue
Block a user