/// <summary> /// Compares two Items to check if they are both stacks and identical /// </summary> /// <param name="item">The original Item</param> /// <param name="comparer">The item to compare against</param> /// <returns>True if both Items are stacks and the same</returns> public static Boolean IsStackAndSame(this ItemBase item, ItemBase comparer) { if (!item.IsStack() || !comparer.IsStack()) { return(false); } return(item.As <ItemCubeStack>().Compare(comparer.As <ItemCubeStack>()) || item.As <ItemStack>().Compare(item.As <ItemStack>())); }
/// <summary> /// Gets the amount of items in an ItemBase, while being Stack friendly /// </summary> /// <param name="item">The original</param> /// <returns>The amount of items</returns> public static Int32 GetAmount(this ItemBase item) { switch (item.mType) { case ItemType.ItemCubeStack: return(item.As <ItemCubeStack>().mnAmount); // If it is original type of ItemCubeStack, it shouldn't be null case ItemType.ItemStack: return(item.As <ItemStack>().mnAmount); // Read above note default: return(1); // All other original types can only have 1 original } }
/// <summary> /// Decrement the Stack Size by the specified amount /// </summary> /// <param name="item">The Item Stack</param> /// <param name="amount">The amount to increment by (Default: 1)</param> public static void DecrementStack(this ItemBase item, Int32 amount = 1) { if (!item.IsStack()) { return; } if (item.mType == ItemType.ItemCubeStack) { item.As <ItemCubeStack>().mnAmount -= amount; } if (item.mType == ItemType.ItemStack) { item.As <ItemStack>().mnAmount -= amount; } }
/// <summary> /// Set the amount of items in original Item Stack /// </summary> /// <param name="item">The Item Stack</param> /// <param name="amount">The amount of Items</param> public static ItemBase SetAmount(this ItemBase item, Int32 amount) { if (!item.IsStack()) { return(item); } if (item.mType == ItemType.ItemCubeStack) { item.As <ItemCubeStack>().mnAmount = amount; } if (item.mType == ItemType.ItemStack) { item.As <ItemStack>().mnAmount = amount; } return(item); }
/// <summary> /// Gets the amount of cubes OR items from any Enumerable ItemBase, based off of an ItemBase /// </summary> /// <param name="items">The list of items to get the total count from</param> /// <param name="restraints">The ItemBase which to restrain the Count to</param> /// <returns>The amount of Cubes or Items</returns> public static Int32 GetItemCount(this IEnumerable <ItemBase> items, ItemBase restraints) { if (restraints.mType != ItemType.ItemCubeStack) { return(items.GetItemCount(restraints.mnItemID)); } var cube = restraints.As <ItemCubeStack>(); return(items.GetItemCount(cube.mCubeType, cube.mCubeValue)); }
/// <summary> /// Compares all possible /// </summary> /// <param name="original">The original ItemBase</param> /// <param name="comparer">The ItemBase to Compare Against</param> /// <returns>True if all major properties match</returns> public static Boolean CompareDeep(this ItemBase original, ItemBase comparer) { return(original.Compare(comparer) && ( original.As <ItemCubeStack>().Compare(comparer.As <ItemCubeStack>()) || original.As <ItemDurability>().Compare(comparer.As <ItemDurability>()) || original.As <ItemStack>().Compare(comparer.As <ItemStack>()) || original.As <ItemSingle>().Compare(comparer.As <ItemSingle>()) || original.As <ItemCharge>().Compare(comparer.As <ItemCharge>()) || original.As <ItemLocation>().Compare(comparer.As <ItemLocation>()) )); }
public Boolean HasItems(SegmentEntity entity, ItemBase item, out Int32 amount) { var hopper = entity.As <StorageHopper>(); var isCube = item.mType == ItemType.ItemCubeStack; ItemCubeStack cube = null; if (isCube) { cube = item.As <ItemCubeStack>(); } amount = !isCube?hopper.CountHowManyOfItem(item.mnItemID) : hopper.CountHowManyOfType(cube.mCubeType, cube.mCubeValue); return(amount > 0); }
public ItemBase TakeItem(SegmentEntity entity, ItemBase item) { var hopper = entity.As <StorageHopper>(); var isCube = item.mType == ItemType.ItemCubeStack; ItemCubeStack cube = null; if (isCube) { cube = item.As <ItemCubeStack>(); } if (!isCube) { return(hopper.RemoveSingleSpecificItemByID(item.mnItemID)); } return(hopper.RemoveSingleSpecificCubeStack(cube)); }
public Boolean GiveItem(SegmentEntity entity, ItemBase item) { var hopper = entity.As <StorageHopper>(); var isCube = item.mType == ItemType.ItemCubeStack; ItemCubeStack cube = null; if (isCube) { cube = item.As <ItemCubeStack>(); } if (!isCube) { return(hopper.AddItem(item)); } // Might be possible to replace with ^ as universal for Item/Cubes var currentStorage = hopper.mnStorageFree; hopper.AddCube(cube.mCubeType, cube.mCubeValue); return(currentStorage != hopper.mnStorageFree); }