Exemple #1
0
        //craft an item
        public Boolean craftItem(Item it)
        {
            Item newItem = new Item(it.getItemID());

            if (it.getItemID() == 0)
            {
                Console.WriteLine("Cannot pick item [item has wrong id]");
                return(false);
            }

            int     line      = 0;
            int     row       = 0;
            int     i         = 0;
            Boolean noMoreSeq = false;

            //move through seq to search stack
            while (noMoreSeq == false && i < 240)
            {
                if (seq[i] != -1)
                {
                    Item item = inv[seq[i]];
                    if (item == null)
                    {
                        Console.WriteLine("Cannot pick item [item in inv missing]");
                        return(false);
                    }
                    if (item.getItemID() == it.getItemID() && item.getQuantity() + newItem.getQuantity() <= ItemDataCache.Instance.getItemData(item.getItemID()).getMaxStack())
                    {
                        //stack
                        item.setQuantity((short)(item.getQuantity() + newItem.getQuantity()));
                        return(true);
                    }
                }
                else
                {
                    noMoreSeq = true;
                }
                i++;
            }

            //move through all lines and rows until free slot is found
            while (row < pages * 5)
            {
                if (line == 8)
                {
                    line = 0;
                }
                while (line < 8)
                {
                    if (addItem(line, row, newItem))
                    {
                        return(true);
                    }
                    line++;
                }
                row++;
            }
            Console.WriteLine("Cannot pick item [no free space in inv]");
            return(true);
        }
Exemple #2
0
        //remove from stack
        public Boolean removeItem(int invID, int amount)
        {
            int hash = seq[invID];

            if (hash == -1)
            {
                Console.WriteLine("Cannot remove item [item index missing]");
                return(false);
            }
            Item item = inv[hash];

            if (item == null)
            {
                Console.WriteLine("Cannot remove item [item missing]");
                return(false);
            }
            if (amount < item.getQuantity())
            {
                item.setQuantity((short)(item.getQuantity() - amount));
                return(true);
            }
            else
            {
                removeItem(invID);
                return(true);
            }
        }
Exemple #3
0
        public Boolean decrementItem(int seqIndex, int newQuantity)
        {
            updateInv();
            if (seqIndex < 0)
            {
                Console.WriteLine("Cannot decrement item [illegal index]");
                return(false);
            }

            if (seq.ElementAt(seqIndex) == -1)
            {
                Console.WriteLine("Cannot decrement item [missing item]");
                return(false);
            }

            if (!inv.ContainsKey(seq.ElementAt(seqIndex)))
            {
                Console.WriteLine("decrement > inv doesn't contain a key");
                return(false);
            }

            Item item = inv[(seq.ElementAt(seqIndex))];

            if (item == null)
            {
                Console.WriteLine("Cannot decrement item [missing item]");
                return(false);
            }

            if (item.getQuantity() == 0)
            {
                Console.WriteLine("Cannot decrement item [item amount is 0]");
                return(false);
            }

            item.setQuantity((short)newQuantity);

            if (item.getQuantity() == 0)
            {
                removeItemFromInv(seq.ElementAt(seqIndex));
                seq[seqIndex] = -1;
            }
            saveInv();
            return(true);
        }
