示例#1
0
        private static void RecycleItems(Session Session, ClientMessage Message)
        {
            if (!mEnabled)
            {
                Session.SendData(NotificationMessageComposer.Compose("The recycler is temporarily disabled. Please check back later."));
                return;
            }

            int Amount = Message.PopWiredInt32();

            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || Amount != 5)
            {
                return;
            }

            ItemDefinition Reward = ItemDefinitionManager.GetDefinition(GetRandomReward());

            if (Reward == null)
            {
                return;
            }

            List <Item> ItemsToRecycle = new List <Item>();

            for (int i = 0; i < 5; i++)
            {
                Item Item = Session.InventoryCache.GetItem(Message.PopWiredUInt32());

                if (Item == null || !Item.Definition.AllowRecycle || ItemsToRecycle.Contains(Item))
                {
                    return;
                }

                ItemsToRecycle.Add(Item);
            }

            Item NewItem = null;

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                foreach (Item Item in ItemsToRecycle)
                {
                    Session.InventoryCache.RemoveItem(Item.Id);
                    Item.RemovePermanently(MySqlClient);

                    Session.SendData(InventoryItemRemovedComposer.Compose(Item.Id));
                }

                NewItem = ItemFactory.CreateItem(MySqlClient, Reward.Id, Session.CharacterId, string.Empty, string.Empty,
                                                 0);
            }

            Session.InventoryCache.Add(NewItem);

            Session.SendData(RecyclerResultComposer.Compose(true, NewItem.Id));
            Session.SendData(InventoryItemAddedComposer.Compose(NewItem));
        }
        public static ServerMessage Compose(Dictionary <int, List <uint> > Rewards)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.CATALOG_RECYCLER_REWARDS);

            Message.AppendInt32(Rewards.Count);

            foreach (KeyValuePair <int, List <uint> > Level in Rewards)
            {
                int ChanceDisplay = 0;

                switch (Level.Key)
                {
                case 5:

                    ChanceDisplay = 2000;
                    break;

                case 4:

                    ChanceDisplay = 200;
                    break;

                case 3:

                    ChanceDisplay = 40;
                    break;

                case 2:

                    ChanceDisplay = 4;
                    break;
                }


                Message.AppendInt32(Level.Key);
                Message.AppendInt32(ChanceDisplay);
                Message.AppendInt32(Level.Value.Count);

                foreach (uint ItemId in Level.Value)
                {
                    ItemDefinition Definition = ItemDefinitionManager.GetDefinition(ItemId);

                    Message.AppendStringWithBreak(Definition.TypeLetter);
                    Message.AppendUInt32(Definition.SpriteId);
                }
            }

            return(Message);
        }