Beispiel #1
0
        public static void Read(byte[] packet, Client client)
        {
            PacketReader packetReader = new PacketReader(packet);

            Header header = packetReader.PopHeader();

            packetReader.PopByte();
            packetReader.PopShort();
            Identity identity = packetReader.PopIdentity();

            NonPlayerCharacterClass npc =
                (NonPlayerCharacterClass)FindDynel.FindDynelById(identity.Type, identity.Instance);
            Character character = FindClient.FindClientById(header.Sender).Character;

            packetReader.PopInt();
            packetReader.PopInt();
            packetReader.PopInt();
            int container = packetReader.PopInt();
            int place     = packetReader.PopInt();

            InventoryEntries ie  = character.GetInventoryAt(place);
            AOItem           aoi = ie.Item.ShallowCopy();

            character.Inventory.Remove(ie); // Silent remove, no message given to client. Client handles this on its own
            npc.KnuBotTrade(character, aoi);
        }
Beispiel #2
0
 public void KnuBotTrade(Character character, AOItem item)
 {
     if (this.KnuBot != null)
     {
         this.KnuBot.KnuBotTrade(character, item);
     }
 }
Beispiel #3
0
    public void Refresh(AOItemEntity ie, AOUIItemList l)
    {
        list   = l;
        entity = ie;
        var item = AOItem.ViewItem(ie.id);

        nameText.text   = item.name;
        icon.sprite     = item.icon;
        numberText.text = entity.amount.ToString();
    }
Beispiel #4
0
        public bool LoadTemplate(int id)
        {
            AOItem it = ItemHandler.GetItemTemplate(id);

            foreach (AOItemAttribute ia in it.Stats)
            {
                this.Stats.SetStatValueByName(ia.Stat, (uint)ia.Value);
            }
            this.FillInventory();
            return(true);
        }
Beispiel #5
0
        public void Create(int templateId)
        {
            AOItem i = ItemHandler.GetItemTemplate(templateId);
            int    c;

            for (c = 0; c < i.Stats.Count; c++)
            {
                this.Stats.SetStatValueByName(i.Stats[c].Stat, (uint)i.Stats[c].Value);
            }
            // TODO i.applyon(this, ItemHandler.eventtype_ontrade, false, false, 0);
            // eventtype_ontrade? Why?
        }
Beispiel #6
0
        public void SpawnItem(int lowid, int highid, int ql)
        {
            // TODO: Add check for full inventory!
            InventoryEntries mi = new InventoryEntries();
            AOItem           it = ItemHandler.interpolate(lowid, highid, ql);

            mi.Item      = it;
            mi.Container = 104;
            mi.Placement = this.TalkingTo.GetNextFreeInventory(104);
            this.TalkingTo.Inventory.Add(mi);
            AddTemplate.Send(this.TalkingTo.Client, mi);
        }
Beispiel #7
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);
            }
        }
Beispiel #8
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");
                }
            }
        }
Beispiel #9
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);
            }
        }
Beispiel #10
0
    public void UseItem()
    {
        var i = AOItem.ViewItem(currentItem.id);

        if (i is AOPropertyDeltaItem)
        {
            (i as AOPropertyDeltaItem).Use(AOGame.Instance.PlayerData);
            currentItem.amount--;
            if (currentItem.amount < 1)
            {
                AOGame.Instance.PlayerData.Items.Remove(currentItem.id);
                ViewItem(null);
            }
            GetComponentInParent <AOUIItemList>().RefreshItems();
        }
    }
Beispiel #11
0
        public static void TradeSkillTargetChanged(Client client, int container, int placement)
        {
            if (container != 0 && placement != 0)
            {
                TradeSkillInfos.Add(new TradeSkillInfo(client, 1, container, placement));

                AOItem it = client.Character.GetInventoryAt(placement).Item;

                TradeskillPacket.SendTarget(client.Character, Tradeskill.TargetProcessesCount(it.HighID));

                var l1 = TradeSkillInfos.Where(m => m.Cli == client && m.Location == 0).Select(m => m);
                var l2 = TradeSkillInfos.Where(m => m.Cli == client && m.Location == 1).Select(m => m);

                if (l1.Count() == 1 && l2.Count() == 1)
                {
                    TradeSkillInfo info1 = l1.ElementAt(0);
                    TradeSkillInfo info2 = l2.ElementAt(0);

                    Tradeskill ts = new Tradeskill(client, info1.Placement, info2.Placement);

                    if (ts.IsTradeSkill)
                    {
                        if (ts.ValidateRange())
                        {
                            foreach (TradeSkillSkillInfo si in ts.Skills)
                            {
                                TradeskillPacket.SendRequirement(client.Character, si);
                            }
                            TradeskillPacket.SendResult(
                                client.Character, ts.MinQL, ts.MaxQL, ts.ResultLowId, ts.ResultHighId);
                        }
                        else
                        {
                            TradeskillPacket.SendOutOfRange(client.Character, ts.sMinQl);
                        }
                    }
                    else
                    {
                        TradeskillPacket.SendNotTradeskill(client.Character);
                    }
                }
            }
            else if (container == 0 && placement == 0)
            {
                TradeSkillInfos.RemoveAll(m => (m.Cli == client) && (m.Location == 1));
            }
        }
