Exemple #1
0
        private int SpawnItem(int lowid, int highid, int ql)
        {
            // Copied from ChatCmd giveitem.
            int firstfree = 64;

            firstfree = Cli.Character.GetNextFreeInventory(104);

            if (firstfree <= 93)
            {
                InventoryEntries ie   = new InventoryEntries();
                AOItem           item = ItemHandler.GetItemTemplate(Convert.ToInt32(lowid));
                ie.Placement    = firstfree;
                ie.Container    = 104;
                ie.Item.lowID   = Convert.ToInt32(lowid);
                ie.Item.highID  = Convert.ToInt32(highid);
                ie.Item.Quality = Convert.ToInt32(ql);
                if (item.ItemType != 1)
                {
                    ie.Item.multiplecount = Math.Max(1, (int)item.getItemAttribute(212));
                }
                else
                {
                    bool found = false;
                    foreach (AOItemAttribute a in ie.Item.Stats)
                    {
                        if (a.Stat != 212)
                        {
                            continue;
                        }
                        found   = true;
                        a.Value = Math.Max(1, (int)item.getItemAttribute(212));
                        break;
                    }
                    if (!found)
                    {
                        AOItemAttribute aoi = new AOItemAttribute();
                        aoi.Stat  = 212;
                        aoi.Value = Math.Max(1, (int)item.getItemAttribute(212));
                        ie.Item.Stats.Add(aoi);
                    }
                }
                Cli.Character.Inventory.Add(ie);
                Packets.AddTemplate.Send(Cli, ie);
                return(firstfree);
            }
            else
            {
                // TODO: open overflow
                Cli.SendChatText("Your Inventory is full");
                return(0);
            }
        }
Exemple #2
0
        public override void ExecuteCommand(Client client, Identity target, string[] args)
        {
            Client targetClient = null;

            if ((targetClient = FindClient.FindClientByName(args[1])) != null)
            {
                int firstfree = 64;
                firstfree = targetClient.Character.GetNextFreeInventory(104);
                if (firstfree <= 93)
                {
                    InventoryEntries mi = new InventoryEntries();
                    AOItem           it = ItemHandler.GetItemTemplate(Convert.ToInt32(args[2]));
                    mi.Placement    = firstfree;
                    mi.Container    = 104;
                    mi.Item.LowID   = Convert.ToInt32(args[2]);
                    mi.Item.HighID  = Convert.ToInt32(args[3]);
                    mi.Item.Quality = Convert.ToInt32(args[4]);
                    if (it.ItemType != 1)
                    {
                        mi.Item.MultipleCount = Math.Max(1, it.getItemAttribute(212));
                    }
                    else
                    {
                        bool found = false;
                        foreach (AOItemAttribute a in mi.Item.Stats)
                        {
                            if (a.Stat != 212)
                            {
                                continue;
                            }
                            found   = true;
                            a.Value = Math.Max(1, it.getItemAttribute(212));
                            break;
                        }
                        if (!found)
                        {
                            AOItemAttribute aoi = new AOItemAttribute();
                            aoi.Stat  = 212;
                            aoi.Value = Math.Max(1, it.getItemAttribute(212));
                            mi.Item.Stats.Add(aoi);
                        }
                    }
                    targetClient.Character.Inventory.Add(mi);
                    AddTemplate.Send(targetClient, mi);
                }
                else
                {
                    client.SendChatText("Your Inventory is full");
                }
            }
        }
Exemple #3
0
        private int SpawnItem()
        {
            int firstfree = this.client.Character.GetNextFreeInventory(104);

            if (firstfree <= 93)
            {
                InventoryEntries mi = new InventoryEntries();
                AOItem           it = ItemHandler.GetItemTemplate(this.ResultLowId);
                mi.Placement    = firstfree;
                mi.Container    = 104;
                mi.Item.LowID   = this.ResultLowId;
                mi.Item.HighID  = this.ResultHighId;
                mi.Item.Quality = this.Quality;
                if (it.ItemType != 1)
                {
                    mi.Item.MultipleCount = Math.Max(1, it.getItemAttribute(212));
                }
                else
                {
                    bool found = false;
                    foreach (AOItemAttribute a in mi.Item.Stats)
                    {
                        if (a.Stat != 212)
                        {
                            continue;
                        }
                        found   = true;
                        a.Value = Math.Max(1, it.getItemAttribute(212));
                        break;
                    }
                    if (!found)
                    {
                        AOItemAttribute aoi = new AOItemAttribute();
                        aoi.Stat  = 212;
                        aoi.Value = Math.Max(1, it.getItemAttribute(212));
                        mi.Item.Stats.Add(aoi);
                    }
                }
                this.client.Character.Inventory.Add(mi);
                AddTemplate.Send(this.client, mi);

                return(firstfree);
            }
            else
            {
                this.client.SendChatText("Your Inventory is full");
                return(0);
            }
        }
        private int SpawnItem(int lowid, int highid, int ql)
        {
            // Copied from ChatCmd giveitem. 
            int firstfree = 64;
            firstfree = Cli.Character.GetNextFreeInventory(104);

            if (firstfree <= 93)
            {
                InventoryEntries ie = new InventoryEntries();
                AOItem item = ItemHandler.GetItemTemplate(Convert.ToInt32(lowid));
                ie.Placement = firstfree;
                ie.Container = 104;
                ie.Item.lowID = Convert.ToInt32(lowid);
                ie.Item.highID = Convert.ToInt32(highid);
                ie.Item.Quality = Convert.ToInt32(ql);
                if (item.ItemType != 1)
                {
                    ie.Item.multiplecount = Math.Max(1, (int)item.getItemAttribute(212));
                }
                else
                {
                    bool found = false;
                    foreach (AOItemAttribute a in ie.Item.Stats)
                    {
                        if (a.Stat != 212)
                            continue;
                        found = true;
                        a.Value = Math.Max(1, (int)item.getItemAttribute(212));
                        break;
                    }
                    if (!found)
                    {
                        AOItemAttribute aoi = new AOItemAttribute();
                        aoi.Stat = 212;
                        aoi.Value = Math.Max(1, (int)item.getItemAttribute(212));
                        ie.Item.Stats.Add(aoi);
                    }
                }
                Cli.Character.Inventory.Add(ie);
                Packets.AddTemplate.Send(Cli, ie);
                return firstfree;
            }
            else
            {
                // TODO: open overflow
                Cli.SendChatText("Your Inventory is full");
                return 0;
            }
        }
Exemple #5
0
 /// <summary>
 /// Read bank account from database
 /// TODO: catch exceptions
 /// </summary>
 public void readBankContentsfromSQL()
 {
     lock (Bank)
     {
         SqlWrapper ms = new SqlWrapper();
         Bank.Clear();
         DataTable dt = ms.ReadDT("SELECT * FROM bank WHERE charID=" + ID.ToString() + " ORDER BY InventoryID ASC");
         if (dt.Rows.Count > 0)
         {
             foreach (DataRow row in dt.Rows)
             {
                 AOItem item = new AOItem();
                 item.flags = (Int32)row["InventoryID"];
                 item.lowID = (Int32)row["lowID"];
                 item.highID = (Int32)row["highID"];
                 item.multiplecount = (Int32)row["Amount"];
                 item.Quality = (Int32)row["QL"];
                 item.Type = (Int32)row["Type"];
                 item.Instance = (Int32)row["instance"];
                 byte[] statsblob = (byte[])row[8];
                 int counter = 0;
                 long bloblen = statsblob.Length;
                 while (counter < bloblen - 1)
                 {
                     AOItemAttribute tempItemAttribute = new AOItemAttribute();
                     tempItemAttribute.Stat = BitConverter.ToInt32(statsblob, counter);
                     tempItemAttribute.Value = BitConverter.ToInt32(statsblob, counter + 4);
                     counter += 8;
                     item.Stats.Add(tempItemAttribute);
                 }
                 Bank.Add(item);
             }
         }
     }
 }
        private int SpawnItem()
        {
            int firstfree = this.client.Character.GetNextFreeInventory(104);
            if (firstfree <= 93)
            {
                InventoryEntries mi = new InventoryEntries();
                AOItem it = ItemHandler.GetItemTemplate(this.ResultLowId);
                mi.Placement = firstfree;
                mi.Container = 104;
                mi.Item.LowID = this.ResultLowId;
                mi.Item.HighID = this.ResultHighId;
                mi.Item.Quality = this.Quality;
                if (it.ItemType != 1)
                {
                    mi.Item.MultipleCount = Math.Max(1, it.getItemAttribute(212));
                }
                else
                {
                    bool found = false;
                    foreach (AOItemAttribute a in mi.Item.Stats)
                    {
                        if (a.Stat != 212)
                        {
                            continue;
                        }
                        found = true;
                        a.Value = Math.Max(1, it.getItemAttribute(212));
                        break;
                    }
                    if (!found)
                    {
                        AOItemAttribute aoi = new AOItemAttribute();
                        aoi.Stat = 212;
                        aoi.Value = Math.Max(1, it.getItemAttribute(212));
                        mi.Item.Stats.Add(aoi);
                    }
                }
                this.client.Character.Inventory.Add(mi);
                AddTemplate.Send(this.client, mi);

                return firstfree;
            }
            else
            {
                this.client.SendChatText("Your Inventory is full");
                return 0;
            }
        }
Exemple #7
0
        public static List <AOItem> GetLoot(NonPlayerCharacterClass npc)
        {
            List <AOItem> drops = new List <AOItem>();

            int minql = (int)Math.Ceiling(npc.Stats.Level.Value - 0.2 * npc.Stats.Level.Value);
            int maxql = (int)Math.Floor(npc.Stats.Level.Value + 0.2 * npc.Stats.Level.Value);

            var lootinfo =
                new SqlWrapper().ReadDatatable(
                    "SELECT drophashes, dropslots, droppercents FROM mobtemplate WHERE hash = " + npc.Hash + ";").Rows;

            int numberOfSlots = 0;

            string[] hashes   = lootinfo[0][0].ToString().ToLower().Split(',');
            string[] slots    = lootinfo[0][1].ToString().ToLower().Split(',');
            string[] percents = lootinfo[0][2].ToString().ToLower().Split(',');

            if (!hashes.Any())
            {
                return(null);
            }
            if (hashes[0] == string.Empty)
            {
                return(null);
            }

            foreach (string s in slots)
            {
                numberOfSlots = Math.Max(numberOfSlots, Convert.ToInt32(s.Trim()));
            }

            List <PartialSlot> list = new List <PartialSlot>();

            for (int hashNumber = 0; hashNumber < hashes.Count(); ++hashNumber)
            {
                list.Add(
                    new PartialSlot(hashes[hashNumber].Trim(), slots[hashNumber].Trim(), percents[hashNumber].Trim()));
            }

            for (int slotNumber = 1; slotNumber <= numberOfSlots; ++slotNumber)
            {
                var fullSlot = list.Where(match => match.Slot == slotNumber).Select(match => match);

                Random rand = new Random();
                double num  = rand.NextDouble();

                double chance = 0;
                foreach (PartialSlot slot in fullSlot)
                {
                    chance = chance + (slot.Chance / (double)10000);
                    if (num <= chance)
                    {
                        List <LootItem> union = new List <LootItem>();

                        foreach (string hash in slot.HashList)
                        {
                            var matches =
                                FullDropList.Where(
                                    match =>
                                    ((match.MinQL <= minql && match.MaxQL >= maxql) ||
                                     (match.MinQL < maxql && match.MaxQL >= maxql) ||
                                     (match.MinQL <= minql && match.MaxQL > minql) ||
                                     (match.MinQL >= minql && match.MaxQL <= maxql) || !match.RangeCheck) &&
                                    match.Hash == hash).Select(match => match);
                            foreach (LootItem li in matches)
                            {
                                if (
                                    !union.Exists(
                                        duplicate => duplicate.HighId == li.HighId && duplicate.MaxQL == li.MaxQL))
                                {
                                    union.Add(li);
                                }
                            }
                        }

                        int ql = rand.Next(minql - 1, maxql + 1);

                        if (union.Any())
                        {
                            int select = rand.Next(-1, union.Count());

                            AOItem item = ItemHandler.interpolate(
                                union.ElementAt(@select).LowId, union.ElementAt(@select).HighId, ql);

                            if (item.ItemType != 1)
                            {
                                item.MultipleCount = Math.Max(1, item.getItemAttribute(212));
                            }
                            else
                            {
                                bool found = false;
                                foreach (AOItemAttribute a in item.Stats)
                                {
                                    if (a.Stat != 212)
                                    {
                                        continue;
                                    }
                                    found   = true;
                                    a.Value = Math.Max(1, item.getItemAttribute(212));
                                    break;
                                }
                                if (!found)
                                {
                                    AOItemAttribute aoi = new AOItemAttribute
                                    {
                                        Stat = 212, Value = Math.Max(1, item.getItemAttribute(212))
                                    };
                                    item.Stats.Add(aoi);
                                }
                            }
                            drops.Add(item);
                            break;
                        }
                    }
                }
            }
            return(drops);
        }
