using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; using SiegeSong; namespace SiegeSong { public class Technique : MonoBehaviour { public int ID; public Equipable Weapon; public string FriendlyName; public EquipableArea EquipSlots; public HitBox[] HitBoxes; public Animator CharacterAnimator; public UnityEvent OnUse; public float UseEffectDelay = 0.3f; public int StaminaCost; public int MagicCost; public bool Increment; public AudioClip[] UseSounds; private string useLeftAnimatorField = "UseLeftEquipment"; private string useAbilityAnimatorField = "UseAbilityEquipment"; private string useRightAnimatorField = "UseRightEquipment"; bool delayTimerActive; float useEffectDelayTimer; void Start() { } void Update() { if (delayTimerActive) { useEffectDelayTimer += Time.deltaTime; if (useEffectDelayTimer > UseEffectDelay) { var soundIndex = Random.Range(0, UseSounds.Length - 1); if (UseSounds.Length < soundIndex) { Weapon.Actor.AudioSource.clip = UseSounds[soundIndex]; Weapon.Actor.AudioSource.Play(); } if (OnUse != null) OnUse.Invoke(); delayTimerActive = false; useEffectDelayTimer = 0; foreach (var hitbox in HitBoxes) hitbox.Active = true; } } } public void Use() { if ((StaminaCost != 0 && Weapon.Actor.Stats.Stamina > StaminaCost) || (MagicCost != 0 && Weapon.Actor.Stats.Magic > MagicCost) || (MagicCost == 0 && StaminaCost == 0)) { switch (EquipSlots) { case EquipableArea.Left: CharacterAnimator.SetTrigger(useLeftAnimatorField); break; case EquipableArea.Ability: CharacterAnimator.SetTrigger(useAbilityAnimatorField); break; case EquipableArea.Right: CharacterAnimator.SetTrigger(useRightAnimatorField); break; } Weapon.Actor.ExpendStamina(StaminaCost, Increment); Weapon.Actor.ExpendStamina(MagicCost, Increment); delayTimerActive = true; } } } }