Last active
April 27, 2019 14:28
-
-
Save erodozer/dcc853ff7fad0d3201ef62672a34841c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
onready var player = get_tree().get_nodes_in_group("player")[0] | |
func estimate_damage(attacker: Combatant, opponent: Combatant, limb: Limb) -> int: | |
return attacker.attack(opponent, limb) | |
func estimate_accuracy(attacker: Combatant, opponent: Combatant, limb: Limb) -> float: | |
return attacker.chance(opponent, limb) | |
func fight(attacker: Combatant, opponent: Combatant, limb: Limb, tileactor): | |
# damage is multiplied by current vigor, encouraging players to wait between attacks | |
# vigor can make attacks as low as 25% as effective | |
var damage = max(0, floor(attacker.attack(opponent, limb) * (.75 + (attacker.vigor * .25)))) | |
# the defender's vigor also determines its ability to evade an attack easily | |
# with lower vigor resulting in an evasion ability as low as 35% as capable of dodging | |
var chance = attacker.chance(opponent, limb) | |
attacker.expend_vigor() | |
if randf() > chance: | |
EventBus.publish("combat.damage", { | |
"source": attacker.actor, | |
"target": tileactor, | |
"is_blocked": false, | |
"damage": 0, | |
}) | |
return 0 | |
opponent.hp -= damage | |
print_debug("%s:%d" % [tileactor.name, opponent.hp]) | |
if damage > 0: | |
EventBus.publish("combat.damage", { | |
"source": attacker.actor, | |
"target": tileactor, | |
"is_blocked": false, | |
"damage": damage, | |
}) | |
else: | |
EventBus.publish("combat.damage", { | |
"target": attacker.actor, | |
"is_blocked": true, | |
"damage": damage, | |
}) | |
if opponent.is_dead(): | |
EventBus.publish("combat.killed", { | |
"target": opponent, | |
"attacker": attacker | |
}) | |
attacker.attack_sfx.play() | |
return damage | |
func _events(): | |
return [ | |
"combat.fight" | |
] | |
func _on_event(type, payload): | |
match type: | |
"combat.fight": | |
fight( | |
payload["attacker"], | |
payload["target"], | |
payload["limb"], | |
payload["actor"] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment