Example #1
0
        public WorldPlaceData GetWorldPlaceByWmId(int wmId)
        {
            WorldPlaceData wpData     = null;
            WorldPlaceData wpDataTemp = null;
            bool           found      = false;

            lock (_worldPlacesLock)
            {
                for (int y = 0; y < _worldPlaces.GetLength(1); y++)
                {
                    if (found)
                    {
                        break;
                    }

                    for (int x = 0; x < _worldPlaces.GetLength(0); x++)
                    {
                        wpDataTemp = _worldPlaces[x, y];
                        if (wpDataTemp == null)
                        {
                            continue;
                        }

                        if (wpDataTemp.WmId == wmId)
                        {
                            wpData = wpDataTemp;
                            found  = true;
                            break;
                        }
                    }
                }
            }

            return(wpData);
        }
Example #2
0
        public BoxedData GetLocalGeoDataOfExitElements(int wmId, int parentObjectId)
        {
            BoxedData             data       = new BoxedData();
            List <GeoDataElement> resultList = null;
            string msg = "";

            try
            {
                WorldPlaceData worldPlace = GetWorldPlaceByWmId(wmId);
                if (worldPlace == null)
                {
                    throw new Exception("world place not found!");
                }

                PlaceInstance placeInstance = worldPlace.GetPredefinedInstanceByParentObjectId(parentObjectId);
                if (placeInstance == null)
                {
                    throw new Exception("place instance not found!");
                }

                resultList = placeInstance.GetGeoDataOfExitElements();
            }
            catch (Exception exception)
            {
                msg = $"An error occured while getting geo data (exit elements), wm_id [{wmId}] parent obj, ID [{parentObjectId}]: {exception.Message}";
            }

            data.Data = (resultList ?? new List <GeoDataElement>());
            data.Msg  = msg;
            return(data);
        }
Example #3
0
        public BoxedData GetLocalGeoData(int wmId, int parentObjectId, Point3 <int> from, Point3 <int> to)
        {
            BoxedData             data       = new BoxedData();
            List <GeoDataElement> resultList = null;
            string msg = "";

            try
            {
                #region Bounds

                int pointFromX = from.X - DbTerrainObjectDefinitions.MaxCollisionXOfAllObjects;
                int pointFromY = from.Y - DbTerrainObjectDefinitions.MaxCollisionYOfAllObjects;
                int pointFromZ = from.Z - DbTerrainObjectDefinitions.MaxCollisionZOfAllObjects;
                //Console.WriteLine($"mod. point from [{pointFromX}, {pointFromY}, {pointFromZ}]");

                Point3 <int> pointFromTemp = new Point3 <int>
                                             (
                    (pointFromX <= to.X ? pointFromX - 1 : to.X - 1), //NOTE: -1 to prevent rounding error
                    (pointFromY <= to.Y ? pointFromY - 1 : to.Y - 1), //NOTE: -1 to prevent rounding error
                    (pointFromZ <= to.Z ? pointFromZ - 1 : to.Z - 1)  //NOTE: -1 to prevent rounding error
                                             );

                Point3 <int> pointToTemp = new Point3 <int>
                                           (
                    (from.X >= to.X ? from.X + 1 : to.X + 1), //NOTE: +1 to prevent rounding error
                    (from.Y >= to.Y ? from.Y + 1 : to.Y + 1), //NOTE: +1 to prevent rounding error
                    (from.Z >= to.Z ? from.Z + 1 : to.Z + 1)  //NOTE: +1 to prevent rounding error
                                           );

                #endregion

                WorldPlaceData worldPlace = GetWorldPlaceByWmId(wmId);
                if (worldPlace == null)
                {
                    throw new Exception("world place not found!");
                }

                PlaceInstance placeInstance = worldPlace.GetPredefinedInstanceByParentObjectId(parentObjectId);
                if (placeInstance == null)
                {
                    throw new Exception("place instance not found!");
                }

                resultList = placeInstance.GetGeoData(pointFromTemp, pointToTemp);
            }
            catch (Exception exception)
            {
                msg = $"An error occured while getting geo data, wm_id [{wmId}] parent obj, ID [{parentObjectId}]: {exception.Message}";
            }

            data.Data = (resultList ?? new List <GeoDataElement>());
            data.Msg  = msg;
            return(data);
        }
Example #4
0
        public Point2 <int> GetWorldCoordsByWmId(int wmId)
        {
            Point2 <int>   result = new Point2 <int>(-1, -1);
            WorldPlaceData wpData = GetWorldPlaceByWmId(wmId);

            if (wpData == null)
            {
                throw new Exception($"(getting coords from wm_id) place data of wm_id [{wmId}] not found!");
            }

            result.X = wpData.WorldPosX;
            result.Y = wpData.WorldPosY;
            return(result);
        }
Example #5
0
        public WorldPlaceDataDetails GetWorldPlaceDataDetails(int coordX, int coordY)
        {
            if (coordX >= this.MapWidth || coordY >= this.MapHeight || coordX < 0 || coordY < 0)
            {
                return(null);
            }

            WorldPlaceData placeData = _worldPlaces[coordX, coordY];

            if (placeData == null)
            {
                return(null);
            }

            return(new WorldPlaceDataDetails()
            {
                WorldPosX = placeData.WorldPosX,
                WorldPosY = placeData.WorldPosY,
                WmId = placeData.WmId,
                PlaceType = (int)placeData.Type,
                PlaceName = placeData.PlaceName
            });
        }
Example #6
0
        public async void LoadWorldDataAsync(MySqlDbManager dbManager)
        {
            this.IsLoaded     = false;
            this.LoadingError = false;
            _logger.UpdateLog("Loading game world data...");

            try
            {
                if (dbManager.GetConnectionState() != System.Data.ConnectionState.Open)
                {
                    throw new Exception("connection not open!");
                }

                #region World map settings
                //WORLD MAP SETTINGS
                _logger.UpdateLog("Getting world map settings...");
                using (BoxedData wmsBoxedData = await dbManager.GetWorldMapSettingsDataTaskStart())
                {
                    List <DbWorldMapSettingsData> wmsDataList = (List <DbWorldMapSettingsData>)wmsBoxedData.Data;
                    if (!String.IsNullOrEmpty(wmsBoxedData.Msg))
                    {
                        _logger.UpdateLog(wmsBoxedData.Msg);
                    }

                    ExtractWorldMapSettingsData(wmsDataList);
                }

                #endregion

                #region Terrain object definitions
                //TERRAIN OBJECT DEFINITIONS

                lock (_terrainDefLock)
                {
                    _terrainObjectDefinitionList.Clear();
                }

                _logger.UpdateLog("Getting terrain object definitions...");

                using (BoxedData todBoxedData = await dbManager.GetTerrainObjectDefinitionsDataTaskStart())
                {
                    lock (_terrainDefLock)
                    {
                        _terrainObjectDefinitionList = (List <DbTerrainObjectDefinitions>)todBoxedData.Data;
                    }

                    if (!String.IsNullOrEmpty(todBoxedData.Msg))
                    {
                        _logger.UpdateLog(todBoxedData.Msg);
                    }
                }

                #endregion

                #region World place data
                //WORLD PLACE DATA INITIALIZATION
                if (this.MapWidth <= 0 || this.MapHeight <= 0)
                {
                    throw new Exception($"wrong map dimensions [{this.MapWidth}, {this.MapHeight}]!");
                }

                _logger.UpdateLog("World place data initialization...");
                _worldPlaces = new WorldPlaceData[this.MapWidth, this.MapHeight];

                await Task.Factory.StartNew
                (
                    () =>
                {
                    for (int y = 0; y < this.MapHeight; y++)
                    {
                        for (int x = 0; x < this.MapWidth; x++)
                        {
                            _worldPlaces[x, y] = new WorldPlaceData(_logger, this, _terrainObjectDefinitionList, x, y);
                        }
                    }
                }
                );

                //WORLD PLACE DATA FILLING
                _logger.UpdateLog("Filling world place data...");

                using (BoxedData wmBoxedData = await dbManager.GetWorldMapDataTaskStart())
                {
                    List <DbWorldMapData> wmDataList = (List <DbWorldMapData>)wmBoxedData.Data;
                    if (!String.IsNullOrEmpty(wmBoxedData.Msg))
                    {
                        _logger.UpdateLog(wmBoxedData.Msg);
                    }

                    await Task.Factory.StartNew(() => FillWorldPlaceData(wmDataList));
                }

                #endregion

                #region Place instance creation
                //PLACE INSTANCE CREATION

                {
                    int wmId = -1;
                    List <DbTerrainObjectsData> terrainObjectsList = new List <DbTerrainObjectsData>();
                    List <int> parentIdList = new List <int>();

                    for (int y = 0; y < this.MapHeight; y++)
                    {
                        for (int x = 0; x < this.MapWidth; x++)
                        {
                            parentIdList.Clear();
                            terrainObjectsList.Clear();

                            wmId = _worldPlaces[x, y].WmId;

                            using (BoxedData parentIdsData = await dbManager.GetParentObjectIdsTaskStart(wmId))
                            {
                                parentIdList = (List <int>)parentIdsData.Data;
                                if (!String.IsNullOrEmpty(parentIdsData.Msg))
                                {
                                    _logger.UpdateLog(parentIdsData.Msg);
                                }

                                LogParentIds(x, y, parentIdList);
                            }

                            foreach (int parentId in parentIdList)
                            {
                                using (BoxedData terrainObjectsData = await dbManager.GetTerrainObjectsDataTaskStart($"`to_wm_id` = {wmId} AND `to_parent_id` = {parentId}"))
                                {
                                    terrainObjectsList = (List <DbTerrainObjectsData>)terrainObjectsData.Data;
                                    if (!String.IsNullOrEmpty(terrainObjectsData.Msg))
                                    {
                                        _logger.UpdateLog(terrainObjectsData.Msg);
                                    }

                                    _worldPlaces[x, y].AddPredefinedInstanceAsync(terrainObjectsList, parentId);

                                    while (WorldPlaceData.InstanceCreationInProgress)
                                    {
                                        await Task.Factory.StartNew(() => Thread.Sleep(50));
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion

                #region Characters
                //CHARACTER DATA INITIALIZATION
                _logger.UpdateLog("Getting characters data...");
                _characterContainer = new CharacterDataContainer();
                bool charInitSuccess = false;

                using (BoxedData dbCharsData = await dbManager.GetCharactersDataTaskStart())
                {
                    List <DbCharactersData> charDataList = (List <DbCharactersData>)dbCharsData.Data;
                    if (!String.IsNullOrEmpty(dbCharsData.Msg))
                    {
                        _logger.UpdateLog(dbCharsData.Msg);
                    }

                    using (BoxedData charContainerInitData = await _characterContainer.InitializeCharacterDataTaskStart(charDataList))
                    {
                        charInitSuccess = (bool)charContainerInitData.Data;
                        _logger.UpdateLog(charContainerInitData.Msg);
                    }
                }

                if (!charInitSuccess)
                {
                    throw new Exception("character initialization failed!");
                }

                #endregion

                this.IsLoaded = true;
            }
            catch (Exception exception)
            {
                this.LoadingError = true;
                _logger.UpdateLog($"An error occured during world data loading: {exception.Message}");
            }

            _logger.UpdateLog($"Loading world data ended with {(this.IsLoaded ? "success" : "failure")}.");
        }