Seuss_CZ

Untitled

Dec 26th, 2016
206
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Rocket.API;
  2. using Rocket.Core.Logging;
  3. using Rocket.Unturned.Chat;
  4. using Rocket.Unturned.Player;
  5. using SDG.Unturned;
  6. using System.Collections.Generic;
  7. using fr34kyn01535.Uconomy;
  8. using Steamworks;
  9.  
  10. namespace LIGHT
  11. {
  12. public class CommandAuction : IRocketCommand
  13. {
  14. public string Name
  15. {
  16. get
  17. {
  18. return "auction";
  19. }
  20. }
  21. public AllowedCaller AllowedCaller
  22. {
  23. get
  24. {
  25. return AllowedCaller.Player;
  26. }
  27. }
  28. public string Help
  29. {
  30. get
  31. {
  32. return "Allows you to auction your items from your inventory.";
  33. }
  34. }
  35. public string Syntax
  36. {
  37. get
  38. {
  39. return "<name or id>";
  40. }
  41. }
  42. public List<string> Aliases
  43. {
  44. get { return new List<string>(); }
  45. }
  46. public List<string> Permissions
  47. {
  48. get
  49. {
  50. return new List<string>() { "auction" };
  51. }
  52. }
  53. public void Execute(IRocketPlayer caller, params string[] command)
  54. {
  55. if (!LIGHT.Instance.Configuration.Instance.AllowAuction)
  56. {
  57. UnturnedChat.Say(caller, LIGHT.Instance.Translate("auction_disabled"));
  58. return;
  59. }
  60. UnturnedPlayer player = (UnturnedPlayer)caller;
  61. if (command.Length == 0)
  62. {
  63. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_command_usage"));
  64. return;
  65. }
  66. if (command.Length == 1)
  67. {
  68. switch (command[0])
  69. {
  70. case ("add"):
  71. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_addcommand_usage"));
  72. return;
  73. case ("list"):
  74. string Message = "";
  75. string[] ItemNameAndQuality = LIGHT.Instance.DatabaseAuction.GetAllItemNameWithQuality();
  76. string[] AuctionID = LIGHT.Instance.DatabaseAuction.GetAllAuctionID();
  77. string[] ItemPrice = LIGHT.Instance.DatabaseAuction.GetAllItemPrice();
  78. int count = 0;
  79. for (int x = 0; x < ItemNameAndQuality.Length; x++)
  80. {
  81. if (x < ItemNameAndQuality.Length - 1)
  82. Message += "[" + AuctionID[x] + "]: " + ItemNameAndQuality[x] + " for " + ItemPrice[x] + Uconomy.Instance.Configuration.Instance.MoneyName + ", ";
  83. else
  84. Message += "[" + AuctionID[x] + "]: " + ItemNameAndQuality[x] + " for " + ItemPrice[x] + Uconomy.Instance.Configuration.Instance.MoneyName;
  85. count++;
  86. if (count == 2)
  87. {
  88. UnturnedChat.Say(player, Message);
  89. Message = "";
  90. count = 0;
  91. }
  92. }
  93. if (Message != "")
  94. UnturnedChat.Say(player, Message);
  95. break;
  96. case ("buy"):
  97. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_buycommand_usage"));
  98. return;
  99. case ("cancel"):
  100. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_cancelcommand_usage"));
  101. return;
  102. case ("find"):
  103. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_findcommand_usage"));
  104. return;
  105. }
  106. }
  107. if (command.Length == 2)
  108. {
  109. int auctionid = 0;
  110. switch (command[0])
  111. {
  112. case ("add"):
  113. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_addcommand_usage2"));
  114. return;
  115. case ("buy"):
  116. if (int.TryParse(command[1], out auctionid))
  117. {
  118. try
  119. {
  120. string[] itemInfo = LIGHT.Instance.DatabaseAuction.AuctionBuy(auctionid);
  121. decimal balance = Uconomy.Instance.Database.GetBalance(player.Id);
  122. decimal cost = 1.00m;
  123. decimal.TryParse(itemInfo[2], out cost);
  124. if (balance < cost)
  125. {
  126. UnturnedChat.Say(player, LIGHT.Instance.DefaultTranslations.Translate("not_enough_currency_msg", Uconomy.Instance.Configuration.Instance.MoneyName, itemInfo[1]));
  127. return;
  128. }
  129. player.GiveItem(ushort.Parse(itemInfo[0]), 1);
  130. InventorySearch inventory = player.Inventory.has(ushort.Parse(itemInfo[0]));
  131. byte index = player.Inventory.getIndex(inventory.page, inventory.jar.x, inventory.jar.y);
  132. player.Inventory.updateQuality(inventory.page, index, byte.Parse(itemInfo[3]));
  133. LIGHT.Instance.DatabaseAuction.DeleteAuction(command[1]);
  134. decimal newbal = Uconomy.Instance.Database.IncreaseBalance(player.CSteamID.ToString(), (cost * -1));
  135. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_buy_msg", itemInfo[1], cost, Uconomy.Instance.Configuration.Instance.MoneyName, newbal, Uconomy.Instance.Configuration.Instance.MoneyName));
  136. decimal sellernewbalance = Uconomy.Instance.Database.IncreaseBalance(itemInfo[4], (cost * 1));
  137. }
  138. catch
  139. {
  140. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_addcommand_idnotexist"));
  141. return;
  142. }
  143.  
  144. }
  145. else
  146. {
  147. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_addcommand_usage2"));
  148. return;
  149. }
  150. break;
  151. case ("cancel"):
  152. if (int.TryParse(command[1], out auctionid))
  153. {
  154. if (LIGHT.Instance.DatabaseAuction.checkAuctionExist(auctionid))
  155. {
  156. string OwnerID = LIGHT.Instance.DatabaseAuction.GetOwner(auctionid);
  157. if (OwnerID.Trim() == player.Id.Trim())
  158. {
  159. string[] itemInfo = LIGHT.Instance.DatabaseAuction.AuctionCancel(auctionid);
  160. player.GiveItem(ushort.Parse(itemInfo[0]), 1);
  161. InventorySearch inventory = player.Inventory.has(ushort.Parse(itemInfo[0]));
  162. byte index = player.Inventory.getIndex(inventory.page, inventory.jar.x, inventory.jar.y);
  163. player.Inventory.updateQuality(inventory.page, index, byte.Parse(itemInfo[1]));
  164. LIGHT.Instance.DatabaseAuction.DeleteAuction(auctionid.ToString());
  165. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_cancelled", auctionid));
  166. }
  167. else
  168. {
  169. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_notown"));
  170. return;
  171. }
  172. }
  173. else
  174. {
  175. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_notexist"));
  176. return;
  177. }
  178. }
  179. else
  180. {
  181. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_notexist"));
  182. return;
  183. }
  184. break;
  185. case ("find"):
  186. uint ItemID;
  187. if (uint.TryParse(command[1], out ItemID))
  188. {
  189. string[] AuctionID = LIGHT.Instance.DatabaseAuction.FindItemByID(ItemID.ToString());
  190. string Message = "";
  191. string[] ItemNameAndQuality = LIGHT.Instance.DatabaseAuction.FindAllItemNameWithQualityByID(ItemID.ToString());
  192. string[] ItemPrice = LIGHT.Instance.DatabaseAuction.FindAllItemPriceByID(ItemID.ToString());
  193. int count = 0;
  194. for (int x = 0; x < ItemNameAndQuality.Length; x++)
  195. {
  196. if (x < ItemNameAndQuality.Length - 1)
  197. Message += "[" + AuctionID[x] + "]: " + ItemNameAndQuality[x] + " for " + ItemPrice[x] + Uconomy.Instance.Configuration.Instance.MoneyName + ", ";
  198. else
  199. Message += "[" + AuctionID[x] + "]: " + ItemNameAndQuality[x] + " for " + ItemPrice[x] + Uconomy.Instance.Configuration.Instance.MoneyName;
  200. count++;
  201. if (count == 2)
  202. {
  203. UnturnedChat.Say(player, Message);
  204. Message = "";
  205. count = 0;
  206. }
  207. }
  208. if (Message != "")
  209. UnturnedChat.Say(player, Message);
  210. else
  211. {
  212. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_find_failed"));
  213. return;
  214. }
  215. }
  216. else
  217. {
  218. Asset[] array = Assets.find(EAssetType.ITEM);
  219. Asset[] array2 = array;
  220. ushort id;
  221. string ItemName = "";
  222. for (int i = 0; i < array2.Length; i++)
  223. {
  224. ItemAsset vAsset = (ItemAsset)array2[i];
  225. if (vAsset != null && vAsset.itemName != null && vAsset.itemName.ToLower().Contains(command[1].ToLower()))
  226. {
  227. id = vAsset.id;
  228. ItemName = vAsset.itemName;
  229. break;
  230. }
  231. }
  232. if (ItemName != "")
  233. {
  234. string[] AuctionID = LIGHT.Instance.DatabaseAuction.FindItemByName(ItemName);
  235. string Message = "";
  236. string[] ItemNameAndQuality = LIGHT.Instance.DatabaseAuction.FindAllItemNameWithQualityByItemName(ItemName);
  237. string[] ItemPrice = LIGHT.Instance.DatabaseAuction.FindAllItemPriceByItemName(ItemName);
  238. int count = 0;
  239. for (int x = 0; x < ItemNameAndQuality.Length; x++)
  240. {
  241. if (x < ItemNameAndQuality.Length - 1)
  242. Message += "[" + AuctionID[x] + "]: " + ItemNameAndQuality[x] + " for " + ItemPrice[x] + Uconomy.Instance.Configuration.Instance.MoneyName + ", ";
  243. else
  244. Message += "[" + AuctionID[x] + "]: " + ItemNameAndQuality[x] + " for " + ItemPrice[x] + Uconomy.Instance.Configuration.Instance.MoneyName;
  245. count++;
  246. if (count == 2)
  247. {
  248. UnturnedChat.Say(player, Message);
  249. Message = "";
  250. count = 0;
  251. }
  252. }
  253. if (Message != "")
  254. UnturnedChat.Say(player, Message);
  255. else
  256. {
  257. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_find_failed"));
  258. return;
  259. }
  260. }
  261. else
  262. {
  263. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_find_failed"));
  264. return;
  265. }
  266. }
  267. break;
  268. }
  269. }
  270. if (command.Length > 2)
  271. {
  272. switch (command[0])
  273. {
  274. case ("add"):
  275. byte amt = 1;
  276. ushort id;
  277. string name = null;
  278. ItemAsset vAsset = null;
  279. string itemname = "";
  280. for (int x = 1; x < command.Length - 1; x++)
  281. {
  282. itemname += command[x] + " ";
  283. }
  284. itemname = itemname.Trim();
  285. if (!ushort.TryParse(itemname, out id))
  286. {
  287. Asset[] array = Assets.find(EAssetType.ITEM);
  288. Asset[] array2 = array;
  289. for (int i = 0; i < array2.Length; i++)
  290. {
  291. vAsset = (ItemAsset)array2[i];
  292. if (vAsset != null && vAsset.itemName != null && vAsset.itemName.ToLower().Contains(itemname.ToLower()))
  293. {
  294. id = vAsset.id;
  295. name = vAsset.itemName;
  296. break;
  297. }
  298. }
  299. }
  300. if (name == null && id == 0)
  301. {
  302. UnturnedChat.Say(player, LIGHT.Instance.Translate("could_not_find", itemname));
  303. return;
  304. }
  305. else if (name == null && id != 0)
  306. {
  307. try
  308. {
  309. vAsset = (ItemAsset)Assets.find(EAssetType.ITEM, id);
  310. name = vAsset.itemName;
  311. }
  312. catch
  313. {
  314. UnturnedChat.Say(player, LIGHT.Instance.Translate("item_invalid"));
  315. return;
  316. }
  317. }
  318. if (player.Inventory.has(id) == null)
  319. {
  320. UnturnedChat.Say(player, LIGHT.Instance.Translate("not_have_item_auction", name));
  321. return;
  322. }
  323. List<InventorySearch> list = player.Inventory.search(id, true, true);
  324. if (vAsset.amount > 1)
  325. {
  326. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_item_mag_ammo", name));
  327. return;
  328. }
  329. decimal price = 0.00m;
  330. if (LIGHT.Instance.Configuration.Instance.EnableShop)
  331. {
  332. price = LIGHT.Instance.ShopDB.GetItemCost(id);
  333. if (price <= 0.00m)
  334. {
  335. price = 0.00m;
  336. }
  337. }
  338. byte quality = 100;
  339. switch (vAsset.amount)
  340. {
  341. case 1:
  342. // These are single items, not ammo or magazines
  343. while (amt > 0)
  344. {
  345. try
  346. {
  347. if (player.Player.equipment.checkSelection(list[0].page, list[0].jar.x, list[0].jar.y))
  348. {
  349. player.Player.equipment.dequip();
  350. }
  351. }
  352. catch
  353. {
  354. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_unequip_item", name));
  355. return;
  356. }
  357. quality = list[0].jar.item.durability;
  358. if (LIGHT.Instance.DatabaseAuction.CurrentListings(player.CSteamID.ToString()) > 2)
  359. {
  360. UnturnedChat.Say(player, "max 3 items!");
  361. return;
  362. }
  363. player.Inventory.removeItem(list[0].page, player.Inventory.getIndex(list[0].page, list[0].jar.x, list[0].jar.y));
  364. list.RemoveAt(0);
  365. amt--;
  366. }
  367. break;
  368. default:
  369. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_item_mag_ammo", name));
  370. return;
  371. }
  372. decimal SetPrice;
  373. if (!decimal.TryParse(command[command.Length - 1], out SetPrice))
  374. SetPrice = price;
  375. if (LIGHT.Instance.DatabaseAuction.CurrentListings(player.CSteamID.ToString()) > 2) { UnturnedChat.Say(player, "max 3 items!"); return; }
  376. if (LIGHT.Instance.DatabaseAuction.AddAuctionItem(LIGHT.Instance.DatabaseAuction.GetLastAuctionNo(), id.ToString(), name, SetPrice, price, (int)quality, player.Id))
  377. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_item_succes", name, SetPrice, Uconomy.Instance.Configuration.Instance.MoneyName));
  378. else
  379. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_item_failed"));
  380. break;
  381. }
  382.  
  383. }
  384. }
  385.  
  386. }
  387.  
  388. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×