public static int tryMoveItems(Inv inv, int IndexFrom, int IndexTo) { log("tryMoveItems"); InvItem foundItem = null; InvItem foundItem1 = null; try { foundItem = inv.items.Find(i => i.Index == IndexFrom); foundItem1 = inv.items.Find(i => i.Index == IndexTo); } catch (Exception e) { log(e.Message); return(-1); } return(0); }
public static int tryGetItems(List <InvItem> items, String name, int current) { log("tryGetItems"); InvItem foundItem = null; try { foundItem = items?.First <InvItem>(i => i.Name == name && i.Current >= current); } catch (Exception e) { log(e.Message); } if (foundItem == null) { return(-1); } return(0); }
public static int AddItems(List <InvItem> items, bool AllItems, bool ExceedMaxItems, int LastIndex, String name, int prefIndex, int current, int MaxIndex, int max = 99) { log("AddItems"); InvItem foundItem = null; try { foundItem = items?.First <InvItem>(i => i.Name == name && i.Current < i.Max && (prefIndex == -1 || i.Index == prefIndex)); } catch (Exception e) { log(e.Message); } if (foundItem == null && AllItems) { LastIndex = LastIndex + 1; if (LastIndex <= MaxIndex) { items.Add(new InvItem(name, LastIndex, current, max)); } else { return(-1); } return(1); } else { foundItem.Current = foundItem.Current + current; if (foundItem.Current > foundItem.Max) { var currentVal = foundItem.Current - foundItem.Max; foundItem.Current = foundItem.Max; if (ExceedMaxItems) { LastIndex = LastIndex + 1; if (LastIndex <= MaxIndex) { items.Add(new InvItem(name, LastIndex, currentVal, max)); } else { return(-2); } } return(2); } } return(0); }