You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.8 KiB
C#

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;
public string UseLeftAnimatorField = "UseLeftEquipment";
public string UseAbilityAnimatorField = "UseAbilityEquipment";
public 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;
}
}
}
}