private int CreateStaticBlock() { // Validation MsgErr(true); if (!ValidateInput()) { return(0); } var part = new StaticBlock { Content = CKEditorControl1.Text, InnerName = txtPageTitle.Text, Key = txtKey.Text, Enabled = chbEnabled.Checked }; var id = StaticBlockService.AddStaticBlock(part); if (id != 0) { return(id); } return(0); }
private void SaveStaticBlock() { if (_mode == eStaicBlockMode.Err) { return; } if (!ValidateInput()) { return; } var part = new StaticBlock(_staticBlockId) { Content = CKEditorControl1.Text, InnerName = txtPageTitle.Text, Key = txtKey.Text, Enabled = chbEnabled.Checked }; if (!StaticBlockService.UpdatePagePart(part)) { MsgErr("Failed to save page part"); } }
public Room ParseRoomData(int roomNumber) { if (roomNumber == 254) { return new Room { RoomNumber = 254, ExitSE = new RoomExit(243, 0, 0), HasExitSE = true, Width = 7, Height = 7, FloorVisible = new bool[7, 7] { {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true} }, RenderFloor = new bool[7, 7] { {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true}, {true, true, true, true, true, true, true} }, Palette = new int[3] { 43, 9, 17 }, WallNW = WallType.Logs4, WallNE = WallType.Logs4, Floor1Cosmetic = FloorCosmeticType.ForestDirt, Floor1Behavior = 0, Floor2Cosmetic = FloorCosmeticType.ForestDirt, Floor2Behavior = 0, Entities = new StaticEntity[0], DynamicBlocks = new DynamicBlock[0], StaticBlocks = new StaticBlock[0], }; } using (var ms = new MemoryStream(RawImage, RoomIndicies[roomNumber], 1024)) using (var br = new BinaryReader(ms)) { byte[] k; Room rm = new Room(); rm.RoomNumber = roomNumber; rm.Palette = new int[3]; rm.Palette[0] = (int)br.ReadByte(); rm.Palette[1] = (int)br.ReadByte(); rm.Palette[2] = (int)br.ReadByte(); byte roomSize = br.ReadByte(); rm.Width = findWidth(roomSize); rm.Height = findHeight(roomSize); // Read entities: int entityCount = br.ReadByte(); rm.Entities = new StaticEntity[entityCount]; if (entityCount > 0) { k = new byte[5]; for (int i = 0; i < entityCount; ++i) { br.Read(k, 0, 5); rm.Entities[i] = new StaticEntity((EntityType)k[0], k[1] & 15, k[1] >> 4, k[2] & 15, k[2] >> 4, k[3], k[4]); } } // Windows, walls, floors: rm.WindowMaskNW = br.ReadByte(); rm.WindowMaskNE = br.ReadByte(); rm.WallNW = (WallType)((br.ReadByte() >> 1) & 15); rm.WallNE = (WallType)((br.ReadByte() >> 1) & 15); byte flr = br.ReadByte(); rm.Floor1Behavior = flr >> 4; rm.Floor1Cosmetic = (FloorCosmeticType)(flr & 15); flr = br.ReadByte(); rm.Floor2Behavior = flr >> 4; rm.Floor2Cosmetic = (FloorCosmeticType)(flr & 15); // Floor visibility mask: k = new byte[7]; br.Read(k, 0, 7); // Fill out floor visibility 2D array: rm.FloorVisible = new bool[rm.Height, rm.Width]; rm.RenderFloor = new bool[rm.Height, rm.Width]; for (int r = 0; r < rm.Height; ++r) for (int c = 0; c < rm.Width; ++c) { rm.RenderFloor[r, c] = true; rm.FloorVisible[rm.Height - r - 1, c] = (k[c] & (1 << (7 - r))) != 0; } // Exits: byte exitMask = br.ReadByte(); rm.HasExitFloor = (exitMask & (1 << 5)) != 0; rm.HasExitCeiling = (exitMask & (1 << 4)) != 0; rm.HasExitNW = (exitMask & (1 << 3)) != 0; rm.HasExitNE = (exitMask & (1 << 2)) != 0; rm.HasExitSE = (exitMask & (1 << 1)) != 0; rm.HasExitSW = (exitMask & (1 << 0)) != 0; int roomDest; byte position; // Ceiling and floor exits: if (rm.HasExitFloor) { roomDest = br.ReadByte(); position = br.ReadByte(); rm.ExitFloor = new RoomExit(roomDest, 0, 0); } if (rm.HasExitCeiling) { roomDest = br.ReadByte(); position = br.ReadByte(); rm.ExitCeiling = new RoomExit(roomDest, 0, 0); } // Position and roomDest bytes are in opposite order for walls: // Single exit per wall. if (rm.HasExitNW) { position = br.ReadByte(); roomDest = br.ReadByte(); rm.ExitNW = new RoomExit(roomDest, findW(position), findZ(position)); } if (rm.HasExitNE) { position = br.ReadByte(); roomDest = br.ReadByte(); rm.ExitNE = new RoomExit(roomDest, findW(position), findZ(position)); } if (rm.HasExitSE) { position = br.ReadByte(); roomDest = br.ReadByte(); rm.ExitSE = new RoomExit(roomDest, findW(position), findZ(position)); } if (rm.HasExitSW) { position = br.ReadByte(); roomDest = br.ReadByte(); rm.ExitSW = new RoomExit(roomDest, findW(position), findZ(position)); } // Blocks: int blockCount = br.ReadByte(); rm.StaticBlocks = new StaticBlock[blockCount]; if (blockCount > 0) { k = new byte[4]; byte[] extra = new byte[12]; for (int i = 0; i < blockCount; ++i) { br.Read(k, 0, 4); var blk = new StaticBlock((BlockCosmeticType)k[0], k[1] & 15, k[1] >> 4, k[2] & 15); rm.StaticBlocks[i] = blk; if (k[3] == 0x00) { br.Read(extra, 0, 12); } // Determine whether this block overrides a floor tile, to prevent things like spikes from // shooting up into this block. if ((blk.Z == 0) && // One of the solid block types: ((blk.CosmeticType == BlockCosmeticType.Solid) || (blk.CosmeticType == BlockCosmeticType.ConveyerEW) || (blk.CosmeticType == BlockCosmeticType.ConveyerNS) || (blk.CosmeticType == BlockCosmeticType.PyramidSpikes) || (blk.CosmeticType == BlockCosmeticType.SandwichBlock) )) { rm.RenderFloor[blk.Y, blk.X] = false; } } } // Dynamic blocks: blockCount = br.ReadByte(); rm.DynamicBlocks = new DynamicBlock[blockCount]; if (blockCount > 0) { k = new byte[4]; byte[] extra = new byte[36]; for (int i = 0; i < blockCount; ++i) { br.Read(k, 0, 4); var blk = new DynamicBlock((BlockCosmeticType)k[0], k[1] & 15, k[1] >> 4, k[2], (BlockFunctionalType)k[3]); rm.DynamicBlocks[i] = blk; // This extra data is PPU tile references for the NES: if (blk.FunctionalType == BlockFunctionalType.DisappearsWhenTouched) { br.Read(extra, 0, 36); } else { br.Read(extra, 0, 12); } // Determine whether this block overrides a floor tile, to prevent things like spikes from // shooting up into this block. if ((blk.Z == 0) && (blk.FunctionalType != BlockFunctionalType.AppearsWhenTouched) && // One of the solid block types: ((blk.CosmeticType == BlockCosmeticType.Solid) || (blk.CosmeticType == BlockCosmeticType.ConveyerEW) || (blk.CosmeticType == BlockCosmeticType.ConveyerNS) || (blk.CosmeticType == BlockCosmeticType.PyramidSpikes) || (blk.CosmeticType == BlockCosmeticType.SandwichBlock) )) { rm.RenderFloor[blk.Y, blk.X] = false; } } } return rm; } }
public void CreateWorldObjects(int oldTop, int newTop) { int createUnit = Math.Min(128, 64 + 40 * this.Score / 5000); while (this.previousCreateObjectTop <= newTop) { int x = this.random.Next(this.Size.Width - 100); int y = this.previousCreateObjectTop + createUnit; this.previousCreateObjectTop = y; WorldObject block = null; int blockId = this.random.Next(Math.Min(500, this.Score / 75), 1000); bool acceptAccelerator = false; if (0 <= blockId && blockId < 500) { block = new StaticBlock(new Point(x, y)); acceptAccelerator = true; } else if (500 <= blockId && blockId < 700) { block = new MovingBlock(new Point(x, y)); acceptAccelerator = true; } else if (700 <= blockId && blockId < 800) { block = new JumpAndBreakBlock(new Point(x, y)); } else if (800 <= blockId && blockId < 900) { block = new TimeoutAndBreakBlock(new Point(x, y)); } else if (this.lastOneIsBrokenBlock) { block = new JumpAndBreakBlock(new Point(x, y)); } else { block = new BrokenBlock(new Point(x, y)); } this.lastOneIsBrokenBlock = block is BrokenBlock || block is TimeoutAndBreakBlock; AddObject(block); if (acceptAccelerator) { WorldObject accelerator = null; int acceleratorId = this.random.Next(1000); if (0 <= acceleratorId && acceleratorId < 100) { accelerator = new JumperAccelerator(block); } else if (100 <= acceleratorId && acceleratorId < 120) { accelerator = new FlyingHatAccelerator(block); } else if (120 <= acceleratorId && acceleratorId < 130) { accelerator = new RocketAccelerator(block); } else if (130 <= acceleratorId && acceleratorId < 200) { if (this.Score >= 5000) { accelerator = new Shield(block); int monsterId = random.Next(100); if (0 <= monsterId && monsterId < 50) { AddObject(new MonsterBat(new Point(x, y + 500), this.Size.Width, this.random)); } else { AddObject(new MonsterMildew(new Point(x, y + 500), this.Size.Width, this.random)); } } } if (accelerator != null) { AddObject(accelerator); } } } }