Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private void PacketHandler_0x10_ClientJoin(Object obj, ClientPacket packet)
        {
            var connectionId = (long) obj;

            var seed = packet.ReadByte();
            var keyLength = packet.ReadByte();
            var key = packet.Read(keyLength);
            var name = packet.ReadString8();
            var id = packet.ReadUInt32();

            var redirect = ExpectedConnections[id];

            if (redirect.Matches(name, key, seed))
            {
                ((IDictionary) ExpectedConnections).Remove(id);

                if (PlayerExists(name))
                {
                    var user = new User(this, connectionId, name);
                    user.SetEncryptionParameters(key, seed, name);
                    user.LoadDataFromEntityFramework(true);
                    user.UpdateLoginTime();
                    user.UpdateAttributes(StatUpdateFlags.Full);
                    Logger.DebugFormat("Elapsed time since login: {0}", user.SinceLastLogin);
                    if (user.Citizenship.spawn_points.Count != 0 &&
                        user.SinceLastLogin > Hybrasyl.Constants.NATION_SPAWN_TIMEOUT)
                    {
                        Insert(user);
                        var spawnpoint = user.Citizenship.spawn_points.First();
                        user.Teleport((ushort) spawnpoint.map_id, (byte) spawnpoint.map_x, (byte) spawnpoint.map_y);

                    }
                    else if (user.MapId != null && Maps.ContainsKey(user.MapId))
                    {
                        Insert(user);
                        user.Teleport(user.MapId, (byte) user.MapX, (byte) user.MapY);
                    }
                    else
                    {
                        // Handle any weird cases where a map someone exited on was deleted, etc
                        // This "default" of Mileth should be set somewhere else
                        Insert(user);
                        user.Teleport((ushort) 500, (byte) 50, (byte) 50);
                    }
                    Logger.DebugFormat("Adding {0} to hash", user.Name);
                    AddUser(user);
                    ActiveUsers[connectionId] = user;
                    ActiveUsersByName[user.Name] = connectionId;
                    Logger.InfoFormat("cid {0}: {1} entering world", connectionId, user.Name);
                }
            }
        }