public void EquipItemTo(InventoryData inventory, int islot, EquipSlot eslot)
        {
            InventoryItemData invt_slot  = inventory.GetItem(islot);
            InventoryItemData invt_equip = EquipData.GetEquippedItem(eslot);
            ItemData          idata      = ItemData.Get(invt_slot?.item_id);
            ItemData          edata      = ItemData.Get(invt_equip?.item_id);

            if (invt_slot != null && inventory != EquipData && invt_slot.quantity > 0 && idata != null && eslot > 0)
            {
                if (edata == null)
                {
                    //Equip only
                    EquipData.EquipItem(eslot, idata.id, invt_slot.durability, invt_slot.uid);
                    inventory.RemoveItemAt(islot, 1);
                }
                else if (invt_slot.quantity == 1 && idata.type == ItemType.Equipment)
                {
                    //Swap
                    inventory.RemoveItemAt(islot, 1);
                    EquipData.UnequipItem(eslot);
                    EquipData.EquipItem(eslot, idata.id, invt_slot.durability, invt_slot.uid);
                    inventory.AddItemAt(edata.id, islot, 1, invt_equip.durability, invt_equip.uid);
                }
            }
        }
        public override void DoAction(PlayerCharacter character, ItemSlot slot)
        {
            ItemData      item      = slot.GetItem();
            InventoryData inventory = slot.GetInventory();

            if (item != null && item.construction_data != null)
            {
                character.Crafting.CraftConstructionBuildMode(item.construction_data, false, (Buildable build) =>
                {
                    InventoryItemData invdata = inventory.GetItem(slot.index);
                    inventory.RemoveItemAt(slot.index, 1);

                    BuiltConstructionData constru = PlayerData.Get().GetConstructed(build.GetUID());
                    if (invdata != null && constru != null && item.HasDurability())
                    {
                        constru.durability = invdata.durability; //Save durability
                    }
                });

                TheAudio.Get().PlaySFX("craft", item.craft_sound);
            }

            if (item != null && item.character_data != null)
            {
                character.Crafting.CraftCharacterBuildMode(item.character_data, false, (Buildable build) =>
                {
                    InventoryItemData invdata = inventory.GetItem(slot.index);
                    inventory.RemoveItemAt(slot.index, 1);
                });

                TheAudio.Get().PlaySFX("craft", item.craft_sound);
            }
        }
        public void SetOneItem(ItemSlot slot_select, ItemSlot slot_target)
        {
            InventoryData inventory1 = slot_select.GetInventory();
            InventoryData inventory2 = slot_target.GetInventory();

            if (current_player != null && inventory1 != null && inventory2 != null)
            {
                InventoryItemData invdata = inventory1.GetItem(slot_select.index);
                if (invdata != null && invdata.quantity > 0 && slot_target.GetItem() == null)
                {
                    if (inventory2.type == InventoryType.Equipment)
                    {
                        current_player.Inventory.EquipItem(inventory1, slot_select.index);
                    }
                    else if (inventory1.type == InventoryType.Equipment && slot_select is EquipSlotUI)
                    {
                        EquipSlotUI eslot = (EquipSlotUI)slot_select;
                        current_player.Inventory.UnequipItemTo(inventory2, eslot.equip_slot, slot_target.index);
                    }
                    else
                    {
                        string uid = invdata.quantity > 1 ? UniqueID.GenerateUniqueID() : invdata.uid;
                        inventory1.RemoveItemAt(slot_select.index, 1);
                        inventory2.AddItemAt(invdata.item_id, slot_target.index, 1, invdata.durability, uid);
                    }

                    if (invdata.quantity <= 1)
                    {
                        CancelPlayerSelection();
                    }
                }
            }
        }
        public override void DoAction(PlayerCharacter character, ItemSlot slot1, ItemSlot slot2)
        {
            InventoryData inventory = slot1.GetInventory();

            inventory.RemoveItemAt(slot1.index, 1);
            character.Inventory.GainItem(cut_item, 1);
        }
        public void UnequipItemTo(InventoryData inventory, EquipSlot eslot, int islot)
        {
            InventoryItemData invt_slot  = inventory.GetItem(islot);
            InventoryItemData invt_equip = EquipData.GetEquippedItem(eslot);
            ItemData          idata      = ItemData.Get(invt_slot?.item_id);
            ItemData          edata      = ItemData.Get(invt_equip?.item_id);

            if (edata != null && inventory != EquipData && inventory.uid != invt_equip.uid)
            {
                bool same_item  = idata != null && invt_slot != null && invt_slot.quantity > 0 && idata.id == edata.id && invt_slot.quantity < idata.inventory_max;
                bool slot_empty = invt_slot == null || invt_slot.quantity <= 0;
                if (same_item || slot_empty)
                {
                    //Unequip
                    EquipData.UnequipItem(eslot);
                    inventory.AddItemAt(edata.id, islot, 1, invt_equip.durability, invt_equip.uid);
                }
                else if (idata != null && invt_slot != null && !same_item && idata.type == ItemType.Equipment && idata.equip_slot == edata.equip_slot && invt_slot.quantity == 1)
                {
                    //swap
                    inventory.RemoveItemAt(islot, 1);
                    EquipData.UnequipItem(eslot);
                    EquipData.EquipItem(eslot, idata.id, invt_slot.durability, invt_slot.uid);
                    inventory.AddItemAt(edata.id, islot, 1, invt_equip.durability, invt_equip.uid);
                }
            }
        }
        public void DropItem(InventoryData inventory, int slot)
        {
            InventoryItemData invdata = inventory?.GetItem(slot);
            ItemData          idata   = ItemData.Get(invdata?.item_id);

            if (invdata != null && idata != null && invdata.quantity > 0)
            {
                if (idata.CanBeDropped())
                {
                    inventory.RemoveItemAt(slot, invdata.quantity);
                    Item iitem = Item.Create(idata, character.GetPosition(), invdata.quantity, invdata.durability, invdata.uid);

                    PlayerUI.Get(character.player_id)?.CancelSelection();

                    if (onDropItem != null)
                    {
                        onDropItem.Invoke(iitem);
                    }
                }
                else if (idata.CanBeBuilt())
                {
                    BuildItem(inventory, slot);
                }
            }
        }
        public void EatItem(InventoryData inventory, int slot)
        {
            InventoryItemData idata = inventory.GetItem(slot);
            ItemData          item  = ItemData.Get(idata?.item_id);

            if (item != null && item.type == ItemType.Consumable)
            {
                if (inventory.IsItemIn(item.id, slot))
                {
                    inventory.RemoveItemAt(slot, 1);
                    if (item.container_data)
                    {
                        inventory.AddItem(item.container_data.id, 1, item.container_data.durability, UniqueID.GenerateUniqueID());
                    }

                    character.StopSleep();
                    character.Attributes.AddAttribute(AttributeType.Health, item.eat_hp);
                    character.Attributes.AddAttribute(AttributeType.Hunger, item.eat_hunger);
                    character.Attributes.AddAttribute(AttributeType.Thirst, item.eat_thirst);
                    character.Attributes.AddAttribute(AttributeType.Happiness, item.eat_happiness);

                    foreach (BonusEffectData bonus in item.eat_bonus)
                    {
                        character.Data.AddTimedBonus(bonus.type, bonus.value, item.eat_bonus_duration);
                    }
                }
            }
        }