Exemple #4
0
        //move item in inventory
        public Boolean moveItem(int fromInvID, int toInvID, int amount, int line, int row)
        {
            updateInv();

            //equipping uses toInvID as fromInvID what the hell and mysterious things when swapped
            if(equipping == true)
            {
                int seq8 = seq.IndexOf(8);
                if(seq8 == -1)
                    fromInvID = toInvID;
                else
                    fromInvID = seq8;
            }

            //index must exist
            if(indexHold == -1 && fromInvID >= 0 && seq[fromInvID] == -1)
            {
                Console.WriteLine("Cannot move item [item missing]");
                return false;
            }

            //get item1
            Item itemF;
            if(indexHold == -1)
                itemF = inv[seq[fromInvID]];
            else
                itemF = holdingItem;

            //there must be item1
            if(itemF == null)
            {
                Console.WriteLine("Cannot move item [item null(ghost)]");
                return false;
            }

            //wrong amount
            if(amount > itemF.getQuantity() || amount == 0)
            {
                Console.WriteLine("Cannot move item [item amount not sync]");
                return false;
            }
            if(amount > 10000)
            {
                Console.WriteLine("Cannot move item [amount is >10000]");
                return false;
            }

            //get the hashes from all blocking items
            List<int> hash = this.checkBlockingItems(line, row, itemF);

            //exception in checkBlockingItems
            if(hash == null)
            {
                Console.WriteLine("Cannot move item [crosses inventory border]");
                return false;
            }

            //move to an empty slot
            if(hash.Count == 0)
            {
                //SWAPPED BEFORE
                if(indexHold != -1)
                {
                    putIntoInv(line, row, holdingItem);
                    seq[indexHold] = seq[indexToSwap];
                    seq[indexToSwap] = -1;
                    seq[nextFreeSequence()] = (row * 100) + line;
                    indexHold = -1;
                    //NOT SWAPPED BEFORE
                }
                else
                {
                    itemF.setQuantity((short)(itemF.getQuantity() - amount));
                    if(itemF.getQuantity() == 0)
                    {
                        removeItemFromInv(seq[fromInvID]);
                        seq[fromInvID] = (row * 100) + line;
                    }
                    else
                    {
                        int nfs = nextFreeSequence();
                        if(nfs != -1)
                        {
                            seq[nextFreeSequence()] = (row * 100) + line;
                        }
                        else
                        {
                            Console.WriteLine("Cannot move item [no free space in inv]");
                            return false;
                        }
                    }

                    Item newItemF = new Item(itemF.getItemID());
                    newItemF.setQuantity((short)amount);
                    putIntoInv(line, row, newItemF);

                    equipping = false;
                }
                saveInv();
                return true;
            }

            if(hash.Count == 1)
            {
                if(seq.IndexOf(hash[0]) != -1)
                {
                    //SWAPPED BEFORE
                    if(indexHold != -1)
                    {
                        //swap indexes first
                        int saveSwapHash = seq[indexToSwap];
                        seq[indexToSwap] = -1;
                        seq[nextFreeSequence()] = seq[indexHold];
                        seq[indexHold] = saveSwapHash;
                        indexHold = indexToSwap;

                        holdingItem = inv[hash[0]];
                        if(holdingItem.getItemID() == itemF.getItemID() && holdingItem.getQuantity() + amount <= ItemDataCache.Instance.getItemData(itemF.getItemID()).getMaxStack())
                        {
                            holdingItem.setQuantity((short)(holdingItem.getQuantity() + amount));
                            indexHold = -1;
                        }
                        else
                        {
                            //do not allow bigger stacks than maxstack
                            if(holdingItem.getItemID() == itemF.getItemID() && holdingItem.getQuantity() + amount > ItemDataCache.Instance.getItemData(itemF.getItemID()).getMaxStack())
                            {
                                Console.WriteLine("Cannot move item [stack too big]");
                                return false;
                            }
                            if(removeItemFromInv(hash[0]) == false)
                            {
                                Console.WriteLine("Cannot move item [swapped item error]");
                                return false;
                            }
                            putIntoInv(line, row, itemF);
                            int saveIndexHold = indexHold;
                            indexToSwap = indexHold;
                            indexHold = seq.IndexOf(hash[0]);
                            if(indexHold == -1)
                            {
                                Console.WriteLine("Cannot move item [item missing]");
                                return false;
                            }
                            seq[saveIndexHold] = (row * 100) + line;
                            seq[indexHold] = -1;
                        }
                        //NOT SWAPPED BEFORE
                    }
                    else
                    {
                        Item itemTo = inv[hash[0]];
                        if(itemTo.getItemID() == itemF.getItemID() && itemTo.getQuantity() + amount <= ItemDataCache.Instance.getItemData(itemTo.getItemID()).getMaxStack())
                        {
                            itemF.setQuantity((short)(itemF.getQuantity() - amount));
                            if(itemF.getQuantity() == 0)
                            {
                                removeItemFromInv(seq[fromInvID]);
                                seq[fromInvID] = -1;
                            }
                            itemTo.setQuantity((short)(itemTo.getQuantity() + amount));
                        }
                        else
                        {
                            //do not allow bigger stacks than maxstack
                            if(itemTo.getItemID() == itemF.getItemID() && itemTo.getQuantity() + amount > ItemDataCache.Instance.getItemData(itemTo.getItemID()).getMaxStack())
                            {
                                Console.WriteLine("Cannot move item [stack too big]");
                                return false;
                            }
                            indexHold = seq.IndexOf(hash[0]);
                            indexToSwap = fromInvID;
                            holdingItem = itemTo;
                            removeItemFromInv(hash[0]);
                            removeItemFromInv(seq[fromInvID]);
                            putIntoInv(line, row, itemF);
                            seq[indexToSwap] = (row * 100) + line;
                            seq[indexHold] = -1;

                            equipping = false;
                        }
                    }
                    saveInv();
                    return true;
                }
            }
            Console.WriteLine("Cannot move item [too many items blocking]");
            return false;
        }
