diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 0109655..eb1c72b 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -11,4 +11,9 @@
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index c6be38f..0515000 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,6 +18,17 @@
+
+ maven-compiler-plugin
+
+ 1.8
+ 1.8
+ UTF-8
+
+ lib
+
+
+
org.apache.maven.plugins
maven-compiler-plugin
diff --git a/src/main/java/com/yuyu/srappraise/appraise/AppraiseGuiService.java b/src/main/java/com/yuyu/srappraise/appraise/AppraiseGuiService.java
index 226e390..4bdffeb 100644
--- a/src/main/java/com/yuyu/srappraise/appraise/AppraiseGuiService.java
+++ b/src/main/java/com/yuyu/srappraise/appraise/AppraiseGuiService.java
@@ -9,6 +9,7 @@ import com.yuyu.srappraise.pojo.AppraiseProduct;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
@@ -34,12 +35,14 @@ public class AppraiseGuiService extends GermGuiScreen {
private HashMap germGuiSlotHashMap;
private List itemStackHashMap;
private int index;
+ Random random;
public AppraiseGuiService(ConfigurationSection configurationSection, String guiName) {
super(guiName, configurationSection);
this.index = 0;
this.germGuiSlotHashMap = new HashMap<>();
this.itemStackHashMap = new ArrayList<>();
+ this.random = new Random();
// //TODO(此处绑定给 √ 按钮绑定一个监听事件,在监听事件中获取放入了物品槽位的物品,然后鉴定)
this.getSoltGui();
this.soltRegister();
@@ -311,7 +314,7 @@ public class AppraiseGuiService extends GermGuiScreen {
}
- Random random = new Random();
+
HashMap itemStacks= new LinkedHashMap<>();
//获取物品槽
GermGuiSlot slot_biomass = this.germGuiSlotHashMap.get("slotConsume");
@@ -353,27 +356,36 @@ public class AppraiseGuiService extends GermGuiScreen {
HashMap stringAppraiseProductHashMap =
SrAppraise.getConfigManager().getAppraiseItemMap().get(itemName);
+ int countInt = SrAppraise.getConfigManager().getCountInt().get(itemName);
//如果同时鉴定多个
for (int i = 0; i < amount.get(); i++) {
//利用Random生成一个随机数来确定产物
- float probility = random.nextFloat();
- for (String product : stringAppraiseProductHashMap.keySet()) {
- AppraiseProduct appraiseProduct = stringAppraiseProductHashMap.get(product);
- if (probility >= appraiseProduct.getProMin() && probility < appraiseProduct.getProMax()) {
- //概率通过,获取该产物 TODO(此处注意,appraiseProduct对象中的产物只能用来展示鉴定!不能做出任何修改!!!)
- ItemStack item =
- SrItemAPI.getItem(appraiseProduct.getIndexName(),new HashMap<>(),null,true,true);
- //获取产物后,将产物String,ItemStack K-V 的形式存到map中
- if (itemStacks.containsKey(product)) {
- ItemStack itemStack1 = itemStacks.get(product);
- itemStack1.setAmount(itemStack1.getAmount() + 1);
- break;
- }else {
- itemStacks.put(product, item);
- break;
- }
- }
+// float probility = random.nextFloat();
+// for (String product : stringAppraiseProductHashMap.keySet()) {
+// AppraiseProduct appraiseProduct = stringAppraiseProductHashMap.get(product);
+// if (probility >= appraiseProduct.getProMin() && probility < appraiseProduct.getProMax()) {
+// //概率通过,获取该产物 TODO(此处注意,appraiseProduct对象中的产物只能用来展示鉴定!不能做出任何修改!!!)
+// ItemStack item =
+// SrItemAPI.getItem(appraiseProduct.getIndexName(),new HashMap<>(),null,true,true);
+// //获取产物后,将产物String,ItemStack K-V 的形式存到map中
+// if (itemStacks.containsKey(product)) {
+// ItemStack itemStack1 = itemStacks.get(product);
+// itemStack1.setAmount(itemStack1.getAmount() + 1);
+// break;
+// }else {
+// itemStacks.put(product, item);
+// break;
+// }
+// }
+// }
+ String index1 = getIndex(itemName, countInt, stringAppraiseProductHashMap);
+ ItemStack item = SrItemAPI.getItem(index1, new HashMap<>(), clickPlayer, true, true);
+ if (itemStacks.containsKey(index1)) {
+ ItemStack itemStack1 = itemStacks.get(index1);
+ itemStack1.setAmount(itemStack1.getAmount()+1);
+ }else {
+ itemStacks.put(index1,item);
}
}
@@ -444,4 +456,22 @@ public class AppraiseGuiService extends GermGuiScreen {
}, GermGuiButton.EventType.LEFT_CLICK);
}
+
+ public String getIndex(String itemName,int countInt, HashMap productS){
+ if (itemName == null || countInt == 0 || productS == null || productS.size() == 0){
+ SrAppraise.getInstance().getLogger().info(ChatColor.RED+"itemName|countInt|productS==null");
+ return null;
+ }
+ int rand = random.nextInt(countInt) + 1;
+ int start = 0;
+ //循环确定权重位置
+ for (String s : productS.keySet()){
+ AppraiseProduct appraiseProduct = productS.get(s);
+ if (rand >= start && rand <= start+appraiseProduct.getWeight()){
+ return appraiseProduct.getIndexName();
+ }
+ start += appraiseProduct.getWeight();
+ }
+ return null;
+ }
}
diff --git a/src/main/java/com/yuyu/srappraise/config/ConfigManager.java b/src/main/java/com/yuyu/srappraise/config/ConfigManager.java
index bb13884..159051d 100644
--- a/src/main/java/com/yuyu/srappraise/config/ConfigManager.java
+++ b/src/main/java/com/yuyu/srappraise/config/ConfigManager.java
@@ -25,6 +25,7 @@ import java.util.logging.Logger;
public class ConfigManager {
//用于存放鉴定的物品,根据玩家放入的物品,获取名称,用于此map集合获取可能得到的物品集合,然后随机数判断
private HashMap> appraiseItemMap;
+ private HashMap countInt;
private Plugin plugin;
public HashMap> getAppraiseItemMap() {
@@ -34,6 +35,7 @@ public class ConfigManager {
public ConfigManager(Plugin plugin) {
Logger logger = plugin.getLogger();
this.plugin = plugin;
+ this.countInt = new HashMap<>();
HashMap> hashMapHashMap = new HashMap<>();
@@ -59,21 +61,20 @@ public class ConfigManager {
//读取该物品可以得到的产物
List productList = appraiseToProduct.getStringList("SrItem." + srItem);
-
+ int count = 0;
for (String product : productList){
//读取配置文件中的数据
- Double proMax = itemAppraiseProduct.getDouble("SrItem."+srItem+"."+product+".probabilityMax");
- Double proMin = itemAppraiseProduct.getDouble("SrItem."+srItem+"."+product+".probabilityMin");
+ int weight = itemAppraiseProduct.getInt("SrItem."+srItem+"."+product+".weight");
String index = itemAppraiseProduct.getString("SrItem."+srItem+"."+product+".index");
- AppraiseProduct appraiseProduct = new AppraiseProduct(product, index, proMax, proMin);
-
+ AppraiseProduct appraiseProduct = new AppraiseProduct(product, index, weight);
+ count+=weight;
logger.info(ChatColor.AQUA+"鉴定物品:"+srItem+"产物:"+ appraiseProduct.toString());
//针对产物存放
productMap.put(product,appraiseProduct);
}
-
+ countInt.put(srItem,count);
//针对鉴定物品存放
hashMapHashMap.put(srItem,productMap);
}
@@ -83,7 +84,7 @@ public class ConfigManager {
public void reloadConfig(){
appraiseItemMap.clear();
-
+ countInt.clear();
plugin.reloadConfig();
HashMap> hashMapHashMap = new HashMap<>();
@@ -110,25 +111,36 @@ public class ConfigManager {
//读取该物品可以得到的产物
List productList = appraiseToProduct.getStringList("SrItem." + srItem);
-
+ int count = 0;
for (String product : productList){
//读取配置文件中的数据
- Double proMax = itemAppraiseProduct.getDouble("SrItem."+srItem+"."+product+".probabilityMax");
- Double proMin = itemAppraiseProduct.getDouble("SrItem."+srItem+"."+product+".probabilityMin");
+ int weight = itemAppraiseProduct.getInt("SrItem."+srItem+"."+product+".weight");
String index = itemAppraiseProduct.getString("SrItem."+srItem+"."+product+".index");
- AppraiseProduct appraiseProduct = new AppraiseProduct(product, index, proMax, proMin);
+ AppraiseProduct appraiseProduct = new AppraiseProduct(product, index, weight);
this.plugin.getLogger().info(ChatColor.AQUA+"鉴定物品:"+srItem+"产物:"+ appraiseProduct.toString());
-
+ count+=weight;
//针对产物存放
productMap.put(product,appraiseProduct);
}
-
+ this.countInt.put(srItem,count);
//针对鉴定物品存放
hashMapHashMap.put(srItem,productMap);
}
this.appraiseItemMap = hashMapHashMap;
}
+
+ public void setAppraiseItemMap(HashMap> appraiseItemMap) {
+ this.appraiseItemMap = appraiseItemMap;
+ }
+
+ public HashMap getCountInt() {
+ return countInt;
+ }
+
+ public void setCountInt(HashMap countInt) {
+ this.countInt = countInt;
+ }
}
diff --git a/src/main/java/com/yuyu/srappraise/pojo/AppraiseProduct.java b/src/main/java/com/yuyu/srappraise/pojo/AppraiseProduct.java
index b5525ad..e3d35f1 100644
--- a/src/main/java/com/yuyu/srappraise/pojo/AppraiseProduct.java
+++ b/src/main/java/com/yuyu/srappraise/pojo/AppraiseProduct.java
@@ -19,10 +19,9 @@ public class AppraiseProduct {
private final String ItemName;
//物品的索引
private final String indexName;
- //最大的概率
- private final double ProMax;
- //最小的概率
- private final double ProMin;
+ //权重
+ private final int weight;
+
//获取ItemStack
private final ItemStack itemStack;
@@ -34,19 +33,14 @@ public class AppraiseProduct {
return indexName;
}
- public double getProMax() {
- return ProMax;
+ public int getWeight() {
+ return weight;
}
- public double getProMin() {
- return ProMin;
- }
-
- public AppraiseProduct(String itemName, String indexName, double proMax, double proMin) {
+ public AppraiseProduct(String itemName, String indexName, int weight) {
ItemName = itemName;
this.indexName = indexName;
- ProMax = proMax;
- ProMin = proMin;
+ this.weight = weight;
this.itemStack = SrItemAPI.getItem(indexName,new HashMap<>(),null,true,true);
}
@@ -59,8 +53,7 @@ public class AppraiseProduct {
return "AppraiseProduct{" +
"ItemName='" + ItemName + '\'' +
", indexName='" + indexName + '\'' +
- ", ProMax=" + ProMax +
- ", ProMin=" + ProMin +
+ ",weight=" + weight +
", itemStack=" + itemStack +
'}';
}
diff --git a/src/main/resources/ItemAppraiseProduct.yml b/src/main/resources/ItemAppraiseProduct.yml
index 4dcf9df..6e54a76 100644
--- a/src/main/resources/ItemAppraiseProduct.yml
+++ b/src/main/resources/ItemAppraiseProduct.yml
@@ -1,10 +1,8 @@
SrItem:
巴尔伐楼伽的怨牙: #这一行填可以鉴定的物品
环齿原胚: #这下面填鉴定物品可以得到的结果
- probabilityMax: 0.4 #概率,相当于一个转盘,多少到多少是这个产物,必定会有结果,比如[0,0.4],左闭右开的范围区间,若随机到0则为此产物,0.4则跳过
- probabilityMin: 0 #概率,相当于一个转盘,多少到多少是这个产物,必定会有结果,比如[0,0.4],左闭右开的范围区间,若随机到0则为此产物,0.4则跳过
+ weight: 20 #概率,相当于一个转盘,多少到多少是这个产物,必定会有结果,比如[0,0.4],左闭右开的范围区间,若随机到0则为此产物,0.4则跳过
index: public.material.巴尔伐楼伽的怨牙 #这里填材料的索引名
保密试作品HC-03原胚: #这下面填鉴定物品可以得到的结果
- probabilityMax: 1 #概率
- probabilityMin: 0.4 #概率
+ weight: 10
index: public.test.保密试作品HC-03原胚 #这里填材料的索引名