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 if item_data.has("level_up_need_material"): item_data["level"]=0 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: n+="(劣质)" 1: n+="(普通)" 2: n+="(优秀)" 3: n+="(稀有)" 4: n+="(史诗)" 5: n+="(传说)" 6: n+="(无双)" _: pass if item_data.has("level") and item_data["level"]!=0: n+="+"+str(item_data["level"]) return n 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 {} #item是否可以升级 static func could_item_level_up(item_data:Dictionary): if item_data.has("quality"): var quality:int=item_data["quality"] if quality==0 ||quality==6: return false if not item_data.has("level_up_need_material"): return false var level_up_need_material=item_data["level_up_need_material"] if not level_up_need_material.has(str(quality)): return false if not item_data.has("level"): return false var now_level:int=item_data["level"] var max_level_arr=[0,5,5,3,3,3,0] var max_level=max_level_arr[quality] if now_level>=max_level: return false else: return true else: return false pass #获取当前item升级所需材料 static func get_item_level_up_need(item_data:Dictionary): return item_data["level_up_need_material"][str(item_data["quality"])].duplicate(true) #当前item是否可以被制作 static func could_item_be_made(item_data:Dictionary)->bool: return item_data.has("make_need") #获取制作材料 static func get_item_make_material(item_data:Dictionary): return item_data["make_need"]