Exemple #8
0
            public Item(int ID)
            {
                ItemAttributes = new List<AOItemAttribute>();
                ItemEvents = new List<AOEvents>();
                SqlWrapper ms = new SqlWrapper();

                DataTable dt = ms.ReadDT("SELECT * FROM items WHERE AOID='" + ID.ToString() + "'");

                if (dt.Rows.Count > 0)
                {
                    AOID = (Int32)dt.Rows[0]["AOID"];
                    isnano = (Int32)dt.Rows[0]["IsNano"];
                    QL = (Int32)dt.Rows[0]["QL"];
                    itemtype = (Int32)dt.Rows[0]["ItemType"];
                    byte[] blob = (byte[])dt.Rows[0]["EFR"];

                    int blobc = 0;

                    // Read Attack Stat/Values
                    int cc = BitConverter.ToInt32(blob, blobc);
                    AOItemAttribute mm_a;
                    blobc += 4;
                    while (cc > 0)
                    {
                        mm_a = new AOItemAttribute();
                        mm_a.Stat = BitConverter.ToInt32(blob, blobc);
                        blobc += 4;
                        mm_a.Value = BitConverter.ToInt32(blob, blobc);
                        blobc += 4;
                        attack.Add(mm_a);
                        cc--;
                    }

                    // Read Defend Stat/Values
                    cc = BitConverter.ToInt32(blob, blobc);
                    blobc += 4;
                    while (cc > 0)
                    {
                        mm_a = new AOItemAttribute();
                        mm_a.Stat = BitConverter.ToInt32(blob, blobc);
                        blobc += 4;
                        mm_a.Value = BitConverter.ToInt32(blob, blobc);
                        blobc += 4;
                        defend.Add(mm_a);
                        cc--;
                    }

                    // Read Item Attributes
                    int c = BitConverter.ToInt32(blob, blobc);
                    blobc += 4;

                    AOItemAttribute tempa;
                    while (c > 0)
                    {
                        tempa = new AOItemAttribute();
                        tempa.Stat = BitConverter.ToInt32(blob, blobc);
                        blobc += 4;
                        tempa.Value = BitConverter.ToInt32(blob, blobc);
                        blobc += 4;
                        ItemAttributes.Add(tempa);
                        c--;
                    }

                    // Read Item Events
                    AOEvents tempe;
                    c = BitConverter.ToInt32(blob, blobc);
                    blobc += 4;
                    while (c > 0)
                    {
                        tempe = new AOEvents();
                        blobc = tempe.readEventfromBlob(ref blob, blobc);
                        ItemEvents.Add(tempe);
                        c--;
                    }

                    /*                    // Read Item Actions
                                        AOActions tempac;
                                        c = BitConverter.ToInt32(blob, blobc);
                                        blobc += 4;
                                        while (c > 0)
                                        {
                                            tempac = new AOActions();
                                            blobc = tempac.readActionfromBlob(ref blob, blobc);
                                            c--;
                                        }
                     */
                }
                else
                {
                    // Setting QL to -1 as "invalid item" flag
                    QL = -1;
                }
            }
