Пример #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);
        }
Пример #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);
            }
        }
Пример #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);
        }
Пример #4
0
        //buy an item
        public Boolean buyItem(Item item, int line, int row)
        {
            updateInv();
            Item it;

            inv.TryGetValue(row * 100 + line, out it);
            if (it != null && item.getItemID() == it.getItemID() && item.getQuantity() + it.getQuantity() > ItemDataCache.Instance.getItemData(item.getItemID()).getMaxStack())
            {
                Console.WriteLine("Cannot buy item [max stack]");
                return(false);
            }

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

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

            //move to an empty slot
            if (hash.Count == 0)
            {
                if (!addItem(line, row, item))
                {
                    Console.WriteLine("Cannot buy item [no space]");
                    return(false);
                }
                saveInv();
                Console.WriteLine("Item bought at free line {0} row {1}", line, row);
                return(true);
            }

            //swap
            if (hash.Count == 1)
            {
                indexHold   = seq.IndexOf(hash[0]);
                indexToSwap = nextFreeSequence();
                if (indexToSwap == -1)
                {
                    Console.WriteLine("Cannot buy item [no free space in inv]");
                    return(false);
                }
                Console.WriteLine("Item bought at free seq {0}, line {1} row {2}", indexToSwap, line, row);
                holdingItem = inv[hash[0]];
                removeItemFromInv(hash[0]);
                putIntoInv(line, row, item);
                seq[indexToSwap] = (row * 100) + line;
                seq[indexHold]   = -1;
                saveInv();
                return(true);
            }
            Console.WriteLine("lolItem bought at free seq {0}, line {1} row {2} hash.Count {3}", indexToSwap, line, row, hash.Count);
            return(false);
        }
Пример #5
0
        // adds item to inventory only if all needed slots are empty, return true is success, false otherwise
        public Boolean addItem(int line, int row, Item it)
        {
            //get the hashes from all blocking items
            List<int> hash = this.checkBlockingItems(line, row, it);

            //exception in checkBlockingItems
            if(hash == null)
            {
                Console.WriteLine("Error occured in checkingBlockingItems");
                return false;
            }

            //move to an empty slot
            if(hash.Count == 0)
            {
                if(put(line, row, it) == false)
                {
                    Console.WriteLine("Cannot put item into given slot");
                    return false;
                }
                return true;
            }

            //stack
            if(hash.Count == 1)
            {
                if(inv[hash[0]].getItemID() == it.getItemID() && inv[hash[0]].getQuantity() + it.getQuantity() <= ItemDataCache.Instance.getItemData(it.getItemID()).getMaxStack())
                {
                    inv[hash[0]].setQuantity((short)(inv[hash[0]].getQuantity() + it.getQuantity()));
                    return true;
                }
            }

            //items block
            Console.WriteLine("Items blocking (" + hash.Count + ")");
            return false;
        }
Пример #6
0
        // adds item to inventory only if all needed slots are empty, return true is success, false otherwise
        public Boolean addItem(int line, int row, Item it)
        {
            //get the hashes from all blocking items
            List <int> hash = this.checkBlockingItems(line, row, it);

            //exception in checkBlockingItems
            if (hash == null)
            {
                Console.WriteLine("Error occured in checkingBlockingItems");
                return(false);
            }

            //move to an empty slot
            if (hash.Count == 0)
            {
                if (put(line, row, it) == false)
                {
                    Console.WriteLine("Cannot put item into given slot");
                    return(false);
                }
                return(true);
            }

            //stack
            if (hash.Count == 1)
            {
                if (inv[hash[0]].getItemID() == it.getItemID() && inv[hash[0]].getQuantity() + it.getQuantity() <= ItemDataCache.Instance.getItemData(it.getItemID()).getMaxStack())
                {
                    inv[hash[0]].setQuantity((short)(inv[hash[0]].getQuantity() + it.getQuantity()));
                    return(true);
                }
            }

            //items block
            Console.WriteLine("Items blocking (" + hash.Count + ")");
            return(false);
        }
Пример #7
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;
        }
Пример #8
0
        //buy an item
        public Boolean buyItem(Item item, int line, int row)
        {
            updateInv();
            Item it;
            inv.TryGetValue(row * 100 + line, out it);
            if(it != null && item.getItemID() == it.getItemID() && item.getQuantity() + it.getQuantity() > ItemDataCache.Instance.getItemData(item.getItemID()).getMaxStack())
            {
                Console.WriteLine("Cannot buy item [max stack]");
                return false;
            }

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

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

            //move to an empty slot
            if(hash.Count == 0)
            {
                if(!addItem(line, row, item))
                {
                    Console.WriteLine("Cannot buy item [no space]");
                    return false;
                }
                saveInv();
                Console.WriteLine("Item bought at free line {0} row {1}",  line, row);
                return true;
            }

            //swap
            if(hash.Count == 1)
            {
                indexHold = seq.IndexOf(hash[0]);
                indexToSwap = nextFreeSequence();
                if(indexToSwap == -1)
                {
                    Console.WriteLine("Cannot buy item [no free space in inv]");
                    return false;
                }
                Console.WriteLine("Item bought at free seq {0}, line {1} row {2}", indexToSwap, line, row);
                holdingItem = inv[hash[0]];
                removeItemFromInv(hash[0]);
                putIntoInv(line, row, item);
                seq[indexToSwap] = (row * 100) + line;
                seq[indexHold] = -1;
                saveInv();
                return true;
            }
            Console.WriteLine("lolItem bought at free seq {0}, line {1} row {2} hash.Count {3}", indexToSwap, line, row, hash.Count);
            return false;
        }
Пример #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;
        }
Пример #10
0
        public static void SaveInventories(Character chr)
        {
            Inventory inv = chr.getInventory();
            StringBuilder sb = new StringBuilder();
            for(int i = 0;i < inv.getPages() * 40;i++) {
                Item item = new Item();
                if(inv.getSeqSaved()[i] != -1)
                    item = inv.getInvSaved()[inv.getSeqSaved()[i]];
                sb.Append(",i" + i + "=" + item.getItemID());
                sb.Append(",h" + i + "=" + inv.getSeqSaved()[i]);
                sb.Append(",q" + i + "=" + item.getQuantity());
                sb.Append(",e" + i + "=" + item.getEnding());
            }

            Save("chars_inv", sb, "charID", chr.getuID());
            return;
        }
Пример #11
0
        public static byte[] getUpgradePacket(Character chr, Item newItem, byte newItemIndex, int newItemHash)
        {
            byte x, y, suc;
            if(newItemHash != -1)
            {
                x = (byte)(newItemHash % 100);
                y = (byte)(newItemHash / 100);
                suc = 1;
            }
            else
            {
                x = (byte)0xFF;
                y = (byte)0xFF;
                suc = 0;
            }

            OutPacket op = new OutPacket(36);
            op.WriteInt(36);
            op.WriteShort(0x04);
            op.WriteShort(0x32);
            op.WriteInt(0x01);
            op.WriteInt(chr.getuID());
            op.WriteShort(suc);
            op.WriteByte();
            op.WriteByte(newItemIndex);
            op.WriteInt(134612548);
            op.WriteShort();
            op.WriteByte(y);
            op.WriteByte(x);
            op.WriteInt(newItem.getItemID());
            op.WriteInt(newItem.getQuantity());
            return op.ToArray();
        }
Пример #12
0
        //move item to inventory from cargo
        public Boolean moveFromCargo(Item item, int cargoSlot, int line, int row)
        {
            updateInv();

            Cargo cargo = owner.getCargo();

            cargo.updateCargo();

            //ADD TO INVENTORY
            Item it;
            inv.TryGetValue(row * 100 + line, out it);
            if(it != null && item.getItemID() == it.getItemID() && item.getQuantity() + it.getQuantity() > ItemDataCache.Instance.getItemData(item.getItemID()).getMaxStack())
            {
                Console.WriteLine("Cannot move item [max stack]");
                return false;
            }

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

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

            //move to an empty slot
            if(hash.Count == 0)
            {
                seq[nextFreeSequence()] = (row * 100) + line;
                putIntoInv(line, row, item);
                cargo.removeItem(cargoSlot);
                saveInv();
                return true;
            }

            //swap
            if(hash.Count == 1)
            {
                indexHold = seq.IndexOf(hash[0]);
                indexToSwap = nextFreeSequence();
                if(indexToSwap == -1)
                {
                    Console.WriteLine("Cannot buy item [no free space in inv]");
                    return false;
                }
                holdingItem = inv[hash[0]];
                removeItemFromInv(hash[0]);
                putIntoInv(line, row, item);
                seq[indexToSwap] = (row * 100) + line;
                seq[indexHold] = -1;
                cargo.removeItem(cargoSlot);
                saveInv();
                return true;
            }

            Console.WriteLine("Count {0}", hash.Count);
            return false;
        }
