コード例 #1
0
    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);
        }
    }
コード例 #2
0
    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);
        }
    }
コード例 #3
0
    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);
        }

    }
コード例 #4
0
    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);
        }
    }
コード例 #5
0
    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;
    }
コード例 #6
0
    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);
    }
コード例 #7
0
    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);
    }
コード例 #8
0
    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;
    }