예제 #1
0
 public override void Initialize()
 {
     if (this._level == "RANDOM")
     {
         LevelGenerator.MakeLevel(allowSymmetry: (this._center.left && this._center.right), seed: this._seed).LoadParts(0.0f, 0.0f, (Level)this, this._seed);
     }
     else
     {
         IEnumerable <XElement> source = XDocument.Load(this._level).Element((XName)"Level").Elements((XName)"Objects");
         if (source == null)
         {
             return;
         }
         foreach (XElement element in source.Elements <XElement>((XName)"Object"))
         {
             Thing t = Thing.LegacyLoadThing(element);
             if (t != null)
             {
                 this.AddThing(t);
             }
         }
     }
 }
        private void GenerateTilesRecurse(RandomLevelData tile, LevGenType type = LevGenType.Any)
        {
            this.visited = true;
            if (tile == null)
            {
                return;
            }
            this.data            = tile;
            this.connectionUp    = this.data.up;
            this.connectionDown  = this.data.down;
            this.connectionLeft  = this.data.left;
            this.connectionRight = this.data.right;
            if (this.symmetric)
            {
                if (this.kingTile)
                {
                    if (this.connectionLeft && this.connectionRight || !this.connectionLeft && !this.connectionRight)
                    {
                        this.mirror = true;
                    }
                    else
                    {
                        if (!this.connectionLeft)
                        {
                            if (this.up != null)
                            {
                                this.up.left        = (RandomLevelNode)null;
                                this.up.removeRight = true;
                            }
                            if (this.down != null)
                            {
                                this.down.left        = (RandomLevelNode)null;
                                this.down.removeRight = true;
                            }
                            this.removeRight = true;
                            this.left        = (RandomLevelNode)null;
                        }
                        if (!this.connectionRight)
                        {
                            if (this.up != null)
                            {
                                this.up.right      = (RandomLevelNode)null;
                                this.up.removeLeft = true;
                            }
                            if (this.down != null)
                            {
                                this.down.right      = (RandomLevelNode)null;
                                this.down.removeLeft = true;
                            }
                            this.removeLeft = true;
                            this.right      = (RandomLevelNode)null;
                        }
                    }
                }
                if (this.mirror)
                {
                    this.connectionRight = this.data.left;
                }
                if (this.up != null)
                {
                    this.up.mirror = this.mirror;
                }
                if (this.down != null)
                {
                    this.down.mirror = this.mirror;
                }
            }
            List <TileConnection> source = new List <TileConnection>()
            {
                TileConnection.Right,
                TileConnection.Left,
                TileConnection.Up,
                TileConnection.Down
            };

            if (this.removeLeft)
            {
                source.Remove(TileConnection.Left);
            }
            if (this.removeRight)
            {
                source.Remove(TileConnection.Right);
            }
            foreach (TileConnection tileConnection in (IEnumerable <TileConnection>)source.OrderBy <TileConnection, float>((Func <TileConnection, float>)(x => Rando.Float(1f))))
            {
                switch (tileConnection)
                {
                case TileConnection.Left:
                    if (this.connectionLeft && this.left != null && this.left.data == null && (!this.mirror || !this.symmetric || !this.rightSymmetric))
                    {
                        if (this.mirror && this.symmetric)
                        {
                            this.leftSymmetric = true;
                            if (this.down != null)
                            {
                                this.down.leftSymmetric = this.leftSymmetric;
                                if (this.down.down != null)
                                {
                                    this.down.down.leftSymmetric = this.leftSymmetric;
                                }
                            }
                            if (this.up != null)
                            {
                                this.up.leftSymmetric = this.leftSymmetric;
                                if (this.up.up != null)
                                {
                                    this.up.up.leftSymmetric = this.leftSymmetric;
                                }
                            }
                        }
                        this.left.leftSymmetric  = this.leftSymmetric;
                        this.left.rightSymmetric = this.rightSymmetric;
                        this.left.symmetric      = this.symmetric;
                        this.left.GenerateTilesRecurse(LevelGenerator.GetTile(TileConnection.Right, tile, type: type, mirror: this.left.mirror, filter: this.left.GetFilter()), type);
                        continue;
                    }
                    continue;

                case TileConnection.Right:
                    if (this.connectionRight && this.right != null && this.right.data == null && (!this.mirror || !this.symmetric || !this.leftSymmetric))
                    {
                        if (this.mirror && this.symmetric)
                        {
                            this.rightSymmetric = true;
                            if (this.down != null)
                            {
                                this.down.rightSymmetric = this.rightSymmetric;
                                if (this.down.down != null)
                                {
                                    this.down.down.rightSymmetric = this.rightSymmetric;
                                }
                            }
                            if (this.up != null)
                            {
                                this.up.rightSymmetric = this.rightSymmetric;
                                if (this.up.up != null)
                                {
                                    this.up.up.rightSymmetric = this.rightSymmetric;
                                }
                            }
                        }
                        this.right.leftSymmetric  = this.leftSymmetric;
                        this.right.rightSymmetric = this.rightSymmetric;
                        this.right.symmetric      = this.symmetric;
                        this.right.GenerateTilesRecurse(LevelGenerator.GetTile(TileConnection.Left, tile, type: type, mirror: this.right.mirror, filter: this.right.GetFilter()), type);
                        continue;
                    }
                    continue;

                case TileConnection.Up:
                    if (this.connectionUp && this.up != null && this.up.data == null)
                    {
                        this.up.leftSymmetric  = this.leftSymmetric;
                        this.up.rightSymmetric = this.rightSymmetric;
                        this.up.symmetric      = this.symmetric;
                        this.up.GenerateTilesRecurse(LevelGenerator.GetTile(TileConnection.Down, tile, type: type, mirror: this.mirror, filter: this.up.GetFilter()), type);
                        continue;
                    }
                    continue;

                case TileConnection.Down:
                    if (this.connectionDown && this.down != null && this.down.data == null)
                    {
                        this.down.leftSymmetric  = this.leftSymmetric;
                        this.down.rightSymmetric = this.rightSymmetric;
                        this.down.symmetric      = this.symmetric;
                        this.down.GenerateTilesRecurse(LevelGenerator.GetTile(TileConnection.Up, tile, type: type, mirror: this.mirror, filter: this.down.GetFilter()), type);
                        continue;
                    }
                    continue;

                default:
                    continue;
                }
            }
            if (!this.kingTile || !this.symmetric)
            {
                return;
            }
            this.SolveSymmetry();
            if (this.up != null)
            {
                this.up.SolveSymmetry();
            }
            if (this.down == null)
            {
                return;
            }
            this.down.SolveSymmetry();
        }
 public void GenerateTiles(RandomLevelData tile = null, LevGenType type = LevGenType.Any, bool symmetricVal = false)
 {
     this.symmetric = symmetricVal;
     this.GenerateTilesRecurse(tile != null ? tile : LevelGenerator.GetTile(TileConnection.None, tile, false, type, requiresSpawns: true), type);
     this.ClearFlags();
 }
예제 #4
0
        public static RandomLevelData GetTile(
            TileConnection requirement,
            RandomLevelData current,
            bool canBeNull  = true,
            LevGenType type = LevGenType.Any,
            Func <RandomLevelData, bool> lambdaReq = null,
            bool mirror           = false,
            TileConnection filter = TileConnection.None,
            bool requiresSpawns   = false)
        {
            List <RandomLevelData> tiles            = LevelGenerator.GetTiles(requirement, filter);
            RandomLevelData        randomLevelData1 = new RandomLevelData();
            bool flag = false;

            while (tiles.Count != 0)
            {
                RandomLevelData randomLevelData2 = tiles[Rando.Int(tiles.Count - 1)];
                if (randomLevelData2.numSpawns <= 0 && requiresSpawns)
                {
                    tiles.Remove(randomLevelData2);
                }
                else if (lambdaReq != null && !lambdaReq(randomLevelData2))
                {
                    tiles.Remove(randomLevelData2);
                }
                else if (mirror && !randomLevelData2.canMirror)
                {
                    tiles.Remove(randomLevelData2);
                }
                else if (mirror && (randomLevelData2.flip || requirement == TileConnection.Right && !randomLevelData2.left))
                {
                    tiles.Remove(randomLevelData2);
                }
                else
                {
                    int num = 0;
                    if (LevelGenerator._used.TryGetValue(randomLevelData2.file, out num) && num >= randomLevelData2.max)
                    {
                        tiles.Remove(randomLevelData2);
                    }
                    else
                    {
                        if (tiles.Count == 1 && !canBeNull)
                        {
                            if (flag)
                            {
                                return(randomLevelData1);
                            }
                            randomLevelData2 = tiles.First <RandomLevelData>();
                        }
                        else if ((double)randomLevelData2.chance != 1.0 && (double)Rando.Float(1f) >= (double)randomLevelData2.chance)
                        {
                            randomLevelData1 = randomLevelData2;
                            tiles.Remove(randomLevelData2);
                            flag             = true;
                            randomLevelData2 = (RandomLevelData)null;
                        }
                        if (randomLevelData2 != null)
                        {
                            if (LevelGenerator._used.ContainsKey(randomLevelData2.file))
                            {
                                Dictionary <string, int> used;
                                string file;
                                (used = LevelGenerator._used)[file = randomLevelData2.file] = used[file] + 1;
                            }
                            else
                            {
                                LevelGenerator._used[randomLevelData2.file] = 1;
                            }
                            return(randomLevelData2);
                        }
                        if (tiles.Count == 0)
                        {
                            return(flag ? randomLevelData1 : (RandomLevelData)null);
                        }
                    }
                }
            }
            return(flag ? randomLevelData1 : (RandomLevelData)null);
        }
