Example #1
0
 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);
                         }
                     }
                 }
             }
         }
     }
 }