challenge-editor/scene/single_identification.gd

131 lines
3.6 KiB
GDScript3
Raw Permalink Normal View History

2024-10-05 18:44:58 +08:00
extends Control
var data:Dictionary
2024-10-05 20:51:00 +08:00
const SINGLE_IDENTIFICATION_CARD = preload("res://scene/single_identification_card.tscn")
var character_data:Dictionary
2024-11-15 17:50:30 +08:00
#单次鉴定的属性名字
var single_judge_name:String=""
#单次鉴定的属性鉴定值
var single_judge_value:float=0
#单次鉴定的成功触发器
var judge_success_triger:Array=[]
#单次鉴定的失败触发器
var judge_fail_trigtr:Array=[]
2024-10-05 20:51:00 +08:00
func _ready() -> void:
#获取装备加成后的角色数据
character_data=CharacterTool.get_character_with_equip_value(Global.get_now_character_data())
2024-10-05 18:44:58 +08:00
func set_data(_data:Dictionary):
2024-10-05 20:51:00 +08:00
apped_item_data.clear()
2024-10-05 18:44:58 +08:00
data=_data
2024-10-05 20:51:00 +08:00
search_bag()
fresh_card()
2024-10-05 18:44:58 +08:00
if data["type"]==1:
2024-10-05 20:51:00 +08:00
%multi_pre.show()
%single.hide()
2024-10-05 18:44:58 +08:00
else:
2024-10-05 20:51:00 +08:00
%multi_pre.hide()
%single.show()
2024-10-16 11:54:14 +08:00
%single_name.text=data["name"]
2024-11-18 11:13:00 +08:00
single_judge_name=data["attribute_name"]
2024-11-15 17:50:30 +08:00
single_judge_value=data["attribute_value"]
2024-11-18 11:13:00 +08:00
%indetification_value.text=CharacterTool.get_name_by_attribute_key(data["attribute_name"])+":"+str(single_judge_value)
2024-10-05 20:51:00 +08:00
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:
2024-11-15 17:50:30 +08:00
var character_dt=CharacterTool.get_character_use_identification_card(character_data,apped_item_data)
var res=judge_single_identification(character_dt)
if res:
2024-11-18 11:13:00 +08:00
Toast.popup("鉴定成功!")
2024-11-15 17:50:30 +08:00
for i in judge_success_triger:
Global.call_triger(i["type"],i["data"])
else:
2024-11-18 11:13:00 +08:00
Toast.popup("鉴定失败!")
2024-11-15 17:50:30 +08:00
for i in judge_fail_trigtr:
Global.call_triger(i["type"],i["data"])
#清空触发器
judge_success_triger=[]
judge_fail_trigtr=[]
hide()
2024-10-05 20:51:00 +08:00
pass # Replace with function body.
2024-11-18 11:13:00 +08:00
#鉴定算法
2024-11-15 17:50:30 +08:00
func judge_single_identification(character_dt:Dictionary)->bool:
2024-11-18 11:13:00 +08:00
#Toast.popup("角色鉴定属性名:"+single_judge_name)
2024-11-15 17:50:30 +08:00
var attribute_value=CharacterTool.get_character_attribute(character_dt,single_judge_name)
2024-11-18 11:13:00 +08:00
#Toast.popup("角色值:"+str(attribute_value))
2024-11-15 17:50:30 +08:00
if attribute_value is float:
var percent=(attribute_value-single_judge_value)/30
var rand=randf()
2024-11-18 11:13:00 +08:00
#Toast.popup("鉴定概率:"+str(percent*100)+"%")
2024-11-15 17:50:30 +08:00
if rand<percent:
return true
else:
return false
else:
2024-11-18 11:13:00 +08:00
#Toast.popup("不存在对应的属性!")
2024-11-15 17:50:30 +08:00
return false
pass
2024-10-05 20:51:00 +08:00
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.