Jump to content

Recommended Posts

List<Object> party = new List<Object>();
       
            var p = new WoWPlayer(0);
            var obj = ObjectManager.Me;
            if (obj.IsValid && obj.Type == WoWObjectType.Player)
            {
                p = new WoWPlayer(obj.GetBaseAddress);
                party.Add(p);
            }
 return party;

If i try with List<WoWUnit> or List<WoWplayer> always the same result : wManager.Wow.ObjectManager.WoWPlayer

Link to comment
https://wrobot.eu/forums/topic/1743-how-to-add-players-unit-to-a-list/
Share on other sites

Hello,

 

I am not sure to understand exactly what you want, but use List<Object> is not good way.

 

If you want create list that containts players and npcs use this (List<WowUnit>):

public static List<WoWUnit> GetElitesNpcAndHostilesPlayers()
    {
        List<WoWUnit> listNpcResult = new List<WoWUnit>();

        List<WoWUnit> allNpc = ObjectManager.GetObjectWoWUnit();
        foreach (var npc in allNpc)
        {
            if (npc.IsValid && npc.IsAlive && npc.IsElite && npc.Reaction <= Reaction.Unfriendly)
                listNpcResult.Add(npc);
        }
        List<WoWPlayer> allPlayers = ObjectManager.GetObjectWoWPlayer();
        foreach (var player in allPlayers)
        {
            if (player.IsValid && player.IsAlive && player.PlayerFaction != ObjectManager.Me.PlayerFaction)
                listNpcResult.Add(player);
        }

        return listNpcResult;
    }

If you want create an list with only wow players use this (List<WoWPlayer>):

public static List<WoWPlayer> GetFriendlyPlayersAndMe()
    {
        List<WoWPlayer> listPlayersResult = new List<WoWPlayer>();

        List<WoWPlayer> allPlayers = ObjectManager.GetObjectWoWPlayer();
        foreach (var player in allPlayers)
        {
            if (player.IsValid && player.IsAlive && player.PlayerFaction == ObjectManager.Me.PlayerFaction)
                listPlayersResult.Add(player);
        }

        listPlayersResult.Add(ObjectManager.Me); // Add your character

        return listPlayersResult;
    }

WowUnit class is the base class of WowPlayer ( WowObject < WowUnit < WowPlayer ).

 

Do not hesitate if you have others questions.

Ty, but :

public static List<WoWPlayer> GetFriendlyPlayersAndMe()
    {
        List<WoWPlayer> listPlayersResult = new List<WoWPlayer>();

        List<WoWPlayer> allPlayers = ObjectManager.GetObjectWoWPlayer();
        foreach (var player in allPlayers)
        {
            if (player.IsValid && player.IsAlive && player.PlayerFaction == ObjectManager.Me.PlayerFaction)
                listPlayersResult.Add(player);
        }

        listPlayersResult.Add(ObjectManager.Me); // Add your character

        Logging.Write("First Element: " + listPlayersResult.FirstOrDefault()); // print the first element

        return listPlayersResult;
    }

Result  => 17:04:49 - First Element: wManager.Wow.ObjectManager.WoWPlayer.

 

