Couple.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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
  69. {
  70. try
  71. {
  72. con.close();
  73. }
  74. catch (Exception e)
  75. {
  76. }
  77. }
  78. }
  79. public Couple(L2PcInstance player1, L2PcInstance player2)
  80. {
  81. int _tempPlayer1Id = player1.getObjectId();
  82. int _tempPlayer2Id = player2.getObjectId();
  83. _player1Id = _tempPlayer1Id;
  84. _player2Id = _tempPlayer2Id;
  85. _affiancedDate = Calendar.getInstance();
  86. _affiancedDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
  87. _weddingDate = Calendar.getInstance();
  88. _weddingDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
  89. java.sql.Connection con = null;
  90. try
  91. {
  92. con = L2DatabaseFactory.getInstance().getConnection();
  93. PreparedStatement statement;
  94. _Id = IdFactory.getInstance().getNextId();
  95. statement = con.prepareStatement("INSERT INTO mods_wedding (id, player1Id, player2Id, married, affianceDate, weddingDate) VALUES (?, ?, ?, ?, ?, ?)");
  96. statement.setInt(1, _Id);
  97. statement.setInt(2, _player1Id);
  98. statement.setInt(3, _player2Id);
  99. statement.setBoolean(4, false);
  100. statement.setLong(5, _affiancedDate.getTimeInMillis());
  101. statement.setLong(6, _weddingDate.getTimeInMillis());
  102. statement.execute();
  103. statement.close();
  104. }
  105. catch (Exception e)
  106. {
  107. _log.severe(e.toString());
  108. }
  109. finally
  110. {
  111. try
  112. {
  113. con.close();
  114. }
  115. catch (Exception e)
  116. {
  117. }
  118. }
  119. }
  120. public void marry()
  121. {
  122. java.sql.Connection con = null;
  123. try
  124. {
  125. con = L2DatabaseFactory.getInstance().getConnection();
  126. PreparedStatement statement;
  127. statement = con.prepareStatement("UPDATE mods_wedding set married = ?, weddingDate = ? where id = ?");
  128. statement.setBoolean(1, true);
  129. _weddingDate = Calendar.getInstance();
  130. statement.setLong(2, _weddingDate.getTimeInMillis());
  131. statement.setInt(3, _Id);
  132. statement.execute();
  133. statement.close();
  134. _maried = true;
  135. }
  136. catch (Exception e)
  137. {
  138. _log.severe(e.toString());
  139. }
  140. finally
  141. {
  142. try
  143. {
  144. con.close();
  145. }
  146. catch (Exception e)
  147. {
  148. }
  149. }
  150. }
  151. public void divorce()
  152. {
  153. java.sql.Connection con = null;
  154. try
  155. {
  156. con = L2DatabaseFactory.getInstance().getConnection();
  157. PreparedStatement statement;
  158. statement = con.prepareStatement("DELETE FROM mods_wedding WHERE id=?");
  159. statement.setInt(1, _Id);
  160. statement.execute();
  161. statement.close();
  162. }
  163. catch (Exception e)
  164. {
  165. _log.severe("Exception: Couple.divorce(): " + e);
  166. }
  167. finally
  168. {
  169. try
  170. {
  171. con.close();
  172. }
  173. catch (Exception e)
  174. {
  175. }
  176. }
  177. }
  178. public final int getId()
  179. {
  180. return _Id;
  181. }
  182. public final int getPlayer1Id()
  183. {
  184. return _player1Id;
  185. }
  186. public final int getPlayer2Id()
  187. {
  188. return _player2Id;
  189. }
  190. public final boolean getMaried()
  191. {
  192. return _maried;
  193. }
  194. public final Calendar getAffiancedDate()
  195. {
  196. return _affiancedDate;
  197. }
  198. public final Calendar getWeddingDate()
  199. {
  200. return _weddingDate;
  201. }
  202. }