/** * License * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR * COPYRIGHT LAW IS PROHIBITED. * * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE * MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS. * */ package l1j.server.server.model; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.logging.Level; import java.util.logging.Logger; import l1j.server.L1DatabaseFactory; import l1j.server.server.datatables.InnKeyTable; import l1j.server.server.datatables.ItemTable; import l1j.server.server.model.Instance.L1ItemInstance; import l1j.server.server.model.Instance.L1PcInstance; import l1j.server.server.templates.L1Item; import l1j.server.server.utils.SQLUtil; public class L1DwarfForClanInventory extends L1Inventory { private static final long serialVersionUID = 1L; private static Logger _log = Logger.getLogger(L1DwarfForClanInventory.class.getName()); private final L1Clan _clan; public L1DwarfForClanInventory(L1Clan clan) { _clan = clan; } // DBのcharacter_itemsの読込 @Override public synchronized void loadItems() { Connection con = null; PreparedStatement pstm = null; ResultSet rs = null; try { con = L1DatabaseFactory.getInstance().getConnection(); pstm = con.prepareStatement("SELECT * FROM clan_warehouse WHERE clan_name = ?"); pstm.setString(1, _clan.getClanName()); rs = pstm.executeQuery(); while (rs.next()) { L1ItemInstance item = new L1ItemInstance(); int objectId = rs.getInt("id"); item.setId(objectId); int itemId = rs.getInt("item_id"); L1Item itemTemplate = ItemTable.getInstance().getTemplate(itemId); if (itemTemplate == null) { throw new NullPointerException("item_id=" + itemId+ " not found"); } item.setItem(itemTemplate); item.setCount(rs.getInt("count")); item.setEquipped(false); item.setEnchantLevel(rs.getInt("enchantlvl")); item.setIdentified(rs.getInt("is_id") != 0 ? true : false); item.set_durability(rs.getInt("durability")); item.setChargeCount(rs.getInt("charge_count")); item.setRemainingTime(rs.getInt("remaining_time")); item.setLastUsed(rs.getTimestamp("last_used")); item.setBless(rs.getInt("bless")); item.setAttrEnchantKind(rs.getInt("attr_enchant_kind")); item.setAttrEnchantLevel(rs.getInt("attr_enchant_level")); item.setFireMr(rs.getInt("firemr")); item.setWaterMr(rs.getInt("watermr")); item.setEarthMr(rs.getInt("earthmr")); item.setWindMr(rs.getInt("windmr")); item.setaddSp(rs.getInt("addsp")); item.setaddHp(rs.getInt("addhp")); item.setaddMp(rs.getInt("addmp")); item.setHpr(rs.getInt("hpr")); item.setMpr(rs.getInt("mpr")); item.setM_Def(rs.getInt("m_def")); // 登入鑰匙紀錄 if (item.getItem().getItemId() == 40312) { InnKeyTable.checkey(item); } _items.add(item); L1World.getInstance().storeObject(item); } } catch (SQLException e) { _log.log(Level.SEVERE, e.getLocalizedMessage(), e); } finally { SQLUtil.close(rs); SQLUtil.close(pstm); SQLUtil.close(con); } } // DBのclan_warehouseへ登録 @Override public synchronized void insertItem(L1ItemInstance item) { Connection con = null; PreparedStatement pstm = null; try { con = L1DatabaseFactory.getInstance().getConnection(); pstm = con.prepareStatement("INSERT INTO clan_warehouse SET id = ?, clan_name = ?, item_id = ?, item_name = ?, count = ?, is_equipped=0, enchantlvl = ?, is_id= ?, durability = ?, charge_count = ?, remaining_time = ?, last_used = ?, bless = ?, attr_enchant_kind = ?, attr_enchant_level = ?,firemr = ?,watermr = ?,earthmr = ?,windmr = ?,addsp = ?,addhp = ?,addmp = ?,hpr = ?,mpr = ?,m_def = ?"); pstm.setInt(1, item.getId()); pstm.setString(2, _clan.getClanName()); pstm.setInt(3, item.getItemId()); pstm.setString(4, item.getName()); pstm.setInt(5, item.getCount()); pstm.setInt(6, item.getEnchantLevel()); pstm.setInt(7, item.isIdentified() ? 1 : 0); pstm.setInt(8, item.get_durability()); pstm.setInt(9, item.getChargeCount()); pstm.setInt(10, item.getRemainingTime()); pstm.setTimestamp(11, item.getLastUsed()); pstm.setInt(12, item.getBless()); pstm.setInt(13, item.getAttrEnchantKind()); pstm.setInt(14, item.getAttrEnchantLevel()); pstm.setInt(15, item.getFireMr()); pstm.setInt(16, item.getWaterMr()); pstm.setInt(17, item.getEarthMr()); pstm.setInt(18, item.getWindMr()); pstm.setInt(19, item.getaddSp()); pstm.setInt(20, item.getaddHp()); pstm.setInt(21, item.getaddMp()); pstm.setInt(22, item.getHpr()); pstm.setInt(23, item.getMpr()); pstm.setInt(24, item.getM_Def()); pstm.execute(); } catch (SQLException e) { _log.log(Level.SEVERE, e.getLocalizedMessage(), e); } finally { SQLUtil.close(pstm); SQLUtil.close(con); } } // DBのclan_warehouseを更新 @Override public synchronized void updateItem(L1ItemInstance item) { Connection con = null; PreparedStatement pstm = null; try { con = L1DatabaseFactory.getInstance().getConnection(); pstm = con.prepareStatement("UPDATE clan_warehouse SET count = ? WHERE id = ?"); pstm.setInt(1, item.getCount()); pstm.setInt(2, item.getId()); pstm.execute(); } catch (SQLException e) { _log.log(Level.SEVERE, e.getLocalizedMessage(), e); } finally { SQLUtil.close(pstm); SQLUtil.close(con); } } // DBのclan_warehouseから削除 @Override public synchronized void deleteItem(L1ItemInstance item) { Connection con = null; PreparedStatement pstm = null; try { con = L1DatabaseFactory.getInstance().getConnection(); pstm = con.prepareStatement("DELETE FROM clan_warehouse WHERE id = ?"); pstm.setInt(1, item.getId()); pstm.execute(); } catch (SQLException e) { _log.log(Level.SEVERE, e.getLocalizedMessage(), e); } finally { SQLUtil.close(pstm); SQLUtil.close(con); } _items.remove(_items.indexOf(item)); } // DBのクラン倉庫のアイテムを全て削除(血盟解散時のみ使用) public synchronized void deleteAllItems() { Connection con = null; PreparedStatement pstm = null; try { con = L1DatabaseFactory.getInstance().getConnection(); pstm = con.prepareStatement("DELETE FROM clan_warehouse WHERE clan_name = ?"); pstm.setString(1, _clan.getClanName()); pstm.execute(); } catch (SQLException e) { _log.log(Level.SEVERE, e.getLocalizedMessage(), e); } finally { SQLUtil.close(pstm); SQLUtil.close(con); } } /** * 寫入血盟使用紀錄 * @param pc L1PcInstance</br> * @param item L1ItemInstance</br> * @param count 物品數量</br> * @param type 領出: 1, 存入: 0 </br> */ public void writeHistory(L1PcInstance pc, L1ItemInstance item, int count, int type){ Connection con = null; PreparedStatement pstm = null; try { con = L1DatabaseFactory.getInstance().getConnection(); pstm = con.prepareStatement("INSERT INTO clan_warehouse_history SET clan_id=?, char_name=?, type=?, item_name=?, item_count=?, record_time=?"); pstm.setInt(1, _clan.getClanId()); pstm.setString(2, pc.getName()); pstm.setInt(3, type); pstm.setString(4, item.getName()); pstm.setInt(5, count); pstm.setTimestamp(6, new Timestamp(System.currentTimeMillis())); pstm.execute(); } catch (SQLException e) { _log.log(Level.SEVERE, e.getLocalizedMessage(), e); } finally { SQLUtil.close(pstm); SQLUtil.close(con); } } }