AvatarData.java 5.53 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
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;
AnimeGitB's avatar
AnimeGitB committed
17
import lombok.Getter;
Melledy's avatar
Melledy committed
18
19

@ResourceType(name = "AvatarExcelConfigData.json", loadPriority = LoadPriority.LOW)
20
public class AvatarData extends GameResource {
Melledy's avatar
Melledy committed
21

AnimeGitB's avatar
AnimeGitB committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    private String iconName;
    @Getter private String bodyType;
    @Getter private String qualityType;
    @Getter private int chargeEfficiency;
    @Getter private int initialWeapon;
    @Getter private WeaponType weaponType;
    @Getter private String imageName;
    @Getter private int avatarPromoteId;
    @Getter private String cutsceneShow;
    @Getter private int skillDepotId;
    @Getter private int staminaRecoverSpeed;
    @Getter private List<String> candSkillDepotIds;
    @Getter private String avatarIdentityType;
    @Getter private List<Integer> avatarPromoteRewardLevelList;
    @Getter private List<Integer> avatarPromoteRewardIdList;

    @Getter private long nameTextMapHash;

Melledy's avatar
Melledy committed
40
41
42
43
44
45
46
47
    private float hpBase;
    private float attackBase;
    private float defenseBase;
    private float critical;
    private float criticalHurt;

    private List<PropGrowCurve> propGrowCurves;
    private int id;
AnimeGitB's avatar
AnimeGitB committed
48

Melledy's avatar
Melledy committed
49
    // Transient
AnimeGitB's avatar
AnimeGitB committed
50
51
    @Getter private String name;

Melledy's avatar
Melledy committed
52
53
54
55
    private Int2ObjectMap<String> growthCurveMap;
    private float[] hpGrowthCurve;
    private float[] attackGrowthCurve;
    private float[] defenseGrowthCurve;
AnimeGitB's avatar
AnimeGitB committed
56
57
58
59
60
61
    @Getter private AvatarSkillDepotData skillDepot;
    @Getter private IntList abilities;

    @Getter private List<Integer> fetters;
    @Getter private int nameCardRewardId;
    @Getter private int nameCardId;
Yazawazi's avatar
Yazawazi committed
62

Melledy's avatar
Melledy committed
63
64
	@Override
	public int getId(){
Melledy's avatar
Melledy committed
65
        return this.id;
Melledy's avatar
Melledy committed
66
67
68
69
    }

    public float getBaseHp(int level){
    	try {
Melledy's avatar
Melledy committed
70
    		return this.hpBase * this.hpGrowthCurve[level - 1];
Melledy's avatar
Melledy committed
71
    	} catch (Exception e) {
Melledy's avatar
Melledy committed
72
    		return this.hpBase;
Melledy's avatar
Melledy committed
73
74
75
76
77
    	}
    }
    
    public float getBaseAttack(int level){
        try {
Melledy's avatar
Melledy committed
78
    		return this.attackBase * this.attackGrowthCurve[level - 1];
Melledy's avatar
Melledy committed
79
    	} catch (Exception e) {
Melledy's avatar
Melledy committed
80
    		return this.attackBase;
Melledy's avatar
Melledy committed
81
82
83
84
85
    	}
    }
    
    public float getBaseDefense(int level){
        try {
Melledy's avatar
Melledy committed
86
    		return this.defenseBase * this.defenseGrowthCurve[level - 1];
Melledy's avatar
Melledy committed
87
    	} catch (Exception e) {
Melledy's avatar
Melledy committed
88
    		return this.defenseBase;
Melledy's avatar
Melledy committed
89
90
91
92
    	}
    }
    
    public float getBaseCritical(){
Melledy's avatar
Melledy committed
93
        return this.critical;
Melledy's avatar
Melledy committed
94
95
96
    }
    
    public float getBaseCriticalHurt(){
Melledy's avatar
Melledy committed
97
        return this.criticalHurt;
Melledy's avatar
Melledy committed
98
99
100
101
102
103
104
    }
    
    public float getGrowthCurveById(int level, FightProperty prop) {
    	String growCurve = this.growthCurveMap.get(prop.getId());
    	if (growCurve == null) {
    		return 1f;
    	}
105
    	AvatarCurveData curveData = GameData.getAvatarCurveDataMap().get(level);
Melledy's avatar
Melledy committed
106
107
108
109
110
111
112
113
    	if (curveData == null) {
    		return 1f;
    	}
		return curveData.getCurveInfos().getOrDefault(growCurve, 1f);
	}

	@Override
	public void onLoad() {
Melledy's avatar
Melledy committed
114
    	this.skillDepot = GameData.getAvatarSkillDepotDataMap().get(this.skillDepotId);
Yazawazi's avatar
Yazawazi committed
115

116
        // Get fetters from GameData
Melledy's avatar
Melledy committed
117
        this.fetters = GameData.getFetterDataEntries().get(this.id);
Yazawazi's avatar
Yazawazi committed
118
        
Melledy's avatar
Melledy committed
119
120
        if (GameData.getFetterCharacterCardDataMap().get(this.id) != null) {
            this.nameCardRewardId = GameData.getFetterCharacterCardDataMap().get(this.id).getRewardId();
Yazawazi's avatar
Yazawazi committed
121
        }
Yazawazi's avatar
Yazawazi committed
122

123
124
        if (GameData.getRewardDataMap().get(this.nameCardRewardId) != null) {
            this.nameCardId = GameData.getRewardDataMap().get(this.nameCardRewardId).getRewardItemList().get(0).getItemId();
Yazawazi's avatar
Yazawazi committed
125
        }
Melledy's avatar
Melledy committed
126
    	
127
    	int size = GameData.getAvatarCurveDataMap().size();
Melledy's avatar
Melledy committed
128
129
130
    	this.hpGrowthCurve = new float[size];
    	this.attackGrowthCurve = new float[size];
    	this.defenseGrowthCurve = new float[size];
131
    	for (AvatarCurveData curveData : GameData.getAvatarCurveDataMap().values()) {
Melledy's avatar
Melledy committed
132
    		int level = curveData.getLevel() - 1;
Melledy's avatar
Melledy committed
133
    		for (PropGrowCurve growCurve : this.propGrowCurves) {
Melledy's avatar
Melledy committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
    			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
159
    	String[] split = this.iconName.split("_");
Melledy's avatar
Melledy committed
160
161
162
    	if (split.length > 0) {
    		this.name = split[split.length - 1];
    		
163
    		AbilityEmbryoEntry info = GameData.getAbilityEmbryoInfo().get(this.name);
Melledy's avatar
Melledy committed
164
165
166
167
168
169
170
171
172
173
    		if (info != null) {
    			this.abilities = new IntArrayList(info.getAbilities().length);
    			for (String ability : info.getAbilities()) {
    				this.abilities.add(Utils.abilityHash(ability));
    			}
    		}
    	}
    }
}