Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SkillHandler = {}
- SkillHandler.Modules = {}
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local CooldownDurations = require(script:FindFirstChild("CooldownDurations"))
- local SkillsFolder = ReplicatedStorage:FindFirstChild("SkillTypes")
- local DEFAULT_COOLDOWN = 5
- local function ReturnVariations(Skill)
- local Functions = {}
- for Name, Callback in require(Skill) do
- if type(Callback) ~= "function" then continue end
- Functions[Name] = Callback
- end
- return Functions
- end
- function SkillHandler:Main(Player)
- for _,Style in SkillsFolder:GetDescendants() do
- if not Style:IsA("ModuleScript") then continue end
- self.Modules[Style] = {
- Type = Style:FindFirstAncestorOfClass("Folder"),
- Variations = ReturnVariations(Style)
- }
- end
- end
- function SkillHandler:StartCooldown(Player, Skill)
- local Duration = CooldownDurations[Skill] or DEFAULT_COOLDOWN
- local CooldownBegan, Cooldowns = os.clock(), self.PlayerData:GetValue(Player, "Cooldowns")
- table.insert(Cooldowns, Skill)
- task.spawn(function()
- repeat task.wait() until os.clock() - CooldownBegan > Duration
- table.remove(Cooldowns, self.Shared["TableUtil"]:GetIndex(Cooldowns, Skill))
- end)
- end
- function SkillHandler:CastSkill(Player, Skill)
- local Values = self.PlayerData:GetAllValues(Player)
- if Values.Attacking or Values.Guarding then return end
- local OnCooldown = table.find(self.PlayerData:GetValue(Player, "Cooldowns"), Skill)
- if OnCooldown then
- warn(Skill,"is currently on cooldown.")
- return
- end
- local PerformedStyle = nil
- for Style, StyleData in self.Modules do
- if not self.Shared:HasFunction(Skill, require(Style)) then continue end
- PerformedStyle = Style
- end
- self:StartCooldown(Player, Skill)
- self.Shared["ClientServer"]:FireAllClients("EffectsHandler", "CastSkill", {
- Style = PerformedStyle,
- Variation = Skill,
- Caster = Player
- })
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement