AvatarData.java 6.96 KB
Newer Older
Melledy's avatar
Melledy committed
1
package emu.grasscutter.data.excels;
Melledy's avatar
Melledy committed
2
3
4

import java.util.List;

5
6
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.GameResource;
Melledy's avatar
Melledy committed
7
8
import emu.grasscutter.data.ResourceType;
import emu.grasscutter.data.ResourceType.LoadPriority;
Melledy's avatar
Melledy committed
9
import emu.grasscutter.data.binout.AbilityEmbryoEntry;
Melledy's avatar
Melledy committed
10
11
12
13
14
15
16
17
import emu.grasscutter.data.common.PropGrowCurve;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.utils.Utils;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;

@ResourceType(name = "AvatarExcelConfigData.json", loadPriority = LoadPriority.LOW)
18
public class AvatarData extends GameResource {
Melledy's avatar
Melledy committed
19
	
Melledy's avatar
Melledy committed
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
	private String iconName;
    private String bodyType;
    private String qualityType;
    private int chargeEfficiency;
    private int initialWeapon;
    private String weaponType;
    private String imageName;
    private int avatarPromoteId;
    private String cutsceneShow;
    private int skillDepotId;
    private int staminaRecoverSpeed;
    private List<String> candSkillDepotIds;
    private String avatarIdentityType;
    private List<Integer> avatarPromoteRewardLevelList;
    private List<Integer> avatarPromoteRewardIdList;

    private long nameTextMapHash;
    
    private float hpBase;
    private float attackBase;
    private float defenseBase;
    private float critical;
    private float criticalHurt;

    private List<PropGrowCurve> propGrowCurves;
    private int id;
    
    // Transient
Melledy's avatar
Melledy committed
48
	private String name;
Melledy's avatar
Melledy committed
49
	
Melledy's avatar
Melledy committed
50
51
52
53
54
55
    private Int2ObjectMap<String> growthCurveMap;
    private float[] hpGrowthCurve;
    private float[] attackGrowthCurve;
    private float[] defenseGrowthCurve;
    private AvatarSkillDepotData skillDepot;
    private IntList abilities;
Yazawazi's avatar
Yazawazi committed
56
57

    private List<Integer> fetters;
Yazawazi's avatar
Yazawazi committed
58
    private int nameCardRewardId;
Melledy's avatar
Melledy committed
59
    private int nameCardId;
Melledy's avatar
Melledy committed
60
61
62
    
	@Override
	public int getId(){
Melledy's avatar
Melledy committed
63
        return this.id;
Melledy's avatar
Melledy committed
64
65
66
67
68
69
70
    }
    
    public String getName() {
		return name;
	}
    
    public String getBodyType(){
Melledy's avatar
Melledy committed
71
        return this.bodyType;
Melledy's avatar
Melledy committed
72
73
74
    }
    
    public String getQualityType(){
Melledy's avatar
Melledy committed
75
        return this.qualityType;
Melledy's avatar
Melledy committed
76
77
78
    }
    
    public int getChargeEfficiency(){
Melledy's avatar
Melledy committed
79
        return this.chargeEfficiency;
Melledy's avatar
Melledy committed
80
81
82
    }

    public int getInitialWeapon(){
Melledy's avatar
Melledy committed
83
        return this.initialWeapon;
Melledy's avatar
Melledy committed
84
85
86
    }

    public String getWeaponType(){
Melledy's avatar
Melledy committed
87
        return this.weaponType;
Melledy's avatar
Melledy committed
88
89
90
    }

    public String getImageName(){
Melledy's avatar
Melledy committed
91
        return this.imageName;
Melledy's avatar
Melledy committed
92
93
94
    }

    public int getAvatarPromoteId(){
Melledy's avatar
Melledy committed
95
        return this.avatarPromoteId;
Melledy's avatar
Melledy committed
96
97
98
    }

    public String getCutsceneShow(){
Melledy's avatar
Melledy committed
99
        return this.cutsceneShow;
Melledy's avatar
Melledy committed
100
101
102
    }

    public int getSkillDepotId(){
Melledy's avatar
Melledy committed
103
        return this.skillDepotId;
Melledy's avatar
Melledy committed
104
105
106
    }

    public int getStaminaRecoverSpeed(){
Melledy's avatar
Melledy committed
107
        return this.staminaRecoverSpeed;
Melledy's avatar
Melledy committed
108
109
110
    }

    public List<String> getCandSkillDepotIds(){
Melledy's avatar
Melledy committed
111
        return this.candSkillDepotIds;
Melledy's avatar
Melledy committed
112
    }
Melledy's avatar
Melledy committed
113
    
Melledy's avatar
Melledy committed
114
    public String getAvatarIdentityType(){
Melledy's avatar
Melledy committed
115
        return this.avatarIdentityType;
Melledy's avatar
Melledy committed
116
117
118
    }

    public List<Integer> getAvatarPromoteRewardLevelList(){
Melledy's avatar
Melledy committed
119
        return this.avatarPromoteRewardLevelList;
Melledy's avatar
Melledy committed
120
121
122
    }

    public List<Integer> getAvatarPromoteRewardIdList(){
Melledy's avatar
Melledy committed
123
        return this.avatarPromoteRewardIdList;
Melledy's avatar
Melledy committed
124
125
126
127
    }

    public float getBaseHp(int level){
    	try {
Melledy's avatar
Melledy committed
128
    		return this.hpBase * this.hpGrowthCurve[level - 1];
Melledy's avatar
Melledy committed
129
    	} catch (Exception e) {
Melledy's avatar
Melledy committed
130
    		return this.hpBase;
Melledy's avatar
Melledy committed
131
132
133
134
135
    	}
    }
    
    public float getBaseAttack(int level){
        try {
Melledy's avatar
Melledy committed
136
    		return this.attackBase * this.attackGrowthCurve[level - 1];
Melledy's avatar
Melledy committed
137
    	} catch (Exception e) {
Melledy's avatar
Melledy committed
138
    		return this.attackBase;
Melledy's avatar
Melledy committed
139
140
141
142
143
    	}
    }
    
    public float getBaseDefense(int level){
        try {
Melledy's avatar
Melledy committed
144
    		return this.defenseBase * this.defenseGrowthCurve[level - 1];
Melledy's avatar
Melledy committed
145
    	} catch (Exception e) {
Melledy's avatar
Melledy committed
146
    		return this.defenseBase;
Melledy's avatar
Melledy committed
147
148
149
150
    	}
    }
    
    public float getBaseCritical(){
Melledy's avatar
Melledy committed
151
        return this.critical;
Melledy's avatar
Melledy committed
152
153
154
    }
    
    public float getBaseCriticalHurt(){
Melledy's avatar
Melledy committed
155
        return this.criticalHurt;
Melledy's avatar
Melledy committed
156
157
158
159
160
161
162
    }
    
    public float getGrowthCurveById(int level, FightProperty prop) {
    	String growCurve = this.growthCurveMap.get(prop.getId());
    	if (growCurve == null) {
    		return 1f;
    	}
163
    	AvatarCurveData curveData = GameData.getAvatarCurveDataMap().get(level);
Melledy's avatar
Melledy committed
164
165
166
167
168
169
170
    	if (curveData == null) {
    		return 1f;
    	}
		return curveData.getCurveInfos().getOrDefault(growCurve, 1f);
	}

    public long getNameTextMapHash(){
Melledy's avatar
Melledy committed
171
        return this.nameTextMapHash;
Melledy's avatar
Melledy committed
172
173
174
175
176
177
178
179
180
181
    }
    
    public AvatarSkillDepotData getSkillDepot() {
		return skillDepot;
	}
    
	public IntList getAbilities() {
		return abilities;
	}

Yazawazi's avatar
Yazawazi committed
182
183
184
185
    public List<Integer> getFetters() {
        return fetters;
    }

Yazawazi's avatar
Yazawazi committed
186
187
188
189
    public int getNameCardRewardId() {
        return nameCardRewardId;
    }

Yazawazi's avatar
Yazawazi committed
190
191
192
193
    public int getNameCardId() {
        return nameCardId;
    }

Melledy's avatar
Melledy committed
194
195
	@Override
	public void onLoad() {
Melledy's avatar
Melledy committed
196
    	this.skillDepot = GameData.getAvatarSkillDepotDataMap().get(this.skillDepotId);
Yazawazi's avatar
Yazawazi committed
197

198
        // Get fetters from GameData
Melledy's avatar
Melledy committed
199
        this.fetters = GameData.getFetterDataEntries().get(this.id);
Yazawazi's avatar
Yazawazi committed
200
        
Melledy's avatar
Melledy committed
201
202
        if (GameData.getFetterCharacterCardDataMap().get(this.id) != null) {
            this.nameCardRewardId = GameData.getFetterCharacterCardDataMap().get(this.id).getRewardId();
Yazawazi's avatar
Yazawazi committed
203
        }
Yazawazi's avatar
Yazawazi committed
204

205
206
        if (GameData.getRewardDataMap().get(this.nameCardRewardId) != null) {
            this.nameCardId = GameData.getRewardDataMap().get(this.nameCardRewardId).getRewardItemList().get(0).getItemId();
Yazawazi's avatar
Yazawazi committed
207
        }
Melledy's avatar
Melledy committed
208
    	
209
    	int size = GameData.getAvatarCurveDataMap().size();
Melledy's avatar
Melledy committed
210
211
212
    	this.hpGrowthCurve = new float[size];
    	this.attackGrowthCurve = new float[size];
    	this.defenseGrowthCurve = new float[size];
213
    	for (AvatarCurveData curveData : GameData.getAvatarCurveDataMap().values()) {
Melledy's avatar
Melledy committed
214
    		int level = curveData.getLevel() - 1;
Melledy's avatar
Melledy committed
215
    		for (PropGrowCurve growCurve : this.propGrowCurves) {
Melledy's avatar
Melledy committed
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
    			FightProperty prop = FightProperty.getPropByName(growCurve.getType());
    			switch (prop) {
    				case FIGHT_PROP_BASE_HP:
    					this.hpGrowthCurve[level] = curveData.getCurveInfos().get(growCurve.getGrowCurve());
    					break;
    				case FIGHT_PROP_BASE_ATTACK:
    					this.attackGrowthCurve[level] = curveData.getCurveInfos().get(growCurve.getGrowCurve());
    					break;
    				case FIGHT_PROP_BASE_DEFENSE:
    					this.defenseGrowthCurve[level] = curveData.getCurveInfos().get(growCurve.getGrowCurve());
    					break;
    				default:
    					break;
    			}
    		}
    	}
    	
    	/*
    	for (PropGrowCurve growCurve : this.PropGrowCurves) {
    		FightProperty prop = FightProperty.getPropByName(growCurve.getType());
    		this.growthCurveMap.put(prop.getId(), growCurve.getGrowCurve());
    	}
    	*/
    	
    	// Cache abilities
Melledy's avatar
Melledy committed
241
    	String[] split = this.iconName.split("_");
Melledy's avatar
Melledy committed
242
243
244
    	if (split.length > 0) {
    		this.name = split[split.length - 1];
    		
245
    		AbilityEmbryoEntry info = GameData.getAbilityEmbryoInfo().get(this.name);
Melledy's avatar
Melledy committed
246
247
248
249
250
251
252
253
254
255
    		if (info != null) {
    			this.abilities = new IntArrayList(info.getAbilities().length);
    			for (String ability : info.getAbilities()) {
    				this.abilities.add(Utils.abilityHash(ability));
    			}
    		}
    	}
    }
}