Problem still exists :(

 

To make a Healing Routine, I need to know if the player is tank or not, to cast Lifebloom on him. Then I put the player in anoter list Tanks.

 

If no tanks (solo playing) then the tanks is Me, so I cast Lifebloom on myself. Same thing for Wild Mushrooms.

I realy think someting is wrong. If you choose the option to cast a buff onSelf :

[F] 17:22:24 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:25 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:25 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:25 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:25 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:25 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:25 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:26 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:26 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:26 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:26 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:26 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:26 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:27 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:27 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:27 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:27 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:27 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:27 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:28 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:28 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:28 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:28 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:28 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:28 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:29 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:29 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:29 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:29 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:29 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:29 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:29 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:30 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:30 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:30 - Cast (onself) Mark of the Wild (Mark of the Wild)
[F] 17:22:30 - Cast (onself) Mark of the Wild (Mark of the Wild)

..........

I think that's also what keeps me frustrating with my lists.

Please send me your code/fightclass if you want best reply.
 
I have written this for help an member to create an heal fightclass (not tested, it is sample code):
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using robotManager.Helpful;
using wManager.Wow.Class;
using wManager.Wow.Enums;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

public class Main : ICustomClass
{
    private HolyPaladin _holyPaladin;
    public float Range { get { return 29.0f; } }

    public void Initialize()
    {
        _holyPaladin = new HolyPaladin();
        _holyPaladin.Pulse();

    }

    public void Dispose()
    {
        _holyPaladin.Stop();
    }

    public void ShowConfiguration()
    {
        MessageBox.Show("No settings for this FightClass.");
    }
}

class HolyPaladin
{
    // Property:
    private bool _isLaunched;
    public bool IsLaunched
    {
        get { return _isLaunched; }
        set { _isLaunched = value; }
    }

    // Spells:
    private Spell _judgment;
    private Spell _flashOfLight;
    private Spell _lightOfDawn;
    private Spell _avengingWrath;
    private Spell _handOfProtection;
    private Spell _divineShield;
    private Spell _layOnHands;
    private Spell _holyShock;
    private Spell _holyRadiance;

    public HolyPaladin()
    {
        // Init spells:
        _judgment = new Spell("Judgment");
        _flashOfLight = new Spell("Flash of Light");
        _lightOfDawn = new Spell("Light of Dawn");
        _avengingWrath = new Spell("Avenging Wrath");
        _handOfProtection = new Spell("Hand of Protection");
        _divineShield = new Spell("Divine Shield");
        _layOnHands = new Spell("Lay On Hands");
        _holyShock = new Spell("Holy Shock");
        _holyRadiance = new Spell("Holy Radiance");
        Logging.WriteFight("'Holy Paladin' by AudreyH loaded");
    }

    public void Pulse()
    {
        _isLaunched = true;
        var thread = new Thread(RoutineThread) { Name = "HolyPaladin_FightClass" };
        thread.Start();
    }

    public void Stop()
    {
        _isLaunched = false;
        Logging.WriteFight("Stop 'Holy Paladin'");
    }

    void RoutineThread()
    {
        Logging.WriteFight("'Holy Paladin' Started");
        while (_isLaunched)
        {
            Routine();

            Thread.Sleep(10); // Temps d'attante pour éviter d'utiliser trop le processeurs
        }
        Logging.WriteFight("'Holy Paladin' Stopped");
    }

    void Routine()
    {
        if (!Conditions.InGameAndConnectedAndAlive)
            return;

        // Ranger par ordre de priorité
        if (Judgment())
            return;
        if (HolyRadiance())
            return;
        if (FlashOfLight())
            return;
        if (LightOfDawn())
            return;
        if (AvengingWrath())
            return;
        if (HandOfProtection())
            return;
        if (DivineShield())
            return;
        if (LayOnHands())
            return;
        if (HolyShock())
            return;
    }

    // Usefuls methods
    List<WoWUnit> GetPartyTargets()
    {
        var partyMembers = Party.GetPartyHomeAndInstance();
        var ret = new List<WoWUnit>();

        foreach (var m in partyMembers)
        {
            if (m.IsValid && m.IsAlive && m.InCombat && m.Target.IsNotZero())
            {
                if (ret.All(u => u.Guid != m.Target)) // Evite doublon dans la liste retournée
                {
                    var targetUnit = new WoWUnit(ObjectManager.GetObjectByGuid(m.Target).GetBaseAddress);
                    if (targetUnit.IsValid && targetUnit.IsAlive)
                    {
                        ret.Add(targetUnit);
                    }
                }
            }
        }

        return ret;
    }

    private List<WoWPlayer> GetPartyMembers(int maxHealthPercent = 100, float maxDistance = float.MaxValue, bool orderByHealth = true)
    {
        return GetPartyMembers(ObjectManager.Me.Position, maxHealthPercent, maxDistance, orderByHealth);
    }
    private List<WoWPlayer> GetPartyMembers(Vector3 positionCenter, int maxHealthPercent = 100, float maxDistance = float.MaxValue, bool orderByHealth = true)
    {
        var partyMembers = Party.GetPartyHomeAndInstance();
        var ret = new List<WoWPlayer>();

        foreach (var m in partyMembers)
        {
            if (m.IsValid && m.IsAlive && m.HealthPercent < maxHealthPercent && m.Position.DistanceTo(positionCenter) <= maxDistance)
            {
                ret.Add(m);
            }
        }

        if (orderByHealth)
            ret = new List<WoWPlayer>(ret.OrderBy(p => p.HealthPercent));

        return ret;
    }

    string GetTankPlayerName()
    {
        var lua = new[]
                  {
                      "partyTank = \"\";",
                      "for groupindex = 1,MAX_PARTY_MEMBERS do",
                      "	if (UnitInParty(\"party\" .. groupindex)) then",
                      "		local role = UnitGroupRolesAssigned(\"party\" .. groupindex);",
                      "		if role == \"TANK\" then",
                      "			local name, realm = UnitName(\"party\" .. groupindex);",
                      "			partyTank = name;",
                      "			return;",
                      "		end",
                      "	end",
                      "end",
                  };
        return Lua.LuaDoString(lua, "partyTank");
    }
    WoWPlayer GetTankPlayer()
    {
        var p = new WoWPlayer(0);
        var playerName = GetTankPlayerName();
        if (!string.IsNullOrWhiteSpace(playerName))
        {
            playerName = playerName.ToLower().Trim();
            var party = GetPartyMembers();
            foreach (var woWPlayer in party)
            {
                if (woWPlayer.Name.ToLower() == playerName)
                {
                    p = new WoWPlayer(woWPlayer.GetBaseAddress);
                    break;
                }
            }
        }
        return p;
    }

    // Spells methods
    bool Judgment()
    {
        if (!_judgment.KnownSpell)
            return false;

        if (!_judgment.IsSpellUsable)
            return false;

        var partyTargets = GetPartyTargets(); // Recupère les cibles des joueurs du groupe.

        foreach (var target in partyTargets) // On recherche dans la liste
        {
            if (target.IsValid && target.IsAlive) // Verif si target valid et en vie
            {
                if (target.GetDistance < _judgment.MaxRange) // Verif si bonne distance
                {
                    if (!TraceLine.TraceLineGo(target.Position)) // TraceLine permet de vérifier un obstacle entre deux position (true si obstacle)
                    {
                        if (UnitCanAttack.CanAttack(target.GetBaseAddress)) // On peut attaquer la cible
                        {
                            Interact.InteractGameObject(target.GetBaseAddress, true); // sélectionne la cible in game
                            MovementManager.Face(target); // Faire face à la cible
                            _judgment.Launch(); // Lancer le sort
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }


    bool BaseHealSpell(Spell spell, int maxHealthPercent, float maxDistance)
    {
        if (!spell.KnownSpell)
            return false;

        if (!spell.IsSpellUsable)
            return false;

        var partyMembers = GetPartyMembers(maxHealthPercent, maxDistance);
        foreach (var partyMember in partyMembers)
        {
            if (!TraceLine.TraceLineGo(partyMember.Position)) // TraceLine permet de vérifier un obstacle entre deux position (true si obstacle)
            {
                Interact.InteractGameObject(partyMember.GetBaseAddress, true); // sélectionne la cible in game
                MovementManager.Face(partyMember); // Faire face à la cible
                spell.Launch(); // Lancer le sort
                return true;
            }
        }
        return false;
    }

    bool FlashOfLight()
    {
        return BaseHealSpell(_flashOfLight, 90, 40);
    }

    bool LightOfDawn()
    {
        if (!_lightOfDawn.KnownSpell)
            return false;

        if (!_lightOfDawn.IsSpellUsable)
            return false;

        if (ObjectManager.Me.GetPowerByPowerType(PowerType.HolyPower) < 3)
            return false;

        var partyMembers = GetPartyMembers(90, 30);
        if (partyMembers.Count >= 3) // Si minimum 3 alliés dans les 30 mètres avec moins de 90% de vie
        {
            _lightOfDawn.Launch(); // Lancer le sort
            return true;
        }
        return false;
    }

    bool AvengingWrath()
    {
        if (!_avengingWrath.KnownSpell)
            return false;

        if (!_avengingWrath.IsSpellUsable)
            return false;

        var partyTargets = GetPartyTargets(); // Recupère les cibles des joueurs du groupe.

        if (partyTargets.Count > 0 || ObjectManager.Me.InCombat) // Si un des joueurs ou moi en combat
        {
            _avengingWrath.Launch(); // Lancer le sort
            return true;
        }

        return false;
    }

    bool HandOfProtection()
    {
        if (!_handOfProtection.KnownSpell)
            return false;

        if (!_handOfProtection.IsSpellUsable)
            return false;

        if (ObjectManager.Me.InCombat && ObjectManager.Me.HealthPercent <= 20) // Si en combat et moins de 20% de vie
        {
            _handOfProtection.Launch(false, true, false, true); // Lancer le sort OnSelf
            return true;
        }

        return false;
    }

    bool DivineShield()
    {
        if (!_divineShield.KnownSpell)
            return false;

        if (!_divineShield.IsSpellUsable)
            return false;

        if (ObjectManager.Me.InCombat) // Si en combat
        {
            _divineShield.Launch(); // Lancer le sort
            return true;
        }

        return false;
    }

    bool LayOnHands()
    {
        if (!_layOnHands.KnownSpell)
            return false;

        if (!_layOnHands.IsSpellUsable)
            return false;

        if (ObjectManager.Me.HealthPercent <= 20)// Si  moins de 20% de vie
        {
            _layOnHands.Launch(false, true, false, true); // Lancer le sort OnSelf
            return true;
        }

        return false;
    }

    bool HolyShock()
    {
        if (ObjectManager.Me.InCombat)
            return BaseHealSpell(_holyShock, 95, 40);
        return false;
    }

    bool HolyRadiance()
    {
        if (!_holyRadiance.KnownSpell)
            return false;

        if (!_holyRadiance.IsSpellUsable)
            return false;

        var partyMembers = GetPartyMembers(90, 40); // On recupere les membres du groupe avec moins de 90% de vie à 40 metres
        var bestPlayer = new WoWPlayer(0); // Le meilleur joueur pour recevoir le sort
        int bestHealthMissing = 0; // Score (plus le score est haut mieux c'est, ce score et le nombre de pourcentages de vie qui manque aux joueurs qui ce trouve dans les 10 metres du joueur bestPlayer)
        foreach (var partyMember in partyMembers) // On va rechercher le meilleur joueur
        {
            if (partyMember.IsValid && partyMember.IsAlive && !TraceLine.TraceLineGo(partyMember.Position))
            {
                var partyMembersNearPartyPlayer = GetPartyMembers(partyMember.Position, 95, 10); // La on recherche les joueurs proches de partyMember qui ce trouve à 10 metres (porté du sort) (retourne également partyMember dans le résultat)
                if (partyMembersNearPartyPlayer.Count > 2) // Si ils sont minimum 2 joueurs dans les 10 metres
                {
                    int healthMissing = 0;
                    foreach (var p in partyMembersNearPartyPlayer)
                    {
                        if (p.IsValid && p.IsAlive)
                        {
                            healthMissing = healthMissing + (100 - (int)p.HealthPercent);
                        }
                    }
                    if (healthMissing > bestHealthMissing)
                    { // Si il manque plus de vie ici alors on le désigne comme le meilleur choix
                        bestPlayer = new WoWPlayer(partyMember.GetBaseAddress);
                        bestHealthMissing = healthMissing;
                    }
                }
            }
        }

        // Si bestPlayer trouvé
        if (bestHealthMissing > 0 && bestPlayer.IsValid)
        {
            Interact.InteractGameObject(bestPlayer.GetBaseAddress, true); // sélectionne la cible in game
            MovementManager.Face(bestPlayer); // Faire face à la cible
            _holyRadiance.Launch(); // Lancer le sort
            return true;
        }

        return false;
    }
}

Why he's not casting wild mushroom ?

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using robotManager;
using robotManager.FiniteStateMachine;
using robotManager.Helpful;

using wManager.Wow.Class;
using wManager.Wow.Enums;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;

public class Main : ICustomClass
{
    private DruidResto _druid;
    public float Range { get { return 39.0f; } }

    public void Initialize()
    {
        _druid = new DruidResto();
        _druid.Pulse();

    }

    public void Dispose()
    {
        _druid.Stop();
    }

    public void ShowConfiguration()
    {
        MessageBox.Show("No settings for this FightClass.");
    }


    class DruidResto
    {
        // Property:
        private bool _isLaunched;
        public bool IsLaunched
        {
            get { return _isLaunched; }
            set { _isLaunched = value; }
        }

        // Spells:
        private Spell _regrowth;
        private Spell _wildgrowth;
        private Spell _healingtouch;
        private Spell _rejuvenation;
        private Spell _tranquility;
        private Spell _swiftmend;
        private Spell _wildmushroom;
        private Spell _genesis;
        private Spell _typhoon;
        private Spell _incapacitatingroar;
        private Spell _rebirth;
        private Spell _naturesvigil;
        private Spell _naturesSwiftness;
        private Spell _lifebloom;
        private Spell _clearcasting;
        private Spell _ironbark;
        private Spell _barkskin;
        private Spell _forceofnature;

        public DruidResto()
        {
            _regrowth = new Spell("Regrowth");
            _wildgrowth = new Spell("Wild Growth");
            _healingtouch = new Spell("Healing Touch");
            _rejuvenation = new Spell("Rejuvenation");
            _tranquility = new Spell("Tranquility");
            _swiftmend = new Spell("Swiftmend");
            _wildmushroom = new Spell("Wild Mushroom");
            _genesis = new Spell("Genesis");
            _typhoon = new Spell("Typhoon");
            _incapacitatingroar = new Spell("Incapacitating Roar");
            _rebirth = new Spell("Rebirth");
            _naturesvigil = new Spell("Nature's Vigil");
            _naturesSwiftness = new Spell("Nature's Swiftness");
            _lifebloom = new Spell("Lifebloom");
            _clearcasting = new Spell("Clearcasting");
            _ironbark = new Spell("Iron Bark");
            _barkskin = new Spell("Barkskin");
            _forceofnature = new Spell("Force of Nature");
        }

        public void Pulse()
        {
            _isLaunched = true;
            var thread = new Thread(RoutineThread) { Name = "Restoration Druid FightClass" };
            thread.Start();
        }

        public void Stop()
        {
            _isLaunched = false;
            Logging.WriteFight("Stop 'Restoration Druid'");
        }

        void RoutineThread()
        {
            Logging.WriteFight("'Restoration Druid' Started");
            while (_isLaunched)
            {
                Routine();

                Thread.Sleep(10); // Temps d'attante pour éviter d'utiliser trop le processeurs
            }
            Logging.WriteFight("'Restoration Druid' Stopped");
        }
        public const uint
            WILD_GROWTHI = 48438,
            REGROWTHI = 8936,
            HEALING_TOUCHI = 5185,
            REJUVENATIONI = 774,
            SWIFTMENDI = 18562,
            LIFEBLOOMI = 33763,
            WILD_MUSHROOMI = 145205,
            FORCE_OF_NATUREI = 102693,
            TRANQUILITYI = 740,
            GENESISI = 145518,
            EINDE = 0;

        void Routine()
        {
            if (!Conditions.InGameAndConnectedAndAlive)
                return;
            if (Lifebloom()) return;

        }
        IEnumerable<WoWUnit> GetPartyTargets()
        {
            var partyMembers = Party.GetPartyHomeAndInstance();
            var ret = new List<WoWUnit>();

            foreach (var m in partyMembers)
            {
                if (m.IsValid && m.IsAlive && m.InCombat && m.Target.IsNotZero())
                {
                    var targetUnit = new WoWUnit(ObjectManager.GetObjectByGuid(m.Target).GetBaseAddress);
                    if (targetUnit.IsValid && targetUnit.IsAlive)
                    {
                        ret.Add(targetUnit);
                    }
                }
            }

            return ret.Distinct();
        }

        private List<WoWPlayer> GetPartyMembers(int maxHealthPercent = 100, float maxDistance = float.MaxValue, bool orderByHealth = true)
        {
            return GetPartyMembers(ObjectManager.Me.Position, maxHealthPercent, maxDistance, orderByHealth);
        }
        private List<WoWPlayer> GetPartyMembers(Vector3 positionCenter, int maxHealthPercent = 100, float maxDistance = float.MaxValue, bool orderByHealth = true)
        {
            var partyMembers = Party.GetPartyHomeAndInstance();
            var ret = new List<WoWPlayer>();

            foreach (var m in partyMembers)
            {
                if (m.IsValid && m.IsAlive && m.HealthPercent < maxHealthPercent && m.Position.DistanceTo(positionCenter) <= maxDistance)
                {
                    ret.Add(m);
                }
            }

            if (orderByHealth)
                ret = new List<WoWPlayer>(ret.OrderBy(p => p.HealthPercent));

            return ret;
        }

        string GetTankPlayerName()
        {
            var lua = new[]
                  {
                      "partyTank = \"\";",
                      "for groupindex = 1,MAX_PARTY_MEMBERS do",
                      "	if (UnitInParty(\"party\" .. groupindex)) then",
                      "		local role = UnitGroupRolesAssigned(\"party\" .. groupindex);",
                      "		if role == \"TANK\" then",
                      "			local name, realm = UnitName(\"party\" .. groupindex);",
                      "			partyTank = name;",
                      "			return;",
                      "		end",
                      "	end",
                      "end",
                  };
            return Lua.LuaDoString(lua, "partyTank");
        }
        WoWPlayer GetTankPlayer()
        {
            var p = new WoWPlayer(0);
            var playerName = GetTankPlayerName();
            if (!string.IsNullOrWhiteSpace(playerName))
            {
                playerName = playerName.ToLower().Trim();
                var party = GetPartyMembers().OrderBy(o => o.GetDistance);
                foreach (var woWPlayer in party)
                {
                    if (woWPlayer.Name.ToLower() == playerName)
                    {
                        p = new WoWPlayer(woWPlayer.GetBaseAddress);
                        break;
                    }
                }
            }
            if (string.IsNullOrWhiteSpace(playerName))
            {
                p = new WoWPlayer(ObjectManager.Me.GetBaseAddress);
            }
            return p;
        }
        bool BaseHealSpell(Spell spell, int maxHealthPercent, float maxDistance)
        {
            if (!spell.KnownSpell)
                return false;

            if (!spell.IsSpellUsable)
                return false;

            var partyMembers = GetPartyMembers();
            foreach (var partyMember in partyMembers)
            {
                if (!TraceLine.TraceLineGo(partyMember.Position)) // TraceLine permet de vérifier un obstacle entre deux position (true si obstacle)
                {
                    Interact.InteractGameObject(partyMember.GetBaseAddress, true); // sélectionne la cible in game
                    //MovementManager.Face(partyMember); // Faire face à la cible
                    spell.Launch();
                    return true;
                }
            }
            return false;
        }
        bool Lifebloom()
        {
            if (!_lifebloom.KnownSpell)
                return false;

            if (!_lifebloom.IsSpellUsable)
                return false;

            var partyMembers = GetTankPlayer();
            if (!TraceLine.TraceLineGo(partyMembers.Position)
                && partyMembers.IsAlive
                && partyMembers.HealthPercent > 0
                && !partyMembers.HaveBuff("Lifebloom"))
            {
                Interact.InteractGameObject(partyMembers.GetBaseAddress, true); // sélectionne la cible in game
                //MovementManager.Face(partyMembers); // Faire face à la cible
                _lifebloom.Launch(); // Lancer le sort
                return true;
            }
            return false;
        }
        private Vector3 mushroomPosition;
        private WoWPlayer mushroomTarget;
        private DateTime mushroomTime;
        private uint wildMushroomID = 145205;
        private bool needMushroom { get; set; }

        bool WildMushroom()
        {
            if (!_wildmushroom.KnownSpell)
                return false;

            if (!_wildmushroom.IsSpellUsable)
                return false;

            var partyMember = GetTankPlayer();

            if (!TraceLine.TraceLineGo(partyMember.Position)) // lign of sight
            {
                Interact.InteractGameObject(partyMember.GetBaseAddress, true); //select target
                Vector3 location = partyMember.Position;
                SpellManager.CastSpellByIDAndPosition(WILD_MUSHROOMI, location);
                mushroomTarget = new WoWPlayer(partyMember.GetBaseAddress);
                mushroomPosition = location;
                mushroomTime.AddSeconds(29);
                return true;
            }
            return false;
        }
    }
}


If you can try it:

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using robotManager;
using robotManager.FiniteStateMachine;
using robotManager.Helpful;

using wManager.Wow.Class;
using wManager.Wow.Enums;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;
using Timer = robotManager.Helpful.Timer;

public class Main : ICustomClass
{
    private DruidResto _druid;
    public float Range { get { return 39.0f; } }

    public void Initialize()
    {
        _druid = new DruidResto();
        _druid.Pulse();

    }

    public void Dispose()
    {
        _druid.Stop();
    }

    public void ShowConfiguration()
    {
        MessageBox.Show("No settings for this FightClass.");
    }


    class DruidResto
    {
        // Property:
        private bool _isLaunched;
        public bool IsLaunched
        {
            get { return _isLaunched; }
            set { _isLaunched = value; }
        }

        // Spells:
        private Spell _regrowth;
        private Spell _wildgrowth;
        private Spell _healingtouch;
        private Spell _rejuvenation;
        private Spell _tranquility;
        private Spell _swiftmend;
        private Spell _wildmushroom;
        private Spell _genesis;
        private Spell _typhoon;
        private Spell _incapacitatingroar;
        private Spell _rebirth;
        private Spell _naturesvigil;
        private Spell _naturesSwiftness;
        private Spell _lifebloom;
        private Spell _clearcasting;
        private Spell _ironbark;
        private Spell _barkskin;
        private Spell _forceofnature;

        public DruidResto()
        {
            _regrowth = new Spell("Regrowth");
            _wildgrowth = new Spell("Wild Growth");
            _healingtouch = new Spell("Healing Touch");
            _rejuvenation = new Spell("Rejuvenation");
            _tranquility = new Spell("Tranquility");
            _swiftmend = new Spell("Swiftmend");
            _wildmushroom = new Spell("Wild Mushroom");
            _genesis = new Spell("Genesis");
            _typhoon = new Spell("Typhoon");
            _incapacitatingroar = new Spell("Incapacitating Roar");
            _rebirth = new Spell("Rebirth");
            _naturesvigil = new Spell("Nature's Vigil");
            _naturesSwiftness = new Spell("Nature's Swiftness");
            _lifebloom = new Spell("Lifebloom");
            _clearcasting = new Spell("Clearcasting");
            _ironbark = new Spell("Iron Bark");
            _barkskin = new Spell("Barkskin");
            _forceofnature = new Spell("Force of Nature");
        }

        public void Pulse()
        {
            _isLaunched = true;
            var thread = new Thread(RoutineThread) { Name = "Restoration Druid FightClass" };
            thread.Start();
        }

        public void Stop()
        {
            _isLaunched = false;
            Logging.WriteFight("Stop 'Restoration Druid'");
        }

        void RoutineThread()
        {
            Logging.WriteFight("'Restoration Druid' Started");
            while (_isLaunched)
            {
                Routine();

                Thread.Sleep(10); // Temps d'attante pour éviter d'utiliser trop le processeurs
            }
            Logging.WriteFight("'Restoration Druid' Stopped");
        }

        void Routine()
        {
            if (!Conditions.InGameAndConnectedAndAlive)
                return;

            if (Lifebloom()) return;
            if (WildMushroom()) return;

        }
        IEnumerable<WoWUnit> GetPartyTargets()
        {
            var partyMembers = Party.GetPartyHomeAndInstance();
            var ret = new List<WoWUnit>();

            foreach (var m in partyMembers)
            {
                if (m.IsValid && m.IsAlive && m.InCombat && m.Target.IsNotZero())
                {
                    var targetUnit = new WoWUnit(ObjectManager.GetObjectByGuid(m.Target).GetBaseAddress);
                    if (targetUnit.IsValid && targetUnit.IsAlive)
                    {
                        ret.Add(targetUnit);
                    }
                }
            }

            return ret.Distinct();
        }

        private List<WoWPlayer> GetPartyMembers(int maxHealthPercent = 100, float maxDistance = float.MaxValue, bool orderByHealth = true)
        {
            return GetPartyMembers(ObjectManager.Me.Position, maxHealthPercent, maxDistance, orderByHealth);
        }
        private List<WoWPlayer> GetPartyMembers(Vector3 positionCenter, int maxHealthPercent = 100, float maxDistance = float.MaxValue, bool orderByHealth = true)
        {
            var partyMembers = Party.GetPartyHomeAndInstance();
            var ret = new List<WoWPlayer>();

            foreach (var m in partyMembers)
            {
                if (m.IsValid && m.IsAlive && m.HealthPercent < maxHealthPercent && m.Position.DistanceTo(positionCenter) <= maxDistance)
                {
                    ret.Add(m);
                }
            }

            if (orderByHealth)
                ret = new List<WoWPlayer>(ret.OrderBy(p => p.HealthPercent));

            return ret;
        }

        string GetTankPlayerName()
        {
            var lua = new[]
                  {
                      "partyTank = \"\";",
                      "for groupindex = 1,MAX_PARTY_MEMBERS do",
                      "	if (UnitInParty(\"party\" .. groupindex)) then",
                      "		local role = UnitGroupRolesAssigned(\"party\" .. groupindex);",
                      "		if role == \"TANK\" then",
                      "			local name, realm = UnitName(\"party\" .. groupindex);",
                      "			partyTank = name;",
                      "			return;",
                      "		end",
                      "	end",
                      "end",
                  };
            return Lua.LuaDoString(lua, "partyTank");
        }
        WoWPlayer GetTankPlayer()
        {
            var p = new WoWPlayer(0);
            var playerName = GetTankPlayerName();
            if (!string.IsNullOrWhiteSpace(playerName))
            {
                playerName = playerName.ToLower().Trim();
                var party = GetPartyMembers().OrderBy(o => o.GetDistance);
                foreach (var woWPlayer in party)
                {
                    if (woWPlayer.Name.ToLower() == playerName)
                    {
                        p = new WoWPlayer(woWPlayer.GetBaseAddress);
                        break;
                    }
                }
            }
            if (string.IsNullOrWhiteSpace(playerName))
            {
                p = new WoWPlayer(ObjectManager.Me.GetBaseAddress);
            }
            return p;
        }

        bool BaseHealSpell(Spell spell, int maxHealthPercent, float maxDistance)
        {
            if (!spell.KnownSpell)
                return false;

            if (!spell.IsSpellUsable)
                return false;

            var partyMembers = GetPartyMembers();
            foreach (var partyMember in partyMembers)
            {
                if (!TraceLine.TraceLineGo(partyMember.Position)) // TraceLine permet de vérifier un obstacle entre deux position (true si obstacle)
                {
                    Interact.InteractGameObject(partyMember.GetBaseAddress, true); // sélectionne la cible in game
                    //MovementManager.Face(partyMember); // Faire face à la cible
                    spell.Launch();
                    return true;
                }
            }
            return false;
        }
        bool Lifebloom()
        {
            if (!_lifebloom.KnownSpell)
                return false;

            if (!_lifebloom.IsSpellUsable)
                return false;

            var partyMember = GetTankPlayer();
            if (partyMember.IsValid
                && partyMember.GetDistance <= 40
                && partyMember.IsAlive
                && partyMember.HealthPercent > 0
                && !partyMember.HaveBuff("Lifebloom")
                && !TraceLine.TraceLineGo(partyMember.Position))
            {
                Interact.InteractGameObject(partyMember.GetBaseAddress, true); // sélectionne la cible in game
                //MovementManager.Face(partyMembers); // Faire face à la cible
                _lifebloom.Launch(); // Lancer le sort
                return true;
            }
            return false;
        }

        private Timer _mushroomTime = new Timer(-1);
        private uint _wildMushroomID = 145205;
        bool WildMushroom()
        {
            if (!_mushroomTime.IsReady) // If timer finish (29 sec)
            {
                Logging.WriteDebug("WildMushroom > !_mushroomTime.IsReady");
                return false;
            }

            if (!_wildmushroom.KnownSpell)
            {
                Logging.WriteDebug("WildMushroom > !_wildmushroom.KnownSpell");
                return false;
            }

            if (!_wildmushroom.IsSpellUsable)
            {
                Logging.WriteDebug("WildMushroom > !_wildmushroom.IsSpellUsable");
                return false;
            }

            var partyMember = GetTankPlayer();

            if (partyMember.IsValid && // Check if an tank player has found
                partyMember.IsAlive && // Check if is alive
                partyMember.GetDistance <= 40 && // check distance
                !TraceLine.TraceLineGo(partyMember.Position)) // lign of sight
            {
                Interact.InteractGameObject(partyMember.GetBaseAddress, true); //select target
                SpellManager.CastSpellByIDAndPosition(_wildMushroomID, partyMember.Position); // you can also use "_wildmushroom.Id" to get spell id
                _mushroomTime = new Timer(29 * 1000); // 29 sec
                return true;
            }

            Logging.WriteDebug(
                "WildMushroom > partyMember.IsValid=" + partyMember.IsValid +
                 " partyMember.IsAlive=" + partyMember.IsAlive +
                 " partyMember.GetDistance=" + (partyMember.GetDistance) +
                 " TraceLine.TraceLineGo(partyMember.Position)=" + TraceLine.TraceLineGo(partyMember.Position));

            return false;
        }
    }
}

ps: I have added debug info in method "WildMushroom()" (Logging.WriteDebug(...)) to help you to found problem, remove it when this works.

I give up. Too many System.NullReferenceException errors because of the bad use of lists.

 

As long as we can't refer to FirstOrDefault() == null it's impossible to get rid of those System.NullReferenceException.

 

Normally it's so easy, you build a list, you sort the list and you take the FirstOrDefault(). But with wrobot structure to approach units, that's impossible.

 

 

Class1.cs

After 

WoWPlayer unit = getTankList().Where(o => o.IsAlive && o.IsValid && !TraceLine.TraceLineGo(o.Position)).OrderBy(o => o.GetDistance).FirstOrDefault();

add

if (unit == null || !unit.IsValid)
   return false;

your fonction "public bool IsTank(WoWPlayer unit)" is not good, try this:

bool IsTank(string name)
        {
            var lua = new[]
                  {
                      "partyTank = \"\";",
                      "for groupindex = 1,MAX_PARTY_MEMBERS do",
                      "	if (UnitInParty(\"party\" .. groupindex)) then",
                      "		local role = UnitGroupRolesAssigned(\"party\" .. groupindex);",
                      "		if role == \"TANK\" then",
                      "			local name, realm = UnitName(\"party\" .. groupindex);",
                      "			if name == \"" + name + "\" then",
                      "				partyTank = \"yes\";",
					  "				return;",
                      "			end",
                      "		end",
                      "	end",
                      "end",
                  };

            return Lua.LuaDoString(lua, "partyTank") == "yes";
        }
  • 1 year later...

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...