Beispiel #12
0
        public override void ExecuteCommand(Client client, Identity target, string[] args)
        {
            int    itemid = Int32.Parse(args[1]);
            AOItem it     = ItemHandler.GetItemTemplate(itemid);

            if (it == null)
            {
                client.SendChatText("No Item with id " + itemid + " found.");
                return;
            }
            client.SendChatText("Item Debug Info for Item " + itemid);
            client.SendChatText("Attack values:");
            foreach (AOItemAttribute at in it.Attack)
            {
                client.SendChatText("Type: " + at.Stat + " Value: " + at.Value);
            }
            client.SendChatText("Defense values:");
            foreach (AOItemAttribute at in it.Defend)
            {
                client.SendChatText("Type: " + at.Stat + " Value: " + at.Value);
            }
            client.SendChatText("Item Attributes:");
            foreach (AOItemAttribute at in it.Stats)
            {
                client.SendChatText("Type: " + at.Stat + " Value: " + at.Value);
            }

            client.SendChatText("Events/Functions:");
            foreach (AOEvents ev in it.Events)
            {
                client.SendChatText("Eventtype: " + ev.EventType);
                foreach (AOFunctions fu in ev.Functions)
                {
                    client.SendChatText("  Functionnumber: " + fu.FunctionType);
                    foreach (object arg in fu.Arguments.Values)
                    {
                        client.SendChatText("    Argument: " + arg);
                    }
                    foreach (AORequirements aor in fu.Requirements)
                    {
                        client.SendChatText(
                            "    Reqs: " + aor.Statnumber + " " + aor.Operator + " " + aor.Value + " "
                            + aor.ChildOperator);
                    }
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// The parse anim sound set.
        /// </summary>
        /// <param name="typeN">
        /// The type n.
        /// </param>
        /// <param name="ITEM">
        /// The item.
        /// </param>
        public void ParseAnimSoundSet(int typeN, AOItem ITEM)
        {
            int num      = this.br.ReadInt32();
            int num2     = this.br.Read3F1();
            int arg_27_0 = 1;
            int num3     = num2;
            int num4     = arg_27_0;

            checked
            {
                while (true)
                {
                    int arg_13B_0 = num4;
                    int num5      = num3;
                    if (arg_13B_0 > num5)
                    {
                        break;
                    }

                    List <int> list      = new List <int>();
                    int        actionNum = this.br.ReadInt32();
                    int        num6      = this.br.Read3F1();
                    int        arg_5C_0  = 1;
                    int        num7      = num6;
                    int        num8      = arg_5C_0;
                    while (true)
                    {
                        int arg_96_0 = num8;
                        num5 = num7;
                        if (arg_96_0 > num5)
                        {
                            break;
                        }

                        int item = this.br.ReadInt32();
                        list.Add(item);
                        num8++;
                    }

                    // TODO: Add to item class
                    num4++;
                }
            }
        }
Beispiel #14
0
        public bool LoadTemplate(string hash)
        {
            SqlWrapper sqlWrapper = new SqlWrapper();
            DataTable  dataTable  = sqlWrapper.ReadDatatable("SELECT * from vendortemplate WHERE HASH='" + hash + "'");

            if (dataTable.Rows.Count > 0)
            {
                this.TemplateId = (Int32)dataTable.Rows[0]["itemtemplate"];
                this.Name       = (string)dataTable.Rows[0]["Name"];
                AOItem item = ItemHandler.GetItemTemplate(this.TemplateId);
                foreach (AOItemAttribute ia in item.Stats)
                {
                    this.Stats.SetStatValueByName(ia.Stat, (uint)ia.Value);
                }
                sqlWrapper.sqlclose();
                this.FillInventory();
                return(true);
            }
            return(false);
        }
Beispiel #15
0
    public void ViewItem(AOItemEntity e)
    {
        if (e == null)
        {
            icon.color    = new Color(0, 0, 0, 0);
            icon.sprite   = null;
            nameText.text = "";
            useButton.SetActive(false);
            return;
        }

        icon.color = Color.white;
        var i = AOItem.ViewItem(e.id);

        currentItem   = e;
        icon.sprite   = i.icon;
        nameText.text = i.name;

        useButton.SetActive(i is AOPropertyDeltaItem);
    }
Beispiel #16
0
        /// <summary>
        /// Transfer Item to bank account
        /// </summary>
        /// <param name="_from">from inventory location</param>
        /// <param name="_to">to bank location</param>
        public void TransferItemtoBank(int _from, int _to)
        {
            lock (this)
            {
                InventoryEntries afrom = getInventoryAt(_from);

                AOItem tobank = new AOItem();
                tobank = afrom.Item.ShallowCopy();
                tobank.flags = GetNextFreeInventory(0x69);
                Inventory.Remove(afrom);
                Bank.Add(tobank);
                writeBankContentstoSQL();
                writeInventorytoSQL();
            }
        }
Beispiel #17
0
        public static void Send(Client cli, AOItem it, int page, int placement)
        {
            PacketWriter equippacket     = new PacketWriter();
            PacketWriter action167packet = new PacketWriter();
            PacketWriter action131packet = new PacketWriter();

            //if (placement == 6)
            switch (placement)
            {
            case 6:     // Right Hand
                /*
                 * // ContainerAddItem Reply
                 * equippacket.PushByte(0xdf);
                 * equippacket.PushByte(0xdf);
                 * equippacket.PushShort(0xa);
                 * equippacket.PushShort(0x1);
                 * equippacket.PushShort(0);
                 * equippacket.PushInt(3086);
                 * equippacket.PushInt(cli.Character.ID);
                 * equippacket.PushInt(0x47537A24);
                 * equippacket.PushInt(50000);
                 * equippacket.PushInt(cli.Character.ID);
                 * equippacket.PushByte(0);
                 * equippacket.PushInt(0x60);
                 * equippacket.PushInt(0x40);
                 * equippacket.PushInt(50000);
                 * equippacket.PushInt(cli.Character.ID);
                 * equippacket.PushInt(0x6);
                 *
                 * byte[] reply = equippacket.Finish();
                 * cli.SendCompressed(reply);
                 */
                // Action 167 Reply
                action167packet.PushByte(0xDF);
                action167packet.PushByte(0xDF);
                action167packet.PushShort(0xA);
                action167packet.PushShort(0x1);
                action167packet.PushShort(0);
                action167packet.PushInt(3086);
                action167packet.PushInt(cli.Character.Id);
                action167packet.PushInt(0x5E477770);
                action167packet.PushInt(50000);
                action167packet.PushInt(cli.Character.Id);
                action167packet.PushByte(0);
                action167packet.PushInt(0xA7);
                action167packet.PushInt(0);
                action167packet.PushInt(0);
                action167packet.PushInt(0);
                action167packet.PushInt(0);
                action167packet.PushInt(0);
                action167packet.PushShort(0);

                byte[] replyAction167 = action167packet.Finish();
                cli.SendCompressed(replyAction167);

                // Action 131 Reply
                action131packet.PushByte(0xDF);
                action131packet.PushByte(0xDF);
                action131packet.PushShort(0xA);
                action131packet.PushShort(0x1);
                action131packet.PushShort(0);
                action131packet.PushInt(3086);
                action131packet.PushInt(cli.Character.Id);
                action131packet.PushInt(0x5E477770);
                action131packet.PushInt(50000);
                action131packet.PushInt(cli.Character.Id);
                action131packet.PushByte(0);
                action131packet.PushInt(0x83);
                action131packet.PushInt(0);
                action131packet.PushInt(0xC74A);
                action131packet.PushInt(0x4598815B);
                action131packet.PushInt(0);
                action131packet.PushInt(0x06);
                action131packet.PushShort(0);

                byte[] replyAction131 = action131packet.Finish();
                cli.SendCompressed(replyAction131);

                break;

            default:
                // Default Template Action
                equippacket.PushByte(0xdf);
                equippacket.PushByte(0xdf);
                equippacket.PushShort(0xa);
                equippacket.PushShort(0x1);
                equippacket.PushShort(0);
                equippacket.PushInt(3086);
                equippacket.PushInt(cli.Character.Id);
                equippacket.PushInt(0x35505644);
                equippacket.PushInt(50000);
                equippacket.PushInt(cli.Character.Id);
                equippacket.PushByte(0);
                equippacket.PushInt(it.LowID);
                equippacket.PushInt(it.HighID);
                equippacket.PushInt(it.Quality);
                equippacket.PushInt(1);
                if ((placement >= 49) && (placement <= 63))
                {
                    equippacket.PushInt(7);
                }
                else
                {
                    equippacket.PushInt(6);
                }
                equippacket.PushInt(page);
                equippacket.PushInt(placement);
                equippacket.PushInt(0);
                equippacket.PushInt(0);

                byte[] defaultReply = equippacket.Finish();
                if (!((placement >= 49) && (placement <= 63)))
                {
                    cli.SendCompressed(defaultReply);
                }
                break;
            }
        }
Beispiel #18
0
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="packet">
        /// The packet.
        /// </param>
        /// <param name="client">
        /// The client.
        /// </param>
        /// <param name="dynel">
        /// The dynel.
        /// </param>
        public static void Read(byte[] packet, Client client, Dynel dynel)
        {
            sender = client;
            PacketReader packetReader = new PacketReader(packet);

            packetReader.PopHeader();
            packetReader.PopByte();
            temp1  = packetReader.PopInt();
            count  = packetReader.PopInt(); // Count of commands sent
            action = packetReader.PopInt();
            temp4  = packetReader.PopInt();
            user   = packetReader.PopIdentity();
            target = packetReader.PopIdentity();
            packetReader.Finish();
            bool feedback = true;

            switch (action)
            {
            case 1:

                // Get
                break;

            case 2:

                // Drop
                break;

            case 3:

                // Use
                OnUse();
                AOCoord newcoord = client.Character.Coordinates;
                feedback = false;

                if (Statels.StatelppfonUse.ContainsKey(client.Character.PlayField))
                {
                    foreach (Statels.Statel s in Statels.StatelppfonUse[client.Character.PlayField])
                    {
                        if (s.onUse(client, target))
                        {
                            return;
                        }
                    }
                }

                bool teleport  = false;
                int  playfield = 152;
                switch (target.Instance)
                {
                // Need to add feedback to the character
                // Are the Newer Grid points in this list???
                // No newer Grid points in list, will be replaced by a check against a list of statels read from rdb anyway
                // - Algorithman
                case -1073605919:         // Teleport Tower(noobisland)(right)
                    if (client.Character.Stats.Side.Value != 2)
                    {
                        client.SendChatText("You need to be omni to use this teleporter!");
                        teleport = false;
                    }
                    else
                    {
                        newcoord.x = 202;
                        newcoord.z = 878;
                        newcoord.y = 16;
                        playfield  = 687;
                    }

                    break;

                case -1073736991:         // Teleport Tower(noobisland)(left)
                    if (client.Character.Stats.Side.Value != 1)
                    {
                        client.SendChatText("You need to be clan to use this teleporter!");
                        teleport = false;
                    }
                    else
                    {
                        newcoord.x = 390;
                        newcoord.z = 340;
                        newcoord.y = 0;
                        playfield  = 545;
                    }

                    break;

                case -1073671455:         // Teleport Tower(noobisland)(middle)
                    if (client.Character.Stats.Side.Value != 0)
                    {
                        client.SendChatText("You need to be neutral to use this teleporter!");
                        teleport = false;
                    }
                    else
                    {
                        newcoord.x = 685;
                        newcoord.z = 480;
                        newcoord.y = 73;
                        playfield  = 800;
                    }

                    break;

                case -1073741189:         // 2ho -> Stret west
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 1143;
                        newcoord.z = 541;
                        newcoord.y = 8;
                        playfield  = 790;
                    }

                    break;

                case -1073478890:         // Stret West -> 2ho
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 760;
                        newcoord.z = 1982;
                        newcoord.y = 7;
                        playfield  = 635;
                    }

                    break;

                case -1073216841:         // Harry's -> Plesant Meadows
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 370;
                        newcoord.z = 1564;
                        newcoord.y = 7;
                        playfield  = 630;
                    }

                    break;

                case -1073216906:         // Plesant Meadows -> Harry's
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 3196;
                        newcoord.z = 3172;
                        newcoord.y = 7;
                        playfield  = 695;
                    }

                    break;

                case -1073282442:         // Pleasant Meadows -> Omni-Tek outpost in Lush Fields
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 3389;
                        newcoord.z = 800;
                        newcoord.y = 8;
                        playfield  = 695;
                    }

                    break;

                case -1073413449:         // Omni-Tek outpost in Lush Fields -> Pleasant Meadows
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 370;
                        newcoord.z = 1562;
                        newcoord.y = 7;
                        playfield  = 630;
                    }

                    break;

                case -1073347913:         // Harry's trading outpost -> Omni-1 Trade (free)
                    newcoord.x = 3569;
                    newcoord.z = 912;
                    newcoord.y = 9;
                    playfield  = 695;
                    break;

                case -1073282377:         // Omni-1 Trade -> Harry's trading outpost (free)
                    newcoord.x = 3290;
                    newcoord.z = 2922;
                    newcoord.y = 7;
                    playfield  = 695;
                    break;

                default:
                    feedback = true;
                    teleport = false;
                    break;
                }

                if (teleport)
                {
                    client.Teleport(newcoord, client.Character.Heading, playfield);
                }

                // Use item in inventory
                if (target.Type == 104)
                {
                    InventoryEntries ie = client.Character.GetInventoryAt(target.Instance);
                    AOItem           mi = ItemHandler.GetItemTemplate(ie.Item.LowID);

                    // TODO mi.applyon(client.Character, ItemHandler.eventtype_onuse, true, false, ie.Placement);
                    TemplateAction.Send(client.Character, ie);
                    if (mi.isConsumable())
                    {
                        ie.Item.MultipleCount--;
                        if (ie.Item.MultipleCount <= 0)
                        {
                            client.Character.Inventory.Remove(ie);
                            DeleteItem.Send(client.Character, ie.Container, ie.Placement);

                            // Packets.Stat.Set(client, 0, client.Character.Stats.GetStat(0),false);
                        }
                    }

                    foreach (AOEvents aoe in mi.Events)
                    {
                        if (aoe.EventType == Constants.EventtypeOnUse)
                        {
                            sender.Character.ExecuteEvent(
                                sender.Character, sender.Character, aoe, true, false, 0, CheckReqs.doCheckReqs);
                            SkillUpdate.SendStat(client, 0x209, client.Character.Stats.SocialStatus.Value, false);

                            // Social Status
                            return;
                        }
                    }

                    int    le    = packet[7] + packet[6] * 256;
                    byte[] reply = new byte[le];
                    Array.Copy(packet, reply, le);
                    reply[0]    = 0xdf;
                    reply[1]    = 0xdf;
                    reply[8]    = 0x00;
                    reply[9]    = 0x00;
                    reply[10]   = 0x0C;
                    reply[11]   = 0x0E;
                    reply[12]   = (byte)(client.Character.Id >> 24);
                    reply[13]   = (byte)(client.Character.Id >> 16);
                    reply[14]   = (byte)(client.Character.Id >> 8);
                    reply[15]   = (byte)client.Character.Id;
                    reply[0x1c] = 0;
                    reply[32]   = 1;
                    reply[36]   = 3;

                    PacketWriter pw = new PacketWriter();
                    pw.PushBytes(reply);
                    byte[] rep = pw.Finish();
                    client.SendCompressed(rep);
                    SkillUpdate.SendStat(client, 0x209, client.Character.Stats.SocialStatus.Value, false);

                    // Social Status
                    return;
                }
                else if (target.Type == 51035)
                {
                    // Shops
                    VendingMachine vm = VendorHandler.GetVendorById(target.Instance);
                    ShopInventory.Send(client, vm);
                    Trade.Send(client, client.Character, vm);
                    Trade.Send(client, vm, client.Character);
                    Trade.Send(client, vm, client.Character);
                    int    le    = packet[7] + packet[6] * 256;
                    byte[] reply = new byte[le];
                    Array.Copy(packet, reply, le);
                    reply[0]    = 0xdf;
                    reply[1]    = 0xdf;
                    reply[8]    = 0x00;
                    reply[9]    = 0x00;
                    reply[10]   = 0x0C;
                    reply[11]   = 0x0E;
                    reply[12]   = (byte)(client.Character.Id >> 24);
                    reply[13]   = (byte)(client.Character.Id >> 16);
                    reply[14]   = (byte)(client.Character.Id >> 8);
                    reply[15]   = (byte)client.Character.Id;
                    reply[0x1c] = 0;
                    reply[0x20] = 1;

                    client.Character.LastTrade = target;

                    PacketWriter pw = new PacketWriter();
                    pw.PushBytes(reply);
                    byte[] rep = pw.Finish();
                    client.SendCompressed(rep);
                }
                else if (target.Type == 51050)
                {
                    // Open corpse
                }

                break;

            case 4:

                // Repair
                break;

            case 5:

                // UseItemOnItem
