147 lines
4.1 KiB
Java
147 lines
4.1 KiB
Java
package com.io.yaohun.myitems.data;
|
|
|
|
import com.io.yaohun.myitems.api.AttributeType;
|
|
import com.io.yaohun.myitems.api.EquipmentSlotType;
|
|
import com.io.yaohun.myitems.api.TierType;
|
|
import com.io.yaohun.myitems.util.RandomBuilder;
|
|
import com.io.yaohun.myitems.util.RandomUtil;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class ItemTemplate {
|
|
|
|
private String itemId;
|
|
private ItemStack itemStack;
|
|
private Material material;
|
|
private String displayName;
|
|
private List<String> lore;
|
|
|
|
private String itemIcon;
|
|
|
|
private EquipmentSlotType equipSlotType;
|
|
|
|
private Map<TierType, Double> tierTypes = new HashMap<>();
|
|
private Map<TierType, TierAttribute> tierAttributes = new HashMap<>();
|
|
private String suitId;
|
|
|
|
|
|
public ItemTemplate(String itemId, String itemIcon,ItemStack itemStack,
|
|
Material material, String displayName,
|
|
List<String> lore, EquipmentSlotType equipSlotType,
|
|
Map<TierType, Double> tierTypes, Map<TierType, TierAttribute> tierAttributes,
|
|
String suitId) {
|
|
this.itemId = itemId;
|
|
this.itemIcon = itemIcon;
|
|
this.itemStack = itemStack;
|
|
this.material = material;
|
|
this.displayName = displayName;
|
|
this.lore = lore;
|
|
this.equipSlotType = equipSlotType;
|
|
this.tierTypes = tierTypes;
|
|
this.tierAttributes = tierAttributes;
|
|
this.suitId = suitId;
|
|
}
|
|
|
|
public String getItemId() {
|
|
return itemId;
|
|
}
|
|
|
|
public String getItemIcon() {
|
|
return itemIcon;
|
|
}
|
|
|
|
public Material getMaterial() {
|
|
return material;
|
|
}
|
|
|
|
public String getDisplayName() {
|
|
return displayName;
|
|
}
|
|
|
|
public List<String> getLore() {
|
|
return lore;
|
|
}
|
|
|
|
public ItemStack getItemStack() {
|
|
return itemStack;
|
|
}
|
|
|
|
public EquipmentSlotType getEquipSlotType() {
|
|
return equipSlotType;
|
|
}
|
|
|
|
public Map<String,Double> getTierTypes() {
|
|
Map<String,Double> chanceMap = new HashMap<>();
|
|
for (Map.Entry<TierType, Double> entry : tierTypes.entrySet()){
|
|
chanceMap.put(entry.getKey().name(),entry.getValue());
|
|
}
|
|
return chanceMap;
|
|
}
|
|
|
|
public Map<TierType, TierAttribute> getTierAttributes() {
|
|
return tierAttributes;
|
|
}
|
|
|
|
public String getSuitId() {
|
|
return suitId;
|
|
}
|
|
|
|
public TierType getRandomTierType() {
|
|
Map<String,Double> chanceMap = getTierTypes();
|
|
RandomBuilder<String> builder = new RandomBuilder<>(chanceMap);
|
|
return TierType.valueOf(builder.random());
|
|
}
|
|
|
|
public TierAttribute getTierAttribute(TierType tierType){
|
|
return tierAttributes.get(tierType);
|
|
}
|
|
|
|
public int getCurrentDurability(TierType tierType){
|
|
return getTierAttribute(tierType).currentDurability;
|
|
}
|
|
|
|
public int getMaxDurability(TierType tierType){
|
|
return getTierAttribute(tierType).maxDurability;
|
|
}
|
|
|
|
public Map<AttributeType, AttributeRandomValue> getAttributes(TierType tierType){
|
|
return getTierAttribute(tierType).getAttributes();
|
|
}
|
|
|
|
public static class TierAttribute {
|
|
|
|
private int currentDurability;
|
|
private int maxDurability;
|
|
|
|
private Map<AttributeType, AttributeRandomValue> attributes = new HashMap<>();
|
|
|
|
public TierAttribute(int currentDurability, int maxDurability, Map<AttributeType, AttributeRandomValue> attributes) {
|
|
this.currentDurability = currentDurability;
|
|
this.maxDurability = maxDurability;
|
|
this.attributes = attributes;
|
|
}
|
|
|
|
public Map<AttributeType, AttributeRandomValue> getAttributes() {
|
|
return attributes;
|
|
}
|
|
}
|
|
|
|
public static class AttributeRandomValue {
|
|
private double min;
|
|
private double max;
|
|
|
|
public AttributeRandomValue(double min, double max) {
|
|
this.min = min;
|
|
this.max = max;
|
|
}
|
|
|
|
public double getRandomValue(){
|
|
return RandomUtil.getRandomDouble(min, max, 2);
|
|
}
|
|
}
|
|
}
|