Пример #13
0
        //move item to inventory from cargo
        public Boolean moveFromCargo(Item item, int cargoSlot, int line, int row)
        {
            updateInv();

            Cargo cargo = owner.getCargo();

            cargo.updateCargo();

            //ADD TO INVENTORY
            Item it;

            inv.TryGetValue(row * 100 + line, out it);
            if (it != null && item.getItemID() == it.getItemID() && item.getQuantity() + it.getQuantity() > ItemDataCache.Instance.getItemData(item.getItemID()).getMaxStack())
            {
                Console.WriteLine("Cannot move item [max stack]");
                return(false);
            }

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

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

            //move to an empty slot
            if (hash.Count == 0)
            {
                seq[nextFreeSequence()] = (row * 100) + line;
                putIntoInv(line, row, item);
                cargo.removeItem(cargoSlot);
                saveInv();
                return(true);
            }

            //swap
            if (hash.Count == 1)
            {
                indexHold   = seq.IndexOf(hash[0]);
                indexToSwap = nextFreeSequence();
                if (indexToSwap == -1)
                {
                    Console.WriteLine("Cannot buy item [no free space in inv]");
                    return(false);
                }
                holdingItem = inv[hash[0]];
                removeItemFromInv(hash[0]);
                putIntoInv(line, row, item);
                seq[indexToSwap] = (row * 100) + line;
                seq[indexHold]   = -1;
                cargo.removeItem(cargoSlot);
                saveInv();
                return(true);
            }

            Console.WriteLine("Count {0}", hash.Count);
            return(false);
        }
Пример #14
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);
        }
Пример #15
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;
        }
Пример #16
0
        //buy an item
        public Boolean insertItemFromInventory(Inventory inv, int itemSlot, int line, int row)
        {
            updateCargo();
            inv.updateInv();

            Item item = null;

            if (inv.getIndexHold() != -1)
            {
                item = inv.getHoldingItem();
            }
            else
            {
                item = inv.getItemBySeqIndexing(itemSlot);
            }
            if (item == null)
            {
                Console.WriteLine("[inv -> cargo] tried to move not existing item");
                return(false);
            }
            else
            {
                Console.WriteLine("moving item: {0} at index {1} and seqIndex {2} and line {3} and row {4}", ItemDataCache.Instance.getItemData(item.getItemID()).getName(), itemSlot, inv.getSeq()[itemSlot], line, row);
            }

            short amount = item.getQuantity();

            Item it;

            cargo.TryGetValue(row * 100 + line, out it);
            if (it != null && item.getItemID() == it.getItemID() && item.getQuantity() + it.getQuantity() > ItemDataCache.Instance.getItemData(item.getItemID()).getMaxStack())
            {
                Console.WriteLine("[inv -> cargo] cannot move item, max stack");
                return(false);
            }

            List <int> hash = this.checkBlockingItems(line, row, item);

            //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)
            {
                if (!addItem(line, row, item))
                {
                    Console.WriteLine("Cannot buy item [no space]");
                    return(false);
                }
                if (inv.getIndexHold() != -1)
                {
                    inv.setHoldingItem(null);
                }
                else
                {
                    inv.removeItem(itemSlot);
                }
                saveCargo();
                inv.saveInv();
                Console.WriteLine("Item putt3d at free line {0} row {1}", line, row);
                return(true);
            }

            //swap
            if (hash.Count == 1)
            {
                owner.getInventory().setIndexHold(seq.IndexOf(hash[0]));
                owner.getInventory().setIndexToSwap(nextFreeSequence());
                if (owner.getInventory().getIndexToSwap() == -1)
                {
                    Console.WriteLine("Cannot buy item [no free space in inv]");
                    return(false);
                }
                Console.WriteLine("Item putt3d at free seq {0}, line {1} row {2}", owner.getInventory().getIndexToSwap(), line, row);
                owner.getInventory().setHoldingItem(cargo[hash[0]]);
                removeItemFromCargo(hash[0]);
                putIntoCargo(line, row, item);
                seq[owner.getInventory().getIndexToSwap()] = (row * 100) + line;
                seq[owner.getInventory().getIndexHold()]   = -1;
                inv.removeItem(itemSlot);
                saveCargo();
                inv.saveInv();
                return(true);
            }
            Console.WriteLine("too m4ny it3mz 2 sw4p");
            return(false);
        }
