jim87
New Member
- Joined
- Aug 26, 2011
- Messages
- 445
- Reaction score
- 7
Hello!
Actually this Action, which is a behavior tree's leaf, should get the nearest WoWObject and gather a node (herbalism/mining) or pull a creature.
There are three problems though:
1. the process is very slow, it seems the Pulse is being fired once a second (and thus analyzing one WoWObject per second), should I change approach?
2. it won't stop searching for new WoWObjects even if it found one
3. it will stop analyzing the objects randomly (generally after 2 or 3 "loops")
Should I make use of global variables? Other hints?
Thanks
Here is Utils class methods (for reference):
Actually this Action, which is a behavior tree's leaf, should get the nearest WoWObject and gather a node (herbalism/mining) or pull a creature.
There are three problems though:
1. the process is very slow, it seems the Pulse is being fired once a second (and thus analyzing one WoWObject per second), should I change approach?
2. it won't stop searching for new WoWObjects even if it found one
3. it will stop analyzing the objects randomly (generally after 2 or 3 "loops")
Should I make use of global variables? Other hints?
Thanks
PHP:
namespace Jim87.Composites
{
class ActionPullOrGather : Action
{
protected override RunStatus Run(object context)
{
LocalPlayer me = ObjectManager.Me;
WoWObject nearest = null;
int herbalismSkill = me.GetSkill(Styx.SkillLine.Herbalism).CurrentValue;
int miningSkill = me.GetSkill(Styx.SkillLine.Mining).CurrentValue;
bool gatherNodes = Jimbo.Instance.MySettings.GatherNodes;
bool gatherGreyNodes = Jimbo.Instance.MySettings.GatherGreyNodes;
// Get a list of objects near the bot
Dictionary<ulong, WoWObject> objects = Utils.GetSurroundingObjects();
if (objects.Count == 0) return RunStatus.Failure;
// Find nearest, interesting WoWObject
bool found = false;
Jimbo.Instance.Log("WoWObjects to be processed: {0}", objects.Count);
foreach (KeyValuePair<ulong, WoWObject> o in objects)
{
if ((nearest == null || me.Location.Distance(o.Value.GetPosition()) < me.Location.Distance(nearest.GetPosition())) && o.Value.IsValid && o.Value != null)
nearest = o.Value;
}
if (nearest.GetType() == typeof(WoWGameObject))
{
WoWGameObject go = nearest.ToGameObject();
// Is the game object gatherable?
if (go.CanLoot && go.RequiredSkill != null && gatherNodes &&
((go.LockType == WoWLockType.Herbalism && go.RequiredSkill <= herbalismSkill) ||
(go.LockType == WoWLockType.Mining && go.RequiredSkill <= miningSkill)))
{
#warning Grey skill set to 50: NEED ATTUNEMENT OR DYNAMIC SYSTEM
int skill = (go.LockType == WoWLockType.Herbalism) ? herbalismSkill : miningSkill;
int diff = (int)(skill - go.RequiredSkill);
if ((!gatherGreyNodes && (diff <= 50)) || gatherGreyNodes)
found = true;
else Utils.RemoveFromSurroundingObjects(go.Guid);
}
// Must the bot use the object in any case?
else if ((go.CanUse() || go.CanLoot) && Jimbo.Instance.objectsToUse.Contains(go.Entry))
found = true;
else Utils.RemoveFromSurroundingObjects(go.Guid);
}
else if (nearest.GetType() == typeof(WoWUnit))
{
WoWUnit u = nearest.ToUnit();
if (Jimbo.Instance.creaturesToKill.Contains(u.Entry))
found = true;
else Utils.RemoveFromSurroundingObjects(u.Guid);
}
if (objects.Count == 0) return RunStatus.Failure;
if (found == false) return RunStatus.Running;
if (nearest.GetType() == typeof(WoWGameObject))
{
WoWGameObject go = nearest.ToGameObject();
// Check if the object still exists
if (!go.IsValid || go == null)
return RunStatus.Running;
if (me.Location.Distance(go.GetPosition()) > 4)
Utils.GoToPoint(go.GetPosition(), 4);
else
{
go.SubObj.Use();
}
}
else if (nearest.GetType() == typeof(WoWUnit))
{
if(RoutineManager.Current.PullDistance > me.Location.Distance(nearest.GetPosition()))
{
if(!me.IsMoving)
{
WoWPoint toMove = WoWMovement.CalculatePointFrom(nearest.GetPosition(), (float)RoutineManager.Current.PullDistance);
Navigator.MoveTo(toMove);
}
}
if(RoutineManager.Current.NeedPreCombatBuffs)
RoutineManager.Current.PreCombatBuff();
RoutineManager.Current.Pull();
}
return RunStatus.Success;
}
}
}
Here is Utils class methods (for reference):
PHP:
public static Dictionary<ulong, WoWObject> GetSurroundingObjects()
{
if (Jimbo.Instance.surroundingObjects.Count > 0)
return Jimbo.Instance.surroundingObjects;
else
{
Jimbo.Instance.surroundingObjects = ObjectManager.GetObjectsOfType<WoWObject>(true, true)
.Where(o =>
o != null &&
o.IsValid &&
(o.GetType() == typeof(WoWGameObject) || o.GetType() == typeof(WoWUnit)))
.ToDictionary(u => u.Guid);
return Jimbo.Instance.surroundingObjects;
}
}
public static Dictionary<ulong, WoWObject> RemoveFromSurroundingObjects(ulong Guid)
{
Jimbo.Instance.surroundingObjects.Remove(Guid);
return Jimbo.Instance.surroundingObjects;
}
Last edited: