Pet aggro model

Pet AI is not as complicated as it first seems. The following is a model that accurately predicts pet behavior (mostly). The model is written to a command intensive use, and does not include passive pet AI that guides the pet when there is no master or when the master is not giving commands. Definitional Framework is given first, followed by the actual model. Bugs and Ad Hoc (things added to allow the model to better predict behavior) are given last.
 * Framework
 * state of attacking: The master enters this state as soon as the attack command is given. If an attack is initiated, and then a casting time skill is used, the master continues to remain in a state of attacking through the cast time.
 * attack: An attack has been performed once the wielded weapon has been used. Attacks that have been obstructed are not considered attacks for this model
 * heeled: This is when the pet is following the master. This state is entered anytime the pet has fully returned to the master.
 * pet aggro delay: This is the delay between the time a target is chosen for the pet and when the pet actually obtains that target. This delay seems to be about one second.
 * aggroed: This is when the pet is actively chasing and attacking its target. This state is entered when the pet has obtained a target.  If the pet loses its target, it will begin to return to the master.
 * flee check: While aggroed, the pet checks periodically to see if the master is fleeing. If the master is moving in any direction when this check is performed, the pet loses its target.  I am not exactly sure what the timing cycle for this flee check is, but it seems to be about every ~5 seconds.
 * target check: While aggroed, the pet checks periodically to see if a new target has been assigned via the master initiating a state of attack on a different target. If you have selected a new target, you must wait for the pet to perform a target check before it will switch.  This may occur on the same cycle the flee check does, and appears to also be about every ~5 seconds.


 * Model
 * The pet's target is that which the master has initiated a state of attack upon.
 * When the pet is heeled, an attack must be completed before the pet aggro delay will start
 * When the pet is aggroed, the pet will switch targets if it performs a target check while a state of attack is initiated. Note that no attack need actually be performed for the pet to switch targets.


 * Bugs/Ad Hoc
 * If the pet gets stuck because it is surrounded by monsters and can't move at all, it may freeze in place and refuse to do anything, even when it is no longer surrounded. If it is stuck and mobs are still around it, assign it to attack the mob it is facing as this will often fix it.  Otherwise the remedy is to run up right on top of the pet.  This does not happen very often, and generally happens in certain areas and with certain mobs.  Once you get a feeling for where it happens, with what mobs, and why, it can usually be avoided altogether.
 * In PvP, your targets are moving around a lot. At times they even seem to shake the pet's AI.  Be wary of this and if you see your pet running back to you or not moving, but you know you haven't tripped the flee check, this is probably what it is.  Just enter a state of attacking for a second and the pet will return to its mark.

Conclusions
Though the model should allow you do deduce anything you should ever want to know about commanding your pet, here is a list of some useful predictions from the model:
 * You can use a long range bow to command your pet to attack. As soon as it has began to run to its target, you are free to run away, continue attacking your now mutual target, or select a new target to heal or cast spells upon.  While you do all these things the pet will continue to chase and attack its given target until either the flee check or target check is tripped. (currently investigating whether switching your target, but not attacking, will trip the target check.  If it doesn't, will investigate if casting spells, but not initiating attack, will then trip it)
 * You can command the pet to attack the closest or easiest target for you to reach with a bow. The pet will run to attack it, you can now switch to a more desirable, soft, backline target (like a healer or nuker), and your pet will switch to it now!  The new target doesn't have to be anywhere near your weapon range or aggro circle, so you can get to an opposing teams softies without putting yourself in danger.  Even better, most players ignore the pet!  Very useful for PvP!
 * If you want to pull, but don't want your pet to rush in where it may aggro everything, shoot one arrow and immediately cancel your attack before your pets aggro delay has completed. This way you can pull monsters out without your pet rushing in.