コード例 #1
0
        void RevertPhysics(Check C)
        {
            //attemps on shutdown to change blocks back into normal selves that are active, hopefully without needing to send into to clients.
            switch (blocks[C.b])
            {
            case Block.Air_Flood:
            case Block.Air_FloodLayer:
            case Block.Air_FloodDown:
            case Block.Air_FloodUp:
                blocks[C.b] = 0; break;
            }

            try {
                PhysicsArgs args = C.data;
                // Copy paste here because it's worthwhile inlining
                if (args.Type1 == PhysicsArgs.Revert)
                {
                    ushort x, y, z;
                    IntToPos(C.b, out x, out y, out z);

                    ExtBlock block = ExtBlock.FromRaw(args.Value1, args.ExtBlock);
                    Blockchange(C.b, block, true, default(PhysicsArgs));
                }
                else if (args.Type2 == PhysicsArgs.Revert)
                {
                    ushort x, y, z;
                    IntToPos(C.b, out x, out y, out z);

                    ExtBlock block = ExtBlock.FromRaw(args.Value2, args.ExtBlock);
                    Blockchange(C.b, block, true, default(PhysicsArgs));
                }
            } catch (Exception e) {
                Logger.LogError(e);
            }
        }
コード例 #2
0
        void RevertPhysics(Check C)
        {
            //attemps on shutdown to change blocks back into normal selves that are active, hopefully without needing to send into to clients.
            switch (blocks[C.Index])
            {
            case Block.Air_Flood:
            case Block.Air_FloodLayer:
            case Block.Air_FloodDown:
            case Block.Air_FloodUp:
                blocks[C.Index] = Block.Air; break;
            }

            try {
                PhysicsArgs args = C.data;
                // Copy paste here because it's worthwhile inlining
                if (args.Type1 == PhysicsArgs.Revert)
                {
                    BlockID block = (BlockID)(args.Value1 | (args.ExtBlock << Block.ExtendedShift));
                    Blockchange(C.Index, block, true, default(PhysicsArgs));
                }
                else if (args.Type2 == PhysicsArgs.Revert)
                {
                    BlockID block = (BlockID)(args.Value2 | (args.ExtBlock << Block.ExtendedShift));
                    Blockchange(C.Index, block, true, default(PhysicsArgs));
                }
            } catch (Exception e) {
                Logger.LogError(e);
            }
        }
コード例 #3
0
        internal bool AddUpdate(int b, ExtBlock block, bool overRide = false)
        {
            PhysicsArgs args = default(PhysicsArgs);

            args.ExtBlock = block.BlockID == Block.custom_block;
            return(AddUpdate(b, block.RawID, overRide, args));
        }
コード例 #4
0
        internal bool AddUpdate(int index, BlockID block, bool overRide = false)
        {
            PhysicsArgs args = default(PhysicsArgs);

            args.Raw |= (uint)(PhysicsArgs.ExtBit * (block >> Block.ExtendedShift));
            return(AddUpdate(index, block, args, overRide));
        }
コード例 #5
0
        internal static ChangeResult Firework(Player p, BlockID old, ushort x, ushort y, ushort z)
        {
            if (p.level.physics == 0 || p.level.physics == 5)
            {
                return(ChangeResult.Unchanged);
            }

            Random rand = new Random();
            // Offset the firework randomly
            Vec3U16 pos = new Vec3U16(0, 0, 0);

            pos.X = (ushort)(x + rand.Next(0, 2) - 1);
            pos.Z = (ushort)(z + rand.Next(0, 2) - 1);
            ushort headY = (ushort)(y + 2), tailY = (ushort)(y + 1);

            bool headFree = p.level.IsAirAt(pos.X, headY, pos.Z) && p.level.CheckClear(pos.X, headY, pos.Z);
            bool tailFree = p.level.IsAirAt(pos.X, tailY, pos.Z) && p.level.CheckClear(pos.X, tailY, pos.Z);

            if (headFree && tailFree)
            {
                p.level.Blockchange(pos.X, headY, pos.Z, Block.Fireworks);

                PhysicsArgs args = default(PhysicsArgs);
                args.Type1 = PhysicsArgs.Wait; args.Value1 = 1;
                args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 100;
                p.level.Blockchange(pos.X, tailY, pos.Z, Block.StillLava, false, args);
            }
            return(ChangeResult.Unchanged);
        }
