Ejemplo n.º 1
0
        public void AddItem(GameClient session, Item item, int amount, string extraData, bool newFurni, bool queueBytes = false)
        {
            if (queueBytes)
            {
                session.GetHabbo().GetInventoryManager().SetQueueBytes(true);
            }

            List <uint> newFloorItems = new List <uint>();
            List <uint> newWallItems  = new List <uint>();
            List <uint> newPets       = new List <uint>();

            switch (item.Type)
            {
            case "i":     //wall item
            {
                switch (item.InteractionType.ToLower())
                {
                case "dimmer":
                default:
                {
                    foreach (uint itemId_ in DatabaseUtils.CreateItems(session.GetHabbo().ID, item, extraData, amount))
                    {
                        newWallItems.Add(itemId_);
                        session.GetHabbo().GetInventoryManager().AddInventoryItemToHand(new InventoryItem(itemId_, item.ID, extraData));
                    }
                }
                break;
                }
            }
            break;

            case "s":     //floor item
            {
                switch (item.InteractionType.ToLower())
                {
                case "pet":
                {
                    string[] data      = extraData.Split('\n');
                    string   petName   = data[0];
                    string   petRace   = data[1];
                    string   petColor  = data[2];
                    double   timestamp = TimeUtilies.GetUnixTimestamp();
                    foreach (uint petId in DatabaseUtils.CreatePets(session.GetHabbo().ID, petName, petRace, petColor, int.Parse(item.ItemName.Split('t')[1]), timestamp, amount))
                    {
                        newPets.Add(petId);

                        Pet pet = new Pet(petId, session.GetHabbo().ID, int.Parse(item.ItemName.Split('t')[1]), petName, petRace, petColor, 0, 120, 100, 0, timestamp);
                        session.GetHabbo().GetInventoryManager().AddPet(pet);
                        session.GetHabbo().Pets.Add(petId, pet);
                    }
                }
                break;

                case "teleport":
                default:
                {
                    foreach (uint itemId_ in DatabaseUtils.CreateItems(session.GetHabbo().ID, item, extraData, amount))
                    {
                        newFloorItems.Add(itemId_);
                        session.GetHabbo().GetInventoryManager().AddInventoryItemToHand(new InventoryItem(itemId_, item.ID, extraData));
                    }
                }
                break;
                }
            }
            break;

            case "h":
            {
                double hcLenghtInSecounds = (2678400.0 * amount);

                string clubType = "habbo_club";
                if (item.ItemName.StartsWith("DEAL_VIP"))         //bought vip days
                {
                    clubType = "habbo_vip";

                    if (!session.GetHabbo().IsVIP() && session.GetHabbo().IsHC())         //is upgrade
                    {
                        hcLenghtInSecounds += session.GetHabbo().GetSubscriptionManager().TryGetSubscription("habbo_club", false, true).SecoundsLeft() / 1.67;

                        session.GetHabbo().GetSubscriptionManager().EndSubscription("habbo_club");         //R.I.P. HC
                    }

                    Skylight.GetGame().GetAchievementManager().AddAchievement(session, "HCMember", 1);
                    Skylight.GetGame().GetAchievementManager().AddAchievement(session, "VIPMember", 1);

                    session.GetHabbo().GetUserAchievements().CheckAchievement("HCMember");
                    session.GetHabbo().GetUserAchievements().CheckAchievement("VIPMember");
                }
                else                                                              //bought hc days
                {
                    if (session.GetHabbo().IsVIP() && !session.GetHabbo().IsHC()) //is downgrade
                    {
                        hcLenghtInSecounds += session.GetHabbo().GetSubscriptionManager().TryGetSubscription("habbo_vip", false, true).SecoundsLeft() * 1.67;

                        session.GetHabbo().GetSubscriptionManager().EndSubscription("habbo_vip");         //R.I.P. VIP
                    }

                    Skylight.GetGame().GetAchievementManager().AddAchievement(session, "HCMember", 1);

                    session.GetHabbo().GetUserAchievements().CheckAchievement("HCMember");
                }

                session.GetHabbo().GetSubscriptionManager().AddSubscription(clubType, hcLenghtInSecounds);

                session.SendMessage(OutgoingPacketsEnum.ClubMembership, new ValueHolder("Session", session, "ClubType", clubType));
                session.SendMessage(BasicUtilies.GetRevisionPacketManager(session.Revision).GetOutgoing(OutgoingPacketsEnum.Fuserights).Handle(new ValueHolder().AddValue("Session", session)));
                break;
            }

            default:
            {
                session.SendNotif("Invalid item type... (" + item.Type + ") Please don't try buy this item again!");
                break;
            }
            }

            if (newPets.Count > 0)
            {
                session.GetHabbo().GetUserAchievements().CheckAchievement("PetOwner");
            }

            session.SendMessage(BasicUtilies.GetRevisionPacketManager(session.Revision).GetOutgoing(OutgoingPacketsEnum.NewItems).Handle(new ValueHolder("Floors", newFloorItems, "Walls", newWallItems, "Pets", newPets)));
            if (queueBytes)
            {
                session.GetHabbo().GetInventoryManager().SetQueueBytes(false);
            }
        }