Beispiel #1
0
 public override void LoadWorldData(TagCompound tag)
 {
     byte[] bytes = tag.GetByteArray("WirelessCoords");
     for (int i = 0; i < bytes.Length; i += 8)
     {
         var transmitter = new Point16(BitConverter.ToInt16(bytes, i), BitConverter.ToInt16(bytes, i + 2));
         var receiver    = new Point16(BitConverter.ToInt16(bytes, i + 4), BitConverter.ToInt16(bytes, i + 6));
         //				Wireless.Log("{0}, {1}", transmitter, receiver);
         if (!WirelessUtils.AlreadyExists(transmitter, receiver))
         {
             Links.Add(transmitter, receiver);
         }
     }
 }
Beispiel #2
0
        public override void NetReceive(BinaryReader reader)
        {
            int linksCount = reader.ReadInt32();

            Links = new Dictionary <Point16, Point16>(linksCount);
            for (int i = 0; i < linksCount; i++)
            {
                Point16 transmitter = new Point16(reader.ReadInt16(), reader.ReadInt16());
                Point16 receiver    = new Point16(reader.ReadInt16(), reader.ReadInt16());
                if (!WirelessUtils.AlreadyExists(transmitter, receiver))
                {
                    Links.Add(new Point16(reader.ReadInt16(), reader.ReadInt16()), new Point16(reader.ReadInt16(), reader.ReadInt16()));
                }
            }
        }
Beispiel #3
0
 void ActivateReceiver(Point16 receiver)
 {
     if (WirelessUtils.IsReceiver(receiver))
     {
         Wiring.TripWire(receiver.X, receiver.Y, 1, 1);
         Tile tile = Main.tile[receiver.X, receiver.Y];
         if (tile.TileType == ModContent.TileType <Tiles.WirelessTransceiver>() && WirelessSystem.Links.ContainsKey(receiver))
         {
             if (WirelessUtils.IsReceiver(WirelessSystem.Links[receiver]))
             {
                 Wiring.TripWire(WirelessSystem.Links[receiver].X, WirelessSystem.Links[receiver].Y, 1, 1);
             }
         }
     }
     else
     {
         SyncRemoveLink(receiver);
     }
 }
Beispiel #4
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            var msgType = (MessageType)reader.ReadByte();

            switch (msgType)
            {
            case MessageType.AddLink:

                var transmitter = new Point16(reader.ReadInt16(), reader.ReadInt16());
                var receiver    = new Point16(reader.ReadInt16(), reader.ReadInt16());
                if (!WirelessUtils.AlreadyExists(transmitter, receiver))
                {
                    WirelessSystem.Links[transmitter] = receiver;
                    if (Main.netMode == NetmodeID.Server)                            //Server-side
                    {
                        SyncAddLink(transmitter, receiver, whoAmI);                  //Broadcast the change to other clients
                    }
                }
                break;

            case MessageType.RemoveLink:
                transmitter = new Point16(reader.ReadInt16(), reader.ReadInt16());
                WirelessSystem.Links.Remove(transmitter);

                if (Main.netMode == NetmodeID.Server)
                {
                    SyncRemoveLink(transmitter, whoAmI);
                }
                break;

            case MessageType.TripWire:
                receiver = new Point16(reader.ReadInt16(), reader.ReadInt16());
                ActivateReceiver(receiver);

                if (Main.netMode == NetmodeID.Server)
                {
                    RemoteClient.CheckSection(whoAmI, receiver.ToWorldCoordinates());
                }
                break;
            }
        }