Seuss_CZ

Untitled

Jan 1st, 2017
54
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 "aukce";
  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>() { "aukce" };
  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 ("pridat"):
  71. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_addcommand_usage"));
  72. return;
  73. case ("seznam"):
  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 ("koupit"):
  97. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_buycommand_usage"));
  98. return;
  99. case ("storno"):
  100. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_cancelcommand_usage"));
  101. return;
  102. case ("hledatt"):
  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 ("pridat"):
  113. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_addcommand_usage2"));
  114. return;
  115. case ("koupit"):
  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 ("storno"):
  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 ("hledatt"):
  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 ("pridat"):
  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. int Ammo = list[0].jar.item.state[10];
  330. var magazineId = (ushort)(list[0].jar.item.state[8] | list[0].jar.item.state[9] << 8);
  331. var maga = Assets.find(EAssetType.ITEM, magazineId) as ItemMagazineAsset;
  332. int MaxAmmo = maga?.amount ?? 0;
  333. if (Ammo < MaxAmmo)
  334. {
  335. UnturnedChat.Say(player, "You cannot auction a gun that is not fully loaded!");
  336. return;
  337. }
  338. decimal price = 0.00m;
  339. if (LIGHT.Instance.Configuration.Instance.EnableShop)
  340. {
  341. price = LIGHT.Instance.ShopDB.GetItemCost(id);
  342. if (price <= 0.00m)
  343. {
  344. price = 0.00m;
  345. }
  346. }
  347. byte quality = 100;
  348. switch (vAsset.amount)
  349. {
  350. case 1:
  351. // These are single items, not ammo or magazines
  352. while (amt > 0)
  353. {
  354. try
  355. {
  356. if (player.Player.equipment.checkSelection(list[0].page, list[0].jar.x, list[0].jar.y))
  357. {
  358. player.Player.equipment.dequip();
  359. }
  360. }
  361. catch
  362. {
  363. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_unequip_item", name));
  364. return;
  365. }
  366. quality = list[0].jar.item.durability;
  367. if (LIGHT.Instance.DatabaseAuction.CurrentListings(player.CSteamID.ToString()) > 2)
  368. {
  369. UnturnedChat.Say(player, "Do aukce můžeš vložit max 3 itemy!");
  370. return;
  371. }
  372. player.Inventory.removeItem(list[0].page, player.Inventory.getIndex(list[0].page, list[0].jar.x, list[0].jar.y));
  373. list.RemoveAt(0);
  374. amt--;
  375. }
  376. break;
  377. default:
  378. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_item_mag_ammo", name));
  379. return;
  380. }
  381. decimal SetPrice;
  382. if (!decimal.TryParse(command[command.Length - 1], out SetPrice))
  383. SetPrice = price;
  384. if (LIGHT.Instance.DatabaseAuction.CurrentListings(player.CSteamID.ToString()) > 2) { UnturnedChat.Say(player, "Do aukce můžeš vložit max 3 itemy!"); return; }
  385. if (LIGHT.Instance.DatabaseAuction.AddAuctionItem(LIGHT.Instance.DatabaseAuction.GetLastAuctionNo(), id.ToString(), name, SetPrice, price, (int)quality, player.Id))
  386. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_item_succes", name, SetPrice, Uconomy.Instance.Configuration.Instance.MoneyName));
  387. else
  388. UnturnedChat.Say(player, LIGHT.Instance.Translate("auction_item_failed"));
  389. break;
  390. }
  391.  
  392. }
  393. }
  394.  
  395. }
  396.  
  397. }
RAW Paste Data