private int AddNewItemEntry(ItemEntry itemEntry) { if (itemEntry.Count > itemEntry.ItemData.MaxCount) { itemEntry.Count = itemEntry.ItemData.MaxCount; } if (this.Count < this.maxSlots) { this.items.Add(itemEntry); return(itemEntry.Count); } // Inventory slots already maxed out. return(0); }
public void ConsumeItem(int index, int amount = 1) { ItemEntry item = this.items[index]; item.Count -= amount; if (this.onItemRemoval != null) { this.onItemRemoval.Invoke(item); } if (item.Count < 1) { this.items.RemoveAt(index); } }
private void SwapWeaponPrefab(ItemEntry item) { if (this.equippedWeapon != null) { PoolManager.Despawn(this.equippedWeapon.gameObject); } GameObject weaponObject = PoolManager.Spawn(item.ItemData.EquipPrefab); Pool weaponPool = PoolManager.GetPool(weaponObject); weaponPool.transform.SetParent(this.attackOrigin); weaponPool.transform.localPosition = Vector3.zero; weaponObject.transform.localPosition = Vector3.zero; Weapon weapon = weaponObject.GetComponent <Weapon>(); this.equippedWeapon = weapon; }
private void SwapItemPrefab(ItemEntry item) { if (this.equippedItem != null) { PoolManager.Despawn(this.equippedItem.gameObject); } GameObject itemObject = PoolManager.Spawn(item.ItemData.EquipPrefab); Pool itemPool = PoolManager.GetPool(itemObject); itemPool.transform.SetParent(this.useItemOrigin); itemPool.transform.localPosition = Vector3.zero; itemObject.transform.localPosition = Vector3.zero; UsableItem usableItem = itemObject.GetComponent <UsableItem>(); this.equippedItem = usableItem; }
public bool AcquireItem(ItemData itemData, int amount) { if (this.locked) { return(false); } ItemEntry existingEntry = this[itemData]; int collected = 0; if (existingEntry != null) { collected = IncreaseItemCount(existingEntry, amount); } else { existingEntry = new ItemEntry() { ItemData = itemData, Count = amount }; collected = AddNewItemEntry(existingEntry); } if (collected > 0) { if (!this.discoveredItems.Contains(itemData)) { this.discoveredItems.Add(itemData); } if (this.onItemPickup != null) { this.onItemPickup.Invoke(existingEntry); } return(true); } return(false); }
public static ItemPickup CreateFromItemEntry(ItemEntry itemEntry) { if (poolObject == null) { Debug.Log("Creating ItemPickup blueprint."); poolObject = new GameObject("Item Pickup"); poolObject.AddComponent<SpriteRenderer>(); poolObject.AddComponent<CameraVisibleTrigger>(); poolObject.SetupRigidbody(); poolObject.AddComponent<ItemPickup>(); poolObject.SetActive(false); } GameObject itemPickupObject = PoolManager.Spawn(poolObject); ItemPickup itemPickup = itemPickupObject.GetComponent<ItemPickup>(); itemPickup.item = itemEntry; itemPickup.SpriteRenderer.sprite = itemEntry.ItemData.Icon; Destroy(itemPickupObject.GetComponent<Collider2D>()); BoxCollider2D collider = itemPickupObject.AddComponent<BoxCollider2D>(); collider.isTrigger = true; return itemPickup; }
public bool AcquireItem(ItemEntry itemEntry) { return(AcquireItem(itemEntry.ItemData, itemEntry.Count)); }
public bool Contains(ItemEntry itemEntry) { return(Contains(itemEntry.ItemData, itemEntry.Count)); }
public void ConsumeItem(ItemEntry itemEntry) { ConsumeItem(itemEntry.ItemData, itemEntry.Count); }