コード例 #6
0
        bool ParseArgs(Player p, string message, ref CatchPos cpos)
        {
            string[] parts = message.Split(' ');
            if (parts.Length % 2 == 1)
            {
                Player.SendMessage(p, "Number of parameters must be even");
                Help(p); return(false);
            }
            PhysicsArgs args = default(PhysicsArgs);
            byte        type = 0, value = 0;

            if (parts.Length >= 2)
            {
                if (!Parse(p, parts[0], parts[1], ref type, ref value))
                {
                    return(false);
                }
                args.Type1 = type; args.Value1 = value;
            }
            if (parts.Length >= 4)
            {
                if (!Parse(p, parts[2], parts[3], ref type, ref value))
                {
                    return(false);
                }
                args.Type2 = type; args.Value2 = value;
            }
            if (parts.Length >= 6)
            {
                Player.SendMessage(p, "You can only use up to two types of physics."); return(false);
            }
            cpos.extraInfo = args; return(true);
        }
コード例 #7
0
        bool ParseArgs(Player p, string message, ref PhysicsArgs extraInfo)
        {
            string[] parts = message.Split(' ');
            if (parts.Length % 2 == 1)
            {
                Player.Message(p, "Number of parameters must be even");
                Help(p); return(false);
            }
            byte type = 0, value = 0;

            if (parts.Length >= 2)
            {
                if (!Parse(p, parts[0], parts[1], ref type, ref value))
                {
                    return(false);
                }
                extraInfo.Type1 = type; extraInfo.Value1 = value;
            }
            if (parts.Length >= 4)
            {
                if (!Parse(p, parts[2], parts[3], ref type, ref value))
                {
                    return(false);
                }
                extraInfo.Type2 = type; extraInfo.Value2 = value;
            }
            if (parts.Length >= 6)
            {
                Player.Message(p, "You can only use up to two types of physics."); return(false);
            }
            return(true);
        }
コード例 #8
0
ファイル: Level.Physics.cs プロジェクト: Benedani/MCGalaxy
        void RevertPhysics(Check C)
        {
            //attemps on shutdown to change blocks back into normal selves that are active, hopefully without needing to send into to clients.
            switch (blocks[C.b])
            {
            case Block.air_flood:
            case Block.air_flood_layer:
            case Block.air_flood_down:
            case Block.air_flood_up:
                blocks[C.b] = 0; break;
            }

            try {
                PhysicsArgs args = C.data;
                if (args.Type1 == PhysicsArgs.Revert)
                {
                    RevertBlock(C.b, args.Value1, args.ExtBlock);
                }
                else if (args.Type2 == PhysicsArgs.Revert)
                {
                    RevertBlock(C.b, args.Value2, args.ExtBlock);
                }
            } catch (Exception e) {
                Server.ErrorLog(e);
            }
        }
コード例 #9
0
        bool ParseArgs(Player p, string message, ref PhysicsArgs args)
        {
            string[] parts = message.SplitSpaces();
            if (parts.Length % 2 == 1)
            {
                p.Message("Number of parameters must be even");
                Help(p); return(false);
            }
            byte type = 0, value = 0;
            byte extBits = 0;

            if (parts.Length >= 2)
            {
                if (!Parse(p, parts[0], parts[1], ref type, ref value, ref extBits))
                {
                    return(false);
                }
                args.Type1 = type; args.Value1 = value;
            }
            if (parts.Length >= 4)
            {
                if (!Parse(p, parts[2], parts[3], ref type, ref value, ref extBits))
                {
                    return(false);
                }
                args.Type2 = type; args.Value2 = value;
            }
            if (parts.Length >= 6)
            {
                p.Message("You can only use up to two types of physics."); return(false);
            }

            args.ExtBlock = extBits;
            return(true);
        }
コード例 #10
0
ファイル: Level.Blocks.cs プロジェクト: ProtheanGod/KingMC
 public void Blockchange(int b, ExtBlock block, bool overRide = false,
                         PhysicsArgs data = default(PhysicsArgs), bool addUndo = true)   //Block change made by physics
 {
     if (DoPhysicsBlockchange(b, block, overRide, data, addUndo))
     {
         Player.GlobalBlockchange(this, b, block);
     }
 }
コード例 #11
0
ファイル: LevelEvents.cs プロジェクト: ProtheanGod/KingMC
 public static void Call(ushort x, ushort y, ushort z, PhysicsArgs extraInfo, Level l)
 {
     if (handlers.Count == 0)
     {
         return;
     }
     CallCommon(pl => pl(x, y, z, extraInfo, l));
 }
コード例 #12
0
ファイル: Level.Blocks.cs プロジェクト: Peteys93/MCGalaxy
 public void Blockchange(int b, byte type, bool overRide = false,
                         PhysicsArgs data = default(PhysicsArgs),
                         byte extType     = 0, bool addUndo = true) //Block change made by physics
 {
     if (DoPhysicsBlockchange(b, type, overRide, data, extType, addUndo))
     {
         Player.GlobalBlockchange(this, b, type, extType);
     }
 }
コード例 #13
0
ファイル: Level.Physics.cs プロジェクト: rdebath/MCGalaxy
        internal bool AddUpdate(int index, BlockID block, PhysicsArgs data, bool overRide = false)
        {
            try {
                int x = index % Width;
                int y = (index / Width) / Length;
                int z = (index / Width) % Length;
                if (x >= Width || y >= Height || z >= Length)
                {
                    return(false);
                }

                if (overRide)
                {
                    // Is the Ext flag just an indicator for the block update?
                    if (data.ExtBlock != 0 && (data.Raw & PhysicsArgs.TypeMask) == 0)
                    {
                        data.Raw &= ~PhysicsArgs.ExtBits;
                    }
                    AddCheck(index, true, data); //Dont need to check physics here....AddCheck will do that
                    Blockchange((ushort)x, (ushort)y, (ushort)z, block, true, data);
                    return(true);
                }

                if (listUpdateExists.TrySetOn(x, y, z))
                {
                }
                else if (block == Block.Sand || block == Block.Gravel)
                {
                    RemoveUpdatesAtPos(index);
                }
                else
                {
                    return(false);
                }

                if ((byte)block != block)
                {
                    data.Data = Block.Obsidian;
                }
                else
                {
                    data.Data = (byte)block;
                }
                Update update; update.Index = index; update.data = data;
                ListUpdate.Add(update);

                if (!physThreadStarted && physics > 0)
                {
                    StartPhysics();
                }
                return(true);
            } catch {
                //s.Log("Warning-PhysicsUpdate");
                //ListUpdate.Add(new Update(b, (byte)type));    //Lousy back up plan
                return(false);
            }
        }
コード例 #14
0
ファイル: TWGame.Plugin.cs プロジェクト: takaaptech/MCGalaxy
        void AddTntCheck(int b, Player p)
        {
            PhysicsArgs args = default(PhysicsArgs);

            args.Type1  = PhysicsArgs.Custom;
            args.Value1 = (byte)p.SessionID;
            args.Value2 = (byte)(p.SessionID >> 8);
            args.Data   = (byte)(p.SessionID >> 16);
            Map.AddCheck(b, false, args);
        }
コード例 #15
0
ファイル: Level.Blocks.cs プロジェクト: Peteys93/MCGalaxy
        void AddTntCheck(int b, Player p)
        {
            PhysicsArgs args = default(PhysicsArgs);

            args.Type1  = PhysicsArgs.TntWars;
            args.Value1 = (byte)p.tntWarsUuid;
            args.Value2 = (byte)(p.tntWarsUuid >> 8);
            args.Data   = (byte)(p.tntWarsUuid >> 16);
            AddCheck(b, false, args);
        }
コード例 #16
0
ファイル: LevelEvents.cs プロジェクト: Peteys93/MCGalaxy
 public static void Call(ushort x, ushort y, ushort z, PhysicsArgs extraInfo, Level l)
 {
     events.ForEach(
         pl => {
         try {
             pl.method(x, y, z, extraInfo, l);
         } catch (Exception e) {
             Server.s.Log("Plugin " + pl.plugin.name + " errored when calling PhysicsUpdate Event."); Server.ErrorLog(e);
         }
     });
 }
