2025-03-13 21:19:33 +08:00
package gui.tw ;
2025-03-14 16:09:54 +08:00
import cn.hutool.core.io.file.FileReader ;
import cn.hutool.core.io.file.FileWriter ;
import com.alibaba.fastjson.JSONObject ;
2025-03-13 21:19:33 +08:00
import database.DBConPool ;
2025-03-14 16:09:54 +08:00
import gui.Start ;
import provider.MapleData ;
import provider.MapleDataTool ;
2025-03-13 21:19:33 +08:00
import server.MapleItemInformationProvider ;
import server.life.MapleLifeFactory ;
import server.life.MapleMonster ;
import server.life.MapleMonsterInformationProvider ;
import server.life.MonsterGlobalDropEntry ;
import tools.FileoutputUtil ;
2025-03-14 16:09:54 +08:00
import tools.StringUtil ;
2025-03-13 21:19:33 +08:00
import javax.swing.* ;
import javax.swing.table.DefaultTableModel ;
2025-03-14 16:09:54 +08:00
import java.io.File ;
2025-03-13 21:19:33 +08:00
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 < Drop > mobs = null ;
public static List < Drop > QQS = null ;
/ * *
* 获得怪物爆率集合
* @return
* /
public static List < Drop > 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 " ) ) ) ;
2025-03-14 15:01:36 +08:00
try {
2025-03-14 16:09:54 +08:00
String string = MapleDataTool . getString ( ( rs . getInt ( " dropperid " ) + " /name " ) , MapleLifeFactory . mobStringData , " 未知怪物 " ) ;
b . setDropName ( string ) ;
2025-03-13 21:19:33 +08:00
}
2025-03-14 15:01:36 +08:00
catch ( Exception e ) {
b . setDropName ( " 无名字 " ) ;
} ;
2025-03-13 21:19:33 +08:00
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 < Drop > getKPS ( ) {
List < Drop > mobBLs = getMobBLs ( ) ;
List < Drop > 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 ) ) ;
2025-03-14 16:09:54 +08:00
String string = MapleDataTool . getString ( ( dropperid + " /name " ) , MapleLifeFactory . mobStringData , " MISSINGNO " ) ;
b . setDropName ( string ) ;
2025-03-13 21:19:33 +08:00
b . setChance ( chance ) ;
2025-03-14 16:09:54 +08:00
mobs . add ( b ) ;
2025-03-13 21:19:33 +08:00
} catch ( SQLException ex ) {
System . err . println ( " [ " + FileoutputUtil . CurrentReadable_Time ( ) + " ]刷新出错: " + ex . getMessage ( ) ) ;
}
MapleMonsterInformationProvider . getInstance ( ) . removeById ( dropperid ) ;
mobs = null ;
}
/ * *
* 获得全局爆率集合
* @return
* /
public static List < Drop > 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 . setItemId ( rs . getInt ( " itemid " ) ) ;
b . setItenName ( MapleItemInformationProvider . getInstance ( ) . getName ( rs . getInt ( " itemid " ) ) ) ;
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 ;
}
2025-03-14 16:09:54 +08:00
/ * *
* 根据序号 删除全局爆率
* @param id 序号
* /
public static void deleteQQId ( int id ) {
try {
final Connection con = ( Connection ) DBConPool . getInstance ( ) . getDataSource ( ) . getConnection ( ) ;
PreparedStatement ps = null ;
ps = con . prepareStatement ( " DELETE FROM drop_data_global 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 ( ) . getGlobalDrop ( ) . clear ( ) ;
MapleMonsterInformationProvider . getInstance ( ) . retrieveGlobal ( ) ;
QQS = QQS . stream ( ) . filter ( drop - > drop . getId ( ) ! = id )
. collect ( Collectors . toList ( ) ) ;
}
2025-03-13 21:19:33 +08:00
/ * *
* 修改全局爆率
* @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 ( ) ;
2025-03-14 16:09:54 +08:00
}
2025-03-13 21:19:33 +08:00
2025-03-14 16:09:54 +08:00
/ * *
* 批量增加全局爆率
* @param drops
* /
public static void insertQQALL ( List < Drop > drops ) {
for ( Drop drop : drops ) {
2025-03-13 21:19:33 +08:00
2025-03-14 16:09:54 +08:00
try {
final Connection con = ( Connection ) DBConPool . getInstance ( ) . getDataSource ( ) . getConnection ( ) ;
PreparedStatement ps = null ;
2025-03-13 21:19:33 +08:00
2025-03-14 16:09:54 +08:00
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 , drop . getItemId ( ) ) ;
ps . setInt ( 2 , drop . getChance ( ) ) ;
int id = ps . executeUpdate ( ) ;
ps . close ( ) ;
con . close ( ) ;
2025-03-13 21:19:33 +08:00
2025-03-14 16:09:54 +08:00
Drop b = new Drop ( ) ;
b . setId ( id ) ;
b . setItemId ( drop . getItemId ( ) ) ;
b . setItenName ( MapleItemInformationProvider . getInstance ( ) . getName ( drop . getItemId ( ) ) ) ;
b . setChance ( drop . getChance ( ) ) ;
QQS . add ( b ) ;
} catch ( SQLException ex ) {
System . err . println ( " [ " + FileoutputUtil . CurrentReadable_Time ( ) + " ]刷新出错: " + ex . getMessage ( ) ) ;
}
}
MapleMonsterInformationProvider . getInstance ( ) . getGlobalDrop ( ) . clear ( ) ;
MapleMonsterInformationProvider . getInstance ( ) . retrieveGlobal ( ) ;
}
2025-03-13 21:19:33 +08:00
/ * *
* 删除全局爆率集合
* /
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 < Drop > getItemIdsMob ( String itemId ) {
List < Drop > mobBLs = getMobBLs ( ) ;
return mobBLs . stream ( ) . filter ( drop - > String . valueOf ( drop . getItemId ( ) ) . contains ( itemId ) )
. collect ( Collectors . toList ( ) ) ;
}
/ * *
* 根据物品名称查询掉落
* /
public static List < Drop > getItemNamesMob ( String itemName ) {
List < Drop > mobBLs = getMobBLs ( ) ;
return mobBLs . stream ( ) . filter ( drop - > String . valueOf ( drop . getItenName ( ) ) . contains ( itemName ) )
. collect ( Collectors . toList ( ) ) ;
}
/ * *
* 根据道具id查询全局掉落
* /
public static List < Drop > getItemIdsQQ ( String itemId ) {
List < Drop > qqs = getQQS ( ) ;
return qqs . stream ( ) . filter ( drop - > String . valueOf ( drop . getItemId ( ) ) . contains ( itemId ) )
. collect ( Collectors . toList ( ) ) ;
}
/ * *
* 根据物品名称查询全局掉落
* /
public static List < Drop > getItemNamesQQ ( String itemName ) {
List < Drop > qqs = getQQS ( ) ;
return qqs . stream ( ) . filter ( drop - > String . valueOf ( drop . getItenName ( ) ) . contains ( itemName ) )
. collect ( Collectors . toList ( ) ) ;
}
/ * *
* 根据怪物id查询掉落
* /
public static List < Drop > getMobIdsMob ( String MobId ) {
List < Drop > mobBLs = getMobBLs ( ) ;
return mobBLs . stream ( ) . filter ( drop - > String . valueOf ( drop . getDropperid ( ) ) . contains ( MobId ) )
. collect ( Collectors . toList ( ) ) ;
}
/ * *
* 根据物品名称查询掉落
* /
public static List < Drop > getMobNames ( String MobName ) {
List < Drop > 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 < Drop > sort ( final List < Drop > 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 ;
}
2025-03-14 16:09:54 +08:00
/ * *
* 导出
* /
public static void exportData ( String file , List < Drop > drops ) {
JSONObject jsonObject1 = new JSONObject ( ) ;
jsonObject1 . put ( " bl " , drops ) ;
String jsonString1 = jsonObject1 . toJSONString ( ) ;
FileWriter fileWriter = new FileWriter ( file ) ;
fileWriter . write ( jsonString1 ) ;
}
/ * *
* 导入全局
* /
public static void importDataQQ ( String file ) {
FileReader fileReader = new FileReader ( file ) ;
String result3 = fileReader . readString ( ) ;
//转json
JSONObject jsonObject1 = JSONObject . parseObject ( result3 ) ;
List < Drop > bl = jsonObject1 . getJSONArray ( " bl " ) . toJavaList ( Drop . class ) ;
getQQS ( ) ;
insertQQALL ( bl ) ;
}
/ * *
* 导入怪物
* /
public static void importDataMob ( String file ) {
FileReader fileReader = new FileReader ( file ) ;
String result3 = fileReader . readString ( ) ;
//转json
JSONObject jsonObject1 = JSONObject . parseObject ( result3 ) ;
List < Drop > bl = jsonObject1 . getJSONArray ( " bl " ) . toJavaList ( Drop . class ) ;
getMobBLs ( ) ;
for ( Drop drop : bl ) {
insertGWId ( drop . getDropperid ( ) , drop . getItemId ( ) , drop . getChance ( ) ) ;
}
}
public static void main ( String [ ] args ) {
List < Drop > qqs = getMobBLs ( ) ;
exportData ( " E: \\ MXD \\ cs.txt " , qqs ) ;
importDataQQ ( " E: \\ MXD \\ cs.txt " ) ;
// insertGWId(3037,11,11);
}
2025-03-13 21:19:33 +08:00
}