AvatarData.java 7.01 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
import emu.grasscutter.data.common.PropGrowCurve;
import emu.grasscutter.game.props.FightProperty;
12
import emu.grasscutter.game.props.WeaponType;
Melledy's avatar
Melledy committed
13
14
15
16
17
18
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)
19
public class AvatarData extends GameResource {
Melledy's avatar
Melledy committed
20
	
Melledy's avatar
Melledy committed
21
22
23
24
25
	private String iconName;
    private String bodyType;
    private String qualityType;
    private int chargeEfficiency;
    private int initialWeapon;
26
    private WeaponType weaponType;
Melledy's avatar
Melledy committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    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
49
	private String name;
Melledy's avatar
Melledy committed
50
	
Melledy's avatar
Melledy committed
51
52
53
54
55
56
    private Int2ObjectMap<String> growthCurveMap;
    private float[] hpGrowthCurve;
    private float[] attackGrowthCurve;
    private float[] defenseGrowthCurve;
    private AvatarSkillDepotData skillDepot;
    private IntList abilities;
Yazawazi's avatar
Yazawazi committed
57
58

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

206
207
        if (GameData.getRewardDataMap().get(this.nameCardRewardId) != null) {
            this.nameCardId = GameData.getRewardDataMap().get(this.nameCardRewardId).getRewardItemList().get(0).getItemId();
Yazawazi's avatar
Yazawazi committed
208
        }
Melledy's avatar
Melledy committed
209
    	
210
    	int size = GameData.getAvatarCurveDataMap().size();
Melledy's avatar
Melledy committed
211
212
213
    	this.hpGrowthCurve = new float[size];
    	this.attackGrowthCurve = new float[size];
    	this.defenseGrowthCurve = new float[size];
214
    	for (AvatarCurveData curveData : GameData.getAvatarCurveDataMap().values()) {
Melledy's avatar
Melledy committed
215
    		int level = curveData.getLevel() - 1;
Melledy's avatar
Melledy committed
216
    		for (PropGrowCurve growCurve : this.propGrowCurves) {
Melledy's avatar
Melledy committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
    			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
242
    	String[] split = this.iconName.split("_");
Melledy's avatar
Melledy committed
243
244
245
    	if (split.length > 0) {
    		this.name = split[split.length - 1];
    		
246
    		AbilityEmbryoEntry info = GameData.getAbilityEmbryoInfo().get(this.name);
Melledy's avatar
Melledy committed
247
248
249
250
251
252
253
254
255
256
    		if (info != null) {
    			this.abilities = new IntArrayList(info.getAbilities().length);
    			for (String ability : info.getAbilities()) {
    				this.abilities.add(Utils.abilityHash(ability));
    			}
    		}
    	}
    }
}