public static ContainerAddState.ActionState MoveItem(ItemData movingItemData, ItemContainer lastContainer, ItemContainer targetContainer) { try { if (movingItemData == null) { throw new Exception("Can Not Move null item"); } if (targetContainer == null) { throw new Exception("Can not move item to null container"); } if (lastContainer != null) { Debug.Log(lastContainer.GetContainerRemoveState(movingItemData)); if (lastContainer.GetContainerRemoveState(movingItemData) == false) { return(ContainerAddState.ActionState.No); } } ContainerAddState targetAddState = targetContainer.GetContainerAddState(movingItemData); switch (targetAddState.actionState) { case ContainerAddState.ActionState.Add: ItemData newItemData = new ItemData(); newItemData.SetItemData(movingItemData); if (movingItemData.ownerContainer != null) { movingItemData.ownerContainer.Remove(movingItemData, true, targetAddState.possibleAddAmount); } targetContainer.Add(newItemData, targetAddState.possibleAddAmount); break; case ContainerAddState.ActionState.No: break; default: break; } return(targetAddState.actionState); } catch (Exception e) { Debug.LogError(e.Message); return(ContainerAddState.ActionState.No); } }
public static ContainerAddState.ActionState MoveItem(ItemData movingItemData, ItemContainer targetContainer) { try { if (movingItemData == null) { throw new Exception("Can Not Move null item"); } if (targetContainer == null) { throw new Exception("Can not move item to null container"); } ContainerAddState targetAddState = targetContainer.GetContainerAddState(movingItemData); switch (targetAddState.actionState) { case ContainerAddState.ActionState.Add: if (movingItemData.ownerContainer != null) { movingItemData.ownerContainer.Remove(movingItemData, true, targetAddState.possibleAddAmount); } targetContainer.Add(ItemConverter.ConvertItemDataToNGUIItemDataObject(movingItemData), targetAddState.possibleAddAmount); break; case ContainerAddState.ActionState.Swap: if (movingItemData.ownerContainer != null) { CheckSwapability(ItemConverter.ConvertItemDataToNGUIItemDataObject(movingItemData), targetContainer, targetAddState); } else { return(ContainerAddState.ActionState.No); } break; case ContainerAddState.ActionState.No: break; default: break; } return(targetAddState.actionState); } catch (Exception e) { Debug.Log(e.Message); return(ContainerAddState.ActionState.No); } }
private static void CheckSwapability(ItemData movingItemData, ItemContainer targetContainer, ContainerAddState possibleSwapState) { if (possibleSwapState.possibleSwapItem == null) return; movingItemData.ownerContainer.Remove(movingItemData, true, possibleSwapState.possibleAddAmount); ContainerAddState sourceAddState = movingItemData.ownerContainer.GetContainerAddState(possibleSwapState.possibleSwapItem); ItemContainer SourceContainer = movingItemData.ownerContainer; if (sourceAddState.actionState == ContainerAddState.ActionState.Add) { SourceContainer.Add(possibleSwapState.possibleSwapItem, -1); targetContainer.Remove(possibleSwapState.possibleSwapItem, true); targetContainer.Add(movingItemData, -1); return; } else { movingItemData.ownerContainer.Add(movingItemData, possibleSwapState.possibleAddAmount); } }
private static void CheckSwapability(ItemData movingItemData, ItemContainer targetContainer, ContainerAddState possibleSwapState) { if (possibleSwapState.possibleSwapItem == null) { return; } movingItemData.ownerContainer.Remove(movingItemData, true, possibleSwapState.possibleAddAmount); ContainerAddState sourceAddState = movingItemData.ownerContainer.GetContainerAddState(possibleSwapState.possibleSwapItem); ItemContainer SourceContainer = movingItemData.ownerContainer; if (sourceAddState.actionState == ContainerAddState.ActionState.Add) { SourceContainer.Add(possibleSwapState.possibleSwapItem, -1); targetContainer.Remove(possibleSwapState.possibleSwapItem, true); targetContainer.Add(movingItemData, -1); return; } else { movingItemData.ownerContainer.Add(movingItemData, possibleSwapState.possibleAddAmount); } }
protected override ContainerAddState MyContainerAddState(ItemData modified) { Dictionary<int, SlottedContainerSlotData> tmp = GetAllAvalibleSlots(modified); List<SlottedContainerSlotData> ShortList = tmp.Values.ToList<SlottedContainerSlotData>(); ContainerAddState state = new ContainerAddState(ContainerAddState.ActionState.No); ShortList.Sort((a, b) => a.priority.CompareTo(b.priority)); if (tmp.Count != 0) { bool Swaping = false; SlottedContainerSlotData firstStack = null; foreach (SlottedContainerSlotData SelectedSlots in tmp.Values)//Check for empty slots { if (SelectedSlots.slotData == null) { state = new ContainerAddState(ContainerAddState.ActionState.Add, (modified.stackSize < SelectedSlots.slotMaxCountLimit ? modified.stackSize : SelectedSlots.slotMaxCountLimit), null); return state; } else if (SelectedSlots.slotData.IsSameItemAs(modified) && SelectedSlots.slotData.stackSize < SelectedSlots.slotMaxCountLimit) { state = new ContainerAddState(ContainerAddState.ActionState.Add, SelectedSlots.slotMaxCountLimit - SelectedSlots.slotData.stackSize, null); return state; } else { Swaping = true; if (firstStack == null) { firstStack = SelectedSlots; } } } if (Swaping && firstStack != null) { if (isSwappable) state = new ContainerAddState(ContainerAddState.ActionState.Swap, firstStack.slotMaxCountLimit, firstStack.slotData); else state = new ContainerAddState(ContainerAddState.ActionState.No, firstStack.slotMaxCountLimit, firstStack.slotData); } } //foreach (KeyValuePair<int, SlottedContainerSlotData> sl in slots) //{ // if (sl.Value.validTypes.Contains(itemData.varianceID)) // { // if (sl.Value.slotData == null) // { // state = new ContainerAddState(ContainerAddState.ActionState.Add, sl.Value.slotMaxCountLimit, null); // } // else // { // state = new ContainerAddState(ContainerAddState.ActionState.Swap, sl.Value.slotMaxCountLimit, sl.Value.slotData); // } // } //} return state; }
protected override ContainerAddState MyContainerAddState(ItemData modified) { ContainerAddState currentAddableState = new ContainerAddState(ContainerAddState.ActionState.No, 0); if (containerItems.Count == containerMaxSize && !containerItems.Contains(modified)) { return(currentAddableState); //No room for this item. } //TODO max stack size to be properly retreived int maxStackSizePerSlot = -1; if (maxStackSizePerSlot == -1) { currentAddableState.actionState = ContainerAddState.ActionState.Add; currentAddableState.possibleAddAmount = modified.stackSize; return(currentAddableState); } int amountAvalibleInCurrentStacks = 0; foreach (ItemData itemIterator in containerItems) { if (itemIterator.varianceID == modified.varianceID) { amountAvalibleInCurrentStacks += maxStackSizePerSlot - itemIterator.stackSize; } } if (amountAvalibleInCurrentStacks >= modified.stackSize) { currentAddableState.actionState = ContainerAddState.ActionState.Add; currentAddableState.possibleAddAmount = modified.stackSize; return(currentAddableState); } int neededSpace = modified.stackSize - amountAvalibleInCurrentStacks; int PossibleEmpytSpace = (containerMaxSize - containerItems.Count) * maxStackSizePerSlot; if (modified.stackSize > amountAvalibleInCurrentStacks) { int numberOfSlotsNeededToFill = (int)Math.Ceiling(((float)modified.stackSize - ((float)maxStackSizePerSlot - (float)amountAvalibleInCurrentStacks)) / (float)maxStackSizePerSlot); if (neededSpace < PossibleEmpytSpace) { currentAddableState.possibleAddAmount = neededSpace + amountAvalibleInCurrentStacks; } else { currentAddableState.possibleAddAmount = PossibleEmpytSpace + amountAvalibleInCurrentStacks; } currentAddableState.actionState = ContainerAddState.ActionState.Add; } else { currentAddableState.actionState = ContainerAddState.ActionState.Add; currentAddableState.possibleAddAmount = modified.stackSize; } return(currentAddableState); }
protected override ContainerAddState MyContainerAddState(ItemData modified) { Dictionary <int, SlottedContainerSlotData> tmp = GetAllAvalibleSlots(modified); List <SlottedContainerSlotData> ShortList = tmp.Values.ToList <SlottedContainerSlotData>(); ContainerAddState state = new ContainerAddState(ContainerAddState.ActionState.No); ShortList.Sort((a, b) => a.priority.CompareTo(b.priority)); if (tmp.Count != 0) { bool Swaping = false; SlottedContainerSlotData firstStack = null; foreach (SlottedContainerSlotData SelectedSlots in tmp.Values)//Check for empty slots { if (SelectedSlots.slotData == null) { state = new ContainerAddState(ContainerAddState.ActionState.Add, (modified.stackSize < SelectedSlots.slotMaxCountLimit ? modified.stackSize : SelectedSlots.slotMaxCountLimit), null); return(state); } else if (SelectedSlots.slotData.IsSameItemAs(modified) && SelectedSlots.slotData.stackSize < SelectedSlots.slotMaxCountLimit) { state = new ContainerAddState(ContainerAddState.ActionState.Add, SelectedSlots.slotMaxCountLimit - SelectedSlots.slotData.stackSize, null); return(state); } else { Swaping = true; if (firstStack == null) { firstStack = SelectedSlots; } } } if (Swaping && firstStack != null) { if (isSwappable) { state = new ContainerAddState(ContainerAddState.ActionState.Swap, firstStack.slotMaxCountLimit, firstStack.slotData); } else { state = new ContainerAddState(ContainerAddState.ActionState.No, firstStack.slotMaxCountLimit, firstStack.slotData); } } } //foreach (KeyValuePair<int, SlottedContainerSlotData> sl in slots) //{ // if (sl.Value.validTypes.Contains(itemData.varianceID)) // { // if (sl.Value.slotData == null) // { // state = new ContainerAddState(ContainerAddState.ActionState.Add, sl.Value.slotMaxCountLimit, null); // } // else // { // state = new ContainerAddState(ContainerAddState.ActionState.Swap, sl.Value.slotMaxCountLimit, sl.Value.slotData); // } // } //} return(state); }
protected override ContainerAddState MyContainerAddState(ItemData modified) { ContainerAddState currentAddableState = new ContainerAddState(ContainerAddState.ActionState.No, 0); if (containerItems.Count == containerMaxSize && !containerItems.Contains(modified)) { return currentAddableState; //No room for this item. } //TODO max stack size to be properly retreived int maxStackSizePerSlot = -1; if (maxStackSizePerSlot == -1) { currentAddableState.actionState = ContainerAddState.ActionState.Add; currentAddableState.possibleAddAmount = modified.stackSize; return currentAddableState; } int amountAvalibleInCurrentStacks = 0; foreach (ItemData itemIterator in containerItems) { if (itemIterator.varianceID == modified.varianceID) { amountAvalibleInCurrentStacks += maxStackSizePerSlot - itemIterator.stackSize; } } if (amountAvalibleInCurrentStacks >= modified.stackSize) { currentAddableState.actionState = ContainerAddState.ActionState.Add; currentAddableState.possibleAddAmount = modified.stackSize; return currentAddableState; } int neededSpace = modified.stackSize - amountAvalibleInCurrentStacks; int PossibleEmpytSpace = (containerMaxSize - containerItems.Count) * maxStackSizePerSlot; if (modified.stackSize > amountAvalibleInCurrentStacks) { int numberOfSlotsNeededToFill = (int)Math.Ceiling(((float)modified.stackSize - ((float)maxStackSizePerSlot - (float)amountAvalibleInCurrentStacks)) / (float)maxStackSizePerSlot); if (neededSpace < PossibleEmpytSpace) { currentAddableState.possibleAddAmount = neededSpace + amountAvalibleInCurrentStacks; } else { currentAddableState.possibleAddAmount = PossibleEmpytSpace + amountAvalibleInCurrentStacks; } currentAddableState.actionState = ContainerAddState.ActionState.Add; } else { currentAddableState.actionState = ContainerAddState.ActionState.Add; currentAddableState.possibleAddAmount = modified.stackSize; } return currentAddableState; }