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 lore; private String itemIcon; private EquipmentSlotType equipSlotType; private Map tierTypes = new HashMap<>(); private Map tierAttributes = new HashMap<>(); private String suitId; public ItemTemplate(String itemId, String itemIcon,ItemStack itemStack, Material material, String displayName, List lore, EquipmentSlotType equipSlotType, Map tierTypes, Map 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 getLore() { return lore; } public ItemStack getItemStack() { return itemStack; } public EquipmentSlotType getEquipSlotType() { return equipSlotType; } public Map getTierTypes() { Map chanceMap = new HashMap<>(); for (Map.Entry entry : tierTypes.entrySet()){ chanceMap.put(entry.getKey().name(),entry.getValue()); } return chanceMap; } public Map getTierAttributes() { return tierAttributes; } public String getSuitId() { return suitId; } public TierType getRandomTierType() { Map chanceMap = getTierTypes(); RandomBuilder 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 getAttributes(TierType tierType){ return getTierAttribute(tierType).getAttributes(); } public static class TierAttribute { private int currentDurability; private int maxDurability; private Map attributes = new HashMap<>(); public TierAttribute(int currentDurability, int maxDurability, Map attributes) { this.currentDurability = currentDurability; this.maxDurability = maxDurability; this.attributes = attributes; } public Map 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); } } }