public override void ProcessPacket(DysonSphereRemoveNodePacket packet, NebulaConnection conn) { DysonSphereLayer layer = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); if (layer == null) { return; } using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On()) { if (!Check(layer, packet)) { Log.Warn($"Cannnot remove node[{packet.NodeId}] on layer[{layer.id}], starIndex[{packet.StarIndex}]"); Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn); return; } //No need to remove if the node is already null if (layer.nodePool[packet.NodeId] != null) { layer.RemoveDysonNode(packet.NodeId); NebulaWorld.Universe.DysonSphereManager.ClearSelection(packet.StarIndex, layer.id); } } if (IsHost) { Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn); } }
public void ProcessPacket(DysonSphereRemoveNodePacket packet, NebulaConnection conn) { Log.Info($"Processing DysonSphere Remove Node notification for system {GameMain.data.galaxy.stars[packet.StarIndex].name} (Index: {GameMain.data.galaxy.stars[packet.StarIndex].index})"); using (DysonSphere_Manager.IncomingDysonSpherePacket.On()) { DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); if (dsl != null) { int num = 0; DysonNode dysonNode = dsl.nodePool[packet.NodeId]; //Remove all frames that are part of the node while (dysonNode.frames.Count > 0) { dsl.RemoveDysonFrame(dysonNode.frames[0].id); if (num++ > 4096) { Assert.CannotBeReached(); break; } } //Remove all shells that are part of the node while (dysonNode.shells.Count > 0) { dsl.RemoveDysonShell(dysonNode.shells[0].id); if (num++ > 4096) { Assert.CannotBeReached(); break; } } dsl.RemoveDysonNode(packet.NodeId); } } }
public void ProcessPacket(DysonSphereAddNodePacket packet, NebulaConnection conn) { Log.Info($"Processing DysonSphere Add Node notification for system {GameMain.data.galaxy.stars[packet.StarIndex].name} (Index: {GameMain.data.galaxy.stars[packet.StarIndex].index})"); Player player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); DysonSphere_Manager.IncomingDysonSpherePacket = true; GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId)?.NewDysonNode(packet.NodeProtoId, DataStructureExtensions.ToUnity(packet.Position)); DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); //Try to add queued Dyson Frames that failed due to the missing nodes DysonSphereAddFramePacket queuedPacked; for (int i = DysonSphere_Manager.QueuedAddFramePackets.Count - 1; i >= 0; i--) { queuedPacked = DysonSphere_Manager.QueuedAddFramePackets[i]; if (dsl?.nodePool[queuedPacked.NodeAId]?.id != 0 && dsl?.nodePool[queuedPacked.NodeBId]?.id != 0) { dsl.NewDysonFrame(queuedPacked.ProtoId, queuedPacked.NodeAId, queuedPacked.NodeBId, queuedPacked.Euler); DysonSphere_Manager.QueuedAddFramePackets.RemoveAt(i); } } DysonSphere_Manager.IncomingDysonSpherePacket = false; } }
public override void ProcessPacket(DysonSphereAddFramePacket packet, NebulaConnection conn) { bool valid = true; if (IsHost) { Player player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); } else { valid = false; } } if (valid) { using (DysonSphereManager.IsIncomingRequest.On()) { DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); //Check if target nodes exists (if not, assume that AddNode packet is on the way) if (DysonSphereManager.CanCreateFrame(packet.NodeAId, packet.NodeBId, dsl)) { dsl.NewDysonFrame(packet.ProtoId, packet.NodeAId, packet.NodeBId, packet.Euler); } else { DysonSphereManager.QueuedAddFramePackets.Add(packet); } } } }
public void ProcessPacket(DysonSphereAddNodePacket packet, NebulaConnection conn) { Player player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); using (DysonSphere_Manager.IncomingDysonSpherePacket.On()) { GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId)?.NewDysonNode(packet.NodeProtoId, DataStructureExtensions.ToVector3(packet.Position)); DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); // DysonSphereLayer is missing, we can't do anything now. if (dsl == null) { NebulaModel.Logger.Log.Warn("Could not add Dyson Sphere Node, DysonSphereLayer is null."); return; } //Try to add queued Dyson Frames that failed due to the missing nodes DysonSphereAddFramePacket queuedPacked; for (int i = DysonSphere_Manager.QueuedAddFramePackets.Count - 1; i >= 0; i--) { queuedPacked = DysonSphere_Manager.QueuedAddFramePackets[i]; if (dsl.nodePool[queuedPacked.NodeAId].id != 0 && dsl.nodePool[queuedPacked.NodeBId].id != 0) { dsl.NewDysonFrame(queuedPacked.ProtoId, queuedPacked.NodeAId, queuedPacked.NodeBId, queuedPacked.Euler); DysonSphere_Manager.QueuedAddFramePackets.RemoveAt(i); } } } } }
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); } }
public static void RemoveLayer_Prefix2(DysonSphere __instance, DysonSphereLayer layer) { if (Multiplayer.IsActive) { RemoveLayer(layer.id, __instance.starData.index); } }
public override void ProcessPacket(DysonSphereRemoveShellPacket packet, NebulaConnection conn) { bool valid = true; if (IsHost) { Player player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); } else { valid = false; } } if (valid) { using (DysonSphereManager.IsIncomingRequest.On()) { DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); if (DysonSphereManager.CanRemoveShell(packet.ShellId, dsl)) { dsl.RemoveDysonShell(packet.ShellId); } } } }
public static void RemoveDysonShell_Prefix(DysonSphereLayer __instance, int shellId) { if (Multiplayer.IsActive && !Multiplayer.Session.DysonSpheres.IsIncomingRequest) { Multiplayer.Session.Network.SendPacket(new DysonSphereRemoveShellPacket(__instance.starData.index, __instance.id, shellId)); } }
public static void NewDysonNode_Prefix(DysonSphereLayer __instance, int protoId, Vector3 pos) { if (Multiplayer.IsActive && !Multiplayer.Session.DysonSpheres.IsIncomingRequest) { int nodeId = __instance.nodeRecycleCursor > 0 ? __instance.nodeRecycle[__instance.nodeRecycleCursor - 1] : __instance.nodeCursor; Multiplayer.Session.Network.SendPacket(new DysonSphereAddNodePacket(__instance.starData.index, __instance.id, nodeId, protoId, new Float3(pos))); } }
public static void NewDysonShell_Prefix(DysonSphereLayer __instance, int protoId, List <int> nodeIds) { if (Multiplayer.IsActive && !Multiplayer.Session.DysonSpheres.IsIncomingRequest) { int shellId = __instance.shellRecycleCursor > 0 ? __instance.shellRecycle[__instance.shellRecycleCursor - 1] : __instance.shellCursor; Multiplayer.Session.Network.SendPacket(new DysonSphereAddShellPacket(__instance.starData.index, __instance.id, shellId, protoId, nodeIds)); } }
public static void NewDysonFrame_Prefix(DysonSphereLayer __instance, int protoId, int nodeAId, int nodeBId, bool euler) { if (Multiplayer.IsActive && !Multiplayer.Session.DysonSpheres.IsIncomingRequest) { int frameId = __instance.frameRecycleCursor > 0 ? __instance.frameRecycle[__instance.frameRecycleCursor - 1] : __instance.frameCursor; Multiplayer.Session.Network.SendPacket(new DysonSphereAddFramePacket(__instance.starData.index, __instance.id, frameId, protoId, nodeAId, nodeBId, euler)); } }
public static bool NewDysonShell_Prefix(DysonSphereLayer __instance, int protoId, List <int> nodeIds) { //Notify others that user removed node from the dyson plan if (!DysonSphere_Manager.IncomingDysonSpherePacket) { LocalPlayer.SendPacket(new DysonSphereAddShellPacket(__instance.starData.index, __instance.id, protoId, nodeIds)); } return(true); }
public static bool AddLayer_Prefix(DysonSphere __instance, DysonSphereLayer __result, float orbitRadius, Quaternion orbitRotation, float orbitAngularSpeed) { //Notify others that user added layer to dyson sphere plan if (!DysonSphere_Manager.IncomingDysonSpherePacket) { LocalPlayer.SendPacket(new DysonSphereAddLayerPacket(__instance.starData.index, orbitRadius, orbitRotation, orbitAngularSpeed)); } return(true); }
public static bool NewDysonNode_Prefix(DysonSphereLayer __instance, int __result, int protoId, Vector3 pos) { //Notify others that user added node to the dyson plan if (!DysonSphere_Manager.IncomingDysonSpherePacket) { LocalPlayer.SendPacket(new DysonSphereAddNodePacket(__instance.starData.index, __instance.id, protoId, new Float3(pos))); } return(true); }
public static bool NewDysonFrame_Prefix(DysonSphereLayer __instance, int __result, int protoId, int nodeAId, int nodeBId, bool euler) { //Notify others that user added frame to the dyson plan if (!DysonSphere_Manager.IncomingDysonSpherePacket) { LocalPlayer.SendPacket(new DysonSphereAddFramePacket(__instance.starData.index, __instance.id, protoId, nodeAId, nodeBId, euler)); } return(true); }
public static bool RemoveDysonShell_Prefix(DysonSphereLayer __instance, int shellId) { //Notify others that user removed node from the dyson plan if (!DysonSphere_Manager.IncomingDysonSpherePacket) { LocalPlayer.SendPacket(new DysonSphereRemoveShellPacket(__instance.starData.index, __instance.id, shellId)); } return(true); }
public static bool RemoveLayer_Prefix2(DysonSphere __instance, DysonSphereLayer layer) { if (!SimulatedWorld.Initialized) { return(true); } //Notify others that user removed layer to dyson sphere plan RemoveLayer(layer.id, __instance.starData.index); return(true); }
public void ProcessPacket(DysonSphereRemoveFramePacket packet, NebulaConnection conn) { using (DysonSphere_Manager.IncomingDysonSpherePacket.On()) { DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); if (DysonSphere_Manager.CanRemoveFrame(packet.FrameId, dsl)) { dsl.RemoveDysonFrame(packet.FrameId); } } }
public static void InitOrbitRotation_Prefix(DysonSphereLayer __instance, Quaternion __1) { if (Multiplayer.IsActive && !Multiplayer.Session.DysonSpheres.IsIncomingRequest) { //Send only when it's trigger by UIDELayerInfo.OnEditConfirmClick() if (UIRoot.instance.uiGame.dysonEditor.controlPanel.inspector.layerInfo.orbitEditMode) { Multiplayer.Session.Network.SendPacket(new DysonSphereEditLayerPacket(__instance.starData.index, __instance.id, __1)); } } }
public static void PaintCells_Postfix(UIDysonPaintingGrid __instance, Color32 paint) { DysonSphereLayer layer = __instance.editor.selection.singleSelectedLayer; if (Multiplayer.IsActive && __instance.cursorCells != null && layer != null) { float strength = __instance.editor.brush_paint.strength; bool superBrightMode = __instance.editor.brush_paint.superBrightMode; Multiplayer.Session.Network.SendPacket(new DysonSpherePaintCellsPacket(layer.starData.index, layer.id, paint, strength, superBrightMode, __instance.cursorCells, __instance.cellCount)); } }
public void ProcessPacket(DysonSphereRemoveShellPacket packet, NebulaConnection conn) { Log.Info($"Processing DysonSphere remove shell notification for system {GameMain.data.galaxy.stars[packet.StarIndex].name} (Index: {GameMain.data.galaxy.stars[packet.StarIndex].index})"); DysonSphere_Manager.IncomingDysonSpherePacket = true; DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); if (DysonSphere_Manager.CanRemoveShell(packet.ShellId, dsl)) { dsl.RemoveDysonShell(packet.ShellId); } DysonSphere_Manager.IncomingDysonSpherePacket = false; }
public void ProcessPacket(DysonSphereRemoveFramePacket packet, NebulaConnection conn) { Log.Info($"Processing DysonSphere Remove Frame notification for system {GameMain.data.galaxy.stars[packet.StarIndex].name} (Index: {GameMain.data.galaxy.stars[packet.StarIndex].index})"); using (DysonSphere_Manager.IncomingDysonSpherePacket.On()) { DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); if (DysonSphere_Manager.CanRemoveFrame(packet.FrameId, dsl)) { dsl.RemoveDysonFrame(packet.FrameId); } } }
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 static bool RemoveDysonFrame_Prefix(DysonSphereLayer __instance, int frameId) { if (!SimulatedWorld.Initialized) { return(true); } //Notify others that user removed frame from the dyson plan if (!DysonSphere_Manager.IncomingDysonSpherePacket) { LocalPlayer.SendPacket(new DysonSphereRemoveFramePacket(__instance.starData.index, __instance.id, frameId)); } return(true); }
public static bool RemoveDysonShell_Prefix(DysonSphereLayer __instance, int shellId) { if (!SimulatedWorld.Initialized) { return(true); } //Notify others that user removed node from the dyson plan if (!DysonSphereManager.IsIncomingRequest) { LocalPlayer.SendPacket(new DysonSphereRemoveShellPacket(__instance.starData.index, __instance.id, shellId)); } return(true); }
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); } }
public override void ProcessPacket(DysonSphereRemoveNodePacket packet, NebulaConnection conn) { bool valid = true; if (IsHost) { Player player = playerManager.GetPlayer(conn); if (player != null) { playerManager.SendPacketToOtherPlayers(packet, player); } else { valid = false; } } if (valid) { using (DysonSphereManager.IsIncomingRequest.On()) { DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); if (dsl != null) { int num = 0; DysonNode dysonNode = dsl.nodePool[packet.NodeId]; //Remove all frames that are part of the node while (dysonNode.frames.Count > 0) { dsl.RemoveDysonFrame(dysonNode.frames[0].id); if (num++ > 4096) { Assert.CannotBeReached(); break; } } //Remove all shells that are part of the node while (dysonNode.shells.Count > 0) { dsl.RemoveDysonShell(dysonNode.shells[0].id); if (num++ > 4096) { Assert.CannotBeReached(); break; } } dsl.RemoveDysonNode(packet.NodeId); } } } }
public static bool CanRemoveShell(int shellId, DysonSphereLayer dsl) { if (dsl?.shellPool[shellId]?.nodes != null) { foreach (DysonNode dysonNode in dsl.shellPool[shellId].nodes) { if (dysonNode == null) { return(false); } } return(true); } return(false); }
public void ProcessPacket(DysonSphereAddFramePacket packet, NebulaConnection conn) { using (DysonSphere_Manager.IncomingDysonSpherePacket.On()) { DysonSphereLayer dsl = GameMain.data.dysonSpheres[packet.StarIndex]?.GetLayer(packet.LayerId); //Check if target nodes exists (if not, assume that AddNode packet is on the way) if (DysonSphere_Manager.CanCreateFrame(packet.NodeAId, packet.NodeBId, dsl)) { dsl.NewDysonFrame(packet.ProtoId, packet.NodeAId, packet.NodeBId, packet.Euler); } else { DysonSphere_Manager.QueuedAddFramePackets.Add(packet); } } }