public override void OnEvent(SpellCooldownEvent cooldownEvent) { base.OnEvent(cooldownEvent); if (LocalPlayer.ExistsIn(World)) { LocalPlayer.SpellHistory.Handle(cooldownEvent); } }
private void OnServerSpellCooldown(Player player, SpellCooldown cooldown) { if (player.BoltEntity.Controller != null) { SpellCooldownEvent spellCooldownEvent = SpellCooldownEvent.Create(player.BoltEntity.Controller, ReliabilityModes.ReliableOrdered); spellCooldownEvent.SpellId = cooldown.SpellId; spellCooldownEvent.CooldownTime = cooldown.Cooldown; spellCooldownEvent.ServerFrame = BoltNetwork.ServerFrame; spellCooldownEvent.Send(); } }
public void Handle(SpellCooldownEvent cooldownEvent) { int expectedCooldownFrames = (int)(cooldownEvent.CooldownTime / BoltNetwork.FrameDeltaTime / 1000.0f); int framesPassed = BoltNetwork.ServerFrame - cooldownEvent.ServerFrame; if (framesPassed > expectedCooldownFrames || expectedCooldownFrames < 1) { return; } float cooldownProgressLeft = 1.0f - (float)framesPassed / expectedCooldownFrames; int cooldownTimeLeft = Mathf.RoundToInt(cooldownEvent.CooldownTime * cooldownProgressLeft); AddCooldown(cooldownEvent.SpellId, cooldownEvent.CooldownTime, cooldownTimeLeft); }