#if DEBUG
                Console.WriteLine("Use Item on Item not defined yet");
                Console.WriteLine("Packet data:");
                string line   = string.Empty;
                int    count2 = 0;
                foreach (byte packbyte in packet)
                {
                    if ((count2 % 16) == 0)
                    {
                        Console.WriteLine(line);
                        line = string.Empty;
                    }

                    line = line + packbyte.ToString("X2") + " ";
                    count2++;
                }

                if (line != string.Empty)
                {
                    Console.WriteLine();
                }

                Console.WriteLine(line);
#endif
                break;

            default:
                break;
            }

            if (feedback)
            {
#if DEBUG
                string Feedback1 = string.Format("T1 {0}, Count {1}, Action {2}, T4 {3}", temp1, count, action, temp4);
                string Feedback2 = string.Format(
                    "User {0}:{1}, Target {2}:{3} ({4}:{5})",
                    user.Type,
                    user.Instance,
                    target.Type,
                    (uint)target.Instance,
                    target.Type.ToString("X4"),
                    ((uint)target.Instance).ToString("X8"));
                Statels.Statel b = null;
                if (Statels.Statelppf.ContainsKey(client.Character.PlayField))
                {
                    foreach (Statels.Statel z in Statels.Statelppf[client.Character.PlayField])
                    {
                        if ((z.Type == target.Type) && ((Int32)z.Instance == target.Instance))
                        {
                            b = z;
                            break;
                        }
                    }
                }

                if (b != null)
                {
                    foreach (Statels.StatelEvent e in b.Events)
                    {
                        Console.WriteLine("DebugOutput: \r\n" + e);
                    }

                    Console.WriteLine(b.Coordinates.ToString());
                }
                else
                {
                    Console.WriteLine(
                        "No Statel defined in database for #" + target.Type + ":" + (UInt32)target.Instance + " ("
                        + target.Type.ToString("X4") + ":" + target.Instance.ToString("X8") + ")");
                }

                client.SendChatText(Feedback1);
                client.SendChatText(Feedback2);
#endif
            }
        }
        public Tradeskill(Client client, int srcLocation, int targetLocation)
        {
            this.client = client;
            this.sourcePlacement = srcLocation;
            this.targetPlacement = targetLocation;
            this.source = this.client.Character.GetInventoryAt(srcLocation).Item;
            this.target = this.client.Character.GetInventoryAt(targetLocation).Item;

            this.SourceID = this.source.HighID;
            this.TargetID = this.target.HighID;

            this.IsTradeSkill = false;

            SqlWrapper wrapper = new SqlWrapper();
            DataTable dt =
                wrapper.ReadDatatable(
                    "SELECT * FROM tradeskill WHERE ID1 = " + this.source.HighID + " AND ID2 = " + this.target.HighID
                    + ";");
            wrapper.Dispose();
            DataRowCollection drc = dt.Rows;

            if (drc.Count > 0)
            {
                this.IsTradeSkill = true;

                this.sourceName = GetItemName(this.source.LowID, this.source.HighID, this.source.Quality);
                this.targetName = GetItemName(this.target.LowID, this.target.HighID, this.target.Quality);

                this.TargetMinQL = (int)drc[0][2];

                List<int> itemids = new List<int>();

                string[] ItemIDS = ((string)drc[0][3]).Split(',');
                foreach (string id in ItemIDS)
                {
                    itemids.Add(Convert.ToInt32(id.Trim()));
                }

                for (int i = 0; i < itemids.Count / 2; i++)
                {
                    int lowid = itemids.ElementAt(i * 2);
                    int highid = itemids.ElementAt(i * 2 + 1);
                    int lowql = ItemHandler.interpolate(lowid, highid, 1).Quality;
                    int highql = ItemHandler.interpolate(lowid, highid, 300).Quality;
                    this.resultProperties.Add(new TradeSkillResultInfo(lowql, highql, lowid, highid));
                }

                this.rangePercent = (int)drc[0][4];
                this.deleteFlag = (int)drc[0][5];
                string skill = (string)drc[0][6];
                string skillpercent = (string)drc[0][7];
                string skillperbump = (string)drc[0][8];
                this.maxBump = (int)drc[0][9];
                this.minXP = (int)drc[0][10];
                this.maxXP = (int)drc[0][11];
                int isImplant = (int)drc[0][12];

                this.isDeleteSource = ((this.deleteFlag & 1) == 1);
                this.isDeleteTarget = (((this.deleteFlag >> 1) & 1) == 1);

                string[] skills = skill.Split(',');
                string[] skillpercents = skillpercent.Split(',');
                string[] skillperbumps = skillperbump.Split(',');

                this.Skills = new List<TradeSkillSkillInfo>();

                if (skills[0] != string.Empty)
                {
                    for (int i = 0; i < skills.Count(); ++i)
                    {
                        if (skills[0].Trim() != string.Empty)
                        {
                            this.Skills.Add(
                                new TradeSkillSkillInfo(
                                    Convert.ToInt32(skills[i]),
                                    Convert.ToInt32(skillpercents[i]),
                                    Convert.ToInt32(skillperbumps[i]),
                                    this.client.Character.Stats.GetStatbyNumber(Convert.ToInt32(skills[i])).Value,
                                    (int)Math.Ceiling(Convert.ToInt32(skillpercents[i]) / 100M * this.target.Quality),
                                    StatsList.GetStatName(Convert.ToInt32(skills[i]))));
                        }
                    }
                }

                int leastBump = 0;

                if (isImplant > 0)
                {
                    if (this.target.Quality >= 250)
                    {
                        this.maxBump = 5;
                    }
                    else if (this.target.Quality >= 201)
                    {
                        this.maxBump = 4;
                    }
                    else if (this.target.Quality >= 150)
                    {
                        this.maxBump = 3;
                    }
                    else if (this.target.Quality >= 100)
                    {
                        this.maxBump = 2;
                    }
                    else if (this.target.Quality >= 50)
                    {
                        this.maxBump = 1;
                    }
                    else
                    {
                        this.maxBump = 0;
                    }
                }

                foreach (TradeSkillSkillInfo skillinfo in this.Skills)
                {
                    if (skillinfo.PerBump != 0)
                    {
                        leastBump = Math.Min(
                            (skillinfo.Value - skillinfo.Requirement) / skillinfo.PerBump, this.maxBump);
                    }
                }

                this.MinQL = this.target.Quality;
                this.MaxQL = Math.Min(
                    this.target.Quality + leastBump,
                    ItemHandler.interpolate(
                        this.resultProperties.ElementAt(this.resultProperties.Count - 1).LowID,
                        this.resultProperties.ElementAt(this.resultProperties.Count - 1).HighID,
                        300).Quality);

                this.Quality = this.MaxQL;

                this.SetResultIDS(this.Quality);
                this.resultName = GetItemName(this.ResultLowId, this.ResultHighId, this.Quality);
            }
        }
Beispiel #20
0
 public void AddItemToInventory(AOItem item)
 {
     // TODO: Check for full inventory/open overflow
     int nextfreespot = this.GetNextFreeInventory(0x68); // Main inventory
     InventoryEntries ie = new InventoryEntries();
     ie.Container = 0x68;
     ie.Item = item.ShallowCopy();
     ie.Placement = nextfreespot;
     this.inventory.Add(ie);
 }
Beispiel #21
0
        /// <summary>
        /// Unequip item
        /// </summary>
        /// <param name="it">Item</param>
        /// <param name="ch">Character</param>
        /// <param name="fromsocialtab">unequip from social tab?</param>
        /// <param name="location">Location</param>
        public void UnequipItem(AOItem it, Character ch, bool fromsocialtab, int location)
        {
            this.CalculateSkills();
            return;
            /* lock (ch)
            {
                int counter = 0;
                int f;

                // Set Weaponmesh
                if (it.ItemType == Constants.itemtype_Weapon)
                {
                    counter = 0;
                    f = -1;
                    while (counter < it.Stats.Count)
                    {
                        if (it.Stats[counter].Stat == 209)
                        {
                            f = counter;
                            break;
                        }
                        counter++;
                    }
                    if (f != -1)
                    {
                        if (!fromsocialtab)
                        {
                            if (location == 6)
                            {
                                Stats.WeaponMeshRight.Set(0); // Weaponmesh
                                ch.MeshLayer.RemoveMesh(2, it.Stats[f].Stat, 0, Misc.MeshLayers.GetLayer(location));
                            }
                            else
                            {
                                Stats.WeaponMeshLeft.Set(0);
                                ch.MeshLayer.RemoveMesh(2, it.Stats[f].Stat, 0, Misc.MeshLayers.GetLayer(location));
                            }
                        }
                        else
                        {
                            if (location == 61)
                            {
                                ch.SocialMeshLayer.RemoveMesh(2, it.Stats[f].Stat, 0, Misc.MeshLayers.GetLayer(location));
                            }
                            else
                            {
                                ch.SocialMeshLayer.RemoveMesh(2, it.Stats[f].Stat, 0, Misc.MeshLayers.GetLayer(location));
                            }
                        }
                    }
                }
            }
             */
        }
