Advertisement
Guest User

Untitled

a guest
Feb 6th, 2017
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.94 KB | None | 0 0
  1. package com.dreamscape.server.net.mysql.store;
  2.  
  3. import com.dreamscape.server.game.content.CollectedGameItem;
  4. import com.dreamscape.server.game.content.CollectionBox;
  5. import com.dreamscape.server.game.content.DonationDataHolder;
  6. import com.dreamscape.server.game.content.ItemSet;
  7. import com.dreamscape.server.game.content.StoreItems;
  8. import com.dreamscape.server.game.minigames.duelarena.Types;
  9. import com.dreamscape.server.game.players.Client;
  10. import com.mysql.jdbc.Statement;
  11.  
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14.  
  15. import java.sql.Connection;
  16. import java.sql.DriverManager;
  17. import java.sql.ResultSet;
  18. import java.sql.SQLException;
  19. import java.util.HashMap;
  20. import java.util.Iterator;
  21. import java.util.Map;
  22.  
  23. public class Donation {
  24.  
  25. private static final Logger logger = LoggerFactory.getLogger(Donation.class);
  26. public static final int EMPEROR_BOX_ID = 20484;
  27. public static final int[] BOXES = {6200, 6202, 6204, 6855, 3230};
  28.  
  29. public static Map<Integer, StoreItems> map = new HashMap<Integer, StoreItems>();
  30.  
  31. public static void loadStore() {
  32. map.put(11, StoreItems.REGULAR_DONATOR);
  33. map.put(13, StoreItems.SUPER_DONATOR);
  34. map.put(14, StoreItems.ICE_KATANA);
  35. map.put(15, StoreItems.BRUTAL_WHIP);
  36. map.put(16, StoreItems.SWORD_OF_1000_TRUTHS);
  37. map.put(18, StoreItems.TENTACLE_WHIP);
  38. map.put(19, StoreItems.TORMENTED_JR);
  39. map.put(20, StoreItems.ASSAULT_RIFLE);
  40. map.put(21, StoreItems.GLOCK);
  41. map.put(22, StoreItems.CALLISTO_JR);
  42. map.put(23, StoreItems.SCORPIA_JR);
  43. //map.put(24, StoreItems.OFFHAND_ICE);
  44. map.put(25, StoreItems.PIKACHU_JR);
  45. map.put(26, StoreItems.VENENATIS_JR);
  46. map.put(27, StoreItems.BLACK_MASK);
  47. map.put(28, StoreItems.VETION_JR);
  48. map.put(29, StoreItems.THUGBOB_JR);
  49. map.put(30, StoreItems.GOLD_MASK);
  50. map.put(31, StoreItems.PARTY_PIE);
  51. map.put(32, StoreItems.BANDOS_PET);
  52. map.put(33, StoreItems.HOT_HWEEN_MASK);
  53. map.put(34, StoreItems.CAMEL_PET);
  54. map.put(35, StoreItems.LAVA_SANTA_HAT);
  55. map.put(36, StoreItems.PET_MYSTERY_BOX);
  56. map.put(37, StoreItems.ICY_GLAIVE);
  57. map.put(38, StoreItems.LIME_SANTA_HAT);
  58. map.put(39, StoreItems.PURPLE_SANTA);
  59. map.put(40, StoreItems.RAINBOW_SANTA_HAT);
  60. map.put(41, StoreItems.OWNERS_CAPE);
  61. map.put(42, StoreItems.BLACK_SANTA_HAT);
  62. map.put(43, StoreItems.DREAM_BOX);
  63. map.put(44, StoreItems.DYNAMIC_MYSTERY_BOX);
  64. map.put(45, StoreItems.ICY_BRUTAL_WINGS);
  65. map.put(46, StoreItems.RAINBOW_WINGS);
  66. map.put(47, StoreItems.PET_MYSTERY_BOX);
  67. map.put(48, StoreItems.SUPER_MYSTERY_BOX);
  68. map.put(49, StoreItems.FLAME_TORVA_SET);
  69. map.put(50, StoreItems.DOUBLE_XP_RING);
  70. map.put(51, StoreItems.DEMONIC_BLUE_TORVA_SET);
  71. map.put(52, StoreItems.FULL_RAINBOW_ARMOUR);
  72. map.put(54, StoreItems.AMERICAN_TORVA);
  73. map.put(55, StoreItems.FALLEN_DEATH_CAPE);
  74. map.put(56, StoreItems.MORPHING_RING);
  75. map.put(57, StoreItems.BLUE_DEATH_CAPE);
  76. map.put(58, StoreItems.AMERICAN_PERNIX);
  77. map.put(59, StoreItems.EXTREME_DONATOR_TICKET);
  78. map.put(60, StoreItems.DREAM_WING_BOOTS);
  79. map.put(61, StoreItems.GOLDEN_AK_47);
  80. map.put(62, StoreItems.RING_OF_WEILTH_I);
  81. //map.put(63, StoreItems.ARMADYL_CROSSBOW);
  82. map.put(64, StoreItems.TORVA_SET);
  83. map.put(65, StoreItems.BLOOD_SPIRIT_SHIELD);
  84. map.put(66, StoreItems.SHADOW_KING_EGGS_100);
  85. map.put(67, StoreItems.SLED);
  86. map.put(68, StoreItems.SHADOW_KING_EGGS_500);
  87. map.put(72, StoreItems.SHADOW_KING_EGGS_1000);
  88. map.put(73, StoreItems.GOLD_CHAIN);
  89. map.put(74, StoreItems.B500_CASH);
  90. map.put(75, StoreItems.T1_CASH);
  91. map.put(76, StoreItems.AK_47);
  92. map.put(77, StoreItems.DREAM_TORVA_SET);
  93. map.put(78, StoreItems.MINIGUN);
  94. map.put(79, StoreItems.NOCTURNAL_CHAIN);
  95. map.put(80, StoreItems.PUMPKIN_PET);
  96. map.put(81, StoreItems.SILVER_CHAIN);
  97. map.put(82, StoreItems.BLUE_BOXING_GLOVES);
  98. map.put(83, StoreItems.BASS_GUITAR);
  99. map.put(84, StoreItems.SOUL_FLARE);
  100. map.put(85, StoreItems.CORPOREAL_PET);
  101. map.put(86, StoreItems.MEGA_CRATE);
  102. map.put(87, StoreItems.INVICTUS_BOX);
  103. map.put(88, StoreItems.AMERICAN_BOXING_GLOVES);
  104.  
  105. try {
  106. Class.forName("com.mysql.jdbc.Driver");
  107. } catch (ClassNotFoundException e) {
  108. System.out.println("Where is your MySQL JDBC Driver?");
  109. e.printStackTrace();
  110. return;
  111. }
  112. Connection connection = null;
  113. Statement statement = null;
  114.  
  115. try {
  116. connection = DriverManager.getConnection(
  117. "jdbc:mysql://149.56.129.176:3306/dsrpay",
  118. "standev", "h7a6leijHjB4U1su");
  119. if (connection != null) {
  120. statement = (Statement) connection.createStatement();
  121. Iterator<Integer> iterator = map.keySet().iterator();
  122. while (iterator.hasNext()) {
  123. int id = iterator.next();
  124. String sql = "SELECT productPrice FROM products WHERE id='" + id
  125. + "' AND storeId='54'";
  126. try {
  127. ResultSet rs = null;
  128.  
  129. rs = ((Statement) connection.createStatement()).executeQuery(sql);
  130. while (rs.next())
  131. map.get(id).setPrice(rs.getInt("productPrice"));
  132. rs.close();
  133. } catch (Exception e) {
  134. // TODO Auto-generated catch block
  135. e.printStackTrace();
  136. }
  137. }
  138. } else {
  139. System.out.println("Failed to make connection!");
  140. }
  141. } catch (SQLException e) {
  142. System.out.println("Connection Failed! Check output console");
  143. e.printStackTrace();
  144. return;
  145. }
  146. try {
  147. connection.close();
  148. } catch (SQLException e) {
  149. // TODO Auto-generated catch block
  150. e.printStackTrace();
  151. }
  152. logger.info("Successfully loaded MySQL.");
  153. }
  154.  
  155. private static int addPointsForAmount(int price) {
  156. return (int) (price / 5);
  157. }
  158.  
  159. public static void main(String[] args) throws SQLException {
  160. System.out.println(addPointsForAmount(6));
  161. }
  162.  
  163.  
  164. public static int priceFor(int id) throws SQLException {
  165. try {
  166. Class.forName("com.mysql.jdbc.Driver");
  167. } catch (ClassNotFoundException e) {
  168. System.out.println("Where is your MySQL JDBC Driver?");
  169. e.printStackTrace();
  170. return 0;
  171. }
  172. Connection connection = null;
  173. Statement stmt = null;
  174. try {
  175. connection = DriverManager.getConnection("jdbc:mysql://149.56.129.176:3306/dsrpay",
  176. "standev", "h7a6leijHjB4U1su");
  177. } catch (SQLException e) {
  178. System.out.println("Connection Failed! Check output console");
  179. e.printStackTrace();
  180. return 0;
  181. }
  182. if (connection != null) {
  183. stmt = (Statement) connection.createStatement();
  184. String sql;
  185. sql = "SELECT productPrice FROM products WHERE id='" + id
  186. + "' AND storeId='54'";
  187. ResultSet rs = stmt.executeQuery(sql);
  188. while (rs.next())
  189. return rs.getInt("productPrice");
  190. rs.close();
  191. stmt.close();
  192. connection.close();
  193. } else {
  194. System.out.println("Failed to make connection!");
  195. }
  196. return 0;
  197. }
  198.  
  199. public static boolean checkDonation(String username, Client c) throws SQLException {
  200. long start = System.currentTimeMillis();
  201. try {
  202. Class.forName("com.mysql.jdbc.Driver");
  203. } catch (ClassNotFoundException e) {
  204. System.out.println("Where is your MySQL JDBC Driver?");
  205. e.printStackTrace();
  206. return false;
  207. }
  208. Connection connection = null;
  209. Statement stmt = null;
  210.  
  211. try {
  212. connection = DriverManager.getConnection("jdbc:mysql://149.56.129.176:3306/dsrpay",
  213. "standev", "h7a6leijHjB4U1su");
  214.  
  215.  
  216. } catch (SQLException e) {
  217. System.out.println("Connection Failed! Check output console");
  218. e.printStackTrace();
  219. return false;
  220. }
  221.  
  222. if (connection != null) {
  223. stmt = (Statement) connection.createStatement();
  224. String sql;
  225. sql = "SELECT productId, quantity FROM checkout WHERE playerName='" + username
  226. + "' AND canClaim='1' AND storeId='54'";
  227.  
  228.  
  229. ResultSet rs = stmt.executeQuery(sql);
  230. ItemSet rewards = new ItemSet();
  231. while (rs.next()) {
  232. int id = rs.getInt("productId");
  233. int quantity = rs.getInt("quantity");
  234. int price = 0;
  235. if (map.containsKey(id)) {
  236. StoreItems reward = map.get(id);
  237. String rewardName = reward.getName();
  238. price = (int) reward.getPrice();
  239. price *= quantity;
  240.  
  241. c.getPA().writeDonationLogs(rewardName);
  242. System.out.println(reward.name() + " " + reward.getItemId() + " " + reward.getAmount() + " " + quantity);
  243. int count = 0;
  244. if (reward.getItemIds() == null) {
  245. count = reward.getAmount() * quantity;
  246. rewards.add(new CollectedGameItem(reward.getItemId(), (reward.getAmount() * quantity), Types.DONATION_ITEM));
  247. } else {
  248. for (int index = 0; index < reward.getItemIds().length; index++) {
  249. for (int ia : BOXES) {
  250. if (reward.getItemIds()[index] == ia) {
  251. count++;
  252. }
  253. }
  254. rewards.add(new CollectedGameItem(reward.getItemIds()[index], (reward.getAmounts()[index] * quantity), Types.DONATION_ITEM)); // was
  255. }
  256. }
  257. int gave = 0;
  258. if (count >= 3)
  259. gave = count / 3;
  260. if (gave <= 0 && count >= 3) {
  261. while (count > 0) {
  262. if (count < 3) {
  263. break;
  264. }
  265. if (count > 3) {
  266. count -= 3;
  267. gave++;
  268. }
  269. }
  270. }
  271. System.out.println(gave + " ----- "+ count);
  272. if (gave > 0) {
  273. rewards.add(new CollectedGameItem(EMPEROR_BOX_ID, gave, Types.DONATION_ITEM));
  274. c.sendMessage("As a bonus for donating for boxes, you've received x"+gave+" Emperor box(es).");
  275. }
  276. c.forcedText = "I just donated for " + rewardName;
  277.  
  278. c.sendMessage("You have successfully donated and recieved " + quantity + "x " + rewardName);
  279. c.getPA().handleDonation(rewardName, quantity);
  280. int points = addPointsForAmount(price);
  281. if (points > 0) {
  282. c.sendMessage("<col=255>You have been rewarded with <col=800000000>" + points
  283. + "<col=255> Donation Points for this donation!");
  284. c.donationPoints += points;
  285. }
  286.  
  287. DonationDataHolder.storeDonatedAmountFor(c, reward.getPrice());
  288. }
  289. }
  290.  
  291. sql = "UPDATE checkout SET canClaim = '2' WHERE playerName='" + username
  292. + "' AND canClaim='1' AND storeId='54'";
  293. stmt.execute(sql);
  294. rs.close();
  295. stmt.close();
  296. connection.close();
  297. if (rewards.isEmpty()) {
  298. return false;
  299. } else {
  300. CollectionBox.save(username, rewards);
  301. if (CollectionBox.hasItems(username)) {
  302. c.sendMessage("@cya@You have items waiting in your collection box.");
  303. }
  304. return true;
  305. }
  306. } else {
  307. System.out.println("Failed to make connection!");
  308. }
  309. long end = System.currentTimeMillis();
  310. System.out.println("TOOK " + (end - start));
  311. return false;
  312. }
  313.  
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement