Exemple #1
0
        internal static void RemoveFromFilter(IMyTerminalBlock block)
        {
            FilteredContainer component = block?.GameLogic?.GetAs <FilteredContainer>();

            if (component.FilterController.ListToRemove.Count == 0)
            {
                return;
            }
            Filterdata filterdata = new Filterdata
            {
                id          = component.Entity.EntityId,
                FilterMode  = component.FilterController.FilterMode,
                FilterItems = component.FilterController.ListToRemove.ToArray(),
            };
            var metaData   = MyAPIGateway.Utilities.SerializeToBinary <Filterdata>(filterdata);
            var SendPacket = new MetaPacket
            {
                EntityId   = component.Entity.EntityId,
                PacketType = PacketType.FILTER_REMOVE,
                MetaData   = metaData,
            };

            MyAPIGateway.Multiplayer.SendMessageToServer(31875, MyAPIGateway.Utilities.SerializeToBinary <MetaPacket>(SendPacket));
            component.RemoveFromFilter(filterdata);
            component.FilterController.ListToRemove.Clear();
            ContainerControls.updateVisual("CurrentList");
        }
Exemple #2
0
        internal static void ClearFilter(IMyTerminalBlock block)
        {
            FilteredContainer component = block?.GameLogic?.GetAs <FilteredContainer>();
            var Sendpacket = new MetaPacket
            {
                EntityId   = component.Entity.EntityId,
                PacketType = PacketType.FILTER_CLEAR,
                MetaData   = MyAPIGateway.Utilities.SerializeToBinary <Filterdata>(new Filterdata()),
            };

            MyAPIGateway.Multiplayer.SendMessageToServer(31875, MyAPIGateway.Utilities.SerializeToBinary <MetaPacket>(Sendpacket));
            component.ClearFilter();
            ContainerControls.updateVisual("CurrentList");
        }
        internal void ParseData(byte[] data)
        {
            MetaPacket metaPacket = MyAPIGateway.Utilities.SerializeFromBinary <MetaPacket>(data);

            if (MyAPIGateway.Multiplayer.IsServer)
            {
                var BaseEntity = MyEntities.GetEntityById(metaPacket.EntityId);
                if (BaseEntity == null)
                {
                    return;
                }
                var filteredContainer = BaseEntity?.GameLogic?.GetAs <FilteredContainer>();
                if (filteredContainer == null)
                {
                    return;
                }

                var filterdata = MyAPIGateway.Utilities.SerializeFromBinary <Filterdata>(metaPacket.MetaData);
                switch (metaPacket.PacketType)
                {
                case PacketType.FILTER_ADD:
                {
                    filteredContainer.AddToFilter(filterdata);
                    break;
                }

                case PacketType.FILTER_REMOVE:
                {
                    filteredContainer.RemoveFromFilter(filterdata);
                    break;
                }

                case PacketType.FILTER_MODE:
                {
                    filteredContainer.SetFilterMode(filterdata.FilterMode);
                    break;
                }

                case PacketType.FILTER_CLEAR:
                {
                    filteredContainer.ClearFilter();
                    break;
                }
                }
            }
        }
Exemple #4
0
        internal static void SetFilterMode(IMyTerminalBlock block, long value)
        {
            FilteredContainer component = block?.GameLogic?.GetAs <FilteredContainer>();
            var filterdata = new Filterdata();

            if (value == 0)
            {
                filterdata.FilterMode = true;
            }
            if (value == 1)
            {
                filterdata.FilterMode = false;
            }
            var Sendpacket = new MetaPacket
            {
                EntityId   = component.Entity.EntityId,
                PacketType = PacketType.FILTER_MODE,
                MetaData   = MyAPIGateway.Utilities.SerializeToBinary <Filterdata>(filterdata),
            };

            MyAPIGateway.Multiplayer.SendMessageToServer(31875, MyAPIGateway.Utilities.SerializeToBinary <MetaPacket>(Sendpacket));
            component.SetFilterMode(filterdata.FilterMode);
        }