Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using Emulator.Communication.Packets.Outgoing.Rooms.Notifications;
- using Emulator.Core;
- using Emulator.Communication.Packets.Incoming;
- using Emulator.HabboHotel.Catalog;
- using Emulator.HabboHotel.GameClients;
- using Emulator.HabboHotel.Items;
- using Emulator.HabboHotel.Groups;
- using Emulator.HabboHotel.Users.Effects;
- using Emulator.HabboHotel.Users.Inventory.Bots;
- using Emulator.HabboHotel.Groups.Forums;
- using Emulator.HabboHotel.Catalog.Utilities;
- using Emulator.HabboHotel.Rooms.AI;
- using Emulator.HabboHotel.Rooms;
- using Emulator.Communication.Packets.Outgoing.Catalog;
- using Emulator.Communication.Packets.Outgoing.Inventory.Bots;
- using Emulator.Communication.Packets.Outgoing.Inventory.Pets;
- using Emulator.Communication.Packets.Outgoing.Inventory.Purse;
- using Emulator.Communication.Packets.Outgoing.Inventory.Furni;
- using Emulator.Communication.Packets.Outgoing.Inventory.AvatarEffects;
- using Emulator.Database.Interfaces;
- using Emulator.Communication.Packets.Outgoing.Moderation;
- using Emulator.Communication.Packets.Outgoing.Users;
- using Emulator.HabboHotel.Badges;
- using Emulator.Communication.Packets.Outgoing.Rooms.Session;
- using Emulator.Communication.Packets.Outgoing.Subscriptions;
- using Emulator.HabboHotel.Users;
- using Emulator.Communication.Packets.Outgoing.Navigator;
- using Emulator.HabboHotel.Subscriptions;
- using Emulator.HabboHotel.Items.Wired;
- using Emulator.Communication.Packets.Outgoing.Handshake;
- using Emulator.Catalog.HabboClub;
- using Emulator.HabboHotel.Subscriptions.HabboClub;
- using Emulator.HabboHotel.Rooms.AI.Speech;
- namespace Emulator.Communication.Packets.Incoming.Catalog
- {
- public class PurchaseFromCatalogEvent : IPacketEvent
- {
- public void Parse(GameClient Session, ClientPacket Packet)
- {
- if (HabboEnvironment.GetDBConfig().DBData["catalogue_enabled"] != "1")
- {
- Session.SendNotification("The hotel managers have disabled the catalogue");
- return;
- }
- int PageId = Packet.PopInt();
- int ItemId = Packet.PopInt();
- string ExtraData = Packet.PopString();
- int Amount = Packet.PopInt();
- if (!HabboEnvironment.GetGame().GetCatalog().TryGetPage(PageId, out CatalogPage Page))
- return;
- if (!Page.Enabled || !Page.Visible || Page.MinimumRank > Session.GetHabbo().Rank || (Page.MinimumVIP > Session.GetHabbo().VIPRank && Session.GetHabbo().Rank == 1))
- return;
- switch (Page.Template)
- {
- default:
- if (!Page.Items.TryGetValue(ItemId, out CatalogItem Item))
- {
- if (Page.ItemOffers.ContainsKey(ItemId))
- {
- Item = (CatalogItem)Page.ItemOffers[ItemId];
- if (Item == null)
- return;
- }
- else
- return;
- }
- if (Item.Data.InteractionType == InteractionType.CHATCOLOUR)
- {
- if (Item.CostCredits > Session.GetHabbo().Credits)
- return;
- if (Item.CostDiamonds > 0)
- {
- Session.GetHabbo().Credits -= Item.CostCredits;
- Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
- }
- if (Item.Name.ToString().ToLower() == "@ccd@")
- {
- Session.GetHabbo().ChatColour = null;
- }
- else
- {
- Session.GetHabbo().ChatColour = Item.Name.ToString().ToLower();
- }
- using (IQueryAdapter dbClient = HabboEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.SetQuery("UPDATE `users` SET `chatColour` = @colour WHERE `id` = @id LIMIT 1");
- dbClient.AddParameter("colour", Session.GetHabbo().ChatColour);
- dbClient.AddParameter("id", Session.GetHabbo().Id);
- dbClient.RunQuery();
- }
- Session.SendWhisper("Your chat colour has been set to " + Session.GetHabbo().ChatColour + ". You can reset this by purchasing the default chat in the same catalog section.");
- Session.SendMessage(new PurchaseOKComposer(Item, Item.Data));
- Session.SendMessage(new FurniListUpdateComposer());
- return;
- }
- if (Amount < 1 || Amount > 100 || !Item.HaveOffer)
- Amount = 1;
- int AmountPurchase = Item.Amount > 1 ? Item.Amount : Amount;
- int TotalCreditsCost = Amount > 1 ? ((Item.CostCredits * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostCredits)) : Item.CostCredits;
- int TotalPixelCost = Amount > 1 ? ((Item.CostPixels * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostPixels)) : Item.CostPixels;
- int TotalDiamondCost = Amount > 1 ? ((Item.CostDiamonds * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostDiamonds)) : Item.CostDiamonds;
- int TotalPointsCost = Amount > 1 ? ((Item.CostPoints * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostPoints)) : Item.CostPoints;
- int PurchaseAmountCredits = Session.GetHabbo().PurchaseAmount > 0 ? ((Item.CostCredits * Session.GetHabbo().PurchaseAmount)) : Item.CostCredits;
- int PurchaseAmountDuckets = Session.GetHabbo().PurchaseAmount > 0 ? ((Item.CostPixels * Session.GetHabbo().PurchaseAmount)) : Item.CostPixels;
- int PurchaseAmountDiamonds = Session.GetHabbo().PurchaseAmount > 0 ? ((Item.CostDiamonds * Session.GetHabbo().PurchaseAmount)) : Item.CostDiamonds;
- if (Item.HC == 1 && !Session.GetHabbo().GetSubscriptions().HasSubscription("club_habbo"))
- {
- Session.SendMessage(new PurchaseErrorComposer(4));
- return;
- }
- if (Session.GetHabbo().Credits < PurchaseAmountCredits)
- return;
- if (Item.EventCount > 0 && Session.GetHabbo().EventCount >= 10)
- {
- Session.SendMessage(new PurchaseErrorComposer(7));
- return;
- }
- if (Session.GetHabbo().Credits < TotalCreditsCost || Session.GetHabbo().Duckets < TotalPixelCost || Session.GetHabbo().Diamonds < TotalDiamondCost || Session.GetHabbo().GOTWPoints < TotalPointsCost)
- return;
- if (Session.GetHabbo().Credits < PurchaseAmountCredits || Session.GetHabbo().Duckets < PurchaseAmountDuckets || Session.GetHabbo().Diamonds < PurchaseAmountDiamonds)
- return;
- if (Item.EventCount > 0 && Session.GetHabbo().Rank >= 2)
- {
- Session.GetHabbo().EventCount = Session.GetHabbo().EventCount + 1;
- }
- int LimitedEditionSells = 0;
- int LimitedEditionStack = 0;
- #region Create the extradata
- switch (Item.Data.InteractionType)
- {
- case InteractionType.NONE:
- ExtraData = "";
- break;
- case InteractionType.GUILD_ITEM:
- case InteractionType.GUILD_GATE:
- break;
- case InteractionType.PINATA:
- case InteractionType.PINATATRIGGERED:
- case InteractionType.MAGICEGG:
- case InteractionType.MAGICCHEST:
- ExtraData = "0";
- break;
- #region Pet handling
- case InteractionType.PET:
- try
- {
- string[] Bits = ExtraData.Split('\n');
- string PetName = Bits[0];
- string Race = Bits[1];
- string Color = Bits[2];
- int.Parse(Race); // to trigger any possible errors
- if (!PetUtility.CheckPetName(PetName))
- return;
- if (Race.Length > 2)
- return;
- if (Color.Length != 6)
- return;
- HabboEnvironment.GetGame().GetAchievementManager().ProgressAchievement(Session, "ACH_PetLover", 1);
- }
- catch (Exception e)
- {
- Logging.LogException(e.ToString());
- return;
- }
- break;
- #endregion
- case InteractionType.FLOOR:
- case InteractionType.WALLPAPER:
- case InteractionType.LANDSCAPE:
- Double Number = 0;
- try
- {
- if (string.IsNullOrEmpty(ExtraData))
- Number = 0;
- else
- Number = Double.Parse(ExtraData, HabboEnvironment.CultureInfo);
- }
- catch (Exception e)
- {
- Logging.HandleException(e, "Catalog.HandlePurchase: " + ExtraData);
- }
- ExtraData = Number.ToString().Replace(',', '.');
- break; // maintain extra data // todo: validate
- case InteractionType.POSTIT:
- ExtraData = "FFFF33";
- break;
- case InteractionType.MOODLIGHT:
- ExtraData = "1,1,1,#000000,255";
- break;
- case InteractionType.TROPHY:
- ExtraData = Session.GetHabbo().Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + Convert.ToChar(9) + ExtraData;
- break;
- case InteractionType.MANNEQUIN:
- ExtraData = "m" + Convert.ToChar(5) + ".ch-210-1321.lg-285-92" + Convert.ToChar(5) + "Default Mannequin";
- break;
- case InteractionType.BADGE_DISPLAY:
- if (!Session.GetHabbo().GetBadgeComponent().HasBadge(ExtraData))
- {
- Session.SendMessage(new BroadcastMessageAlertComposer("Oops, it appears that you do not own this badge."));
- return;
- }
- ExtraData = ExtraData + Convert.ToChar(9) + Session.GetHabbo().Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year;
- break;
- case InteractionType.BADGE:
- {
- if (Session.GetHabbo().GetBadgeComponent().HasBadge(Item.Data.ItemName))
- {
- Session.SendMessage(new PurchaseErrorComposer(1));
- return;
- }
- break;
- }
- case InteractionType.CRACKABLE_EGG:
- {
- switch (Item.Data.ItemName)
- {
- default:
- case "easter13_egg_0":
- ExtraData = "0" + Convert.ToChar(5) + "0" + Convert.ToChar(5) + "1000";
- break;
- case "easter13_egg_1":
- ExtraData = "0" + Convert.ToChar(5) + "0" + Convert.ToChar(5) + "5000";
- break;
- case "easter13_egg_2":
- ExtraData = "0" + Convert.ToChar(5) + "0" + Convert.ToChar(5) + "10000";
- break;
- case "easter13_egg_3":
- ExtraData = "0" + Convert.ToChar(5) + "0" + Convert.ToChar(5) + "20000";
- break;
- }
- break;
- }
- case InteractionType.GUILD_FORUM:
- {
- if (!int.TryParse(ExtraData, out int GroupId))
- {
- Session.SendNotification("Oops, Error. ");
- Session.SendMessage(new PurchaseOKComposer());
- return;
- }
- if (!HabboEnvironment.GetGame().GetGroupManager().TryGetGroup(GroupId, out Group Group))
- {
- Session.SendNotification("An forum already exists for this Group.");
- Session.SendMessage(new PurchaseOKComposer());
- return;
- }
- if (!HabboEnvironment.GetGame().GetGroupManager().TryGetGroup(GroupId, out Group))
- {
- if (!Group.HasForum)
- {
- Session.SendNotification("This group doesn't have a forum. Therefore a terminal won't be created.");
- Session.SendMessage(new PurchaseOKComposer());
- return;
- }
- }
- if (!HabboEnvironment.GetGame().GetGroupForumManager().TryGetForum(GroupId, out GroupForum Gf))
- {
- if (Group.CreatorId != Session.GetHabbo().Id)
- {
- Session.SendMessage(new PurchaseOKComposer());
- return;
- }
- Gf = HabboEnvironment.GetGame().GetGroupForumManager().CreateGroupForum(Group);
- }
- var blah = new Dictionary<string, string>
- {
- { "groupId", ExtraData },
- { "groupName", Group.Name }
- };
- Session.SendMessage(new RoomNotificationComposer("forums.delivered", blah));
- break;
- }
- default:
- ExtraData = "";
- break;
- }
- #endregion
- if (Item.IsLimited)
- {
- if (Item.LimitedEditionStack <= Item.LimitedEditionSells)
- {
- Session.SendNotification("This item has sold out!\n\n" + "Please note, you have not recieved another item (You have also not been charged for it!)");
- Session.SendMessage(new CatalogUpdatedComposer());
- Session.SendMessage(new PurchaseOKComposer());
- return;
- }
- Item.LimitedEditionSells++;
- using (IQueryAdapter dbClient = HabboEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.RunQuery("UPDATE `catalog_items` SET `limited_sells` = '" + Item.LimitedEditionSells + "' WHERE `id` = '" + Item.Id + "' LIMIT 1");
- LimitedEditionSells = Item.LimitedEditionSells;
- LimitedEditionStack = Item.LimitedEditionStack;
- }
- }
- if (Item.CostCredits > 0)
- {
- Session.GetHabbo().Credits -= TotalCreditsCost;
- Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
- }
- if (Item.CostCredits > 0 && Session.GetHabbo().PurchaseAmount > 0)
- {
- Session.GetHabbo().Credits -= PurchaseAmountCredits;
- Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
- }
- if (Item.CostPixels > 0 && Session.GetHabbo().PurchaseAmount > 0)
- {
- Session.GetHabbo().Duckets -= PurchaseAmountDuckets;
- Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Duckets, Session.GetHabbo().Duckets));//Love you, Tom.
- }
- if (Item.CostDiamonds > 0 && Session.GetHabbo().PurchaseAmount > 0)
- {
- Session.GetHabbo().Diamonds -= PurchaseAmountDiamonds;
- Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Diamonds, 0, 5));
- }
- if (Item.CostPixels > 0 && Item.Type == 0)
- {
- Session.GetHabbo().Duckets -= TotalPixelCost;
- Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Duckets, Session.GetHabbo().Duckets));//Love you, Tom.
- }
- if (Item.CostPixels > 0 && Item.Type == 103)
- {
- Session.GetHabbo().GOTWPoints -= TotalPixelCost;
- Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().GOTWPoints, Session.GetHabbo().GOTWPoints, 103));//Love you, Tom.
- }
- if (Item.CostDiamonds > 0)
- {
- Session.GetHabbo().Diamonds -= TotalDiamondCost;
- Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Diamonds, 0, 5));
- }
- Item NewItem = null;
- switch (Item.Data.Type.ToString().ToLower())
- {
- default:
- List<Item> GeneratedGenericItems = new List<Item>();
- switch (Item.Data.InteractionType)
- {
- default:
- if (AmountPurchase > 1)
- {
- List<Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase);
- if (Items != null)
- {
- GeneratedGenericItems.AddRange(Items);
- }
- }
- else if (Session.GetHabbo().PurchaseAmount > 1)
- {
- List<Item> Items2 = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, Session.GetHabbo().PurchaseAmount);
- if (Items2 != null)
- {
- GeneratedGenericItems.AddRange(Items2);
- }
- }
- else
- {
- NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData, 0, LimitedEditionSells, LimitedEditionStack);
- if (NewItem != null)
- {
- GeneratedGenericItems.Add(NewItem);
- }
- }
- break;
- case InteractionType.GUILD_GATE:
- case InteractionType.GUILD_ITEM:
- case InteractionType.GUILD_FORUM:
- if (AmountPurchase > 1)
- {
- List<Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase, Convert.ToInt32(ExtraData));
- if (Items != null)
- {
- GeneratedGenericItems.AddRange(Items);
- }
- }
- else
- {
- NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData, Convert.ToInt32(ExtraData));
- if (NewItem != null)
- {
- GeneratedGenericItems.Add(NewItem);
- }
- }
- break;
- case InteractionType.ARROW:
- case InteractionType.TELEPORT:
- for (int i = 0; i < AmountPurchase; i++)
- {
- List<Item> TeleItems = ItemFactory.CreateTeleporterItems(Item.Data, Session.GetHabbo());
- if (TeleItems != null)
- {
- GeneratedGenericItems.AddRange(TeleItems);
- }
- }
- break;
- case InteractionType.MOODLIGHT:
- {
- if (AmountPurchase > 1)
- {
- List<Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase);
- if (Items != null)
- {
- GeneratedGenericItems.AddRange(Items);
- foreach (Item I in Items)
- {
- ItemFactory.CreateMoodlightData(I);
- }
- }
- }
- else
- {
- NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData);
- if (NewItem != null)
- {
- GeneratedGenericItems.Add(NewItem);
- ItemFactory.CreateMoodlightData(NewItem);
- }
- }
- }
- break;
- case InteractionType.TONER:
- {
- if (AmountPurchase > 1)
- {
- List<Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase);
- if (Items != null)
- {
- GeneratedGenericItems.AddRange(Items);
- foreach (Item I in Items)
- {
- ItemFactory.CreateTonerData(I);
- }
- }
- }
- else
- {
- NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData);
- if (NewItem != null)
- {
- GeneratedGenericItems.Add(NewItem);
- ItemFactory.CreateTonerData(NewItem);
- }
- }
- }
- break;
- case InteractionType.DEAL:
- {
- if (HabboEnvironment.GetGame().GetCatalog().TryGetDeal(Item.Data.BehaviourData, out CatalogDeal deal))
- {
- //Here I loop the DealItems ItemDataList.
- foreach (CatalogItem CatalogItem in deal.ItemDataList.ToList())
- {
- List<Item> Items = ItemFactory.CreateMultipleItems(CatalogItem.Data, Session.GetHabbo(), "", deal.DealAmount);
- if (Items != null)
- {
- GeneratedGenericItems.AddRange(Items);
- }
- }
- }
- break;
- }
- case InteractionType.ROOMDEAL:
- {
- //WeeklyBundle WBundle = HabboEnvironment.GetGame().GetCatalog().GetWeeklyBundle(Page.Id);
- //if (Page.Id == WBundle.BundleId)
- //{
- // if (Item.CostCredits > 0)
- // {
- // WBundle.GetCreator().Credits += Item.CostCredits;
- // WBundle.GetCreator().GetClient().SendMessage(new CreditBalanceComposer(WBundle.GetCreator().Credits));
- // }
- // if (Item.CostPixels > 0)
- // {
- // WBundle.GetCreator().Duckets += Item.CostPixels;
- // WBundle.GetCreator().GetClient().SendMessage(new HabboActivityPointNotificationComposer(WBundle.GetCreator().Duckets, Session.GetHabbo().Duckets));//Love you, Tom.
- // }
- //}
- if (HabboEnvironment.GetGame().GetCatalog().TryGetDeal(Item.Data.BehaviourData, out CatalogDeal deal))
- {
- Room room = HabboEnvironment.GetGame().GetRoomManager().LoadRoom(deal.RoomId);
- if (room == null)
- Session.SendNotification("There was an error loading this Room Bundle, if this happens again please contact hotel management!");
- RoomData newRoom = HabboEnvironment.GetGame().GetRoomManager().CreateRoom(Session, room.Name, room.Description, room.ModelName, room.Category, 10, room.TradeSettings, room.Wallpaper, room.Floor, room.Landscape, room.WallThickness, room.FloorThickness);
- if (newRoom == null)
- return;
- Room myRoom = HabboEnvironment.GetGame().GetRoomManager().LoadRoom(newRoom.Id);
- if (myRoom != null)
- {
- List<Pet> Pets = ItemLoader.GetPets(deal.RoomId);
- List<Item> Items = ItemLoader.GetItemsForRoom(deal.RoomId, room);
- Item teleLink = null;
- foreach(Pet pet in Pets)
- {
- if (pet == null)
- continue;
- var RndSpeechList = new List<RandomSpeech>();
- myRoom.GetRoomUserManager().DeployBot(new RoomBot(pet.PetId, newRoom.Id, "pet", "freeroam", pet.Name, "", pet.Look, pet.X, pet.Y, Convert.ToInt32(pet.Z), 0, 0, 0, 0, 0, ref RndSpeechList, "", 0, pet.OwnerId, false, 0, false, 0), pet);
- }
- foreach (Item furni in Items)
- {
- if (furni.Data.InteractionType == InteractionType.TELEPORT)
- {
- if (teleLink == null)
- {
- List<Item> TeleItems = ItemFactory.CreateTeleporterItems(furni.Data, Session.GetHabbo());
- if (TeleItems != null && TeleItems.ToList().Count > 1)
- {
- myRoom.GetRoomItemHandler().SetFloorItem(Session, TeleItems[0], furni.GetX, furni.GetY, furni.Rotation, true, true, true, false, furni.GetZ);
- teleLink = TeleItems[1];
- }
- }
- else
- {
- myRoom.GetRoomItemHandler().SetFloorItem(Session, teleLink, furni.GetX, furni.GetY, furni.Rotation, true, true, true, false, furni.GetZ);
- teleLink = null;
- }
- }
- else
- {
- NewItem = ItemFactory.CreateSingleItemNullable(furni.Data, Session.GetHabbo(), furni.ExtraData, "", furni.GroupId);
- if (NewItem != null)
- {
- if (NewItem.IsWallItem)
- {
- NewItem.wallCoord = furni.wallCoord;
- myRoom.GetRoomItemHandler().SetWallItem(Session, NewItem);
- }
- else
- myRoom.GetRoomItemHandler().SetFloorItem(Session, NewItem, furni.GetX, furni.GetY, furni.Rotation, true, true, true, false, furni.GetZ);
- }
- }
- }
- Session.GetHabbo().PrepareRoom(myRoom.Id, "");
- }
- }
- break;
- }
- }
- foreach (Item PurchasedItem in GeneratedGenericItems)
- {
- if (Session.GetHabbo().GetInventoryComponent().TryAddItem(PurchasedItem))
- {
- //Session.SendMessage(new FurniListAddComposer(PurchasedItem));
- Session.SendMessage(new FurniListNotificationComposer(PurchasedItem.Id, 1));
- }
- }
- break;
- case "e":
- AvatarEffect Effect = null;
- if (Session.GetHabbo().Effects().HasEffect(Item.Data.SpriteId))
- {
- Effect = Session.GetHabbo().Effects().GetEffectNullable(Item.Data.SpriteId);
- if (Effect != null)
- {
- Effect.AddToQuantity();
- }
- }
- else
- Effect = AvatarEffectFactory.CreateNullable(Session.GetHabbo(), Item.Data.SpriteId, 3600);
- if (Effect != null)// && Session.GetHabbo().Effects().TryAdd(Effect))
- {
- Session.SendMessage(new AvatarEffectAddedComposer(Item.Data.SpriteId, 3600));
- }
- break;
- case "r":
- Bot Bot = BotUtility.CreateBot(Item.Data, Session.GetHabbo().Id);
- if (Bot != null)
- {
- Session.GetHabbo().GetInventoryComponent().TryAddBot(Bot);
- Session.SendMessage(new BotInventoryComposer(Session.GetHabbo().GetInventoryComponent().GetBots()));
- Session.SendMessage(new FurniListNotificationComposer(Bot.Id, 5));
- }
- else
- Session.SendNotification("Oops! There was an error whilst purchasing this bot. It seems that there is no bot data for the bot!");
- break;
- case "b":
- {
- Session.GetHabbo().GetBadgeComponent().GiveBadge(Item.Data.ItemName, true, Session);
- Session.SendMessage(new FurniListNotificationComposer(0, 4));
- break;
- }
- case "p":
- {
- string[] PetData = ExtraData.Split('\n');
- Pet GeneratedPet = PetUtility.CreatePet(Session.GetHabbo().Id, PetData[0], Item.Data.BehaviourData, PetData[1], PetData[2]);
- if (GeneratedPet != null)
- {
- Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet);
- Session.SendMessage(new FurniListNotificationComposer(GeneratedPet.PetId, 3));
- Session.SendMessage(new PetInventoryComposer(Session.GetHabbo().GetInventoryComponent().GetPets()));
- if (HabboEnvironment.GetGame().GetItemManager().GetItem(320, out ItemData PetFood))
- {
- Item Food = ItemFactory.CreateSingleItemNullable(PetFood, Session.GetHabbo(), "", "");
- if (Food != null)
- {
- Session.GetHabbo().GetInventoryComponent().TryAddItem(Food);
- Session.SendMessage(new FurniListNotificationComposer(Food.Id, 1));
- }
- }
- }
- break;
- }
- }
- if (!string.IsNullOrEmpty(Item.Badge) &&
- HabboEnvironment.GetGame().GetBadgeManager().TryGetBadge(Item.Badge, out BadgeDefinition Badge) &&
- (string.IsNullOrEmpty(Badge.RequiredRight) || Session.GetHabbo().GetPermissions().HasRight(Badge.RequiredRight)))
- {
- Session.GetHabbo().GetBadgeComponent().GiveBadge(Badge.Code, true, Session);
- }
- Session.SendMessage(new PurchaseOKComposer(Item, Item.Data));
- Session.SendMessage(new FurniListUpdateComposer());
- break;
- case "vip_buy":
- if (!HabboEnvironment.GetGame().GetCatalog().GetHabboClub().TryGetClubOffer(ItemId, out CatalogClubOffer Offer))
- {
- SendErrorMessage(Session, "Club offer item does not exist.");
- return;
- }
- if (Offer.CreditsCost > 0 && Session.GetHabbo().Credits < Offer.CreditsCost)
- {
- SendErrorMessage(Session, "Subscription purchase failed.");
- return;
- }
- if (Session.GetHabbo().GetSubscriptions().TryGetSubscription("club_habbo", out ClubSubscription ActiveSub))
- {
- }
- if (!ClubSubscriptionFactory.AddOrExtend(Session.GetHabbo(), "club_habbo", Offer.LengthSeconds, out ClubSubscription SubCreated))
- {
- SendErrorMessage(Session, "Subscription factory failed.");
- return;
- }
- if (ActiveSub == null)
- {
- ActiveSub = SubCreated;
- }
- if (Offer.CreditsCost > 0)
- {
- Session.GetHabbo().Credits -= Offer.CreditsCost;
- Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
- }
- Session.GetHabbo().GetPermissions().Init(Session.GetHabbo());
- Session.GetHabbo().GetBadgeComponent().GiveBadge("ACH_VipHC1", true, Session);
- Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
- Session.SendMessage(new PurchaseOKComposer(Offer));
- Session.SendMessage(new ScrSendUserInfoComposer(Session, ActiveSub));
- Session.SendMessage(new UserRightsComposer(Session, Session.GetHabbo().Rank, Session.GetHabbo().Ambassadar));
- break;
- }
- }
- private void SendErrorMessage(GameClient Session, string Error)
- {
- Session.SendNotification("Catalog error: " + Error);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement