CharacterReloadTaskAction.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using NodeCanvas.Framework;
  5. using ParadoxNotion.Design;
  6. using KairoEngine.Core;
  7. using KairoEngine.Inventory;
  8. namespace KairoEngine.CharacterSystem
  9. {
  10. [Category("KairoEngine")]
  11. public class CharacterReloadTaskAction : ActionTask
  12. {
  13. [BlackboardOnly, RequiredField] public BBParameter<CharacterController> character;
  14. private bool done = false;
  15. protected override string info
  16. {
  17. get { return "Reload Firearm"; }
  18. }
  19. protected override void OnExecute()
  20. {
  21. done = false;
  22. ItemFirearmRef firearmRef = (ItemFirearmRef)character.value.GetEquipedItem();
  23. if(firearmRef == null) EndAction(false);
  24. if(character.value.HasSpareAmmo(firearmRef))
  25. {
  26. CharacterReloadFirearmCommand reloadCommand = new CharacterReloadFirearmCommand(character.value, firearmRef);
  27. CommandInvoker.AddCommand(reloadCommand);
  28. GenericEvents.StartListening(character.value.unique_name + "-ReloadDone", End);
  29. }
  30. else EndAction(true);
  31. }
  32. protected override void OnUpdate()
  33. {
  34. if(done == true) EndAction(true);
  35. }
  36. private void End()
  37. {
  38. GenericEvents.StopListening(character.value.unique_name + "-ReloadDone", End);
  39. done = true;
  40. }
  41. }
  42. }