123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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<CharacterController> character;
- [BlackboardOnly, RequiredField] public BBParameter<Transform> 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);
- }
- }
- }
- }
|