Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Threading;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using ArcheBuddy.Bot.Classes;
  7.  
  8. namespace OpenAuctionHouse
  9. {
  10. public class OpenAuctionHouse : Core
  11. {
  12. private int overbidamount = 40; //dinero en cobre que subes la apuesta
  13. private int waitSecondsForAuctionEnd = 180; // if a bid item is at < 3 minutes wait for it to end
  14. private int msToBidBeforeAuctionEnd = 5000; // tiempo que le queda para apostar (5seg)
  15.  
  16. private Random r = new Random();
  17. public static string GetPluginAuthor()
  18. {
  19. return "lypnn";
  20. }
  21.  
  22. public static string GetPluginVersion()
  23. {
  24. return "2.3.0.0";
  25. }
  26.  
  27. public static string GetPluginDescription()
  28. {
  29. return "Open Auction House";
  30. }
  31.  
  32. //Call on plugin start
  33. public void PluginRun()
  34. {
  35. try
  36. {
  37. Log(DateTime.Now.ToShortTimeString() + " > ----- Open Auction House started -----");
  38.  
  39. while (true)
  40. {
  41. buyFromAuctionHouse("Potato", 110, 25); // 1 º nombre del objeto, 2º precio en cobre por lo que lo comprarias, 3º cantidad minima
  42. buyFromAuctionHouse("Yellow Potato", 990, 2);
  43.  
  44. // add more items here
  45. }
  46. }
  47. catch (Exception e)
  48. {
  49. if (e.GetType() != typeof(System.Threading.ThreadAbortException))
  50. {
  51. Log(DateTime.Now.ToShortTimeString() +" ERROR " +GetLastError().ToString() +" " +e.GetType().ToString() +" " +e.StackTrace);
  52. Log(e.Message);
  53. }
  54. }
  55. }
  56.  
  57. //Call on plugin stop
  58. public void PluginStop()
  59. {
  60. Log(DateTime.Now.ToShortTimeString() + " > ----- Open Auction House stopped -----");
  61. }
  62.  
  63. ////////// no variables to edit below this line /////////////
  64.  
  65. //buyout an auction house item
  66. public void buyFromAuctionHouse(string mySearchText, int maxprice, int minamount) // maxprice per item in copper, 1g = 1 00 00 copper
  67. {
  68. AuctionRequestParams req = new AuctionRequestParams(AuctionCategory.Off, 0, 0, mySearchText, false, ItemGrade.Common, AuctionSortType.Time, SortOrder.Asc);
  69. int pip; // per item price
  70. bool bidreturn;
  71.  
  72. List<AuctionItem> items = getAuctionBuyList(req, 0);
  73. if(items != null)
  74. {
  75. foreach (AuctionItem item in items)
  76. {
  77. if (!item.item.name.Equals(mySearchText)) // auctionitem item name must match the searchText
  78. continue;
  79.  
  80. if (Convert.ToInt32(item.time) > waitSecondsForAuctionEnd)
  81. {
  82. pip = (int)item.buyBackPrice / item.item.count;
  83.  
  84. if (item.item.count < minamount || item.buyBackPrice == 0 || pip > maxprice)
  85. continue;
  86.  
  87. if (me.goldCount >= item.buyBackPrice)
  88. {
  89. Thread.Sleep(100 + r.Next(150));
  90. bidreturn = item.MakeAuctionBid(item.buyBackPrice);
  91. Thread.Sleep(1000 + r.Next(500));
  92. if (bidreturn)
  93. Log(DateTime.Now.ToShortTimeString() + " > Attempting to BUYOUT " + item.item.count + " " + item.item.name + " with per item price " + pip.ToString() + " ... succeeded !");
  94. else
  95. Log(DateTime.Now.ToShortTimeString() + " > Attempting to BUYOUT " + item.item.count + " " + item.item.name + " with per item price " + pip.ToString() + " ... failed.");
  96. }
  97. else
  98. Log(DateTime.Now.ToShortTimeString() + " > not enough gold to buyout " + item.item.count + " " + item.item.name + " for " + item.buyBackPrice);
  99. }
  100. else // auction items time is nearly over, check if we want to bid on it
  101. {
  102. pip = (item.bidMoney != 0 ? item.bidMoney : item.sellPrice) / item.item.count;
  103. if (pip + overbidamount <= maxprice && item.item.count >= minamount) // check if this is an item below maxprice
  104. {
  105. bidOnAuctionHouse(req, item.uniqId, maxprice);
  106. break;
  107. }
  108. }
  109. }
  110. }
  111. else
  112. {
  113. Log(DateTime.Now.ToShortTimeString() + " > " +GetLastError().ToString() +" Error ... will try again");
  114. }
  115. Thread.Sleep(2000 + r.Next(3000)); // Random sleep 2-5s
  116. }
  117. public void bidOnAuctionHouse(AuctionRequestParams req, ulong itemId, int maxprice)
  118. {
  119. int pip; // per item price
  120. int myBidAmount;
  121. int sleepTime;
  122. bool bidreturn;
  123.  
  124. List<AuctionItem> items = getAuctionBuyList(req, 9);
  125. foreach (AuctionItem item in items)
  126. {
  127. if (item.uniqId == itemId)
  128. {
  129. pip = (item.bidMoney != 0 ? item.bidMoney : item.sellPrice) / item.item.count;
  130. if (pip + overbidamount <= maxprice)
  131. {
  132. sleepTime = Convert.ToInt32(item.time) * 1000 - Convert.ToInt32(r.Next(500)) - msToBidBeforeAuctionEnd;
  133. Log(DateTime.Now.ToShortTimeString() + " > waiting " + ((int)sleepTime / 1000).ToString() + " seconds to attempt a last-second-bid on " + item.item.count + " " + item.item.name + " (current bid price per item: " + pip + " maxprice: " +maxprice +")");
  134. if (sleepTime > 100)
  135. Thread.Sleep(sleepTime);
  136. break;
  137. }
  138. else
  139. return; // the item has become too expensive
  140. }
  141. }
  142.  
  143. items = getAuctionBuyList(req, 9);
  144. foreach (AuctionItem item in items)
  145. {
  146. if (item.uniqId == itemId)
  147. {
  148. pip = (item.bidMoney != 0 ? item.bidMoney : item.sellPrice) / item.item.count;
  149. if (pip + overbidamount <= maxprice)
  150. {
  151. myBidAmount = (item.bidMoney != 0 ? item.bidMoney : item.sellPrice) + overbidamount;
  152. if (me.goldCount >= myBidAmount)
  153. {
  154. bidreturn = item.MakeAuctionBid(myBidAmount);
  155. Thread.Sleep(1000 + r.Next(500));
  156. if (bidreturn)
  157. Log(DateTime.Now.ToShortTimeString() + " > Successfully sent a BID on " + item.item.count + " " + item.item.name + " with " + myBidAmount + " (pip: " + (myBidAmount/item.item.count) + ")");
  158. else
  159. Log(DateTime.Now.ToShortTimeString() + " > Failed to send a BID on " + item.item.count + " " + item.item.name + " with " + myBidAmount + " (pip: " +(myBidAmount/item.item.count) +")");
  160. }
  161. else
  162. Log(DateTime.Now.ToShortTimeString() + " > not enough gold to bid on " + item.item.count + " " + item.item.name + " with " + myBidAmount);
  163. }
  164. else
  165. return; // the item has become too expensive
  166. }
  167. }
  168. }
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement