public bool CanCraftItem(CraftableItem item)
    {
        Player_Inventory_Script invRef = Player_Accessor_Script.InventoryScript;
        bool craftable = true;

        foreach (Reagent r in item.RequiredReagents)
        {
            int invCount = invRef.GetResourceQuantity(r);
            if (invCount == -1 || invCount < r.ReagentQuantity)
            {
                print("Insufficient resource: " + r.ReagentName + " - " + r.ReagentQuantity);
                craftable = false;
                break;
            }
        }

        if (craftable)
        {
            foreach (Reagent r in item.RequiredReagents)
            {
                invRef.RemoveResource(r, r.ReagentQuantity);
            }
        }

        return(craftable);
        //return true;
    }
Esempio n. 2
0
    private void Start()
    {
        aLib = GameObject.FindGameObjectWithTag("AbilityDictionary").GetComponent <AbilityLibrary>();
        equipmentController      = GameObject.FindGameObjectWithTag("PrimaryInterface").transform.Find("ItemCrafting").GetComponent <EquipmentCrafting_Controller>();
        inventory                = GetComponent <Player_Inventory_Script>();
        activeLegendaryPerks     = new List <LegendaryPerk>();
        equipmentController.ALib = aLib;

        #region Armor types
        ArmorItemTypes = new List <ItemType>();
        ArmorItemTypes.Add(ItemType.HELMET);
        ArmorItemTypes.Add(ItemType.HAT);
        ArmorItemTypes.Add(ItemType.COIF);
        ArmorItemTypes.Add(ItemType.CHESTPLATE);
        ArmorItemTypes.Add(ItemType.CHESTGUARD);
        ArmorItemTypes.Add(ItemType.ROBE);
        ArmorItemTypes.Add(ItemType.CHAPS);
        ArmorItemTypes.Add(ItemType.PLATELEGS);
        ArmorItemTypes.Add(ItemType.TROUSERS);
        #endregion

        if (File.Exists("CharData.dat"))
        {
            LoadCharacterData();
            GetComponent <Player_Details_Script>().MaxHealth = BonusHealth;
        }
        CurrentWeaponSlot = 0;
    }
    // Use this for initialization
    void Awake()
    {
        if (GameObject.FindGameObjectsWithTag(transform.tag).Length > 1)
        {
            Destroy(gameObject);
            return;
        }

        EquipmentScript    = GetComponent <Player_Equipment_Script>();
        SkillsScript       = GetComponent <Player_Skills_Script>();
        InventoryScript    = GetComponent <Player_Inventory_Script>();
        ControllerScript   = GetComponent <Player_Controller_Script>();
        DetailsScript      = GetComponent <Player_Details_Script>();
        ReputationScript   = GetComponent <Player_Reputation_Script>();
        AbilitiesInterface = GameObject.Find("Interface/Abilities").GetComponent <Abilities_Interface>();
        DialogInterface    = GameObject.Find("Interface/Dialog").GetComponent <Dialog_Interface>();
    }
Esempio n. 4
0
 void Start()
 {
     itemPane        = transform.Find("Panel");
     playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent <Player_Inventory_Script>();
     playerEquipment = playerInventory.GetComponent <Player_Equipment_Script>();
     for (int i = 0; i < itemPane.childCount; i++)
     {
         for (int j = 0; j < itemPane.GetChild(i).childCount; j++)
         {
             Slot_Tracker scr = itemPane.GetChild(i).GetChild(j).gameObject.GetComponent <Slot_Tracker>();
             scr.Slot = (i * itemPane.childCount) + j;
             scr.GetComponent <Button>().onClick.AddListener(scr.EquipItemFromSlot);
             scr.PlayerInventory = playerInventory;
             scr.PlayerEquipment = playerEquipment;
         }
     }
 }
Esempio n. 5
0
    private void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
            return;
        }

        Interface_Controller.instance.InterfaceEvents.Add("EquipWeapon", new UnityEngine.Events.UnityEvent());
        Interface_Controller.instance.InterfaceEvents.Add("OpenInventory", new UnityEngine.Events.UnityEvent());

        itemPane      = transform.Find("Background/Inventory/Item_Pane/ItemSection");
        characterPane = transform.Find("Background/Inventory/Character_Pane");

        playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent <Player_Inventory_Script>();
        playerEquipment = playerInventory.GetComponent <Player_Equipment_Script>();
        emptySlotIcon   = Resources.Load <Sprite>("ItemIcons/EmptySlot");

        for (int i = 0; i < itemPane.childCount; i++)
        {
            for (int j = 0; j < itemPane.GetChild(i).childCount; j++)
            {
                Slot_Tracker scr = itemPane.GetChild(i).GetChild(j).gameObject.GetComponent <Slot_Tracker>();
                scr.Slot           = (i * itemPane.GetChild(i).childCount + j);
                scr.transform.name = scr.Slot.ToString();
                //scr.GetComponent<Button>().onClick.AddListener(scr.EquipItemFromSlot);
                scr.PlayerInventory = playerInventory;
                scr.PlayerEquipment = playerEquipment;
            }
        }

        //Stat Icon References
        Sprite[] statIconSprites = Resources.LoadAll <Sprite>("StatIcons");
        foreach (Sprite statSprite in statIconSprites)
        {
            statIcons.Add(statSprite.name, statSprite);
        }
        //Inventory Hovering & Comparison
        hoveredItemPanel        = transform.Find("Background/HoverItems/Hovered");
        hoveredReagentItemPanel = transform.Find("Background/HoverItems/HoveredReagent");
        comparedItemPanel       = transform.Find("Background/HoverItems/Current");
        hoveredItemPanel.GetComponent <CanvasGroup>().alpha        = 0;
        hoveredReagentItemPanel.GetComponent <CanvasGroup>().alpha = 0;
        comparedItemPanel.GetComponent <CanvasGroup>().alpha       = 0;

        //Drag events for inventory items
        for (int i = 0; i < itemPane.childCount; i++)
        {
            Transform rowRef = itemPane.GetChild(i);
            for (int j = 0; j < rowRef.childCount; j++)
            {
                EventTrigger       trigger = rowRef.GetChild(j).GetComponent <EventTrigger>();
                EventTrigger.Entry entry   = new EventTrigger.Entry();
                entry.eventID = EventTriggerType.Drop;
                int temp = new int();
                temp = i * rowRef.childCount + j;
                entry.callback.AddListener((data) => { DropActiveItem((PointerEventData)data, temp); });
                trigger.triggers.Add(entry);

                entry         = new EventTrigger.Entry();
                entry.eventID = EventTriggerType.Drag;
                temp          = new int();
                temp          = i * rowRef.childCount + j;
                entry.callback.AddListener((data) => { DragActiveItem((PointerEventData)data, temp); });
                trigger.triggers.Add(entry);
            }
        }

        currentGearPanel = characterPane.Find("Equipment/Gear_Column");
        for (int i = 1; i < 5; i++)
        {
            Transform          section = currentGearPanel.GetChild(i);
            EventTrigger       trigger = section.GetComponent <EventTrigger>();
            EventTrigger.Entry entry   = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.Drop;
            entry.callback.AddListener((data) => { EquipDraggedItem((PointerEventData)data, section.name); });
            trigger.triggers.Add(entry);
        }

        currentGearPanel.GetChild(0).Find("Weapons").GetComponent <Button>().interactable = !displayEquippedWeaponTab;
        currentGearPanel.GetChild(0).Find("Armor").GetComponent <Button>().interactable   = displayEquippedWeaponTab;

        //Reagent Cards
        for (int i = 0; i < EquipmentCrafting_Controller.instance.CraftableReagents.Count; i++)
        {
            GameObject reagentRef = Instantiate(reagentItemCard, resourcePanel.transform, false);
            if (playerInventory.GetResourceQuantity(EquipmentCrafting_Controller.instance.CraftableReagents[i].ItemName) > -1)
            {
                reagentRef.GetComponent <Image>().sprite = Resources.Load <Sprite>("ItemIcons/ResourceIcons/" + EquipmentCrafting_Controller.instance.CraftableReagents[i].SpritePath);
            }
            else
            {
                reagentRef.GetComponent <Image>().sprite = Resources.Load <Sprite>("ItemIcons/LockedSlot");
            }
            reagentRef.name = EquipmentCrafting_Controller.instance.CraftableReagents[i].ItemName;
            reagentRef.GetComponent <Slot_Tracker>().Resource = true;
        }

        GetComponent <CanvasGroup>().alpha = 0;
    }