Advertisement
Guest User

Untitled

a guest
Jul 27th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. package server.partyquest;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import server.maps.MapleMap;
  9. import tools.DatabaseConnection;
  10. import client.MapleCharacter;
  11.  
  12. public class JumpQuest {
  13.  
  14. private List<Integer> maps = new ArrayList<Integer>();
  15. private List<MapleCharacter> chrs = new ArrayList<MapleCharacter>();
  16. private int returnMap;
  17. private int level = 0;
  18. private long timeStarted;
  19.  
  20.  
  21. public JumpQuest(List<MapleCharacter> chrs, List<Integer> maps, int returnMap) {
  22. this.maps = maps;
  23. this.chrs = chrs;
  24. this.returnMap = returnMap;
  25. this.timeStarted = System.currentTimeMillis();
  26. registerAll();
  27. advanceStage();
  28. }
  29.  
  30. public void registerAll() {
  31. for (MapleCharacter chr : chrs) {
  32. chr.setJumpQuest(this);
  33. }
  34. }
  35.  
  36. public int getReturnMap() {
  37. return returnMap;
  38. }
  39.  
  40. public boolean checkFinished() {
  41. return level >= maps.size();
  42. }
  43.  
  44. public void advanceStage() {
  45.  
  46. double timeFinished = (System.currentTimeMillis() - timeStarted)/1000;
  47.  
  48. for (MapleCharacter chr : chrs) {
  49.  
  50. if (level >= maps.size()) {
  51. endPQ();
  52. return;
  53. }
  54.  
  55. if (chr.getJQ() != null) {
  56. if (level == 0) {
  57. chr.yellowMessage("The JQ has just begun!!");
  58. break;
  59. } else {
  60. setScores(chr, chr.getMapId(), timeFinished);
  61. chr.yellowMessage("You completed this JQ in " + timeFinished + " seconds.");
  62. }
  63. }
  64. }
  65. level++;
  66. timeStarted = System.currentTimeMillis();
  67. }
  68.  
  69. public void endPQ() {
  70.  
  71. float timeFinished = (System.currentTimeMillis() - timeStarted)/1000;
  72.  
  73. for (MapleCharacter chr : chrs) {
  74. if (chr.getJQ() != null) {
  75. setScores(chr, chr.getMapId(), timeFinished);
  76. chr.changeMap(returnMap);
  77. chr.setJumpQuest(null);
  78. chr.yellowMessage("You have finished the JQ in " + timeFinished +" seconds! Congratulations!");
  79. }
  80. }
  81. }
  82.  
  83. public int getLevel() {
  84. return level;
  85. }
  86.  
  87. public List<Integer> getMaps() {
  88. return maps;
  89. }
  90.  
  91. public int getCurrentMap() {
  92. return maps.get((level - 1));
  93. }
  94.  
  95. public int getMap(int map) {
  96. return maps.get(map);
  97. }
  98.  
  99. public int getNextMap() {
  100. return maps.get(level);
  101. }
  102.  
  103. public void setScores(MapleCharacter chr, int mapid, double time) {
  104. Connection con1 = DatabaseConnection.getConnection();
  105. try {
  106. PreparedStatement ps;
  107. ps = con1.prepareStatement("SELECT time from jumpquests WHERE name = ? AND mapid = ?");
  108. ps.setString(1, chr.getName());
  109. ps.setInt(2, mapid);
  110. ResultSet rs = ps.executeQuery();
  111. if (rs.next()) {
  112. if (time < rs.getFloat("time")) {
  113. executeScores(chr, mapid, time);
  114. }
  115. } else {
  116. executeScores(chr, mapid, time);
  117. }
  118. rs.close();
  119. ps.close();
  120. } catch (Exception Ex) {
  121. }
  122. }
  123.  
  124. public void executeScores(MapleCharacter chr, int mapid, double time) {
  125. System.out.println("Setting scores for " + chr.getName() + " for map " + mapid + " at time " + time);
  126. Connection con1 = DatabaseConnection.getConnection();
  127. try {
  128. PreparedStatement ps = con1.prepareStatement("REPLACE INTO jumpquests (name, mapid, time) values (?,?,?)");
  129. ps.setString(1, chr.getName());
  130. ps.setInt(2, mapid);
  131. ps.setDouble(3, time);
  132. ps.executeUpdate();
  133. ps.close();
  134. } catch (Exception e) {
  135. }
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement