Skip to content

Commit

Permalink
Refactor excel datas (Mainly item data)
Browse files Browse the repository at this point in the history
  • Loading branch information
Melledy authored and Melledy committed Jul 22, 2022
1 parent c041806 commit f15262d
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 202 deletions.
18 changes: 5 additions & 13 deletions src/main/java/emu/grasscutter/data/common/ItemUseData.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
package emu.grasscutter.data.common;

import java.util.List;
import emu.grasscutter.game.props.ItemUseOp;

public class ItemUseData {
private String useOp;
private List<String> useParam;
private ItemUseOp useOp;
private String[] useParam;

public String getUseOp() {
public ItemUseOp getUseOp() {
return useOp;
}

public void setUseOp(String useOp) {
this.useOp = useOp;
}

public List<String> getUseParam() {
public String[] getUseParam() {
return useParam;
}

public void setUseParam(List<String> useParam) {
this.useParam = useParam;
}
}
17 changes: 0 additions & 17 deletions src/main/java/emu/grasscutter/data/excels/AvatarSkillData.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ public class AvatarSkillData extends GameResource {
private boolean isAttackCameraLock;
private int proudSkillGroupId;
private ElementType costElemType;
private List<Float> lockWeightParams;

private long nameTextMapHash;

private String abilityName;
private String lockShape;
private String globalValueKey;

@Override
public int getId(){
Expand Down Expand Up @@ -58,25 +53,13 @@ public ElementType getCostElemType() {
return costElemType;
}

public List<Float> getLockWeightParams() {
return lockWeightParams;
}

public long getNameTextMapHash() {
return nameTextMapHash;
}

public String getAbilityName() {
return abilityName;
}

public String getLockShape() {
return lockShape;
}

public String getGlobalValueKey() {
return globalValueKey;
}

@Override
public void onLoad() {
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/emu/grasscutter/data/excels/GadgetData.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public class GadgetData extends GameResource {
private boolean isInteractive;
private String[] tags;
private String itemJsonName;
private String inteeIconName;
private long nameTextMapHash;
private int campID;
private String LODPatternName;

@Override
public int getId() {
Expand All @@ -43,10 +41,6 @@ public String getItemJsonName() {
return itemJsonName;
}

public String getInteeIconName() {
return inteeIconName;
}

public long getNameTextMapHash() {
return nameTextMapHash;
}
Expand All @@ -55,8 +49,6 @@ public int getCampID() {
return campID;
}

public String getLODPatternName() { return LODPatternName; }

@Override
public void onLoad() {

Expand Down
161 changes: 62 additions & 99 deletions src/main/java/emu/grasscutter/data/excels/ItemData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package emu.grasscutter.data.excels;

import java.util.Arrays;
import java.util.List;

import com.google.gson.annotations.SerializedName;
Expand All @@ -8,6 +9,7 @@
import emu.grasscutter.data.common.ItemUseData;
import emu.grasscutter.game.inventory.*;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.ItemUseTarget;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import lombok.Getter;
Expand All @@ -17,152 +19,113 @@
"ReliquaryExcelConfigData.json",
"HomeWorldFurnitureExcelConfigData.json"
})
@Getter
public class ItemData extends GameResource {

// Main
private int id;
@Getter private int stackLimit = 1;
@Getter private int maxUseCount;
@Getter private int rankLevel;
@Getter private String effectName;
@Getter private int[] satiationParams;
@Getter private int rank;
@Getter private int weight;
@Getter private int gadgetId;

@Getter private int[] destroyReturnMaterial;
@Getter private int[] destroyReturnMaterialCount;

@Getter private List<ItemUseData> itemUse;

// Food
@Getter private String foodQuality;
@Getter private String useTarget;
private String[] iseParam;

// String enums
private String itemType;
private String materialType;
private String equipType;
private int stackLimit = 1;
private int maxUseCount;
private int rankLevel;
private String effectName;
private int rank;
private int weight;
private int gadgetId;

private int[] destroyReturnMaterial;
private int[] destroyReturnMaterialCount;

// Enums
private ItemType itemType = ItemType.ITEM_NONE;
private MaterialType materialType = MaterialType.MATERIAL_NONE;
private EquipType equipType = EquipType.EQUIP_NONE;
private String effectType;
private String destroyRule;

// Post load enum forms of above
private transient MaterialType materialEnumType;
private transient ItemType itemEnumType;
private transient EquipType equipEnumType;
// Food
private String foodQuality;
private int[] satiationParams;

// Usable item
private ItemUseTarget useTarget;
private List<ItemUseData> itemUse;

// Relic
@Getter private int mainPropDepotId;
@Getter private int appendPropDepotId;
@Getter private int appendPropNum;
@Getter private int setId;
private int mainPropDepotId;
private int appendPropDepotId;
private int appendPropNum;
private int setId;
private int[] addPropLevels;
@Getter private int baseConvExp;
@Getter private int maxLevel;
private int baseConvExp;
private int maxLevel;

// Weapon
@Getter private int weaponPromoteId;
@Getter private int weaponBaseExp;
@Getter private int storyId;
@Getter private int avatarPromoteId;
@Getter private int awakenMaterial;
@Getter private int[] awakenCosts;
@Getter private int[] skillAffix;
private int weaponPromoteId;
private int weaponBaseExp;
private int storyId;
private int avatarPromoteId;
private int awakenMaterial;
private int[] awakenCosts;
private int[] skillAffix;
private WeaponProperty[] weaponProp;

// Hash
@Getter private String icon;
@Getter private long nameTextMapHash;

@Getter private IntSet addPropLevelSet;
private long nameTextMapHash;

// Furniture
@Getter private int comfort;
@Getter private List<Integer> furnType;
@Getter private List<Integer> furnitureGadgetID;
private int comfort;
private List<Integer> furnType;
private List<Integer> furnitureGadgetID;
@SerializedName("JFDLJGDFIGL")
@Getter private int roomSceneId;
private int roomSceneId;

// Custom
private transient IntSet addPropLevelSet;

@Override
public int getId(){
return this.id;
}

public String getMaterialTypeString(){
return this.materialType;
}

public String[] getUseParam(){
return this.iseParam;
}

public String getItemTypeString(){
return this.itemType;
}

public WeaponProperty[] getWeaponProperties() {
return weaponProp;
}

public ItemType getItemType() {
return this.itemEnumType;
}

public MaterialType getMaterialType() {
return this.materialEnumType;
}

public EquipType getEquipType() {
return this.equipEnumType;
public WeaponProperty[] getWeaponProperties() {
return this.weaponProp;
}

public boolean canAddRelicProp(int level) {
return this.addPropLevelSet != null && this.addPropLevelSet.contains(level);
}

public boolean isEquip() {
return this.itemEnumType == ItemType.ITEM_RELIQUARY || this.itemEnumType == ItemType.ITEM_WEAPON;
return this.itemType == ItemType.ITEM_RELIQUARY || this.itemType == ItemType.ITEM_WEAPON;
}

@Override
public void onLoad() {
this.itemEnumType = ItemType.getTypeByName(getItemTypeString());
this.materialEnumType = MaterialType.getTypeByName(getMaterialTypeString());

if (this.itemEnumType == ItemType.ITEM_RELIQUARY) {
this.equipEnumType = EquipType.getTypeByName(this.equipType);
if (this.itemType == ItemType.ITEM_RELIQUARY) {
if (this.addPropLevels != null && this.addPropLevels.length > 0) {
this.addPropLevelSet = new IntOpenHashSet(this.addPropLevels);
}
} else if (this.itemEnumType == ItemType.ITEM_WEAPON) {
this.equipEnumType = EquipType.EQUIP_WEAPON;
} else if (this.itemType == ItemType.ITEM_WEAPON) {
this.equipType = EquipType.EQUIP_WEAPON;
} else {
this.equipEnumType = EquipType.EQUIP_NONE;
this.equipType = EquipType.EQUIP_NONE;
}

if (this.getWeaponProperties() != null) {
for (WeaponProperty weaponProperty : this.getWeaponProperties()) {
weaponProperty.onLoad();
}
if (this.weaponProp != null) {
this.weaponProp = Arrays.stream(this.weaponProp).filter(prop -> prop.getPropType() != null).toArray(WeaponProperty[]::new);
}

if(this.getFurnType() != null){
if (this.getFurnType() != null) {
this.furnType = this.furnType.stream().filter(x -> x > 0).toList();
}
if(this.getFurnitureGadgetID() != null){
if (this.getFurnitureGadgetID() != null) {
this.furnitureGadgetID = this.furnitureGadgetID.stream().filter(x -> x > 0).toList();
}
}

@Getter
public static class WeaponProperty {
@Getter private FightProperty fightProp;
@Getter private String propType;
@Getter private float initValue;
@Getter private String type;

public void onLoad() {
this.fightProp = FightProperty.getPropByName(propType);
}

private FightProperty propType;
private float initValue;
private String type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class MonsterDescribeData extends GameResource {
private long nameTextMapHash;
private int titleID;
private int specialNameLabID;
private String icon;

@Override
public int getId() {
Expand All @@ -29,10 +28,6 @@ public int getSpecialNameLabID() {
return specialNameLabID;
}

public String getIcon() {
return icon;
}

@Override
public void onLoad() {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emu/grasscutter/game/avatar/Avatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public void recalcStats(boolean forceSendAbilityChange) {
WeaponCurveData curveData = GameData.getWeaponCurveDataMap().get(weapon.getLevel());
if (curveData != null) {
for (WeaponProperty weaponProperty : weapon.getItemData().getWeaponProperties()) {
this.addFightProperty(weaponProperty.getFightProp(), weaponProperty.getInitValue() * curveData.getMultByProp(weaponProperty.getType()));
this.addFightProperty(weaponProperty.getPropType(), weaponProperty.getInitValue() * curveData.getMultByProp(weaponProperty.getType()));
}
}
// Weapon promotion stats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.BattlePassMissionRefreshType;
import emu.grasscutter.game.props.BattlePassMissionStatus;
import emu.grasscutter.game.props.ItemUseOp;
import emu.grasscutter.game.props.WatcherTriggerType;
import emu.grasscutter.net.proto.BattlePassCycleOuterClass.BattlePassCycle;
import emu.grasscutter.net.proto.BattlePassUnlockStatusOuterClass.BattlePassUnlockStatus;
Expand Down Expand Up @@ -195,7 +196,7 @@ private void takeRewardsFromSelectChest(ItemData rewardItemData, int index, Item
}

// Get possible item choices.
String[] choices = rewardItemData.getItemUse().get(0).getUseParam().get(0).split(",");
String[] choices = rewardItemData.getItemUse().get(0).getUseParam()[0].split(",");
if (choices.length < index) {
return;
}
Expand All @@ -205,7 +206,7 @@ private void takeRewardsFromSelectChest(ItemData rewardItemData, int index, Item
int chosenId = Integer.parseInt(choices[index - 1]);

// For ITEM_USE_ADD_SELECT_ITEM chests, we can directly add the item specified in the chest's data.
if (rewardItemData.getItemUse().get(0).getUseOp().equals("ITEM_USE_ADD_SELECT_ITEM")) {
if (rewardItemData.getItemUse().get(0).getUseOp() == ItemUseOp.ITEM_USE_ADD_SELECT_ITEM) {
GameItem rewardItem = new GameItem(GameData.getItemDataMap().get(chosenId), entry.getItemCount());
rewardItems.add(rewardItem);
}
Expand Down
Loading

0 comments on commit f15262d

Please sign in to comment.