public bool IsValid(IWowUnit unit) { // is unit on blacklist return(BlacklistTargetValidator.IsValid(unit) // run all other validators && Validators.All(e => e.IsValid(unit))); }
private bool IsUnitToFollowThere(out IWowUnit playerToFollow, bool ignoreRange = false) { IEnumerable <IWowPlayer> wowPlayers = Bot.Objects.All.OfType <IWowPlayer>().Where(e => !e.IsDead); if (wowPlayers.Any()) { IWowUnit[] playersToTry = { Config.FollowSpecificCharacter?wowPlayers.FirstOrDefault(p => Bot.Db.GetUnitName(p, out string name) && name.Equals(Config.SpecificCharacterToFollow, StringComparison.OrdinalIgnoreCase)) : null, Config.FollowGroupLeader ? Bot.Objects.Partyleader : null, Config.FollowGroupMembers ? Bot.Objects.Partymembers.FirstOrDefault() : null }; foreach (IWowUnit unit in playersToTry) { if (unit == null || (!ignoreRange && !ShouldIFollowPlayer(unit))) { continue; } playerToFollow = unit; return(true); } } playerToFollow = null; return(false); }
protected bool IsInSpellRange(IWowUnit unit, string spellName) { if (string.IsNullOrEmpty(spellName)) { return(false); } if (unit == null) { return(false); } var spell = Bot.Character.SpellBook.GetSpellByName(spellName); if (spell == null) { return(false); } if (spell.MinRange == 0 && spell.MaxRange == 0 || spell.MaxRange == 0) { return(Bot.Player.IsInMeleeRange(unit)); } double distance = Bot.Player.Position.GetDistance(unit.Position); return(distance >= spell.MinRange && distance <= spell.MaxRange - 1.0); }
public bool IsTargetAttackable(IWowUnit target) { Spell openingSpell = GetOpeningSpell(); float posOffset = 0.5f; Vector3 currentPos = Bot.Player.Position; Vector3 posXLeft = Bot.Player.Position; posXLeft.X -= posOffset; Vector3 posXRight = Bot.Player.Position; posXRight.X += posOffset; Vector3 posYRight = Bot.Player.Position; posYRight.Y += posOffset; Vector3 posYLeft = Bot.Player.Position; posYLeft.Y -= posOffset; return(IsInRange(openingSpell, target) && DateTime.Now.Subtract(LastFailedOpener).TotalSeconds > 3 && Bot.Wow.IsInLineOfSight(currentPos, target.Position) && Bot.Wow.IsInLineOfSight(posXLeft, target.Position) && Bot.Wow.IsInLineOfSight(posXRight, target.Position) && Bot.Wow.IsInLineOfSight(posYRight, target.Position) && Bot.Wow.IsInLineOfSight(posYLeft, target.Position)); }
public virtual void AttackTarget() { IWowUnit target = Bot.Target; if (target == null) { return; } switch (IsMelee) { case true when Bot.Player.Position.GetDistance(Bot.Target.Position) <= WowClickToMoveDistance.AttackGuid: { if (Bot.Player.IsCasting) { Bot.Wow.StopCasting(); } // todo: kinda buggy Bot.Wow.StopClickToMove(); Bot.Movement.Reset(); Bot.Wow.InteractWithUnit(target); break; } case true when Bot.Player.Position.GetDistance(Bot.Target.Position) > WowClickToMoveDistance.AttackGuid: Bot.Movement.SetMovementAction(MovementAction.Move, target.Position); break; }
public bool Get(out Vector3 position, out MovementAction type) { if (Bot.CombatClass != null && !Bot.CombatClass.HandlesMovement && IWowUnit.IsValidAliveInCombat(Bot.Player) && IWowUnit.IsValidAlive(Bot.Target) && !Bot.Player.IsGhost) { float distance = Bot.Player.DistanceTo(Bot.Target); switch (Bot.CombatClass.Role) { case WowRole.Dps: if (Bot.CombatClass.IsMelee) { if (distance > Bot.Player.MeleeRangeTo(Bot.Target)) { position = Bot.Target.Position; type = MovementAction.Chase; return(true); } } else { if (distance > 26.5f + Bot.Target.CombatReach) { position = Bot.Target.Position; type = MovementAction.Chase; return(true); } } break; case WowRole.Heal: if (distance > 26.5f + Bot.Target.CombatReach) { position = Bot.Target.Position; type = MovementAction.Chase; return(true); } break; case WowRole.Tank: if (distance > Bot.Player.MeleeRangeTo(Bot.Target)) { position = Bot.Target.Position; type = MovementAction.Chase; return(true); } break; } } type = MovementAction.None; position = Vector3.Zero; return(false); }
public void Execute() { IWowUnit randomPartymember = NpcsNearMe.ElementAt(Rnd.Next(0, NpcsNearMe.Count())); if (randomPartymember != null) { Bot.Wow.FacePosition(Bot.Player.BaseAddress, Bot.Player.Position, BotMath.CalculatePositionAround(randomPartymember.Position, 0.0f, (float)Rnd.NextDouble() * (MathF.PI * 2), (float)Rnd.NextDouble()), true); } }
protected bool IsValidUnit(IWowUnit wowUnit) { return(!wowUnit.IsDead && !wowUnit.IsNotAttackable && wowUnit.IsInCombat && !IsBlacklisted(wowUnit) && Bot.Db.GetReaction(wowUnit, Bot.Player) == WowUnitReaction.Hostile && wowUnit.DistanceTo(Bot.Player) < 80.0f); }
public void Execute() { IWowUnit randomPartymember = NearPartymembers.ElementAt(Rnd.Next(0, NearPartymembers.Count())); if (randomPartymember != null) { Bot.Wow.FacePosition(Bot.Player.BaseAddress, Bot.Player.Position, randomPartymember.Position * ((float)Rnd.NextDouble() / 10.0f)); } }
public bool HasPriority(IWowUnit unit) { if (Priorities.TryGetValue(Bot.Objects.MapId, out Func <IWowUnit, bool> hasPriority)) { return(hasPriority(unit)); } // no entry found, skip validation return(false); }
private BtStatus GetTrainer() { if (Bot.GetClosestTrainerByEntryId(trainerEntryId) == null) { return(BtStatus.Failed); } trainer = Bot.GetClosestTrainerByEntryId(trainerEntryId); return(BtStatus.Success); }
public bool IsValid(IWowUnit unit) { // is tagged by me or my group return((unit.IsTaggedByMe || !unit.IsTaggedByOther) // has no target && (unit.TargetGuid == 0 // unit is targeting me, group or pets || (unit.TargetGuid == Bot.Player.Guid || Bot.Objects.PartymemberGuids.Contains(unit.TargetGuid) || Bot.Objects.PartyPetGuids.Contains(unit.TargetGuid) // group or pets are targeting the unit || (Bot.Objects.Partymembers.Any(e => e.TargetGuid == unit.Guid) || Bot.Objects.PartyPets.Any(e => e.TargetGuid == unit.Guid))))); }
public void OnPartyKill(ulong sourceGuid, ulong npcGuid) { IWowUnit wowUnit = Bot.GetWowObjectByGuid <IWowUnit>(npcGuid); if (wowUnit != null && (Bot.Player.Guid == sourceGuid || Bot.Objects.PartymemberGuids.Contains(sourceGuid)) && NpcIds.Contains(BotUtils.GuidToNpcId(npcGuid))) { ++Killed; } }
public override bool SelectTarget(out IEnumerable <IWowUnit> possibleTargets) { possibleTargets = null; IEnumerable <IWowUnit> unitsAroundMe = Bot.Objects.All .OfType <IWowUnit>() .Where(e => TargetValidator.IsValid(e) && e.IsInCombat) .OrderByDescending(e => e.Type) .ThenByDescending(e => e.MaxHealth); IEnumerable <IWowUnit> targetsINeedToTank = unitsAroundMe .Where(e => e.Type != WowObjectType.Player && e.TargetGuid != Bot.Wow.PlayerGuid && Bot.Objects.PartymemberGuids.Contains(e.TargetGuid)); if (targetsINeedToTank.Any()) { possibleTargets = targetsINeedToTank; return(true); } else { if (Bot.Objects.Partymembers.Any()) { Dictionary <IWowUnit, int> targets = new(); foreach (IWowUnit unit in Bot.Objects.Partymembers) { if (unit.TargetGuid > 0) { IWowUnit targetUnit = Bot.GetWowObjectByGuid <IWowUnit>(unit.TargetGuid); if (targetUnit != null && Bot.Db.GetReaction(targetUnit, Bot.Player) != WowUnitReaction.Friendly) { if (!targets.ContainsKey(targetUnit)) { targets.Add(targetUnit, 1); } else { ++targets[targetUnit]; } } } } possibleTargets = targets.OrderBy(e => e.Value).Select(e => e.Key); return(true); } possibleTargets = unitsAroundMe; return(true); } }
private bool ShouldIFollowPlayer(IWowUnit playerToFollow) { if (playerToFollow == null) { return(false); } Vector3 pos = Config.FollowPositionDynamic ? playerToFollow.Position + FollowOffset : playerToFollow.Position; double distance = Bot.Player.DistanceTo(pos); return(distance > Config.MinFollowDistance && distance < Config.MaxFollowDistance); }
public WowUnitReaction GetReaction(IWowUnit a, IWowUnit b) { if (Reactions.ContainsKey(a.FactionTemplate) && Reactions[a.FactionTemplate].ContainsKey(b.FactionTemplate)) { return(Reactions[a.FactionTemplate][b.FactionTemplate]); } else { WowUnitReaction reaction = Wow.GetReaction(a.BaseAddress, b.BaseAddress); CacheReaction(a.FactionTemplate, b.FactionTemplate, reaction); return(reaction); } }
private bool HasPathReachedUnit(Vector3 position, IWowUnit unit) { if (Bot.CombatClass.IsMelee) { // last node should be in combat reach and not too far above return(position.GetDistance2D(unit.Position) <= Bot.Player.MeleeRangeTo(unit) && MathF.Abs(position.Z - unit.Position.Z) < 2.5f); } else { // TODO: best way should be line of sight test? skipped at the moment due to too // much calls return(Bot.Player.DistanceTo(unit) <= 40.0f); } }
public static bool Run(AmeisenBotInterfaces bot, IWowUnit selectedUnit) { if (bot == null || selectedUnit == null) { return(false); } if (bot.Wow.TargetGuid != selectedUnit.Guid) { bot.Wow.ChangeTarget(selectedUnit.Guid); return(false); } if (!BotMath.IsFacing(bot.Objects.Player.Position, bot.Objects.Player.Rotation, selectedUnit.Position, 0.5f)) { bot.Wow.FacePosition(bot.Objects.Player.BaseAddress, bot.Player.Position, selectedUnit.Position); } if (!bot.Wow.UiIsVisible("GossipFrame", "MerchantFrame")) { bot.Wow.InteractWithUnit(selectedUnit.BaseAddress); return(false); } if (selectedUnit.IsGossip) { if (bot.Wow.UiIsVisible("GossipFrame")) { string[] gossipTypes = bot.Wow.GetGossipTypes(); for (int i = 0; i < gossipTypes.Length; ++i) { if (gossipTypes[i].Equals("vendor", StringComparison.OrdinalIgnoreCase) || gossipTypes[i].Equals("repair", StringComparison.OrdinalIgnoreCase)) { bot.Wow.SelectGossipOption(i + 1); } } } if (!bot.Wow.UiIsVisible("MerchantFrame")) { return(false); } } return(true); }
public void Execute() { ulong targetGuid = Bot.Wow.TargetGuid; IWowUnit target = Bot.Objects.WowObjects.OfType <IWowUnit>().FirstOrDefault(t => t.Guid == targetGuid); if (target != null) { // make sure we're auto attacking if (!Bot.Objects.Player.IsAutoAttacking) { Bot.Wow.StartAutoAttack(); } HandleAttacking(target); } }
public static bool Run(AmeisenBotInterfaces bot, IWowUnit selectedUnit) { if (bot == null || selectedUnit == null) { return(false); } if (bot.Wow.TargetGuid != selectedUnit.Guid) { bot.Wow.ChangeTarget(selectedUnit.Guid); } if (!BotMath.IsFacing(bot.Objects.Player.Position, bot.Objects.Player.Rotation, selectedUnit.Position, 0.5f)) { bot.Wow.FacePosition(bot.Objects.Player.BaseAddress, bot.Player.Position, selectedUnit.Position); } if (!bot.Wow.UiIsVisible("GossipFrame")) { bot.Wow.InteractWithUnit(selectedUnit.BaseAddress); } if (!selectedUnit.IsGossip) { return(false); } // gossip 1 train skills // gossip 2 unlearn talents // quest gossip from trainer?? string[] gossipTypes = bot.Wow.GetGossipTypes(); for (int i = 0; i < gossipTypes.Length; ++i) { if (!gossipTypes[i].Equals("trainer", StringComparison.OrdinalIgnoreCase)) { continue; } // +1 is due to implicit conversion between lua array (indexed at 1 not 0) and c# array bot.Wow.SelectGossipOptionSimple(i + 1); return(true); } return(false); }
private void RenderUnits(int halfWidth, int halfHeight, Graphics graphics, float scale, Vector3 playerPosition, float playerRotation) { IEnumerable <IWowUnit> wowUnits = AmeisenBot.Bot.Objects.WowObjects .OfType <IWowUnit>(); for (int i = 0; i < wowUnits.Count(); ++i) { IWowUnit unit = wowUnits.ElementAt(i); Brush selectedBrush = unit.IsDead ? DeadBrush : AmeisenBot.Bot.Db.GetReaction(AmeisenBot.Bot.Player, unit) switch { WowUnitReaction.Hated => EnemyBrush, WowUnitReaction.Hostile => EnemyBrush, WowUnitReaction.Neutral => NeutralBrush, WowUnitReaction.Friendly => FriendBrush, _ => DefaultEntityBrush, }; Point positionOnMap = GetRelativePosition(playerPosition, unit.Position, playerRotation, halfWidth, halfHeight, scale); if (unit.GetType() == typeof(IWowPlayer)) { if (AmeisenBot.Config.MapRenderPlayers) { string playerName = AmeisenBot.Config.MapRenderPlayerNames && AmeisenBot.Bot.Db.GetUnitName(unit, out string name) ? name : string.Empty; string playerExtra = AmeisenBot.Config.MapRenderPlayerExtra ? $"<{unit.Level} {unit.Race} {unit.Class}>" : string.Empty; RenderUnit(positionOnMap.X, positionOnMap.Y, playerName, playerExtra, selectedBrush, WowColorsDrawing.GetClassPrimaryBrush(unit.Class), TextFont, SubTextFont, SubTextBrush, graphics, 7); } } else { if (AmeisenBot.Config.MapRenderUnits) { string unitName = AmeisenBot.Config.MapRenderUnitNames && AmeisenBot.Bot.Db.GetUnitName(unit, out string name) ? name : string.Empty; string unitExtra = AmeisenBot.Config.MapRenderPlayerExtra ? $"<{unit.Level}>" : string.Empty; RenderUnit(positionOnMap.X, positionOnMap.Y, unitName, unitExtra, selectedBrush, TextBrush, TextFont, SubTextFont, SubTextBrush, graphics); } } } }
public void Execute() { if (Finished || Bot.Player.IsCasting) { return; } Unit = Bot.GetClosestQuestGiverByDisplayId(Bot.Player.Position, ObjectDisplayIds, QuestgiversOnly); if (Unit != null) { if (Unit.Position.GetDistance(Bot.Player.Position) < 3.0) { Bot.Wow.StopClickToMove(); Bot.Movement.Reset(); } Bot.Wow.InteractWithUnit(Unit); } }
public void AttackTarget() { IWowUnit target = Bot.Target; if (target == null) { return; } if (Bot.Player.Position.GetDistance(target.Position) <= 3.0) { Bot.Wow.StopClickToMove(); Bot.Movement.Reset(); Bot.Wow.InteractWithUnit(target.BaseAddress); } else { Bot.Movement.SetMovementAction(MovementAction.Move, target.Position); } }
public bool Tick(IEnumerable <IWowUnit> units) { if (InterruptSpells != null && InterruptSpells.Count > 0 && units != null && units.Any()) { IWowUnit selectedUnit = units.FirstOrDefault(e => e != null && e.IsCasting); if (selectedUnit != null) { foreach (KeyValuePair <int, CastInterruptFunction> keyValuePair in InterruptSpells) { if (keyValuePair.Value(selectedUnit)) { AmeisenLogger.I.Log("Interrupt", $"Interrupted \"{selectedUnit}\" using CastInterruptFunction: \"{keyValuePair.Key}\""); return(true); } } } } return(false); }
public bool GetUnitName(IWowUnit unit, out string name) { if (Names.ContainsKey(unit.Guid)) { name = Names[unit.Guid]; return(true); } else { name = unit.ReadName(); if (!string.IsNullOrWhiteSpace(name)) { Names.TryAdd(unit.Guid, name); return(true); } name = "unk"; return(false); } }
public void Execute() { if (Finished || Bot.Player.IsCasting) { return; } if (Bot.Target != null && !Bot.Target.IsDead && !Bot.Target.IsNotAttackable && Bot.Db.GetReaction(Bot.Player, Bot.Target) != WowUnitReaction.Friendly) { Unit = Bot.Target; } else { Bot.Wow.ClearTarget(); Unit = Bot.Objects.All .OfType <IWowUnit>() .Where(e => !e.IsDead && ObjectDisplayIds.Values.Contains(e.DisplayId)) .OrderBy(e => e.Position.GetDistance(Bot.Player.Position)) .OrderBy(e => ObjectDisplayIds.First(x => x.Value == e.DisplayId).Key) .FirstOrDefault(); } if (Unit != null) { if (Unit.Position.GetDistance(Bot.Player.Position) < 3.0) { Bot.Wow.StopClickToMove(); Bot.Movement.Reset(); Bot.Wow.InteractWithUnit(Unit); } else { Bot.Movement.SetMovementAction(MovementAction.Move, Unit.Position); } } }
public void Execute() { if (Finished || Bot.Player.IsCasting) { return; } Unit = Bot.Objects.All .OfType <IWowUnit>() .Where(e => e.IsGossip && !e.IsDead && DisplayIds.Contains(e.DisplayId)) .OrderBy(e => e.Position.GetDistance(Bot.Player.Position)) .FirstOrDefault(); if (Unit != null) { if (Unit.Position.GetDistance(Bot.Player.Position) < 3.0) { if (TalkEvent.Run()) { Bot.Wow.StopClickToMove(); Bot.Movement.Reset(); Bot.Wow.InteractWithUnit(Unit); ++Counter; if (Counter > GossipIds.Count) { Counter = 1; } Bot.Wow.SelectGossipOption(GossipIds[Counter - 1]); } } else { Bot.Movement.SetMovementAction(MovementAction.Move, Unit.Position); } } }
private bool IsInRangePathfinding(IWowUnit unit) { float distance = 0; IEnumerable <Vector3> path = Bot.PathfindingHandler.GetPath((int)Bot.Objects.MapId, Bot.Objects.Player.Position, unit.Position); if (path != null && path.Any() && HasPathReachedUnit(path.Last(), unit)) { for (int i = 0; i < path.Count() - 1; ++i) { distance += path.ElementAt(i).GetDistance(path.ElementAt(i + 1)); if (distance > MaxDistance) { return(false); } } return(true); } return(false); }
public override void AttackTarget() { IWowUnit target = Bot.Target; if (target == null) { return; } if (IsTargetAttackable(target)) { Spell openingSpell = GetOpeningSpell(); Bot.Wow.StopClickToMove(); Bot.Movement.StopMovement(); Bot.Movement.Reset(); TryCastSpell(openingSpell.Name, target.Guid, openingSpell.Costs > 0); } else if (Bot.Player.Position.GetDistance(target.Position) < 3.5f || Bot.Movement.Status == MovementAction.None) { Bot.Movement.SetMovementAction(MovementAction.Move, target.Position); } }
public void Execute() { if (!TalkedToAuctioneer) { if (CurrentAuctioneer.GetDistance(Bot.Player.Position) > 3.2f) { Bot.Movement.SetMovementAction(MovementAction.Move, CurrentAuctioneer); } else { Bot.Movement.StopMovement(); IWowUnit auctioneer = Bot.Objects.All.OfType <IWowUnit>() .FirstOrDefault(e => e.IsAuctioneer && e.Position.GetDistance(CurrentAuctioneer) < 1.0f); if (auctioneer != null) { Bot.Wow.FacePosition(Bot.Player.BaseAddress, Bot.Player.Position, auctioneer.Position); Bot.Wow.InteractWithUnit(auctioneer); } TalkedToAuctioneer = true; AuctioneerTalkTime = DateTime.UtcNow + TimeSpan.FromSeconds(Rnd.Next(120, 180)); } } else if (!ReturnedToOrigin && AuctioneerTalkTime < DateTime.UtcNow) { if (CurrentAuctioneer.GetDistance(OriginPosition) > 8.0f) { Bot.Movement.SetMovementAction(MovementAction.Move, OriginPosition); } else { Bot.Movement.StopMovement(); ReturnedToOrigin = true; } } }