Exemplo n.º 1
0
 public void NewArena(MapInfo map)
 {
     lock (LevelSync)
     {
         AnvilWorldProvider l;
         if (OnlyRead)
         {
             l = map.ProviderCache;
         }
         else
         {
             l = map.ProviderCache.Clone() as AnvilWorldProvider;
         }
         int id = LevelCount;
         if (LevelPoolId.Count > 0)
         {
             id = LevelPoolId.First();
             LevelPoolId.Remove(id);
         }
         else
         {
             LevelCount++;
             id = LevelCount;
         }
         var level = new xCoreLevel(l, Game.Context.Server.LevelManager.EntityManager, Game, map, id);
         LevelCount++;
         level.Initialize();
         SkyLightCalculations.Calculate(level);
         while (l.LightSources.Count > 0)
         {
             var block = l.LightSources.Dequeue();
             block = level.GetBlock(block.Coordinates);
             BlockLightCalculations.Calculate(level, block);
         }
         Game.Initialization(level);
         Levels.Add(level);
     }
 }
Exemplo n.º 2
0
        public LevelPoolGame(xCoreGames core, xCoreInterface game, bool onlyread, bool parse)
        {
            Random rnd     = new Random();
            var    timings = new Stopwatch();

            timings.Start();
            string basepath = Config.GetProperty("PluginDirectory", "Plugins") + "\\" + game.NameGame;

            for (int id = 1; id <= game.ArenaLoaded; id++)
            {
                if (Maps.Count == 0)
                {
                    DirectoryInfo dirInfo = new DirectoryInfo(basepath);
                    foreach (var dir in dirInfo.GetDirectories())
                    {
                        var     provider = new AnvilWorldProvider(basepath + "\\" + dir.Name);
                        var     cfg      = File.ReadAllText(basepath + "\\" + dir.Name + "\\config.json");
                        JObject jobj     = JObject.Parse(cfg);
                        Maps.Add(dir.Name, new MapInfo(dir.Name, jobj));
                        Maps[dir.Name].ProviderCache = provider;
                        Maps[dir.Name].ProviderCache.Initialize();
                        Maps[dir.Name].ProviderCache.PruneAir();
                        Maps[dir.Name].ProviderCache.MakeAirChunksAroundWorldToCompensateForBadRendering();
                    }
                }

                string map = Maps.Keys.ElementAt(rnd.Next(0, Maps.Keys.Count - 1));

                Level levelkey = Levels.FirstOrDefault(l => l.LevelId.Equals(game.NameGame + id, StringComparison.InvariantCultureIgnoreCase));
                if (levelkey == null)
                {
                    AnvilWorldProvider provider;
                    //provider = Maps[map].ProviderCache;
                    //if (!Maps[map].ProviderBool)
                    //{
                    if (onlyread)
                    {
                        provider = Maps[map].ProviderCache;
                    }
                    else
                    {
                        provider = Maps[map].ProviderCache.Clone() as AnvilWorldProvider;
                    }
                    //}
                    var level = new xCoreLevel(provider, game.Context.Server.LevelManager.EntityManager, game, Maps[map], LevelCount);
                    LevelCount++;
                    level.Initialize();
                    SkyLightCalculations.Calculate(level);
                    while (provider.LightSources.Count > 0)
                    {
                        var block = provider.LightSources.Dequeue();
                        block = level.GetBlock(block.Coordinates);
                        BlockLightCalculations.Calculate(level, block);
                    }
                    if (parse)
                    {
                        int X = Maps[map].Center.X;
                        int Z = Maps[map].Center.Z;
                        List <BlockCoordinates> BE = new List <BlockCoordinates>();
                        if (Maps[map].CacheBlockEntites == null)
                        {
                            int startX = Math.Min(X - 256, X + 256);
                            int endX   = Math.Max(X - 256, X + 256);
                            int startY = Math.Min(11, 129);
                            int endY   = Math.Max(11, 129);
                            int startZ = Math.Min(Z - 256, Z + 256);
                            int endZ   = Math.Max(Z - 256, Z + 256);
                            for (int x = startX; x <= endX; ++x)
                            {
                                for (int y = startY; y <= endY; ++y)
                                {
                                    for (int z = startZ; z <= endZ; ++z)
                                    {
                                        var         bc = new BlockCoordinates(x, y, z);
                                        BlockEntity blockentity;
                                        if ((blockentity = level.GetBlockEntity(bc)) != null)
                                        {
                                            if (blockentity is ChestBlockEntity)
                                            {
                                                if (!BE.Contains(blockentity.Coordinates))
                                                {
                                                    BE.Add(blockentity.Coordinates);
                                                }
                                            }
                                            else if (blockentity is Sign)
                                            {
                                                CleanSignText(((Sign)blockentity).GetCompound(), "Text1");
                                                CleanSignText(((Sign)blockentity).GetCompound(), "Text2");
                                                CleanSignText(((Sign)blockentity).GetCompound(), "Text3");
                                                CleanSignText(((Sign)blockentity).GetCompound(), "Text4");
                                                BE.Add(bc);
                                            }
                                        }
                                    }
                                }
                            }
                            for (int x = startX; x <= endX; ++x)
                            {
                                for (int z = startZ; z <= endZ; ++z)
                                {
                                    var bc = new BlockCoordinates(x, 127, z);
                                    MiNET.Blocks.Block b = level.GetBlock(bc);
                                    if (b.Id == 95)
                                    {
                                        level.SetAir(bc, false);
                                    }
                                }
                            }
                        }
                        if (Maps[map].CacheBlockEntites == null)
                        {
                            Maps[map].CacheBlockEntites = BE;
                        }
                    }
                    game.Initialization(level);
                    Levels.Add(level);
                }
            }
            Core     = core;
            Game     = game;
            OnlyRead = onlyread;
            timings.Stop();
            Log.Info("Loaded " + Levels.Count + " arenas . Load time " + timings.ElapsedMilliseconds + " ms");
            _tickerHighPrecisionTimer = new Timer(QueueTimer, null, 0, 1000);
        }
