public static void ImportBP(this DysonFrame _this, BinaryReader r, DysonSphere dysonSphere) { _this.SetEmpty(); r.ReadInt32(); _this.id = r.ReadInt32(); _this.protoId = r.ReadInt32(); _this.layerId = r.ReadInt32(); _this.reserved = r.ReadBoolean(); int nodeId = r.ReadInt32(); int nodeId2 = r.ReadInt32(); _this.euler = r.ReadBoolean(); _this.spMax = r.ReadInt32(); _this.nodeA = dysonSphere.FindNode(_this.layerId, nodeId); _this.nodeB = dysonSphere.FindNode(_this.layerId, nodeId2); Assert.NotNull(_this.nodeA); Assert.NotNull(_this.nodeB); if (_this.nodeA != null && !_this.nodeA.frames.Contains(_this)) { _this.nodeA.frames.Add(_this); } if (_this.nodeB != null && !_this.nodeB.frames.Contains(_this)) { _this.nodeB.frames.Add(_this); } _this.spMax = _this.segCount * 10; _this.GetSegments(); }
public void SetupSavedMegaStructuresData(MegaStructuresData megaStructuresData) { PlanetaryShield ps = planetaryShield.GetComponent <PlanetaryShield>(); MegaCollector mc = megaCollector.GetComponent <MegaCollector>(); DysonSphere ds = dysonSphere.GetComponent <DysonSphere>(); Debug.Log("SetupSavedMegaStructuresData | PlanetaryShield unlocked [" + ps.isUnlocked + "] | MegaCollector unlocked [" + mc.isUnlocked + "] | DysonSphere unlocked [" + ds.isUnlocked + "]"); ps.isUnlocked = megaStructuresData.shieldUnlocked; if (ps.isUnlocked) { //ps.Initialize(); ps.ReceiveSettings(megaStructuresData.shieldRadius, megaStructuresData.shieldPower, PlanetaryShield.ViewMode.Full); } mc.isUnlocked = megaStructuresData.collectorUnlocked; if (mc.isUnlocked) { //mc.Initialize(); mc.BuildCollectionPoints(); mc.Configure(megaStructuresData.collectionSpeed, megaStructuresData.collectionPointsNb); } ds.isUnlocked = megaStructuresData.dysonSphereUnlocked; if (ds.isUnlocked) { //ds.Initialize(); ds.Configure(megaStructuresData.dysonSphereStructurePoints, megaStructuresData.dysonSphereAutoRepair); } }
public override void ProcessPacket(DysonSwarmRemoveOrbitPacket packet, NebulaConnection conn) { DysonSphere sphere = GameMain.data.dysonSpheres[packet.StarIndex]; if (sphere == null) { return; } using (Multiplayer.Session.DysonSpheres.IncomingDysonSwarmPacket.On()) { if (packet.Event == SwarmRemoveOrbitEvent.Remove) { sphere.swarm.RemoveOrbit(packet.OrbitId); } else if (packet.Event == SwarmRemoveOrbitEvent.Enable || packet.Event == SwarmRemoveOrbitEvent.Disable) { sphere.swarm.SetOrbitEnable(packet.OrbitId, packet.Event == SwarmRemoveOrbitEvent.Enable); } NebulaWorld.Universe.DysonSphereManager.ClearSelection(packet.StarIndex); } if (IsHost) { Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn); } }
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 override void ProcessPacket(DysonSwarmEditOrbitPacket packet, NebulaConnection conn) { DysonSphere sphere = GameMain.data.dysonSpheres[packet.StarIndex]; if (sphere == null) { return; } using (Multiplayer.Session.DysonSpheres.IncomingDysonSwarmPacket.On()) { if (!sphere.swarm.OrbitExist(packet.OrbitId)) { Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn); return; } if (packet.Radius >= 0) { sphere.swarm.EditOrbit(packet.OrbitId, packet.Radius, packet.Rotation.ToQuaternion()); } else { sphere.swarm.SetOrbitColor(packet.OrbitId, new Vector4(packet.Color.x, packet.Color.y, packet.Color.z, packet.Color.w)); } } if (IsHost) { Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn); } }
public DysonSphereStatusPacket(DysonSphere dysonSphere) { StarIndex = dysonSphere.starData.index; GrossRadius = dysonSphere.grossRadius; EnergyReqCurrentTick = dysonSphere.energyReqCurrentTick; EnergyGenCurrentTick = dysonSphere.energyGenCurrentTick; }
public static void RemoveLayer_Prefix(DysonSphere __instance, int id) { if (Multiplayer.IsActive) { RemoveLayer(id, __instance.starData.index); } }
public static void RemoveLayer_Prefix2(DysonSphere __instance, DysonSphereLayer layer) { if (Multiplayer.IsActive) { RemoveLayer(layer.id, __instance.starData.index); } }
public MegaStructuresData BuildMegaStructuresData() { PlanetaryShield ps = planetaryShield.GetComponent <PlanetaryShield>(); MegaCollector mc = megaCollector.GetComponent <MegaCollector>(); DysonSphere ds = dysonSphere.GetComponent <DysonSphere>(); return(new MegaStructuresData(ps.enabled, ps.radius, ps.damagePower, mc.isUnlocked, mc.currentCollectionPointNb, mc.currentCollectionSpeed, ds.isUnlocked, ds.currentStructurePoints, ds.currentAutoRepairState)); }
void Awake() { if (instance != null) { Debug.LogError("More than one DysonSphere in scene !"); return; } instance = this; }
IEnumerator RemoveSail(DysonSphere dsp) { yield return(new WaitForEndOfFrame()); for (int i = 1; i < dsp.swarm.sailCapacity; i++) { dsp.swarm.RemoveSolarSail(i); } }
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 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(DysonSphereLoadRequest packet, NebulaConnection conn) { DysonSphere dysonSphere = GameMain.data.CreateDysonSphere(packet.StarIndex); using (BinaryUtils.Writer writer = new BinaryUtils.Writer()) { dysonSphere.Export(writer.BinaryWriter); conn.SendPacket(new DysonSphereData(packet.StarIndex, writer.CloseAndGetBytes())); } }
public static void AddLayer_Postfix(DysonSphere __instance, float orbitRadius, Quaternion orbitRotation, float orbitAngularSpeed) { if (!Multiplayer.IsActive) { return; } //If local is the author and not in the process of importing blueprint if (!Multiplayer.Session.DysonSpheres.IsIncomingRequest && !Multiplayer.Session.DysonSpheres.InBlueprint) { Multiplayer.Session.Network.SendPacket(new DysonSphereAddLayerPacket(__instance.starData.index, __instance.QueryLayerId(), orbitRadius, orbitRotation, orbitAngularSpeed)); } }
public override void ProcessPacket(DysonSphereStatusPacket packet, NebulaConnection conn) { DysonSphere dysonSphere = GameMain.data.dysonSpheres[packet.StarIndex]; if (IsHost || dysonSphere == null) { return; } dysonSphere.grossRadius = packet.GrossRadius; dysonSphere.energyReqCurrentTick = packet.EnergyReqCurrentTick; dysonSphere.energyGenCurrentTick = packet.EnergyGenCurrentTick; }
static void DspShow(UIDysonPanel __instance) { viewDsp = __instance.viewDysonSphere; if (viewDsp != null) { for (int i = 0; i < viewDsp.layersIdBased.Length; i++) { tempDsp[i] = null; } isShow = true; } }
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); } }
static void AddDspData() { //yield return new WaitForFixedUpdate(); for (int i = 1; i < viewDsp.layersIdBased.Length; i++) { if (!shell[i]) { viewDsp.layersIdBased[i] = tempDsp[i]; } } viewDsp.modelRenderer.RebuildModels(); viewDsp = null; AllTrue(); }
static void DspInit(DysonSphere __instance) { if (__instance != null) { var _this = __instance; int index = __instance.starData.index; double num5 = (double)_this.starData.dysonLumino; _this.energyGenPerSail = Configs.freeMode.solarSailEnergyPerTick; _this.energyGenPerNode = Configs.freeMode.dysonNodeEnergyPerTick; _this.energyGenPerFrame = Configs.freeMode.dysonFrameEnergyPerTick; _this.energyGenPerShell = Configs.freeMode.dysonShellEnergyPerTick; _this.energyGenPerSail = (long)((double)_this.energyGenPerSail * num5); _this.energyGenPerNode = (long)((double)_this.energyGenPerNode * num5); _this.energyGenPerFrame = (long)((double)_this.energyGenPerFrame * num5); _this.energyGenPerShell = (long)((double)_this.energyGenPerShell * num5); } }
public override void ProcessPacket(DysonSphereLoadRequest packet, NebulaConnection conn) { if (IsClient) { return; } switch (packet.Event) { case DysonSphereRequestEvent.List: using (BinaryUtils.Writer writer = new BinaryUtils.Writer()) { List <int> list = new List <int>(); for (int i = 0; i < GameMain.data.dysonSpheres.Length; ++i) { if (GameMain.data.dysonSpheres[i] != null) { list.Add(i); } } writer.BinaryWriter.Write(list.Count); foreach (int starIndex in list) { writer.BinaryWriter.Write(starIndex); } conn.SendPacket(new DysonSphereData(packet.StarIndex, writer.CloseAndGetBytes(), DysonSphereRespondEvent.List)); } break; case DysonSphereRequestEvent.Load: DysonSphere dysonSphere = GameMain.data.CreateDysonSphere(packet.StarIndex); using (BinaryUtils.Writer writer = new BinaryUtils.Writer()) { dysonSphere.Export(writer.BinaryWriter); byte[] data = writer.CloseAndGetBytes(); Log.Info($"Sent {data.Length} bytes of data for DysonSphereData (INDEX: {packet.StarIndex})"); conn.SendPacket(new DysonSphereData(packet.StarIndex, data, DysonSphereRespondEvent.Load)); Multiplayer.Session.DysonSpheres.RegisterPlayer(conn, packet.StarIndex); } break; case DysonSphereRequestEvent.Unload: Multiplayer.Session.DysonSpheres.UnRegisterPlayer(conn, packet.StarIndex); break; } }
public static void ExportBP(this DysonSphere _this, BinaryWriter w) { w.Write(2); w.Write(_this.randSeed); w.Write(_this.layerCount); w.Write(_this.layersIdBased.Length); for (int i = 1; i < _this.layersIdBased.Length; i++) { if (_this.layersIdBased[i] != null && _this.layersIdBased[i].id == i) { w.Write(i); _this.layersIdBased[i].ExportBP(w); } else { w.Write(0); } } w.Write(_this.autoNodeCount); w.Write(_this.autoNodes.Length); for (int l = 0; l < _this.autoNodes.Length; l++) { if (_this.autoNodes[l] != null) { w.Write(1); w.Write(_this.autoNodes[l].layerId); w.Write(_this.autoNodes[l].id); } else { w.Write(0); } } w.Write(_this.nrdCapacity); w.Write(_this.nrdCursor); w.Write(_this.nrdRecycleCursor); for (int m = 1; m < _this.nrdCursor; m++) { _this.nrdPool[m].Export(w); } for (int n = 0; n < _this.nrdRecycleCursor; n++) { w.Write(_this.nrdRecycle[n]); } }
public override void ProcessPacket(DysonSphereRemoveLayerPacket packet, NebulaConnection conn) { DysonSphere sphere = GameMain.data.dysonSpheres[packet.StarIndex]; if (sphere == null) { return; } using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On()) { sphere.RemoveLayer(packet.LayerId); NebulaWorld.Universe.DysonSphereManager.ClearSelection(packet.StarIndex); } if (IsHost) { Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn); } }
public override void ProcessPacket(DysonSwarmAddOrbitPacket packet, NebulaConnection conn) { DysonSphere sphere = GameMain.data.dysonSpheres[packet.StarIndex]; if (sphere == null) { return; } using (Multiplayer.Session.DysonSpheres.IncomingDysonSwarmPacket.On()) { if (packet.OrbitId != NebulaWorld.Universe.DysonSphereManager.QueryOrbitId(sphere.swarm)) { Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn); return; } sphere.swarm.NewOrbit(packet.Radius, packet.Rotation.ToQuaternion()); } if (IsHost) { Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn); } }
public override void ProcessPacket(DysonSphereAddLayerPacket packet, NebulaConnection conn) { DysonSphere sphere = GameMain.data.dysonSpheres[packet.StarIndex]; if (sphere == null) { return; } using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On()) { if (packet.LayerId != sphere.QueryLayerId()) { Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn); return; } sphere.AddLayer(packet.OrbitRadius, packet.OrbitRotation.ToQuaternion(), packet.OrbitAngularSpeed); } if (IsHost) { Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn); } }
public static bool BeforeGameTick_Prefix(DysonSphere __instance, long times) { if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) { return(true); } //Update swarm and layer energy generation stats every 120 frames if (times % 120 == 0) { __instance.swarm.energyGenCurrentTick = __instance.swarm.sailCount * __instance.energyGenPerSail; for (int i = 0; i < 10; i++) { DysonSphereLayer dysonSphereLayer = __instance.layersSorted[i]; if (dysonSphereLayer != null) { dysonSphereLayer.energyGenCurrentTick = 0L; DysonNode[] nodePool = dysonSphereLayer.nodePool; DysonShell[] shellPool = dysonSphereLayer.shellPool; for (int j = 1; j < dysonSphereLayer.nodeCursor; j++) { if (nodePool[j] != null && nodePool[j].id == j) { dysonSphereLayer.energyGenCurrentTick += nodePool[j].EnergyGenCurrentTick(__instance.energyGenPerNode, __instance.energyGenPerFrame, 0L); } } for (int k = 1; k < dysonSphereLayer.shellCursor; k++) { if (shellPool[k] != null && shellPool[k].id == k) { dysonSphereLayer.energyGenCurrentTick += shellPool[k].cellPoint * __instance.energyGenPerShell; } } } } } //Sync other Dyson sphere status related to ray receivers on client side by DysonSphereStatusPacket return(false); }
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); } }
IEnumerator AddSp(DysonSphere dsp) { yield return(new WaitForEndOfFrame()); long count = 0; for (int i = 0; i < dsp.layersIdBased.Length; i++) { var shell = dsp.layersIdBased[i]; if (shell != null) { for (int j = 0; j < shell.nodeCursor; j++) { var node = shell.nodePool[j]; if (node != null) { count++; node.ConstructSp(); //node.ConstructCp(); } } } } }
public static bool RemoveLayer_Prefix2(DysonSphere __instance, DysonSphereLayer layer) { //Notify others that user removed layer to dyson sphere plan RemoveLayer(layer.id, __instance.starData.index); return(true); }