public override void OnEvent(SpellChargeEvent chargeEvent) { base.OnEvent(chargeEvent); if (LocalPlayer.ExistsIn(World)) { LocalPlayer.SpellHistory.Handle(chargeEvent); } }
private void OnServerSpellChargeCooldown(Player player, SpellChargeCooldown cooldown) { if (player.BoltEntity.Controller != null) { SpellChargeEvent spellChargeEvent = SpellChargeEvent.Create(player.BoltEntity.Controller, ReliabilityModes.ReliableOrdered); spellChargeEvent.SpellId = cooldown.SpellId; spellChargeEvent.CooldownTime = cooldown.ChargeTime; spellChargeEvent.ServerFrame = BoltNetwork.ServerFrame; spellChargeEvent.Send(); } }
public void Handle(SpellChargeEvent chargeEvent) { if (spellChargesById.TryGetValue(chargeEvent.SpellId, out List <SpellChargeCooldown> chargeCooldowns)) { if (chargeCooldowns.Count > 0) { AddCharge(chargeEvent.SpellId, chargeEvent.CooldownTime, chargeEvent.CooldownTime); return; } } int expectedCooldownFrames = (int)(chargeEvent.CooldownTime / BoltNetwork.FrameDeltaTime / 1000.0f); int framesPassed = BoltNetwork.ServerFrame - chargeEvent.ServerFrame; if (framesPassed > expectedCooldownFrames || expectedCooldownFrames < 1) { return; } float cooldownProgressLeft = 1.0f - (float)framesPassed / expectedCooldownFrames; int cooldownTimeLeft = Mathf.RoundToInt(chargeEvent.CooldownTime * cooldownProgressLeft); AddCharge(chargeEvent.SpellId, chargeEvent.CooldownTime, cooldownTimeLeft); }