using System;
using System.Collections.Generic;
using ControlFreak2;
using Opsive.Shared.Game;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities;
using UnityEngine;
public class SkillDoping : Ability
{
public float dopingDuration = 5f;
public float cooldownDuration = 7f;
private UltimateCharacterLocomotion characterLocomotion;
public ScheduledEventBase scheduledCooldownEvent;
public ScheduledEventBase scheduledDopingEvent;
private Jump jumpAbility;
private bool isCoolingDown;
private List<Action<bool>> OnSkillActive = new List<Action<bool>>();
// Start is called before the first frame update
public override void Start()
{
Debug.Log("(SkillDoping) Start");
characterLocomotion = m_GameObject.GetComponent<UltimateCharacterLocomotion>();
jumpAbility = characterLocomotion.GetAbility<Jump>();
isCoolingDown = false;
Debug.Log("(SkillDoping) jump ability has these states: ");
foreach (var state in jumpAbility.States)
Debug.Log(" - " + state.Name);
base.Start();
}
public override bool CanStartAbility()
{
return !isCoolingDown;
}
public override bool AbilityWillStart()
{
if (ReferenceEquals(characterLocomotion, null))
{
Debug.Log("(SkillDoping) characterLocomotion is null");
return false;
}
if (ReferenceEquals(jumpAbility, null))
{
Debug.Log("(SkillDoping) jumpAbility is null");
return false;
}
return true;
}
protected override void AbilityStarted()
{
Debug.Log("(SkillDoping) AbilityStarted");
isCoolingDown = true;
jumpAbility.SetState("Doping", true);
jumpAbility.SetState("Normal", false);
Debug.Log("(SkillDoping) jumpAbility state = " + jumpAbility.State);
scheduledDopingEvent = SchedulerBase.Schedule(dopingDuration, () =>
{
jumpAbility.SetState("Normal", true);
jumpAbility.SetState("Doping", false);
Debug.Log("(SkillDoping) skill disabled, state is now = " + jumpAbility.State);
});
scheduledCooldownEvent = SchedulerBase.Schedule(cooldownDuration, () =>
{
isCoolingDown = false;
});
base.AbilityStarted();
}
public void AddOnSkillActiveListener(Action<bool> listener)
{
OnSkillActive.Add(listener);
}
public void RemoveOnSkillActiveListener(Action<bool> listener)
{
OnSkillActive.Remove(listener);
}
// // Update is called once per frame
// void Update()
// {
// if(CF2Input.GetButton("Doping Skill"))
// Debug.Log("Doping Skill Button Pressed");
// }
}