Esempio n. 1
0
        public override void ProcessPacket(DysonBlueprintPacket packet, NebulaConnection conn)
        {
            DysonSphere sphere = GameMain.data.dysonSpheres[packet.StarIndex];

            if (sphere == null)
            {
                return;
            }
            using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On())
            {
                DysonSphereLayer          layer     = sphere.GetLayer(packet.LayerId);
                string                    str64Data = Encoding.ASCII.GetString(packet.BinaryData);
                DysonBlueprintDataIOError err       = new DysonBlueprintData().FromBase64String(str64Data, packet.BlueprintType, sphere, layer);
                if (err != DysonBlueprintDataIOError.OK)
                {
                    Log.Warn($"DysonBlueprintData IO error: {err}");
                    Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn);
                    return;
                }
            }
            if (IsHost)
            {
                Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn);
            }
        }
Esempio n. 2
0
        public override void ProcessPacket(DysonSpherePaintCellsPacket packet, NebulaConnection conn)
        {
            DysonSphere sphere = GameMain.data.dysonSpheres[packet.StarIndex];

            if (sphere == null)
            {
                return;
            }
            using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On())
            {
                DysonSphereLayer layer = sphere.GetLayer(packet.LayerId);
                if (layer == null)
                {
                    Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn);
                    return;
                }

                // UIDEPaintingbox.OpenGrid()
                Color32[] cellColors;
                if (layer.cellColors != null)
                {
                    Assert.True(layer.cellColors.Length == packet.CellCount);
                    cellColors = layer.cellColors;
                }
                else
                {
                    cellColors = new Color32[packet.CellCount];
                }

                // UIDysonPaintingGrid.PaintCells()
                Color32 paint = packet.Paint.ToColor32();
                for (int i = 0; i < packet.CursorCells.Length; i++)
                {
                    int cid = packet.CursorCells[i];
                    if (cid >= 0)
                    {
                        Color32 color = cellColors[cid];
                        color.a -= (color.a <= 127) ? (byte)0 : (byte)127;
                        color.a *= 2;
                        Color32 color2 = Color32.Lerp(color, paint, packet.Strength);
                        color2.a       /= 2;
                        color2.a       += ((paint.a > 0) ? (packet.SuperBrightMode ? (byte)127 : (byte)0) : (byte)0);
                        cellColors[cid] = color2;
                    }
                }
                layer.SetPaintingData(cellColors);
            }
            if (IsHost)
            {
                Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn);
            }
        }
        public override void ProcessPacket(DysonSphereColorChangePacket packet, NebulaConnection conn)
        {
            DysonSphere sphere = GameMain.data.dysonSpheres[packet.StarIndex];

            if (sphere == null)
            {
                return;
            }
            using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On())
            {
                DysonSphereLayer layer = sphere.GetLayer(packet.LayerId);
                if (layer == null)
                {
                    Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn);
                    return;
                }
                Color32 color = packet.Color.ToColor32();
                switch (packet.Type)
                {
                case DysonSphereColorChangePacket.ComponentType.Node:
                    DysonNode node = packet.Index < layer.nodeCursor ? layer.nodePool[packet.Index] : null;
                    if (node != null)
                    {
                        node.color = color;
                        sphere.UpdateColor(node);
                    }
                    break;

                case DysonSphereColorChangePacket.ComponentType.Frame:
                    DysonFrame frame = packet.Index < layer.frameCursor ? layer.framePool[packet.Index] : null;
                    if (frame != null)
                    {
                        frame.color = color;
                        sphere.UpdateColor(frame);
                    }
                    break;

                case DysonSphereColorChangePacket.ComponentType.Shell:
                    DysonShell shell = packet.Index < layer.shellCursor ? layer.shellPool[packet.Index] : null;
                    if (shell != null)
                    {
                        shell.color = color;
                    }
                    break;
                }
            }
            if (IsHost)
            {
                Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn);
            }
        }
Esempio n. 4
0
        public override void ProcessPacket(DysonSphereEditLayerPacket packet, NebulaConnection conn)
        {
            DysonSphere sphere = GameMain.data.dysonSpheres[packet.StarIndex];

            if (sphere == null)
            {
                return;
            }
            using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On())
            {
                DysonSphereLayer layer = sphere.GetLayer(packet.LayerId);
                if (layer == null)
                {
                    Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn);
                    return;
                }
                layer.targetOrbitRotation = packet.OrbitRotation.ToQuaternion();
                layer.InitOrbitRotation(layer.orbitRotation, layer.targetOrbitRotation);
            }
            if (IsHost)
            {
                Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn);
            }
        }