AvatarData.java 5.87 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
    private float hpBase;
    private float attackBase;
    private float defenseBase;
    private float critical;
    private float criticalHurt;

    private List<PropGrowCurve> propGrowCurves;
AnimeGitB's avatar
AnimeGitB committed
47
    @Getter(onMethod = @__(@Override))
Melledy's avatar
Melledy committed
48
    private int id;
AnimeGitB's avatar
AnimeGitB committed
49

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

Melledy's avatar
Melledy committed
53
54
55
56
    private Int2ObjectMap<String> growthCurveMap;
    private float[] hpGrowthCurve;
    private float[] attackGrowthCurve;
    private float[] defenseGrowthCurve;
AnimeGitB's avatar
AnimeGitB committed
57
58
59
60
61
62
    @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
63

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

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

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

    public float getBaseCritical() {
Melledy's avatar
Melledy committed
89
        return this.critical;
Melledy's avatar
Melledy committed
90
    }
github-actions's avatar
github-actions committed
91
92

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

Melledy's avatar
Melledy committed
96
    public float getGrowthCurveById(int level, FightProperty prop) {
github-actions's avatar
github-actions committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
        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
111

112
        // Get fetters from GameData
Melledy's avatar
Melledy committed
113
        this.fetters = GameData.getFetterDataEntries().get(this.id);
github-actions's avatar
github-actions committed
114

Melledy's avatar
Melledy committed
115
116
        if (GameData.getFetterCharacterCardDataMap().get(this.id) != null) {
            this.nameCardRewardId = GameData.getFetterCharacterCardDataMap().get(this.id).getRewardId();
Yazawazi's avatar
Yazawazi committed
117
        }
Yazawazi's avatar
Yazawazi committed
118

119
120
        if (GameData.getRewardDataMap().get(this.nameCardRewardId) != null) {
            this.nameCardId = GameData.getRewardDataMap().get(this.nameCardRewardId).getRewardItemList().get(0).getItemId();
Yazawazi's avatar
Yazawazi committed
121
        }
github-actions's avatar
github-actions committed
122
123
124
125
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

        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
167
168
169
    }
}