Advertisement
Guest User

Untitled

a guest
Aug 5th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.04 KB | None | 0 0
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package Extensions.Balancer;
  16.  
  17. import java.sql.Connection;
  18. import java.sql.PreparedStatement;
  19. import java.sql.ResultSet;
  20.  
  21. import net.sf.l2j.L2DatabaseFactory;
  22. import net.sf.l2j.gameserver.model.L2World;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  24. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  25. import net.sf.l2j.gameserver.network.serverpackets.UserInfo;
  26.  
  27. public class BalancerEdit
  28. {
  29. public static void editStat(String stat, int classId, int value, boolean add)
  30. {
  31. switch (stat)
  32. {
  33. case "patk":
  34. {
  35. Connection con = null;
  36. try
  37. {
  38. con = L2DatabaseFactory.getInstance().getConnection();
  39. PreparedStatement stm = con.prepareStatement("UPDATE balance SET patk=? WHERE class_id=?");
  40. PreparedStatement stm2 = con.prepareStatement("SELECT patk FROM balance WHERE class_id=" + classId);
  41. ResultSet rset = stm2.executeQuery();
  42.  
  43. if (rset.next())
  44. {
  45. if (add)
  46. {
  47. stm.setInt(1, rset.getInt("patk") + value);
  48. BalanceLoad.PAtk[classId - 88] = BalanceLoad.PAtk[classId - 88] + value;
  49. }
  50. else
  51. {
  52. stm.setInt(1, rset.getInt("patk") - value);
  53. BalanceLoad.PAtk[classId - 88] = BalanceLoad.PAtk[classId - 88] - value;
  54. }
  55. stm.setInt(2, classId);
  56. }
  57.  
  58. stm.execute();
  59. stm.close();
  60. stm2.close();
  61. }
  62. catch (Exception e)
  63. {
  64. System.err.println("Error while saving balance stats to database.");
  65. e.printStackTrace();
  66. }
  67. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  68. {
  69. if (p.getClassId().getId() == classId)
  70. {
  71. p.sendPacket(new UserInfo(p));
  72. }
  73. }
  74. break;
  75. }
  76. case "matk":
  77. {
  78. Connection con = null;
  79. try
  80. {
  81. con = L2DatabaseFactory.getInstance().getConnection();
  82. PreparedStatement stm = con.prepareStatement("UPDATE balance SET matk=? WHERE class_id=?");
  83. PreparedStatement stm2 = con.prepareStatement("SELECT matk FROM balance WHERE class_id=" + classId);
  84. ResultSet rset = stm2.executeQuery();
  85.  
  86. if (rset.next())
  87. {
  88. if (add)
  89. {
  90. stm.setInt(1, rset.getInt("matk") + value);
  91. BalanceLoad.MAtk[classId - 88] = BalanceLoad.MAtk[classId - 88] + value;
  92. }
  93. else
  94. {
  95. stm.setInt(1, rset.getInt("matk") - value);
  96. BalanceLoad.MAtk[classId - 88] = BalanceLoad.MAtk[classId - 88] - value;
  97. }
  98. stm.setInt(2, classId);
  99. }
  100.  
  101. stm.execute();
  102. stm.close();
  103. stm2.close();
  104. }
  105. catch (Exception e)
  106. {
  107. System.err.println("Error while saving balance stats to database.");
  108. e.printStackTrace();
  109. }
  110. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  111. {
  112. if (p.getClassId().getId() == classId)
  113. {
  114. p.sendPacket(new UserInfo(p));
  115. }
  116. }
  117. break;
  118. }
  119. case "pdef":
  120. {
  121. Connection con = null;
  122. try
  123. {
  124. con = L2DatabaseFactory.getInstance().getConnection();
  125. PreparedStatement stm = con.prepareStatement("UPDATE balance SET pdef=? WHERE class_id=?");
  126. PreparedStatement stm2 = con.prepareStatement("SELECT pdef FROM balance WHERE class_id=" + classId);
  127. ResultSet rset = stm2.executeQuery();
  128.  
  129. if (rset.next())
  130. {
  131. if (add)
  132. {
  133. stm.setInt(1, rset.getInt("pdef") + value);
  134. BalanceLoad.PDef[classId - 88] = BalanceLoad.PDef[classId - 88] + value;
  135. }
  136. else
  137. {
  138. stm.setInt(1, rset.getInt("pdef") - value);
  139. BalanceLoad.PDef[classId - 88] = BalanceLoad.PDef[classId - 88] - value;
  140. }
  141. stm.setInt(2, classId);
  142. }
  143.  
  144. stm.execute();
  145. stm.close();
  146. stm2.close();
  147. }
  148. catch (Exception e)
  149. {
  150. System.err.println("Error while saving balance stats to database.");
  151. e.printStackTrace();
  152. }
  153. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  154. {
  155. if (p.getClassId().getId() == classId)
  156. {
  157. p.sendPacket(new UserInfo(p));
  158. }
  159. }
  160. break;
  161. }
  162. case "mdef":
  163. {
  164. Connection con = null;
  165. try
  166. {
  167. con = L2DatabaseFactory.getInstance().getConnection();
  168. PreparedStatement stm = con.prepareStatement("UPDATE balance SET mdef=? WHERE class_id=?");
  169. PreparedStatement stm2 = con.prepareStatement("SELECT mdef FROM balance WHERE class_id=" + classId);
  170. ResultSet rset = stm2.executeQuery();
  171.  
  172. if (rset.next())
  173. {
  174. if (add)
  175. {
  176. stm.setInt(1, rset.getInt("mdef") + value);
  177. BalanceLoad.MDef[classId - 88] = BalanceLoad.MDef[classId - 88] + value;
  178. }
  179. else
  180. {
  181. stm.setInt(1, rset.getInt("mdef") - value);
  182. BalanceLoad.MDef[classId - 88] = BalanceLoad.MDef[classId - 88] - value;
  183. }
  184. stm.setInt(2, classId);
  185. }
  186.  
  187. stm.execute();
  188. stm.close();
  189. stm2.close();
  190. }
  191. catch (Exception e)
  192. {
  193. System.err.println("Error while saving balance stats to database.");
  194. e.printStackTrace();
  195. }
  196. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  197. {
  198. if (p.getClassId().getId() == classId)
  199. {
  200. p.sendPacket(new UserInfo(p));
  201. }
  202. }
  203. break;
  204. }
  205. case "acc":
  206. {
  207. Connection con = null;
  208. try
  209. {
  210. con = L2DatabaseFactory.getInstance().getConnection();
  211. PreparedStatement stm = con.prepareStatement("UPDATE balance SET acc=? WHERE class_id=?");
  212. PreparedStatement stm2 = con.prepareStatement("SELECT acc FROM balance WHERE class_id=" + classId);
  213. ResultSet rset = stm2.executeQuery();
  214.  
  215. if (rset.next())
  216. {
  217. if (add)
  218. {
  219. stm.setInt(1, rset.getInt("acc") + value);
  220. BalanceLoad.Accuracy[classId - 88] = BalanceLoad.Accuracy[classId - 88] + value;
  221. }
  222. else
  223. {
  224. stm.setInt(1, rset.getInt("acc") - value);
  225. BalanceLoad.Accuracy[classId - 88] = BalanceLoad.Accuracy[classId - 88] - value;
  226. }
  227. stm.setInt(2, classId);
  228. }
  229.  
  230. stm.execute();
  231. stm.close();
  232. stm2.close();
  233. }
  234. catch (Exception e)
  235. {
  236. System.err.println("Error while saving balance stats to database.");
  237. e.printStackTrace();
  238. }
  239. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  240. {
  241. if (p.getClassId().getId() == classId)
  242. {
  243. p.sendPacket(new UserInfo(p));
  244. }
  245. }
  246. break;
  247. }
  248. case "ev":
  249. {
  250. Connection con = null;
  251. try
  252. {
  253. con = L2DatabaseFactory.getInstance().getConnection();
  254. PreparedStatement stm = con.prepareStatement("UPDATE balance SET ev=? WHERE class_id=?");
  255. PreparedStatement stm2 = con.prepareStatement("SELECT ev FROM balance WHERE class_id=" + classId);
  256. ResultSet rset = stm2.executeQuery();
  257.  
  258. if (rset.next())
  259. {
  260. if (add)
  261. {
  262. stm.setInt(1, rset.getInt("ev") + value);
  263. BalanceLoad.Evasion[classId - 88] = BalanceLoad.Evasion[classId - 88] + value;
  264. }
  265. else
  266. {
  267. stm.setInt(1, rset.getInt("ev") - value);
  268. BalanceLoad.Evasion[classId - 88] = BalanceLoad.Evasion[classId - 88] - value;
  269. }
  270. stm.setInt(2, classId);
  271. }
  272.  
  273. stm.execute();
  274. stm.close();
  275. stm2.close();
  276. }
  277. catch (Exception e)
  278. {
  279. System.err.println("Error while saving balance stats to database.");
  280. e.printStackTrace();
  281. }
  282. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  283. {
  284. if (p.getClassId().getId() == classId)
  285. {
  286. p.sendPacket(new UserInfo(p));
  287. }
  288. }
  289. break;
  290. }
  291. case "patksp":
  292. {
  293. Connection con = null;
  294. try
  295. {
  296. con = L2DatabaseFactory.getInstance().getConnection();
  297. PreparedStatement stm = con.prepareStatement("UPDATE balance SET patksp=? WHERE class_id=?");
  298. PreparedStatement stm2 = con.prepareStatement("SELECT patksp FROM balance WHERE class_id=" + classId);
  299. ResultSet rset = stm2.executeQuery();
  300.  
  301. if (rset.next())
  302. {
  303. if (add)
  304. {
  305. stm.setInt(1, rset.getInt("patksp") + value);
  306. BalanceLoad.PAtkSpd[classId - 88] = BalanceLoad.PAtkSpd[classId - 88] + value;
  307. }
  308. else
  309. {
  310. stm.setInt(1, rset.getInt("patksp") - value);
  311. BalanceLoad.PAtkSpd[classId - 88] = BalanceLoad.PAtkSpd[classId - 88] - value;
  312. }
  313. stm.setInt(2, classId);
  314. }
  315.  
  316. stm.execute();
  317. stm.close();
  318. stm2.close();
  319. }
  320. catch (Exception e)
  321. {
  322. System.err.println("Error while saving balance stats to database.");
  323. e.printStackTrace();
  324. }
  325. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  326. {
  327. if (p.getClassId().getId() == classId)
  328. {
  329. p.sendPacket(new UserInfo(p));
  330. }
  331. }
  332. break;
  333. }
  334. case "matksp":
  335. {
  336. Connection con = null;
  337. try
  338. {
  339. con = L2DatabaseFactory.getInstance().getConnection();
  340. PreparedStatement stm = con.prepareStatement("UPDATE balance SET matksp=? WHERE class_id=?");
  341. PreparedStatement stm2 = con.prepareStatement("SELECT matksp FROM balance WHERE class_id=" + classId);
  342. ResultSet rset = stm2.executeQuery();
  343.  
  344. if (rset.next())
  345. {
  346. if (add)
  347. {
  348. stm.setInt(1, rset.getInt("matksp") + value);
  349. BalanceLoad.MAtkSpd[classId - 88] = BalanceLoad.MAtkSpd[classId - 88] + value;
  350. }
  351. else
  352. {
  353. stm.setInt(1, rset.getInt("matksp") - value);
  354. BalanceLoad.MAtkSpd[classId - 88] = BalanceLoad.MAtkSpd[classId - 88] - value;
  355. }
  356. stm.setInt(2, classId);
  357. }
  358.  
  359. stm.execute();
  360. stm.close();
  361. stm2.close();
  362. }
  363. catch (Exception e)
  364. {
  365. System.err.println("Error while saving balance stats to database.");
  366. e.printStackTrace();
  367. }
  368. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  369. {
  370. if (p.getClassId().getId() == classId)
  371. {
  372. p.sendPacket(new UserInfo(p));
  373. }
  374. }
  375. break;
  376. }
  377. case "cp":
  378. {
  379. Connection con = null;
  380. try
  381. {
  382. con = L2DatabaseFactory.getInstance().getConnection();
  383. PreparedStatement stm = con.prepareStatement("UPDATE balance SET cp=? WHERE class_id=?");
  384. PreparedStatement stm2 = con.prepareStatement("SELECT cp FROM balance WHERE class_id=" + classId);
  385. ResultSet rset = stm2.executeQuery();
  386.  
  387. if (rset.next())
  388. {
  389. if (add)
  390. {
  391. stm.setInt(1, rset.getInt("cp") + value);
  392. BalanceLoad.CP[classId - 88] = BalanceLoad.CP[classId - 88] + value;
  393. }
  394. else
  395. {
  396. stm.setInt(1, rset.getInt("cp") - value);
  397. BalanceLoad.CP[classId - 88] = BalanceLoad.CP[classId - 88] - value;
  398. }
  399. stm.setInt(2, classId);
  400. }
  401.  
  402. stm.execute();
  403. stm.close();
  404. stm2.close();
  405. }
  406. catch (Exception e)
  407. {
  408. System.err.println("Error while saving balance stats to database.");
  409. e.printStackTrace();
  410. }
  411. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  412. {
  413. if (p.getClassId().getId() == classId)
  414. {
  415. p.sendPacket(new UserInfo(p));
  416. }
  417. }
  418. break;
  419. }
  420. case "hp":
  421. {
  422. Connection con = null;
  423. try
  424. {
  425. con = L2DatabaseFactory.getInstance().getConnection();
  426. PreparedStatement stm = con.prepareStatement("UPDATE balance SET hp=? WHERE class_id=?");
  427. PreparedStatement stm2 = con.prepareStatement("SELECT hp FROM balance WHERE class_id=" + classId);
  428. ResultSet rset = stm2.executeQuery();
  429.  
  430. if (rset.next())
  431. {
  432. if (add)
  433. {
  434. stm.setInt(1, rset.getInt("hp") + value);
  435. BalanceLoad.HP[classId - 88] = BalanceLoad.HP[classId - 88] + value;
  436. }
  437. else
  438. {
  439. stm.setInt(1, rset.getInt("hp") - value);
  440. BalanceLoad.HP[classId - 88] = BalanceLoad.HP[classId - 88] - value;
  441. }
  442. stm.setInt(2, classId);
  443. }
  444.  
  445. stm.execute();
  446. stm.close();
  447. stm2.close();
  448. }
  449. catch (Exception e)
  450. {
  451. System.err.println("Error while saving balance stats to database.");
  452. e.printStackTrace();
  453. }
  454. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  455. {
  456. if (p.getClassId().getId() == classId)
  457. {
  458. p.sendPacket(new UserInfo(p));
  459. }
  460. }
  461. break;
  462. }
  463. case "mp":
  464. {
  465. Connection con = null;
  466. try
  467. {
  468. con = L2DatabaseFactory.getInstance().getConnection();
  469. PreparedStatement stm = con.prepareStatement("UPDATE balance SET mp=? WHERE class_id=?");
  470. PreparedStatement stm2 = con.prepareStatement("SELECT mp FROM balance WHERE class_id=" + classId);
  471. ResultSet rset = stm2.executeQuery();
  472.  
  473. if (rset.next())
  474. {
  475. if (add)
  476. {
  477. stm.setInt(1, rset.getInt("mp") + value);
  478. BalanceLoad.MP[classId - 88] = BalanceLoad.MP[classId - 88] + value;
  479. }
  480. else
  481. {
  482. stm.setInt(1, rset.getInt("mp") - value);
  483. BalanceLoad.MP[classId - 88] = BalanceLoad.MP[classId - 88] - value;
  484. }
  485. stm.setInt(2, classId);
  486. }
  487.  
  488. stm.execute();
  489. stm.close();
  490. stm2.close();
  491. }
  492. catch (Exception e)
  493. {
  494. System.err.println("Error while saving balance stats to database.");
  495. e.printStackTrace();
  496. }
  497. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  498. {
  499. if (p.getClassId().getId() == classId)
  500. {
  501. p.sendPacket(new UserInfo(p));
  502. }
  503. }
  504. break;
  505. }
  506. case "walk":
  507. {
  508. Connection con = null;
  509. try
  510. {
  511. con = L2DatabaseFactory.getInstance().getConnection();
  512. PreparedStatement stm = con.prepareStatement("UPDATE balance SET walk=? WHERE class_id=?");
  513. PreparedStatement stm2 = con.prepareStatement("SELECT walk FROM balance WHERE class_id=" + classId);
  514. ResultSet rset = stm2.executeQuery();
  515.  
  516. if (rset.next())
  517. {
  518. if (add)
  519. {
  520. stm.setInt(1, rset.getInt("walk") + value);
  521. BalanceLoad.Speed[classId - 88] = BalanceLoad.Speed[classId - 88] + value;
  522. }
  523. else
  524. {
  525. stm.setInt(1, rset.getInt("walk") - value);
  526. BalanceLoad.Speed[classId - 88] = BalanceLoad.Speed[classId - 88] - value;
  527. }
  528. stm.setInt(2, classId);
  529. }
  530.  
  531. stm.execute();
  532. stm.close();
  533. stm2.close();
  534. }
  535. catch (Exception e)
  536. {
  537. System.err.println("Error while saving balance stats to database.");
  538. e.printStackTrace();
  539. }
  540. for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  541. {
  542. if (p.getClassId().getId() == classId)
  543. {
  544. p.sendPacket(new UserInfo(p));
  545. }
  546. }
  547. break;
  548. }
  549. }
  550. }
  551.  
  552. public void sendBalanceWindow(int classId, L2PcInstance p)
  553. {
  554. NpcHtmlMessage htm = new NpcHtmlMessage(0);
  555. htm.setFile("./data/html/admin/balance/balance.htm");
  556. htm.replace("%classId%", classId + "");
  557.  
  558. p.sendPacket(htm);
  559. }
  560. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement