Exemplo n.º 1
0
        private void MerchantMenuHandler_SellItemWithQuantity(User user, Merchant merchant, ClientPacket packet)
        {
            packet.ReadByte();
            byte slot = packet.ReadByte();
            string qStr = packet.ReadString8();

            int quantity;
            if (!int.TryParse(qStr, out quantity) || quantity < 1)
            {
                user.ShowSellQuantity(merchant, slot);
                return;
            }

            var item = user.Inventory[slot];
            if (item == null || !item.Stackable) return;

            if (!merchant.Inventory.ContainsKey(item.Name))
            {
                user.ShowMerchantGoBack(merchant, "I do not want that item.", MerchantMenuItem.SellItemMenu);
                return;
            }

            if (item.Count < quantity)
            {
                user.ShowMerchantGoBack(merchant, "You don't have that many to sell.", MerchantMenuItem.SellItemMenu);
                return;
            }

            user.ShowSellConfirm(merchant, slot, quantity);
        }
Exemplo n.º 2
0
        private void MerchantMenuHandler_SellItemConfirmation(User user, Merchant merchant, ClientPacket packet)
        {
            packet.ReadByte();
            byte slot = packet.ReadByte();
            byte quantity = packet.ReadByte();

            var item = user.Inventory[slot];
            if (item == null) return;

            if (!merchant.Inventory.ContainsKey(item.Name))
            {
                user.ShowMerchantGoBack(merchant, "I do not want that item.", MerchantMenuItem.SellItemMenu);
                return;
            }

            if (item.Count < quantity)
            {
                user.ShowMerchantGoBack(merchant, "You don't have that many to sell.", MerchantMenuItem.SellItemMenu);
                return;
            }

            uint profit = (uint) (Math.Round(item.Value*0.50)*quantity);

            if (item.Stackable && quantity < item.Count)
                user.DecreaseItem(slot, quantity);
            else user.RemoveItem(slot);

            user.AddGold(profit);

            merchant.DisplayPursuits(user);
        }
Exemplo n.º 3
0
        private void MerchantMenuHandler_BuyItemWithQuantity(User user, Merchant merchant, ClientPacket packet)
        {
            string name = packet.ReadString8();
            string qStr = packet.ReadString8();


            if (!merchant.Inventory.ContainsKey(name))
            {
                user.ShowMerchantGoBack(merchant, "I do not sell that item.", MerchantMenuItem.BuyItemMenu);
                return;
            }

            var template = merchant.Inventory[name];

            if (!template.Stackable) return;

            int quantity;
            if (!int.TryParse(qStr, out quantity) || quantity < 1)
            {
                user.ShowBuyMenuQuantity(merchant, name);
                return;
            }

            uint cost = (uint) (template.value*quantity);

            if (user.Gold < cost)
            {
                user.ShowMerchantGoBack(merchant, "You do not have enough gold.", MerchantMenuItem.BuyItemMenu);
                return;
            }

            if (quantity > template.max_stack)
            {
                user.ShowMerchantGoBack(merchant, string.Format("You cannot hold that many {0}.", name),
                    MerchantMenuItem.BuyItemMenu);
                return;
            }

            if (user.Inventory.Contains(name))
            {
                byte slot = user.Inventory.SlotOf(name);
                if (user.Inventory[slot].Count + quantity > template.max_stack)
                {
                    user.ShowMerchantGoBack(merchant, string.Format("You cannot hold that many {0}.", name),
                        MerchantMenuItem.BuyItemMenu);
                    return;
                }
                user.IncreaseItem(slot, quantity);
            }
            else
            {
                if (user.Inventory.IsFull)
                {
                    user.ShowMerchantGoBack(merchant, "You cannot carry any more items.", MerchantMenuItem.BuyItemMenu);
                    return;
                }

                var item = CreateItem(template.id, quantity);
                Insert(item);
                user.AddItem(item);
            }

            user.RemoveGold(cost);
            user.UpdateAttributes(StatUpdateFlags.Experience);
            user.ShowBuyMenu(merchant);
        }
Exemplo n.º 4
0
        private void MerchantMenuHandler_SellItem(User user, Merchant merchant, ClientPacket packet)
        {
            byte slot = packet.ReadByte();

            var item = user.Inventory[slot];
            if (item == null) return;

            if (!merchant.Inventory.ContainsKey(item.Name))
            {
                user.ShowMerchantGoBack(merchant, "I do not want that item.", MerchantMenuItem.SellItemMenu);
                return;
            }

            if (item.Stackable && item.Count > 1)
            {
                user.ShowSellQuantity(merchant, slot);
                return;
            }

            user.ShowSellConfirm(merchant, slot, 1);
        }
Exemplo n.º 5
0
 private void MerchantMenuHandler_SellItemMenu(User user, Merchant merchant, ClientPacket packet)
 {
     user.ShowSellMenu(merchant);
 }
Exemplo n.º 6
0
        private void MerchantMenuHandler_BuyItem(User user, Merchant merchant, ClientPacket packet)
        {
            string name = packet.ReadString8();

            if (!merchant.Inventory.ContainsKey(name))
            {
                user.ShowMerchantGoBack(merchant, "I do not sell that item.", MerchantMenuItem.BuyItemMenu);
                return;
            }

            var template = merchant.Inventory[name];

            if (template.Stackable)
            {
                user.ShowBuyMenuQuantity(merchant, name);
                return;
            }

            if (user.Gold < template.value)
            {
                user.ShowMerchantGoBack(merchant, "You do not have enough gold.", MerchantMenuItem.BuyItemMenu);
                return;
            }

            if (user.CurrentWeight + template.weight > user.MaximumWeight)
            {
                user.ShowMerchantGoBack(merchant, "That item is too heavy for you to carry.",
                    MerchantMenuItem.BuyItemMenu);
                return;
            }

            if (user.Inventory.IsFull)
            {
                user.ShowMerchantGoBack(merchant, "You cannot carry any more items.", MerchantMenuItem.BuyItemMenu);
                return;
            }

            user.RemoveGold((uint) template.value);

            var item = CreateItem(template.id);
            Insert(item);
            user.AddItem(item);

            user.UpdateAttributes(StatUpdateFlags.Experience);
            user.ShowBuyMenu(merchant);
        }
Exemplo n.º 7
0
 public void ShowSellQuantity(Merchant merchant, byte slot)
 {
     var x2F = new ServerPacket(0x2F);
     x2F.WriteByte(0x03); // type!
     x2F.WriteByte(0x01); // obj type
     x2F.WriteUInt32(merchant.Id);
     x2F.WriteByte(0x01); // ??
     x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
     x2F.WriteByte(0x00); // color
     x2F.WriteByte(0x01); // ??
     x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
     x2F.WriteByte(0x00); // color
     x2F.WriteByte(0x00); // ??
     x2F.WriteString8(merchant.Name);
     x2F.WriteString16("How many are you selling?");
     x2F.WriteByte(1);
     x2F.WriteByte(slot);
     x2F.WriteUInt16((ushort)MerchantMenuItem.SellItemQuantity);
     Enqueue(x2F);
 }
Exemplo n.º 8
0
 private void MerchantMenuHandler_MainMenu(User user, Merchant merchant, ClientPacket packet)
 {
     merchant.DisplayPursuits(user);
 }
Exemplo n.º 9
0
        public void ShowSellConfirm(Merchant merchant, byte slot, int quantity)
        {
            var item = Inventory[slot];
            double offer = Math.Round(item.Value * 0.50) * quantity;

            var x2F = new ServerPacket(0x2F);
            x2F.WriteByte(0x01); // type!
            x2F.WriteByte(0x01); // obj type
            x2F.WriteUInt32(merchant.Id);
            x2F.WriteByte(0x01); // ??
            x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
            x2F.WriteByte(0x00); // color
            x2F.WriteByte(0x01); // ??
            x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
            x2F.WriteByte(0x00); // color
            x2F.WriteByte(0x00); // ??
            x2F.WriteString8(merchant.Name);
            x2F.WriteString16(string.Format("I'll give you {0} gold for {1}.", offer, quantity == 1 ? "that" : "those"));
            x2F.WriteByte(2);
            x2F.WriteByte(slot);
            x2F.WriteByte((byte)quantity);
            x2F.WriteByte(2);
            x2F.WriteString8("Accept");
            x2F.WriteUInt16((ushort)MerchantMenuItem.SellItemAccept);
            x2F.WriteString8("Decline");
            x2F.WriteUInt16((ushort)MerchantMenuItem.SellItemMenu);
            Enqueue(x2F);
        }
Exemplo n.º 10
0
        public void ShowSellMenu(Merchant merchant)
        {
            var x2F = new ServerPacket(0x2F);
            x2F.WriteByte(0x05); // type!
            x2F.WriteByte(0x01); // obj type
            x2F.WriteUInt32(merchant.Id);
            x2F.WriteByte(0x01); // ??
            x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
            x2F.WriteByte(0x00); // color
            x2F.WriteByte(0x01); // ??
            x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
            x2F.WriteByte(0x00); // color
            x2F.WriteByte(0x00); // ??
            x2F.WriteString8(merchant.Name);
            x2F.WriteString16("What would you like to sell?");
            x2F.WriteUInt16((ushort)MerchantMenuItem.SellItem);

            int position = x2F.Position;
            x2F.WriteByte(0);
            int count = 0;

            for (byte i = 1; i <= Inventory.Size; ++i)
            {
                if (Inventory[i] == null || !merchant.Inventory.ContainsKey(Inventory[i].Name))
                    continue;

                x2F.WriteByte((byte)i);
                ++count;
            }

            x2F.Seek(position, PacketSeekOrigin.Begin);
            x2F.WriteByte((byte)count);

            Enqueue(x2F);
        }
Exemplo n.º 11
0
 public void ShowMerchantGoBack(Merchant merchant, string message, MerchantMenuItem menuItem = MerchantMenuItem.MainMenu)
 {
     var x2F = new ServerPacket(0x2F);
     x2F.WriteByte(0x00); // type!
     x2F.WriteByte(0x01); // obj type
     x2F.WriteUInt32(merchant.Id);
     x2F.WriteByte(0x01); // ??
     x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
     x2F.WriteByte(0x00); // color
     x2F.WriteByte(0x01); // ??
     x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
     x2F.WriteByte(0x00); // color
     x2F.WriteByte(0x00); // ??
     x2F.WriteString8(merchant.Name);
     x2F.WriteString16(message);
     x2F.WriteByte(1);
     x2F.WriteString8("Go back");
     x2F.WriteUInt16((ushort)menuItem);
     Enqueue(x2F);
 }
Exemplo n.º 12
0
 public void ShowBuyMenuQuantity(Merchant merchant, string name)
 {
     var x2F = new ServerPacket(0x2F);
     x2F.WriteByte(0x03); // type!
     x2F.WriteByte(0x01); // obj type
     x2F.WriteUInt32(merchant.Id);
     x2F.WriteByte(0x01); // ??
     x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
     x2F.WriteByte(0x00); // color
     x2F.WriteByte(0x01); // ??
     x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
     x2F.WriteByte(0x00); // color
     x2F.WriteByte(0x00); // ??
     x2F.WriteString8(merchant.Name);
     x2F.WriteString16(string.Format("How many {0} would you like to buy?", name));
     x2F.WriteString8(name);
     x2F.WriteUInt16((ushort)MerchantMenuItem.BuyItemQuantity);
     Enqueue(x2F);
 }
