95 lines
3.1 KiB
C#
95 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.Contracts;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
[System.Serializable]
|
|
public class ClassBase {
|
|
|
|
[HideInInspector] public float TimeElapsed;
|
|
[HideInInspector] public int MaxHealth;
|
|
[HideInInspector] public int MaxMana;
|
|
[HideInInspector] public float AttackPower;
|
|
[HideInInspector] public float MagicPower;
|
|
//[HideInInspector] public List<Ability> Abilities;
|
|
|
|
protected Player Player;
|
|
protected Animator Animator;
|
|
protected AttackAnimatorFactory AttackAnimator;
|
|
protected float PlayerOriginalSpeed;
|
|
protected FloatingTextSpawner TextPopUp;
|
|
/// <summary>Always in the order of Up, Down, Left, Right</summary>
|
|
public string AnimationToPlay = "";
|
|
public Dictionary<int, ClassSkill> Skills = new Dictionary<int, ClassSkill>();
|
|
[SerializeField] private List<ClassSkill> AvailableSkills = new List<ClassSkill>();
|
|
|
|
public ClassBase(Player player) {
|
|
Player = player;
|
|
Animator = Player.Animator;
|
|
AttackAnimator = Player.AttackAnimator;
|
|
TextPopUp = new FloatingTextSpawner(player.transform);
|
|
}
|
|
|
|
public void GenerateAvailableSkillsList() {
|
|
AvailableSkills.AddRange(Skills.Values);
|
|
}
|
|
|
|
virtual public void Tick() {
|
|
TimeElapsed = Time.time;
|
|
ClassSkill.TimeElapsed = TimeElapsed;
|
|
AvailableSkills.ForEach((x) => x.UpdateCooldown());
|
|
foreach (var skill in Skills.Values) { skill.UpdateCooldown(); }
|
|
}
|
|
virtual public void HandlePrimaryAttack() { }
|
|
virtual public void HandleSecondaryAttack() { }
|
|
|
|
|
|
[Serializable]
|
|
public class ClassSkill {
|
|
public static float TimeElapsed;
|
|
public string Name { get; private set; }
|
|
public float CooldownTime { get; private set; }
|
|
public float CooldownTimeElapsed { get; private set; }
|
|
public float CooldownRef { get; private set; }
|
|
public int SkillCountMax { get; private set; }
|
|
public int SkillCount { get; private set; } = 0;
|
|
public bool IsPaused { get; set; }
|
|
public bool IsNotReady { get { return SkillCount == 0; } }
|
|
protected bool SkillCountMaxed { get { return SkillCount == SkillCountMax; } }
|
|
protected float CooldownLeftInRatio { get { return SkillCountMaxed ? 1 : (CooldownTimeElapsed / CooldownTime); } }
|
|
|
|
|
|
public ClassSkill(string skillName, float cooldownTime, int skillCount) {
|
|
Name = skillName;
|
|
CooldownTime = cooldownTime;
|
|
SkillCountMax = skillCount;
|
|
}
|
|
|
|
public bool IsReady(bool useSkill = true) {
|
|
if (SkillCount == 0) return false;
|
|
if (useSkill) {
|
|
if (SkillCountMaxed) CooldownRef = Time.time;
|
|
SkillCount--;
|
|
Debug.Log($"[{Name}] Using skill [{SkillCount}/{SkillCountMax}]");
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
public void UpdateCooldown() {
|
|
if (SkillCount == SkillCountMax) return;
|
|
CooldownTimeElapsed = TimeElapsed - CooldownRef;
|
|
if (CooldownTimeElapsed < CooldownTime) return;
|
|
SkillCount++;
|
|
CooldownRef = Time.time;
|
|
Debug.Log($"[{Name}] Updating skill count [{SkillCount}/{SkillCountMax}]");
|
|
}
|
|
}
|
|
}
|