Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Releases
Server Releases
[PLUS] Randomly numbered Limited Edition.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Damien" data-source="post: 447141" data-attributes="member: 72299"><p>Someone asked me to code this into plus for them, thought I'd share it for everyone. [USER=1553]@Meap[/USER]</p><p></p><p>[SPOILER="RandomNumber.cs"]</p><p>Firstly add this method:</p><p>[CODE]</p><p>public static void Shuffle<T>(this List<T> list)</p><p>{</p><p> int n = list.Count;</p><p> while (n > 1)</p><p> {</p><p> n--;</p><p> int k = r.Next(n + 1);</p><p> T value = list[k];</p><p> list[k] = list[n];</p><p> list[n] = value;</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p></p><p>Don't forget the reference:</p><p>[CODE]</p><p>using System.Collections.Generic;</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p>[SPOILER="CatalogItem.cs"]</p><p>Replace the constructor with this:</p><p>[CODE]</p><p>public CatalogItem(int id, int itemId, ItemData data, string catalogName, int pageId, int costCredits, int costPixels,</p><p> int costDiamonds, int amount, int limitedEditionSells, int limitedEditionStack, bool hasOffer, string extraData, string badge, int offerId)</p><p> int costDiamonds, int amount, List<int> limitedNumbers, int limitedEditionStack, bool hasOffer, string extraData, string badge, int offerId)</p><p>{</p><p> Id = id;</p><p> Name = catalogName;</p><p> ItemId = itemId;</p><p> Data = data;</p><p> PageID = pageId;</p><p> CostCredits = costCredits;</p><p> CostPixels = costPixels;</p><p> CostDiamonds = costDiamonds;</p><p> Amount = amount;</p><p> LimitedEditionSells = limitedEditionSells;</p><p> LimitedNumbers = limitedNumbers;</p><p> LimitedEditionSells = limitedEditionStack - limitedNumbers.Count;</p><p> LimitedEditionStack = limitedEditionStack;</p><p> IsLimited = (limitedEditionStack > 0);</p><p> IsLimited = limitedEditionStack > 0;</p><p> HaveOffer = hasOffer;</p><p> ExtraData = extraData;</p><p> Badge = badge;</p><p> OfferId = offerId;</p><p>}</p><p>[/CODE]</p><p></p><p></p><p>Making sure to add the variable</p><p>[CODE]</p><p>public List<int> LimitedNumbers { get; private set; }</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p>[SPOILER="CatalogManager.cs"]</p><p>Add this method:</p><p>[CODE]</p><p>private List<int> GetLimitedNumbers(int itemId, int size)</p><p>{</p><p> List<int> availableNumbers = new List<int>();</p><p> List<int> takenNumbers = new List<int>();</p><p></p><p> using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())</p><p> {</p><p> dbClient.SetQuery("SELECT `number` FROM `catalog_items_limited` WHERE `item_id` = @itemId");</p><p> dbClient.AddParameter("itemId", itemId);</p><p> DataTable limitedNumbers = dbClient.GetTable();</p><p></p><p> if (limitedNumbers != null)</p><p> {</p><p> foreach (DataRow row in limitedNumbers.Rows)</p><p> {</p><p> int numberId = Convert.ToInt32(row["number"]);</p><p> if (!takenNumbers.Contains(numberId))</p><p> takenNumbers.Add(numberId);</p><p> }</p><p> }</p><p> }</p><p></p><p> for (int i = 1; i <= size; i++)</p><p> {</p><p> if (!takenNumbers.Contains(i))</p><p> availableNumbers.Add(i);</p><p> }</p><p></p><p> return availableNumbers;</p><p>}</p><p>[/CODE]</p><p></p><p></p><p>Then change this script:</p><p>[CODE]</p><p>_items[PageId].Add(Convert.ToInt32(Row["id"]), new CatalogItem(...));</p><p>[/CODE]</p><p></p><p></p><p>To this:</p><p>[CODE]</p><p>List<int> limitedNumbers = GetLimitedNumbers(</p><p> Convert.ToInt32(Row["id"]),</p><p> Convert.ToInt32(Row["limited_stack"]));</p><p>limitedNumbers.Shuffle();</p><p></p><p>_items[PageId].Add(Convert.ToInt32(Row["id"]), new CatalogItem(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["item_id"]),</p><p> Data, Convert.ToString(Row["catalog_name"]), Convert.ToInt32(Row["page_id"]), Convert.ToInt32(Row["cost_credits"]), Convert.ToInt32(Row["cost_pixels"]), Convert.ToInt32(Row["cost_diamonds"]),</p><p> Convert.ToInt32(Row["amount"]), Convert.ToInt32(Row["limited_sells"]), Convert.ToInt32(Row["limited_stack"]), PlusEnvironment.EnumToBool(Row["offer_active"].ToString()),</p><p> Convert.ToInt32(Row["amount"]), limitedNumbers, Convert.ToInt32(Row["limited_stack"]), PlusEnvironment.EnumToBool(Row["offer_active"].ToString()),</p><p> Convert.ToString(Row["extradata"]), Convert.ToString(Row["badge"]), Convert.ToInt32(Row["offer_id"])));</p><p>[/CODE]</p><p></p><p></p><p>Making sure to add the appropriate references:</p><p>[CODE]</p><p>using Plus.Utilities;</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p>[SPOILER="CatalogDeal.cs"]</p><p>Change this script:</p><p>[CODE]</p><p>ItemDataList.Add(new CatalogItem(...));</p><p>[/CODE]</p><p></p><p></p><p>To this:</p><p>[CODE]</p><p>ItemDataList.Add(new CatalogItem(0, itemId, data, string.Empty, 0, 0, 0, 0, Amount, new List<int>(), 0, false, "", "", 0));</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p>[SPOILER="PurchaseFromCatalogEvent.cs"]</p><p>Find this if statement:</p><p>[CODE]</p><p>if (item.IsLimited)</p><p>{</p><p> ....</p><p>}</p><p>[/CODE]</p><p></p><p></p><p>And change it to this:</p><p>[CODE]</p><p>if (item.IsLimited)</p><p>{</p><p> if (item.LimitedNumbers.Count <= 0)</p><p> {</p><p> 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!)");</p><p> session.SendPacket(new CatalogUpdatedComposer());</p><p> session.SendPacket(new PurchaseOKComposer());</p><p> return;</p><p> }</p><p></p><p> limitedEditionNumber = item.LimitedNumbers[0];</p><p> limitedEditionStack = item.LimitedEditionStack;</p><p> item.LimitedEditionSells++;</p><p></p><p> using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())</p><p> {</p><p> dbClient.SetQuery("INSERT INTO `catalog_items_limited` (`number`, `item_id`) VALUES (@number, @itemId)");</p><p> dbClient.AddParameter("number", limitedEditionNumber);</p><p> dbClient.AddParameter("itemId", item.Id);</p><p> dbClient.RunQuery();</p><p> </p><p> item.LimitedNumbers.Remove(limitedEditionNumber);</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p></p><p>Then change every reference for:</p><p>[CODE]</p><p>limitedEditionSells</p><p>[/CODE]</p><p></p><p></p><p>To this:</p><p>[CODE]</p><p>limitedEditionNumber</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p>[SPOILER="Database Table"]</p><p>[CODE]</p><p>CREATE TABLE `catalog_items_limited` (</p><p> `id` int(11) NOT NULL AUTO_INCREMENT,</p><p> `number` int(11) NOT NULL DEFAULT 0,</p><p> `item_id` int(11) NOT NULL DEFAULT 0,</p><p> PRIMARY KEY (`id`) USING BTREE,</p><p> UNIQUE INDEX `number, item_id`(`number`, `item_id`) USING BTREE,</p><p> INDEX `item_id`(`item_id`) USING BTREE</p><p>) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p>And you're done.</p></blockquote><p></p>
[QUOTE="Damien, post: 447141, member: 72299"] Someone asked me to code this into plus for them, thought I'd share it for everyone. [USER=1553]@Meap[/USER] [SPOILER="RandomNumber.cs"] Firstly add this method: [CODE] public static void Shuffle<T>(this List<T> list) { int n = list.Count; while (n > 1) { n--; int k = r.Next(n + 1); T value = list[k]; list[k] = list[n]; list[n] = value; } } [/CODE] Don't forget the reference: [CODE] using System.Collections.Generic; [/CODE] [/SPOILER] [SPOILER="CatalogItem.cs"] Replace the constructor with this: [CODE] public CatalogItem(int id, int itemId, ItemData data, string catalogName, int pageId, int costCredits, int costPixels, int costDiamonds, int amount, int limitedEditionSells, int limitedEditionStack, bool hasOffer, string extraData, string badge, int offerId) int costDiamonds, int amount, List<int> limitedNumbers, int limitedEditionStack, bool hasOffer, string extraData, string badge, int offerId) { Id = id; Name = catalogName; ItemId = itemId; Data = data; PageID = pageId; CostCredits = costCredits; CostPixels = costPixels; CostDiamonds = costDiamonds; Amount = amount; LimitedEditionSells = limitedEditionSells; LimitedNumbers = limitedNumbers; LimitedEditionSells = limitedEditionStack - limitedNumbers.Count; LimitedEditionStack = limitedEditionStack; IsLimited = (limitedEditionStack > 0); IsLimited = limitedEditionStack > 0; HaveOffer = hasOffer; ExtraData = extraData; Badge = badge; OfferId = offerId; } [/CODE] Making sure to add the variable [CODE] public List<int> LimitedNumbers { get; private set; } [/CODE] [/SPOILER] [SPOILER="CatalogManager.cs"] Add this method: [CODE] private List<int> GetLimitedNumbers(int itemId, int size) { List<int> availableNumbers = new List<int>(); List<int> takenNumbers = new List<int>(); using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT `number` FROM `catalog_items_limited` WHERE `item_id` = @itemId"); dbClient.AddParameter("itemId", itemId); DataTable limitedNumbers = dbClient.GetTable(); if (limitedNumbers != null) { foreach (DataRow row in limitedNumbers.Rows) { int numberId = Convert.ToInt32(row["number"]); if (!takenNumbers.Contains(numberId)) takenNumbers.Add(numberId); } } } for (int i = 1; i <= size; i++) { if (!takenNumbers.Contains(i)) availableNumbers.Add(i); } return availableNumbers; } [/CODE] Then change this script: [CODE] _items[PageId].Add(Convert.ToInt32(Row["id"]), new CatalogItem(...)); [/CODE] To this: [CODE] List<int> limitedNumbers = GetLimitedNumbers( Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["limited_stack"])); limitedNumbers.Shuffle(); _items[PageId].Add(Convert.ToInt32(Row["id"]), new CatalogItem(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["item_id"]), Data, Convert.ToString(Row["catalog_name"]), Convert.ToInt32(Row["page_id"]), Convert.ToInt32(Row["cost_credits"]), Convert.ToInt32(Row["cost_pixels"]), Convert.ToInt32(Row["cost_diamonds"]), Convert.ToInt32(Row["amount"]), Convert.ToInt32(Row["limited_sells"]), Convert.ToInt32(Row["limited_stack"]), PlusEnvironment.EnumToBool(Row["offer_active"].ToString()), Convert.ToInt32(Row["amount"]), limitedNumbers, Convert.ToInt32(Row["limited_stack"]), PlusEnvironment.EnumToBool(Row["offer_active"].ToString()), Convert.ToString(Row["extradata"]), Convert.ToString(Row["badge"]), Convert.ToInt32(Row["offer_id"]))); [/CODE] Making sure to add the appropriate references: [CODE] using Plus.Utilities; [/CODE] [/SPOILER] [SPOILER="CatalogDeal.cs"] Change this script: [CODE] ItemDataList.Add(new CatalogItem(...)); [/CODE] To this: [CODE] ItemDataList.Add(new CatalogItem(0, itemId, data, string.Empty, 0, 0, 0, 0, Amount, new List<int>(), 0, false, "", "", 0)); [/CODE] [/SPOILER] [SPOILER="PurchaseFromCatalogEvent.cs"] Find this if statement: [CODE] if (item.IsLimited) { .... } [/CODE] And change it to this: [CODE] if (item.IsLimited) { if (item.LimitedNumbers.Count <= 0) { 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.SendPacket(new CatalogUpdatedComposer()); session.SendPacket(new PurchaseOKComposer()); return; } limitedEditionNumber = item.LimitedNumbers[0]; limitedEditionStack = item.LimitedEditionStack; item.LimitedEditionSells++; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("INSERT INTO `catalog_items_limited` (`number`, `item_id`) VALUES (@number, @itemId)"); dbClient.AddParameter("number", limitedEditionNumber); dbClient.AddParameter("itemId", item.Id); dbClient.RunQuery(); item.LimitedNumbers.Remove(limitedEditionNumber); } } [/CODE] Then change every reference for: [CODE] limitedEditionSells [/CODE] To this: [CODE] limitedEditionNumber [/CODE] [/SPOILER] [SPOILER="Database Table"] [CODE] CREATE TABLE `catalog_items_limited` ( `id` int(11) NOT NULL AUTO_INCREMENT, `number` int(11) NOT NULL DEFAULT 0, `item_id` int(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `number, item_id`(`number`, `item_id`) USING BTREE, INDEX `item_id`(`item_id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic; [/CODE] [/SPOILER] And you're done. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Releases
Server Releases
[PLUS] Randomly numbered Limited Edition.
Top