A small thing I noticed when I was creating a script involving waypoints. If a monster is set on a waypoint, it will follow the exact path of the waypoints. Good good, all good, however, when the monster is attacked by an outside source (pet, player, other monster) it will continue to follow the path, and will not approach the player in order to melee.
This is the original code located in baseAI.cs which controls the waypoint pathing, line unknown since I've added above it.
Code:
else if( m_Mobile.CurrentWayPoint != null )
{
WayPoint point = m_Mobile.CurrentWayPoint;
if( (point.X != m_Mobile.Location.X || point.Y != m_Mobile.Location.Y) && point.Map == m_Mobile.Map && point.Parent == null && !point.Deleted )
{
m_Mobile.DebugSay( "I will move towards my waypoint." );
DoMove( m_Mobile.GetDirectionTo( m_Mobile.CurrentWayPoint ) );
}
else if( OnAtWayPoint() )
{
m_Mobile.DebugSay( "I will go to the next waypoint" );
m_Mobile.CurrentWayPoint = point.NextPoint;
if( point.NextPoint != null && point.NextPoint.Deleted )
m_Mobile.CurrentWayPoint = point.NextPoint = point.NextPoint.NextPoint;
}
}
I managed to 'fix' the script in my eyes, the monster will now respond to attacks correctly, and if the monster successfully wins the battle, will return to pathing on the waypoints at where it left off.
This is my 'fix':
Code:
else if( m_Mobile.CurrentWayPoint != null ) //Addition
{
if( m_Mobile.Combatant == null )
{
WayPoint point = m_Mobile.CurrentWayPoint;
if( (point.X != m_Mobile.Location.X || point.Y != m_Mobile.Location.Y) && point.Map == m_Mobile.Map && point.Parent == null && !point.Deleted )
{
m_Mobile.DebugSay( "I will move towards my waypoint." );
DoMove( m_Mobile.GetDirectionTo( m_Mobile.CurrentWayPoint) );
}
else if( OnAtWayPoint() )
{
m_Mobile.DebugSay( "I will go to the next waypoint" );
m_Mobile.CurrentWayPoint = point.NextPoint;
if( point.NextPoint != null && point.NextPoint.Deleted )
m_Mobile.CurrentWayPoint = point.NextPoint = point.NextPoint.NextPoint;
}
}
else if( m_Mobile.Combatant != null )
{
Mobile c = m_Mobile.Combatant;
if( c == null || c.Deleted || c.Map != m_Mobile.Map || !c.Alive || c.IsDeadBondedPet )
{
Action = ActionType.Wander;
}
else
{
m_Mobile.Direction = m_Mobile.GetDirectionTo( c );
Action = ActionType.Combat;
}
}
}