Couple.java 5.2 KB

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