Exemplo n.º 13
0
 public void ShowBuyMenu(Merchant merchant)
 {
     var x2F = new ServerPacket(0x2F);
     x2F.WriteByte(0x04); // type!
     x2F.WriteByte(0x01); // obj type
     x2F.WriteUInt32(merchant.Id);
     x2F.WriteByte(0x01); // ??
     x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
     x2F.WriteByte(0x00); // color
     x2F.WriteByte(0x01); // ??
     x2F.WriteUInt16((ushort)(0x4000 + merchant.Sprite));
     x2F.WriteByte(0x00); // color
     x2F.WriteByte(0x00); // ??
     x2F.WriteString8(merchant.Name);
     x2F.WriteString16("What would you like to buy?");
     x2F.WriteUInt16((ushort)MerchantMenuItem.BuyItem);
     x2F.WriteUInt16((ushort)merchant.Inventory.Count);
     foreach (var item in merchant.Inventory.Values)
     {
         x2F.WriteUInt16((ushort)(0x8000 + item.sprite));
         x2F.WriteByte((byte)item.color);
         x2F.WriteUInt32((uint)item.value);
         x2F.WriteString8(item.name);
         x2F.WriteString8(string.Empty); // defunct item description
     }
     Enqueue(x2F);
 }
Exemplo n.º 14
0
 public void InsertNpc(Merchant toInsert)
 {
     World.Insert(toInsert);
     Insert(toInsert, toInsert.X, toInsert.Y);
     toInsert.OnSpawn();
 }
Exemplo n.º 15
0
        /// <summary>
        /// Create a new Hybrasyl map from an XMLMap object.
        /// </summary>
        /// <param name="mapElement"></param>
        public Map(XSD.Map newMap, World theWorld)
        {
            Init();
            World = theWorld;

            // TODO: refactor Map class to not do this, but be a partial which overlays
            // TODO: XmlMap (which would then just be Map)
            Id = newMap.Id;
            X = newMap.X;
            Y = newMap.Y;
            Name = newMap.Name;
            EntityTree = new QuadTree<VisibleObject>(0,0,X,Y);
            Music = newMap.Music;

            foreach (var warpElement in newMap.Warps)
            {
                var warp = new Warp(this);
                warp.X = warpElement.X;
                warp.Y = warpElement.Y;

                if (warpElement.MapTarget !=null)
                {
                    var maptarget = warpElement.MapTarget as XSD.WarpMaptarget;
                    // map warp
                    warp.DestinationMapName = maptarget.Value;
                    warp.WarpType = WarpType.Map;
                    warp.DestinationX = maptarget.X;
                    warp.DestinationY = maptarget.Y;
                }
                else
                {
                    var worldmaptarget = warpElement.WorldMapTarget as XSD.WorldMapPointTarget;
                    // worldmap warp
                    warp.DestinationMapName = worldmaptarget.Value;
                    warp.WarpType = WarpType.WorldMap;
                }

                warp.MinimumLevel = warpElement.Restrictions.Level.Min;
                warp.MaximumLevel = warpElement.Restrictions.Level.Max;
                warp.MinimumAbility = warpElement.Restrictions.Ab.Min;
                warp.MaximumAbility = warpElement.Restrictions.Ab.Max;
                warp.MobUse = warpElement.Restrictions.NoMobUse == null;
                Warps[new Tuple<byte, byte>(warp.X, warp.Y)] = warp;
            }

            foreach (var npcElement in newMap.Npcs)
            {
                var merchant = new Merchant
                {
                    X = npcElement.X,
                    Y = npcElement.Y,
                    Name = npcElement.Name,
                    Sprite = npcElement.Appearance.Sprite,
                    Direction = (Enums.Direction) npcElement.Appearance.Direction,
                    Portrait = npcElement.Appearance.Portrait,
                    // Wow this is terrible
                    Jobs = ((MerchantJob) (int) npcElement.Jobs)
                };
                InsertNpc(merchant);
            }

            foreach (var reactorElement in newMap.Reactors)
            {
                // TODO: implement reactor loading support
            }

            foreach (var postElement in newMap.Signposts.Items)
            {
                if (postElement is XSD.Signpost)
                {
                    var signpostElement = postElement as XSD.Signpost;
                    var signpost = new Objects.Signpost(signpostElement.X, signpostElement.Y, signpostElement.Message);
                    InsertSignpost(signpost);
                }
                else
                {
                    // TODO: Messageboards
                    Logger.InfoFormat("{0}: messageboard ignored", Name);                
                }
            }

            foreach (var spawnElement in newMap.Spawns)
            {
                // TODO: implement spawning
            }

            Load();
        }