コード例 #1
0
 public void Clear()
 {
     lock (_lck)
     {
         ServerMap.Clear();
     }
 }
コード例 #2
0
 public void RemoveServer(string baseUrl)
 {
     lock (_lck)
     {
         ServerMap.RemoveAll(m => m.BaseUrl == baseUrl);
     }
 }
コード例 #3
0
        private MapSaveResponse SaveMapRot(MapApiParams p)
        {
            List <string>   mapRot = p.Maps;
            MapSaveResponse r;

            sRMtx.WaitOne();
            try
            {
                ServerMap.SaveMapRotation(Core, mapRot);
                //theres a good chance that only maps were updated
                //in this case we dont want to re-write ServerSettings.cfg -> check if Randomize changed
                if (Core.Server.Settings.Randomize != p.Randomize)
                {
                    Core.Server.Settings.Randomize = p.Randomize;
                    Core.Server.Settings.WriteToFile(Core);
                }
                r = new MapSaveResponse();
            }
            catch (Exception e)
            {
                r = new MapSaveResponse(e);
            }
            finally
            {
                sRMtx.ReleaseMutex();
            }
            return(r);
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: PsychoTeras/RatKing
        public static ShortPoint?FindPlayerStartPoint(ServerMap map, Player player, int minAreaSpace)
        {
            var areas = map.SpaceAreas;
            int iStart = _rnd.Next(areas.Count), iEnd = areas.Count;

            bool secondIter = false;

            for (int i = iStart; i <= iEnd; i++)
            {
                if (i == iEnd)
                {
                    if (secondIter)
                    {
                        return(null);
                    }
                    i          = 0;
                    iEnd       = iStart - 1;
                    secondIter = true;
                }
                MapArea area = areas[i];
                if (area.CellsCount * ConstMap.PIXEL_SIZE_SQR >= minAreaSpace)
                {
                    int        playerMargin = (int)Math.Floor((float)player.Size.HighValue / ConstMap.PIXEL_SIZE);
                    ShortPoint?cell         = area.FindFreeCell(map, playerMargin, _rnd);
                    if (cell != null)
                    {
                        return(cell);
                    }
                }
            }

            return(null);
        }
コード例 #5
0
        public void TestSimpleLoading()
        {
            ServerMap map = AssetLoader.LoadMapFromFile();

            Assert.That(map.Tilesets.Count > 0);

            Assert.That(map.Chunks.Count >= 2);
        }
コード例 #6
0
ファイル: CmdAddMap.cs プロジェクト: yonilerner/swbf2admin
        public override bool AffectMap(ServerMap map, string mode, Player player, string commandLine, string[] parameters, int paramIdx)
        {
            SendFormatted(OnAddMap, "{map_name}", map.Name, "{map_nicename}", map.NiceName, "{gamemode}", mode);

            Core.Rcon.SendCommand("removemap", map.Name + mode);
            Core.Rcon.SendCommand("addmap", map.Name + mode);
            return(true);
        }
コード例 #7
0
        public override bool AffectMap(ServerMap map, string mode, Player player, string commandLine, string[] parameters, int paramIdx)
        {
            SendFormatted(OnSetMap, "{map_name}", map.Name, "{map_nicename}", map.NiceName, "{gamemode}", mode);

            //hacky way of setting next map without having to worry about it being in the rotation
            Core.Rcon.SendCommand("removemap", map.Name + mode);
            Core.Rcon.SendCommand("addmap", map.Name + mode);
            return(true);
        }
コード例 #8
0
        public void TestTileIndexesCorrect()
        {
            ServerMap map = AssetLoader.LoadMapFromFile();

            var chunk0 = map.GetChunkByChunkPosition(0, 0);
            var chunk1 = map.GetChunkByChunkPosition(1, 0);

            Assert.That(chunk0.Tiles[0, 0].Position.X == 0);
            Assert.That(chunk1.Tiles[0, 0].Position.X == 16);
        }
コード例 #9
0
ファイル: Server.cs プロジェクト: tuita520/MobileMMORTS
 public Server(int port, string mapName = "test")
 {
     PORT      = port;
     _instance = this;
     Events?.Clear();
     Events         = new ServerEvents();
     CommandHandler = new CommandHandler();
     AssetLoader.LoadServerAssets();
     Map = AssetLoader.LoadMapFromFile(mapName);
     Map.LoadAllSpawners();
 }
コード例 #10
0
ファイル: GameWorld.cs プロジェクト: PsychoTeras/RatKing
 public void LoadMap()
 {
     foreach (ServerMap map in _maps.Values)
     {
         map.Dispose();
     }
     _maps.Clear();
     if (File.Exists("RK.save"))
     {
         ServerMap map = ServerMap.LoadFromFile("RK.save");
         _maps.Add(map.Id, map);
     }
 }
コード例 #11
0
        public void TestMapLoadTestMap()
        {
            ServerMap map = AssetLoader.LoadMapFromFile("test_map");

            Assert.That(map.Chunks.Count >= 2);

            Chunk chunk = map.GetChunkByChunkPosition(0, 0);

            Assert.AreEqual(chunk.Tiles[0, 0].TileId, 1);
            Assert.AreEqual(chunk.Tiles[1, 0].TileId, 1);
            Assert.AreEqual(chunk.Tiles[2, 0].TileId, 1);

            chunk = map.GetChunkByChunkPosition(0, 0);
        }
コード例 #12
0
        public void TestLoadingSpawners()
        {
            ServerMap map = AssetLoader.LoadMapFromFile("test");

            Assert.That(map.Spawners.Count > 0);

            var spawner = map.Spawners[0];

            Assert.That(spawner.SpawnerMobs.Count == 1);

            var spawnerMob = spawner.SpawnerMobs[0];

            Assert.AreEqual(typeof(Skeleton), spawnerMob.MonsterClassType);
            Assert.AreEqual(1, spawnerMob.Amount);
        }
コード例 #13
0
        public CrawlerElectResult GetServer(string ip)
        {
            var server = ServerMap.FirstOrDefault(m => m.ClientIp == ip);

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

            return(new CrawlerElectResult
            {
                BaseUrl = server.BaseUrl,
                ClientIp = ip
            });
        }
コード例 #14
0
 public Server(ServerStartConfig config)
 {
     PORT      = config.Port;
     _instance = this;
     Events?.Clear();
     Events         = new ServerEvents();
     CommandHandler = new CommandHandler();
     TcpHandler     = new ServerTcpHandler();
     AssetLoader.LoadServerAssets();
     Map = AssetLoader.LoadMapFromFile(config.MapName);
     if (!config.DisableSpawners)
     {
         Map.LoadAllSpawners();
     }
 }
コード例 #15
0
        public void AddServer(string baseUrl, string[] ips)
        {
            lock (_lck)
            {
                ServerMap.RemoveAll(m => m.BaseUrl == baseUrl);

                foreach (var ip in ips)
                {
                    var svr = new Server();
                    svr.BaseUrl  = baseUrl;
                    svr.ClientIp = ip;

                    ServerMap.Add(svr);
                }
            }
        }
コード例 #16
0
ファイル: Tools.cs プロジェクト: Xathz/Head-Non-Sub
        public async Task ServerMap()
        {
            try {
                ServerMap map      = new ServerMap(Context);
                string    jsonFile = map.Generate();

                await Context.User.SendFileAsync(jsonFile, $"{Context.Guild.Name} (`{Context.Guild.Id}`): Server Map");

                await BetterReplyAsync($"{Context.User.Mention} the server map was sent to you privately. The message may be blocked if you reject direct messages.");
            } catch (Exception ex) {
                LoggingManager.Log.Error(ex);
                await BetterReplyAsync("Failed to generate the server map.");
            }

            await LogMessageEmbedAsync($"Server map executed `@{Context.Guild.CurrentUser} servermap`");
        }
コード例 #17
0
ファイル: CmdRemoveMap.cs プロジェクト: yonilerner/swbf2admin
        public override bool AffectMap(ServerMap map, string mode, Player player, string commandLine, string[] parameters, int paramIdx)
        {
            string r = Core.Rcon.SendCommand("removemap", map.Name + mode);

            //TODO: check if that's what the server outputs
            if (r.Equals("map removed"))
            {
                SendFormatted(OnRemoveMap, "{map_name}", map.Name, "{map_nicename}", map.NiceName, "{gamemode}", mode);
            }
            else
            {
                SendFormatted(OnNotInMapRot, "{map_name}", map.Name, "{map_nicename}", map.NiceName, "{gamemode}", mode);
            }

            return(true);
        }
コード例 #18
0
ファイル: TileBorders.cs プロジェクト: PsychoTeras/RatKing
        public static byte GetBorders(int x, int y, ushort w, ushort h, TileType areaType, ServerMap map)
        {
            if (IsNotValidTile(x, y, w, h, areaType, map))
            {
                return 0;
            }

            byte flag = 0;

            if (IsNotValidTile(x - 1, y, w, h, areaType, map)) flag |= 1;
            if (IsNotValidTile(x + 1, y, w, h, areaType, map)) flag |= 2;
            if (IsNotValidTile(x, y - 1, w, h, areaType, map)) flag |= 4;
            if (IsNotValidTile(x, y + 1, w, h, areaType, map)) flag |= 8;

            return flag;
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: PsychoTeras/RatKing
        internal void TestGameMapPerf()
        {
            const ushort mapWidth = 1000, mapHeight = 1000;

            int     count = mapWidth * mapHeight;
            HRTimer timer = HRTimer.CreateAndStart();

#if UNSAFE_ARRAY
            int   sizeOfTile = Marshal.SizeOf(typeof(Tile));
            Tile *pTiles     = (Tile *)Memory.HeapAlloc(count * sizeOfTile);
#else
            Tile[,] aTiles = new Tile[MapWidth, MapHeight];
#endif
            System.Console.WriteLine(timer.StopWatch());

            timer = HRTimer.CreateAndStart();
            for (int i = 0; i < count; i++)
            {
#if !UNSAFE_ARRAY
                fixed(Tile *pTiles = aTiles)
#endif
                {
                    pTiles[i].Type      = TileType.Wall;
                    pTiles[i].TypeIndex = 100;
                }
            }
            System.Console.WriteLine(timer.StopWatch());
#if UNSAFE_ARRAY
            Memory.HeapFree(pTiles);
#endif

            using (ServerMap map = new ServerMap(mapWidth, mapHeight, 0))
            {
                timer = HRTimer.CreateAndStart();

                for (ushort y = 0; y < mapHeight; y++)
                {
                    for (ushort x = 0; x < mapWidth; x++)
                    {
                        Tile *tile = map[x, y];
                        (*tile).Type      = TileType.Nothing;
                        (*tile).TypeIndex = 1;
                    }
                }
                System.Console.WriteLine(timer.StopWatch());
            }
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: PsychoTeras/RatKing
        internal static void TestMapWindowGetPerf()
        {
            using (ServerMap serverMap = ServerMap.LoadFromFile("RK.save"))
            {
                ServerMap map = serverMap;

                HRTimer timer = HRTimer.CreateAndStart();

                for (int i = 0; i < 100; i++)
                {
                    int startX = 0, startY = 0;
                    int wWidth = 150, wHeight = 150;
                    map.GetWindow(startX, startY, wWidth, wHeight);
                }
                System.Console.WriteLine(timer.StopWatch());
            }
        }
コード例 #21
0
        public void TestMapLoadTestMap()
        {
            ServerMap map = AssetLoader.LoadMapFromFile("test_map");

            Assert.That(map.Chunks.Count >= 2);

            Chunk chunk = map.GetChunk(0, 0);

            Assert.AreEqual(chunk.GetTile(0, 0), 1);
            Assert.AreEqual(chunk.GetTile(1, 0), 2);
            Assert.AreEqual(chunk.GetTile(2, 0), 3);

            Assert.AreEqual(chunk.GetTile(0, 1), 4);
            Assert.AreEqual(chunk.GetTile(1, 1), 3);
            Assert.AreEqual(chunk.GetTile(2, 1), 2);
            Assert.AreEqual(chunk.GetTile(3, 1), 1);

            chunk = map.GetChunk(0, 0);
        }
コード例 #22
0
        private MapRotResponse GetMapRotation()
        {
            MapRotResponse r;

            sRMtx.WaitOne();
            try
            {
                r = new MapRotResponse(ServerMap.ReadMapRotation(Core), Core.Server.Settings.Randomize);
            }
            catch (Exception e)
            {
                r = new MapRotResponse(e);
            }
            finally
            {
                sRMtx.ReleaseMutex();
            }

            return(r);
        }
コード例 #23
0
        private MapSaveResponse SaveMapRot(MapApiParams p)
        {
            List <string>   mapRot = p.Maps;
            MapSaveResponse r;

            sRMtx.WaitOne();
            try
            {
                ServerMap.SaveMapRotation(Core, mapRot);

                if (Core.Config.EnableRuntime && Core.Server.Status == ServerStatus.Online)
                {
                    Core.Scheduler.PushTask(() => Core.Rcon.UpdateMapList(mapRot));
                }

                //there's a good chance that only maps were updated
                //in this case we dont want to re-write ServerSettings.cfg -> check if Randomize changed
                if (Core.Server.Settings.Randomize != p.Randomize)
                {
                    Core.Server.Settings.Randomize = p.Randomize;
                    Core.Server.Settings.WriteToFile(Core);
                    if (Core.Config.EnableRuntime && Core.Server.Status == ServerStatus.Online)
                    {
                        Core.Scheduler.PushTask(() => Core.Rcon.SendCommand("randomize", p.Randomize ? "1" : "0"));
                    }
                }
                r = new MapSaveResponse();
            }
            catch (Exception e)
            {
                r = new MapSaveResponse(e);
            }
            finally
            {
                sRMtx.ReleaseMutex();
            }
            return(r);
        }
コード例 #24
0
        public void Run(string[] args)
        {
            Logger.Log(LogLevel.Info, Log.CORE_START, Util.GetProductName(), Util.GetProductVersion(), Util.GetProductAuthor());
            Logger.Log(LogLevel.Verbose, Log.CORE_READ_CONFIG);
            config = Files.ReadConfig <CoreConfiguration>();
            Logger.Log(LogLevel.Info, Log.CORE_READ_CONFIG_OK);
            Logger.MinLevel  = config.LogMinimumLevel;
            Logger.LogToFile = config.LogToFile;
            Logger.LogFile   = config.LogFileName;

            components.Add(Database);
            components.Add(Server);
            components.Add(WebAdmin);
            components.Add(Plugins);

            if (config.EnableRuntime)
            {
                components.Add(Rcon);
                components.Add(Players);
                components.Add(Announce);
                components.Add(Game);
                components.Add(Commands);
                components.Add(Mods);
            }

            Scheduler.TickDelay = Config.TickDelay;

            Rcon.Disconnected += new EventHandler(Rcon_Disconnected);
            Rcon.ChatInput    += new EventHandler(Rcon_Chat);

            Server.ServerStarted += new EventHandler(Server_Started);
            Server.ServerStopped += new EventHandler(Server_Stopped);
            Server.ServerCrashed += new EventHandler(Server_Crashed);

            Announce.Broadcast += new EventHandler(Announce_Broadcast);

            foreach (ComponentBase h in components)
            {
                h.Configure(Config);
                h.OnInit();
                if (h.UpdateInterval > 0)
                {
                    Scheduler.PushRepeatingTask(h.Task);
                }
            }

            if (!Database.WebUserExists())
            {
                SetupWebUser();
            }
            else
            {
                foreach (string s in args)
                {
                    if (s.Equals(ARG_RESET_WEBUSER))
                    {
                        Logger.Log(LogLevel.Info, "Resetting web users...");
                        Database.TruncateWebUsers();
                        SetupWebUser();
                    }
                }
            }

            Scheduler.Start();
            if (Config.AutoLaunchServer)
            {
                Scheduler.PushTask(Server.Start);
            }

            string cmd = string.Empty;

            while ((cmd = Console.ReadLine()) != "quit")
            {
                if (cmd == "import maps")
                {
                    Database.ImportMaps(ServerMap.ReadServerMapConfig(this));
                }
                else if (Commands.IsConsoleCommand(cmd))
                {
                    //using the scheduler to execute so we dont have to worry about concurrency
                    Scheduler.PushTask(() => { Commands.HandleConsoleCommand(cmd); });
                }
            }

            Scheduler.Stop();
            foreach (ComponentBase h in components)
            {
                h.OnDeInit();
            }
        }
コード例 #25
0
ファイル: TileBorders.cs プロジェクト: PsychoTeras/RatKing
 public static bool IsNotValidTile(int x, int y, ushort w, ushort h, TileType areaType, ServerMap map)
 {
     return x < 0 || x >= w || y < 0 || y >= h || (*map[(ushort)x, (ushort)y]).Type != areaType;
 }
コード例 #26
0
ファイル: TileBorders.cs プロジェクト: PsychoTeras/RatKing
 public static bool IsNotValidTile(int x, int y, ushort w, ushort h, TileType areaType, ServerMap map)
 {
     return(x < 0 || x >= w || y < 0 || y >= h || (*map[(ushort)x, (ushort)y]).Type != areaType);
 }
コード例 #27
0
ファイル: TileBorders.cs プロジェクト: PsychoTeras/RatKing
        public static byte GetBorders(int x, int y, ushort w, ushort h, TileType areaType, ServerMap map)
        {
            if (IsNotValidTile(x, y, w, h, areaType, map))
            {
                return(0);
            }

            byte flag = 0;

            if (IsNotValidTile(x - 1, y, w, h, areaType, map))
            {
                flag |= 1;
            }
            if (IsNotValidTile(x + 1, y, w, h, areaType, map))
            {
                flag |= 2;
            }
            if (IsNotValidTile(x, y - 1, w, h, areaType, map))
            {
                flag |= 4;
            }
            if (IsNotValidTile(x, y + 1, w, h, areaType, map))
            {
                flag |= 8;
            }

            return(flag);
        }
コード例 #28
0
 private string GetModes(ServerMap map)
 {
     return(string.Join(Separator, map.GetGCWGameModes().ToArray())
            + Separator + string.Join(Separator, map.GetCWGameModes().ToArray()));
 }
コード例 #29
0
 public abstract bool AffectMap(ServerMap map, string mode, Player player, string commandLine, string[] parameters, int paramIdx);
コード例 #30
0
        public override bool Run(Player player, string commandLine, string[] parameters)
        {
            if (parameters.Length < 1)
            {
                SendFormatted(OnSyntaxError, "{usage}", Usage);
                return(false);
            }

            string shortExp = (parameters[0].Length > 3 ? parameters[0].Substring(0, 3) : parameters[0]);

            // If the map name had a number suffix (eg. tat2), include it in the search
            if (parameters[0].Length > 3 && int.TryParse(parameters[0][3].ToString(), out _))
            {
                shortExp += parameters[0][3];
            }
            string gamemode;

            if (parameters.Length < 2)
            {
                if (parameters[0].Contains("_"))
                {
                    gamemode = parameters[0].Split('_')[1];
                }
                else
                {
                    SendFormatted(OnSyntaxError, "{usage}", Usage);
                    return(false);
                }
            }
            else
            {
                gamemode = parameters[1];
            }

            if (!CheckMode(gamemode))
            {
                SendFormatted(OnInvalidMode, "{expression}", gamemode);
                return(false);
            }

            List <ServerMap> matchingMaps = Core.Database.GetMaps(shortExp, (SearchNiceName ? parameters[0] : ""));

            if (matchingMaps.Count == 0)
            {
                SendFormatted(OnNoMapFound, "{expression}", parameters[0]);
                return(false);
            }

            if (matchingMaps.Count > 1)
            {
                if (matchingMaps.Count > MaxMapListLen)
                {
                    SendFormatted(OnTooMany, "{count}", matchingMaps.ToString());
                }
                else
                {
                    string mapList = string.Empty;
                    foreach (ServerMap m in matchingMaps)
                    {
                        mapList += FormatString(MapFormat, "{nicename}", m.NiceName, "{name}", m.Name, "{modes}", GetModes(m));
                        mapList += Separator;
                    }
                    SendFormatted(OnMultiple, "{count}", matchingMaps.ToString(), "{maps}", mapList);
                }
                return(false);
            }
            ServerMap map = matchingMaps[0];

            if (!map.HasMode(gamemode))
            {
                SendFormatted(OnNoMode, "{map_name}", map.Name, "{map_nicename}", "{available}", map.NiceName, GetModes(map));
                return(false);
            }

            return(AffectMap(matchingMaps[0], gamemode, player, commandLine, parameters, 1));
        }
コード例 #31
0
        public static void AddMap(ServerMap map)
        {
            //File.WriteAllText(GTANInstallDir + "\\logs\\map.json", JsonConvert.SerializeObject(map));
            Ped PlayerChar = Game.Player.Character;

            try
            {
                NetEntityHandler.ServerWorld = map.World;

                if (map.World.LoadedIpl != null)
                {
                    foreach (var ipl in map.World.LoadedIpl)
                    {
                        Function.Call(Hash.REQUEST_IPL, ipl);
                    }
                }

                if (map.World.RemovedIpl != null)
                {
                    foreach (var ipl in map.World.RemovedIpl)
                    {
                        Function.Call(Hash.REMOVE_IPL, ipl);
                    }
                }

                if (map.Objects != null)
                {
                    foreach (var pair in map.Objects)
                    {
                        if (NetEntityHandler.ClientMap.ContainsKey(pair.Key))
                        {
                            continue;
                        }
                        NetEntityHandler.CreateObject(pair.Key, pair.Value);
                        //GTA.UI.Screen.ShowSubtitle("Creating object...", 500000);
                    }
                }

                if (map.Vehicles != null)
                {
                    foreach (var pair in map.Vehicles)
                    {
                        if (NetEntityHandler.ClientMap.ContainsKey(pair.Key))
                        {
                            continue;
                        }
                        NetEntityHandler.CreateVehicle(pair.Key, pair.Value);
                        //GTA.UI.Screen.ShowSubtitle("Creating vehicle...", 500000);
                    }
                }

                if (map.Blips != null)
                {
                    foreach (var blip in map.Blips)
                    {
                        if (NetEntityHandler.ClientMap.ContainsKey(blip.Key))
                        {
                            continue;
                        }
                        NetEntityHandler.CreateBlip(blip.Key, blip.Value);
                    }
                }

                if (map.Markers != null)
                {
                    foreach (var marker in map.Markers)
                    {
                        if (NetEntityHandler.ClientMap.ContainsKey(marker.Key))
                        {
                            continue;
                        }
                        NetEntityHandler.CreateMarker(marker.Key, marker.Value);
                    }
                }

                if (map.Pickups != null)
                {
                    foreach (var pickup in map.Pickups)
                    {
                        if (NetEntityHandler.ClientMap.ContainsKey(pickup.Key))
                        {
                            continue;
                        }
                        NetEntityHandler.CreatePickup(pickup.Key, pickup.Value);
                    }
                }

                if (map.TextLabels != null)
                {
                    //map.TextLabels.GroupBy(x => x.Key).Select(y => y.First()); //Remove duplicates before procceeding

                    foreach (var label in map.TextLabels)
                    {
                        if (NetEntityHandler.ClientMap.ContainsKey(label.Key))
                        {
                            continue;
                        }
                        NetEntityHandler.CreateTextLabel(label.Key, label.Value);
                    }
                }

                if (map.Peds != null)
                {
                    foreach (var ped in map.Peds)
                    {
                        if (NetEntityHandler.ClientMap.ContainsKey(ped.Key))
                        {
                            continue;
                        }
                        NetEntityHandler.CreatePed(ped.Key, ped.Value);
                    }
                }

                if (map.Particles != null)
                {
                    foreach (var ped in map.Particles)
                    {
                        if (NetEntityHandler.ClientMap.ContainsKey(ped.Key))
                        {
                            continue;
                        }
                        NetEntityHandler.CreateParticle(ped.Key, ped.Value);
                    }
                }

                if (map.Players != null)
                {
                    LogManager.DebugLog("STARTING PLAYER MAP");

                    foreach (var pair in map.Players)
                    {
                        if (NetEntityHandler.NetToEntity(pair.Key)?.Handle == PlayerChar.Handle)
                        {
                            // It's us!
                            var remPl = NetEntityHandler.NetToStreamedItem(pair.Key) as RemotePlayer;
                            remPl.Name = pair.Value.Name;
                        }
                        else
                        {
                            var ourSyncPed = NetEntityHandler.GetPlayer(pair.Key);
                            NetEntityHandler.UpdatePlayer(pair.Key, pair.Value);
                            if (ourSyncPed.Character != null)
                            {
                                ourSyncPed.Character.RelationshipGroup = (pair.Value.Team == LocalTeam &&
                                                                          pair.Value.Team != -1)
                                    ? Main.FriendRelGroup
                                    : Main.RelGroup;

                                for (int i = 0; i < 15; i++) //NEEDS A CHECK
                                {
                                    Function.Call(Hash.SET_PED_COMPONENT_VARIATION, ourSyncPed.Character, i,
                                                  pair.Value.Props.Get((byte)i),
                                                  pair.Value.Textures.Get((byte)i), 2);
                                }

                                lock (NetEntityHandler.HandleMap)
                                    NetEntityHandler.HandleMap.Set(pair.Key, ourSyncPed.Character.Handle);

                                ourSyncPed.Character.Opacity = pair.Value.Alpha;

                                /*
                                 * if (ourSyncPed.Character.AttachedBlip != null)
                                 * {
                                 *  ourSyncPed.Character.AttachedBlip.Sprite = (BlipSprite)pair.Value.BlipSprite;
                                 *  ourSyncPed.Character.AttachedBlip.Color = (BlipColor)pair.Value.BlipColor;
                                 *  ourSyncPed.Character.AttachedBlip.Alpha = pair.Value.BlipAlpha;
                                 * }
                                 */
                                NetEntityHandler.ReattachAllEntities(ourSyncPed, false);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                GTA.UI.Notification.Show("FATAL ERROR WHEN PARSING MAP");
                GTA.UI.Notification.Show(ex.Message);
                Client.Disconnect("Map Parse Error");

                LogManager.LogException(ex, "MAP PARSE");

                return;
            }

            World.CurrentTimeOfDay = new TimeSpan(map.World.Hours, map.World.Minutes, 00);

            Time = new TimeSpan(map.World.Hours, map.World.Minutes, 00);
            if (map.World.Weather >= 0 && map.World.Weather < Enums._weather.Length)
            {
                Weather = Enums._weather[map.World.Weather];
                Function.Call(Hash.SET_WEATHER_TYPE_NOW_PERSIST, Enums._weather[map.World.Weather]);
            }

            Function.Call(Hash.PAUSE_CLOCK, true);
        }
コード例 #32
0
ファイル: frmMain.cs プロジェクト: PsychoTeras/RatKing
        private unsafe void BtnGenerateLabyrinthClick(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            FractalType type    = (FractalType)cbLabyrinthType.SelectedItem;
            BasisTypes  basis   = (BasisTypes)cbLabyrinthBasis.SelectedItem;
            InterpTypes interp  = (InterpTypes)cbLabyrinthInterp.SelectedItem;
            int?        octaves = !string.IsNullOrEmpty(tbLabyrinthOctaves.Text)
                ? int.Parse(tbLabyrinthOctaves.Text)
                : (int?)null;
            double?frequency = !string.IsNullOrEmpty(tbLabyrinthFrequency.Text)
                ? double.Parse(tbLabyrinthFrequency.Text)
                : (double?)null;
            double?angle = !string.IsNullOrEmpty(tbLabyrinthAngle.Text)
                ? double.Parse(tbLabyrinthAngle.Text)
                : (double?)null;
            double?lacunarity = !string.IsNullOrEmpty(tbLabyrinthLacunarity.Text)
                ? double.Parse(tbLabyrinthLacunarity.Text)
                : (double?)null;

            _labOldSeed = cbLabyrinthRnd.Checked ? (uint?)Environment.TickCount : _labOldSeed;

            ModuleBase moduleBase = new Fractal(type, basis, interp, octaves, frequency, _labOldSeed,
                                                angle, lacunarity);

            if (chkLabyrinthAC.Checked)
            {
                double        acLow    = double.Parse(tbLabyrinthACLow.Text);
                double        acHigh   = double.Parse(tbLabyrinthACHigh.Text);
                CombinerTypes combType = (CombinerTypes)cbLabyrinthACCombine.SelectedItem;
                AutoCorrect   correct  = new AutoCorrect(moduleBase, acLow, acHigh);
                moduleBase = new Combiner(combType, correct, moduleBase);
            }

//            Bias bias = new Bias(moduleBase, 0.01);
//            Gradient gradient = new Gradient(0, 0, 50, 100);
//            moduleBase = new TranslatedDomain(moduleBase, gradient, bias);

            if (chkLabyrinthSel.Checked)
            {
                double selLow       = double.Parse(tbLabyrinthSelLow.Text);
                double selHigh      = double.Parse(tbLabyrinthSelHigh.Text);
                double selThreshold = double.Parse(tbLabyrinthSelThreshold.Text);
                double?selFalloff   = !string.IsNullOrEmpty(tbLabyrinthSelFalloff.Text)
                    ? double.Parse(tbLabyrinthSelFalloff.Text)
                    : (double?)null;
                moduleBase = new Select(moduleBase, selLow, selHigh, selThreshold, selFalloff);
            }

            if (pbLabyrinth.Image != null)
            {
                pbLabyrinth.Image.Dispose();
            }

            ushort     width = 500, height = 500;
            Bitmap     bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
            BitmapData data   = bitmap.LockBits(new Rectangle(0, 0, width, height),
                                                ImageLockMode.ReadWrite, bitmap.PixelFormat);

            byte *pRoughMap = (byte *)Memory.HeapAlloc(width * height);

            Parallel.For(0, height, y =>
            {
                int *row = (int *)data.Scan0 + (y * data.Stride) / 4;
                Parallel.For(0, width, x =>
                {
                    double p   = (double)x / width;
                    double q   = (double)y / height;
                    double val = moduleBase.Get(p, q);
                    pRoughMap[y * width + x] = (byte)Math.Abs(val - 1);
                    Color color = Color.Black.Lerp(Color.White, val);
                    row[x]      = color.ToArgb();
                });
            });

            using (ServerMap map = new ServerMap(width, height, 0, pRoughMap))
            {
                map.SaveToFile("RK.save");
            }
            Memory.HeapFree(pRoughMap);

            bitmap.UnlockBits(data);
            pbLabyrinth.Image = bitmap;

            Cursor = DefaultCursor;
        }