Marriage.java
上传用户:gwt600
上传日期:2021-06-03
资源大小:704k
文件大小:4k
- /*
- * This file is part of the OdinMS Maple Story Server
- Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
- Matthias Butz <matze@odinms.de>
- Jan Christian Meyer <vimes@odinms.de>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License version 3
- as published by the Free Software Foundation. You may not use, modify
- or distribute this program under any other version of the
- GNU Affero General Public License.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /*
- * @Author Jvlaple
- */
- package net.sf.odinms.scripting.npc;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import net.sf.odinms.client.MapleCharacter;
- import net.sf.odinms.database.DatabaseConnection;
- public class Marriage {
- private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Marriage.class);
- public static void createMarriage(MapleCharacter player, MapleCharacter partner) {
- try {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("INSERT INTO marriages (husbandid, wifeid) VALUES (?, ?)");
- ps.setInt(1, player.getId());
- ps.setInt(2, partner.getId());
- ps.executeUpdate();
- ps.close();
- } catch (SQLException ex) {
- log.warn("Problem marrying " + player.getName() + " and " + partner.getName(), ex);
- }
- }
- public static void createEngagement(MapleCharacter player, MapleCharacter partner) {
- try {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("INSERT INTO engagements (husbandid, wifeid) VALUES (?, ?)");
- ps.setInt(1, player.getId());
- ps.setInt(2, partner.getId());
- ps.executeUpdate();
- } catch (SQLException ex) {
- log.warn("Problem announcing engagement with " + player.getName() + " and " + partner.getName(), ex);
- }
- }
- public static void divorceEngagement(MapleCharacter player) {
- try {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("DELETE FROM engagements WHERE husbandid = ?");
- if (player.getGender() != 0) {
- ps = con.prepareStatement("DELETE FROM engagements WHERE wifeid = ?");
- }
- ps.executeUpdate();
- PreparedStatement ps1 = con.prepareStatement("UPDATE characters SET marriagequest = 0 WHERE id = ?");
- ps1.setInt(1, player.getPartnerId());
- ps1.executeUpdate();
- } catch (SQLException ex) {
- log.warn("Problem divorcing" + player.getName() + " and his or her partner", ex);
- }
- }
- public static void divorceMarriage(MapleCharacter player) {
- try {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("DELETE FROM marriages WHERE husbandid = ?");
- if (player.getGender() != 0) {
- ps = con.prepareStatement("DELETE FROM marriages WHERE wifeid = ?");
- }
- ps.setInt(1, player.getId());
- ps.executeUpdate();
- PreparedStatement ps1 = con.prepareStatement("UPDATE characters SET married = 0 WHERE id = ?");
- ps1.setInt(2, player.getPartnerId());
- ps1.executeUpdate();
- PreparedStatement ps2 = con.prepareStatement("UPDATE characters SET partnerid = 0 WHERE id = ?");
- ps2.setInt(2, player.getPartnerId());
- ps2.executeUpdate();
- ps.close();
- ps1.close();
- ps2.close();
- } catch (SQLException ex) {
- log.warn("Problem divorcing" + player.getName() + " and his or her partner", ex);
- }
- }
- }