challenge-editor/scene/single_identification.gd

131 lines
3.6 KiB
GDScript

extends Control
var data:Dictionary
const SINGLE_IDENTIFICATION_CARD = preload("res://scene/single_identification_card.tscn")
var character_data:Dictionary
#单次鉴定的属性名字
var single_judge_name:String=""
#单次鉴定的属性鉴定值
var single_judge_value:float=0
#单次鉴定的成功触发器
var judge_success_triger:Array=[]
#单次鉴定的失败触发器
var judge_fail_trigtr:Array=[]
func _ready() -> void:
#获取装备加成后的角色数据
character_data=CharacterTool.get_character_with_equip_value(Global.get_now_character_data())
func set_data(_data:Dictionary):
apped_item_data.clear()
data=_data
search_bag()
fresh_card()
if data["type"]==1:
%multi_pre.show()
%single.hide()
else:
%multi_pre.hide()
%single.show()
%single_name.text=data["name"]
single_judge_name=data["attribute_name"]
single_judge_value=data["attribute_value"]
%indetification_value.text=CharacterTool.get_name_by_attribute_key(data["attribute_name"])+":"+str(single_judge_value)
var apped_item_data:Array=[]
#从背包中寻找可用item
func search_bag():
item_data_arr.clear()
#获取游戏中的所有物品数据
var all_item:Array=Global.get_all_item_game_data()
for i in all_item.size():
var atrribute=ItemTool.get_item_attribute_for_indetification(all_item[i])
if atrribute!=null:
item_data_arr.append(all_item[i])
var item_data_arr:Array=[]
func fresh_card():
for i in %card_add_pos.get_children():
i.queue_free()
for i in item_data_arr.size():
var new_card=SINGLE_IDENTIFICATION_CARD.instantiate()
%card_add_pos.add_child(new_card)
new_card.set_data(item_data_arr[i])
new_card.click.connect(card_click.bind(i))
pass
func card_click(ind:int):
var data=item_data_arr[ind]
%card_show.set_data(data)
%AnimationPlayer.play("show_card")
%card_show.show()
now_select_ind=ind
pass
var now_select_ind:int=0
func _on_accept_pressed() -> void:
%card_show.hide()
apped_item_data.append(item_data_arr[now_select_ind])
item_data_arr.pop_at(now_select_ind)
fresh_card()
pass # Replace with function body.
func _on_refuse_pressed() -> void:
%card_show.hide()
pass # Replace with function body.
func _on_single_start_pressed() -> void:
var character_dt=CharacterTool.get_character_use_identification_card(character_data,apped_item_data)
var res=judge_single_identification(character_dt)
if res:
Toast.popup("鉴定成功!")
for i in judge_success_triger:
Global.call_triger(i["type"],i["data"])
else:
Toast.popup("鉴定失败!")
for i in judge_fail_trigtr:
Global.call_triger(i["type"],i["data"])
#清空触发器
judge_success_triger=[]
judge_fail_trigtr=[]
hide()
pass # Replace with function body.
#鉴定算法
func judge_single_identification(character_dt:Dictionary)->bool:
#Toast.popup("角色鉴定属性名:"+single_judge_name)
var attribute_value=CharacterTool.get_character_attribute(character_dt,single_judge_name)
#Toast.popup("角色值:"+str(attribute_value))
if attribute_value is float:
var percent=(attribute_value-single_judge_value)/30
var rand=randf()
#Toast.popup("鉴定概率:"+str(percent*100)+"%")
if rand<percent:
return true
else:
return false
else:
#Toast.popup("不存在对应的属性!")
return false
pass
func _on_multi_start_pressed() -> void:
%multi_indetification.character_data=CharacterTool.get_character_use_identification_card(character_data,apped_item_data)
%multi_indetification.set_data(data)
%multi_indetification.show()
pass # Replace with function body.
func _on_multi_indetification_finish() -> void:
hide()
pass # Replace with function body.