HealAbilityManager.java 9.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package emu.grasscutter.game.ability;

import java.util.*;
import java.util.Optional;
import java.util.Map.Entry;

import com.google.protobuf.InvalidProtocolBufferException;

import emu.grasscutter.Grasscutter;

import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.AbilityModifierEntry;
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
import emu.grasscutter.data.excels.AvatarSkillDepotData;
import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.entity.EntityClientGadget;
import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ElementType;
import emu.grasscutter.net.proto.AbilityActionGenerateElemBallOuterClass.AbilityActionGenerateElemBall;
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 emu.grasscutter.utils.Position;
import emu.grasscutter.utils.Utils;
import emu.grasscutter.game.props.FightProperty;

public class HealAbilityManager {
    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 {
64
65
        public int avatarId = 0;
        public String avatarName = "";
66
67
68
        public int fightPropertyType= 0; //0: maxHP, 1: curAttack, 2: curDefense
        public ArrayList<HealData> healDataList;

69
70
71
        public HealDataAvatar(int _avatarId, String _avatarName, int _fightPropertyType) {
            avatarId = _avatarId;
            avatarName = _avatarName;
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
            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;
        }
    }

    ArrayList<HealDataAvatar> healDataAvatarList;
	private Player player;
    
    public HealAbilityManager (Player player) {
		this.player = player;
        healDataAvatarList = new ArrayList();
95
        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));
96
97
98
99
100
        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));
101
        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, 4660, true));
102
        healDataAvatarList.add(new HealDataAvatar(10000065, "Shinobu", 0).addHealData("E", "ElementalArt_Heal_MaxHP_Percentage", 0.064f, 795f, false));
103
        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));
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
    }

	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, curAttack, curDefense;
        Map<String, Float> map = sourceEntity.getMetaOverrideMap();
133

134
135
        for(int i = 0 ; i < healDataAvatarList.size() ; i ++) {
            HealDataAvatar healDataAvatar = healDataAvatarList.get(i);
136
            if(modifierString.contains(healDataAvatar.avatarName)) {
137
138
139
140
141
                fightPropertyType = healDataAvatar.fightPropertyType;
                ArrayList<HealData> healDataList = healDataAvatar.healDataList;

                for(int j = 0 ; j < healDataList.size(); j++) {
                    HealData healData = healDataList.get(j);
142
                    if(map.containsKey(healData.sRatio) || modifierString.equals(healData.sRatio)) {
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
                        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);
                    }

164
165
166
167
168
169
                    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;
170
                            break;
171
                        }
172
                    }
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

                    if(healActionAvatar != null) {
                        maxHP = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
                        curAttack = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK);
                        curDefense = healActionAvatar.getFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE);
                        switch(fightPropertyType) {
                            case 0:
                                healAmount = ratio * maxHP + base;
                                break;
                            case 1:
                                healAmount = ratio * curAttack + base;
                                break;
                            case 2:
                                healAmount = ratio * curDefense + base;
                                break;
                        }
                    }

191
192
193
194
195
196
197
198
199
200
                    for(int k = 0 ; k < needHealAvatars.size() ; k ++) {
                        EntityAvatar avatar = needHealAvatars.get(k);
                        avatar.heal(healAmount);
                    }
                }
                break;
            }
        }
    }
}