[4267] Vending Bug.

02/23/2012 02:35 killersub#1
Okay so, I've been working on this 4267 base I picked up on, BUT, I seem to find a small bug to it.

Once you click "Ok" on the vending dialog nothing happens. I'm fairly sure(101%) that vending is fully coded inside the source just cant seem to find the problem.

here is my StartVending() method:
Code:
public bool StartVending(uint lParam)
        {
            if (m_IsVending)
                return false;
            Dictionary<uint, INpc> npcs;

            if (Kernel.Npcs.TryGetValue(Owner.Entity.MapID, out npcs))
            {
                ushort vendx = (ushort)(Owner.Entity.X - 2);
                ushort vendy = Owner.Entity.Y;
                foreach (INpc npc in npcs.Values)
                {
                    if (npc.X == vendx && npc.Y == vendy && !npc.IsVendor)
                    {
                        m_VendorNpc = npc;
                        m_VendorNpc.ConvertToVendor(Owner.Entity.Name);
                        m_VendorNpc.UID = lParam;
                        PacketKernel.SendRangedPacket(1036, vendx, vendy, ((NpcSpawnPacket)m_VendorNpc).Packet);
                        VendingItems = new Dictionary<uint, VendingItem>();
                        m_IsVending = true;
                        break;
                    }
                }
            }
            return m_IsVending;
        }
Any help would be greatly appreciated.
02/23/2012 07:37 -Shunsui-#2
Add some break points see were it reaches to.
02/23/2012 11:48 JobvdH#3
Check your packet?
Perhaps your packets are wrong.
02/24/2012 23:26 killersub#4
Quote:
Originally Posted by JobvdH View Post
Check your packet?
Perhaps your packets are wrong.
What that does is send a ranged packet to the server with the NpcSpawnPacket to act as the visible "flag" npc.
Code:
public bool StartVending(uint lParam)
        {
            if (m_IsVending)
                return false;
            Dictionary<uint, INpc> npcs;

            if (Kernel.Npcs.TryGetValue(Owner.Entity.MapID, out npcs))
            {
                ushort vendx = (ushort)(Owner.Entity.X - 2);
                ushort vendy = Owner.Entity.Y;
                foreach (INpc npc in npcs.Values)
                {
                    if (npc.X == vendx && npc.Y == vendy && !npc.IsVendor)
                    {
                        m_VendorNpc = npc;
                        m_VendorNpc.ConvertToVendor(Owner.Entity.Name);
                        m_VendorNpc.UID = lParam;
                        [COLOR="Red"]PacketKernel.SendRangedPacket(1036, vendx, vendy, ((NpcSpawnPacket)m_VendorNpc).Packet);[/COLOR]
                        VendingItems = new Dictionary<uint, VendingItem>();
                        m_IsVending = true;
                        break;
                    }
                }
            }
            return m_IsVending;
        }
THIS, is the SendRangedPacket method it uses for sending the Npc reply to the appointed map, 1036, as said above, with INPC acting as the "flag".
Code:
public static void SendRangedPacket(ushort MapID, ushort X, ushort Y, byte[] Packet)
        {
            foreach (GameClient DE in Kernel.Clients)
                if (DE.Entity.MapID.ID == MapID)
                    if (Kernel.GetDistance(X, Y, DE.Entity.X, DE.Entity.Y) < DataStructures.ViewDistance)
                        DE.Send(Packet);
        }
this seems fairly fine to me, don't know why it wouldn't work.
02/25/2012 00:39 pro4never#5
Someone had this issue trying to add it to an earlier patch. Turns out they weren't sending map flags. You can apparently only finish setting up show (show the leave shop icon) if the map has the market flag active and you send map flag properly.

Look at albetros or other sources for examples of how to impliment the cq_map table from binaries. Mine also contains an enum of map flags so it's easier to check.