private void OnMouseClick(object s, MouseEventArgs e) { //Console.WriteLine("Mouse click. Selected: " + SelectedAbility); if (e.Button == MouseButtons.Right) { if (SelectedAbility != AbilityKey.None && CanRecastAbility(SelectedAbility) && !AbilityCastModes[SelectedAbility].RecastOnKeyUp) { SelectedAbility = AbilityKey.None; } } else if (e.Button == MouseButtons.Left) // cooldowns are accounted for here aswell in case between key press and click user died, or did zhonyas... { if (SelectedAbility == AbilityKey.None) { return; } if (CanCastAbility(SelectedAbility)) { if (CanRecastAbility(SelectedAbility)) { // its a recast RecastAbility(SelectedAbility); } else { CastAbility(SelectedAbility); } } } }
/// <summary> /// Called when an ability is casted again (few champions have abilities that can be recast, only those with special abilities such as Vel'Koz or Zoes Q) /// </summary> private void OnAbilityRecast(object s, AbilityKey key) { if (key == AbilityKey.W) { animator.StopCurrentAnimation(); animator.ColorBurst(new HSVColor(0, 0, 1)); } if (key == AbilityKey.R) { if (LightingMode == LightingMode.Keyboard) { Task.Run(async() => { await animator.RunAnimationOnce(ANIMATION_PATH + "TwistedFate/r_cast.txt", fadeOutAfterRate: 0.1f, timeScale: 0.22f); await Task.Delay(300); _ = animator.ColorBurst(new HSVColor(0, 0, 1), 0.08f); }); } else { Task.Run(async() => { await animator.RunAnimationOnce(ANIMATION_PATH + "TwistedFate/r_cast_line.txt", true, timeScale: 0.3f); await animator.ColorBurst(new HSVColor(0, 0, 1)); }); } } }
private void RecastAbility(AbilityKey key) { AbilityRecast?.Invoke(this, key); AbilitiesOnRecast[key]--; if (AbilitiesOnRecast[key] == 0) { StartCooldownTimer(key); } }
public int GetAbilityLevel(AbilityKey ability) { return(ability switch { AbilityKey.Q => Q_Level, AbilityKey.W => W_Level, AbilityKey.E => E_Level, AbilityKey.R => R_Level, _ => 0, });
public AbilityCooldown GetCooldown(AbilityKey key) { return(key switch { AbilityKey.Q => Q_Cooldown, AbilityKey.W => W_Cooldown, AbilityKey.E => E_Cooldown, AbilityKey.R => R_Cooldown, _ => null });
/// <summary> /// Called when an ability is casted again (few champions have abilities that can be recast, only those with special abilities such as Vel'Koz or Zoes Q) /// </summary> private void OnAbilityRecast(object s, AbilityKey key) { if (key == AbilityKey.E && canRecastE) { Task.Run(async() => { castingE = false; await Task.Delay(200); _ = animator.RunAnimationOnce(ANIMATION_PATH + "Jax/e_recast_end.txt"); }); } }
private void CastAbility(AbilityKey key) { AbilityCast?.Invoke(this, key); if (AbilityCastModes[key].HasRecast) { StartRecastTimer(key); } else { StartCooldownTimer(key); } SelectedAbility = AbilityKey.None; }
private void RecastAbility(AbilityKey key) { AbilityRecast?.Invoke(this, key); AbilitiesOnRecast[key]--; if (AbilitiesOnRecast[key] == 0) { if (AbilityCastModes[key].RecastMode.RecastOnKeyUp) { SelectedAbility = AbilityKey.None; } StartCooldownTimer(key); } }
/// <summary> /// Returns the cooldown in milliseconds for a given ability, after applying cooldown reduction. /// </summary> protected int GetCooldownForAbility(AbilityKey ability) { return(ability switch { AbilityKey.Q => (int)(ChampionInfo.Costs.Q_Cooldown[PlayerInfo.AbilityLoadout.Q_Level - 1] + ChampionInfo.Costs.Q_Cooldown[PlayerInfo.AbilityLoadout.Q_Level - 1] * PlayerInfo.Stats.CooldownReduction), AbilityKey.W => (int)(ChampionInfo.Costs.W_Cooldown[PlayerInfo.AbilityLoadout.W_Level - 1] + ChampionInfo.Costs.W_Cooldown[PlayerInfo.AbilityLoadout.W_Level - 1] * PlayerInfo.Stats.CooldownReduction), AbilityKey.E => (int)(ChampionInfo.Costs.E_Cooldown[PlayerInfo.AbilityLoadout.E_Level - 1] + ChampionInfo.Costs.E_Cooldown[PlayerInfo.AbilityLoadout.E_Level - 1] * PlayerInfo.Stats.CooldownReduction), AbilityKey.R => (int)(ChampionInfo.Costs.R_Cooldown[PlayerInfo.AbilityLoadout.R_Level - 1] + ChampionInfo.Costs.R_Cooldown[PlayerInfo.AbilityLoadout.R_Level - 1] * PlayerInfo.Stats.CooldownReduction), _ => 0, });
/// <summary> /// Returns the cooldown in milliseconds for a given ability, after applying cooldown reduction. /// </summary> protected int GetCooldownForAbility(AbilityKey ability) { AbilityLoadout abilities = GameState.ActivePlayer.Abilities; ChampionCosts costs = ChampionInfo.Costs; float cdr = GameState.ActivePlayer.Stats.CooldownReduction; return(ability switch { AbilityKey.Q => (int)(costs.Q_Cooldown[abilities.Q_Level - 1] * (1 - cdr)), AbilityKey.W => (int)(costs.W_Cooldown[abilities.W_Level - 1] * (1 - cdr)), AbilityKey.E => (int)(costs.E_Cooldown[abilities.E_Level - 1] * (1 - cdr)), AbilityKey.R => (int)(costs.R_Cooldown[abilities.R_Level - 1] * (1 - cdr)), _ => 0, });
private void OnMouseClick(object s, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { SelectedAbility = AbilityKey.None; } else if (e.Button == MouseButtons.Left) // cooldowns are accounted for here aswell in case between key press and click user died, or did zhonyas... { // CODE FOR Q if (SelectedAbility == AbilityKey.Q) { if (CanCastAbility(AbilityKey.Q)) { CastAbility(AbilityKey.Q); } } // CODE FOR W if (SelectedAbility == AbilityKey.W) { if (CanCastAbility(AbilityKey.W)) { CastAbility(AbilityKey.W); } } // CODE FOR E if (SelectedAbility == AbilityKey.E) { if (CanCastAbility(AbilityKey.E)) { CastAbility(AbilityKey.E); } } // CODE FOR R if (SelectedAbility == AbilityKey.R) { if (CanCastAbility(AbilityKey.R)) { CastAbility(AbilityKey.R); } } } //OnMouseClicked?.Invoke(s,e); }
/// <summary> /// Called when an ability is casted again (few champions have abilities that can be recast, only those with special abilities such as Vel'Koz or Zoes Q) /// </summary> private void OnAbilityRecast(object s, AbilityKey key) { // Add any abilities that need special logic when they are recasted. if (key == AbilityKey.R) { if (rCastInProgress == 1) { animator.RunAnimationOnce(ANIMATION_PATH + "Ahri/r_left.txt"); rCastInProgress++; } else if (rCastInProgress == 2) { animator.RunAnimationOnce(ANIMATION_PATH + "Ahri/r_right.txt"); rCastInProgress = 0; // done, all 3 casts have been used. } } }
private void CastAbility(AbilityKey key) { Task.Run(async() => { /*if (AbilityCastModes[key].IsPointAndClick) * { * // check if mana was substracted, right after casting the ability * * lastManaAmount = LeagueOfLegendsModule.CurrentGameState.ActivePlayer.Stats.ResourceValue; * // Debug.WriteLine("A: " + lastManaAmount); * // TODO: Find an alternative method for point and click * await Task.Delay(300); // This is very slow, but if you put less time, the mana change won't be detected. There seems to be about 300ms delay in stats. * // Debug.WriteLine("B: " + LeagueOfLegendsModule.CurrentGameState.ActivePlayer.Stats.ResourceValue); * * if (LeagueOfLegendsModule.CurrentGameState.ActivePlayer.Stats.ResourceValue >= lastManaAmount) * { * // mana wasn't consumed, so no ability was cast. Maybe this trick doesn't always work. E.g. Anivia E while having R enabled? * SelectedAbility = AbilityKey.None; * return; * } * }*/ AbilityCast?.Invoke(this, key); if (AbilityCastModes[key].HasRecast) { StartRecastTimer(key); } else { if (!AbilityCastModes[key].IsPointAndClick) // no cooldown for point and clicks { StartCooldownTimer(key); } } if (AbilityCastModes[key].RecastMode != null && AbilityCastModes[key].RecastMode.RecastOnKeyUp) { SelectedAbility = key; } else { SelectedAbility = AbilityKey.None; } }); }
/// <summary> /// Called when an ability is cast. /// </summary> private void OnAbilityCast(object s, AbilityKey key) { if (key == AbilityKey.Q) { OnCastQ(); } if (key == AbilityKey.W) { OnCastW(); } if (key == AbilityKey.E) { OnCastE(); } if (key == AbilityKey.R) { OnCastR(); } }
private Func <Task> GetAbilityRecastTask(AbilityKey key) { switch (key) { case AbilityKey.Q: return(OnRecastQ); case AbilityKey.W: return(OnRecastW); case AbilityKey.E: return(OnRecastE); case AbilityKey.R: return(OnRecastR); } // Should never happen return(null); }
private void CastAbility(AbilityKey key) { AbilityCast?.Invoke(this, key); if (AbilityCastModes[key].HasRecast) { StartRecastTimer(key); } else { StartCooldownTimer(key); } if (AbilityCastModes[key].RecastMode != null && AbilityCastModes[key].RecastMode.RecastOnKeyUp) { SelectedAbility = key; } else { SelectedAbility = AbilityKey.None; } }
/// <summary> /// Called when an ability is casted again (few champions have abilities that can be recast, only those with special abilities such as Vel'Koz or Zoes Q) /// </summary> private void OnAbilityRecast(object s, AbilityKey key) { // Add any abilities that need special logic when they are recasted. if (key == AbilityKey.Q) { if (qCastInProgress) { qCastInProgress = false; if (!rCastInProgress) { animator.RunAnimationOnce(ANIMATION_PATH + "Vel'Koz/q_recast.txt"); } } } if (key == AbilityKey.R) { animator.StopCurrentAnimation(); rCastInProgress = false; } }
/// <summary> /// Called when an ability is casted again (few champions have abilities that can be recast, only those with special abilities such as Vel'Koz or Zoes Q) /// </summary> private void OnAbilityRecast(object s, AbilityKey key) { if (key == AbilityKey.Q) { Task.Run(async() => { castingQ = false; await animator.RunAnimationOnce(ANIMATION_PATH + "Xerath/q_retract.txt", timeScale: 0.6f); await Task.Delay(300); _ = animator.ColorBurst(BlueExplodeColor); }); } else if (key == AbilityKey.R) { if (chargesRemaining == 0) { return; } chargesRemaining--; Task.Run(async() => { _ = animator.RunAnimationOnce(ANIMATION_PATH + "Xerath/r_launch.txt", true, timeScale: 0.4f); await Task.Delay(700); if (chargesRemaining > 0) { int previousCharges = chargesRemaining; await animator.ColorBurst(BlueExplodeColor, 0.15f, HSVColor.White); if (previousCharges == chargesRemaining) { _ = animator.HoldColor(HSVColor.White, rTimeRemaining); } } else if (chargesRemaining == 0) { await animator.ColorBurst(BlueExplodeColor, 0.10f); } }); } }
private void OnAbilityRecast(object sender, AbilityKey e) { }
private void DoCastLogicForAbility(AbilityKey key, bool keyUp) { if (keyUp && SelectedAbility != key) { return; // keyUp event shouldn't trigger anything if the ability is not selected. } AbilityCastMode castMode = AbilityCastModes[key]; //Console.WriteLine(key + " " + (keyUp ? "up" : "down")); if (castMode.HasRecast && AbilitiesOnRecast[key] > 0) { //Console.WriteLine(castMode); if (castMode.RecastMode.IsInstant) { if (CanCastAbility(key)) // We must check if CanCastAbility is true. Players can't recast abilities if they're dead or in zhonyas. { RecastAbility(key); } return; } if (PreferredCastMode == AbilityCastPreference.Normal) { if (castMode.RecastMode.IsNormal) { if (CanCastAbility(key)) { SelectedAbility = key; // RECAST SELECTED } } if (castMode.RecastMode.RecastOnKeyUp && !keyUp) { if (CanCastAbility(key)) { RecastAbility(key); } } return; } if (PreferredCastMode == AbilityCastPreference.Quick) { if (CanCastAbility(key)) { RecastAbility(key); } return; } if (PreferredCastMode == AbilityCastPreference.QuickWithIndicator) { if (castMode.RecastMode.RecastOnKeyUp && keyUp && SelectedAbility == key) { if (CanCastAbility(key)) { RecastAbility(key); } } if (castMode.RecastMode.IsNormal) { if (CanCastAbility(key)) { SelectedAbility = key; // RECAST SELECTED } } if (castMode.RecastMode.IsNormal && keyUp && SelectedAbility == key) { if (CanCastAbility(key)) { RecastAbility(key); } } return; } return; } if (castMode.IsInstant) // ability is cast with just pressing down the key { if (CanCastAbility(key)) { CastAbility(key); } return; } if (castMode.IsNormal) // ability has normal cast { if (PreferredCastMode == AbilityCastPreference.Normal) { if (CanCastAbility(key)) // normal press & click cast, typical { SelectedAbility = key; } return; } if (PreferredCastMode == AbilityCastPreference.Quick) { if (CanCastAbility(key)) { CastAbility(key); } return; } if (PreferredCastMode == AbilityCastPreference.QuickWithIndicator) { if (CanCastAbility(key)) { if (keyUp && SelectedAbility == key) // Key released, so CAST IT if it's selected { if (CanCastAbility(key)) { CastAbility(key); } } else // Key down, so select it { if (CanCastAbility(key)) { SelectedAbility = key; } } } } } }
/// <summary> /// Called when an ability is casted again (few champions have abilities that can be recast, only those with special abilities such as Vel'Koz or Zoes Q) /// </summary> protected virtual void OnAbilityRecast(object s, AbilityKey key) { Task.Run(GetAbilityRecastTask(key)); }
private void DoCastLogicForAbility(AbilityKey key, bool keyUp) { if (keyUp && SelectedAbility != key) { return; // keyUp event shouldn't trigger anything if the ability is not selected. } if (!CanCastAbility(key)) { return; } AbilityCastMode castMode = AbilityCastModes[key]; //Debug.WriteLine(key + " " + (keyUp ? "up" : "down")); if (castMode.HasRecast && AbilitiesOnRecast[key] > 0) { //Debug.WriteLine(castMode); if (castMode.RecastMode.IsInstant) { RecastAbility(key); return; } if (PreferredCastMode == AbilityCastPreference.Normal) { if (castMode.RecastMode.IsNormal) { SelectedAbility = key; // RECAST SELECTED } if (castMode.RecastMode.RecastOnKeyUp && !keyUp) { RecastAbility(key); } return; } if (PreferredCastMode == AbilityCastPreference.Quick) { RecastAbility(key); return; } if (PreferredCastMode == AbilityCastPreference.QuickWithIndicator) { if (castMode.RecastMode.RecastOnKeyUp && keyUp && SelectedAbility == key) { RecastAbility(key); } if (castMode.RecastMode.IsNormal) { SelectedAbility = key; // RECAST SELECTED } if (castMode.RecastMode.IsNormal && keyUp && SelectedAbility == key) { if (CanCastAbility(key)) { RecastAbility(key); } } return; } return; } if (castMode.IsInstant) // ability is cast with just pressing down the key { CastAbility(key); return; } if (castMode.IsNormal) // ability has normal cast { if (PreferredCastMode == AbilityCastPreference.Normal) { SelectedAbility = key; return; } if (PreferredCastMode == AbilityCastPreference.Quick) { CastAbility(key); return; } if (PreferredCastMode == AbilityCastPreference.QuickWithIndicator) { if (keyUp && SelectedAbility == key) // Key released, so CAST IT if it's selected { CastAbility(key); } else // Key down, so select it { SelectedAbility = key; } } } }
/// <summary> /// Called when an ability is casted again (few champions have abilities that can be recast, only those with special abilities such as Vel'Koz or Zoes Q) /// </summary> private void OnAbilityRecast(object s, AbilityKey key) { }
/// <summary> /// Called when the mouse is clicked. /// </summary> private void OnMouseClick(object sender, MouseEventArgs m) { // TODO: Quick cast support if (m.Button == MouseButtons.Right) { SelectedAbility = AbilityKey.None; } else if (m.Button == MouseButtons.Left) { // CODE FOR Q if (SelectedAbility == AbilityKey.Q && !qCastInProgress) { // Here you should write code to trigger the appropiate animations to play when the user casts Q. // The code will slightly change depending on the champion, since not all champion abilities are cast in the same "Q + Left Click" fashion, // plus you might want to implement custom animation logic for the different champion abilities. // Trigger the start animation. Task.Run(async() => { await Task.Delay(100); if (!rCastInProgress) { animator.RunAnimationOnce(@"Animations/Vel'Koz/q_start.txt", true); } }); // The Q cast is in progress. qCastInProgress = true; // After 1.15s, if user didn't press Q again already, the Q split animation plays. Task.Run(async() => { await Task.Delay(1150); if (CanCastAbility(AbilityKey.Q) && !rCastInProgress && qCastInProgress) { animator.RunAnimationOnce(@"Animations/Vel'Koz/q_recast.txt"); // Since the ability was cast, start the cooldown timer. StartCooldownTimer(AbilityKey.Q); } qCastInProgress = false; }); // Q was cast, so now there is no ability selected. // Note that this doesn't get triggered after 1.15s (it doesn't wait for the above task to finish). SelectedAbility = AbilityKey.None; } // CODE FOR W if (SelectedAbility == AbilityKey.W) { Task.Run(async() => { animator.RunAnimationOnce(@"Animations/Vel'Koz/w_cast.txt", true); await Task.Delay(1800); if (!rCastInProgress) { animator.RunAnimationOnce(@"Animations/Vel'Koz/w_close.txt", false, 0.15f); } }); StartCooldownTimer(AbilityKey.W); SelectedAbility = AbilityKey.None; } // CODE FOR E if (SelectedAbility == AbilityKey.E) { Task.Run(async() => { await Task.Delay(1000); if (!rCastInProgress) { _ = animator.ColorBurst(HSVColor.FromRGB(229, 115, 255), 0.15f); } }); StartCooldownTimer(AbilityKey.E); SelectedAbility = AbilityKey.None; } // if (SelectedAbility == AbilityKey.R) { } --- Not needed for vel'koz because vel'koz ult is instant cast and doesn't need a mouse click. } }
/// <summary> /// Called when a key is pressed; /// </summary> private void OnKeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 'q') { if (qCastInProgress) { qCastInProgress = false; if (!rCastInProgress) { animator.RunAnimationOnce(@"Animations/Vel'Koz/q_recast.txt"); } StartCooldownTimer(AbilityKey.Q); } else if (CanCastAbility(AbilityKey.Q)) { SelectedAbility = AbilityKey.Q; } } if (e.KeyChar == 'w') { if (CanCastAbility(AbilityKey.W)) { SelectedAbility = AbilityKey.W; } } if (e.KeyChar == 'e') { if (CanCastAbility(AbilityKey.E)) { SelectedAbility = AbilityKey.E; } } if (e.KeyChar == 'r') { if (rCastInProgress) { animator.StopCurrentAnimation(); rCastInProgress = false; StartCooldownTimer(AbilityKey.R); } else { if (CanCastAbility(AbilityKey.R)) { animator.StopCurrentAnimation(); animator.RunAnimationInLoop(@"Animations/Vel'Koz/r_loop.txt", 2300, 0.15f); rCastInProgress = true; Task.Run(async() => { await Task.Delay(2300); if (rCastInProgress) { StartCooldownTimer(AbilityKey.R); rCastInProgress = false; } }); } } } if (e.KeyChar == 'f') // TODO: Refactor this into LeagueOfLegendsModule, or a new SummonerSpells module. Also take cooldown into consideration. { animator.ColorBurst(HSVColor.FromRGB(255, 237, 41), 0.1f); } }