Jump to content

GetWoWUnitHostile for PVP


headcrab

Recommended Posts

ObjectManager.GetWoWUnitHostile is useful function in many cases. To select lowest HP enemy, to multi dot, etc. But useless in pvp, because returns List<WoWUnit> objects with WoWPlayer exclusion (there is woWObject.Type==WoWObjectType.Unit condition inside this function). So, proper GetWoWUnitHostile is:

public static List<WoWUnit> GetWoWPlayerHostile() {
  List<WoWUnit> result = new List<WoWUnit>();
  try {
    foreach (WoWObject woWObject in ObjectManager.ObjectList) {
      if (!woWObject.IsValid || woWObject.IsInvisible) continue;
      WoWUnit o;
      switch (woWObject.Type) {
      //case WoWObjectType.Unit:
      //  o = new WoWUnit(woWObject.GetBaseAddress);
      //  break;
      case WoWObjectType.Player:
        o = new WoWPlayer(woWObject.GetBaseAddress);
        break;
      default: continue;
      }
      if (woWObject.IsInvisible) continue;
      if (o.Reaction <= Reaction.Unfriendly && !o.IsDead) {
        result.Add(o);
      }
    }
  } catch (Exception arg) {
    Logging.WriteError("GetWoWPlayerHostile error " + arg, true);
  }
  return result;
}

public static List<WoWUnit> GetWoWUnitHostile() {
  List<WoWUnit> enemies = GetWoWPlayerHostile();
  if (enemies.Count == 0)
    enemies = ObjectManager.GetWoWUnitHostile();
  return enemies;
}

This function selects enemy players first, and if nothing found, selects hostile units.

I left some commented code in GetWoWPlayerHostile so you can see my 1st variant - 1 list with players and units together. But i think final variant is better for PVP and even for all cases

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...