Advertisement
Guest User

eyy bby

a guest
Oct 21st, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.98 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; // attempt to bid 40c above current bid
  13. private int waitSecondsForAuctionEnd = 180; // if a bid item is at < 3 minutes wait for it to end
  14. private int msToBidBeforeAuctionEnd = 5000; // wait until timeleft = 5 seconds until bidding myself
  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("Moonlight Archeum Motes", 663, 1); // 100 copper per item, minimum amount 2
  42. buyFromAuctionHouse("Trimmed Meat", 69, 2); // 100 copper per item, minimum amount 2
  43. buyFromAuctionHouse("Ground Spices", 101, 2); // 50 copper per item, minimum amount 2
  44. buyFromAuctionHouse("Orchard Puree", 250, 2); // 100 copper per item, minimum amount 2
  45. buyFromAuctionHouse("Medicinal Powder", 101, 2); // 100 copper per item, minimum amount 2
  46.  
  47. // add more items here
  48. }
  49. }
  50. catch (Exception e)
  51. {
  52. if (e.GetType() != typeof(System.Threading.ThreadAbortException))
  53. {
  54. Log(DateTime.Now.ToShortTimeString() +" ERROR " +GetLastError().ToString() +" " +e.GetType().ToString() +" " +e.StackTrace);
  55. Log(e.Message);
  56. }
  57. }
  58. }
  59.  
  60. //Call on plugin stop
  61. public void PluginStop()
  62. {
  63. Log(DateTime.Now.ToShortTimeString() + " > ----- Open Auction House stopped -----");
  64. }
  65.  
  66. ////////// no variables to edit below this line /////////////
  67.  
  68. //buyout an auction house item
  69. public void buyFromAuctionHouse(string mySearchText, int maxprice, int minamount) // maxprice per item in copper, 1g = 1 00 00 copper
  70. {
  71. AuctionRequestParams req = new AuctionRequestParams(AuctionCategory.Off, 0, 0, mySearchText, false, ItemGrade.Common, AuctionSortType.Time, SortOrder.Asc);
  72. int pip; // per item price
  73. bool bidreturn;
  74.  
  75. List<AuctionItem> items = getAuctionBuyList(req, 0);
  76. if(items != null)
  77. {
  78. foreach (AuctionItem item in items)
  79. {
  80. if (!item.item.name.Equals(mySearchText)) // auctionitem item name must match the searchText
  81. continue;
  82.  
  83. if (Convert.ToInt32(item.time) > waitSecondsForAuctionEnd)
  84. {
  85. pip = (int)item.buyBackPrice / item.item.count;
  86.  
  87. if (item.item.count < minamount || item.buyBackPrice == 0 || pip > maxprice)
  88. continue;
  89.  
  90. if (me.goldCount >= item.buyBackPrice)
  91. {
  92. Thread.Sleep(100 + r.Next(150));
  93. bidreturn = item.MakeAuctionBid(item.buyBackPrice);
  94. Thread.Sleep(1000 + r.Next(500));
  95. if (bidreturn)
  96. Log(DateTime.Now.ToShortTimeString() + " > Attempting to BUYOUT " + item.item.count + " " + item.item.name + " with per item price " + pip.ToString() + " ... succeeded !");
  97. else
  98. Log(DateTime.Now.ToShortTimeString() + " > Attempting to BUYOUT " + item.item.count + " " + item.item.name + " with per item price " + pip.ToString() + " ... failed.");
  99. }
  100. else
  101. Log(DateTime.Now.ToShortTimeString() + " > not enough gold to buyout " + item.item.count + " " + item.item.name + " for " + item.buyBackPrice);
  102. }
  103. else // auction items time is nearly over, check if we want to bid on it
  104. {
  105. pip = (item.bidMoney != 0 ? item.bidMoney : item.sellPrice) / item.item.count;
  106. if (pip + overbidamount <= maxprice && item.item.count >= minamount) // check if this is an item below maxprice
  107. {
  108. bidOnAuctionHouse(req, item.uniqId, maxprice);
  109. break;
  110. }
  111. }
  112. }
  113. }
  114. else
  115. {
  116. Log(DateTime.Now.ToShortTimeString() + " > " +GetLastError().ToString() +" Error ... will try again");
  117. }
  118. Thread.Sleep(2000 + r.Next(3000)); // Random sleep 2-5s
  119. }
  120. public void bidOnAuctionHouse(AuctionRequestParams req, ulong itemId, int maxprice)
  121. {
  122. int pip; // per item price
  123. int myBidAmount;
  124. int sleepTime;
  125. bool bidreturn;
  126.  
  127. List<AuctionItem> items = getAuctionBuyList(req, 9);
  128. foreach (AuctionItem item in items)
  129. {
  130. if (item.uniqId == itemId)
  131. {
  132. pip = (item.bidMoney != 0 ? item.bidMoney : item.sellPrice) / item.item.count;
  133. if (pip + overbidamount <= maxprice)
  134. {
  135. sleepTime = Convert.ToInt32(item.time) * 1000 - Convert.ToInt32(r.Next(500)) - msToBidBeforeAuctionEnd;
  136. 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 +")");
  137. if (sleepTime > 100)
  138. Thread.Sleep(sleepTime);
  139. break;
  140. }
  141. else
  142. return; // the item has become too expensive
  143. }
  144. }
  145.  
  146. items = getAuctionBuyList(req, 9);
  147. foreach (AuctionItem item in items)
  148. {
  149. if (item.uniqId == itemId)
  150. {
  151. pip = (item.bidMoney != 0 ? item.bidMoney : item.sellPrice) / item.item.count;
  152. if (pip + overbidamount <= maxprice)
  153. {
  154. myBidAmount = (item.bidMoney != 0 ? item.bidMoney : item.sellPrice) + overbidamount;
  155. if (me.goldCount >= myBidAmount)
  156. {
  157. bidreturn = item.MakeAuctionBid(myBidAmount);
  158. Thread.Sleep(1000 + r.Next(500));
  159. if (bidreturn)
  160. Log(DateTime.Now.ToShortTimeString() + " > Successfully sent a BID on " + item.item.count + " " + item.item.name + " with " + myBidAmount + " (pip: " + (myBidAmount/item.item.count) + ")");
  161. else
  162. Log(DateTime.Now.ToShortTimeString() + " > Failed to send a BID on " + item.item.count + " " + item.item.name + " with " + myBidAmount + " (pip: " +(myBidAmount/item.item.count) +")");
  163. }
  164. else
  165. Log(DateTime.Now.ToShortTimeString() + " > not enough gold to bid on " + item.item.count + " " + item.item.name + " with " + myBidAmount);
  166. }
  167. else
  168. return; // the item has become too expensive
  169. }
  170. }
  171. }
  172. }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement