Example #1
0
    //use token?

    // public void OnStatsChanged(IinventoryState state, string path, Bolt.ArrayIndices indices)
    // {
    //     int index = indices[0];
    // }

    public void swapSlots(swapSlots evnt)
    {
        //step1: check if match
        //step2: check is stackable
        //step3: check if "to" is full, if full then just swap
        //check if they add up to beyond stack cap
        //if they not beyond cap, add to "to" and make "from" empty
        //otherwise add to "to" until full and subtrace from "from"

        if (state.items[evnt.to].ID == state.items[evnt.from].ID)
        {
            if (myInventory.lookUpID(state.items[evnt.to].ID).stackable)
            {
                if (myInventory.lookUpID(state.items[evnt.to].ID).stackSize > state.items[evnt.to].quantity)
                {
                    int moveQuanity = 0;
                    //how many item units are moving

                    int moveSpace = myInventory.lookUpID(state.items[evnt.to].ID).stackSize - state.items[evnt.to].quantity;
                    //how much room is available in "to"

                    int fromQuantity = state.items[evnt.from].quantity;

                    if (moveSpace >= fromQuantity)
                    {
                        moveQuanity = fromQuantity;
                    }
                    else
                    {
                        moveQuanity = moveSpace;
                    }

                    state.items[evnt.to].quantity   += moveQuanity;
                    state.items[evnt.from].quantity -= moveQuanity;

                    if (state.items[evnt.from].quantity == 0)
                    {
                        state.items[evnt.from].ID = 0;
                    }

                    return;
                }
            }
        }

        int oldItem = state.items[evnt.to].ID;

        state.items[evnt.to].ID   = state.items[evnt.from].ID;
        state.items[evnt.from].ID = oldItem;

        int oldQuantity = state.items[evnt.to].quantity;

        state.items[evnt.to].quantity   = state.items[evnt.from].quantity;
        state.items[evnt.from].quantity = oldQuantity;
    }
Example #2
0
 public override void OnEvent(swapSlots evnt)
 {
     PlayerController.swapSlots(evnt);
 }