Ejemplo n.º 1
0
        bool LoadPath(uint entry)
        {
            if (HasEscortState(SmartEscortState.Escorting))
            {
                return(false);
            }

            WaypointPath path = Global.SmartAIMgr.GetPath(entry);

            if (path == null || path.nodes.Empty())
            {
                GetScript().SetPathId(0);
                return(false);
            }

            _path       = new WaypointPath();
            _path.id    = path.id;
            _path.nodes = path.nodes;
            foreach (WaypointNode waypoint in _path.nodes)
            {
                GridDefines.NormalizeMapCoord(ref waypoint.x);
                GridDefines.NormalizeMapCoord(ref waypoint.y);
                waypoint.moveType = mRun ? WaypointMoveType.Run : WaypointMoveType.Walk;
            }

            GetScript().SetPathId(entry);
            return(true);
        }
Ejemplo n.º 2
0
        void FillPointMovementListForCreature()
        {
            var movePoints = Global.ScriptMgr.GetPointMoveList(me.GetEntry());

            if (movePoints.Empty())
            {
                return;
            }

            LastWP = movePoints.Last().uiPointId;

            foreach (var point in movePoints)
            {
                float x = point.fX;
                float y = point.fY;
                float z = point.fZ;

                GridDefines.NormalizeMapCoord(ref x);
                GridDefines.NormalizeMapCoord(ref y);

                WaypointNode wp = new WaypointNode();
                wp.id          = point.uiPointId;
                wp.x           = x;
                wp.y           = y;
                wp.z           = z;
                wp.orientation = 0.0f;
                wp.moveType    = m_bIsRunning ? WaypointMoveType.Run : WaypointMoveType.Walk;
                wp.delay       = point.uiWaitTime;
                wp.eventId     = 0;
                wp.eventChance = 100;

                _path.nodes.Add(wp);
            }
        }
Ejemplo n.º 3
0
        public void Load()
        {
            var oldMSTime = Time.GetMSTime();

            //                                          0    1         2           3          4            5           6        7      8           9
            SQLResult result = DB.World.Query("SELECT id, point, position_x, position_y, position_z, orientation, move_type, delay, action, action_chance FROM waypoint_data ORDER BY id, point");

            if (result.IsEmpty())
            {
                Log.outInfo(LogFilter.ServerLoading, "Loaded 0 waypoints. DB table `waypoint_data` is empty!");
                return;
            }

            uint count = 0;

            do
            {
                uint pathId = result.Read <uint>(0);

                float x = result.Read <float>(2);
                float y = result.Read <float>(3);
                float z = result.Read <float>(4);
                float o = result.Read <float>(5);

                GridDefines.NormalizeMapCoord(ref x);
                GridDefines.NormalizeMapCoord(ref y);

                WaypointNode waypoint = new();
                waypoint.id          = result.Read <uint>(1);
                waypoint.x           = x;
                waypoint.y           = y;
                waypoint.z           = z;
                waypoint.orientation = o;
                waypoint.moveType    = (WaypointMoveType)result.Read <uint>(6);

                if (waypoint.moveType >= WaypointMoveType.Max)
                {
                    Log.outError(LogFilter.Sql, $"Waypoint {waypoint.id} in waypoint_data has invalid move_type, ignoring");
                    continue;
                }

                waypoint.delay       = result.Read <uint>(7);
                waypoint.eventId     = result.Read <uint>(8);
                waypoint.eventChance = result.Read <byte>(9);

                if (!_waypointStore.ContainsKey(pathId))
                {
                    _waypointStore[pathId] = new WaypointPath();
                }

                WaypointPath path = _waypointStore[pathId];
                path.id = pathId;
                path.nodes.Add(waypoint);

                ++count;
            } while (result.NextRow());

            Log.outInfo(LogFilter.ServerLoading, $"Loaded {count} waypoints in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
        }
Ejemplo n.º 4
0
        public void LeaderMoveTo(float x, float y, float z)
        {
            //! To do: This should probably get its own movement generator or use WaypointMovementGenerator.
            //! If the leader's path is known, member's path can be plotted as well using formation offsets.
            if (!m_leader)
            {
                return;
            }

            float pathangle = (float)Math.Atan2(m_leader.GetPositionY() - y, m_leader.GetPositionX() - x);

            foreach (var pair in m_members)
            {
                Creature member = pair.Key;
                if (member == m_leader || !member.IsAlive() || member.GetVictim() || !pair.Value.groupAI.HasAnyFlag((uint)GroupAIFlags.IdleInFormation))
                {
                    continue;
                }

                if (pair.Value.point_1 != 0)
                {
                    if (m_leader.GetCurrentWaypointID() == pair.Value.point_1 - 1 || m_leader.GetCurrentWaypointID() == pair.Value.point_2 - 1)
                    {
                        pair.Value.follow_angle = (float)Math.PI * 2 - pair.Value.follow_angle;
                    }
                }

                float angle = pair.Value.follow_angle;
                float dist  = pair.Value.follow_dist;

                float dx = x + (float)Math.Cos(angle + pathangle) * dist;
                float dy = y + (float)Math.Sin(angle + pathangle) * dist;
                float dz = z;

                GridDefines.NormalizeMapCoord(ref dx);
                GridDefines.NormalizeMapCoord(ref dy);

                if (!member.IsFlying())
                {
                    member.UpdateGroundPositionZ(dx, dy, ref dz);
                }

                if (member.IsWithinDist(m_leader, dist + 5.0f))
                {
                    member.SetUnitMovementFlags(m_leader.GetUnitMovementFlags());
                }
                else
                {
                    member.SetWalk(false);
                }

                member.GetMotionMaster().MovePoint(0, dx, dy, dz);
                member.SetHomePosition(dx, dy, dz, pathangle);
            }
        }
Ejemplo n.º 5
0
        public void Load()
        {
            var oldMSTime = Time.GetMSTime();

            //                                          0    1         2           3          4            5           6        7      8           9
            SQLResult result = DB.World.Query("SELECT id, point, position_x, position_y, position_z, orientation, move_type, delay, action, action_chance FROM waypoint_data ORDER BY id, point");

            if (result.IsEmpty())
            {
                Log.outError(LogFilter.ServerLoading, "Loaded 0 waypoints. DB table `waypoint_data` is empty!");
                return;
            }

            uint count = 0;

            do
            {
                WaypointData wp = new WaypointData();

                uint pathId = result.Read <uint>(0);

                float x = result.Read <float>(2);
                float y = result.Read <float>(3);
                float z = result.Read <float>(4);
                float o = result.Read <float>(5);

                GridDefines.NormalizeMapCoord(ref x);
                GridDefines.NormalizeMapCoord(ref y);

                wp.id          = result.Read <uint>(1);
                wp.x           = x;
                wp.y           = y;
                wp.z           = z;
                wp.orientation = o;
                wp.movetype    = (WaypointMoveType)result.Read <uint>(6);
                if (wp.movetype >= WaypointMoveType.Max)
                {
                    Log.outError(LogFilter.Sql, "Waypoint {0} in waypoint_data has invalid move_type, ignoring", wp.id);
                    continue;
                }

                wp.delay        = result.Read <uint>(7);
                wp.event_id     = result.Read <uint>(8);
                wp.event_chance = result.Read <byte>(9);

                _waypointStore.Add(pathId, wp);
                ++count;
            } while (result.NextRow());

            Log.outInfo(LogFilter.ServerLoading, "Loaded {0} waypoints in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
        }
Ejemplo n.º 6
0
        public void ReloadPath(uint id)
        {
            _waypointStore.Remove(id);

            PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_ID);

            stmt.AddValue(0, id);
            SQLResult result = DB.World.Query(stmt);

            if (result.IsEmpty())
            {
                return;
            }

            do
            {
                float x = result.Read <float>(1);
                float y = result.Read <float>(2);
                float z = result.Read <float>(3);
                float o = result.Read <float>(4);

                GridDefines.NormalizeMapCoord(ref x);
                GridDefines.NormalizeMapCoord(ref y);

                WaypointNode wp = new WaypointNode();
                wp.id          = result.Read <uint>(0);
                wp.x           = x;
                wp.y           = y;
                wp.z           = z;
                wp.orientation = o;
                wp.moveType    = (WaypointMoveType)result.Read <uint>(5);

                if (wp.moveType >= WaypointMoveType.Max)
                {
                    Log.outError(LogFilter.Sql, "Waypoint {0} in waypoint_data has invalid move_type, ignoring", wp.id);
                    continue;
                }

                wp.delay       = result.Read <uint>(6);
                wp.eventId     = result.Read <uint>(7);
                wp.eventChance = result.Read <byte>(8);

                if (!_waypointStore.ContainsKey(id))
                {
                    _waypointStore[id] = new WaypointPath();
                }

                _waypointStore[id].nodes.Add(wp);
            }while (result.NextRow());
        }
Ejemplo n.º 7
0
        void FillPointMovementListForCreature()
        {
            WaypointPath path = Global.WaypointMgr.GetPath(me.GetEntry());

            if (path == null)
            {
                return;
            }

            foreach (WaypointNode value in path.nodes)
            {
                WaypointNode node = value;
                GridDefines.NormalizeMapCoord(ref node.x);
                GridDefines.NormalizeMapCoord(ref node.y);
                node.moveType = _running ? WaypointMoveType.Run : WaypointMoveType.Walk;

                _path.nodes.Add(node);
            }
        }
Ejemplo n.º 8
0
        public void AddWaypoint(uint id, float x, float y, float z, float orientation = 0, uint waitTime = 0)
        {
            GridDefines.NormalizeMapCoord(ref x);
            GridDefines.NormalizeMapCoord(ref y);

            WaypointNode waypoint = new WaypointNode();

            waypoint.id          = id;
            waypoint.x           = x;
            waypoint.y           = y;
            waypoint.z           = z;
            waypoint.orientation = orientation;
            waypoint.moveType    = _running ? WaypointMoveType.Run : WaypointMoveType.Walk;
            waypoint.delay       = waitTime;
            waypoint.eventId     = 0;
            waypoint.eventChance = 100;
            _path.nodes.Add(waypoint);

            _manualPath = true;
        }
Ejemplo n.º 9
0
        bool LoadPath(uint entry)
        {
            if (HasEscortState(SmartEscortState.Escorting))
            {
                return(false);
            }

            var path = Global.SmartAIMgr.GetPath(entry);

            if (path.Empty())
            {
                GetScript().SetPathId(0);
                return(false);
            }

            foreach (WayPoint waypoint in path)
            {
                float x = waypoint.x;
                float y = waypoint.y;
                float z = waypoint.z;

                GridDefines.NormalizeMapCoord(ref x);
                GridDefines.NormalizeMapCoord(ref y);

                WaypointNode wp = new WaypointNode();
                wp.id          = waypoint.id;
                wp.x           = x;
                wp.y           = y;
                wp.z           = z;
                wp.orientation = 0.0f;
                wp.moveType    = mRun ? WaypointMoveType.Run : WaypointMoveType.Walk;
                wp.delay       = 0;
                wp.eventId     = 0;
                wp.eventChance = 100;

                _path.nodes.Add(wp);
            }

            GetScript().SetPathId(entry);
            return(true);
        }
Ejemplo n.º 10
0
        public void AddWaypoint(uint id, float x, float y, float z, uint waitTime = 0)
        {
            GridDefines.NormalizeMapCoord(ref x);
            GridDefines.NormalizeMapCoord(ref y);

            WaypointNode wp = new WaypointNode();

            wp.id          = id;
            wp.x           = x;
            wp.y           = y;
            wp.z           = z;
            wp.orientation = 0.0f;
            wp.moveType    = m_bIsRunning ? WaypointMoveType.Run : WaypointMoveType.Walk;
            wp.delay       = waitTime;
            wp.eventId     = 0;
            wp.eventChance = 100;

            _path.nodes.Add(wp);

            LastWP = id;

            ScriptWP = true;
        }
Ejemplo n.º 11
0
        public void _setRandomLocation(Creature creature)
        {
            if (creature.IsMovementPreventedByCasting())
            {
                creature.CastStop();
                return;
            }

            float respX, respY, respZ, respO, destX, destY, destZ, travelDistZ;

            creature.GetHomePosition(out respX, out respY, out respZ, out respO);
            Map map = creature.GetMap();

            bool is_air_ok = creature.CanFly();

            float angle     = (float)(RandomHelper.NextDouble() * MathFunctions.TwoPi);
            float range     = (float)(RandomHelper.NextDouble() * wander_distance);
            float distanceX = (float)(range * Math.Cos(angle));
            float distanceY = (float)(range * Math.Sin(angle));

            destX = respX + distanceX;
            destY = respY + distanceY;

            // prevent invalid coordinates generation
            GridDefines.NormalizeMapCoord(ref destX);
            GridDefines.NormalizeMapCoord(ref destY);

            travelDistZ = range;   // sin^2+cos^2=1, so travelDistZ=range^2; no need for sqrt below

            if (is_air_ok)         // 3D system above ground and above water (flying mode)
            {
                // Limit height change
                float distanceZ = (float)(RandomHelper.NextDouble() * travelDistZ / 2.0f);
                destZ = respZ + distanceZ;
                float levelZ = map.GetWaterOrGroundLevel(creature.GetPhases(), destX, destY, destZ - 2.5f);

                // Problem here, we must fly above the ground and water, not under. Let's try on next tick
                if (levelZ >= destZ)
                {
                    return;
                }
            }
            else                                                    // 2D only
            {
                // 10.0 is the max that vmap high can check (MAX_CAN_FALL_DISTANCE)
                travelDistZ = travelDistZ >= 10.0f ? 10.0f : travelDistZ;

                // The fastest way to get an accurate result 90% of the time.
                // Better result can be obtained like 99% accuracy with a ray light, but the cost is too high and the code is too long.
                destZ = map.GetHeight(creature.GetPhases(), destX, destY, respZ + travelDistZ - 2.0f, false);

                if (Math.Abs(destZ - respZ) > travelDistZ)              // Map check
                {
                    // Vmap Horizontal or above
                    destZ = map.GetHeight(creature.GetPhases(), destX, destY, respZ - 2.0f, true);

                    if (Math.Abs(destZ - respZ) > travelDistZ)
                    {
                        // Vmap Higher
                        destZ = map.GetHeight(creature.GetPhases(), destX, destY, respZ + travelDistZ - 2.0f, true);

                        // let's forget this bad coords where a z cannot be find and retry at next tick
                        if (Math.Abs(destZ - respZ) > travelDistZ)
                        {
                            return;
                        }
                    }
                }
            }

            if (is_air_ok)
            {
                i_nextMoveTime.Reset(0);
            }
            else
            {
                if (RandomHelper.randChance(50))
                {
                    i_nextMoveTime.Reset(RandomHelper.IRand(5000, 10000));
                }
                else
                {
                    i_nextMoveTime.Reset(RandomHelper.IRand(50, 400));
                }
            }

            creature.AddUnitState(UnitState.RoamingMove);

            MoveSplineInit init = new MoveSplineInit(creature);

            init.MoveTo(destX, destY, destZ);
            init.SetWalk(true);
            init.Launch();

            //Call for creature group update
            if (creature.GetFormation() != null && creature.GetFormation().getLeader() == creature)
            {
                creature.GetFormation().LeaderMoveTo(destX, destY, destZ);
            }
        }