mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-04-02 14:02:44 +02:00
Run Spotless on src/main
This commit is contained in:
@@ -1,222 +1,228 @@
|
||||
package emu.grasscutter.game.ability;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
|
||||
import emu.grasscutter.data.binout.AbilityModifierEntry;
|
||||
import emu.grasscutter.game.entity.EntityGadget;
|
||||
import emu.grasscutter.game.entity.GameEntity;
|
||||
import emu.grasscutter.game.entity.gadget.GadgetGatherObject;
|
||||
import emu.grasscutter.game.player.BasePlayerManager;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.proto.AbilityInvokeEntryHeadOuterClass.AbilityInvokeEntryHead;
|
||||
import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry;
|
||||
import emu.grasscutter.net.proto.AbilityMetaModifierChangeOuterClass.AbilityMetaModifierChange;
|
||||
import emu.grasscutter.net.proto.AbilityMetaReInitOverrideMapOuterClass.AbilityMetaReInitOverrideMap;
|
||||
import emu.grasscutter.net.proto.AbilityMixinCostStaminaOuterClass.AbilityMixinCostStamina;
|
||||
import emu.grasscutter.net.proto.AbilityScalarValueEntryOuterClass.AbilityScalarValueEntry;
|
||||
import emu.grasscutter.net.proto.ModifierActionOuterClass.ModifierAction;
|
||||
import lombok.Getter;
|
||||
|
||||
public final class AbilityManager extends BasePlayerManager {
|
||||
HealAbilityManager healAbilityManager;
|
||||
|
||||
@Getter
|
||||
private boolean abilityInvulnerable = false;
|
||||
|
||||
public AbilityManager(Player player) {
|
||||
super(player);
|
||||
this.healAbilityManager = new HealAbilityManager(player);
|
||||
}
|
||||
|
||||
public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception {
|
||||
this.healAbilityManager.healHandler(invoke);
|
||||
|
||||
//Grasscutter.getLogger().info(invoke.getArgumentType() + " (" + invoke.getArgumentTypeValue() + "): " + Utils.bytesToHex(invoke.toByteArray()));
|
||||
switch (invoke.getArgumentType()) {
|
||||
case ABILITY_INVOKE_ARGUMENT_META_OVERRIDE_PARAM -> this.handleOverrideParam(invoke);
|
||||
case ABILITY_INVOKE_ARGUMENT_META_REINIT_OVERRIDEMAP -> this.handleReinitOverrideMap(invoke);
|
||||
case ABILITY_INVOKE_ARGUMENT_META_MODIFIER_CHANGE -> this.handleModifierChange(invoke);
|
||||
case ABILITY_INVOKE_ARGUMENT_MIXIN_COST_STAMINA -> this.handleMixinCostStamina(invoke);
|
||||
case ABILITY_INVOKE_ARGUMENT_ACTION_GENERATE_ELEM_BALL -> this.handleGenerateElemBall(invoke);
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when a player starts a skill.
|
||||
*
|
||||
* @param player The player who started the skill.
|
||||
* @param skillId The skill ID.
|
||||
* @param casterId The caster ID.
|
||||
*/
|
||||
public void onSkillStart(Player player, int skillId, int casterId) {
|
||||
// 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 {
|
||||
GameEntity entity = this.player.getScene().getEntityById(invoke.getEntityId());
|
||||
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbilityScalarValueEntry entry = AbilityScalarValueEntry.parseFrom(invoke.getAbilityData());
|
||||
|
||||
entity.getMetaOverrideMap().put(entry.getKey().getStr(), entry.getFloatValue());
|
||||
}
|
||||
|
||||
private void handleReinitOverrideMap(AbilityInvokeEntry invoke) throws Exception {
|
||||
GameEntity entity = this.player.getScene().getEntityById(invoke.getEntityId());
|
||||
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbilityMetaReInitOverrideMap map = AbilityMetaReInitOverrideMap.parseFrom(invoke.getAbilityData());
|
||||
|
||||
for (AbilityScalarValueEntry entry : map.getOverrideMapList()) {
|
||||
entity.getMetaOverrideMap().put(entry.getKey().getStr(), entry.getFloatValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleModifierChange(AbilityInvokeEntry invoke) throws Exception {
|
||||
// Sanity checks
|
||||
GameEntity target = this.player.getScene().getEntityById(invoke.getEntityId());
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbilityMetaModifierChange data = AbilityMetaModifierChange.parseFrom(invoke.getAbilityData());
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Destroying rocks
|
||||
if (target instanceof EntityGadget targetGadget && targetGadget.getContent() instanceof GadgetGatherObject gatherObject) {
|
||||
if (data.getAction() == ModifierAction.MODIFIER_ACTION_REMOVED) {
|
||||
gatherObject.dropItems(this.getPlayer());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Sanity checks
|
||||
AbilityInvokeEntryHead head = invoke.getHead();
|
||||
if (head == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntity sourceEntity = this.player.getScene().getEntityById(data.getApplyEntityId());
|
||||
if (sourceEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This is not how it works but we will keep it for now since healing abilities dont work properly anyways
|
||||
if (data.getAction() == ModifierAction.MODIFIER_ACTION_ADDED && data.getParentAbilityName() != null) {
|
||||
// Handle add modifier here
|
||||
String modifierString = data.getParentAbilityName().getStr();
|
||||
AbilityModifierEntry modifier = GameData.getAbilityModifiers().get(modifierString);
|
||||
|
||||
if (modifier != null && modifier.getOnAdded().size() > 0) {
|
||||
for (AbilityModifierAction action : modifier.getOnAdded()) {
|
||||
this.invokeAction(action, target, sourceEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// Add to meta modifier list
|
||||
target.getMetaModifiers().put(head.getInstancedModifierId(), modifierString);
|
||||
} else if (data.getAction() == ModifierAction.MODIFIER_ACTION_REMOVED) {
|
||||
// Handle remove modifier
|
||||
String modifierString = target.getMetaModifiers().get(head.getInstancedModifierId());
|
||||
|
||||
if (modifierString != null) {
|
||||
// Get modifier and call on remove event
|
||||
AbilityModifierEntry modifier = GameData.getAbilityModifiers().get(modifierString);
|
||||
|
||||
if (modifier != null && modifier.getOnRemoved().size() > 0) {
|
||||
for (AbilityModifierAction action : modifier.getOnRemoved()) {
|
||||
this.invokeAction(action, target, sourceEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove from meta modifiers
|
||||
target.getMetaModifiers().remove(head.getInstancedModifierId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMixinCostStamina(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
|
||||
AbilityMixinCostStamina costStamina = AbilityMixinCostStamina.parseFrom((invoke.getAbilityData()));
|
||||
this.getPlayer().getStaminaManager().handleMixinCostStamina(costStamina.getIsSwim());
|
||||
}
|
||||
|
||||
private void handleGenerateElemBall(AbilityInvokeEntry invoke) throws InvalidProtocolBufferException {
|
||||
this.player.getEnergyManager().handleGenerateElemBall(invoke);
|
||||
}
|
||||
|
||||
private void invokeAction(AbilityModifierAction action, GameEntity target, GameEntity sourceEntity) {
|
||||
switch (action.type) {
|
||||
case HealHP -> {
|
||||
}
|
||||
case LoseHP -> {
|
||||
if (action.amountByTargetCurrentHPRatio == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
float damageAmount = action.amount.get();
|
||||
|
||||
// if (action.amount.isDynamic && action.amount.dynamicKey != null) {
|
||||
// damageAmount = sourceEntity.getMetaOverrideMap().getOrDefault(action.amount.dynamicKey, 0f);
|
||||
// }
|
||||
|
||||
if (damageAmount > 0) {
|
||||
target.damage(damageAmount);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package emu.grasscutter.game.ability;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
|
||||
import emu.grasscutter.data.binout.AbilityModifierEntry;
|
||||
import emu.grasscutter.game.entity.EntityGadget;
|
||||
import emu.grasscutter.game.entity.GameEntity;
|
||||
import emu.grasscutter.game.entity.gadget.GadgetGatherObject;
|
||||
import emu.grasscutter.game.player.BasePlayerManager;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.proto.AbilityInvokeEntryHeadOuterClass.AbilityInvokeEntryHead;
|
||||
import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry;
|
||||
import emu.grasscutter.net.proto.AbilityMetaModifierChangeOuterClass.AbilityMetaModifierChange;
|
||||
import emu.grasscutter.net.proto.AbilityMetaReInitOverrideMapOuterClass.AbilityMetaReInitOverrideMap;
|
||||
import emu.grasscutter.net.proto.AbilityMixinCostStaminaOuterClass.AbilityMixinCostStamina;
|
||||
import emu.grasscutter.net.proto.AbilityScalarValueEntryOuterClass.AbilityScalarValueEntry;
|
||||
import emu.grasscutter.net.proto.ModifierActionOuterClass.ModifierAction;
|
||||
import lombok.Getter;
|
||||
|
||||
public final class AbilityManager extends BasePlayerManager {
|
||||
HealAbilityManager healAbilityManager;
|
||||
|
||||
@Getter private boolean abilityInvulnerable = false;
|
||||
|
||||
public AbilityManager(Player player) {
|
||||
super(player);
|
||||
this.healAbilityManager = new HealAbilityManager(player);
|
||||
}
|
||||
|
||||
public void onAbilityInvoke(AbilityInvokeEntry invoke) throws Exception {
|
||||
this.healAbilityManager.healHandler(invoke);
|
||||
|
||||
// Grasscutter.getLogger().info(invoke.getArgumentType() + " (" + invoke.getArgumentTypeValue()
|
||||
// + "): " + Utils.bytesToHex(invoke.toByteArray()));
|
||||
switch (invoke.getArgumentType()) {
|
||||
case ABILITY_INVOKE_ARGUMENT_META_OVERRIDE_PARAM -> this.handleOverrideParam(invoke);
|
||||
case ABILITY_INVOKE_ARGUMENT_META_REINIT_OVERRIDEMAP -> this.handleReinitOverrideMap(invoke);
|
||||
case ABILITY_INVOKE_ARGUMENT_META_MODIFIER_CHANGE -> this.handleModifierChange(invoke);
|
||||
case ABILITY_INVOKE_ARGUMENT_MIXIN_COST_STAMINA -> this.handleMixinCostStamina(invoke);
|
||||
case ABILITY_INVOKE_ARGUMENT_ACTION_GENERATE_ELEM_BALL -> this.handleGenerateElemBall(invoke);
|
||||
default -> {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when a player starts a skill.
|
||||
*
|
||||
* @param player The player who started the skill.
|
||||
* @param skillId The skill ID.
|
||||
* @param casterId The caster ID.
|
||||
*/
|
||||
public void onSkillStart(Player player, int skillId, int casterId) {
|
||||
// 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 {
|
||||
GameEntity entity = this.player.getScene().getEntityById(invoke.getEntityId());
|
||||
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbilityScalarValueEntry entry = AbilityScalarValueEntry.parseFrom(invoke.getAbilityData());
|
||||
|
||||
entity.getMetaOverrideMap().put(entry.getKey().getStr(), entry.getFloatValue());
|
||||
}
|
||||
|
||||
private void handleReinitOverrideMap(AbilityInvokeEntry invoke) throws Exception {
|
||||
GameEntity entity = this.player.getScene().getEntityById(invoke.getEntityId());
|
||||
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbilityMetaReInitOverrideMap map =
|
||||
AbilityMetaReInitOverrideMap.parseFrom(invoke.getAbilityData());
|
||||
|
||||
for (AbilityScalarValueEntry entry : map.getOverrideMapList()) {
|
||||
entity.getMetaOverrideMap().put(entry.getKey().getStr(), entry.getFloatValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleModifierChange(AbilityInvokeEntry invoke) throws Exception {
|
||||
// Sanity checks
|
||||
GameEntity target = this.player.getScene().getEntityById(invoke.getEntityId());
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbilityMetaModifierChange data = AbilityMetaModifierChange.parseFrom(invoke.getAbilityData());
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Destroying rocks
|
||||
if (target instanceof EntityGadget targetGadget
|
||||
&& targetGadget.getContent() instanceof GadgetGatherObject gatherObject) {
|
||||
if (data.getAction() == ModifierAction.MODIFIER_ACTION_REMOVED) {
|
||||
gatherObject.dropItems(this.getPlayer());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Sanity checks
|
||||
AbilityInvokeEntryHead head = invoke.getHead();
|
||||
if (head == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntity sourceEntity = this.player.getScene().getEntityById(data.getApplyEntityId());
|
||||
if (sourceEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This is not how it works but we will keep it for now since healing abilities dont work
|
||||
// properly anyways
|
||||
if (data.getAction() == ModifierAction.MODIFIER_ACTION_ADDED
|
||||
&& data.getParentAbilityName() != null) {
|
||||
// Handle add modifier here
|
||||
String modifierString = data.getParentAbilityName().getStr();
|
||||
AbilityModifierEntry modifier = GameData.getAbilityModifiers().get(modifierString);
|
||||
|
||||
if (modifier != null && modifier.getOnAdded().size() > 0) {
|
||||
for (AbilityModifierAction action : modifier.getOnAdded()) {
|
||||
this.invokeAction(action, target, sourceEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// Add to meta modifier list
|
||||
target.getMetaModifiers().put(head.getInstancedModifierId(), modifierString);
|
||||
} else if (data.getAction() == ModifierAction.MODIFIER_ACTION_REMOVED) {
|
||||
// Handle remove modifier
|
||||
String modifierString = target.getMetaModifiers().get(head.getInstancedModifierId());
|
||||
|
||||
if (modifierString != null) {
|
||||
// Get modifier and call on remove event
|
||||
AbilityModifierEntry modifier = GameData.getAbilityModifiers().get(modifierString);
|
||||
|
||||
if (modifier != null && modifier.getOnRemoved().size() > 0) {
|
||||
for (AbilityModifierAction action : modifier.getOnRemoved()) {
|
||||
this.invokeAction(action, target, sourceEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove from meta modifiers
|
||||
target.getMetaModifiers().remove(head.getInstancedModifierId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMixinCostStamina(AbilityInvokeEntry invoke)
|
||||
throws InvalidProtocolBufferException {
|
||||
AbilityMixinCostStamina costStamina =
|
||||
AbilityMixinCostStamina.parseFrom((invoke.getAbilityData()));
|
||||
this.getPlayer().getStaminaManager().handleMixinCostStamina(costStamina.getIsSwim());
|
||||
}
|
||||
|
||||
private void handleGenerateElemBall(AbilityInvokeEntry invoke)
|
||||
throws InvalidProtocolBufferException {
|
||||
this.player.getEnergyManager().handleGenerateElemBall(invoke);
|
||||
}
|
||||
|
||||
private void invokeAction(
|
||||
AbilityModifierAction action, GameEntity target, GameEntity sourceEntity) {
|
||||
switch (action.type) {
|
||||
case HealHP -> {}
|
||||
case LoseHP -> {
|
||||
if (action.amountByTargetCurrentHPRatio == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
float damageAmount = action.amount.get();
|
||||
|
||||
// if (action.amount.isDynamic && action.amount.dynamicKey != null) {
|
||||
// damageAmount =
|
||||
// sourceEntity.getMetaOverrideMap().getOrDefault(action.amount.dynamicKey, 0f);
|
||||
// }
|
||||
|
||||
if (damageAmount > 0) {
|
||||
target.damage(damageAmount);
|
||||
}
|
||||
}
|
||||
default -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,185 +1,214 @@
|
||||
package emu.grasscutter.game.ability;
|
||||
|
||||
import emu.grasscutter.game.entity.EntityAvatar;
|
||||
import emu.grasscutter.game.entity.GameEntity;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.FightProperty;
|
||||
import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry;
|
||||
import emu.grasscutter.net.proto.AbilityMetaModifierChangeOuterClass.AbilityMetaModifierChange;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HealAbilityManager {
|
||||
ArrayList<HealDataAvatar> healDataAvatarList;
|
||||
private final Player player;
|
||||
|
||||
public HealAbilityManager(Player player) {
|
||||
this.player = player;
|
||||
healDataAvatarList = new ArrayList();
|
||||
healDataAvatarList.add(new HealDataAvatar(10000054, "Kokomi", 0).addHealData("E", "ElementalArt_Heal_MaxHP_Base_Percentage", "ElementalArt_Heal_Base_Amount", false).addHealData("Q", "Avatar_Kokomi_ElementalBurst_Heal", 0.0172f, 212f, false));
|
||||
healDataAvatarList.add(new HealDataAvatar(10000003, "Qin", 1).addHealData("Q", "Heal", "BurstHealConst", true));
|
||||
healDataAvatarList.add(new HealDataAvatar(10000034, "Noel", 2).addHealData("E", "OnAttack_HealthRate", 0.452f, 282f, true));
|
||||
healDataAvatarList.add(new HealDataAvatar(10000032, "Bennett", 0).addHealData("Q", "HealMaxHpRatio", "HealConst", false));
|
||||
healDataAvatarList.add(new HealDataAvatar(10000039, "Diona", 0).addHealData("Q", "HealHPRatio", "HealHP_Const", false));
|
||||
healDataAvatarList.add(new HealDataAvatar(10000053, "Sayu", 1).addHealData("Q", "Constellation_6_Damage", "Heal_BaseAmount", true).addHealData("Q", "Heal_AttackRatio", "Constellation_6_Heal", true));
|
||||
healDataAvatarList.add(new HealDataAvatar(10000014, "Barbara", 0).addHealData("E", "HealHPOnAdded", "HealHPOnAdded_Const", true).addHealData("E", "HealHP_OnHittingOthers", "HealHP_Const_OnHittingOthers", true).addHealData("Q", "Avatar_Barbara_IdolHeal", 0.374f, 4660f, true));
|
||||
healDataAvatarList.add(new HealDataAvatar(10000065, "Shinobu", 0).addHealData("E", "ElementalArt_Heal_MaxHP_Percentage", 0.064f, 795f, false));
|
||||
healDataAvatarList.add(new HealDataAvatar(10000035, "Qiqi", 1).addHealData("E", "HealHP_OnHittingOthers", "HealHP_Const_OnHittingOthers", true).addHealData("E", "ElementalArt_HealHp_Ratio", "ElementalArt_HealHp_Const", true).addHealData("Q", "Avatar_Qiqi_ElementalBurst_ApplyModifier", 0.0191f, 1588f, false));
|
||||
healDataAvatarList.add(new HealDataAvatar(10000046, "Hutao", 0).addHealData("Q", "Avatar_Hutao_VermilionBite_BakeMesh", 0.1166f, 0f, false));
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public void healHandler(AbilityInvokeEntry invoke) throws Exception {
|
||||
AbilityMetaModifierChange data = AbilityMetaModifierChange.parseFrom(invoke.getAbilityData());
|
||||
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntity sourceEntity = player.getScene().getEntityById(data.getApplyEntityId());
|
||||
|
||||
String modifierString = "";
|
||||
if (data.getParentAbilityName() != null)
|
||||
modifierString = data.getParentAbilityName().getStr();
|
||||
|
||||
if (sourceEntity != null)
|
||||
checkAndHeal(sourceEntity, modifierString);
|
||||
}
|
||||
|
||||
public void checkAndHeal(GameEntity sourceEntity, String modifierString) {
|
||||
int fightPropertyType = 0;
|
||||
float healAmount = 0;
|
||||
float ratio = 0, base = 0;
|
||||
float maxHP, curHP, curAttack, curDefense;
|
||||
Map<String, Float> map = sourceEntity.getMetaOverrideMap();
|
||||
|
||||
for (int i = 0; i < healDataAvatarList.size(); i++) {
|
||||
HealDataAvatar healDataAvatar = healDataAvatarList.get(i);
|
||||
if (modifierString.contains(healDataAvatar.avatarName)) {
|
||||
fightPropertyType = healDataAvatar.fightPropertyType;
|
||||
ArrayList<HealData> healDataList = healDataAvatar.healDataList;
|
||||
|
||||
for (int j = 0; j < healDataList.size(); j++) {
|
||||
HealData healData = healDataList.get(j);
|
||||
if (map.containsKey(healData.sRatio) || modifierString.equals(healData.sRatio)) {
|
||||
if (healData.isString) {
|
||||
ratio = map.get(healData.sRatio);
|
||||
base = map.get(healData.sBase);
|
||||
} else {
|
||||
ratio = healData.fRatio;
|
||||
base = healData.fBase;
|
||||
}
|
||||
}
|
||||
|
||||
List<EntityAvatar> activeTeam = player.getTeamManager().getActiveTeam();
|
||||
List<EntityAvatar> needHealAvatars = new ArrayList();
|
||||
int currentIndex = player.getTeamManager().getCurrentCharacterIndex();
|
||||
EntityAvatar currentAvatar = activeTeam.get(currentIndex);
|
||||
if (healData.healAll) {
|
||||
needHealAvatars = activeTeam;
|
||||
} else {
|
||||
needHealAvatars.add(currentAvatar);
|
||||
}
|
||||
|
||||
EntityAvatar healActionAvatar = null;
|
||||
for (int k = 0; k < activeTeam.size(); k++) {
|
||||
EntityAvatar avatar = activeTeam.get(k);
|
||||
int avatarId = avatar.getAvatar().getAvatarId();
|
||||
if (avatarId == healDataAvatar.avatarId) {
|
||||
healActionAvatar = avatar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (healActionAvatar != null) {
|
||||
maxHP = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
|
||||
curHP = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
|
||||
curAttack = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK);
|
||||
curDefense = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE);
|
||||
|
||||
//Special case for Hu Tao:
|
||||
if (healDataAvatar.avatarName.equals("Hutao") && curHP <= maxHP * 0.5 && ratio != 0) {
|
||||
ratio = 0.1555f;
|
||||
}
|
||||
|
||||
switch (fightPropertyType) {
|
||||
case 0:
|
||||
healAmount = ratio * maxHP + base;
|
||||
break;
|
||||
case 1:
|
||||
healAmount = ratio * curAttack + base;
|
||||
break;
|
||||
case 2:
|
||||
healAmount = ratio * curDefense + base;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; k < needHealAvatars.size(); k++) {
|
||||
EntityAvatar avatar = needHealAvatars.get(k);
|
||||
avatar.heal(healAmount);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class HealData {
|
||||
public boolean isString = true;
|
||||
public String abilityType = ""; //"E" or "Q"
|
||||
public String sRatio = "";
|
||||
public String sBase = "";
|
||||
public float fRatio = 0;
|
||||
public float fBase = 0;
|
||||
public boolean healAll = false;
|
||||
|
||||
public HealData(String _abilityType, String _sRatio, String _sBase, boolean _healAll) {
|
||||
abilityType = _abilityType;
|
||||
isString = true;
|
||||
sRatio = _sRatio;
|
||||
sBase = _sBase;
|
||||
healAll = _healAll;
|
||||
}
|
||||
|
||||
public HealData(String _abilityType, String _sRatio, float _fRatio, float _fBase, boolean _healAll) {
|
||||
abilityType = _abilityType;
|
||||
isString = false;
|
||||
sRatio = _sRatio;
|
||||
fRatio = _fRatio;
|
||||
fBase = _fBase;
|
||||
healAll = _healAll;
|
||||
}
|
||||
}
|
||||
|
||||
private class HealDataAvatar {
|
||||
public int avatarId = 0;
|
||||
public String avatarName = "";
|
||||
public int fightPropertyType = 0; //0: maxHP, 1: curAttack, 2: curDefense
|
||||
public ArrayList<HealData> healDataList;
|
||||
|
||||
public HealDataAvatar(int _avatarId, String _avatarName, int _fightPropertyType) {
|
||||
avatarId = _avatarId;
|
||||
avatarName = _avatarName;
|
||||
fightPropertyType = _fightPropertyType;
|
||||
healDataList = new ArrayList();
|
||||
}
|
||||
|
||||
public HealDataAvatar addHealData(String abilityType, String sRatio, String sBase, boolean healAll) {
|
||||
HealData healData = new HealData(abilityType, sRatio, sBase, healAll);
|
||||
healDataList.add(healData);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HealDataAvatar addHealData(String abilityType, String sRatio, float fRatio, float fBase, boolean healAll) {
|
||||
HealData healData = new HealData(abilityType, sRatio, fRatio, fBase, healAll);
|
||||
healDataList.add(healData);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
package emu.grasscutter.game.ability;
|
||||
|
||||
import emu.grasscutter.game.entity.EntityAvatar;
|
||||
import emu.grasscutter.game.entity.GameEntity;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.FightProperty;
|
||||
import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry;
|
||||
import emu.grasscutter.net.proto.AbilityMetaModifierChangeOuterClass.AbilityMetaModifierChange;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HealAbilityManager {
|
||||
ArrayList<HealDataAvatar> healDataAvatarList;
|
||||
private final Player player;
|
||||
|
||||
public HealAbilityManager(Player player) {
|
||||
this.player = player;
|
||||
healDataAvatarList = new ArrayList();
|
||||
healDataAvatarList.add(
|
||||
new HealDataAvatar(10000054, "Kokomi", 0)
|
||||
.addHealData(
|
||||
"E",
|
||||
"ElementalArt_Heal_MaxHP_Base_Percentage",
|
||||
"ElementalArt_Heal_Base_Amount",
|
||||
false)
|
||||
.addHealData("Q", "Avatar_Kokomi_ElementalBurst_Heal", 0.0172f, 212f, false));
|
||||
healDataAvatarList.add(
|
||||
new HealDataAvatar(10000003, "Qin", 1).addHealData("Q", "Heal", "BurstHealConst", true));
|
||||
healDataAvatarList.add(
|
||||
new HealDataAvatar(10000034, "Noel", 2)
|
||||
.addHealData("E", "OnAttack_HealthRate", 0.452f, 282f, true));
|
||||
healDataAvatarList.add(
|
||||
new HealDataAvatar(10000032, "Bennett", 0)
|
||||
.addHealData("Q", "HealMaxHpRatio", "HealConst", false));
|
||||
healDataAvatarList.add(
|
||||
new HealDataAvatar(10000039, "Diona", 0)
|
||||
.addHealData("Q", "HealHPRatio", "HealHP_Const", false));
|
||||
healDataAvatarList.add(
|
||||
new HealDataAvatar(10000053, "Sayu", 1)
|
||||
.addHealData("Q", "Constellation_6_Damage", "Heal_BaseAmount", true)
|
||||
.addHealData("Q", "Heal_AttackRatio", "Constellation_6_Heal", true));
|
||||
healDataAvatarList.add(
|
||||
new HealDataAvatar(10000014, "Barbara", 0)
|
||||
.addHealData("E", "HealHPOnAdded", "HealHPOnAdded_Const", true)
|
||||
.addHealData("E", "HealHP_OnHittingOthers", "HealHP_Const_OnHittingOthers", true)
|
||||
.addHealData("Q", "Avatar_Barbara_IdolHeal", 0.374f, 4660f, true));
|
||||
healDataAvatarList.add(
|
||||
new HealDataAvatar(10000065, "Shinobu", 0)
|
||||
.addHealData("E", "ElementalArt_Heal_MaxHP_Percentage", 0.064f, 795f, false));
|
||||
healDataAvatarList.add(
|
||||
new HealDataAvatar(10000035, "Qiqi", 1)
|
||||
.addHealData("E", "HealHP_OnHittingOthers", "HealHP_Const_OnHittingOthers", true)
|
||||
.addHealData("E", "ElementalArt_HealHp_Ratio", "ElementalArt_HealHp_Const", true)
|
||||
.addHealData("Q", "Avatar_Qiqi_ElementalBurst_ApplyModifier", 0.0191f, 1588f, false));
|
||||
healDataAvatarList.add(
|
||||
new HealDataAvatar(10000046, "Hutao", 0)
|
||||
.addHealData("Q", "Avatar_Hutao_VermilionBite_BakeMesh", 0.1166f, 0f, false));
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public void healHandler(AbilityInvokeEntry invoke) throws Exception {
|
||||
AbilityMetaModifierChange data = AbilityMetaModifierChange.parseFrom(invoke.getAbilityData());
|
||||
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntity sourceEntity = player.getScene().getEntityById(data.getApplyEntityId());
|
||||
|
||||
String modifierString = "";
|
||||
if (data.getParentAbilityName() != null) modifierString = data.getParentAbilityName().getStr();
|
||||
|
||||
if (sourceEntity != null) checkAndHeal(sourceEntity, modifierString);
|
||||
}
|
||||
|
||||
public void checkAndHeal(GameEntity sourceEntity, String modifierString) {
|
||||
int fightPropertyType = 0;
|
||||
float healAmount = 0;
|
||||
float ratio = 0, base = 0;
|
||||
float maxHP, curHP, curAttack, curDefense;
|
||||
Map<String, Float> map = sourceEntity.getMetaOverrideMap();
|
||||
|
||||
for (int i = 0; i < healDataAvatarList.size(); i++) {
|
||||
HealDataAvatar healDataAvatar = healDataAvatarList.get(i);
|
||||
if (modifierString.contains(healDataAvatar.avatarName)) {
|
||||
fightPropertyType = healDataAvatar.fightPropertyType;
|
||||
ArrayList<HealData> healDataList = healDataAvatar.healDataList;
|
||||
|
||||
for (int j = 0; j < healDataList.size(); j++) {
|
||||
HealData healData = healDataList.get(j);
|
||||
if (map.containsKey(healData.sRatio) || modifierString.equals(healData.sRatio)) {
|
||||
if (healData.isString) {
|
||||
ratio = map.get(healData.sRatio);
|
||||
base = map.get(healData.sBase);
|
||||
} else {
|
||||
ratio = healData.fRatio;
|
||||
base = healData.fBase;
|
||||
}
|
||||
}
|
||||
|
||||
List<EntityAvatar> activeTeam = player.getTeamManager().getActiveTeam();
|
||||
List<EntityAvatar> needHealAvatars = new ArrayList();
|
||||
int currentIndex = player.getTeamManager().getCurrentCharacterIndex();
|
||||
EntityAvatar currentAvatar = activeTeam.get(currentIndex);
|
||||
if (healData.healAll) {
|
||||
needHealAvatars = activeTeam;
|
||||
} else {
|
||||
needHealAvatars.add(currentAvatar);
|
||||
}
|
||||
|
||||
EntityAvatar healActionAvatar = null;
|
||||
for (int k = 0; k < activeTeam.size(); k++) {
|
||||
EntityAvatar avatar = activeTeam.get(k);
|
||||
int avatarId = avatar.getAvatar().getAvatarId();
|
||||
if (avatarId == healDataAvatar.avatarId) {
|
||||
healActionAvatar = avatar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (healActionAvatar != null) {
|
||||
maxHP = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
|
||||
curHP = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
|
||||
curAttack = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK);
|
||||
curDefense = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE);
|
||||
|
||||
// Special case for Hu Tao:
|
||||
if (healDataAvatar.avatarName.equals("Hutao") && curHP <= maxHP * 0.5 && ratio != 0) {
|
||||
ratio = 0.1555f;
|
||||
}
|
||||
|
||||
switch (fightPropertyType) {
|
||||
case 0:
|
||||
healAmount = ratio * maxHP + base;
|
||||
break;
|
||||
case 1:
|
||||
healAmount = ratio * curAttack + base;
|
||||
break;
|
||||
case 2:
|
||||
healAmount = ratio * curDefense + base;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; k < needHealAvatars.size(); k++) {
|
||||
EntityAvatar avatar = needHealAvatars.get(k);
|
||||
avatar.heal(healAmount);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class HealData {
|
||||
public boolean isString = true;
|
||||
public String abilityType = ""; // "E" or "Q"
|
||||
public String sRatio = "";
|
||||
public String sBase = "";
|
||||
public float fRatio = 0;
|
||||
public float fBase = 0;
|
||||
public boolean healAll = false;
|
||||
|
||||
public HealData(String _abilityType, String _sRatio, String _sBase, boolean _healAll) {
|
||||
abilityType = _abilityType;
|
||||
isString = true;
|
||||
sRatio = _sRatio;
|
||||
sBase = _sBase;
|
||||
healAll = _healAll;
|
||||
}
|
||||
|
||||
public HealData(
|
||||
String _abilityType, String _sRatio, float _fRatio, float _fBase, boolean _healAll) {
|
||||
abilityType = _abilityType;
|
||||
isString = false;
|
||||
sRatio = _sRatio;
|
||||
fRatio = _fRatio;
|
||||
fBase = _fBase;
|
||||
healAll = _healAll;
|
||||
}
|
||||
}
|
||||
|
||||
private class HealDataAvatar {
|
||||
public int avatarId = 0;
|
||||
public String avatarName = "";
|
||||
public int fightPropertyType = 0; // 0: maxHP, 1: curAttack, 2: curDefense
|
||||
public ArrayList<HealData> healDataList;
|
||||
|
||||
public HealDataAvatar(int _avatarId, String _avatarName, int _fightPropertyType) {
|
||||
avatarId = _avatarId;
|
||||
avatarName = _avatarName;
|
||||
fightPropertyType = _fightPropertyType;
|
||||
healDataList = new ArrayList();
|
||||
}
|
||||
|
||||
public HealDataAvatar addHealData(
|
||||
String abilityType, String sRatio, String sBase, boolean healAll) {
|
||||
HealData healData = new HealData(abilityType, sRatio, sBase, healAll);
|
||||
healDataList.add(healData);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HealDataAvatar addHealData(
|
||||
String abilityType, String sRatio, float fRatio, float fBase, boolean healAll) {
|
||||
HealData healData = new HealData(abilityType, sRatio, fRatio, fBase, healAll);
|
||||
healDataList.add(healData);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user