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.