예제 #5
0
        public static RandomLevelNode MakeLevel(
            RandomLevelData tile       = null,
            bool allowSymmetry         = true,
            int seed                   = 0,
            LevGenType type            = LevGenType.Any,
            int varwide                = 0,
            int varhigh                = 0,
            int genX                   = 1,
            int genY                   = 1,
            List <GeneratorRule> rules = null)
        {
            Random generator = Rando.generator;

            if (seed == 0)
            {
                seed = Rando.Int(2147483646);
            }
            Rando.generator = new Random(seed);
            bool flag1 = true;
            int  num1  = 0;
            int  length1;
            int  length2;

            RandomLevelNode[,] randomLevelNodeArray;
            while (true)
            {
                LevelGenerator._used.Clear();
                length1 = varwide;
                length2 = varhigh;
                if (varwide == 0)
                {
                    length1 = (double)Rando.Float(1f) <= 0.800000011920929 ? 3 : 2;
                }
                if (varhigh == 0)
                {
                    float num2 = Rando.Float(1f);
                    if ((double)num2 > 0.800000011920929)
                    {
                        ;
                    }
                    length2 = (double)num2 <= 0.349999994039536 ? 3 : 2;
                }
                if (flag1)
                {
                    length1 = length2 = 3;
                }
                genX = length1 != 3 ? 0 : 1;
                genY = length2 != 3 ? 0 : 1;
                if (genX > length1 - 1)
                {
                    genX = length1 - 1;
                }
                if (genY > length2 - 1)
                {
                    genY = length2 - 1;
                }
                randomLevelNodeArray = new RandomLevelNode[length1, length2];
                for (int index1 = 0; index1 < length1; ++index1)
                {
                    for (int index2 = 0; index2 < length2; ++index2)
                    {
                        randomLevelNodeArray[index1, index2]     = new RandomLevelNode();
                        randomLevelNodeArray[index1, index2].map = randomLevelNodeArray;
                    }
                }
                for (int index1 = 0; index1 < length1; ++index1)
                {
                    for (int index2 = 0; index2 < length2; ++index2)
                    {
                        RandomLevelNode randomLevelNode = randomLevelNodeArray[index1, index2];
                        if (index1 > 0)
                        {
                            randomLevelNode.left = randomLevelNodeArray[index1 - 1, index2];
                        }
                        if (index1 < length1 - 1)
                        {
                            randomLevelNode.right = randomLevelNodeArray[index1 + 1, index2];
                        }
                        if (index2 > 0)
                        {
                            randomLevelNode.up = randomLevelNodeArray[index1, index2 - 1];
                        }
                        if (index2 < length2 - 1)
                        {
                            randomLevelNode.down = randomLevelNodeArray[index1, index2 + 1];
                        }
                    }
                }
                if (tile != null)
                {
                    LevelGenerator._used[tile.file] = 1;
                }
                randomLevelNodeArray[genX, genY].kingTile = true;
                randomLevelNodeArray[genX, genY].GenerateTiles(tile, type, (double)Rando.Float(1f) > 0.300000011920929);
                List <RandomLevelNode> available = new List <RandomLevelNode>();
                for (int index1 = 0; index1 < length1; ++index1)
                {
                    for (int index2 = 0; index2 < length2; ++index2)
                    {
                        RandomLevelNode randomLevelNode = randomLevelNodeArray[index1, index2];
                        if (randomLevelNode.data != null)
                        {
                            available.Add(randomLevelNode);
                        }
                    }
                }
                if (rules == null)
                {
                    rules = new List <GeneratorRule>();
                    rules.Add(new GeneratorRule((Func <RandomLevelData, bool>)(problem => problem.numPermanentFatalWeapons < 1), (Func <RandomLevelData, bool>)(solution => solution.numPermanentFatalWeapons > 0), varMandatory: true));
                    rules.Add(new GeneratorRule((Func <RandomLevelData, bool>)(problem => problem.numLockedDoors > 0 && problem.numKeys == 0), (Func <RandomLevelData, bool>)(solution => solution.numLockedDoors == 0 && solution.numKeys > 0)));
                }
                bool flag2 = false;
                foreach (GeneratorRule rule in rules)
                {
                    if ((double)rule.chance == 1.0 || (double)Rando.Float(1f) < (double)rule.chance)
                    {
                        RandomLevelNode specific = (RandomLevelNode)null;
                        if (rule.special == SpecialRule.AffectCenterTile && length1 == 3)
                        {
                            specific = randomLevelNodeArray[1, Rando.Int(length2 - 1)];
                        }
                        if (!LevelGenerator.TryReroll(randomLevelNodeArray[genX, genY].totalData, available, rule.problem, rule.solution, specific) && rule.mandatory)
                        {
                            flag2 = true;
                            break;
                        }
                    }
                }
                if (flag2 && num1 < 6)
                {
                    if (num1 > 3)
                    {
                        flag1 = true;
                    }
                    ++num1;
                }
                else
                {
                    break;
                }
            }
            Rando.generator = generator;
            randomLevelNodeArray[genX, genY].seed      = seed;
            randomLevelNodeArray[genX, genY].tilesWide = length1;
            randomLevelNodeArray[genX, genY].tilesHigh = length2;
            randomLevelNodeArray[genX, genY].tiles     = randomLevelNodeArray;
            return(randomLevelNodeArray[genX, genY]);
        }
