public static void StructureComponentAction(uLink.BitStream stream, ItemRepresentation rep, ref uLink.NetworkMessageInfo info, StructureComponentDataBlock SCDB) { uLink.NetworkPlayer netPlayer = info.sender; PlayerClient playerClient = Array.Find(AllPlayerClients.ToArray(), (PlayerClient pc) => pc.netPlayer == netPlayer); IStructureComponentItem item; NetCull.VerifyRPC(ref info); if (rep.Item<IStructureComponentItem>(out item) && (item.uses > 0)) { StructureComponent structureToPlacePrefab = SCDB.structureToPlacePrefab; Vector3 origin = stream.ReadVector3(); Vector3 direction = stream.ReadVector3(); Vector3 position = stream.ReadVector3(); Quaternion rotation = stream.ReadQuaternion(); uLink.NetworkViewID viewID = stream.ReadNetworkViewID(); StructureMaster component = null; if (nearZone(position) && !buildList.Contains(playerClient.userID.ToString())) { Rust.Notice.Popup(info.sender, "", "You can't place that near safe zones or war zones.", 4f); } else { if (viewID == uLink.NetworkViewID.unassigned) { if (SCDB.MasterFromRay(new Ray(origin, direction))) { return; } if (structureToPlacePrefab.type != StructureComponent.StructureComponentType.Foundation) { Debug.Log("ERROR, tried to place non foundation structure on terrain!"); } else { component = NetCull.InstantiateClassic<StructureMaster>(Bundling.Load<StructureMaster>("content/structures/StructureMasterPrefab"), position, rotation, 0); component.SetupCreator(item.controllable); } } else { component = uLink.NetworkView.Find(viewID).gameObject.GetComponent<StructureMaster>(); } if (component == null) { Debug.Log("NO master, something seriously wrong"); } else if (SCDB._structureToPlace.CheckLocation(component, position, rotation) && SCDB.CheckBlockers(position)) { StructureComponent comp = NetCull.InstantiateStatic(SCDB.structureToPlaceName, position, rotation).GetComponent<StructureComponent>(); if (comp != null) { component.AddStructureComponent(comp); int count = 1; if (item.Consume(ref count)) { item.inventory.RemoveItem(item.slot); } } } } } }
public static void DeployableItemAction(uLink.BitStream stream, ItemRepresentation rep, ref uLink.NetworkMessageInfo info, DeployableItemDataBlock DIDB) { uLink.NetworkPlayer netPlayer = info.sender; PlayerClient playerClient = Array.Find(AllPlayerClients.ToArray(), (PlayerClient pc) => pc.netPlayer == netPlayer); IDeployableItem item; NetCull.VerifyRPC(ref info); if (rep.Item<IDeployableItem>(out item) && (item.uses > 0)) { Vector3 vector3; Quaternion quaternion; TransCarrier carrier; Vector3 origin = stream.ReadVector3(); Vector3 direction = stream.ReadVector3(); Ray ray = new Ray(origin, direction); if (!DIDB.CheckPlacement(ray, out vector3, out quaternion, out carrier)) { Rust.Notice.Popup(info.sender, "", "You can't place that here.", 4f); } else { if (nearZone(vector3) && !buildList.Contains(playerClient.userID.ToString())) { Rust.Notice.Popup(info.sender, "", "You can't place that near safe zones or war zones.", 4f); } else { DeployableObject component = NetCull.InstantiateStatic(DIDB.DeployableObjectPrefabName, vector3, quaternion).GetComponent<DeployableObject>(); // Creates model in world space if (component != null) { try { component.SetupCreator(item.controllable); // Sets object variables such as ownerID DIDB.SetupDeployableObject(stream, rep, ref info, component, carrier); } finally { int count = 1; if (item.Consume(ref count)) { item.inventory.RemoveItem(item.slot); } } } } } } }