axazol
New Member
- Joined
- Jun 27, 2010
- Messages
- 308
- Reaction score
- 8
[CB] UseOnGround
Listing:
Example:
In theory it must be workin to do quest like bombing or so. Needs testing and feedback.
Listing:
PHP:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading;
using Styx.Helpers;
using Styx.Logic.BehaviorTree;
using Styx.Logic.Pathing;
using Styx.Logic.Questing;
using Styx.Logic.Combat;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using TreeSharp;
using Action = TreeSharp.Action;
namespace Styx.Bot.Quest_Behaviors
{
///
/// UseOnGround by AxaZol
/// Allows you to trow items or spells on the ground under gameobjects/npc's
/// ##Syntax##
/// QuestId: The id of the quest.
/// TargetId: The id of the object/npc.
/// [One of two]ItemId: The id of the item to use.
/// [One of two]SpellId: The id of the item to use.
/// NumOfTimes: Number of times to use said item/spell.
/// [Optional]WaitTime: Time to wait after using an item/spell. DefaultValue: 1500 ms
/// [Optional]CollectionDistance: The distance it will use to collect objects/npc's. DefaultValue:100 yards
/// [Optional]UsageDistance: The value wich will use to determine distance spell casting or using item on objects or npc. DefaultValue:10 yards
/// ObjectType: the type of object to interact with, expected value: Npc/Gameobject
/// X,Y,Z: The general location where theese objects can be found
///
public class UseOnGround : CustomForcedBehavior
{
public UseOnGround(Dictionary args)
: base(args)
{
bool error = false;
uint questId;
if (!uint.TryParse(Args["QuestId"], out questId))
{
Logging.Write("Parsing attribute 'QuestId' in UseOnGround behavior failed! please check your profile!");
error = true;
}
uint targetId;
if (!uint.TryParse(Args["TargetId"], out targetId))
{
Logging.Write("Parsing attribute 'TargetId' in UseOnGround behavior failed! please check your profile!");
error = true;
}
if(Args.ContainsKey("ItemId"))
{
int itemId;
int.TryParse((string)Args["ItemId"], out itemId);
ItemId = itemId != 0 ? itemId : 0;
}
if(ItemId == 0)
{
Logging.Write("Parsing attribute 'ItemId' in UseOnGround behavior failed! please check your profile!");
error = true;
}
int numOfTimes;
if (!int.TryParse(Args["NumOfTimes"], out numOfTimes))
{
Logging.Write("Parsing attribute 'NumOfTimes' in UseOnGround behavior failed! please check your profile!");
error = true;
}
if(Args.ContainsKey("WaitTime"))
{
int waitTime;
int.TryParse(Args["WaitTime"], out waitTime);
WaitTime = waitTime != 0 ? waitTime : 1500;
}
if (Args.ContainsKey("UsageDistance"))
{
int udistance;
int.TryParse(Args["UsageDistance"], out udistance);
UsageDistance = udistance != 0 ? udistance : 10;
}
if (Args.ContainsKey("CollectionDistance"))
{
int distance;
int.TryParse(Args["CollectionDistance"], out distance);
CollectionDistance = distance != 0 ? distance : 100;
}
if (!Args.ContainsKey("ObjectType"))
{
Logging.Write("Could not find attribute 'ObjectType' in UseOnGround behavior! please check your profile!");
error = true;
}
var type = (ObjectType)Enum.Parse(typeof(ObjectType), Args["ObjectType"], true);
float x, y, z;
if (!float.TryParse((string)Args["X"], out x))
{
Logging.Write("Parsing attribute 'X' in UseOnGround behavior failed! please check your profile!");
error = true;
}
if (!float.TryParse((string)Args["Y"], out y))
{
Logging.Write("Parsing attribute 'Y' in UseOnGround behavior failed! please check your profile!");
error = true;
}
if (!float.TryParse((string)Args["Z"], out z))
{
Logging.Write("Parsing attribute 'Z' in UseOnGround behavior failed! please check your profile!");
error = true;
}
if (error)
TreeRoot.Stop();
ObjectType = type;
QuestId = questId;
NumOfTimes = numOfTimes;
TargetId = targetId;
Location = new WoWPoint(x, y, z);
}
public WoWPoint Location { get; private set; }
public int WaitTime { get; private set; }
public int Counter { get; private set; }
public uint TargetId { get; private set; }
public int ItemId { get; private set; }
public int NumOfTimes { get; private set; }
public uint QuestId { get; private set; }
public ObjectType ObjectType { get; private set; }
public int CollectionDistance { get; private set; }
public int UsageDistance { get; private set; }
private readonly List _npcBlacklist = new List();
/// Current object we should interact with.
/// The object.
private WoWObject CurrentObject
{
get
{
WoWObject @object = null;
switch (ObjectType)
{
case ObjectType.Gameobject:
@object = ObjectManager.GetObjectsOfType().OrderBy(ret => ret.Distance).FirstOrDefault(obj =>
!_npcBlacklist.Contains(obj.Guid) &&
obj.Distance < CollectionDistance &&
obj.Entry == TargetId);
break;
case ObjectType.Npc:
@object = ObjectManager.GetObjectsOfType().OrderBy(ret => ret.Distance).FirstOrDefault(obj =>
!_npcBlacklist.Contains(obj.Guid) &&
obj.Distance < CollectionDistance &&
obj.Entry == TargetId);
break;
}
if (@object != null)
{
Logging.Write(@object.Name);
}
return @object;
}
}
#region Overrides of CustomForcedBehavior
private Composite _root;
protected override Composite CreateBehavior()
{
return _root ?? (_root =
new PrioritySelector(
new Decorator(ret => Counter >= NumOfTimes,
new Action(ret => _isDone = true)),
new PrioritySelector(
new Decorator(ret => CurrentObject != null && (CurrentObject.Distance > UsageDistance || !CurrentObject.InLineOfSight),
new Sequence(
new Action(delegate { TreeRoot.StatusText = "Moving to " + CurrentObject.Name; }),
new Action(ret => Navigator.MoveTo(CurrentObject.Location))
)
),
new Decorator(ret => CurrentObject != null && CurrentObject.Distance <= UsageDistance && CurrentObject.InLineOfSight,
new Sequence(
new DecoratorContinue(ret => StyxWoW.Me.IsMoving,
new Action(delegate
{
WoWMovement.MoveStop();
StyxWoW.SleepForLagDuration();
})),
new Action(delegate
{
TreeRoot.StatusText = "Using on " + CurrentObject.Name;
if (CurrentObject is WoWUnit)
{
(CurrentObject as WoWUnit).Target();
}
var item = StyxWoW.Me.CarriedItems.FirstOrDefault(ret => ret.Entry == ItemId);
if(item == null)
{
Logging.Write(Color.Red, "Could not find item with id:{0} for UseOnGround behavior!", ItemId);
Logging.Write(Color.Red, "Honorbuddy stopped!");
TreeRoot.Stop();
return;
}
WoWMovement.Face(CurrentObject.Guid);
item.UseContainerItem();
LegacySpellManager.ClickRemoteLocation(CurrentObject.Location);
_npcBlacklist.Add(CurrentObject.Guid);
StyxWoW.SleepForLagDuration();
Counter++;
Thread.Sleep(WaitTime);
}))
),
new Sequence(
new Action(delegate { TreeRoot.StatusText = "Moving towards - " + Location; }),
new Action(ret => Navigator.MoveTo(Location))))
));
}
private bool _isDone;
public override bool IsDone
{
get
{
PlayerQuest quest = StyxWoW.Me.QuestLog.GetQuestById(QuestId);
return
_isDone ||
(quest != null && quest.IsCompleted) ||
quest == null;
}
}
public override void OnStart()
{
PlayerQuest quest = StyxWoW.Me.QuestLog.GetQuestById(QuestId);
if (quest != null)
{
var item = StyxWoW.Me.CarriedItems.FirstOrDefault(ret => ret.Entry == ItemId);
if(item != null)
TreeRoot.GoalText = string.Format("Using {0} for {1}", item.Name, quest.Name);
else
{
TreeRoot.GoalText = string.Format("Use {0} times on id:{1} for quest:{2}", NumOfTimes, TargetId, quest.Name);
}
}
}
#endregion
}
public enum ObjectType
{
Npc,
Gameobject
}
}
PHP:
<CustomBehavior QuestId="123"
File="UseOnGround"
TargetId="123"
ItemId="123" // Use item
NumOfTimes="1"
WaitTime="2000" // Optional
CollectionDistance="100" // Optional
UsageDistance="15" // Optional
ObjectType="Gameobject" // 'Gameobject' or 'Npc'
X="12.3" Y="45.6" Z="78.9" />
Last edited: