/// <summary> /// Creates a new <see cref="Indicators.CandlestickPatterns.Counterattack"/> pattern indicator. /// The indicator will be automatically updated on the given resolution. /// </summary> /// <param name="symbol">The symbol whose pattern we seek</param> /// <param name="resolution">The resolution.</param> /// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to casting the input value to a TradeBar</param> /// <returns>The pattern indicator for the requested symbol.</returns> public Counterattack Counterattack(Symbol symbol, Resolution?resolution = null, Func <BaseData, TradeBar> selector = null) { var name = _algorithm.CreateIndicatorName(symbol, "COUNTERATTACK", resolution); var pattern = new Counterattack(name); _algorithm.RegisterIndicator(symbol, pattern, resolution, selector); return(pattern); }
/// <summary> /// Uses Charging Strike /// </summary> /// <param name="attacker"></param> /// <param name="skill"></param> /// <param name="packet"></param> public void Use(Creature attacker, Skill skill, Packet packet) { // Get Target var targetEntityId = packet.GetLong(); var target = attacker.Region.GetCreature(targetEntityId); var attackerPos = attacker.GetPosition(); var targetPos = target.GetPosition(); // Check target + collisions if (target == null || attacker.Region.Collisions.Any(attackerPos, targetPos)) { Send.SkillUseSilentCancel(attacker); attacker.Unlock(Locks.All); return; } // Stop movement attacker.Lock(Locks.Walk | Locks.Run); attacker.StopMove(); target.StopMove(); // Effects Send.EffectDelayed(attacker, attackerPos.GetDistance(targetPos), Effect.ChargingStrike, (byte)0, targetEntityId); // Conditions var extra = new MabiDictionary(); extra.SetBool("CONDITION_FAST_MOVE_NO_LOCK", false); attacker.Conditions.Activate(ConditionsC.FastMove, extra); Send.ForceRunTo(attacker, targetPos); attacker.SetPosition(targetPos.X, targetPos.Y); Send.SkillUseEntity(attacker, skill.Info.Id, targetEntityId); Send.EffectDelayed(attacker, attackerPos.GetDistance(targetPos), Effect.ChargingStrike, (byte)1, targetEntityId); // Counter if (Counterattack.Handle(target, attacker)) { attacker.Conditions.Deactivate(ConditionsC.FastMove); return; } // Prepare Combat Actions var cap = new CombatActionPack(attacker, skill.Info.Id); var aAction = new AttackerAction(CombatActionType.SpecialHit, attacker, targetEntityId, skill.Info.Id); aAction.Set(AttackerOptions.UseEffect); aAction.PropId = targetEntityId; var tAction = new TargetAction(CombatActionType.TakeHit, target, attacker, skill.Info.Id); tAction.Set(TargetOptions.Result); tAction.Delay = attackerPos.GetDistance(targetPos); cap.Add(aAction, tAction); // Damage var damage = (attacker.GetRndFighterDamage() * (skill.RankData.Var1 / 100f)); // Chain Mastery Damage Bonus var chainMasterySkill = attacker.Skills.Get(SkillId.ChainMastery); var damageBonus = (chainMasterySkill == null ? 0 : chainMasterySkill.RankData.Var1); damage += damage * (damageBonus / 100f); // Master Title - Damage +30% if (attacker.Titles.SelectedTitle == skill.Data.MasterTitle) { damage += (damage * 0.3f); } // Critical Hit var critChance = attacker.GetRightCritChance(target.Protection); CriticalHit.Handle(attacker, critChance, ref damage, tAction); // Handle skills and reductions SkillHelper.HandleDefenseProtection(target, ref damage); HeavyStander.Handle(attacker, target, ref damage, tAction); SkillHelper.HandleConditions(attacker, target, ref damage); ManaShield.Handle(target, ref damage, tAction); // Apply Damage target.TakeDamage(tAction.Damage = damage, attacker); // Aggro target.Aggro(attacker); // Stun Times tAction.Stun = TargetStun; aAction.Stun = AttackerStun; // Death and Knockback if (target.IsDead) { if (target.Is(RaceStands.KnockDownable)) { tAction.Set(TargetOptions.FinishingKnockDown); attacker.Shove(target, KnockbackDistance); } else { tAction.Set(TargetOptions.Finished | TargetOptions.FinishingHit); } } else // This skill never knocks back normally { if (!target.IsKnockedDown) { target.Stability -= StabilityReduction; } } cap.Handle(); attacker.Conditions.Deactivate(ConditionsC.FastMove); Send.SkillComplete(attacker, skill.Info.Id); // Chain Progress to Stage 2 attacker.Temp.FighterChainStartTime = DateTime.Now; attacker.Temp.FighterChainLevel = 2; attacker.Skills.ActiveSkill = null; // Charging strike locks EVERYTHING for some reason... attacker.Unlock(Locks.All); }
/// <summary> /// Uses the skill /// </summary> /// <param name="attacker"></param> /// <param name="skill"></param> /// <param name="packet"></param> public void UseSkill(Creature attacker, Skill skill, long targetEntityId) { var target = attacker.Region.GetCreature(targetEntityId); var attackerPos = attacker.GetPosition(); var targetPos = target.GetPosition(); // Check target + collisions if (target == null || attacker.Region.Collisions.Any(attackerPos, targetPos)) { Send.SkillUseSilentCancel(attacker); return; } // Stop movement attacker.StopMove(); target.StopMove(); Send.SkillUseEntity(attacker, skill.Info.Id, targetEntityId); skill.State = SkillState.Used; // Counter if (Counterattack.Handle(target, attacker)) { return; } // Defense/Protection decrease on target var debuffChance = (int)skill.RankData.Var6; var defDecrease = (int)skill.RankData.Var3; var protDecrease = (int)skill.RankData.Var4; var extra = new MabiDictionary(); extra.SetShort("NEW_DEF", (short)defDecrease); extra.SetShort("NEW_PROT", (short)protDecrease); extra.SetLong("DDP_CHAR", attacker.EntityId); extra.SetShort("DDP_SKILL", (short)skill.Info.Id); var rnd = RandomProvider.Get(); if (rnd.NextDouble() * 100 < debuffChance) { Send.Effect(target, Effect.SpinningUppercutDebuff, (short)skill.Info.Id, 0, defDecrease, protDecrease); target.Conditions.Activate(ConditionsC.DefProtectDebuff, extra); attacker.Temp.SpinningUppercutDebuffApplied = true; } // Prepare Combat Actions var cap = new CombatActionPack(attacker, skill.Info.Id); var aAction = new AttackerAction(CombatActionType.RangeHit, attacker, targetEntityId, skill.Info.Id); aAction.Set(AttackerOptions.Result); var tAction = new TargetAction(CombatActionType.TakeHit | CombatActionType.Attacker, target, attacker, skill.Info.Id); tAction.Set(TargetOptions.Result | TargetOptions.FighterUnk); cap.Add(aAction, tAction); // Damage var damage = (attacker.GetRndFighterDamage() * (skill.RankData.Var1 / 100f)); // Chain Mastery Damage Bonus var chainMasterySkill = attacker.Skills.Get(SkillId.ChainMastery); var damageBonus = (chainMasterySkill == null ? 0 : chainMasterySkill.RankData.Var1); damage += damage * (damageBonus / 100f); // Master Title - Damage +20% if (attacker.Titles.SelectedTitle == skill.Data.MasterTitle) { damage += (damage * 0.2f); } // Critical Hit var critChance = attacker.GetRightCritChance(target.Protection); CriticalHit.Handle(attacker, critChance, ref damage, tAction); // Handle skills and reductions SkillHelper.HandleDefenseProtection(target, ref damage); HeavyStander.Handle(attacker, target, ref damage, tAction); SkillHelper.HandleConditions(attacker, target, ref damage); ManaShield.Handle(target, ref damage, tAction); // Apply Damage target.TakeDamage(tAction.Damage = damage, attacker); // Aggro target.Aggro(attacker); // Stun Times tAction.Stun = TargetStun; aAction.Stun = AttackerStun; // Death and Knockback if (target.IsDead) { if (target.Is(RaceStands.KnockDownable)) { tAction.Set(TargetOptions.FinishingKnockDown); attacker.Shove(target, KnockbackDistance); } else { tAction.Set(TargetOptions.Finished | TargetOptions.FinishingHit); } } else { if (!target.IsKnockedDown) { target.Stability -= StabilityReduction; } if (target.IsUnstable && target.Is(RaceStands.KnockDownable)) { tAction.Set(TargetOptions.KnockDown); attacker.Shove(target, KnockbackDistance); } } cap.Handle(); // Chain Progress to Stage 3 attacker.Temp.FighterChainStartTime = DateTime.Now; attacker.Temp.FighterChainLevel = 3; }