diff --git a/src/gui/tw/Bwsql.java b/src/gui/tw/Bwsql.java new file mode 100644 index 0000000..bcf76a6 --- /dev/null +++ b/src/gui/tw/Bwsql.java @@ -0,0 +1,7 @@ +package gui.tw; + +public class Bwsql { + + + +} diff --git a/src/gui/tw/Drop.java b/src/gui/tw/Drop.java new file mode 100644 index 0000000..c2d01fc --- /dev/null +++ b/src/gui/tw/Drop.java @@ -0,0 +1,527 @@ +package gui.tw; + +import database.DBConPool; +import server.MapleItemInformationProvider; +import server.life.MapleLifeFactory; +import server.life.MapleMonster; +import server.life.MapleMonsterInformationProvider; +import server.life.MonsterGlobalDropEntry; +import tools.FileoutputUtil; + +import javax.swing.*; +import javax.swing.table.DefaultTableModel; +import java.sql.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +public class Drop { + + int id; + + int dropperid; + + int itemId; + + String itenName; + String dropName; + + int chance; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getDropperid() { + return dropperid; + } + + public void setDropperid(int dropperid) { + this.dropperid = dropperid; + } + + public int getItemId() { + return itemId; + } + + public void setItemId(int itemId) { + this.itemId = itemId; + } + + public String getItenName() { + return itenName; + } + + public void setItenName(String itenName) { + this.itenName = itenName; + } + + public String getDropName() { + return dropName; + } + + public void setDropName(String dropName) { + this.dropName = dropName; + } + + public int getChance() { + return chance; + } + + public void setChance(int chance) { + this.chance = chance; + } + + + public static List mobs =null; + public static List QQS =null; + + /** + * 获得怪物爆率集合 + * @return + */ + public static List getMobBLs() { + + if (mobs != null) { + return mobs; + } + mobs = new ArrayList<>(); + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + ResultSet rs = null; + + ps = con.prepareStatement("SELECT * FROM drop_data WHERE itemid !=0"); + rs = ps.executeQuery(); + while (rs.next()) { + Drop b = new Drop(); + b.setId(rs.getInt("id")); + b.setDropperid(rs.getInt("dropperid")); + b.setItemId(rs.getInt("itemid")); + b.setItenName(MapleItemInformationProvider.getInstance().getName(rs.getInt("itemid"))); + MapleMonster dropperid1 = MapleLifeFactory.getMonster(rs.getInt("dropperid")); + if (dropperid1 != null) { + b.setDropName(dropperid1.getStats().getName()); + } else { + b.setDropName("未查询到怪物"); + } + b.setChance(rs.getInt("chance")); + b.setChance(rs.getInt("chance")); + mobs.add(b); + } + rs.close(); + ps.close(); + con.close(); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]怪物暴率出错:" + ex.getMessage()); + } + return mobs; + } + + /** + * 获得卡片爆率集合 + * @return + */ + public static List getKPS() { + List mobBLs = getMobBLs(); + List collect = mobBLs.stream() + .filter(drop -> drop.getItemId() > 2380000 && drop.getItemId() < 2390000) + .collect(Collectors.toList()); + return collect; + } + + + /** + * 根据序号 删除怪物爆率 + * @param id 序号 + * @param dropperid 怪物id + */ + public static void deleteGWId(int id,int dropperid) { + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + + ps = con.prepareStatement("DELETE FROM drop_data where id = ?"); + ps.setInt(1,id); + ps.execute(); + ps.close(); + con.close(); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]删除出错:" + ex.getMessage()); + } + MapleMonsterInformationProvider.getInstance().removeById(dropperid); + mobs = mobs.stream().filter(drop -> drop.getId() != id) + .collect(Collectors.toList()); + } + + /** + * 根据怪物id删除这个怪物的爆率 + * @param dropperid 怪物id + */ + public static void deleteGWdropperid(int dropperid) { + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + + ps = con.prepareStatement("DELETE FROM drop_data where dropperid = ?"); + ps.setInt(1,dropperid); + ps.execute(); + ps.close(); + con.close(); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]删除出错:" + ex.getMessage()); + } + MapleMonsterInformationProvider.getInstance().removeById(dropperid); + + mobs = mobs.stream().filter(drop -> drop.getDropperid() != dropperid) + .collect(Collectors.toList()); + } + + /** + * 清空怪物爆率表 + */ + public static void deleteGWAll() { + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + ps = con.prepareStatement("TRUNCATE TABLE drop_data "); + ps.execute(); + ps.close(); + con.close(); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]刷新出错:" + ex.getMessage()); + } + MapleMonsterInformationProvider.getInstance().removeByAll(); + mobs = null; + } + + /** + * 修改怪物爆率 + * @param dropperid 怪物id + * @param itemid 物品id + * @param chance 爆率 + * @param id 序号 + */ + public static void updateGWId(int dropperid, int itemid, int chance, int id) { + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + + ps = con.prepareStatement("UPDATE drop_data set dropperid = ?,itemid = ?,chance = ? where id = ?"); + ps.setInt(1, dropperid); + ps.setInt(2, itemid); + ps.setInt(3, chance); + ps.setInt(4, id); + ps.execute(); + con.close(); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]刷新出错:" + ex.getMessage()); + } + MapleMonsterInformationProvider.getInstance().removeById(dropperid); + mobs.forEach(drop -> { + if (drop.getId() == id) { + drop.setDropperid(dropperid); + drop.setItemId(itemid); + drop.setChance(chance); + } + }); + } + + /** + * 添加怪物爆率 + * @param dropperid 怪物id + * @param itemid 物品id + * @param chance 爆率 + */ + public static void insertGWId(int dropperid, int itemid, int chance) { + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + + ps = con.prepareStatement("INSERT INTO drop_data (dropperid,itemid,minimum_quantity,maximum_quantity,chance) VALUES( ?,?,1,1,?)", Statement.RETURN_GENERATED_KEYS); + ps.setInt(1, dropperid); + ps.setInt(2, itemid); + ps.setInt(3, chance); + int id = ps.executeUpdate(); + + ps.close(); + con.close(); + + Drop b = new Drop(); + b.setId(id); + b.setDropperid(dropperid); + b.setItemId(itemid); + b.setItenName(MapleItemInformationProvider.getInstance().getName(itemid)); + MapleMonster dropperid1 = MapleLifeFactory.getMonster(itemid); + if (dropperid1 != null) { + b.setDropName(dropperid1.getStats().getName()); + } else { + b.setDropName("未查询到怪物"); + } + b.setChance(chance); + QQS.add(b); + + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]刷新出错:" + ex.getMessage()); + } + MapleMonsterInformationProvider.getInstance().removeById(dropperid); + mobs =null; + } + + /** + * 获得全局爆率集合 + * @return + */ + public static List getQQS() { + if (QQS!=null){ + return QQS; + } + QQS = new ArrayList<>(); + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + ResultSet rs = null; + + ps = con.prepareStatement("SELECT * FROM drop_data_global WHERE itemid !=0"); + rs = ps.executeQuery(); + while (rs.next()) { + Drop b = new Drop(); + b.setId(rs.getInt("id")); + b.setDropperid(rs.getInt("dropperid")); + b.setItemId(rs.getInt("itemid")); + b.setItenName(MapleItemInformationProvider.getInstance().getName(rs.getInt("itemid"))); + MapleMonster dropperid1 = MapleLifeFactory.getMonster(rs.getInt("dropperid")); + if (dropperid1 != null) { + b.setDropName(dropperid1.getStats().getName()); + } else { + b.setDropName("未查询到怪物"); + } + b.setChance(rs.getInt("chance")); + QQS.add(b); + } + rs.close(); + ps.close(); + con.close(); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]怪物暴率出错:" + ex.getMessage()); + } + return QQS; + } + + /** + * 修改全局爆率 + * @param itemid 物品id + * @param chance 爆率 + * @param id 序号 + */ + public static void updateQQId(int itemid, int chance, int id) { + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + + ps = con.prepareStatement("UPDATE drop_data_global set itemid = ?,chance = ? where id = ?"); + ps.setInt(1, itemid); + ps.setInt(2, chance); + ps.setInt(3, id); + ps.execute(); + con.close(); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]刷新出错:" + ex.getMessage()); + } + MapleMonsterInformationProvider.getInstance().getGlobalDrop().clear(); + MapleMonsterInformationProvider.getInstance().retrieveGlobal(); + + QQS.forEach(drop -> { + if (drop.getId() == id) { + drop.setItemId(itemid); + drop.setChance(chance); + } + }); + } + + + /** + * 增加全局爆率 + * @param itemid 物品id + * @param chance 爆率 + */ + public static void insertQQ(int itemid, int chance ) { + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + + ps = con.prepareStatement("INSERT INTO drop_data_global (continent,droptype,itemid,minimum_quantity,maximum_quantity,chance) VALUES(1,1,?,1,1,?)", Statement.RETURN_GENERATED_KEYS); + ps.setInt(1, itemid); + ps.setInt(2, chance); + int id = ps.executeUpdate(); + ps.close(); + con.close(); + + Drop b = new Drop(); + b.setId(id); + b.setItemId(itemid); + b.setItenName(MapleItemInformationProvider.getInstance().getName(itemid)); + b.setChance(chance); + QQS.add(b); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]刷新出错:" + ex.getMessage()); + } + MapleMonsterInformationProvider.getInstance().getGlobalDrop().clear(); + MapleMonsterInformationProvider.getInstance().retrieveGlobal(); + + + + } + + + + /** + * 删除全局爆率集合 + */ + public static void deleteQJAll() { + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + ps = con.prepareStatement("TRUNCATE TABLE drop_data_global "); + ps.execute(); + ps.close(); + con.close(); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]刷新出错:" + ex.getMessage()); + } + MapleMonsterInformationProvider.getInstance().getGlobalDrop().clear(); + MapleMonsterInformationProvider.getInstance().retrieveGlobal(); + QQS = null; + } + /** + * 清理道具id爆率 + */ + public static void deleteItemId(int itemId) { + + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + + ps = con.prepareStatement("DELETE FROM drop_data where itemid = ?"); + ps.setInt(1,itemId); + ps.execute(); + ps.close(); + con.close(); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]删除出错:" + ex.getMessage()); + } + MapleMonsterInformationProvider.getInstance().removeByAll(); + + mobs = mobs.stream().filter(drop -> drop.getItemId() != itemId) + .collect(Collectors.toList()); + + try { + final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection(); + PreparedStatement ps = null; + + ps = con.prepareStatement("DELETE FROM drop_data_global where itemid = ?"); + ps.setInt(1,itemId); + ps.execute(); + ps.close(); + } catch (SQLException ex) { + System.err.println("[" + FileoutputUtil.CurrentReadable_Time() + "]删除出错:" + ex.getMessage()); + } + MapleMonsterInformationProvider.getInstance().getGlobalDrop().clear(); + MapleMonsterInformationProvider.getInstance().retrieveGlobal(); + + QQS = QQS.stream().filter(drop -> drop.getItemId() != itemId) + .collect(Collectors.toList()); + } + + /** + * 根据道具id查询掉落 + */ + public static List getItemIdsMob(String itemId) { + List mobBLs = getMobBLs(); + return mobBLs.stream().filter(drop -> String.valueOf(drop.getItemId()).contains(itemId)) + .collect(Collectors.toList()); + } + + /** + * 根据物品名称查询掉落 + */ + public static List getItemNamesMob(String itemName) { + List mobBLs = getMobBLs(); + return mobBLs.stream().filter(drop -> String.valueOf(drop.getItenName()).contains(itemName)) + .collect(Collectors.toList()); + } + + + + /** + * 根据道具id查询全局掉落 + */ + public static List getItemIdsQQ(String itemId) { + List qqs = getQQS(); + return qqs.stream().filter(drop -> String.valueOf(drop.getItemId()).contains(itemId)) + .collect(Collectors.toList()); + } + + /** + * 根据物品名称查询全局掉落 + */ + public static List getItemNamesQQ(String itemName) { + List qqs = getQQS(); + return qqs.stream().filter(drop -> String.valueOf(drop.getItenName()).contains(itemName)) + .collect(Collectors.toList()); + } + + /** + * 根据怪物id查询掉落 + */ + public static List getMobIdsMob(String MobId) { + List mobBLs = getMobBLs(); + return mobBLs.stream().filter(drop -> String.valueOf(drop.getDropperid()).contains(MobId)) + .collect(Collectors.toList()); + } + + /** + * 根据物品名称查询掉落 + */ + public static List getMobNames(String MobName) { + List mobBLs = getMobBLs(); + return mobBLs.stream().filter(drop -> String.valueOf(drop.getDropName()).contains(MobName)) + .collect(Collectors.toList()); + } + + /** + * 排序 + * @param drops 原始集合 + * @param type 1按序号排序 2道具id 3道具名字 4怪物id 5怪物名字 6爆率 + * @return + */ + public static List sort(final List drops,int type) { + switch (type){ + case 1: + drops.sort(Comparator.comparingInt(Drop::getId)); + break; + case 2: + drops.sort(Comparator.comparingInt(Drop::getItemId)); + break; + case 3: + drops.sort(Comparator.comparing(Drop::getItenName)); + break; + case 4: + drops.sort(Comparator.comparingInt(Drop::getDropperid)); + break; + case 5: + drops.sort(Comparator.comparing(Drop::getDropName)); + break; + case 6: + drops.sort(Comparator.comparingInt(Drop::getChance)); + break; + } + return drops; + } + +} diff --git a/src/handling/channel/handler/InventoryHandler.java b/src/handling/channel/handler/InventoryHandler.java index c24998f..4af23a3 100644 --- a/src/handling/channel/handler/InventoryHandler.java +++ b/src/handling/channel/handler/InventoryHandler.java @@ -102,12 +102,12 @@ public class InventoryHandler { final short dst = slea.readShort(); final short quantity = slea.readShort(); if (src < 0 && dst > 0) { - MapleInventoryManipulator.unequip(c, src, dst);//脱装备时 - c.getSession().write(MaplePacketCreator.fuckGuildInfo(c.getPlayer()));//自定义的显示名字 + MapleInventoryManipulator.unequip(c, src, dst); + c.getSession().write(MaplePacketCreator.fuckGuildInfo(c.getPlayer())); c.sendPacket(FamilyPacket.getFamilyInfo(c.getPlayer())); } else if (dst < 0) { - MapleInventoryManipulator.equip(c, src, dst);//穿装备时 - c.getSession().write(MaplePacketCreator.fuckGuildInfo(c.getPlayer()));//自定义的显示名字 + MapleInventoryManipulator.equip(c, src, dst); + c.getSession().write(MaplePacketCreator.fuckGuildInfo(c.getPlayer())); c.sendPacket(FamilyPacket.getFamilyInfo(c.getPlayer())); } else if (dst == 0) { MapleInventoryManipulator.drop(c, type, src, quantity); @@ -115,9 +115,6 @@ public class InventoryHandler { MapleInventoryManipulator.move(c, type, src, dst); } - - System.out.println(1); - } public static final void ItemSort(final LittleEndianAccessor slea, final MapleClient c) { diff --git a/src/server/life/MapleMonsterInformationProvider.java b/src/server/life/MapleMonsterInformationProvider.java index 3184391..80689b3 100644 --- a/src/server/life/MapleMonsterInformationProvider.java +++ b/src/server/life/MapleMonsterInformationProvider.java @@ -35,6 +35,13 @@ public class MapleMonsterInformationProvider { this.retrieveGlobal(); } + public void removeById(Integer id) { + drops.remove(id); + } + public void removeByAll( ) { + drops.clear(); + } + public static final MapleMonsterInformationProvider getInstance() { return MapleMonsterInformationProvider.instance; } @@ -54,7 +61,7 @@ public class MapleMonsterInformationProvider { return this.mobCache; } - private void retrieveGlobal() { + public void retrieveGlobal() { PreparedStatement ps = null; ResultSet rs = null; try (final Connection con = (Connection) DBConPool.getInstance().getDataSource().getConnection()) { diff --git a/src/server/maps/MapleMap.java b/src/server/maps/MapleMap.java index 7f44764..36b5f7a 100644 --- a/src/server/maps/MapleMap.java +++ b/src/server/maps/MapleMap.java @@ -667,6 +667,7 @@ public final class MapleMap { if (mmeos < 1) { mmeos = 1; } + this.spawnMobMesoDrop(mmeos, this.calcDropPos(pos, mob.getTruePosition()), (MapleMapObject) mob, chr, false, droptype); mesoDropped = true; }