コード例 #17
0
        internal bool AddUpdate(int b, byte type, bool overRide, PhysicsArgs data)
        {
            try {
                int x = b % Width;
                int y = (b / Width) / Length;
                int z = (b / Width) % Length;
                if (x >= Width || y >= Height || z >= Length)
                {
                    return(false);
                }

                if (overRide)
                {
                    ExtBlock block;
                    block.BlockID = type;
                    block.ExtID   = 0;

                    // Is the Ext flag just an indicator for the block update?
                    if (data.ExtBlock && (data.Raw & PhysicsArgs.TypeMask) == 0)
                    {
                        block.ExtID   = block.BlockID;
                        block.BlockID = Block.custom_block;
                        data.ExtBlock = false;
                    }
                    AddCheck(b, true, data); //Dont need to check physics here....AddCheck will do that
                    Blockchange((ushort)x, (ushort)y, (ushort)z, block, true, data);
                    return(true);
                }

                if (!listUpdateExists.Get(x, y, z))
                {
                    listUpdateExists.Set(x, y, z, true);
                }
                else if (type == Block.Sand || type == Block.Gravel)
                {
                    RemoveUpdatesAtPos(b);
                }
                else
                {
                    return(false);
                }
                ListUpdate.Add(new Update(b, (byte)type, data));

                if (!physThreadStarted && physics > 0)
                {
                    StartPhysics();
                }
                return(true);
            } catch {
                //s.Log("Warning-PhysicsUpdate");
                //ListUpdate.Add(new Update(b, (byte)type));    //Lousy back up plan
                return(false);
            }
        }
コード例 #18
0
 internal static void Door(Player p, ExtBlock block, ushort x, ushort y, ushort z)
 {
     if (p.level.physics != 0)
     {
         byte        physForm;
         PhysicsArgs args = ActivateablePhysics.GetDoorArgs(block, out physForm);
         p.level.Blockchange(x, y, z, (ExtBlock)physForm, false, args);
     }
     else
     {
         p.RevertBlock(x, y, z);
     }
 }
コード例 #19
0
        internal static bool Door(Player p, BlockID block, ushort x, ushort y, ushort z)
        {
            if (p.level.physics == 0)
            {
                return(true);
            }

            BlockID     physForm;
            PhysicsArgs args = ActivateablePhysics.GetDoorArgs(block, out physForm);

            p.level.Blockchange(x, y, z, physForm, false, args);
            return(true);
        }
コード例 #20
0
        public override void Use(Player p, string message, CommandData data)
        {
            PhysicsArgs extraInfo = default(PhysicsArgs);

            message = message.ToLower();
            if (message.Length > 0 && !ParseArgs(p, message, ref extraInfo))
            {
                return;
            }

            p.Message("Place or break two blocks to determine the edges.");
            p.MakeSelection(2, "Selecting region for &SRestart physics", extraInfo, DoRestart);
        }
コード例 #21
0
        public override void Use(Player p, string message)
        {
            PhysicsArgs extraInfo = default(PhysicsArgs);

            message = message.ToLower();
            if (message != "" && !ParseArgs(p, message, ref extraInfo))
            {
                return;
            }

            Player.Message(p, "Place two blocks to determine the edges.");
            p.MakeSelection(2, extraInfo, DoRestart);
        }
コード例 #22
0
        public void Blockchange(int b, BlockID block, bool overRide = false,
                                PhysicsArgs data = default(PhysicsArgs), bool addUndo = true)   //Block change made by physics
        {
            if (!DoPhysicsBlockchange(b, block, overRide, data, addUndo))
            {
                return;
            }

            ushort x, y, z;

            IntToPos(b, out x, out y, out z);
            BroadcastChange(x, y, z, block);
        }
コード例 #23
0
        internal static ChangeResult Door(Player p, BlockID old, ushort x, ushort y, ushort z)
        {
            if (p.level.physics == 0)
            {
                return(p.ChangeBlock(x, y, z, Block.Air));
            }

            BlockID     physForm;
            PhysicsArgs args = ActivateablePhysics.GetDoorArgs(old, out physForm);

            p.level.Blockchange(x, y, z, physForm, false, args);
            return(ChangeResult.Modified);
        }
