Files
project-reset/Assets/Scripts/Core/Graph Tasks/DealDamage.cs

56 lines
1.6 KiB
C#

using System.Collections.Generic;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace Reset.Core {
[Category("Reset")]
[Description("Deal damage using a damage source to a target")]
public class DealDamage : ActionTask{
public BBParameter<List<Collider>> targets;
public BBParameter<DamageSource> damageSource;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit() {
return null;
}
//This is called once each time the task is enabled.
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override void OnExecute() {
foreach (Collider target in targets.value) {
if (target.GetComponent<IDamageable>() == null) {
if (damageSource.value.source != null) {
Debug.LogError($"Target {target.name} cannot be dealt damage as it does not implement the IDamageable interface. It was attempted an attack by {damageSource.value.source}");
} else {
Debug.LogError($"Target {target.name} cannot be dealt damage as it does not implement the IDamageable interface.");
}
continue;
}
target.GetComponent<IDamageable>().TakeDamage(damageSource.value);
}
EndAction(true);
}
//Called once per frame while the action is active.
protected override void OnUpdate() {
}
//Called when the task is disabled.
protected override void OnStop() {
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}