Couple.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 net.sf.l2j.gameserver.model.entity;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.util.Calendar;
  19. import java.util.logging.Logger;
  20. import net.sf.l2j.L2DatabaseFactory;
  21. import net.sf.l2j.gameserver.idfactory.IdFactory;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  23. /**
  24. * @author evill33t
  25. *
  26. */
  27. public class Couple
  28. {
  29. private static final Logger _log = Logger.getLogger(Couple.class.getName());
  30. // =========================================================
  31. // Data Field
  32. private int _Id = 0;
  33. private int _player1Id = 0;
  34. private int _player2Id = 0;
  35. private boolean _maried = false;
  36. private Calendar _affiancedDate;
  37. private Calendar _weddingDate;
  38. // =========================================================
  39. // Constructor
  40. public Couple(int coupleId)
  41. {
  42. _Id = coupleId;
  43. java.sql.Connection con = null;
  44. try
  45. {
  46. PreparedStatement statement;
  47. ResultSet rs;
  48. con = L2DatabaseFactory.getInstance().getConnection();
  49. statement = con.prepareStatement("Select * from mods_wedding where id = ?");
  50. statement.setInt(1, _Id);
  51. rs = statement.executeQuery();
  52. while (rs.next())
  53. {
  54. _player1Id = rs.getInt("player1Id");
  55. _player2Id = rs.getInt("player2Id");
  56. _maried = rs.getBoolean("married");
  57. _affiancedDate = Calendar.getInstance();
  58. _affiancedDate.setTimeInMillis(rs.getLong("affianceDate"));
  59. _weddingDate = Calendar.getInstance();
  60. _weddingDate.setTimeInMillis(rs.getLong("weddingDate"));
  61. }
  62. statement.close();
  63. }
  64. catch (Exception e)
  65. {
  66. _log.severe("Exception: Couple.load(): "+e);
  67. }
  68. finally {try { con.close(); } catch (Exception e) {}}
  69. }
  70. public Couple(L2PcInstance player1,L2PcInstance player2)
  71. {
  72. int _tempPlayer1Id = player1.getObjectId();
  73. int _tempPlayer2Id = player2.getObjectId();
  74. _player1Id = _tempPlayer1Id;
  75. _player2Id = _tempPlayer2Id;
  76. _affiancedDate = Calendar.getInstance();
  77. _affiancedDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
  78. _weddingDate = Calendar.getInstance();
  79. _weddingDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
  80. java.sql.Connection con = null;
  81. try
  82. {
  83. con = L2DatabaseFactory.getInstance().getConnection();
  84. PreparedStatement statement;
  85. _Id = IdFactory.getInstance().getNextId();
  86. statement = con.prepareStatement("INSERT INTO mods_wedding (id, player1Id, player2Id, married, affianceDate, weddingDate) VALUES (?, ?, ?, ?, ?, ?)");
  87. statement.setInt(1, _Id);
  88. statement.setInt(2, _player1Id);
  89. statement.setInt(3, _player2Id);
  90. statement.setBoolean(4, false);
  91. statement.setLong(5, _affiancedDate.getTimeInMillis());
  92. statement.setLong(6, _weddingDate.getTimeInMillis());
  93. statement.execute();
  94. statement.close();
  95. }
  96. catch (Exception e)
  97. {
  98. _log.severe(e.toString());
  99. }
  100. finally
  101. {
  102. try { con.close(); } catch (Exception e) {}
  103. }
  104. }
  105. public void marry()
  106. {
  107. java.sql.Connection con = null;
  108. try
  109. {
  110. con = L2DatabaseFactory.getInstance().getConnection();
  111. PreparedStatement statement;
  112. statement = con.prepareStatement("UPDATE mods_wedding set married = ?, weddingDate = ? where id = ?");
  113. statement.setBoolean(1, true);
  114. _weddingDate = Calendar.getInstance();
  115. statement.setLong(2, _weddingDate.getTimeInMillis());
  116. statement.setInt(3, _Id);
  117. statement.execute();
  118. statement.close();
  119. _maried = true;
  120. }
  121. catch (Exception e)
  122. {
  123. _log.severe(e.toString());
  124. }
  125. finally
  126. {
  127. try { con.close(); } catch (Exception e) {}
  128. }
  129. }
  130. public void divorce()
  131. {
  132. java.sql.Connection con = null;
  133. try
  134. {
  135. con = L2DatabaseFactory.getInstance().getConnection();
  136. PreparedStatement statement;
  137. statement = con.prepareStatement("DELETE FROM mods_wedding WHERE id=?");
  138. statement.setInt(1, _Id);
  139. statement.execute();
  140. statement.close();
  141. }
  142. catch (Exception e)
  143. {
  144. _log.severe("Exception: Couple.divorce(): "+e);
  145. }
  146. finally
  147. {
  148. try { con.close(); } catch (Exception e) {}
  149. }
  150. }
  151. public final int getId() { return _Id; }
  152. public final int getPlayer1Id() { return _player1Id; }
  153. public final int getPlayer2Id() { return _player2Id; }
  154. public final boolean getMaried() { return _maried; }
  155. public final Calendar getAffiancedDate() { return _affiancedDate; }
  156. public final Calendar getWeddingDate() { return _weddingDate; }
  157. }