コード例 #24
0
        void RevertPhysics(Check C)
        {
            ushort x, y, z;

            IntToPos(C.b, out x, out y, out z);
            //attemps on shutdown to change blocks back into normal selves that are active, hopefully without needing to send into to clients.
            switch (blocks[C.b])
            {
            case Block.air_flood:
            case Block.air_flood_layer:
            case Block.air_flood_down:
            case Block.air_flood_up:
                blocks[C.b] = 0; break;

            case Block.door_tree_air:
                //blocks[C.b] = 111;
                Blockchange(x, y, z, Block.door_tree); break;

            case Block.door_obsidian_air:
                //blocks[C.b] = 113;
                Blockchange(x, y, z, Block.door_obsidian); break;

            case Block.door_glass_air:
                //blocks[C.b] = 114;
                Blockchange(x, y, z, Block.door_glass); break;

            case Block.door_stone_air:
                //blocks[C.b] = 115;
                Blockchange(x, y, z, Block.door_stone); break;
            }

            try {
                if (!(C.data is PhysicsArgs))
                {
                    return;
                }
                PhysicsArgs args = (PhysicsArgs)C.data;
                if (args.Type1 == PhysicsArgs.Revert)
                {
                    Blockchange(x, y, z, args.Value1, true);
                }
                if (args.Type2 == PhysicsArgs.Revert)
                {
                    Blockchange(x, y, z, args.Value2, true);
                }
            } catch (Exception e) {
                Server.ErrorLog(e);
            }
        }
コード例 #25
0
        bool DoRestart(Player p, Vec3S32[] m, object state, byte type, byte extType)
        {
            PhysicsArgs extraInfo = (PhysicsArgs)state;
            List <int>  buffer    = new List <int>();

            for (int y = Math.Min(m[0].Y, m[1].Y); y <= Math.Max(m[0].Y, m[1].Y); y++)
            {
                for (int z = Math.Min(m[0].Z, m[1].Z); z <= Math.Max(m[0].Z, m[1].Z); z++)
                {
                    for (int x = Math.Min(m[0].X, m[1].X); x <= Math.Max(m[0].X, m[1].X); x++)
                    {
                        int index = p.level.PosToInt((ushort)x, (ushort)y, (ushort)z);
                        if (index >= 0 && p.level.blocks[index] != Block.air)
                        {
                            buffer.Add(index);
                        }
                    }
                }
            }

            if (extraInfo.Raw == 0)
            {
                if (buffer.Count > Server.rpNormLimit)
                {
                    Player.Message(p, "Cannot restart more than " + Server.rpNormLimit + " blocks.");
                    Player.Message(p, "Tried to restart " + buffer.Count + " blocks.");
                    return(false);
                }
            }
            else if (buffer.Count > Server.rpLimit)
            {
                Player.Message(p, "Tried to add physics to " + buffer.Count + " blocks.");
                Player.Message(p, "Cannot add physics to more than " + Server.rpLimit + " blocks.");
                return(false);
            }

            foreach (int index in buffer)
            {
                p.level.AddCheck(index, true, extraInfo);
            }
            Player.Message(p, "Activated " + buffer.Count + " blocks.");
            return(true);
        }
コード例 #26
0
        internal bool AddUpdate(int b, int type, bool overRide, PhysicsArgs data)
        {
            try {
                int x = b % Width;
                int y = (b / Width) / Length;
                int z = (b / Width) % Length;
                if (x >= Width || y >= Height || z >= Length)
                {
                    return(false);
                }

                if (overRide)
                {
                    AddCheck(b, true, data); //Dont need to check physics here....AddCheck will do that
                    Blockchange((ushort)x, (ushort)y, (ushort)z, (byte)type, true, data);
                    return(true);
                }

                if (!listUpdateExists.Get(x, y, z))
                {
                    listUpdateExists.Set(x, y, z, true);
                }
                else if (type == Block.sand || type == Block.gravel)
                {
                    RemoveUpdatesAtPos(b);
                }
                else
                {
                    return(false);
                }

                ListUpdate.Add(new Update(b, (byte)type, data));
                if (!physicssate && physics > 0)
                {
                    StartPhysics();
                }
                return(true);
            } catch {
                //s.Log("Warning-PhysicsUpdate");
                //ListUpdate.Add(new Update(b, (byte)type));    //Lousy back up plan
                return(false);
            }
        }
