void blk_list_SelectedIndexChanged(object sender, EventArgs e)
        {
            blockID        = Block.Byte(blk_list.SelectedItem.ToString());
            blockPermsOrig = BlockPerms.List[blockID];
            blockPerms     = blockPermsChanged.Find(p => p.BlockID == blockID);
            BlockInitSpecificArrays();
            blockSupressEvents = true;

            BlockProps props = blockPropsChanged[blockID];

            blk_cbMsgBlock.Checked = props.IsMessageBlock;
            blk_cbPortal.Checked   = props.IsPortal;
            blk_cbDeath.Checked    = props.KillerBlock;
            blk_txtDeath.Text      = props.DeathMessage;
            blk_txtDeath.Enabled   = blk_cbDeath.Checked;

            blk_cbDoor.Checked  = props.IsDoor;
            blk_cbTdoor.Checked = props.IsTDoor;
            blk_cbRails.Checked = props.IsRails;
            blk_cbLava.Checked  = props.LavaKills;
            blk_cbWater.Checked = props.WaterKills;

            BlockPerms perms = blockPerms != null ? blockPerms : blockPermsOrig;

            GuiPerms.SetDefaultIndex(blk_cmbMin, perms.MinRank);
            GuiPerms.SetSpecificPerms(perms.Allowed, blockAllowBoxes);
            GuiPerms.SetSpecificPerms(perms.Disallowed, blockDisallowBoxes);
            blockSupressEvents = false;
        }
Beispiel #2
0
        public static void SetBlocks()
        {
            BlockProps[] props = Props;
            for (int b = 0; b < props.Length; b++)
            {
                props[b] = MakeDefaultProps((BlockID)b);
            }

            SetDefaultNames();
            string propsPath = Paths.BlockPropsPath("default");

            // backwards compatibility with older versions
            if (!File.Exists(propsPath))
            {
                BlockProps.Load("core", Props, 1, false);
                BlockProps.Load("global", Props, 1, true);
            }
            else
            {
                BlockProps.Load("default", Props, 1, false);
            }

            BlockPerms.Load();
            UpdateLoadedLevels();
        }
        static void RemoveBlockProps(bool global, ExtBlock block, Player p)
        {
            // Level block reverts to using global block
            if (!global)
            {
                p.level.Props[block.Index] = BlockDefinition.DefaultProps(block);
                p.level.UpdateBlockHandler(block);
                return;
            }

            BlockProps props = BlockProps.MakeDefault();

            if (!block.IsCustomType)
            {
                props = Block.Props[block.RawID];
            }

            BlockDefinition.GlobalProps[block.RawID] = props;
            Level[] loaded = LevelInfo.Loaded.Items;
            byte    raw    = block.RawID;

            foreach (Level lvl in loaded)
            {
                if (lvl.CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw])
                {
                    continue;
                }
                lvl.Props[block.Index] = BlockDefinition.GlobalProps[block.RawID];
                lvl.UpdateBlockHandler(block);
            }
        }
        void SaveBlocks()
        {
            if (!BlocksChanged())
            {
                LoadBlocks(); return;
            }

            for (int b = 0; b < blockPropsChanged.Length; b++)
            {
                if (blockPropsChanged[b].ChangedScope == 0)
                {
                    continue;
                }
                Block.Props[b] = blockPropsChanged[b];
            }

            foreach (BlockPerms changed in blockPermsChanged)
            {
                BlockPerms.Set(changed.ID, changed.MinRank,
                               changed.Allowed, changed.Disallowed);
            }
            BlockPerms.ResendAllBlockPermissions();

            BlockProps.Save("default", Block.Props, 1);
            BlockPerms.Save();
            Block.SetBlocks();
            LoadBlocks();
        }
Beispiel #5
0
 void LoadDefaultProps()
 {
     for (int b = 0; b < Props.Length; b++)
     {
         Props[b] = BlockProps.MakeDefault(Props, this, (BlockID)b);
     }
 }
        static bool DoCopy(Player p, bool global, string cmd, bool keepOrder,
                           BlockDefinition srcDef, BlockID src, BlockID dst)
        {
            if (srcDef == null && src < Block.CpeCount)
            {
                srcDef = DefaultSet.MakeCustomBlock(src);
            }
            if (srcDef == null)
            {
                MessageNoBlock(p, src, global, cmd); return(false);
            }

            BlockDefinition[] defs   = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
            BlockDefinition   dstDef = defs[dst];

            if (ExistsInScope(dstDef, dst, global))
            {
                MessageAlreadyBlock(p, dst, global, cmd); return(false);
            }

            BlockProps props = global ? Block.Props[src] : p.level.Props[src];

            dstDef = srcDef.Copy();
            dstDef.SetBlock(dst);
            if (!keepOrder)
            {
                dstDef.InventoryOrder = -1;
            }

            AddBlock(p, dstDef, global, cmd, props);
            return(true);
        }
        void blk_list_SelectedIndexChanged(object sender, EventArgs e)
        {
            curBlock       = blockIDMap[blk_list.SelectedIndex];
            blockPermsOrig = BlockPerms.Find(curBlock);
            blockPermsCopy = blockPermsChanged.Find(p => p.ID == curBlock);
            BlockInitSpecificArrays();
            blockItems.SupressEvents = true;

            BlockProps props = blockPropsChanged[curBlock];

            blk_cbMsgBlock.Checked = props.IsMessageBlock;
            blk_cbPortal.Checked   = props.IsPortal;
            blk_cbDeath.Checked    = props.KillerBlock;
            blk_txtDeath.Text      = props.DeathMessage;
            blk_txtDeath.Enabled   = blk_cbDeath.Checked;

            blk_cbDoor.Checked  = props.IsDoor;
            blk_cbTdoor.Checked = props.IsTDoor;
            blk_cbRails.Checked = props.IsRails;
            blk_cbLava.Checked  = props.LavaKills;
            blk_cbWater.Checked = props.WaterKills;

            BlockPerms perms = blockPermsCopy != null ? blockPermsCopy : blockPermsOrig;

            blockItems.Update(perms);
        }
Beispiel #8
0
        public static void LoadGlobal()
        {
            BlockDefinition[] oldDefs = GlobalDefs;
            GlobalDefs         = Load(true, null);
            GlobalDefs[0]      = new BlockDefinition();
            GlobalDefs[0].Name = "Air fallback";

            GlobalProps = new BlockProps[256];
            for (int i = 0; i < GlobalProps.Length; i++)
            {
                GlobalProps[i] = new BlockProps((byte)i);
            }

            try {
                if (File.Exists(GlobalPath))
                {
                    File.Copy(GlobalPath, GlobalBackupPath, true);
                }
            } catch (Exception ex) {
                Server.ErrorLog(ex);
            }

            Save(true, null);
            BlockProps.Load("global", BlockDefinition.GlobalProps);

            // As the BlockDefinition instances in levels will now be different
            // to the instances in GlobalDefs, we need to update them.
            if (oldDefs != null)
            {
                UpdateLoadedLevels(oldDefs);
            }
        }
Beispiel #9
0
        static string Format(BlockProps props)
        {
            if (!props.IsMessageBlock)
            {
                return(null);
            }

            // We want to use the simple aliases if possible
            if (Check(props, Block.MsgBlack, "black"))
            {
                return("black");
            }
            if (Check(props, Block.MsgWhite, "white"))
            {
                return("white");
            }
            if (Check(props, Block.MsgAir, "air"))
            {
                return("air");
            }
            if (Check(props, Block.MsgLava, "lava"))
            {
                return("lava");
            }
            if (Check(props, Block.MsgWater, "water"))
            {
                return("water");
            }
            return(props.Name);
        }
    public BlockProps GetBlockProps(BlockType bType)
    {
        BlockProps blockProps = new BlockProps();

        switch (bType)
        {
        case BlockType.Mud:
            blockProps.maxHits    = 4;
            blockProps.normalMat  = mats[0];
            blockProps.damagedMat = mats[1];
            break;

        case BlockType.Wood:
            blockProps.maxHits    = 6;
            blockProps.normalMat  = mats[2];
            blockProps.damagedMat = mats[3];
            break;

        case BlockType.Stone:
            blockProps.maxHits    = 8;
            blockProps.normalMat  = mats[4];
            blockProps.damagedMat = mats[5];
            break;
        }

        blockProps.blockType = bType;

        return(blockProps);
    }
Beispiel #11
0
        static void OnPropsChanged(BlockProps[] scope, Level level, byte id)
        {
            scope[id].Changed = true;

            if (scope == Block.Props)
            {
                BlockBehaviour.SetupCoreHandlers();
                BlockProps.Save("core", scope);
            }
            else if (scope == BlockDefinition.GlobalProps)
            {
                Level[] loaded = LevelInfo.Loaded.Items;
                foreach (Level lvl in loaded)
                {
                    if (lvl.CustomBlockDefs[id] != BlockDefinition.GlobalDefs[id])
                    {
                        continue;
                    }
                    lvl.CustomBlockProps[id] = BlockDefinition.GlobalProps[id];
                }
                BlockProps.Save("global", scope);
            }
            else
            {
                BlockProps.Save("lvl_" + level.name, scope);
            }
        }
        void SaveBlocks()
        {
            if (!BlocksChanged())
            {
                LoadBlocks(); return;
            }

            for (int i = 0; i < blockPropsChanged.Length; i++)
            {
                if (!blockPropsChanged[i].Changed)
                {
                    continue;
                }
                Block.Props[i] = blockPropsChanged[i];
            }
            foreach (BlockPerms perms in blockPermsChanged)
            {
                BlockPerms.List[perms.BlockID] = perms;
                if (perms.BlockID < Block.CpeCount)
                {
                    BlockPerms.ResendAllBlockPermissions();
                }
            }

            BlockProps.Save("core", Block.Props, Block.CorePropsLock, null);
            BlockPerms.Save();
            Block.SetBlocks();
            LoadBlocks();
        }
Beispiel #13
0
        static string Format(BlockProps props)
        {
            if (!props.IsPortal)
            {
                return(null);
            }

            // We want to use the simple aliases if possible
            if (Check(props, Block.orange_portal, "orange"))
            {
                return("orange");
            }
            if (Check(props, Block.blue_portal, "blue"))
            {
                return("blue");
            }
            if (Check(props, Block.air_portal, "air"))
            {
                return("air");
            }
            if (Check(props, Block.lava_portal, "lava"))
            {
                return("lava");
            }
            if (Check(props, Block.water_portal, "water"))
            {
                return("water");
            }
            return(props.Name);
        }
        void ResetProps(Player p, BlockProps[] scope, BlockID block)
        {
            scope[block] = BlockProps.MakeDefault(scope, p.level, block);
            string name = BlockProps.ScopedName(scope, p, block);

            p.Message("Reset properties of {0} to default", name);
            BlockProps.ApplyChanges(scope, p.level, block, true);
        }
Beispiel #15
0
 public static void SetBlocks()
 {
     SetCoreProperties();
     BlockProps.Load("core", Props, CorePropsLock, false);
     BlockDefinition.UpdateGlobalBlockProps();
     BlockPerms.Load();
     UpdateLoadedLevels();
 }
Beispiel #16
0
        static void OutputBlockProps(Player p, byte b)
        {
            BlockProps props = Block.Props[b];

            if (Block.LightPass(b))
            {
                Player.Message(p, "Block will allow light through");
            }
            if (Physics(b))
            {
                Player.Message(p, "Block affects physics in some way"); //AFFECT!
            }
            else
            {
                Player.Message(p, "Block will not affect physics in any way"); //It's AFFECT!
            }
            if (Block.NeedRestart(b))
            {
                Player.Message(p, "The block's physics will auto-start");
            }

            if (props.OPBlock)
            {
                Player.Message(p, "Block is unaffected by explosions");
            }

            if (Block.AllowBreak(b))
            {
                Player.Message(p, "Anybody can activate the block");
            }
            if (Block.Walkthrough(b))
            {
                Player.Message(p, "Block can be walked through");
            }
            if (props.KillerBlock)
            {
                Player.Message(p, "Walking through block will kill you");
            }

            if (props.IsDoor)
            {
                Player.Message(p, "Block is an ordinary door");
            }
            if (props.IsTDoor)
            {
                Player.Message(p, "Block is a tdoor, which allows other blocks through when open");
            }
            if (props.oDoorIndex != Block.Invalid)
            {
                Player.Message(p, "Block is an odoor, which can be toggled by doors and toggles other odoors");
            }

            if (Mover(b))
            {
                Player.Message(p, "Block can be activated by walking through it");
            }
        }
Beispiel #17
0
        void Init(string n, ushort x, ushort y, ushort z)
        {
            Width  = x;
            Height = y;
            Length = z;
            if (Width < 16)
            {
                Width = 16;
            }
            if (Height < 16)
            {
                Height = 16;
            }
            if (Length < 16)
            {
                Length = 16;
            }

            #pragma warning disable 0612
            width  = Width;
            length = Height;
            height = Length; depth = Length;
            #pragma warning restore 0612

            CustomBlockDefs = new BlockDefinition[256];
            for (int i = 0; i < CustomBlockDefs.Length; i++)
            {
                CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i];
            }
            CustomBlockProps = new BlockProps[256];
            for (int i = 0; i < CustomBlockProps.Length; i++)
            {
                CustomBlockProps[i] = BlockDefinition.GlobalProps[i];
            }

            name         = n;
            BlockDB      = new BlockDB(this);
            EdgeLevel    = (short)(y / 2);
            CloudsHeight = (short)(y + 2);

            blocks       = new byte[Width * Height * Length];
            ChunksX      = (Width + 15) >> 4;
            ChunksY      = (Height + 15) >> 4;
            ChunksZ      = (Length + 15) >> 4;
            CustomBlocks = new byte[ChunksX * ChunksY * ChunksZ][];

            spawnx = (ushort)(Width / 2);
            spawny = (ushort)(Height * 0.75f);
            spawnz = (ushort)(Length / 2);
            rotx   = 0; roty = 0;

            ZoneList         = new List <Zone>();
            VisitAccess      = new LevelAccessController(this, true);
            BuildAccess      = new LevelAccessController(this, false);
            listCheckExists  = new SparseBitSet(Width, Height, Length);
            listUpdateExists = new SparseBitSet(Width, Height, Length);
        }
Beispiel #18
0
        void ListProps(Player p, BlockProps[] scope, string[] args)
        {
            List <BlockID> filtered = FilterProps(scope);
            string         cmd      = "BlockProps " + args[0] + " list";
            string         modifier = args.Length > 2 ? args[2] : "";

            MultiPageOutput.Output(p, filtered, b => BlockProps.ScopedName(scope, p, b),
                                   cmd, "modified blocks", modifier, false);
        }
Beispiel #19
0
        static string FormatCustom(Level lvl, BlockProps props)
        {
            if (!props.IsPortal)
            {
                return(null);
            }
            BlockDefinition def = lvl.CustomBlockDefs[props.BlockId];

            return(def == null ? null : def.Name.Replace(" ", ""));
        }
Beispiel #20
0
        static void CopyBlockProps(string src, string dst)
        {
            string path = Path.Combine(oldServer, BlockProps.PropsPath("_" + src));

            if (!File.Exists(path))
            {
                return;
            }
            File.Copy(path, BlockProps.PropsPath("_" + dst), true);
        }
Beispiel #21
0
 public static void UpdateGlobalBlockProps()
 {
     for (int i = 0; i < GlobalProps.Length; i++)
     {
         ExtBlock block = ExtBlock.FromRaw((byte)i);
         GlobalProps[i] = BlockProps.MakeDefault();
         GlobalProps[i] = DefaultProps(block);
     }
     BlockProps.Load("global", GlobalProps, GlobalPropsLock, false);
 }
Beispiel #22
0
 static bool Check(BlockProps props, byte id, string name)
 {
     if (props.BlockId != id)
     {
         return(false);
     }
     if (props.Name == "unknown")
     {
         return(false);
     }
     id = Block.Byte(name);
     return(!Block.Props[id].IsMessageBlock);
 }
Beispiel #23
0
 static bool Check(BlockProps props, byte id, string name)
 {
     if (props.BlockId != id)
     {
         return(false);
     }
     if (props.Name == "unknown")
     {
         return(false);                         // custom blocks
     }
     id = Block.Byte(name);
     return(!Block.Props[id].IsPortal);
 }
        static void ResetProps(bool global, Level lvl, BlockID block, Player p)
        {
            BlockProps[] scope   = global ? Block.Props : lvl.Props;
            int          changed = scope[block].ChangedScope & BlockProps.ScopeId(scope);

            if (changed != 0)
            {
                return;
            }

            // properties not manually modified, revert (e.g. make grass die in shadow again)
            scope[block] = BlockProps.MakeDefault(scope, lvl, block);
            BlockProps.ApplyChanges(scope, lvl, block, false);
        }
Beispiel #25
0
        void SetProps(Player p, BlockProps[] scope, BlockID block, string[] args)
        {
            BlockOption opt = BlockOptions.Find(args[2]);

            if (opt == null)
            {
                Help(p); return;
            }
            string value = args.Length > 3 ? args[3] : "";

            opt.SetFunc(p, scope, block, value);
            scope[block].ChangedScope |= BlockProps.ScopeId(scope);
            BlockProps.ApplyChanges(scope, p.level, block, true);
        }
Beispiel #26
0
        static void Toggle(Player p, BlockProps[] scope, byte id, string type,
                           BoolSetter setter, Func <BlockProps, bool> getter)
        {
            BlockProps props = scope[id];

            setter(ref props);
            scope[id] = props;
            Level lvl = Player.IsSuper(p) ? null : p.level;

            Player.Message(p, "Block {0} is {1}: {2}",
                           BlockName(scope, lvl, id),
                           type, getter(props) ? "&aYes" : "&cNo");
            OnPropsChanged(scope, lvl, id);
        }
Beispiel #27
0
        static void OnPropsChanged(BlockProps[] scope, Level level, ExtBlock block)
        {
            scope[GetIndex(scope, block)].Changed = true;
            if (scope == Block.Props)
            {
                BlockProps.Save("core", scope, Block.CorePropsLock, null);
                Level[] loaded = LevelInfo.Loaded.Items;
                if (!block.IsPhysicsType)
                {
                    BlockDefinition.GlobalProps[block.RawID] = BlockDefinition.DefaultProps(block);
                }

                foreach (Level lvl in loaded)
                {
                    if (lvl.HasCustomProps(block))
                    {
                        continue;
                    }

                    lvl.Props[block.Index] = BlockDefinition.DefaultProps(block);
                    lvl.UpdateBlockHandler(block);
                }
            }
            else if (scope == BlockDefinition.GlobalProps)
            {
                Level[] loaded = LevelInfo.Loaded.Items;
                BlockProps.Save("global", scope, BlockDefinition.GlobalPropsLock, null);

                byte raw = block.RawID;
                foreach (Level lvl in loaded)
                {
                    if (lvl.CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw])
                    {
                        continue;
                    }
                    if (lvl.HasCustomProps(block))
                    {
                        continue;
                    }

                    lvl.Props[block.Index] = BlockDefinition.DefaultProps(block);
                    lvl.UpdateBlockHandler(block);
                }
            }
            else
            {
                BlockProps.Save("lvl_" + level.name, scope, level.PropsLock, idx => SelectLevel(level, idx));
                level.UpdateBlockHandler(block);
            }
        }
Beispiel #28
0
        static List <BlockID> FilterProps(BlockProps[] scope)
        {
            int            changed  = BlockProps.ScopeId(scope);
            List <BlockID> filtered = new List <BlockID>();

            for (int b = 0; b < scope.Length; b++)
            {
                if ((scope[b].ChangedScope & changed) == 0)
                {
                    continue;
                }
                filtered.Add((BlockID)b);
            }
            return(filtered);
        }
Beispiel #29
0
 void LoadCoreProps()
 {
     for (int i = 0; i < Props.Length; i++)
     {
         ExtBlock block = ExtBlock.FromIndex(i);
         if (!HasCustomProps(block))
         {
             Props[i] = BlockDefinition.DefaultProps(block);
         }
         else
         {
             Props[i] = BlockProps.MakeDefault();
         }
     }
 }
Beispiel #30
0
        public void UpdateBlockProps()
        {
            LoadDefaultProps();
            string propsPath = BlockProps.PropsPath("_" + MapName);

            // backwards compatibility with older versions
            if (!File.Exists(propsPath))
            {
                BlockProps.Load("lvl_" + MapName, Props, 2, true);
            }
            else
            {
                BlockProps.Load("_" + MapName, Props, 2, false);
            }
        }