Пример #17
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);
        }
Пример #18
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;
        }
Пример #19
0
        public static void SaveCargo(Character chr)
        {
            Cargo cargo = chr.getCargo();
            StringBuilder sb = new StringBuilder();
            for(int i = 0;i < 120;i++)
            {
                Item item = new Item();
                if(cargo.getSeqSaved()[i] != -1)
                    item = cargo.getCargoSaved()[cargo.getSeqSaved()[i]];
                sb.Append(",i" + i + "=" + item.getItemID());
                sb.Append(",h" + i + "=" + cargo.getSeqSaved()[i]);
                sb.Append(",q" + i + "=" + item.getQuantity());
                sb.Append(",e" + i + "=" + item.getEnding());
            }

            Save("chars_cargo", sb, "charID", chr.getuID());
            return;
        }
Пример #20
0
        // Holy Grail ftw
        public static void useItem(Character chr, Item item, byte usingIndex, InPacket p)
        {
            MartialClient c = chr.getAccount().mClient;
            ItemData itemData = ItemDataCache.Instance.getItemData(item.getItemID());
            Boolean shouldDecrease = false;
            string determined = null;
            int determiner = 0;
            if(itemData.getIsStackable()) shouldDecrease = true;
            else
            {
                if(itemData.getTimeToExpire() == 0)
                    shouldDecrease = true;
            }

            // well.. we don't care if it's handled by server.. let's just remove them & f**k haterz! qq
            if(shouldDecrease)
                if(!chr.getInventory().decrementItem(usingIndex))
                {
                    Console.WriteLine("something went wrong with decrement..");
                    return;
                }

            switch(itemData.getCategory())
            {
                case 1001: // healingz
                {
                    if(itemData.getHealHP() > 0 || itemData.getHealMana() > 0 || itemData.getHealStamina() > 0)
                        StaticPackets.releaseHealPacket(chr, (int)(chr.getCurHP() + itemData.getHealHP()), (short)(chr.getCurMP() + itemData.getHealMana()), (short)(chr.getCurSP() + itemData.getHealStamina()));
                    break;
                }
                case 1002: // skillz o.o
                {
                    StaticPackets.sendSystemMessageToClient(chr.getAccount().mClient, 1, "If you'd like to learn any skill, go to skills list and press CTRL+LMB.");
                    break;
                }
                case 1003: // teleport
                {
                    if(chr.getMap() == itemData.getTeleportMap() || chr.getMap() != itemData.getTeleportMap() && itemData.getSpecialEffect() != 0)
                        CharacterFunctions.setPlayerPosition(chr, itemData.getTeleportX(), itemData.getTeleportY(), (short)itemData.getTeleportMap());
                    break;
                }
                case 1007: // reset skills
                {
                    chr.getSkills().resetAll();
                    chr.getSkillBar().getSkillBar().Clear();
                    break;
                }
                case 1011: // effect potions
                {
                    chr.setEffect((byte)itemData.getSpecialEffect());
                    break;
                }
                case 1012: // tae potion
                {
                    break;
                }
                case 1013: // faction change
                {
                    if(chr.getFaction() == 0)
                        return;

                    chr.setFaction(chr.getFaction() == 1 ? (byte)2 : (byte)1);
                    break;
                }
                case 1015: // chuk amulet
                {
                    determiner = BitConverter.ToInt32(p.ReadBytes(4), 0);
                    if(determiner == 0) return;
                    ItemData determinedItem = ItemDataCache.Instance.getItemData(determiner);
                    if(determinedItem == null || determinedItem.getCategory() != 1003 || (determiner < 212100146 && determiner > 212100164 && determiner != 212100185 && determiner != 212100187))
                    {
                        Console.WriteLine("I CAN'T TURN 10 INTO 20 CHICKENZ");
                        return;
                    }
                    CharacterFunctions.setPlayerPosition(chr, determinedItem.getTeleportX(), determinedItem.getTeleportY(), (short)determinedItem.getTeleportMap());
                    break;
                }
                case 1016: // karma amulet
                {
                    chr.setKarmaMessagingTimes((short)(chr.getKarmaMessagingTimes()+1));
                    break;
                }
                case 1020: // name changer
                {
                    p.Skip(4);
                    string charName = MiscFunctions.obscureString(p.ReadString(16));
                    if(charName.Length < 3 || Regex.Replace(charName, "[^A-Za-z0-9]+", "") != charName || MySQLTool.NameTaken(charName))
                    {
                        StaticPackets.sendSystemMessageToClient(chr.getAccount().mClient, 1, "Wrong input " + charName + ".");
                        return;
                    }

                    chr.setName(charName);
                    determined = charName;

                    CharacterFunctions.refreshCharacterForTheWorld(chr);
                    break;
                }
                case 1021: // face changer
                {
                    chr.setFace((byte)itemData.getSpecialEffect());
                    break;
                }
                case 1024:
                {
                    // yy..?
                    break;
                }
                case 1031: // red castle
                {
                    determiner = BitConverter.ToInt32(p.ReadBytes(4), 0);
                    if(determiner == 0) return;
                    ItemData determinedItem = ItemDataCache.Instance.getItemData(determiner);
                    if(determinedItem == null || determinedItem.getCategory() != 56 || ((determiner < 273001255 && determiner > 273001257) && determiner != 283000472 && determiner != 283000543 && determiner != 283000575 && determiner != 283000614 && determiner != 283000934 && determiner != 283001078 && determiner != 283001373 && determiner != 283001376))
                    {
                        Console.WriteLine("I CAN'T TURN 10 INTO 20 CHICKENZ");
                        return;
                    }
                    CharacterFunctions.setPlayerPosition(chr, determinedItem.getTeleportX(), determinedItem.getTeleportY(), (short)determinedItem.getTeleportMap());
                    break;
                }
                default:
                {
                    StaticPackets.sendSystemMessageToClient(chr.getAccount().mClient, 1, "Feature not implemented yet");
                    return;
                }
            }

            OutPacket op = new OutPacket(52);
            op.WriteInt(52);
            op.WriteShort(0x04);
            op.WriteShort(0x05);
            op.WriteInt(140328705);
            op.WriteInt(chr.getuID());
            op.WriteShort(0x01);
            op.WriteByte(0x01);
            op.WriteByte(usingIndex);
            op.WriteInt(item.getQuantity());
            op.WriteInt(793149441);
            op.WriteInt(/*determiner > 0 ? determiner : 0*/);
            op.WritePaddedString(determined, 17);
            op.WriteByte(0x90);
            op.WriteByte(0xd2);
            op.WriteByte(0x2a);
            c.WriteRawPacket(op.ToArray());

            OutPacket ops = new OutPacket(40);
            ops.WriteInt(40);
            ops.WriteShort(0x05);
            ops.WriteShort(0x05);
            ops.WriteInt(779458561);
            ops.WriteInt(chr.getuID());
            ops.WriteInt(item.getItemID());
            ops.WritePaddedString(determined, 17);
            ops.WriteByte(0x9e);
            ops.WriteByte(0x0f);
            ops.WriteByte(0xbf);
            WMap.Instance.getGrid(chr.getMap()).sendTo3x3Area(chr, chr.getArea(), ops.ToArray());
        }
Пример #21
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);
        }