예제 #6
0
 public override void Initialize()
 {
     Vote.ClearVotes();
     if (this.level == "RANDOM")
     {
         this._randomLevel = LevelGenerator.MakeLevel(seed: this.seed);
         this.seed         = this._randomLevel.seed;
     }
     base.Initialize();
     if (Network.isActive)
     {
         Level.core.gameInProgress = true;
     }
     if (this._randomLevel != null)
     {
         this._randomLevel.LoadParts(0.0f, 0.0f, (Level)this, this.seed);
         List <SpawnPoint> source1 = new List <SpawnPoint>();
         foreach (SpawnPoint spawnPoint in this.things[typeof(SpawnPoint)])
         {
             source1.Add(spawnPoint);
         }
         if (source1.Count == 0)
         {
             Level.current = (Level) new GameLevel("RANDOM");
             return;
         }
         List <SpawnPoint> chosenSpawns = new List <SpawnPoint>();
         for (int index = 0; index < 4; ++index)
         {
             if (chosenSpawns.Count == 0)
             {
                 chosenSpawns.Add(source1.ElementAt <SpawnPoint>(Rando.Int(source1.Count - 1)));
             }
             else
             {
                 IOrderedEnumerable <SpawnPoint> source2 = source1.OrderByDescending <SpawnPoint, int>((Func <SpawnPoint, int>)(x =>
                 {
                     int num = 9999999;
                     foreach (Transform transform in chosenSpawns)
                     {
                         num = (int)Math.Min((transform.position - x.position).length, (float)num);
                     }
                     return(num);
                 }));
                 chosenSpawns.Add(source2.First <SpawnPoint>());
             }
         }
         foreach (SpawnPoint spawnPoint in source1)
         {
             if (!chosenSpawns.Contains(spawnPoint))
             {
                 Level.Remove((Thing)spawnPoint);
             }
         }
         foreach (Thing thing in this.things)
         {
             if (Network.isActive && thing.isStateObject)
             {
                 GhostManager.context.MakeGhost(thing, initLevel: true);
                 thing.ghostType = Editor.IDToType[thing.GetType()];
             }
         }
         PyramidBackground pyramidBackground = new PyramidBackground(0.0f, 0.0f);
         pyramidBackground.visible = false;
         Level.Add((Thing)pyramidBackground);
         base.Initialize();
     }
     this.things.RefreshState();
     if (this._mode == null)
     {
         this._mode = (GameMode) new DM(this._validityTest, this._editorTestMode);
     }
     this._mode.DoInitialize();
     if (!Network.isServer)
     {
         return;
     }
     foreach (Duck prepareSpawn in this._mode.PrepareSpawns())
     {
         prepareSpawn.localSpawnVisible = false;
         prepareSpawn.immobilized       = true;
         Level.Add((Thing)prepareSpawn);
     }
 }
        public override void Initialize()
        {
            this._pauseGroup  = new UIComponent(Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 0.0f, 0.0f);
            this._pauseMenu   = new UIMenu("@LWING@PAUSE@RWING@", Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 160f, conString: "@DPAD@MOVE  @SELECT@SELECT");
            this._confirmMenu = new UIMenu("REALLY QUIT?", Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 160f, conString: "@SELECT@SELECT");
            this._testMode    = new UIMenu("TEST MODE", Layer.HUD.camera.width / 2f, Layer.HUD.camera.height / 2f, 160f, conString: "@SELECT@SELECT");
            UIDivider uiDivider = new UIDivider(true, 0.8f);

            uiDivider.leftSection.Add((UIComponent) new UIMenuItem("RESTART", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._pauseGroup, this._restart), UIAlign.Left), true);
            uiDivider.leftSection.Add((UIComponent) new UIMenuItem("RESUME", (UIMenuAction) new UIMenuActionCloseMenu(this._pauseGroup), UIAlign.Left), true);
            uiDivider.leftSection.Add((UIComponent) new UIMenuItem("OPTIONS", (UIMenuAction) new UIMenuActionOpenMenu((UIComponent)this._pauseMenu, (UIComponent)Options.optionsMenu), UIAlign.Left), true);
            uiDivider.leftSection.Add((UIComponent) new UIMenuItem("TEST MODE", (UIMenuAction) new UIMenuActionOpenMenu((UIComponent)this._pauseMenu, (UIComponent)this._testMode), UIAlign.Left), true);
            uiDivider.leftSection.Add((UIComponent) new UIText("", Color.White), true);
            uiDivider.leftSection.Add((UIComponent) new UIMenuItem("QUIT", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._pauseGroup, this._quit), UIAlign.Left), true);
            uiDivider.rightSection.Add((UIComponent) new UIImage("pauseIcons", UIAlign.Right), true);
            this._pauseMenu.Add((UIComponent)uiDivider, true);
            this._pauseMenu.Close();
            this._pauseGroup.Add((UIComponent)this._pauseMenu, false);
            this._pauseGroup.Add((UIComponent)Options.optionsMenu, false);
            Options.openOnClose = this._pauseMenu;
            this._confirmMenu.Add((UIComponent) new UIMenuItem("NO!", (UIMenuAction) new UIMenuActionOpenMenu((UIComponent)this._confirmMenu, (UIComponent)this._pauseMenu)), true);
            this._confirmMenu.Add((UIComponent) new UIMenuItem("YES!", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._pauseGroup, this._quit)), true);
            this._confirmMenu.Close();
            this._pauseGroup.Add((UIComponent)this._confirmMenu, false);
            this._testMode.Add((UIComponent) new UIMenuItemNumber("PLAYERS", field: new FieldBinding((object)this, "numPlayers", 2f, 4f, 1f)), true);
            this._testMode.Add((UIComponent) new UIMenuItem("START", (UIMenuAction) new UIMenuActionCloseMenuSetBoolean(this._pauseGroup, this._startTestMode)), true);
            this._testMode.Add((UIComponent) new UIText("", Color.White), true);
            this._testMode.Add((UIComponent) new UIMenuItem("CANCEL", (UIMenuAction) new UIMenuActionOpenMenu((UIComponent)this._testMode, (UIComponent)this._pauseMenu), backButton: true), true);
            this._testMode.Close();
            this._pauseGroup.Add((UIComponent)this._testMode, false);
            this._pauseGroup.Close();
            Level.Add((Thing)this._pauseGroup);
            if (this._level == "RANDOM")
            {
                LevelGenerator.MakeLevel(this._center, this._center.left && this._center.right, this._seed, this._genType, Editor._procTilesWide, Editor._procTilesHigh, Editor._procXPos, Editor._procYPos).LoadParts(0.0f, 0.0f, (Level)this, this._seed);
                List <SpawnPoint> source1 = new List <SpawnPoint>();
                foreach (SpawnPoint spawnPoint in this.things[typeof(SpawnPoint)])
                {
                    source1.Add(spawnPoint);
                }
                List <SpawnPoint> chosenSpawns = new List <SpawnPoint>();
                for (int index = 0; index < 4; ++index)
                {
                    if (chosenSpawns.Count == 0)
                    {
                        chosenSpawns.Add(source1.ElementAt <SpawnPoint>(Rando.Int(source1.Count - 1)));
                    }
                    else
                    {
                        IOrderedEnumerable <SpawnPoint> source2 = source1.OrderByDescending <SpawnPoint, int>((Func <SpawnPoint, int>)(x =>
                        {
                            int num = 9999999;
                            foreach (Transform transform in chosenSpawns)
                            {
                                num = (int)Math.Min((transform.position - x.position).length, (float)num);
                            }
                            return(num);
                        }));
                        chosenSpawns.Add(source2.First <SpawnPoint>());
                    }
                }
                foreach (SpawnPoint spawnPoint in source1)
                {
                    if (!chosenSpawns.Contains(spawnPoint))
                    {
                        Level.Remove((Thing)spawnPoint);
                    }
                }
                PyramidBackground pyramidBackground = new PyramidBackground(0.0f, 0.0f);
                pyramidBackground.visible = false;
                Level.Add((Thing)pyramidBackground);
            }
            else
            {
                this._level = this._level.Replace(Directory.GetCurrentDirectory() + "\\", "");
                LevelData levelData = DuckFile.LoadLevel(this._level);
                if (levelData != null)
                {
                    foreach (BinaryClassChunk node in levelData.objects.objects)
                    {
                        Thing t = Thing.LoadThing(node);
                        if (t != null)
                        {
                            if (!t.visibleInGame)
                            {
                                t.visible = false;
                            }
                            this.AddThing(t);
                        }
                    }
                }
            }
            this.things.RefreshState();
            foreach (Duck spawnPlayer in new Deathmatch((Level)this).SpawnPlayers())
            {
                Level.Add((Thing)spawnPlayer);
                this.followCam.Add((Thing)spawnPlayer);
            }
        }