152 lines
4.7 KiB
C#
152 lines
4.7 KiB
C#
using Invector;
|
|
using Invector.vCharacterController.AI;
|
|
using Invector.vCharacterController.AI.FSMBehaviour;
|
|
using Sirenix.OdinInspector;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
public class IDBattleController : MonoBehaviour
|
|
{
|
|
public bControlAIMelee aIController;
|
|
public QTEController firstQTEController, secondQTEController;
|
|
public Animator animator;
|
|
|
|
public GameObject basileus, iD;
|
|
|
|
public Transform iDTransformAfterCS, bTransformAfterCS;
|
|
|
|
public bHUDController bHudController;
|
|
|
|
private bool firstQTEDone = false, secondQTEDone;
|
|
|
|
public static int firstEventHP = 200, secondEventHP = 100;
|
|
|
|
private bool shouldAnimateKnockback = false;
|
|
|
|
public AudioSource iDGetHitSound, basileusGetHitSound, iDPushSound;
|
|
|
|
public ScalableSliderController iDHealthSlider;
|
|
|
|
private void Start()
|
|
{
|
|
aIController.onChangeHealth.AddListener(SetIDSliderValue);
|
|
aIController.onChangeHealth.AddListener(TryToStartQTESequence);
|
|
}
|
|
|
|
public void SetIDSliderValue(float value)
|
|
{
|
|
iDHealthSlider.SetSliderValue(value / aIController.maxHealth);
|
|
}
|
|
|
|
public void ResetCharacters()
|
|
{
|
|
basileus.transform.position = bTransformAfterCS.position;
|
|
basileus.transform.rotation = bTransformAfterCS.rotation;
|
|
iD.transform.position = iDTransformAfterCS.position;
|
|
iD.transform.rotation = iDTransformAfterCS.rotation;
|
|
aIController.ResetAnimationTags();
|
|
aIController.EnableAIController();
|
|
Player.Instance.ResetInputs();
|
|
Player.Instance.ResetAnimator();
|
|
aIController.ResetAttackTime();
|
|
aIController.InitAttackTime();
|
|
aIController.ResetAttackTriggers();
|
|
}
|
|
|
|
public void SetBasileusToAnimateKnockback()
|
|
{
|
|
shouldAnimateKnockback = true;
|
|
}
|
|
|
|
public void TryToPlayKnockbackAnimation()
|
|
{
|
|
if (shouldAnimateKnockback)
|
|
{
|
|
shouldAnimateKnockback = false;
|
|
Player.Instance.ResetInputs();
|
|
Player.Instance.ResetAnimator();
|
|
animator.SetTrigger("KnockID");
|
|
}
|
|
}
|
|
|
|
public void TryToStartQTESequence(float health)
|
|
{
|
|
if (health < firstEventHP && !firstQTEDone)
|
|
{
|
|
aIController.SetAttackTimes(3.5f, 4.5f);
|
|
firstQTEDone = true;
|
|
firstQTEController.StartQteSequence();
|
|
TryToToSetHPOver0();
|
|
}
|
|
else if (health < secondEventHP && !secondQTEDone)
|
|
{
|
|
aIController.SetAttackTimes(3f, 4f);
|
|
aIController.animatorSpeed = 1.1f;
|
|
secondQTEDone = true;
|
|
secondQTEController.StartQteSequence();
|
|
TryToToSetHPOver0();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// in case B. gets hit on start, so we will not get weird behaviour
|
|
/// </summary>
|
|
private static void TryToToSetHPOver0()
|
|
{
|
|
if (Player.Instance.ThirdPersonController.currentHealth < 0)
|
|
{
|
|
Player.Instance.ThirdPersonController.ChangeHealth(1);
|
|
}
|
|
}
|
|
|
|
public void DamageBasileus()
|
|
{
|
|
var thirdPersonController = Player.Instance.ThirdPersonController;
|
|
float currentBasileusHealth = thirdPersonController.currentHealth;
|
|
int newHealth = ((int)(currentBasileusHealth - 20f));
|
|
if (newHealth <= 0)
|
|
{
|
|
int damageAmount = (int)(currentBasileusHealth - 1);
|
|
vDamage damage = new vDamage(damageAmount);
|
|
thirdPersonController.TakeDamage(damage);
|
|
}
|
|
else
|
|
{
|
|
thirdPersonController.TakeDamage(new vDamage(20));
|
|
}
|
|
Player.Instance.PlayerInput.UpdateHUD();
|
|
basileusGetHitSound.Play();
|
|
}
|
|
|
|
[Button]
|
|
public void DamageID()
|
|
{
|
|
vDamage damage = new vDamage(15);
|
|
iDGetHitSound.Play();
|
|
aIController.TakeDamage(damage);
|
|
// Debug.LogError("damaged ID");
|
|
}
|
|
|
|
public void PlayKnockSound()
|
|
{
|
|
basileusGetHitSound.Play();
|
|
}
|
|
|
|
public void PlayIDPushSound()
|
|
{
|
|
iDPushSound.Play();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
private void Update()
|
|
{
|
|
if (firstQTEController.IsSequenceRunning || secondQTEController.IsSequenceRunning)
|
|
{
|
|
Player.Instance.PlayerInput.UpdateHUD();
|
|
}
|
|
}
|
|
}
|
|
} |