AvatarData.java 5.9 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

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

github-actions's avatar
github-actions committed
68
69
70
71
72
73
    public float getBaseHp(int level) {
        try {
            return this.hpBase * this.hpGrowthCurve[level - 1];
        } catch (Exception e) {
            return this.hpBase;
        }
Melledy's avatar
Melledy committed
74
    }
github-actions's avatar
github-actions committed
75
76

    public float getBaseAttack(int level) {
Melledy's avatar
Melledy committed
77
        try {
github-actions's avatar
github-actions committed
78
79
80
81
            return this.attackBase * this.attackGrowthCurve[level - 1];
        } catch (Exception e) {
            return this.attackBase;
        }
Melledy's avatar
Melledy committed
82
    }
github-actions's avatar
github-actions committed
83
84

    public float getBaseDefense(int level) {
Melledy's avatar
Melledy committed
85
        try {
github-actions's avatar
github-actions committed
86
87
88
89
            return this.defenseBase * this.defenseGrowthCurve[level - 1];
        } catch (Exception e) {
            return this.defenseBase;
        }
Melledy's avatar
Melledy committed
90
    }
github-actions's avatar
github-actions committed
91
92

    public float getBaseCritical() {
Melledy's avatar
Melledy committed
93
        return this.critical;
Melledy's avatar
Melledy committed
94
    }
github-actions's avatar
github-actions committed
95
96

    public float getBaseCriticalHurt() {
Melledy's avatar
Melledy committed
97
        return this.criticalHurt;
Melledy's avatar
Melledy committed
98
    }
github-actions's avatar
github-actions committed
99

Melledy's avatar
Melledy committed
100
    public float getGrowthCurveById(int level, FightProperty prop) {
github-actions's avatar
github-actions committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
        String growCurve = this.growthCurveMap.get(prop.getId());
        if (growCurve == null) {
            return 1f;
        }
        AvatarCurveData curveData = GameData.getAvatarCurveDataMap().get(level);
        if (curveData == null) {
            return 1f;
        }
        return curveData.getCurveInfos().getOrDefault(growCurve, 1f);
    }

    @Override
    public void onLoad() {
        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);
github-actions's avatar
github-actions 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
        }
github-actions's avatar
github-actions committed
126
127
128
129
130
131
132
133
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
159
160
161
162
163
164
165
166
167
168
169
170

        int size = GameData.getAvatarCurveDataMap().size();
        this.hpGrowthCurve = new float[size];
        this.attackGrowthCurve = new float[size];
        this.defenseGrowthCurve = new float[size];
        for (AvatarCurveData curveData : GameData.getAvatarCurveDataMap().values()) {
            int level = curveData.getLevel() - 1;
            for (PropGrowCurve growCurve : this.propGrowCurves) {
                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
        String[] split = this.iconName.split("_");
        if (split.length > 0) {
            this.name = split[split.length - 1];

            AbilityEmbryoEntry info = GameData.getAbilityEmbryoInfo().get(this.name);
            if (info != null) {
                this.abilities = new IntArrayList(info.getAbilities().length);
                for (String ability : info.getAbilities()) {
                    this.abilities.add(Utils.abilityHash(ability));
                }
            }
        }
Melledy's avatar
Melledy committed
171
172
173
    }
}