public int GetFirstEmptySlot() { for (int i = 0; i < size; i++) { InventoryItemData invdata = GetItem(i); if (invdata == null || invdata.quantity <= 0) { return(i); } } return(-1); }
public void UpdateAllEquippedItemsDurability(bool weapon, float value) { //Durability foreach (KeyValuePair <int, InventoryItemData> pair in EquipData.items) { InventoryItemData invdata = pair.Value; ItemData idata = ItemData.Get(invdata?.item_id); if (idata != null && invdata != null && idata.IsWeapon() == weapon && idata.durability_type == DurabilityType.UsageCount) { invdata.durability += value; } } }
public void RemoveEquipItem(EquipSlot eslot) { InventoryItemData invtem = EquipData.GetEquippedItem(eslot); ItemData idata = ItemData.Get(invtem?.item_id); if (idata != null) { EquipData.UnequipItem(eslot); if (idata.container_data) { EquipData.EquipItem(eslot, idata.container_data.id, idata.container_data.durability, UniqueID.GenerateUniqueID()); } } }
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 void UnequipItem(EquipSlot eslot) { InventoryItemData invdata = EquipData.GetEquippedItem(eslot); if (invdata != null && InventoryData.CanTakeItem(invdata.item_id, 1)) { EquipData.UnequipItem(eslot); InventoryData.AddItem(invdata.item_id, 1, invdata.durability, invdata.uid); } else if (invdata != null && BagData != null && BagData.CanTakeItem(invdata.item_id, 1)) { EquipData.UnequipItem(eslot); BagData.AddItem(invdata.item_id, 1, invdata.durability, invdata.uid); } }
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()); }
//Return the best equipped bag (bag is an item that can contain other items) public InventoryItemData GetBestEquippedBag() { int best_size = 0; InventoryItemData bag = null; foreach (KeyValuePair <int, InventoryItemData> invdata in EquipData.items) { ItemData idata = invdata.Value?.GetItem(); if (idata != null && idata.bag_size > best_size && !string.IsNullOrEmpty(invdata.Value.uid)) { best_size = idata.bag_size; bag = invdata.Value; } } return(bag); }
public void AddItemAt(string item_id, int slot, int quantity, float durability, string uid) { if (!string.IsNullOrEmpty(item_id) && slot >= 0 && quantity > 0) { InventoryItemData invt_slot = GetItem(slot); if (invt_slot != null && invt_slot.item_id == item_id) { int amount = invt_slot.quantity + quantity; float durabi = ((invt_slot.durability * invt_slot.quantity) + (durability * quantity)) / (float)amount; items[slot] = new InventoryItemData(item_id, amount, durabi, uid); } else if (invt_slot == null || invt_slot.quantity <= 0) { items[slot] = new InventoryItemData(item_id, quantity, durability, uid); } } }
//Get the EquipItem (spawned model for equipment items) public EquipItem GetEquippedItemMesh(EquipSlot slot) { InventoryItemData invdata = EquipData.GetEquippedItem(slot); ItemData equipped = ItemData.Get(invdata?.item_id); if (equipped != null) { foreach (KeyValuePair <string, EquipItem> item in equipped_items) { if (item.Key == equipped.id) { return(item.Value); } } } return(null); }
public void SwapItemSlots(int slot1, int slot2) { InventoryItemData invt_slot1 = GetItem(slot1); InventoryItemData invt_slot2 = GetItem(slot2); items[slot1] = invt_slot2; items[slot2] = invt_slot1; if (invt_slot2 == null) { items.Remove(slot1); } if (invt_slot1 == null) { items.Remove(slot2); } }
// ---- Multi-inventory Items ----- public void SwapInventoryItems(InventoryData inventory1, int slot1, InventoryData inventory2, int slot2) { InventoryItemData invt_slot1 = inventory1.GetItem(slot1); InventoryItemData invt_slot2 = inventory2.GetItem(slot2); inventory1.items[slot1] = invt_slot2; inventory2.items[slot2] = invt_slot1; if (invt_slot2 == null) { inventory1.items.Remove(slot1); } if (invt_slot1 == null) { inventory2.items.Remove(slot2); } }
public void RemoveItemAt(int slot, int quantity) { if (slot >= 0 && quantity >= 0) { InventoryItemData invt_slot = GetItem(slot); if (invt_slot != null && invt_slot.quantity > 0) { int amount = invt_slot.quantity - quantity; if (amount <= 0) { items.Remove(slot); } else { items[slot] = new InventoryItemData(invt_slot.item_id, amount, invt_slot.durability, invt_slot.uid); } } } }
public override void DoAction(PlayerCharacter character, Selectable select) { DigSpot spot = select.GetComponent <DigSpot>(); if (spot != null) { string animation = character.Animation ? character.Animation.dig_anim : ""; character.TriggerAnim(animation, spot.transform.position); character.TriggerProgressAction(1.5f, () => { spot.Dig(); InventoryItemData ivdata = character.EquipData.GetFirstItemInGroup(required_item); if (ivdata != null) { ivdata.durability -= 1; } }); } }
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(); } }
public void UpdateAllDurability(float game_speed) { List <int> remove_items = new List <int>(); foreach (KeyValuePair <int, InventoryItemData> pair in items) { InventoryItemData invdata = pair.Value; ItemData idata = ItemData.Get(invdata?.item_id); if (idata != null && invdata != null) { if (idata.durability_type == DurabilityType.Spoilage) { invdata.durability -= game_speed * Time.deltaTime; } if (idata.durability_type == DurabilityType.UsageTime && type == InventoryType.Equipment) { invdata.durability -= game_speed * Time.deltaTime; } } if (idata != null && invdata != null && idata.HasDurability() && invdata.durability <= 0f) { remove_items.Add(pair.Key); } } foreach (int slot in remove_items) { InventoryItemData invdata = GetItem(slot); ItemData idata = ItemData.Get(invdata?.item_id); RemoveItemAt(slot, invdata.quantity); if (idata.container_data) { AddItemAt(idata.container_data.id, slot, invdata.quantity, idata.container_data.durability, UniqueID.GenerateUniqueID()); } } remove_items.Clear(); }
void Update() { ItemSlotPanel panel = ItemSlotPanel.Get(inventory_target); if (panel != null) { Vector3 wPos = panel.GetSlotWorldPosition(slot_target); DoMoveToward(wPos); InventoryData inventory = panel.GetInventory(); InventoryItemData islot = inventory?.GetItem(slot_target); if (islot == null || islot.GetItem() == null) { Destroy(gameObject); } } timer += Time.deltaTime; if (timer > 2f) { Destroy(gameObject); } }
protected override void RefreshPanel() { base.RefreshPanel(); InventoryData inventory = GetInventory(); if (inventory != null) { for (int i = 0; i < slots.Length; i++) { InventoryItemData invdata = inventory.GetItem(i); ItemData idata = ItemData.Get(invdata?.item_id); ItemSlot slot = (ItemSlot)slots[i]; if (invdata != null && idata != null) { slot.SetSlot(idata, invdata.quantity, selected_slot == slot.index || selected_right_slot == slot.index); slot.SetDurability(idata.GetDurabilityPercent(invdata.durability), ShouldShowDurability(idata, invdata.durability)); slot.SetFilter(GetFilterLevel(idata, invdata.durability)); } else if (i < inventory_size) { slot.SetSlot(null, 0, false); } else { slot.Hide(); } } ItemSlot sslot = GetSelectedSlot(); if (sslot != null && sslot.GetItem() == null) { CancelSelection(); } } }
public ItemData GetEquippedItemData(EquipSlot equip_slot) { InventoryItemData idata = GetEquippedItem(equip_slot); return(idata?.GetItem()); }
public ItemData GetItemData(int slot) { InventoryItemData idata = GetItem(slot); return(idata?.GetItem()); }
public ItemData GetEquippedWeaponData() { InventoryItemData idata = GetEquippedWeapon(); return(idata?.GetItem()); }
protected override void Update() { base.Update(); PlayerCharacter character = GetPlayer(); int gold = (character != null) ? character.Data.gold : 0; if (gold_value != null) { gold_value.text = gold.ToString(); } //Init inventories from here because they are disabled foreach (ItemSlotPanel panel in item_slot_panels) { panel.InitPanel(); } //Fx visibility damage_fx_timer += Time.deltaTime; if (build_mode_text != null) { build_mode_text.enabled = IsBuildMode(); } if (tps_cursor != null) { tps_cursor.enabled = TheCamera.Get().IsLocked(); } if (character != null && !character.IsDead() && character.Attributes.IsDepletingHP()) { DoDamageFXInterval(); } //Cold FX if (character != null && !character.IsDead()) { PlayerCharacterHeat characterHeat = PlayerCharacterHeat.Get(character.player_id); if (cold_fx != null && characterHeat != null) { cold_fx.SetVisible(characterHeat.IsCold()); } if (damage_fx != null && characterHeat != null && characterHeat.IsColdDamage()) { DoDamageFXInterval(); } } //Controls PlayerControls controls = PlayerControls.Get(player_id); if (controls.IsPressCraft()) { CraftPanel.Get(player_id)?.Toggle(); ActionSelectorUI.Get(player_id)?.Hide(); ActionSelector.Get(player_id)?.Hide(); } //Backpack panel BagPanel bag_panel = BagPanel.Get(player_id); if (character != null && bag_panel != null) { InventoryItemData item = character.Inventory.GetBestEquippedBag(); ItemData idata = ItemData.Get(item?.item_id); if (idata != null) { bag_panel.ShowBag(character, item.uid, idata.bag_size); } else { bag_panel.HideBag(); } } }