Ejemplo n.º 1
0
 public override bool EnableWalking()
 {
     if (typeof(T) == typeof(Player))
     {
         return(false);
     }
     else
     {
         return(Reftarget.IsValid() && Target.IsWalking());
     }
 }
Ejemplo n.º 2
0
        public override void _updateSpeed(T owner)
        {
            if (owner.IsTypeId(TypeId.Player))
            {
                return;
            }

            if (!owner.IsPet() || !owner.IsInWorld || !Reftarget.IsValid() && Target.GetGUID() != owner.GetOwnerGUID())
            {
                return;
            }

            owner.UpdateSpeed(UnitMoveType.Run);
            owner.UpdateSpeed(UnitMoveType.Walk);
            owner.UpdateSpeed(UnitMoveType.Swim);
        }
Ejemplo n.º 3
0
        public override bool DoUpdate(T owner, uint time_diff)
        {
            if (!Reftarget.IsValid() || !Target.IsInWorld)
            {
                return(false);
            }

            if (owner == null || !owner.IsAlive())
            {
                return(false);
            }

            if (owner.HasUnitState(UnitState.NotMove))
            {
                _clearUnitStateMove(owner);
                return(true);
            }

            // prevent movement while casting spells with cast time or channel time
            if (owner.IsMovementPreventedByCasting())
            {
                if (!owner.IsStopped())
                {
                    owner.StopMoving();
                }
                return(true);
            }

            // prevent crash after creature killed pet
            if (_lostTarget(owner))
            {
                _clearUnitStateMove(owner);
                return(true);
            }

            bool targetMoved = false;

            recheckDistance.Update((int)time_diff);
            if (recheckDistance.Passed())
            {
                recheckDistance.Reset(100);
                //More distance let have better performance, less distance let have more sensitive reaction at target move.
                float allowed_dist = 0.0f;// owner.GetCombatReach() + WorldConfig.GetFloatValue(WorldCfg.RateTargetPosRecalculationRange);

                if (owner.IsPet() && (owner.GetCharmerOrOwnerGUID() == Target.GetGUID()))
                {
                    allowed_dist = 1.0f; // pet following owner
                }
                else
                {
                    allowed_dist = owner.GetCombatReach() + WorldConfig.GetFloatValue(WorldCfg.RateTargetPosRecalculationRange);
                }

                Vector3 dest = owner.MoveSpline.FinalDestination();
                if (owner.MoveSpline.onTransport)
                {
                    float      o         = 0;
                    ITransport transport = owner.GetDirectTransport();
                    if (transport != null)
                    {
                        transport.CalculatePassengerPosition(ref dest.X, ref dest.Y, ref dest.Z, ref o);
                    }
                }

                // First check distance
                if (owner.IsTypeId(TypeId.Unit) && (owner.ToCreature().CanFly() || owner.ToCreature().CanSwim()))
                {
                    targetMoved = !Target.IsWithinDist3d(dest.X, dest.Y, dest.Z, allowed_dist);
                }
                else
                {
                    targetMoved = !Target.IsWithinDist2d(dest.X, dest.Y, allowed_dist);
                }


                // then, if the target is in range, check also Line of Sight.
                if (!targetMoved)
                {
                    targetMoved = !Target.IsWithinLOSInMap(owner);
                }
            }

            if (recalculateTravel || targetMoved)
            {
                _setTargetLocation(owner, targetMoved);
            }

            if (owner.MoveSpline.Finalized())
            {
                MovementInform(owner);
                if (angle == 0.0f && !owner.HasInArc(0.01f, Target))
                {
                    owner.SetInFront(Target);
                }

                if (!targetReached)
                {
                    targetReached = true;
                    _reachTarget(owner);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        public void _setTargetLocation(T owner, bool updateDestination)
        {
            if (!Reftarget.IsValid() || !Target.IsInWorld)
            {
                return;
            }

            if (owner.HasUnitState(UnitState.NotMove))
            {
                return;
            }

            if (owner.IsMovementPreventedByCasting())
            {
                return;
            }

            if (owner.IsTypeId(TypeId.Unit) && !Target.IsInAccessiblePlaceFor(owner.ToCreature()))
            {
                owner.ToCreature().SetCannotReachTarget(true);
                return;
            }

            if (owner.IsTypeId(TypeId.Unit) && owner.ToCreature().IsFocusing(null, true))
            {
                return;
            }

            float x, y, z;

            if (updateDestination || i_path == null)
            {
                if (offset == 0)
                {
                    if (Target.IsWithinDistInMap(owner, SharedConst.ContactDistance))
                    {
                        return;
                    }

                    // to nearest contact position
                    Target.GetContactPoint(owner, out x, out y, out z);
                }
                else
                {
                    float dist = 0;
                    float size = 0;

                    // Pets need special handling.
                    // We need to subtract GetObjectSize() because it gets added back further down the chain
                    //  and that makes pets too far away. Subtracting it allows pets to properly
                    //  be (GetCombatReach() + i_offset) away.
                    // Only applies when i_target is pet's owner otherwise pets and mobs end up
                    //   doing a "dance" while fighting
                    if (owner.IsPet() && Target.IsTypeId(TypeId.Player))
                    {
                        dist = 1.0f; // target.GetCombatReach();
                        size = 1.0f; // target.GetCombatReach() - target.GetObjectSize();
                    }
                    else
                    {
                        dist = offset + 1.0f;
                        size = owner.GetObjectSize();
                    }

                    if (Target.IsWithinDistInMap(owner, dist))
                    {
                        return;
                    }

                    // to at i_offset distance from target and i_angle from target facing
                    Target.GetClosePoint(out x, out y, out z, size, offset, angle);
                }
            }
            else
            {
                // the destination has not changed, we just need to refresh the path (usually speed change)
                var end = i_path.GetEndPosition();
                x = end.X;
                y = end.Y;
                z = end.Z;
            }

            if (i_path == null)
            {
                i_path = new PathGenerator(owner);
            }

            // allow pets to use shortcut if no path found when following their master
            bool forceDest = (owner.IsTypeId(TypeId.Unit) && owner.IsPet() &&
                              owner.HasUnitState(UnitState.Follow));

            bool result = i_path.CalculatePath(x, y, z, forceDest);

            if (!result && Convert.ToBoolean(i_path.GetPathType() & PathType.NoPath))
            {
                // Can't reach target
                recalculateTravel = true;
                if (owner.IsTypeId(TypeId.Unit))
                {
                    owner.ToCreature().SetCannotReachTarget(true);
                }
                return;
            }

            _addUnitStateMove(owner);
            targetReached     = false;
            recalculateTravel = false;
            owner.AddUnitState(UnitState.Chase);
            if (owner.IsTypeId(TypeId.Unit))
            {
                owner.ToCreature().SetCannotReachTarget(false);
            }

            MoveSplineInit init = new MoveSplineInit(owner);

            init.MovebyPath(i_path.GetPath());
            init.SetWalk(EnableWalking());
            // Using the same condition for facing target as the one that is used for SetInFront on movement end
            // - applies to ChaseMovementGenerator mostly
            if (angle == 0.0f)
            {
                init.SetFacing(Target);
            }

            init.Launch();
        }