コード例 #27
0
        bool DoRestart(Player p, Vec3S32[] m, object state, BlockID block)
        {
            PhysicsArgs extraInfo = (PhysicsArgs)state;
            List <int>  buffer    = new List <int>();
            int         index;

            for (int y = Math.Min(m[0].Y, m[1].Y); y <= Math.Max(m[0].Y, m[1].Y); y++)
            {
                for (int z = Math.Min(m[0].Z, m[1].Z); z <= Math.Max(m[0].Z, m[1].Z); z++)
                {
                    for (int x = Math.Min(m[0].X, m[1].X); x <= Math.Max(m[0].X, m[1].X); x++)
                    {
                        if (!p.level.IsAirAt((ushort)x, (ushort)y, (ushort)z, out index))
                        {
                            buffer.Add(index);
                        }
                    }
                }
            }

            if (extraInfo.Raw == 0)
            {
                if (buffer.Count > Server.Config.PhysicsRestartNormLimit)
                {
                    p.Message("Cannot restart more than " + Server.Config.PhysicsRestartNormLimit + " blocks.");
                    p.Message("Tried to restart " + buffer.Count + " blocks.");
                    return(false);
                }
            }
            else if (buffer.Count > Server.Config.PhysicsRestartLimit)
            {
                p.Message("Tried to add physics to " + buffer.Count + " blocks.");
                p.Message("Cannot add physics to more than " + Server.Config.PhysicsRestartLimit + " blocks.");
                return(false);
            }

            foreach (int index1 in buffer)
            {
                p.level.AddCheck(index1, true, extraInfo);
            }
            p.Message("Activated " + buffer.Count + " blocks.");
            return(true);
        }
コード例 #28
0
ファイル: TWGame.Plugin.cs プロジェクト: takaaptech/MCGalaxy
        static Player GetPlayer(ref PhysicsArgs args)
        {
            if (args.Type1 != PhysicsArgs.Custom)
            {
                return(null);
            }

            int id = args.Value1 | args.Value2 << 8 | (args.Data & 0xF) << 16;

            Player[] players = PlayerInfo.Online.Items;
            for (int i = 0; i < players.Length; i++)
            {
                if (players[i].SessionID == id)
                {
                    return(players[i]);
                }
            }
            return(null);
        }
コード例 #29
0
        internal static bool Door(Player p, byte block, ushort x, ushort y, ushort z)
        {
            if (p.level.physics == 0)
            {
                return(true);
            }
            bool isExt = false;

            if (block == Block.custom_block)
            {
                isExt = true;
                block = p.level.GetExtTile(x, y, z);
            }

            byte        physForm;
            PhysicsArgs args = ActivateablePhysics.GetDoorArgs(block, isExt, out physForm);

            p.level.Blockchange(x, y, z, physForm, false, args);
            return(true);
        }
コード例 #30
0
        public void AddCheck(int index, bool overRide, PhysicsArgs data)
        {
            try {
                int x = index % Width;
                int y = (index / Width) / Length;
                int z = (index / Width) % Length;
                if (x >= Width || y >= Height || z >= Length)
                {
                    return;
                }

                if (listCheckExists.TrySetOn(x, y, z))
                {
                    Check check; check.Index = index; check.data = data;
                    ListCheck.Add(check); // Adds block to list to be updated
                }
                else if (overRide)
                {
                    Check[] items = ListCheck.Items;
                    int     count = ListCheck.Count;
                    for (int i = 0; i < count; i++)
                    {
                        if (items[i].Index != index)
                        {
                            continue;
                        }
                        items[i].data = data; return;
                    }
                    //Dont need to check physics here because if the list is active, then physics is active :)
                }

                if (!physThreadStarted && physics > 0)
                {
                    StartPhysics();
                }
            } catch {
                //s.Log("Warning-PhysicsCheck");
                //ListCheck.Add(new Check(b));    //Lousy back up plan
            }
        }