public EquipmentItem(EquipmentBlueprint a_blue, CraftingMaterial a_craft) { blueprint = a_blue; material = a_craft; CraftUpdate(); itemType = ItemType.Equipable; stackSize = 1; useable = true; consumable = false; }
bool AddEquipmentToSlot(EquipmentBlueprint SlotItem) { // display equipment to slot try { SlotIcon.sprite = SlotItem.ItemIcon; SlotIcon.enabled = true; UnEquipButton.interactable = true; } catch (System.Exception) { return(false); throw; } return(true); }
public void UnEquip(int SlotIndex) { // Try adding equipment item to inventory if (Inventory.InventoryInstance.InventorySlots > Inventory.InventoryInstance.InventoryItems.Count) { EquipmentBlueprint ItemToUnequip = Equipment.EquipmentInstance.equipmentSlot[SlotIndex]; Inventory.InventoryInstance.AddToInventory(ItemToUnequip); // remove trait values of the equipment to the player stat RemoveTraitsFromPlayer(ItemToUnequip); if (CallEquipmentUpdated != null) // Fixed: items are being deleted when you have more than one equipped item and then click unequip { CallEquipmentUpdated.Invoke(ItemToUnequip, false); } equipmentSlot[SlotIndex] = null; } else { Debug.LogError("ERROR - EquipmentInventory: Item can not be unequip, no space in inventory!"); } }
// Update is called once per frame void UpdateEquipment_UI(EquipmentBlueprint Item, bool AddorRemove) { if (AddorRemove == true) { if ((int)Item.EquipSlot == (int)equipmentType && AddEquipmentToSlot(Item) == true) { Debug.Log("DEBUG - EquipmentInventory: Update equipment UI: " + Item.ItemName); } } else if (AddorRemove == false) { for (int i = 0; i < Enum.GetNames(typeof(EquipmentType)).Length; i++) { if (i == (int)Item.EquipSlot && RemoveEquipmentFromSlot(i) == true) { Debug.Log("DEBUG - EquipmentInventory: Equipment slot " + i + " unequiped"); } } } else { Debug.LogError("ERROR - EquipmentInventory: UpdateEquipment_UI has an invalid action index!"); } }
public void Equip(EquipmentBlueprint Item) { int SlotIndex = (int)Item.EquipSlot; // get equipment currently in use EquipmentBlueprint oldEquipment; // Swap new equipment with old if (equipmentSlot[SlotIndex] != null) { oldEquipment = equipmentSlot[SlotIndex]; Inventory.InventoryInstance.AddToInventory(oldEquipment); } equipmentSlot[SlotIndex] = Item; // apply the trait values of the equipment to the player stat ApplyTraitsToPlayer(Item); if (CallEquipmentUpdated != null) { CallEquipmentUpdated.Invoke(Item, true); } }
public SavedData(AllCharacterStats characterStats, Inventory inventory) { // player position/rotation position = new float[3]; position[0] = characterStats.transform.position.x; position[1] = characterStats.transform.position.y; position[2] = characterStats.transform.position.z; rotation = new float[4]; rotation[0] = characterStats.transform.rotation.x; rotation[1] = characterStats.transform.rotation.y; rotation[2] = characterStats.transform.rotation.z; rotation[3] = characterStats.transform.rotation.w; // player stats balance = characterStats.Balance; health = characterStats.Health; protection = characterStats.Protection; speed = characterStats.Speed; damage = characterStats.Damage; // player inventory inventorySlots = inventory.InventoryItems.Count; inventoryItems = new List <InventoryItem>(); inventoryEquipment = new List <InventoryEquipment>(); for (int i = 0; i < inventorySlots; i++) { Debug.Log("checking inventory slot at index" + i); if (inventory.GetInventory()[i] != null) { Debug.Log("found item at index " + i); if (inventory.GetInventory()[i].item is EquipmentBlueprint) { InventoryEquipment item = new InventoryEquipment(); EquipmentBlueprint equipBP = inventory.GetInventory()[i].item.equipBP; EquipmentSlots equipmentSlots = equipBP.EquipSlot; item.EquipSlot = equipmentSlots; List <Positives> positives = new List <Positives>(); for (int j = 0; j < equipBP.PositiveTraits.Count; j++) { Positives posTrait = new Positives(); posTrait.traitLevel = equipBP.PositiveTraits[j].traitLevel; posTrait.traits = equipBP.PositiveTraits[j].traits; positives.Add(posTrait); } List <Negatives> negatives = new List <Negatives>(); for (int j = 0; j < equipBP.NegativeTraits.Count; j++) { Negatives negTrait = new Negatives(); negTrait.traitLevel = equipBP.NegativeTraits[j].traitLevel; negTrait.traits = equipBP.NegativeTraits[j].traits; negatives.Add(negTrait); } item.ItemName = equipBP.ItemName; Texture2D tex = equipBP.ItemIcon.texture; exportObj.x = tex.width; exportObj.y = tex.height; exportObj.bytes = ImageConversion.EncodeToPNG(tex); string icon = JsonUtility.ToJson(exportObj, false); item.ItemIcon = icon; item.isDefault = equipBP.isDefault; item.StackUntil = equipBP.StackUntil; item.Bundle = equipBP.Bundle; item.AssetName = equipBP.AssetName; item.ItemDescription = equipBP.ItemDescription; inventoryEquipment.Add(item); } else { InventoryItem item = new InventoryItem(); ItemBlueprint itemBP = inventory.GetInventory()[i].item; item.ItemName = itemBP.ItemName; Texture2D tex = itemBP.ItemIcon.texture; exportObj.x = tex.width; exportObj.y = tex.height; exportObj.bytes = ImageConversion.EncodeToPNG(tex); string icon = JsonUtility.ToJson(exportObj, false); item.ItemIcon = icon; item.isDefault = itemBP.isDefault; item.StackUntil = itemBP.StackUntil; item.Bundle = itemBP.Bundle; item.AssetName = itemBP.AssetName; item.ItemDescription = itemBP.ItemDescription; inventoryItems.Add(item); } } } }