1
0
Fork 0
spacetac/helpers/battle.gd

77 lines
1.8 KiB
GDScript3
Raw Normal View History

2020-02-03 21:59:43 +00:00
static func update_anchors(tree: SceneTree, position, acceptability) -> Anchor:
""" Update anchor visual hint, and return selected one
"""
var anchors = tree.get_nodes_in_group("anchors")
for anchor in anchors:
anchor.selectable = position and acceptability.call_func(anchor)
var selected_anchor = null
var selected_distance = INF
for anchor in anchors:
if anchor.selectable:
var distance = anchor.global_position.distance_to(position)
if distance < 150 and distance < selected_distance:
selected_anchor = anchor
selected_distance = distance
2020-02-18 22:24:00 +00:00
2020-02-03 21:59:43 +00:00
for anchor in anchors:
anchor.selected = (anchor == selected_anchor)
2020-02-18 22:24:00 +00:00
2020-02-03 21:59:43 +00:00
return selected_anchor
2020-02-18 22:24:00 +00:00
2020-02-18 22:32:33 +00:00
static func spawn_unit(unit: PackedScene, anchor: Anchor, attacker: bool) -> Node:
2020-02-03 21:59:43 +00:00
""" Spawn a unit on an empty anchor
"""
2020-02-18 22:32:33 +00:00
var node = unit.instance()
2020-02-03 21:59:43 +00:00
anchor.set_content(node)
node.attacker = attacker
2020-02-03 23:22:23 +00:00
return node
2020-02-18 22:24:00 +00:00
static func list_units(tree: SceneTree):
""" List all units in battle
"""
var units = []
for anchor in tree.get_nodes_in_group("anchors"):
var content = anchor.get_content()
if content:
units.append(content)
2020-02-18 22:24:00 +00:00
return units
2020-02-18 22:24:00 +00:00
static func apply_combat(attacker: UnitPoints, defender: UnitPoints):
""" Apply a unit combat to points
"""
while attacker.damage:
attacker.damage -= 1
if defender.shield:
defender.shield -= 1
elif defender.hull:
defender.hull -= 1
while defender.damage:
defender.damage -= 1
if attacker.shield:
attacker.shield -= 1
elif attacker.hull:
attacker.hull -= 1
2020-02-09 23:28:05 +00:00
static func get_state(tree: SceneTree):
""" Build the simple state associated with current battle scene
"""
var nodes = []
var routes = []
2020-02-18 22:24:00 +00:00
2020-02-09 23:28:05 +00:00
for anchor in tree.get_nodes_in_group("anchors"):
pass
2020-02-18 22:24:00 +00:00
2020-02-09 23:28:05 +00:00
for route in tree.get_nodes_in_group("routes"):
pass
2020-02-18 22:24:00 +00:00
2020-02-09 23:28:05 +00:00
return {
"nodes": nodes,
"routes": routes
}