Exemple #5
0
        //decrement item with given seq index and delete it when amount is 0
        public Boolean decrementItem(int seqIndex, Item item = null)
        {
            updateInv();
            if(seqIndex < 0)
            {
                Console.WriteLine("Cannot decrement item [illegal index]");
                return false;
            }

            if(seq.ElementAt(seqIndex) == -1)
            {
                Console.WriteLine("Cannot decrement item [missing item]");
                return false;
            }

            if(!inv.ContainsKey(seq.ElementAt(seqIndex)))
            {
                Console.WriteLine("decrement > inv doesn't contain a key");
                return false;
            }

            item = inv[(seq.ElementAt(seqIndex))];

            if(item == null)
            {
                Console.WriteLine("Cannot decrement item [missing item]");
                return false;
            }

            if(item.getQuantity() == 0)
            {
                Console.WriteLine("Cannot decrement item [item amount is 0]");
                return false;
            }

            item.setQuantity((short)(item.getQuantity() - 1));

            if(item.getQuantity() == 0)
            {
                removeItemFromInv(seq.ElementAt(seqIndex));
                seq[seqIndex] = -1;
            }
            saveInv();
            return true;
        }
Exemple #6
0
        //try to put item into inv
        public Boolean pickItem(Item it, int amount)
        {
            updateInv();

            Item newItem = new Item(it.getItemID(), (short)amount);
            if(ItemDataCache.Instance.getItemData(newItem.getItemID()).getIsStackable() == false)
                newItem.setQuantity(1);

            if(it.getItemID() == 0)
            {
                Console.WriteLine("Cannot pick item [item has wrong id]");
                return false;
            }

            //coin
            if(it.getItemID() == 217000501)
            {
                //add money
                /*int dif = addCoins(newItem.getQuantity());
                if(dif != 0)
                {
                    Console.WriteLine("Cannot pick item [coin limit]");
                    return false;
                }*/
                saveInv();
                return true;
            }

            int line = 0;
            int row = 0;
            int i = 0;
            Boolean noMoreSeq = false;

            //move through seq to search stack
            while(noMoreSeq == false && i < 240)
            {
                if(seq[i] != -1)
                {
                    Item item = inv[seq[i]];
                    if(item == null)
                    {
                        Console.WriteLine("Cannot pick item [item in inv missing]");
                        return false;
                    }
                    if(item.getItemID() == it.getItemID() && item.getQuantity() + newItem.getQuantity() <= ItemDataCache.Instance.getItemData(item.getItemID()).getMaxStack())
                    {
                        //stack
                        if(ItemDataCache.Instance.getItemData(item.getItemID()).getIsStackable() == false)
                            item.setQuantity(1);
                        else
                            item.setQuantity((short)(item.getQuantity() + newItem.getQuantity()));
                        saveInv();
                        return true;
                    }
                }
                else
                {
                    noMoreSeq = true;
                }
                i++;
            }

            //move through all lines and rows until free slot is found
            while(row < pages * 5)
            {
                if(line == 8)
                    line = 0;
                while(line < 8)
                {
                    if(addItem(line, row, newItem))
                    {
                        saveInv();
                        return true;
                    }
                    line++;
                }
                row++;
            }
            Console.WriteLine("Cannot pick item [no free space in inv]");
            return false;
        }
