challenge-editor/class/2dFightBlock/base_block.gd
2024-11-29 01:02:57 +08:00

86 lines
1.9 KiB
GDScript

@tool
extends Node2D
#基础地块
class_name BaseBlock
#当地块要求进行移动时发出
signal request_block_move(before_pos:Vector2i,request_pos:Vector2i)
#当前地块是否可以行走
@export var walkable:bool=false
#当前块是否可以被用作施法(攻击目标)
@export var could_be_used_for_target:bool=false
#当前地块的坐标
@export var block_pos:Vector2i=Vector2i.ZERO:
set(val):
block_pos=val
var parent=get_parent()
if parent is TileMapLayer:
self.position=parent.map_to_local(block_pos)
pass
#实例化地块来源场景库
static var BlockClassDictionary:Dictionary={
}
func _ready() -> void:
var parent=get_parent()
if parent is TileMapLayer:
self.position=parent.map_to_local(block_pos)
_on_create()
pass
#地块被创建时发出
func _on_create():
pass
#当地块删除时发出
func _on_delete():
pass
#当其他地块进入自己的地块时触发
func blocker_enter(block:BaseBlock):
pass
#当其他地块退出自己的区域时触发
func blocker_out(block:BaseBlock):
pass
#当其他地块在自己的地块上等待一回合时触发
func blocker_turn(blocker:BaseBlock):
pass
#要求地块移动
func request_move(move_path_point_arr:Array,global_blocker_data:Dictionary):
if move_path_point_arr.size()<2:
return
self.block_pos=move_path_point_arr.back()
if global_blocker_data.has(move_path_point_arr[0]):
var arr:Array=global_blocker_data[move_path_point_arr[0]]
for i in arr:
if i is BaseBlock:
i.blocker_out(self)
for i in range(1,move_path_point_arr.size()-1):
if global_blocker_data.has(move_path_point_arr[i]):
var arr:Array=global_blocker_data[move_path_point_arr[0]]
for j in arr:
if j is BaseBlock:
j.blocker_enter(self)
j.blocker_out(self)
request_block_move.emit(move_path_point_arr[0],move_path_point_arr.back())
pass
func turn():
pass