2024-04-27 18:12:03 +00:00
extends Node2D
class_name SacrificeStone
2024-04-28 09:09:00 +00:00
2024-04-28 09:33:18 +00:00
## Emitted when the sacrifice on top of the stone changes.
2024-04-28 09:09:31 +00:00
signal sacrifice_changed ( entity : PhysicsBody2D , type : Enums . MonsterType )
2024-04-27 18:12:03 +00:00
2024-04-28 09:09:00 +00:00
2024-04-28 09:09:31 +00:00
var current_monster : PhysicsBody2D
2024-04-27 18:12:03 +00:00
2024-04-28 09:09:00 +00:00
2024-04-28 09:09:31 +00:00
func _on_tracked ( body : PhysicsBody2D ) :
2024-04-28 09:33:18 +00:00
# If a monster is dragged on top of the SacrificeStone while another monster is already on top of it, ignore the capture and let the collision resolve instead
2024-04-27 18:12:03 +00:00
if current_monster != null :
return
2024-04-28 09:33:18 +00:00
# Make sure the monster is sacrificable, and if it is, lock it in and emit [signal sacrifice_changed].
2024-04-28 09:23:07 +00:00
var types : Array = body . find_children ( " * " , " Sacrificable " , false , false )
2024-04-27 18:12:03 +00:00
for type in types :
current_monster = body
2024-04-28 09:35:28 +00:00
sacrifice_changed . emit ( current_monster )
2024-04-27 18:12:03 +00:00
break
2024-04-28 09:09:31 +00:00
func _on_untracked ( body : PhysicsBody2D ) :
2024-04-27 18:12:03 +00:00
if body == current_monster :
current_monster = null
2024-04-28 09:35:28 +00:00
sacrifice_changed . emit ( current_monster )