Hello,
Use an Fightclass is not a good way to manage target at attack. It is more recommended to make an "Custom Profile" or the best is to make an "Product" (bot) (you can activate option "Dont Start Fighting" in general settings but I recommand to not use Fightclass for this).
I have make sample of custom class with your code (if this works like you want say me it I'll give code to join queue and enter in bg) (you can after use this code with small edit to make product dll):
using System;
using System.Collections.Generic;
using System.Linq;
using robotManager.FiniteStateMachine;
using robotManager.Helpful;
using robotManager.Products;
using wManager;
using wManager.Wow.Bot.States;
using wManager.Wow.Enums;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;
public class CustomProfile : Custom_Profile.ICustomProfile
{
private static readonly Engine Fsm = new Engine();
// Start custom profile
public void Pulse()
{
try
{
// Update spell list
SpellManager.UpdateSpellBook();
// Load CC:
wManager.Wow.Helpers.CustomClass.LoadCustomClass();
// FSM : http://en.wikipedia.org/wiki/Finite-state_machine
Fsm.States.Clear();
Fsm.AddState(new wManager.Wow.Bot.States.Relogger { Priority = 200 }); // Relog if disconnected
Fsm.AddState(new wManager.Wow.Bot.States.Pause { Priority = 13 }); // Manage bot pause
Fsm.AddState(new wManager.Wow.Bot.States.ResurrectBG { Priority = 12 }); // Resurrect player (bg mode)
Fsm.AddState(new wManager.Wow.Bot.States.Resurrect { Priority = 12 }); // Resurrect player (b=normal mode)
Fsm.AddState(new wManager.Wow.Bot.States.MyMacro { Priority = 11 }); // Manage MyMacro (user settings in general settings)
Fsm.AddState(new wManager.Wow.Bot.States.FarmingBG { Priority = 10 }); // Farm in BG (for flag, door, ...)
Fsm.AddState(new ManageTargetBG { Priority = 9, DistanceSearch = 150 }); // Search target at attacked (THIS CLASS IS AT TGE END OF THIS PAGE)
//Fsm.AddState(new wManager.Wow.Bot.States.GrindingBG { Priority = 9, DistanceSearch = 150 }); // Search target at attacked
Fsm.AddState(new wManager.Wow.Bot.States.IsAttacked { Priority = 8 }); // Launch combat if player attacked
//Fsm.AddState(new wManager.Wow.Bot.States.Regeneration {Priority = 8}); // Regen health/mana
//Fsm.AddState(new wManager.Wow.Bot.States.Looting { Priority = 7 }); // Loot npc dead
//Fsm.AddState(new wManager.Wow.Bot.States.Farming { Priority = 6 }); // farm mines/herbs/...
Fsm.AddState(new wManager.Wow.Bot.States.AntiAfk { Priority = 5 }); // Anti AFK
Fsm.AddState(new wManager.Wow.Bot.States.Idle { Priority = 0 }); // If not states need to run, wait
Fsm.States.Sort(); // Order states by Prority
Fsm.StartEngine(10, "_customProfile"); // Launch FSN (with all added states)
StopBotIf.LaunchNewThread(); // Launch bot security (tab "security" in general settings)
// Attach onlevelup for spell book:
EventsLua.AttachEventLua(LuaEventsId.PLAYER_LEVEL_UP, m => OnLevelUp()); // Follow lua event for get when player level up
// Move during combat:
//FightBG.MoveDuringCombat = true;
Logging.Write("Custom Profile Started.");
}
catch (Exception e)
{
try
{
Dispose();
}
catch
{
}
Logging.WriteError("Bot > Pulse(): " + e);
}
}
// Stop custom profile
public void Dispose()
{
try
{
wManager.Wow.Helpers.CustomClass.DisposeCustomClass();
Fsm.StopEngine();
Fight.StopFight();
MovementManager.StopMove();
}
catch (Exception e)
{
Logging.WriteError("Bot > Dispose(): " + e);
}
}
// When player levelup
void OnLevelUp()
{
Logging.Write("Level UP! Reload Fight Class.");
// Update spell list
SpellManager.UpdateSpellBook();
// Load CC:
wManager.Wow.Helpers.CustomClass.ResetCustomClass();
}
// Fsm state to manage target at attack
public class ManageTargetBG : State
{
public override string DisplayName
{
get { return "Manage target BG"; }
}
public override int Priority
{
get { return _priority; }
set { _priority = value; }
}
private int _priority;
public override List<State> NextStates
{
get { return new List<State>(); }
}
public override List<State> BeforeStates
{
get { return new List<State>(); }
}
public List<int> EntryTarget = new List<int>();
public List<uint> FactionsTarget = new List<uint>();
public float DistanceSearch = 150;
private WoWUnit _unit;
// If this method return true, wrobot launch method Run(), if return false wrobot go to next state in FSM
public override bool NeedToRun
{
get
{
if (wManagerSetting.CurrentSetting.DontStartFighting)
return false;
if (!Battleground.IsInBattleground() || !Battleground.BattlegroundIsStarted()) // Not run is not in bg
return false;
if (!Usefuls.InGame ||
Usefuls.IsLoadingOrConnecting ||
ObjectManager.Me.IsDeadMe ||
!ObjectManager.Me.IsValid ||
!Products.IsStarted)
return false;
// Get unit:
_unit = new WoWUnit(0);
var enemyPlayerList = new List<WoWUnit>();
if (FactionsTarget.Count > 0)
enemyPlayerList.AddRange(ObjectManager.GetWoWUnitByFaction(FactionsTarget));
if (EntryTarget.Count > 0)
enemyPlayerList.AddRange(ObjectManager.GetWoWUnitByEntry(EntryTarget));
if (ObjectManager.Me.PlayerFaction == "Alliance")
enemyPlayerList.AddRange(ObjectManager.GetWoWUnitHorde());
if (ObjectManager.Me.PlayerFaction == "Horde")
enemyPlayerList.AddRange(ObjectManager.GetWoWUnitAlliance());
// Your code
WoWUnit[] cibles = new WoWUnit[enemyPlayerList.Count];
long[] ciblePv = new long[enemyPlayerList.Count];
int offset = 0;
foreach (WoWUnit adversaire in enemyPlayerList)
{
cibles[offset] = adversaire;
ciblePv[offset] = adversaire.Health;
offset++;
}
Array.Sort(ciblePv, cibles);
// You can replace your code to sort players by:
// cibles = enemyPlayerList.OrderBy(p => p.Health).ToArray();
// And I think it is more appropriate to use HealthPercent instead Health
for (int x = 0; x < enemyPlayerList.Count; x++)
{
if (cibles[x].IsValid &&
cibles[x].GetDistance < DistanceSearch &&
cibles[x].IsAlive &&
_unit.SummonedBy <= 0 && // Avoid pet
_unit.Guid != ObjectManager.Pet.Guid &&
!wManagerSetting.IsBlackListedAllConditions(_unit)) // Check if blacklisted
{
bool result;
PathFinder.FindPath(_unit.Position, out result); // Test if wrobot can make path to the target to avoid stuck
if (result)
{
_unit = cibles[x];
return true;
}
}
}
_unit = new WoWUnit(0);
return false;
}
}
// If NeedToRun() == true
public override void Run()
{
if (!_unit.IsValid)
return;
Logging.Write("Player Attack " + _unit.Name + " (lvl " + _unit.Level + ")");
FightBG.StartFight(_unit.Guid); // Launch Fight
if (_unit.IsDead)
{
Statistics.Kills++;
}
FightBG.StopFight();
}
}
}
ps: I haven't time to test it now, tell me if this don't works, save this file in "WRobot\Profiles\Custom Profile\" (.cs file) and use product "Custom Product).