예제 #8
0
 //Merge action
 public override void DoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
 {
     if (select.HasGroup(merge_target))
     {
         InventoryData inventory = slot.GetInventory();
         inventory.RemoveItemAt(slot.index, 1);
         character.Inventory.GainItem(inventory, filled_item, 1);
     }
 }
        public void UseItem(ItemSlot slot, int quantity = 1)
        {
            InventoryData inventory1 = slot.GetInventory();

            if (current_player != null && inventory1 != null)
            {
                inventory1.RemoveItemAt(slot.index, quantity);
            }
        }
예제 #10
0
 //Merge action
 public override void DoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
 {
     character.TriggerAnim("Craft", select.transform.position);
     character.TriggerProgressAction(duration, () =>
     {
         InventoryData inventory = slot.GetInventory();
         inventory.RemoveItemAt(slot.index, 1);
         character.Inventory.GainItem(cooked_item, 1);
     });
 }
        //Merge action
        public override void DoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
        {
            Firepit       fire      = select.GetComponent <Firepit>();
            InventoryData inventory = slot.GetInventory();

            if (fire != null && slot.GetItem() && inventory.HasItem(slot.GetItem().id))
            {
                fire.AddFuel(fire.wood_add_fuel);
                inventory.RemoveItemAt(slot.index, 1);
            }
        }
        public void CombineInventoryItems(InventoryData inventory1, int slot1, InventoryData inventory2, int slot2)
        {
            InventoryItemData invt_slot1 = inventory1.GetItem(slot1);
            InventoryItemData invt_slot2 = inventory2.GetItem(slot2);

            if (invt_slot1.item_id == invt_slot2.item_id)
            {
                inventory1.RemoveItemAt(slot1, invt_slot1.quantity);
                inventory2.AddItemAt(invt_slot1.item_id, slot2, invt_slot1.quantity, invt_slot1.durability, invt_slot1.uid);
            }
        }
        public void BuildItem(InventoryData inventory, int slot)
        {
            InventoryItemData invdata = inventory?.GetItem(slot);
            ItemData          idata   = ItemData.Get(invdata?.item_id);

            if (invdata != null && idata != null)
            {
                ConstructionData construct  = idata.construction_data;
                PlantData        aplant     = idata.plant_data;
                CharacterData    acharacter = idata.character_data;

                if (construct != null)
                {
                    inventory.RemoveItemAt(slot, 1);
                    Construction          construction = character.Crafting.CraftConstruction(construct, false);
                    BuiltConstructionData constru      = PlayerData.Get().GetConstructed(construction.GetUID());
                    if (idata.HasDurability())
                    {
                        constru.durability = invdata.durability; //Save durability
                    }
                    TheAudio.Get().PlaySFX("craft", construction.GetBuildable().build_audio);
                }

                else if (aplant != null)
                {
                    inventory.RemoveItemAt(slot, 1);
                    Plant plant = character.Crafting.CraftPlant(aplant, 0, false);
                    TheAudio.Get().PlaySFX("craft", plant.GetBuildable().build_audio);
                }

                else if (acharacter != null)
                {
                    inventory.RemoveItemAt(slot, 1);
                    Character charact = character.Crafting.CraftCharacter(acharacter, false);
                    TheAudio.Get().PlaySFX("craft", charact.GetBuildable().build_audio);
                }

                PlayerUI.Get(character.player_id)?.CancelSelection();
            }
        }
예제 #14
0
        public override void DoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
        {
            if (select.HasGroup(merge_target))
            {
                ItemProvider  provider  = select.GetComponent <ItemProvider>();
                InventoryData inventory = slot.GetInventory();

                provider.RemoveItem();
                provider.PlayTakeSound();
                inventory.RemoveItemAt(slot.index, 1);
                character.Inventory.GainItem(inventory, filled_item, 1);
            }
        }
예제 #15
0
        public override void DoAction(PlayerCharacter character, ItemSlot slot)
        {
            InventoryData inventory = slot.GetInventory();

            inventory.RemoveItemAt(slot.index, 1);
            foreach (ItemData item in items)
            {
                if (item != null)
                {
                    character.Inventory.GainItem(item, 1);
                }
            }
        }
예제 #16
0
        public float duration         = 1f; //In game hours

        //Merge action
        public override void DoAction(PlayerCharacter character, ItemSlot slot, Selectable select)
        {
            InventoryData     inventory = slot.GetInventory();
            InventoryItemData iidata    = inventory.GetItem(slot.index);

            Furnace furnace = select.GetComponent <Furnace>();

            if (furnace != null && furnace.CountItemSpace() > 0)
            {
                int create_quantity = Mathf.FloorToInt(iidata.quantity / (float)melt_item_quantity);
                int quantity        = furnace.PutItem(slot.GetItem(), melt_item, duration, create_quantity);
                inventory.RemoveItemAt(slot.index, quantity * melt_item_quantity);
            }
        }
        public override void DoAction(PlayerCharacter character, ItemSlot slot)
        {
            int               half      = slot.GetQuantity() / 2;
            ItemData          item      = slot.GetItem();
            InventoryData     inventory = slot.GetInventory();
            InventoryItemData item_data = inventory.GetItem(slot.index);

            inventory.RemoveItemAt(slot.index, half);

            bool          can_take   = inventory.CanTakeItem(item.id, half);
            InventoryData ninventory = can_take ? inventory : character.Inventory.GetValidInventory(item, half); //If cant take, find a valid one
            int           new_slot   = ninventory.GetFirstEmptySlot();

            ninventory.AddItemAt(item.id, new_slot, half, item_data.durability, UniqueID.GenerateUniqueID());
        }
예제 #18
0
        public override void DoAction(PlayerCharacter character, ItemSlot slot)
        {
            ItemData      item      = slot.GetItem();
            InventoryData inventory = slot.GetInventory();

            if (item != null && item.plant_data != null)
            {
                character.Crafting.CraftPlantBuildMode(item.plant_data, 0, false, (Buildable build) =>
                {
                    inventory.RemoveItemAt(slot.index, 1);
                });

                TheAudio.Get().PlaySFX("craft", item.craft_sound);
            }
        }
        public override void DoAction(PlayerCharacter character, ItemSlot slot)
        {
            foreach (CraftData data in learn_list)
            {
                character.Crafting.LearnCraft(data.id);
            }

            TheAudio.Get().PlaySFX("learn", learn_audio);

            InventoryData inventory = slot.GetInventory();

            if (destroy_on_learn)
            {
                inventory.RemoveItemAt(slot.index, 1);
            }

            CraftSubPanel.Get(character.player_id)?.RefreshCraftPanel();
        }