Beispiel #22
0
        /// <summary>
        /// Fake equip, don't pass effects to local stats
        /// </summary>
        /// <param name="it">Item</param>
        /// <param name="ch">Character</param>
        /// <param name="tosocialtab">should it be equipped to social tab</param>
        /// <param name="location">Location</param>
        public void FakeEquipItem(AOItem it, Character ch, bool tosocialtab, int location)
        {
            int counter = 0;
            int f;
            lock (ch)
            {
                while (counter < it.Events.Count)
                {
                    if (it.Events[counter].EventType == Constants.EventtypeOnWear)
                    {
                        this.ExecuteEvent(
                            this, this, it.Events[counter], false, tosocialtab, location, CheckReqs.doEquipCheckReqs);
                    }
                    counter++;
                }

                // TODO check if still needed
                // Set Weaponmesh
                // Todo: another packet has to be sent, defining how to hold the weapon
                if (it.ItemType == Constants.itemtype_Weapon)
                {
                    this.stats.WeaponsStyle.Value |= it.GetWeaponStyle();
                    if (tosocialtab)
                    {
                        this.stats.WeaponsStyle.Value = it.GetWeaponStyle();
                    }

                    counter = 0;
                    f = -1;
                    while (counter < it.Stats.Count)
                    {
                        if (it.Stats[counter].Stat == 209)
                        {
                            f = counter; // found Weapon mesh attribute
                            break;
                        }
                        counter++;
                    }
                    if (f != -1)
                    {
                        if (!tosocialtab)
                        {
                            if (location == 6)
                            {
                                this.stats.WeaponMeshRight.Set((uint)it.Stats[f].Value); // Weaponmesh
                                this.meshLayer.AddMesh(1, it.Stats[f].Value, 0, 4);
                            }
                            else
                            {
                                this.stats.WeaponMeshLeft.Set((uint)it.Stats[f].Value); // Weaponmesh
                                this.meshLayer.AddMesh(2, it.Stats[f].Value, 0, 4);
                            }
                        }
                        else
                        {
                            if (location == 61)
                            {
                                if (this.SocialTab.ContainsKey(1006))
                                {
                                    this.SocialTab[1006] = it.Stats[f].Value;
                                }
                                else
                                {
                                    this.SocialTab.Add(1006, it.Stats[f].Value);
                                }
                                this.socialMeshLayer.AddMesh(1, it.Stats[f].Value, 0, 4);
                            }
                            else
                            {
                                if (this.SocialTab.ContainsKey(1007))
                                {
                                    this.SocialTab[1007] = it.Stats[f].Value;
                                }
                                else
                                {
                                    this.SocialTab.Add(1007, it.Stats[f].Value);
                                }
                                this.socialMeshLayer.AddMesh(2, it.Stats[f].Value, 0, 4);
                            }
                        }
                    }
                }
            }
        }
Beispiel #23
0
        public static void AddItemToContainer(byte[] packet, Client cli)
        {
            PacketReader packetReader       = new PacketReader(packet);
            bool         noAppearanceUpdate = false;

            /* Container ID's:
             * 0065 Weaponpage
             * 0066 Armorpage
             *  0067 Implantpage
             *  0068 Inventory (places 64-93)
             *  0069 Bank
             *  006B Backpack
             *  006C KnuBot Trade Window
             *  006E Overflow window
             *  006F Trade Window
             *  0073 Socialpage
             *  0767 Shop Inventory
             *  0790 Playershop Inventory
             *  DEAD Trade Window (incoming)
             */

            packetReader.PopInt();
            packetReader.PopInt();
            int sender = packetReader.PopInt();

            packetReader.PopInt();
            packetReader.PopInt();
            Identity fromIdentity = packetReader.PopIdentity();
            byte     flag         = packetReader.PopByte();
            int      c350         = fromIdentity.Type;
            int      fromId       = fromIdentity.Instance;

            int      fromContainerID = packetReader.PopInt();
            int      fromPlacement   = packetReader.PopInt();
            Identity toIdentity      = packetReader.PopIdentity();
            int      toid            = toIdentity.Instance;

            c350 = toIdentity.Type;
            int toPlacement = packetReader.PopInt();

            int counterFrom = 0;

            if ((fromContainerID <= 0x68) || (fromContainerID == 0x73)) // Inventory or Equipmentpages?
            {
                for (counterFrom = 0;
                     (counterFrom < cli.Character.Inventory.Count) &&
                     (fromPlacement != cli.Character.Inventory[counterFrom].Placement);
                     counterFrom++)
                {
                    ;
                }
            }
            else
            {
                if (fromContainerID == 0x69)
                {
                    for (counterFrom = 0;
                         (counterFrom < cli.Character.Bank.Count) &&
                         (fromPlacement != cli.Character.Bank[counterFrom].Flags);
                         counterFrom++)
                    {
                        ;
                    }
                }
                else
                {
                    counterFrom = -1;
                }
            }

            // TODO: Add check for instanced items (fromcontainerid:fromplacement)
            if (counterFrom == -1)
            {
                return;
            }

            int counterTo;

            if (toIdentity.Type == 0xdead) // Transferring to a trade window??? (only bank trade window yet)
            {
                counterTo = cli.Character.Bank.Count;
            }
            else
            {
                for (counterTo = 0;
                     (counterTo < cli.Character.Inventory.Count) &&
                     (toPlacement != cli.Character.Inventory[counterTo].Placement);
                     counterTo++)
                {
                    ;
                }
            }

            AOItem itemFrom = null;

            if (counterFrom < cli.Character.Inventory.Count)
            {
                itemFrom = ItemHandler.interpolate(
                    cli.Character.Inventory[counterFrom].Item.LowID,
                    cli.Character.Inventory[counterFrom].Item.HighID,
                    cli.Character.Inventory[counterFrom].Item.Quality);
            }

            AOItem itemTo = null;

            if (counterTo < cli.Character.Inventory.Count)
            {
                itemTo = ItemHandler.interpolate(
                    cli.Character.Inventory[counterTo].Item.LowID,
                    cli.Character.Inventory[counterTo].Item.HighID,
                    cli.Character.Inventory[counterTo].Item.Quality);
            }

            // Calculating delay for equip/unequip/switch gear
            int delay = 0;

            if (itemFrom != null)
            {
                delay += itemFrom.getItemAttribute(211);
            }
            if (itemTo != null)
            {
                delay += itemTo.getItemAttribute(211);
            }
            if (delay == 0)
            {
                delay = 200;
            }
            int counter;

            if (toPlacement == 0x6f) // 0x6f = next free inventory place, we need to send back the actual spot where the item goes
            // something has to be free, client checks for full inventory
            {
                counter = 0;
                int counter2 = 0;
                int counter3 = 0;
                if (toIdentity.Type == 0xdead)
                {
                    while (counter3 == 0)
                    {
                        counter3 = 1;
                        for (counter2 = 0; counter2 < cli.Character.Bank.Count; counter2++)
                        {
                            if (cli.Character.Bank[counter2].Flags == counter) // using flags for placement
                            {
                                counter++;
                                counter3 = 0;
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    counter = 64;
                    while (counter3 == 0)
                    {
                        counter3 = 1;
                        for (counter2 = 0; counter2 < cli.Character.Inventory.Count; counter2++)
                        {
                            if (cli.Character.Inventory[counter2].Placement == counter)
                            {
                                counter++;
                                counter3 = 0;
                                continue;
                            }
                        }
                    }
                }
                toPlacement = counter;
            }

            cli.Character.DoNotDoTimers = true;
            if (toIdentity.Type == 0xdead) // 0xdead only stays for bank at the moment
            {
                cli.Character.TransferItemtoBank(fromPlacement, toPlacement);
                noAppearanceUpdate = true;
            }
            else
            {
                switch (fromContainerID)
                {
                case 0x68:
                    // from Inventory
                    if (toPlacement <= 30)
                    {
                        // to Weaponspage or Armorpage
                        // TODO: Send some animation
                        if (itemTo != null)
                        {
                            cli.Character.UnequipItem(itemTo, cli.Character, false, fromPlacement);
                            // send interpolated item
                            Unequip.Send(cli, itemTo, InventoryPage(toPlacement), toPlacement);
                            // client takes care of hotswap

                            cli.Character.EquipItem(itemFrom, cli.Character, false, toPlacement);
                            Equip.Send(cli, itemFrom, InventoryPage(toPlacement), toPlacement);
                        }
                        else
                        {
                            cli.Character.EquipItem(itemFrom, cli.Character, false, toPlacement);
                            Equip.Send(cli, itemFrom, InventoryPage(toPlacement), toPlacement);
                        }
                    }
                    else
                    {
                        if (toPlacement < 46)
                        {
                            if (itemTo == null)
                            {
                                cli.Character.EquipItem(itemFrom, cli.Character, false, toPlacement);
                                Equip.Send(cli, itemFrom, InventoryPage(toPlacement), toPlacement);
                            }
                        }
                        // Equiping to social page
                        if ((toPlacement >= 49) && (toPlacement <= 63))
                        {
                            if (itemTo != null)
                            {
                                cli.Character.UnequipItem(itemTo, cli.Character, true, fromPlacement);
                                // send interpolated item
                                cli.Character.EquipItem(itemFrom, cli.Character, true, toPlacement);
                            }
                            else
                            {
                                cli.Character.EquipItem(itemFrom, cli.Character, true, toPlacement);
                            }

                            //cli.Character.switchItems(cli, fromplacement, toplacement);
                        }
                    }
                    cli.Character.SwitchItems(fromPlacement, toPlacement);
                    cli.Character.CalculateSkills();
                    noAppearanceUpdate = false;
                    break;

                case 0x66:
                    // from Armorpage
                    cli.Character.UnequipItem(itemFrom, cli.Character, false, fromPlacement);
                    // send interpolated item
                    Unequip.Send(cli, itemFrom, InventoryPage(fromPlacement), fromPlacement);
                    cli.Character.SwitchItems(fromPlacement, toPlacement);
                    cli.Character.CalculateSkills();
                    noAppearanceUpdate = false;
                    break;

                case 0x65:
                    // from Weaponspage
                    cli.Character.UnequipItem(itemFrom, cli.Character, false, fromPlacement);
                    // send interpolated item
                    Unequip.Send(cli, itemFrom, InventoryPage(fromPlacement), fromPlacement);
                    cli.Character.SwitchItems(fromPlacement, toPlacement);
                    cli.Character.CalculateSkills();
                    noAppearanceUpdate = false;
                    break;

                case 0x67:
                    // from Implantpage
                    cli.Character.UnequipItem(itemFrom, cli.Character, false, fromPlacement);
                    // send interpolated item
                    Unequip.Send(cli, itemFrom, InventoryPage(fromPlacement), fromPlacement);
                    cli.Character.SwitchItems(fromPlacement, toPlacement);
                    cli.Character.CalculateSkills();
                    noAppearanceUpdate = true;
                    break;

                case 0x73:
                    cli.Character.UnequipItem(itemFrom, cli.Character, true, fromPlacement);

                    cli.Character.SwitchItems(fromPlacement, toPlacement);
                    cli.Character.CalculateSkills();
                    break;

                case 0x69:
                    cli.Character.TransferItemfromBank(fromPlacement, toPlacement);
                    toPlacement        = 0x6f; // setting back to 0x6f for packet reply
                    noAppearanceUpdate = true;
                    break;

                case 0x6c:
                    // KnuBot Trade Window
                    cli.Character.TransferItemfromKnuBotTrade(fromPlacement, toPlacement);
                    break;

                default:
                    break;
                }
            }
            cli.Character.DoNotDoTimers = false;
            if ((fromPlacement < 0x30) || (toPlacement < 0x30)) // Equipmentpages need delays
            {
                // Delay when equipping/unequipping
                // has to be redone, jumping breaks the equiping/unequiping
                // and other messages have to be done too
                // like heartbeat timer, damage from environment and such
                Thread.Sleep(delay);
            }
            else
            {
                Thread.Sleep(200); //social has to wait for 0.2 secs too (for helmet update)
            }
            SwitchItem.Send(cli, fromContainerID, fromPlacement, toIdentity, toPlacement);
            cli.Character.Stats.ClearChangedFlags();
            if (!noAppearanceUpdate)
            {
                cli.Character.AppearanceUpdate();
            }
            itemFrom = null;
            itemTo   = null;
        }
Beispiel #24
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);
        }
Beispiel #25
0
        static void Main(string[] args)
        {


            SqlWrapper ms = new SqlWrapper();
            DataTable dt = ms.ReadDatatable("SELECT AOID from items order by AOID asc");
            TextWriter output = new StreamWriter(@"items_ser.sql", false);
            int c = 0;
            output.WriteLine("CREATE  TABLE `items_ser` (`AOID` INT NOT NULL ,`Data` BLOB NULL ,PRIMARY KEY (`AOID`) );");
            string fullline = "";
            List<AOItem> lll = new List<AOItem>();
            foreach (DataRow row in dt.Rows)
            {
                MemoryStream m = new MemoryStream();

                ItemHandlerold.Item it = new ItemHandlerold.Item((int)row[0]);
                if ((c % 200) == 0)
                    Console.Write("\r" + it.AOID.ToString() + ":" + c.ToString());
                c++;
                AOItem it2 = new AOItem();
                it2.Flags = (int)it.getItemAttribute(30);
                it2.LowID = it.AOID;
                it2.HighID = it.AOID;
                it2.Instance = 0;
                it2.Type = 0;
                it2.Quality = it.QL;
                it2.Nothing = 0;
                it2.MultipleCount = 1;
                it2.ItemType = it.itemtype;

                foreach (AOItemAttribute aoit in it.attack)
                {
                    it2.Attack.Add(aoit);
                }

                foreach (AOItemAttribute aoit in it.defend)
                {
                    it2.Defend.Add(aoit);
                }

                foreach (AOItemAttribute aoit in it.ItemAttributes)
                {
                    it2.Stats.Add(aoit);
                }
                foreach (AOEvents ev in it.ItemEvents)
                {
                    it2.Events.Add(ev);
                }
                lll.Add(it2);
            }

            BinaryFormatter bf = new BinaryFormatter();
            Stream file = new FileStream("items.dat", FileMode.Create);
            MemoryStream mz = new MemoryStream();
            DeflateStream gz = new DeflateStream(file, CompressionMode.Compress);

            List<AOItem> temp = new List<AOItem>();
            int i = 0;
            while (i < lll.Count)
            {
                temp.Add(lll.ElementAt(i).ShallowCopy());
                i++;
                if (i % 500 == 0)
                {
                    bf.Serialize(mz, temp);
                    temp.Clear();
                }
            }
            bf.Serialize(mz, temp);

            mz.Seek(0, SeekOrigin.Begin);
            mz.CopyTo(gz);

            /*
            foreach (AOItem d in lll)
            {
                bf.Serialize(file, d);
            }
             */

            gz.Flush();
            gz.Close();
            file.Close();
            //output.WriteLine("INSERT INTO items_ser VALUES " + fullline.Substring(0, fullline.Length - 1) + ";");
            output.Close();

        }
Beispiel #26
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);
             }
         }
     }
 }
Beispiel #27
0
 public void KnuBotTrade(Character character, AOItem item)
 {
     this.OnKnuBotTradeEvent(new KnuBotTradeEventArgs(character, item));
 }
Beispiel #28
0
        public static void Send(Client client, AOItem item, int page, int placement)
        {
            // tell the client to remove (07) the item modifiers (AC, skills and so on)
            PacketWriter unequipPacketWriter  = new PacketWriter();
            PacketWriter action97PacketWriter = new PacketWriter();

            //if (placement == 6)
            switch (placement)
            {
            case 6:     // Right Hand
                // Action 97
                action97PacketWriter.PushByte(0xdf);
                action97PacketWriter.PushByte(0xdf);
                action97PacketWriter.PushShort(0xa);
                action97PacketWriter.PushShort(0x1);
                action97PacketWriter.PushShort(0);
                action97PacketWriter.PushInt(3086);
                action97PacketWriter.PushInt(client.Character.Id);
                action97PacketWriter.PushInt(0x5E477770);
                action97PacketWriter.PushInt(50000);
                action97PacketWriter.PushInt(client.Character.Id);
                action97PacketWriter.PushByte(0);
                action97PacketWriter.PushInt(0x61);
                action97PacketWriter.PushInt(0);
                action97PacketWriter.PushInt(0);
                action97PacketWriter.PushInt(0);
                action97PacketWriter.PushInt(0);
                action97PacketWriter.PushInt(0x6);
                action97PacketWriter.PushShort(0);

                byte[] action97Reply = action97PacketWriter.Finish();
                client.SendCompressed(action97Reply);

                break;

            default:
                unequipPacketWriter.PushByte(0xdf);
                unequipPacketWriter.PushByte(0xdf);
                unequipPacketWriter.PushShort(0xa);
                unequipPacketWriter.PushShort(0x1);
                unequipPacketWriter.PushShort(0);
                unequipPacketWriter.PushInt(3086);
                unequipPacketWriter.PushInt(client.Character.Id);
                unequipPacketWriter.PushInt(0x35505644);
                unequipPacketWriter.PushInt(50000);
                unequipPacketWriter.PushInt(client.Character.Id);
                unequipPacketWriter.PushByte(0);
                unequipPacketWriter.PushInt(item.LowID);
                unequipPacketWriter.PushInt(item.HighID);
                unequipPacketWriter.PushInt(item.Quality);
                unequipPacketWriter.PushInt(1);
                unequipPacketWriter.PushInt(7);
                unequipPacketWriter.PushInt(page);
                unequipPacketWriter.PushInt(placement);
                unequipPacketWriter.PushInt(0);
                unequipPacketWriter.PushInt(0);

                byte[] unequipReply = unequipPacketWriter.Finish();
                client.SendCompressed(unequipReply);
                break;
            }
        }
Beispiel #29
0
        public Tradeskill(Client client, int srcLocation, int targetLocation)
        {
            this.client          = client;
            this.sourcePlacement = srcLocation;
            this.targetPlacement = targetLocation;
            this.source          = this.client.Character.GetInventoryAt(srcLocation).Item;
            this.target          = this.client.Character.GetInventoryAt(targetLocation).Item;

            this.SourceID = this.source.HighID;
            this.TargetID = this.target.HighID;

            this.IsTradeSkill = false;

            SqlWrapper wrapper = new SqlWrapper();
            DataTable  dt      =
                wrapper.ReadDatatable(
                    "SELECT * FROM tradeskill WHERE ID1 = " + this.source.HighID + " AND ID2 = " + this.target.HighID
                    + ";");

            wrapper.Dispose();
            DataRowCollection drc = dt.Rows;

            if (drc.Count > 0)
            {
                this.IsTradeSkill = true;

                this.sourceName = GetItemName(this.source.LowID, this.source.HighID, this.source.Quality);
                this.targetName = GetItemName(this.target.LowID, this.target.HighID, this.target.Quality);

                this.TargetMinQL = (int)drc[0][2];

                List <int> itemids = new List <int>();

                string[] ItemIDS = ((string)drc[0][3]).Split(',');
                foreach (string id in ItemIDS)
                {
                    itemids.Add(Convert.ToInt32(id.Trim()));
                }

                for (int i = 0; i < itemids.Count / 2; i++)
                {
                    int lowid  = itemids.ElementAt(i * 2);
                    int highid = itemids.ElementAt(i * 2 + 1);
                    int lowql  = ItemHandler.interpolate(lowid, highid, 1).Quality;
                    int highql = ItemHandler.interpolate(lowid, highid, 300).Quality;
                    this.resultProperties.Add(new TradeSkillResultInfo(lowql, highql, lowid, highid));
                }

                this.rangePercent = (int)drc[0][4];
                this.deleteFlag   = (int)drc[0][5];
                string skill        = (string)drc[0][6];
                string skillpercent = (string)drc[0][7];
                string skillperbump = (string)drc[0][8];
                this.maxBump = (int)drc[0][9];
                this.minXP   = (int)drc[0][10];
                this.maxXP   = (int)drc[0][11];
                int isImplant = (int)drc[0][12];

                this.isDeleteSource = ((this.deleteFlag & 1) == 1);
                this.isDeleteTarget = (((this.deleteFlag >> 1) & 1) == 1);

                string[] skills        = skill.Split(',');
                string[] skillpercents = skillpercent.Split(',');
                string[] skillperbumps = skillperbump.Split(',');

                this.Skills = new List <TradeSkillSkillInfo>();

                if (skills[0] != string.Empty)
                {
                    for (int i = 0; i < skills.Count(); ++i)
                    {
                        if (skills[0].Trim() != string.Empty)
                        {
                            this.Skills.Add(
                                new TradeSkillSkillInfo(
                                    Convert.ToInt32(skills[i]),
                                    Convert.ToInt32(skillpercents[i]),
                                    Convert.ToInt32(skillperbumps[i]),
                                    this.client.Character.Stats.GetStatbyNumber(Convert.ToInt32(skills[i])).Value,
                                    (int)Math.Ceiling(Convert.ToInt32(skillpercents[i]) / 100M * this.target.Quality),
                                    StatsList.GetStatName(Convert.ToInt32(skills[i]))));
                        }
                    }
                }

                int leastBump = 0;

                if (isImplant > 0)
                {
                    if (this.target.Quality >= 250)
                    {
                        this.maxBump = 5;
                    }
                    else if (this.target.Quality >= 201)
                    {
                        this.maxBump = 4;
                    }
                    else if (this.target.Quality >= 150)
                    {
                        this.maxBump = 3;
                    }
                    else if (this.target.Quality >= 100)
                    {
                        this.maxBump = 2;
                    }
                    else if (this.target.Quality >= 50)
                    {
                        this.maxBump = 1;
                    }
                    else
                    {
                        this.maxBump = 0;
                    }
                }

                foreach (TradeSkillSkillInfo skillinfo in this.Skills)
                {
                    if (skillinfo.PerBump != 0)
                    {
                        leastBump = Math.Min(
                            (skillinfo.Value - skillinfo.Requirement) / skillinfo.PerBump, this.maxBump);
                    }
                }

                this.MinQL = this.target.Quality;
                this.MaxQL = Math.Min(
                    this.target.Quality + leastBump,
                    ItemHandler.interpolate(
                        this.resultProperties.ElementAt(this.resultProperties.Count - 1).LowID,
                        this.resultProperties.ElementAt(this.resultProperties.Count - 1).HighID,
                        300).Quality);

                this.Quality = this.MaxQL;

                this.SetResultIDS(this.Quality);
                this.resultName = GetItemName(this.ResultLowId, this.ResultHighId, this.Quality);
            }
        }
 public void KnuBotTrade(Character character, AOItem item)
 {
     if (this.KnuBot != null)
     {
         this.KnuBot.KnuBotTrade(character, item);
     }
 }
Beispiel #31
0
 public KnuBotTradeEventArgs(Character sender, AOItem item)
 {
     this.Sender = sender;
     this.Item   = item;
 }
Beispiel #32
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);
        }