Exemplo n.º 3
0
        public void Initialization(xCoreLevel level)
        {
            List <PlayerLocation> Loclist;

            if (!SpawnPoints.TryGetValue(level.Map.Name, out Loclist))
            {
                List <PlayerLocation>   location  = new List <PlayerLocation>();
                List <PlayerLocation>   death     = new List <PlayerLocation>();
                List <BlockCoordinates> coords    = new List <BlockCoordinates>();
                List <BlockCoordinates> topcoords = new List <BlockCoordinates>();
                foreach (BlockCoordinates bc in level.Map.CacheBlockEntites)
                {
                    Block be = level.GetBlock(bc);
                    if (be is StandingSign)
                    {
                        Sign sign = level.GetBlockEntity(be.Coordinates) as Sign;
                        Log.Warn(sign.Text1);
                        if (sign.Text1 == "spawnpoint")
                        {
                            location.Add(new PlayerLocation(new Vector3(sign.Coordinates.X + 0.5f, sign.Coordinates.Y, sign.Coordinates.Z + 0.5f)));                            //0.5
                            level.SetAir(bc.X, bc.Y, bc.Z, false);
                            level.RemoveBlockEntity(be.Coordinates);
                        }
                        else if (sign.Text1 == "match")
                        {
                            death.Add(new PlayerLocation(new Vector3(sign.Coordinates.X + 0.5f, sign.Coordinates.Y, sign.Coordinates.Z + 0.5f)));                            //0.5
                            level.SetAir(bc.X, bc.Y, bc.Z, false);
                            level.RemoveBlockEntity(be.Coordinates);
                        }
                    }
                    else if (be is Chest)
                    {
                        var bcc = new BlockCoordinates(be.Coordinates.X, be.Coordinates.Y + 1, be.Coordinates.Z);
                        if (level.GetBlock(bcc) is StandingSign)
                        {
                            topcoords.Add(bc);
                        }
                        else
                        {
                            coords.Add(bc);
                        }
                    }
                }
                Chests.Add(level.Map.Name, coords);
                TopChests.Add(level.Map.Name, topcoords);
                DeathPoints.Add(level.Map.Name, death);
                SpawnPoints.Add(level.Map.Name, location);
            }
            else
            {
                foreach (BlockCoordinates bc in level.Map.CacheBlockEntites)
                {
                    BlockEntity be = level.GetBlockEntity(bc);
                    if (be is Sign)
                    {
                        //if (((Sign)be).Text1 == "spawnpoint")
                        {
                            level.SetAir(be.Coordinates.X, be.Coordinates.Y, be.Coordinates.Z, true);
                            level.RemoveBlockEntity(new BlockCoordinates(be.Coordinates.X, be.Coordinates.Y, be.Coordinates.Z));
                        }
                    }
                }
            }
            ChestFill(level);
        }