Exemple #9
0
        /// <summary>
        /// The parse atk def set.
        /// </summary>
        /// <param name="attackstat">
        /// The attackstat.
        /// </param>
        /// <param name="defstat">
        /// The defstat.
        /// </param>
        private void ParseAtkDefSet(List <AOItemAttribute> attackstat, List <AOItemAttribute> defstat)
        {
            List <AOItemAttribute> list  = new List <AOItemAttribute>();
            List <AOItemAttribute> list2 = new List <AOItemAttribute>();

            this.br.Skip(4);
            int num2 = this.br.Read3F1(); // Number of Attack/Defense Stat members
            int num3 = 1;

            checked
            {
                while (true)
                {
                    if (num3 > num2)
                    {
                        break;
                    }

                    int value           = this.br.ReadInt32();
                    int numberOfMembers = this.br.Read3F1();
                    int num7            = 1;
                    while (true)
                    {
                        if (num7 > numberOfMembers)
                        {
                            break;
                        }
                        try
                        {
                            AOItemAttribute attack = new AOItemAttribute();
                            attack.Stat  = this.br.ReadInt32();
                            attack.Value = this.br.ReadInt32();

                            if (value == 12)
                            {
                                list.Add(attack);
                                num7++;
                            }

                            if (value == 13)
                            {
                                list2.Add(attack);
                                num7++;
                            }
                        }
                        catch (Exception)
                        {
                            num7++;
                        }
                    }

                    num3++;
                }

                foreach (AOItemAttribute ua in list)
                {
                    attackstat.Add(ua);
                }

                foreach (AOItemAttribute ua in list2)
                {
                    defstat.Add(ua);
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// The parse nano.
        /// </summary>
        /// <param name="rectype">
        /// The rectype.
        /// </param>
        /// <param name="recnum">
        /// The recnum.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        /// <param name="sqlFile">
        /// The sql file.
        /// </param>
        /// <returns>
        /// The <see cref="AONanos"/>.
        /// </returns>
        public AONanos ParseNano(int rectype, int recnum, byte[] data, string sqlFile)
        {
            this.br = new BufferedReader(rectype, recnum, data);
            AONanos aon = new AONanos();

            aon.ID = recnum;
            Console.Write("\rNano ID: " + recnum);
            this.br.Skip(16);

            int numberOfAttributes = this.br.Read3F1() - 1;
            int counter            = 0;

            while (true)
            {
                if (counter > numberOfAttributes)
                {
                    break;
                }

                int attrkey = this.br.ReadInt32();
                int attrval = this.br.ReadInt32();
                if (attrkey == 54)
                {
                    aon.NCUCost = attrval;
                    AOItemAttribute aoia = new AOItemAttribute();
                    aoia.Stat  = attrkey;
                    aoia.Value = attrval;
                    aon.Stats.Add(aoia);
                }
                else
                {
                    AOItemAttribute aoia = new AOItemAttribute();
                    aoia.Stat  = attrkey;
                    aoia.Value = attrval;
                    aon.Stats.Add(aoia);
                }

                counter++;
            }

            this.br.Skip(8);

            short nameLength        = this.br.ReadInt16();
            short descriptionLength = this.br.ReadInt16();

            if (nameLength > 0)
            {
                this.br.ReadString(nameLength);
            }

            if (descriptionLength > 0)
            {
                this.br.ReadString(descriptionLength); // Read and discard Description
            }

            bool flag4 = true;

            checked
            {
                while (this.br.Ptr < this.br.Buffer.Length - 8 && flag4)
                {
                    switch (this.br.ReadInt32())
                    {
                    case 2:
                        this.ParseFunctionSet(aon.Events);
                        break;

                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 13:
                    case 15:
                    case 16:
                    case 17:
                    case 18:
                    case 19:
                    case 21:
                        goto IL_4BF;

                    case 4:
                        this.ParseAtkDefSet(aon.Attack, aon.Defend);
                        break;

                    case 6:
                    {
                        this.br.Skip(4);
                        int count = this.br.Read3F1() * 8;
                        this.br.Skip(count);
                        break;
                    }

                    case 14:
                        this.ParseAnimSoundSet(1, null);
                        break;

                    case 20:
                        this.ParseAnimSoundSet(2, null);
                        break;

                    case 22:
                        this.ParseActionSet(aon.Actions);
                        break;

                    case 23:
                        this.ParseShopHash(aon.Events);
                        break;

                    default:
                        goto IL_4BF;
                    }

                    continue;
IL_4BF:
                    flag4 = false;
                }
            }

            return(aon);
        }
Exemple #11
0
        /// <summary>
        /// The parse item.
        /// </summary>
        /// <param name="rectype">
        /// The rectype.
        /// </param>
        /// <param name="recnum">
        /// The recnum.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        /// <param name="sqlFile">
        /// The sql file.
        /// </param>
        /// <returns>
        /// The <see cref="AOItem"/>.
        /// </returns>
        public AOItem ParseItem(int rectype, int recnum, byte[] data, List <string> itemnamessql)
        {
            this.br = new BufferedReader(rectype, recnum, data);
            AOItem aoi = new AOItem();

            aoi.LowID  = recnum;
            aoi.HighID = recnum;
            Console.Write("\rItem ID: " + recnum);
            this.br.Skip(16);

            int num   = this.br.Read3F1();
            int argc0 = 0;

            int num2 = num - 1;
            int num3 = argc0;

            while (true)
            {
                int arg1c2 = num3;
                int num4   = num2;
                if (arg1c2 > num4)
                {
                    break;
                }

                int attrkey = this.br.ReadInt32();
                int attrval = this.br.ReadInt32();
                if (attrkey == 54)
                {
                    aoi.Quality = attrval;
                }
                else
                {
                    AOItemAttribute aoia = new AOItemAttribute();
                    aoia.Stat  = attrkey;
                    aoia.Value = attrval;
                    aoi.Stats.Add(aoia);
                }

                num3++;
            }

            this.br.Skip(8);

            short  num5     = this.br.ReadInt16();
            short  num6     = this.br.ReadInt16();
            string itemname = string.Empty;

            if (num5 > 0)
            {
                itemname = this.br.ReadString(num5);
            }


            if (itemnamessql != null)
            {
                itemnamessql.Add("(" + recnum + ",'" + itemname.Replace("'", "''") + "')");
            }

            if (num6 > 0)
            {
                this.br.ReadString(num6); // Read and discard Description
            }

            bool flag4 = true;

            checked
            {
                while (this.br.Ptr < this.br.Buffer.Length - 8 && flag4)
                {
                    switch (this.br.ReadInt32())
                    {
                    case 2:
                        this.ParseFunctionSet(aoi.Events);
                        break;

                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 13:
                    case 15:
                    case 16:
                    case 17:
                    case 18:
                    case 19:
                    case 21:
                        goto IL_4BF;

                    case 4:
                        this.ParseAtkDefSet(aoi.Attack, aoi.Defend);
                        break;

                    case 6:
                    {
                        this.br.Skip(4);
                        int count = this.br.Read3F1() * 8;
                        this.br.Skip(count);
                        break;
                    }

                    case 14:
                        this.ParseAnimSoundSet(1, aoi);
                        break;

                    case 20:
                        this.ParseAnimSoundSet(2, aoi);
                        break;

                    case 22:
                        this.ParseActionSet(aoi.Actions);
                        break;

                    case 23:
                        this.ParseShopHash(aoi.Events);
                        break;

                    default:
                        goto IL_4BF;
                    }

                    continue;
IL_4BF:
                    flag4 = false;
                }
            }

            return(aoi);
        }