void OnItemSelected(int itemIndex)
    {
        if (inventory_Controller.inventory.inventory_items[itemIndex].item == null)
        {
            return;
        }
        currMachine.AnimateOn();
        if (playerInventoryControl == null)
        {
            playerInventoryControl = Character_Manager.instance.player_GObj.GetComponent <Courier_Controller>();
        }

        Inventory playerInventory = playerInventoryControl.characterData.characterInventory;

        if (playerInventory.IsFull() == true)
        {
            return;
        }

        Item item = inventory_Controller.inventory.inventory_items[itemIndex].item;

        if (playerInventory.AddItem(item) == false)
        {
            return;
        }
        if (inventory_Controller.inventory.RemoveItem(item.name, 1) == false)
        {
            return;
        }
        // Instead of spawning item, give it to player directly
        //Item_Manager.instance.SpawnItem(item, currMachine.transform.position + Vector3.down);
    }
    public override void Interact(GameObject user)
    {
        Debug.Log("Interacting with " + producer.name);
        if (isProducing == true)
        {
            Debug.Log("Producer already producing!");
            return;
        }

        Courier_Controller controller = user.GetComponent <Courier_Controller>();

        if (controller == null)
        {
            return;
        }
        // Try to start production with item in user's hand
        if (CanStart(controller) == true)
        {
            if (HasRequiredItems(controller))
            {
                ChargeItems(controller);
                StartProduction();
            }
        }
    }
Beispiel #3
0
 void Awake()
 {
     movementController              = GetComponent <CharacterMovement>();
     courierController               = GetComponent <Courier_Controller>();
     movementController.onStartMove += OnStartMove;
     movementController.onStopMove  += OnStopMove;
     countdown = new CountdownHelper(1);
     animator  = GetComponentInChildren <Animator>();
 }
    bool CanStart(Courier_Controller controller)
    {
        if (inventory_Controller.inventory.IsFull())
        {
            return(false);
        }

        if (controller.iteminHand == null)
        {
            return(false);
        }

        return(true);
    }
 void ChargeItems(Courier_Controller controller)
 {
     if (controller.RemoveItem(producer.current_Blueprint.keyIngredient.itemName, producer.current_Blueprint.keyIngredient.count) == false)
     {
         return;
     }
     if (producer.current_Blueprint.secondaryIngredients.Length > 0)
     {
         foreach (ItemReference itemRef in producer.current_Blueprint.secondaryIngredients)
         {
             if (controller.RemoveItem(itemRef.itemName, itemRef.count) == false)
             {
                 break;
             }
         }
     }
 }
 bool HasRequiredItems(Courier_Controller controller)
 {
     if (producer.SetCurrentBlueprint(controller.iteminHand.name) == false)
     {
         return(false);
     }
     if (controller.HasItem(producer.current_Blueprint.keyIngredient.itemName, producer.current_Blueprint.keyIngredient.count) == false)
     {
         return(false);
     }
     if (producer.current_Blueprint.secondaryIngredients.Length > 0)
     {
         for (int i = 0; i < producer.current_Blueprint.secondaryIngredients.Length; i++)
         {
             if (controller.HasItem(producer.current_Blueprint.secondaryIngredients[i].itemName, producer.current_Blueprint.secondaryIngredients[i].count) == false)
             {
                 return(false);
             }
         }
     }
     return(true);
 }