Exemple #7
0
        //move item in cargo
        public Boolean moveItem(int fromCargoID, int toCargoID, int line, int row)
        {
            updateCargo();

            //equipping uses toCargoID as fromCargoID what the hell and mysterious things when swapped
            if (equipping == true)
            {
                int seq8 = seq.IndexOf(8);
                if (seq8 == -1)
                {
                    fromCargoID = toCargoID;
                }
                else
                {
                    fromCargoID = seq8;
                }
            }

            //index must exist
            if (owner.getInventory().getIndexHold() == -1 && fromCargoID >= 0 && seq[fromCargoID] == -1)
            {
                Console.WriteLine("Cannot move item [item missing]");
                return(false);
            }

            //get item1
            Item itemF;

            if (owner.getInventory().getIndexHold() == -1)
            {
                itemF = cargo[seq[fromCargoID]];
            }
            else
            {
                itemF = owner.getInventory().getHoldingItem();
            }

            //there must be item1
            if (itemF == null)
            {
                Console.WriteLine("Cannot move item [item null(ghost)]");
                return(false);
            }

            short amount = itemF.getQuantity();

            //wrong amount
            if (amount > itemF.getQuantity() || amount == 0)
            {
                Console.WriteLine("Cannot move item [item amount not sync]");
                return(false);
            }
            if (amount > 10000)
            {
                Console.WriteLine("Cannot move item [amount is >10000]");
                return(false);
            }

            //get the hashes from all blocking items
            List <int> hash = this.checkBlockingItems(line, row, itemF);

            //exception in checkBlockingItems
            if (hash == null)
            {
                Console.WriteLine("Cannot move item [crosses cargo border]");
                return(false);
            }

            //move to an empty slot
            if (hash.Count == 0)
            {
                //SWAPPED BEFORE
                if (owner.getInventory().getIndexHold() != -1)
                {
                    putIntoCargo(line, row, owner.getInventory().getHoldingItem());
                    seq[owner.getInventory().getIndexHold()]   = seq[owner.getInventory().getIndexToSwap()];
                    seq[owner.getInventory().getIndexToSwap()] = -1;
                    seq[nextFreeSequence()] = (row * 100) + line;
                    owner.getInventory().setIndexHold(-1);
                    //NOT SWAPPED BEFORE
                }
                else
                {
                    itemF.setQuantity((short)(itemF.getQuantity() - amount));
                    if (itemF.getQuantity() == 0)
                    {
                        removeItemFromCargo(seq[fromCargoID]);
                        seq[fromCargoID] = (row * 100) + line;
                    }
                    else
                    {
                        int nfs = nextFreeSequence();
                        if (nfs != -1)
                        {
                            seq[nextFreeSequence()] = (row * 100) + line;
                        }
                        else
                        {
                            Console.WriteLine("Cannot move item [no free space in cargo]");
                            return(false);
                        }
                    }

                    Item newItemF = new Item(itemF.getItemID());
                    newItemF.setQuantity((short)amount);
                    putIntoCargo(line, row, newItemF);

                    equipping = false;
                }
                saveCargo();
                return(true);
            }

            if (hash.Count == 1)
            {
                if (seq.IndexOf(hash[0]) != -1)
                {
                    //SWAPPED BEFORE
                    if (owner.getInventory().getIndexHold() != -1)
                    {
                        //swap indexes first
                        int saveSwapHash = seq[owner.getInventory().getIndexToSwap()];
                        seq[owner.getInventory().getIndexToSwap()] = -1;
                        seq[nextFreeSequence()] = seq[owner.getInventory().getIndexHold()];
                        seq[owner.getInventory().getIndexHold()] = saveSwapHash;
                        owner.getInventory().setIndexHold(owner.getInventory().getIndexToSwap());

                        owner.getInventory().setHoldingItem(cargo[hash[0]]);
                        if (owner.getInventory().getHoldingItem().getItemID() == itemF.getItemID() && owner.getInventory().getHoldingItem().getQuantity() + amount <= ItemDataCache.Instance.getItemData(itemF.getItemID()).getMaxStack())
                        {
                            owner.getInventory().getHoldingItem().setQuantity((short)(owner.getInventory().getHoldingItem().getQuantity() + amount));
                            owner.getInventory().setIndexHold(-1);
                        }
                        else
                        {
                            //do not allow bigger stacks than maxstack
                            if (owner.getInventory().getHoldingItem().getItemID() == itemF.getItemID() && owner.getInventory().getHoldingItem().getQuantity() + amount > ItemDataCache.Instance.getItemData(itemF.getItemID()).getMaxStack())
                            {
                                Console.WriteLine("Cannot move item [stack too big]");
                                return(false);
                            }
                            if (removeItemFromCargo(hash[0]) == false)
                            {
                                Console.WriteLine("Cannot move item [swapped item error]");
                                return(false);
                            }
                            putIntoCargo(line, row, itemF);
                            int saveIndexHold = owner.getInventory().getIndexHold();
                            owner.getInventory().setIndexToSwap(owner.getInventory().getIndexHold());
                            owner.getInventory().setIndexHold(seq.IndexOf(hash[0]));
                            if (owner.getInventory().getIndexHold() == -1)
                            {
                                Console.WriteLine("Cannot move item [item missing]");
                                return(false);
                            }
                            seq[saveIndexHold] = (row * 100) + line;
                            seq[owner.getInventory().getIndexHold()] = -1;
                        }
                        //NOT SWAPPED BEFORE
                    }
                    else
                    {
                        Item itemTo = cargo[hash[0]];
                        if (itemTo.getItemID() == itemF.getItemID() && itemTo.getQuantity() + amount <= ItemDataCache.Instance.getItemData(itemTo.getItemID()).getMaxStack())
                        {
                            itemF.setQuantity((short)(itemF.getQuantity() - amount));
                            if (itemF.getQuantity() == 0)
                            {
                                removeItemFromCargo(seq[fromCargoID]);
                                seq[fromCargoID] = -1;
                            }
                            itemTo.setQuantity((short)(itemTo.getQuantity() + amount));
                        }
                        else
                        {
                            //do not allow bigger stacks than maxstack
                            if (itemTo.getItemID() == itemF.getItemID() && itemTo.getQuantity() + amount > ItemDataCache.Instance.getItemData(itemTo.getItemID()).getMaxStack())
                            {
                                Console.WriteLine("Cannot move item [stack too big]");
                                return(false);
                            }
                            owner.getInventory().setIndexHold(seq.IndexOf(hash[0]));
                            owner.getInventory().setIndexToSwap(fromCargoID);
                            owner.getInventory().setHoldingItem(itemTo);
                            removeItemFromCargo(hash[0]);
                            removeItemFromCargo(seq[fromCargoID]);
                            putIntoCargo(line, row, itemF);
                            seq[owner.getInventory().getIndexToSwap()] = (row * 100) + line;
                            seq[owner.getInventory().getIndexHold()]   = -1;

                            equipping = false;
                        }
                    }
                    saveCargo();
                    return(true);
                }
            }
            Console.WriteLine("Cannot move item [too many items blocking]");
            return(false);
        }
Exemple #8
0
        //drop item from inv to ground
        public int dropItem(int fromInvID, int amount, Character cur, Boolean isCoin)
        {
            int uid = 0;

            //amount must be >0
            if (amount == 0)
            {
                Console.WriteLine("Cannot drop item [amount is 0]");
                return(-1);
            }

            //amount must be <=10000
            if (amount > 10000 && !isCoin)
            {
                Console.WriteLine("Cannot drop item [amount is >=10000]");
                return(-1);
            }

            //if it was an equipped item
            if (equipping == true)
            {
                fromInvID = seq.IndexOf(8);
                if (fromInvID == -1)
                {
                    Console.WriteLine("Cannot equip item [item index missing]");
                    return(-1);
                }
            }

            //SWAPPED BEFORE
            if (indexHold != -1)
            {
                //swap indexes first
                int saveSwapHash = seq[indexToSwap];
                seq[indexToSwap]        = -1;
                seq[nextFreeSequence()] = seq[indexHold];
                seq[indexHold]          = saveSwapHash;

                //create drop
                ItemData it = ItemDataCache.Instance.getItemData(holdingItem.getItemID());
                //uid=it.dropItem(cur.getCurrentMap(), cur.getLocation(), amount).getuid();
                //TODO

                indexHold = -1;
            }
            else
            {
                //NOT SWAPPED BEFORE

                ItemData it;
                //coin is not an item in inv
                if (isCoin == false)
                {
                    if (seq[fromInvID] == -1)
                    {
                        Console.WriteLine("Cannot drop item [item missing]");
                        return(-1);
                    }
                    Item itemF = inv[seq[fromInvID]];
                    if (itemF == null)
                    {
                        Console.WriteLine("Cannot drop item [item null(ghost)]");
                        return(-1);
                    }
                    //wrong amount
                    if (amount > itemF.getQuantity())
                    {
                        Console.WriteLine("Cannot drop item [item amount not sync]");
                        return(-1);
                    }

                    //create drop
                    it = ItemDataCache.Instance.getItemData(inv[seq[fromInvID]].getItemID());

                    //reduce amount or remove item
                    itemF.setQuantity((short)(itemF.getQuantity() - amount));
                    if (itemF.getQuantity() == 0)
                    {
                        removeItemFromInv(seq[fromInvID]);
                        seq[fromInvID] = -1;
                    }

                    //if it was an equipped item
                    equipping = false;
                }
                else
                {
                    it = ItemDataCache.Instance.getItemData(217000501);
                    //subtract money and check if possible

                    /*if(subtractCoins(amount) == false)
                     * {
                     *      Console.WriteLine("Cannot drop item [not enough coins]");
                     *      return -1;
                     * }*/
                }

                //TODO
                //uid=it.dropItem(cur.getCurrentMap(), cur.getLocation(), amount).getuid();
            }
            return(uid);
        }
Exemple #9
0
        //try to put item into inv
        public Boolean pickItem(Item it, int amount)
        {
            updateInv();

            Item newItem = new Item(it.getItemID(), (short)amount);

            if (ItemDataCache.Instance.getItemData(newItem.getItemID()).getIsStackable() == false)
            {
                newItem.setQuantity(1);
            }

            if (it.getItemID() == 0)
            {
                Console.WriteLine("Cannot pick item [item has wrong id]");
                return(false);
            }

            //coin
            if (it.getItemID() == 217000501)
            {
                //add money

                /*int dif = addCoins(newItem.getQuantity());
                 * if(dif != 0)
                 * {
                 *      Console.WriteLine("Cannot pick item [coin limit]");
                 *      return false;
                 * }*/
                saveInv();
                return(true);
            }

            int     line      = 0;
            int     row       = 0;
            int     i         = 0;
            Boolean noMoreSeq = false;

            //move through seq to search stack
            while (noMoreSeq == false && i < 240)
            {
                if (seq[i] != -1)
                {
                    Item item = inv[seq[i]];
                    if (item == null)
                    {
                        Console.WriteLine("Cannot pick item [item in inv missing]");
                        return(false);
                    }
                    if (item.getItemID() == it.getItemID() && item.getQuantity() + newItem.getQuantity() <= ItemDataCache.Instance.getItemData(item.getItemID()).getMaxStack())
                    {
                        //stack
                        if (ItemDataCache.Instance.getItemData(item.getItemID()).getIsStackable() == false)
                        {
                            item.setQuantity(1);
                        }
                        else
                        {
                            item.setQuantity((short)(item.getQuantity() + newItem.getQuantity()));
                        }
                        saveInv();
                        return(true);
                    }
                }
                else
                {
                    noMoreSeq = true;
                }
                i++;
            }

            //move through all lines and rows until free slot is found
            while (row < pages * 5)
            {
                if (line == 8)
                {
                    line = 0;
                }
                while (line < 8)
                {
                    if (addItem(line, row, newItem))
                    {
                        saveInv();
                        return(true);
                    }
                    line++;
                }
                row++;
            }
            Console.WriteLine("Cannot pick item [no free space in inv]");
            return(false);
        }