147 lines
3.7 KiB
GDScript
147 lines
3.7 KiB
GDScript
extends Control
|
|
class_name FightScene
|
|
var user:FightCharacterCard
|
|
##角色节点的引用队列
|
|
var character_arr:Array[FightCharacterCard]=[]
|
|
var enermy_arr:Array[FightEnermyCard]=[]
|
|
var extract_card_arr:Array=[]
|
|
var hand_card_arr:Array=[]
|
|
var left_card_arr:Array=[]
|
|
var extract_num:int=5
|
|
const FIGHT_CHARACTER_CARD = preload("res://scene/fight_character_card.tscn")
|
|
const FIGHT_ENERMY_CARD = preload("res://scene/fight_enermy_card.tscn")
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
Global.now_fight_scene=self
|
|
extract_card_arr=Global.get_all_card()
|
|
extract_card(extract_num)
|
|
add_user(Database.get_character_data("test_character_01"))
|
|
add_character(Database.get_character_data("test_character_01"))
|
|
add_enermy(Database.get_character_data("test_character_01"))
|
|
add_enermy(Database.get_character_data("test_character_02"))
|
|
pass # Replace with function body.
|
|
##抽牌
|
|
func extract_card(num:int):
|
|
if extract_card_arr.size()<num:
|
|
refresh_card()
|
|
for i in num:
|
|
if extract_card_arr.size()==0:
|
|
break
|
|
var rand:int=randi()%extract_card_arr.size()
|
|
var id=extract_card_arr[rand]
|
|
extract_card_arr.pop_at(rand)
|
|
hand_card_arr.append(id)
|
|
%card_machine.add_card(id,1)
|
|
pass
|
|
##洗牌
|
|
func refresh_card():
|
|
extract_card_arr.append_array(left_card_arr.duplicate())
|
|
left_card_arr.clear()
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|
|
##释放队列决定后开始回合
|
|
func start_turn():
|
|
left_card_arr.append_array(hand_card_arr.duplicate())
|
|
hand_card_arr.clear()
|
|
var sort_unit=get_sort_all_unit()
|
|
for i in sort_unit:
|
|
if i[0]!=user:
|
|
await i[0].atk()
|
|
else:
|
|
await %card_machine.exe_queue()
|
|
|
|
extract_card(extract_num)
|
|
%end_select.show()
|
|
pass
|
|
##添加友方角色(非玩家)
|
|
func add_character(character_data:Dictionary):
|
|
var new_character=FIGHT_CHARACTER_CARD.instantiate()
|
|
%character_card_add_pos.add_child(new_character)
|
|
new_character.set_data(character_data)
|
|
character_arr.append(new_character)
|
|
pass
|
|
##添加敌方角色
|
|
func add_enermy(character_data:Dictionary):
|
|
var new_character=FIGHT_ENERMY_CARD.instantiate()
|
|
%enermy_card_add_pos.add_child(new_character)
|
|
new_character.set_data(character_data)
|
|
enermy_arr.append(new_character)
|
|
pass
|
|
##设置玩家
|
|
func add_user(character_data:Dictionary):
|
|
if user!=null:
|
|
if is_instance_valid(user):
|
|
user.queue_free()
|
|
user=null
|
|
var new_character=FIGHT_CHARACTER_CARD.instantiate()
|
|
%character_card_add_pos.add_child(new_character)
|
|
new_character.set_data(character_data)
|
|
user=new_character
|
|
|
|
func _on_tool_button_pressed() -> void:
|
|
pass # Replace with function body.
|
|
|
|
func _on_end_select_pressed() -> void:
|
|
%card_machine.clear_card()
|
|
%end_select.hide()
|
|
start_turn()
|
|
pass # Replace with function body.
|
|
|
|
func get_all_character():
|
|
return character_arr.duplicate()
|
|
func get_all_enermy():
|
|
return enermy_arr.duplicate()
|
|
func get_all_unit():
|
|
var unit_arr:Array=[]
|
|
unit_arr.append_array(get_all_character())
|
|
unit_arr.append_array(get_all_enermy())
|
|
unit_arr.append(user)
|
|
return unit_arr
|
|
func sort(a,b)->bool:
|
|
if a[1]<b[1]:
|
|
return false
|
|
else:
|
|
return true
|
|
|
|
|
|
|
|
pass
|
|
#获取全部根据先手排序的单位
|
|
func get_sort_all_unit():
|
|
var all_unit=get_all_unit()
|
|
var sort_arr:Array=[]
|
|
for i in all_unit:
|
|
var new_arr=[i,i.cacul_initiative_value()]
|
|
sort_arr.append(new_arr)
|
|
sort_arr.sort_custom(sort)
|
|
return sort_arr
|
|
pass
|
|
|
|
func reset():
|
|
set_process(false)
|
|
for i in character_arr:
|
|
i.queue_free()
|
|
character_arr.clear()
|
|
for i in enermy_arr:
|
|
i.queue_free()
|
|
enermy_arr.clear()
|
|
if user!=null:
|
|
user.queue_free()
|
|
user=null
|
|
|
|
func win():
|
|
|
|
SceneManager.change_scene_to("res://scene/game_flow.tscn")
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
func _on_debug_win_pressed() -> void:
|
|
win()
|
|
pass # Replace with function body.
|