Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.63 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using Emulator.Communication.Packets.Outgoing.Rooms.Notifications;
  5. using Emulator.Core;
  6. using Emulator.Communication.Packets.Incoming;
  7. using Emulator.HabboHotel.Catalog;
  8. using Emulator.HabboHotel.GameClients;
  9. using Emulator.HabboHotel.Items;
  10. using Emulator.HabboHotel.Groups;
  11. using Emulator.HabboHotel.Users.Effects;
  12. using Emulator.HabboHotel.Users.Inventory.Bots;
  13. using Emulator.HabboHotel.Groups.Forums;
  14. using Emulator.HabboHotel.Catalog.Utilities;
  15. using Emulator.HabboHotel.Rooms.AI;
  16. using Emulator.HabboHotel.Rooms;
  17. using Emulator.Communication.Packets.Outgoing.Catalog;
  18. using Emulator.Communication.Packets.Outgoing.Inventory.Bots;
  19. using Emulator.Communication.Packets.Outgoing.Inventory.Pets;
  20. using Emulator.Communication.Packets.Outgoing.Inventory.Purse;
  21. using Emulator.Communication.Packets.Outgoing.Inventory.Furni;
  22. using Emulator.Communication.Packets.Outgoing.Inventory.AvatarEffects;
  23. using Emulator.Database.Interfaces;
  24. using Emulator.Communication.Packets.Outgoing.Moderation;
  25. using Emulator.Communication.Packets.Outgoing.Users;
  26. using Emulator.HabboHotel.Badges;
  27. using Emulator.Communication.Packets.Outgoing.Rooms.Session;
  28. using Emulator.Communication.Packets.Outgoing.Subscriptions;
  29. using Emulator.HabboHotel.Users;
  30. using Emulator.Communication.Packets.Outgoing.Navigator;
  31. using Emulator.HabboHotel.Subscriptions;
  32. using Emulator.HabboHotel.Items.Wired;
  33. using Emulator.Communication.Packets.Outgoing.Handshake;
  34. using Emulator.Catalog.HabboClub;
  35. using Emulator.HabboHotel.Subscriptions.HabboClub;
  36. using Emulator.HabboHotel.Rooms.AI.Speech;
  37.  
  38. namespace Emulator.Communication.Packets.Incoming.Catalog
  39. {
  40. public class PurchaseFromCatalogEvent : IPacketEvent
  41. {
  42. public void Parse(GameClient Session, ClientPacket Packet)
  43. {
  44. if (HabboEnvironment.GetDBConfig().DBData["catalogue_enabled"] != "1")
  45. {
  46. Session.SendNotification("The hotel managers have disabled the catalogue");
  47. return;
  48. }
  49.  
  50. int PageId = Packet.PopInt();
  51. int ItemId = Packet.PopInt();
  52. string ExtraData = Packet.PopString();
  53. int Amount = Packet.PopInt();
  54.  
  55.  
  56. if (!HabboEnvironment.GetGame().GetCatalog().TryGetPage(PageId, out CatalogPage Page))
  57. return;
  58.  
  59. if (!Page.Enabled || !Page.Visible || Page.MinimumRank > Session.GetHabbo().Rank || (Page.MinimumVIP > Session.GetHabbo().VIPRank && Session.GetHabbo().Rank == 1))
  60. return;
  61.  
  62. switch (Page.Template)
  63. {
  64. default:
  65.  
  66. if (!Page.Items.TryGetValue(ItemId, out CatalogItem Item))
  67. {
  68. if (Page.ItemOffers.ContainsKey(ItemId))
  69. {
  70. Item = (CatalogItem)Page.ItemOffers[ItemId];
  71. if (Item == null)
  72. return;
  73. }
  74. else
  75. return;
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. if (Item.Data.InteractionType == InteractionType.CHATCOLOUR)
  84. {
  85. if (Item.CostCredits > Session.GetHabbo().Credits)
  86. return;
  87.  
  88. if (Item.CostDiamonds > 0)
  89. {
  90. Session.GetHabbo().Credits -= Item.CostCredits;
  91. Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
  92. }
  93.  
  94. if (Item.Name.ToString().ToLower() == "@ccd@")
  95. {
  96. Session.GetHabbo().ChatColour = null;
  97. }
  98. else
  99. {
  100.  
  101. Session.GetHabbo().ChatColour = Item.Name.ToString().ToLower();
  102. }
  103.  
  104. using (IQueryAdapter dbClient = HabboEnvironment.GetDatabaseManager().GetQueryReactor())
  105. {
  106. dbClient.SetQuery("UPDATE `users` SET `chatColour` = @colour WHERE `id` = @id LIMIT 1");
  107. dbClient.AddParameter("colour", Session.GetHabbo().ChatColour);
  108. dbClient.AddParameter("id", Session.GetHabbo().Id);
  109. dbClient.RunQuery();
  110. }
  111. 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.");
  112. Session.SendMessage(new PurchaseOKComposer(Item, Item.Data));
  113. Session.SendMessage(new FurniListUpdateComposer());
  114. return;
  115. }
  116.  
  117.  
  118.  
  119. if (Amount < 1 || Amount > 100 || !Item.HaveOffer)
  120. Amount = 1;
  121.  
  122. int AmountPurchase = Item.Amount > 1 ? Item.Amount : Amount;
  123.  
  124. int TotalCreditsCost = Amount > 1 ? ((Item.CostCredits * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostCredits)) : Item.CostCredits;
  125. int TotalPixelCost = Amount > 1 ? ((Item.CostPixels * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostPixels)) : Item.CostPixels;
  126. int TotalDiamondCost = Amount > 1 ? ((Item.CostDiamonds * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostDiamonds)) : Item.CostDiamonds;
  127. int TotalPointsCost = Amount > 1 ? ((Item.CostPoints * Amount) - ((int)Math.Floor((double)Amount / 6) * Item.CostPoints)) : Item.CostPoints;
  128. int PurchaseAmountCredits = Session.GetHabbo().PurchaseAmount > 0 ? ((Item.CostCredits * Session.GetHabbo().PurchaseAmount)) : Item.CostCredits;
  129. int PurchaseAmountDuckets = Session.GetHabbo().PurchaseAmount > 0 ? ((Item.CostPixels * Session.GetHabbo().PurchaseAmount)) : Item.CostPixels;
  130. int PurchaseAmountDiamonds = Session.GetHabbo().PurchaseAmount > 0 ? ((Item.CostDiamonds * Session.GetHabbo().PurchaseAmount)) : Item.CostDiamonds;
  131.  
  132. if (Item.HC == 1 && !Session.GetHabbo().GetSubscriptions().HasSubscription("club_habbo"))
  133. {
  134. Session.SendMessage(new PurchaseErrorComposer(4));
  135. return;
  136. }
  137.  
  138. if (Session.GetHabbo().Credits < PurchaseAmountCredits)
  139. return;
  140.  
  141. if (Item.EventCount > 0 && Session.GetHabbo().EventCount >= 10)
  142. {
  143. Session.SendMessage(new PurchaseErrorComposer(7));
  144. return;
  145. }
  146.  
  147. if (Session.GetHabbo().Credits < TotalCreditsCost || Session.GetHabbo().Duckets < TotalPixelCost || Session.GetHabbo().Diamonds < TotalDiamondCost || Session.GetHabbo().GOTWPoints < TotalPointsCost)
  148. return;
  149.  
  150. if (Session.GetHabbo().Credits < PurchaseAmountCredits || Session.GetHabbo().Duckets < PurchaseAmountDuckets || Session.GetHabbo().Diamonds < PurchaseAmountDiamonds)
  151. return;
  152. if (Item.EventCount > 0 && Session.GetHabbo().Rank >= 2)
  153. {
  154. Session.GetHabbo().EventCount = Session.GetHabbo().EventCount + 1;
  155. }
  156.  
  157.  
  158. int LimitedEditionSells = 0;
  159. int LimitedEditionStack = 0;
  160.  
  161. #region Create the extradata
  162. switch (Item.Data.InteractionType)
  163. {
  164. case InteractionType.NONE:
  165. ExtraData = "";
  166. break;
  167.  
  168. case InteractionType.GUILD_ITEM:
  169. case InteractionType.GUILD_GATE:
  170. break;
  171.  
  172. case InteractionType.PINATA:
  173. case InteractionType.PINATATRIGGERED:
  174. case InteractionType.MAGICEGG:
  175. case InteractionType.MAGICCHEST:
  176. ExtraData = "0";
  177. break;
  178.  
  179. #region Pet handling
  180.  
  181. case InteractionType.PET:
  182. try
  183. {
  184. string[] Bits = ExtraData.Split('\n');
  185. string PetName = Bits[0];
  186. string Race = Bits[1];
  187. string Color = Bits[2];
  188.  
  189. int.Parse(Race); // to trigger any possible errors
  190.  
  191. if (!PetUtility.CheckPetName(PetName))
  192. return;
  193.  
  194. if (Race.Length > 2)
  195. return;
  196.  
  197. if (Color.Length != 6)
  198. return;
  199.  
  200. HabboEnvironment.GetGame().GetAchievementManager().ProgressAchievement(Session, "ACH_PetLover", 1);
  201. }
  202. catch (Exception e)
  203. {
  204. Logging.LogException(e.ToString());
  205. return;
  206. }
  207.  
  208. break;
  209.  
  210. #endregion
  211.  
  212. case InteractionType.FLOOR:
  213. case InteractionType.WALLPAPER:
  214. case InteractionType.LANDSCAPE:
  215.  
  216. Double Number = 0;
  217.  
  218. try
  219. {
  220. if (string.IsNullOrEmpty(ExtraData))
  221. Number = 0;
  222. else
  223. Number = Double.Parse(ExtraData, HabboEnvironment.CultureInfo);
  224. }
  225. catch (Exception e)
  226. {
  227. Logging.HandleException(e, "Catalog.HandlePurchase: " + ExtraData);
  228. }
  229.  
  230. ExtraData = Number.ToString().Replace(',', '.');
  231. break; // maintain extra data // todo: validate
  232.  
  233. case InteractionType.POSTIT:
  234. ExtraData = "FFFF33";
  235. break;
  236.  
  237. case InteractionType.MOODLIGHT:
  238. ExtraData = "1,1,1,#000000,255";
  239. break;
  240.  
  241. case InteractionType.TROPHY:
  242. ExtraData = Session.GetHabbo().Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + Convert.ToChar(9) + ExtraData;
  243. break;
  244.  
  245. case InteractionType.MANNEQUIN:
  246. ExtraData = "m" + Convert.ToChar(5) + ".ch-210-1321.lg-285-92" + Convert.ToChar(5) + "Default Mannequin";
  247. break;
  248.  
  249. case InteractionType.BADGE_DISPLAY:
  250. if (!Session.GetHabbo().GetBadgeComponent().HasBadge(ExtraData))
  251. {
  252. Session.SendMessage(new BroadcastMessageAlertComposer("Oops, it appears that you do not own this badge."));
  253. return;
  254. }
  255.  
  256. ExtraData = ExtraData + Convert.ToChar(9) + Session.GetHabbo().Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year;
  257. break;
  258.  
  259. case InteractionType.BADGE:
  260. {
  261. if (Session.GetHabbo().GetBadgeComponent().HasBadge(Item.Data.ItemName))
  262. {
  263. Session.SendMessage(new PurchaseErrorComposer(1));
  264. return;
  265. }
  266. break;
  267. }
  268. case InteractionType.CRACKABLE_EGG:
  269. {
  270. switch (Item.Data.ItemName)
  271. {
  272. default:
  273. case "easter13_egg_0":
  274. ExtraData = "0" + Convert.ToChar(5) + "0" + Convert.ToChar(5) + "1000";
  275. break;
  276.  
  277. case "easter13_egg_1":
  278. ExtraData = "0" + Convert.ToChar(5) + "0" + Convert.ToChar(5) + "5000";
  279. break;
  280.  
  281. case "easter13_egg_2":
  282. ExtraData = "0" + Convert.ToChar(5) + "0" + Convert.ToChar(5) + "10000";
  283. break;
  284.  
  285. case "easter13_egg_3":
  286. ExtraData = "0" + Convert.ToChar(5) + "0" + Convert.ToChar(5) + "20000";
  287. break;
  288. }
  289. break;
  290. }
  291. case InteractionType.GUILD_FORUM:
  292. {
  293. if (!int.TryParse(ExtraData, out int GroupId))
  294. {
  295. Session.SendNotification("Oops, Error. ");
  296. Session.SendMessage(new PurchaseOKComposer());
  297. return;
  298. }
  299.  
  300. if (!HabboEnvironment.GetGame().GetGroupManager().TryGetGroup(GroupId, out Group Group))
  301. {
  302. Session.SendNotification("An forum already exists for this Group.");
  303. Session.SendMessage(new PurchaseOKComposer());
  304. return;
  305. }
  306. if (!HabboEnvironment.GetGame().GetGroupManager().TryGetGroup(GroupId, out Group))
  307. {
  308. if (!Group.HasForum)
  309. {
  310. Session.SendNotification("This group doesn't have a forum. Therefore a terminal won't be created.");
  311. Session.SendMessage(new PurchaseOKComposer());
  312. return;
  313. }
  314. }
  315. if (!HabboEnvironment.GetGame().GetGroupForumManager().TryGetForum(GroupId, out GroupForum Gf))
  316. {
  317. if (Group.CreatorId != Session.GetHabbo().Id)
  318. {
  319. Session.SendMessage(new PurchaseOKComposer());
  320. return;
  321. }
  322.  
  323. Gf = HabboEnvironment.GetGame().GetGroupForumManager().CreateGroupForum(Group);
  324. }
  325.  
  326. var blah = new Dictionary<string, string>
  327. {
  328. { "groupId", ExtraData },
  329. { "groupName", Group.Name }
  330. };
  331. Session.SendMessage(new RoomNotificationComposer("forums.delivered", blah));
  332. break;
  333. }
  334. default:
  335. ExtraData = "";
  336. break;
  337. }
  338.  
  339. #endregion
  340.  
  341.  
  342.  
  343.  
  344.  
  345. if (Item.IsLimited)
  346. {
  347. if (Item.LimitedEditionStack <= Item.LimitedEditionSells)
  348. {
  349. 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!)");
  350. Session.SendMessage(new CatalogUpdatedComposer());
  351. Session.SendMessage(new PurchaseOKComposer());
  352. return;
  353. }
  354.  
  355. Item.LimitedEditionSells++;
  356. using (IQueryAdapter dbClient = HabboEnvironment.GetDatabaseManager().GetQueryReactor())
  357. {
  358. dbClient.RunQuery("UPDATE `catalog_items` SET `limited_sells` = '" + Item.LimitedEditionSells + "' WHERE `id` = '" + Item.Id + "' LIMIT 1");
  359. LimitedEditionSells = Item.LimitedEditionSells;
  360. LimitedEditionStack = Item.LimitedEditionStack;
  361. }
  362. }
  363.  
  364. if (Item.CostCredits > 0)
  365. {
  366. Session.GetHabbo().Credits -= TotalCreditsCost;
  367. Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
  368. }
  369. if (Item.CostCredits > 0 && Session.GetHabbo().PurchaseAmount > 0)
  370. {
  371. Session.GetHabbo().Credits -= PurchaseAmountCredits;
  372. Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
  373. }
  374. if (Item.CostPixels > 0 && Session.GetHabbo().PurchaseAmount > 0)
  375. {
  376. Session.GetHabbo().Duckets -= PurchaseAmountDuckets;
  377. Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Duckets, Session.GetHabbo().Duckets));//Love you, Tom.
  378. }
  379. if (Item.CostDiamonds > 0 && Session.GetHabbo().PurchaseAmount > 0)
  380. {
  381. Session.GetHabbo().Diamonds -= PurchaseAmountDiamonds;
  382. Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Diamonds, 0, 5));
  383. }
  384. if (Item.CostPixels > 0 && Item.Type == 0)
  385. {
  386. Session.GetHabbo().Duckets -= TotalPixelCost;
  387. Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Duckets, Session.GetHabbo().Duckets));//Love you, Tom.
  388. }
  389. if (Item.CostPixels > 0 && Item.Type == 103)
  390. {
  391. Session.GetHabbo().GOTWPoints -= TotalPixelCost;
  392. Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().GOTWPoints, Session.GetHabbo().GOTWPoints, 103));//Love you, Tom.
  393. }
  394.  
  395. if (Item.CostDiamonds > 0)
  396. {
  397. Session.GetHabbo().Diamonds -= TotalDiamondCost;
  398. Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Diamonds, 0, 5));
  399. }
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410. Item NewItem = null;
  411. switch (Item.Data.Type.ToString().ToLower())
  412. {
  413. default:
  414. List<Item> GeneratedGenericItems = new List<Item>();
  415.  
  416. switch (Item.Data.InteractionType)
  417. {
  418. default:
  419.  
  420. if (AmountPurchase > 1)
  421. {
  422. List<Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase);
  423.  
  424. if (Items != null)
  425. {
  426. GeneratedGenericItems.AddRange(Items);
  427. }
  428. }
  429. else if (Session.GetHabbo().PurchaseAmount > 1)
  430. {
  431. List<Item> Items2 = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, Session.GetHabbo().PurchaseAmount);
  432.  
  433. if (Items2 != null)
  434. {
  435. GeneratedGenericItems.AddRange(Items2);
  436. }
  437. }
  438. else
  439. {
  440. NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData, 0, LimitedEditionSells, LimitedEditionStack);
  441.  
  442. if (NewItem != null)
  443. {
  444. GeneratedGenericItems.Add(NewItem);
  445. }
  446. }
  447. break;
  448.  
  449. case InteractionType.GUILD_GATE:
  450. case InteractionType.GUILD_ITEM:
  451. case InteractionType.GUILD_FORUM:
  452. if (AmountPurchase > 1)
  453. {
  454. List<Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase, Convert.ToInt32(ExtraData));
  455.  
  456. if (Items != null)
  457. {
  458. GeneratedGenericItems.AddRange(Items);
  459. }
  460. }
  461. else
  462. {
  463. NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData, Convert.ToInt32(ExtraData));
  464.  
  465. if (NewItem != null)
  466. {
  467. GeneratedGenericItems.Add(NewItem);
  468. }
  469. }
  470. break;
  471.  
  472.  
  473.  
  474.  
  475. case InteractionType.ARROW:
  476. case InteractionType.TELEPORT:
  477. for (int i = 0; i < AmountPurchase; i++)
  478. {
  479. List<Item> TeleItems = ItemFactory.CreateTeleporterItems(Item.Data, Session.GetHabbo());
  480.  
  481. if (TeleItems != null)
  482. {
  483. GeneratedGenericItems.AddRange(TeleItems);
  484. }
  485. }
  486. break;
  487.  
  488. case InteractionType.MOODLIGHT:
  489. {
  490. if (AmountPurchase > 1)
  491. {
  492. List<Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase);
  493.  
  494. if (Items != null)
  495. {
  496. GeneratedGenericItems.AddRange(Items);
  497. foreach (Item I in Items)
  498. {
  499. ItemFactory.CreateMoodlightData(I);
  500. }
  501. }
  502. }
  503. else
  504. {
  505. NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData);
  506.  
  507. if (NewItem != null)
  508. {
  509. GeneratedGenericItems.Add(NewItem);
  510. ItemFactory.CreateMoodlightData(NewItem);
  511. }
  512. }
  513. }
  514. break;
  515.  
  516. case InteractionType.TONER:
  517. {
  518. if (AmountPurchase > 1)
  519. {
  520. List<Item> Items = ItemFactory.CreateMultipleItems(Item.Data, Session.GetHabbo(), ExtraData, AmountPurchase);
  521.  
  522. if (Items != null)
  523. {
  524. GeneratedGenericItems.AddRange(Items);
  525. foreach (Item I in Items)
  526. {
  527. ItemFactory.CreateTonerData(I);
  528. }
  529. }
  530. }
  531. else
  532. {
  533. NewItem = ItemFactory.CreateSingleItemNullable(Item.Data, Session.GetHabbo(), ExtraData, ExtraData);
  534.  
  535. if (NewItem != null)
  536. {
  537. GeneratedGenericItems.Add(NewItem);
  538. ItemFactory.CreateTonerData(NewItem);
  539. }
  540. }
  541. }
  542. break;
  543.  
  544.  
  545. case InteractionType.DEAL:
  546. {
  547. if (HabboEnvironment.GetGame().GetCatalog().TryGetDeal(Item.Data.BehaviourData, out CatalogDeal deal))
  548. {
  549. //Here I loop the DealItems ItemDataList.
  550. foreach (CatalogItem CatalogItem in deal.ItemDataList.ToList())
  551. {
  552. List<Item> Items = ItemFactory.CreateMultipleItems(CatalogItem.Data, Session.GetHabbo(), "", deal.DealAmount);
  553.  
  554. if (Items != null)
  555. {
  556. GeneratedGenericItems.AddRange(Items);
  557. }
  558. }
  559. }
  560. break;
  561. }
  562.  
  563. case InteractionType.ROOMDEAL:
  564. {
  565. //WeeklyBundle WBundle = HabboEnvironment.GetGame().GetCatalog().GetWeeklyBundle(Page.Id);
  566.  
  567. //if (Page.Id == WBundle.BundleId)
  568. //{
  569. // if (Item.CostCredits > 0)
  570. // {
  571. // WBundle.GetCreator().Credits += Item.CostCredits;
  572. // WBundle.GetCreator().GetClient().SendMessage(new CreditBalanceComposer(WBundle.GetCreator().Credits));
  573. // }
  574. // if (Item.CostPixels > 0)
  575. // {
  576. // WBundle.GetCreator().Duckets += Item.CostPixels;
  577. // WBundle.GetCreator().GetClient().SendMessage(new HabboActivityPointNotificationComposer(WBundle.GetCreator().Duckets, Session.GetHabbo().Duckets));//Love you, Tom.
  578. // }
  579.  
  580. //}
  581. if (HabboEnvironment.GetGame().GetCatalog().TryGetDeal(Item.Data.BehaviourData, out CatalogDeal deal))
  582. {
  583. Room room = HabboEnvironment.GetGame().GetRoomManager().LoadRoom(deal.RoomId);
  584. if (room == null)
  585. Session.SendNotification("There was an error loading this Room Bundle, if this happens again please contact hotel management!");
  586.  
  587. 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);
  588. if (newRoom == null)
  589. return;
  590.  
  591. Room myRoom = HabboEnvironment.GetGame().GetRoomManager().LoadRoom(newRoom.Id);
  592. if (myRoom != null)
  593. {
  594. List<Pet> Pets = ItemLoader.GetPets(deal.RoomId);
  595. List<Item> Items = ItemLoader.GetItemsForRoom(deal.RoomId, room);
  596. Item teleLink = null;
  597. foreach(Pet pet in Pets)
  598. {
  599. if (pet == null)
  600. continue;
  601.  
  602. var RndSpeechList = new List<RandomSpeech>();
  603. 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);
  604. }
  605.  
  606. foreach (Item furni in Items)
  607. {
  608. if (furni.Data.InteractionType == InteractionType.TELEPORT)
  609. {
  610. if (teleLink == null)
  611. {
  612. List<Item> TeleItems = ItemFactory.CreateTeleporterItems(furni.Data, Session.GetHabbo());
  613. if (TeleItems != null && TeleItems.ToList().Count > 1)
  614. {
  615. myRoom.GetRoomItemHandler().SetFloorItem(Session, TeleItems[0], furni.GetX, furni.GetY, furni.Rotation, true, true, true, false, furni.GetZ);
  616. teleLink = TeleItems[1];
  617. }
  618. }
  619. else
  620. {
  621. myRoom.GetRoomItemHandler().SetFloorItem(Session, teleLink, furni.GetX, furni.GetY, furni.Rotation, true, true, true, false, furni.GetZ);
  622. teleLink = null;
  623. }
  624. }
  625. else
  626. {
  627. NewItem = ItemFactory.CreateSingleItemNullable(furni.Data, Session.GetHabbo(), furni.ExtraData, "", furni.GroupId);
  628. if (NewItem != null)
  629. {
  630. if (NewItem.IsWallItem)
  631. {
  632. NewItem.wallCoord = furni.wallCoord;
  633. myRoom.GetRoomItemHandler().SetWallItem(Session, NewItem);
  634. }
  635. else
  636. myRoom.GetRoomItemHandler().SetFloorItem(Session, NewItem, furni.GetX, furni.GetY, furni.Rotation, true, true, true, false, furni.GetZ);
  637. }
  638. }
  639. }
  640. Session.GetHabbo().PrepareRoom(myRoom.Id, "");
  641. }
  642. }
  643. break;
  644. }
  645. }
  646.  
  647. foreach (Item PurchasedItem in GeneratedGenericItems)
  648. {
  649. if (Session.GetHabbo().GetInventoryComponent().TryAddItem(PurchasedItem))
  650. {
  651. //Session.SendMessage(new FurniListAddComposer(PurchasedItem));
  652. Session.SendMessage(new FurniListNotificationComposer(PurchasedItem.Id, 1));
  653. }
  654. }
  655. break;
  656.  
  657. case "e":
  658. AvatarEffect Effect = null;
  659. if (Session.GetHabbo().Effects().HasEffect(Item.Data.SpriteId))
  660. {
  661. Effect = Session.GetHabbo().Effects().GetEffectNullable(Item.Data.SpriteId);
  662.  
  663. if (Effect != null)
  664. {
  665. Effect.AddToQuantity();
  666. }
  667. }
  668. else
  669. Effect = AvatarEffectFactory.CreateNullable(Session.GetHabbo(), Item.Data.SpriteId, 3600);
  670.  
  671. if (Effect != null)// && Session.GetHabbo().Effects().TryAdd(Effect))
  672. {
  673. Session.SendMessage(new AvatarEffectAddedComposer(Item.Data.SpriteId, 3600));
  674. }
  675. break;
  676.  
  677. case "r":
  678. Bot Bot = BotUtility.CreateBot(Item.Data, Session.GetHabbo().Id);
  679. if (Bot != null)
  680. {
  681. Session.GetHabbo().GetInventoryComponent().TryAddBot(Bot);
  682. Session.SendMessage(new BotInventoryComposer(Session.GetHabbo().GetInventoryComponent().GetBots()));
  683. Session.SendMessage(new FurniListNotificationComposer(Bot.Id, 5));
  684. }
  685. else
  686. Session.SendNotification("Oops! There was an error whilst purchasing this bot. It seems that there is no bot data for the bot!");
  687. break;
  688.  
  689. case "b":
  690. {
  691. Session.GetHabbo().GetBadgeComponent().GiveBadge(Item.Data.ItemName, true, Session);
  692. Session.SendMessage(new FurniListNotificationComposer(0, 4));
  693. break;
  694. }
  695.  
  696.  
  697. case "p":
  698. {
  699. string[] PetData = ExtraData.Split('\n');
  700. Pet GeneratedPet = PetUtility.CreatePet(Session.GetHabbo().Id, PetData[0], Item.Data.BehaviourData, PetData[1], PetData[2]);
  701. if (GeneratedPet != null)
  702. {
  703. Session.GetHabbo().GetInventoryComponent().TryAddPet(GeneratedPet);
  704.  
  705. Session.SendMessage(new FurniListNotificationComposer(GeneratedPet.PetId, 3));
  706. Session.SendMessage(new PetInventoryComposer(Session.GetHabbo().GetInventoryComponent().GetPets()));
  707.  
  708. if (HabboEnvironment.GetGame().GetItemManager().GetItem(320, out ItemData PetFood))
  709. {
  710. Item Food = ItemFactory.CreateSingleItemNullable(PetFood, Session.GetHabbo(), "", "");
  711. if (Food != null)
  712. {
  713. Session.GetHabbo().GetInventoryComponent().TryAddItem(Food);
  714. Session.SendMessage(new FurniListNotificationComposer(Food.Id, 1));
  715. }
  716. }
  717. }
  718. break;
  719. }
  720. }
  721.  
  722. if (!string.IsNullOrEmpty(Item.Badge) &&
  723. HabboEnvironment.GetGame().GetBadgeManager().TryGetBadge(Item.Badge, out BadgeDefinition Badge) &&
  724. (string.IsNullOrEmpty(Badge.RequiredRight) || Session.GetHabbo().GetPermissions().HasRight(Badge.RequiredRight)))
  725. {
  726. Session.GetHabbo().GetBadgeComponent().GiveBadge(Badge.Code, true, Session);
  727. }
  728.  
  729. Session.SendMessage(new PurchaseOKComposer(Item, Item.Data));
  730. Session.SendMessage(new FurniListUpdateComposer());
  731. break;
  732.  
  733.  
  734. case "vip_buy":
  735. if (!HabboEnvironment.GetGame().GetCatalog().GetHabboClub().TryGetClubOffer(ItemId, out CatalogClubOffer Offer))
  736. {
  737. SendErrorMessage(Session, "Club offer item does not exist.");
  738. return;
  739. }
  740. if (Offer.CreditsCost > 0 && Session.GetHabbo().Credits < Offer.CreditsCost)
  741. {
  742. SendErrorMessage(Session, "Subscription purchase failed.");
  743. return;
  744. }
  745. if (Session.GetHabbo().GetSubscriptions().TryGetSubscription("club_habbo", out ClubSubscription ActiveSub))
  746. {
  747. }
  748. if (!ClubSubscriptionFactory.AddOrExtend(Session.GetHabbo(), "club_habbo", Offer.LengthSeconds, out ClubSubscription SubCreated))
  749. {
  750. SendErrorMessage(Session, "Subscription factory failed.");
  751. return;
  752. }
  753. if (ActiveSub == null)
  754. {
  755. ActiveSub = SubCreated;
  756. }
  757. if (Offer.CreditsCost > 0)
  758. {
  759. Session.GetHabbo().Credits -= Offer.CreditsCost;
  760. Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
  761. }
  762. Session.GetHabbo().GetPermissions().Init(Session.GetHabbo());
  763. Session.GetHabbo().GetBadgeComponent().GiveBadge("ACH_VipHC1", true, Session);
  764. Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
  765. Session.SendMessage(new PurchaseOKComposer(Offer));
  766. Session.SendMessage(new ScrSendUserInfoComposer(Session, ActiveSub));
  767. Session.SendMessage(new UserRightsComposer(Session, Session.GetHabbo().Rank, Session.GetHabbo().Ambassadar));
  768. break;
  769. }
  770. }
  771. private void SendErrorMessage(GameClient Session, string Error)
  772. {
  773. Session.SendNotification("Catalog error: " + Error);
  774. }
  775. }
  776. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement