Example #1
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
            {
                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 WaypointNode();
                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");
        }
Example #2
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());
        }