Example #1
0
    //! Called once per frame when the player is looking at an iron block.
    public void InteractWithIronBlock()
    {
        playerController.machineGUIopen = false;
        if (cInput.GetKeyDown("Collect Object"))
        {
            string objectName = "";
            if (playerController.objectInSight.name.Equals("IronRamp(Clone)"))
            {
                objectName = "Iron Ramp";
            }
            else
            {
                objectName = "Iron Block";
            }

            interactionController.CollectObject(objectName);
        }
    }
Example #2
0
    //! Called when the player is looking at a storage container.
    public void InteractWithStorageContainer()
    {
        playerController.machineGUIopen = false;
        InventoryManager inventory = playerController.objectInSight.GetComponent <InventoryManager>();

        if (cInput.GetKeyDown("Interact"))
        {
            if (PlayerPrefsX.GetPersistentBool("multiplayer") == true)
            {
                if (!interactionController.CanInteract())
                {
                    return;
                }
            }
            if (playerController.storageGUIopen == false)
            {
                if (inventory.initialized == true)
                {
                    Cursor.visible   = true;
                    Cursor.lockState = CursorLockMode.None;
                    playerController.storageGUIopen      = true;
                    playerController.craftingGUIopen     = false;
                    playerController.machineGUIopen      = false;
                    playerController.inventoryOpen       = true;
                    playerController.storageInventory    = inventory;
                    playerController.remoteStorageActive = false;
                }
            }
            else
            {
                Cursor.visible   = false;
                Cursor.lockState = CursorLockMode.Locked;
                playerController.inventoryOpen   = false;
                playerController.craftingGUIopen = false;
                playerController.machineGUIopen  = false;
                playerController.storageGUIopen  = false;
            }
        }
        if (cInput.GetKeyDown("Collect Object") && inventory.ID != "Rocket" && inventory.ID != "Lander")
        {
            bool spaceAvailable = false;
            foreach (InventorySlot slot in playerController.playerInventory.inventory)
            {
                if (slot.typeInSlot.Equals("nothing") || slot.typeInSlot.Equals("Storage Container") && slot.amountInSlot < 1000)
                {
                    spaceAvailable = true;
                }
            }
            if (spaceAvailable == true)
            {
                InventoryManager thisContainer = inventory;
                foreach (InventorySlot slot in thisContainer.inventory)
                {
                    slot.typeInSlot   = "nothing";
                    slot.amountInSlot = 0;
                }
                thisContainer.SaveData();
                if (playerController.objectInSight.GetComponent <RailCart>() != null)
                {
                    interactionController.CollectObject("Rail Cart");
                }
                else
                {
                    interactionController.CollectObject("Storage Container");
                }
                Object.Destroy(playerController.objectInSight);
                playerController.PlayCraftingSound();
            }
            else
            {
                playerController.cannotCollect = true;
                playerController.PlayCraftingSound();
            }
        }
    }