class_name ItemTool #用来进行对物品数据进行处理的工具类 #对物品数据进行预处理(如随机品质,随机词条等项) static func re_process_item_data(item_data:Dictionary): var new_item_data=item_data.duplicate(true) #随机品质 if new_item_data.has("quality_lib"): var quality:Array=new_item_data["quality_lib"] new_item_data["quality"]=get_rand_value_weight(quality) #根据品质及词条库添加词条 if item_data.has("word_lib"): var word_num:int=0 match int(new_item_data["quality"]): 2: if randf()>0.5: word_num=1 3: if randf()>0.5: word_num=2 else: word_num=1 4: if randf()>0.5: word_num=3 else: word_num=2 5: word_num=3 6: word_num=3 var word_lib=item_data["word_lib"] var word_arr:Array=[] for i in word_num: word_arr.append(get_rand_value_weight(word_lib)) new_item_data["word"]=word_arr return new_item_data static func get_weight(qalib:Dictionary): return qalib["weight"] static func sum_weight(acc:float,new:Dictionary): return acc+get_weight(new) static func get_rand_value_weight(weight_arr:Array): var sum_wight=weight_arr.reduce(sum_weight,0) #迭代器 var weight_ind:float=0 var final_res:Dictionary var rand=randf_range(0,sum_wight) for i in weight_arr: weight_ind+=get_weight(i) if weight_ind>=rand: final_res=i break return final_res["value"] static func get_name_from_item_data(item_data:Dictionary)->String: var n:String=item_data["name"] if item_data.has("quality"): var quility:int=item_data["quality"] #劣质 普通 优秀 稀有 史诗 传说 无双 match quility: 0: return n+"(劣质)" 1: return n+"(普通)" 2: return n+"(优秀)" 3: return n+"(稀有)" 4: return n+"(史诗)" 5: return n+"(传说)" 6: return n+"(无双)" _: return n else: return n pass static func get_introduction_from_item_data(item_data:Dictionary)->String: var res:String="" if item_data.has("word"): var word_arr:Array=item_data["word"] for i in word_arr: var word_data=Database.get_word_data(i) res+=word_data["name"]+":"+word_data["introduction"]+"\n" res+=item_data["introduction"] return res pass #从item获取可以用于鉴定的属性 static func get_item_attribute_for_indetification(item_data:Dictionary): if item_data.has("identification"): return item_data["identification"] else: return null #获取装备的基础属性(白值) static func get_item_attribute_basic(item_data:Dictionary): if item_data.has("attribute"): return item_data["attribute"].duplicate() else: return {}