using System.Collections; using System.Collections.Generic; using UnityEngine; using NodeCanvas.Framework; using ParadoxNotion.Design; using KairoEngine.Core; using KairoEngine.Inventory; namespace KairoEngine.CharacterSystem { [Category("KairoEngine")] public class CharacterShootTaskAction : ActionTask { [BlackboardOnly, RequiredField] public BBParameter character; [BlackboardOnly, RequiredField] public BBParameter target; private float waitTime = 0f; private float counter = 0f; private ItemBaseFirearm firearm; private int burstCount = 0; protected override string info { get { return "Shoot at Target"; } } protected override void OnExecute() { if(character.value == null) EndAction(false); if(target.value == null) EndAction(true); if(character.value.GetEquipedItem() == null) EndAction(false); firearm = (ItemBaseFirearm)character.value.GetEquipedItem().item; waitTime = firearm.firingSpeed; counter = 0f; burstCount = 0; ICommand shootCommand = new ShootCommand(character.value); CommandInvoker.AddCommand(shootCommand); } protected override void OnUpdate() { if(character.value == null || firearm == null) EndAction(false); if(target.value != null) { ICommand mousePosCommand = new TurnCommand(character.value, target.value.position); CommandInvoker.AddCommand(mousePosCommand); } counter += Time.deltaTime; if(counter > waitTime) { if(firearm.isAutomatic) { burstCount += 1; if(burstCount <= firearm.ammoCapacity/4) { counter = 0f; ICommand shootCommand = new ShootCommand(character.value); CommandInvoker.AddCommand(shootCommand); } else EndAction(true); } else EndAction(true); } } } }