コード例 #1
0
        public bool CanCraft(CraftData item, bool skip_near = false)
        {
            if (item == null)
            {
                return(false);
            }

            CraftCostData cost      = item.GetCraftCost();
            bool          can_craft = true;

            Dictionary <GroupData, int> item_groups = new Dictionary <GroupData, int>(); //Add to groups so that fillers are not same than items

            foreach (KeyValuePair <ItemData, int> pair in cost.craft_items)
            {
                AddCraftCostItemsGroups(item_groups, pair.Key, pair.Value);
                if (!HasItem(pair.Key, pair.Value))
                {
                    can_craft = false; //Dont have required items
                }
            }

            foreach (KeyValuePair <GroupData, int> pair in cost.craft_fillers)
            {
                int value = pair.Value + CountCraftCostGroup(item_groups, pair.Key);
                if (!HasItemInGroup(pair.Key, value))
                {
                    can_craft = false; //Dont have required items
                }
            }

            return(can_craft);
        }
コード例 #2
0
        public void PayCraftingCost(CraftData item)
        {
            CraftCostData cost = item.GetCraftCost();

            foreach (KeyValuePair <ItemData, int> pair in cost.craft_items)
            {
                RemoveItem(pair.Key, pair.Value);
            }
            foreach (KeyValuePair <GroupData, int> pair in cost.craft_fillers)
            {
                RemoveItemInGroup(pair.Key, pair.Value);
            }
        }
コード例 #3
0
        //---- Crafting ----

        public bool CanCraft(CraftData item, bool skip_near = false)
        {
            if (item == null)
            {
                return(false);
            }

            CraftCostData cost      = item.GetCraftCost();
            bool          can_craft = true;

            Dictionary <GroupData, int> item_groups = new Dictionary <GroupData, int>(); //Add to groups so that fillers are not same than items

            foreach (KeyValuePair <ItemData, int> pair in cost.craft_items)
            {
                AddCraftCostItemsGroups(item_groups, pair.Key, pair.Value);
                if (!character.Inventory.HasItem(pair.Key, pair.Value))
                {
                    can_craft = false; //Dont have required items
                }
            }

            foreach (KeyValuePair <GroupData, int> pair in cost.craft_fillers)
            {
                int value = pair.Value + CountCraftCostGroup(item_groups, pair.Key);
                if (!character.Inventory.HasItemInGroup(pair.Key, value))
                {
                    can_craft = false; //Dont have required items
                }
            }

            foreach (KeyValuePair <CraftData, int> pair in cost.craft_requirements)
            {
                if (CountRequirements(pair.Key) < pair.Value)
                {
                    can_craft = false; //Dont have required constructions
                }
            }

            if (!skip_near && cost.craft_near != null && !character.IsNearGroup(cost.craft_near) && !character.EquipData.HasItemInGroup(cost.craft_near))
            {
                can_craft = false; //Not near required construction
            }
            return(can_craft);
        }
コード例 #4
0
        private void RefreshPanel()
        {
            slot.SetSlot(data, data.craft_quantity, true);
            title.text = data.title;
            desc.text  = data.desc;

            foreach (ItemSlot slot in craft_slots)
            {
                slot.Hide();
            }

            PlayerCharacter player = parent_ui.GetPlayer();

            CraftCostData cost  = data.GetCraftCost();
            int           index = 0;

            foreach (KeyValuePair <ItemData, int> pair in cost.craft_items)
            {
                if (index < craft_slots.Length)
                {
                    ItemSlot slot = craft_slots[index];
                    slot.SetSlot(pair.Key, pair.Value, false);
                    slot.SetFilter(player.Inventory.HasItem(pair.Key, pair.Value) ? 0 : 2);
                    slot.ShowTitle();
                }
                index++;
            }

            foreach (KeyValuePair <GroupData, int> pair in cost.craft_fillers)
            {
                if (index < craft_slots.Length)
                {
                    ItemSlot slot = craft_slots[index];
                    slot.SetSlotCustom(pair.Key.icon, pair.Key.title, pair.Value, false);
                    slot.SetFilter(player.Inventory.HasItemInGroup(pair.Key, pair.Value) ? 0 : 2);
                    slot.ShowTitle();
                }
                index++;
            }

            foreach (KeyValuePair <CraftData, int> pair in cost.craft_requirements)
            {
                if (index < craft_slots.Length)
                {
                    ItemSlot slot = craft_slots[index];
                    slot.SetSlot(pair.Key, pair.Value, false);
                    slot.SetFilter(player.Crafting.CountRequirements(pair.Key) >= pair.Value ? 0 : 2);
                    slot.ShowTitle();
                }
                index++;
            }

            if (index < craft_slots.Length)
            {
                ItemSlot slot = craft_slots[index];
                if (cost.craft_near != null)
                {
                    slot.SetSlotCustom(cost.craft_near.icon, cost.craft_near.title, 1, false);
                    bool isnear = player.IsNearGroup(cost.craft_near) || player.EquipData.HasItemInGroup(cost.craft_near);
                    slot.SetFilter(isnear ? 0 : 2);
                    slot.ShowTitle();
                }
            }

            craft_btn.interactable = player.Crafting.CanCraft(data);
        }