CPQ 1 CPQ 2 CASAMENTO

This commit is contained in:
Diego Armando de Freitas Matos
2019-03-06 21:55:47 -03:00
parent 799870df63
commit 90ad58f17f
60 changed files with 17440 additions and 15140 deletions
@@ -44,306 +44,308 @@ import tools.Pair;
import tools.Randomizer;
public class MapleMonsterInformationProvider {
// Author : LightPepsi
// Author : LightPepsi
private static final MapleMonsterInformationProvider instance = new MapleMonsterInformationProvider();
public static MapleMonsterInformationProvider getInstance() {
return instance;
}
private final Map<Integer, List<MonsterDropEntry>> drops = new HashMap<>();
private final List<MonsterGlobalDropEntry> globaldrops = new ArrayList<>();
private final Map<Integer, List<MonsterGlobalDropEntry>> continentdrops = new HashMap<>();
private final Map<Integer, List<Integer>> dropsChancePool = new HashMap<>(); // thanks to ronan
private final Set<Integer> hasNoMultiEquipDrops = new HashSet<>();
private final Map<Integer, List<MonsterDropEntry>> extraMultiEquipDrops = new HashMap<>();
private final Map<Pair<Integer, Integer>, Integer> mobAttackAnimationTime = new HashMap<>();
private final Map<MobSkill, Integer> mobSkillAnimationTime = new HashMap<>();
private final Map<Integer, Pair<Integer, Integer>> mobAttackInfo = new HashMap<>();
private final Map<Integer, Boolean> mobBossCache = new HashMap<>();
private final Map<Integer, String> mobNameCache = new HashMap<>();
private static final MapleMonsterInformationProvider instance = new MapleMonsterInformationProvider();
protected MapleMonsterInformationProvider() {
retrieveGlobal();
}
public final List<MonsterGlobalDropEntry> getRelevantGlobalDrops(int mapid) {
int continentid = mapid / 100000000;
List<MonsterGlobalDropEntry> contiItems = continentdrops.get(continentid);
if (contiItems == null) { // continent separated global drops found thanks to marcuswoon
contiItems = new ArrayList<>();
for (MonsterGlobalDropEntry e : globaldrops) {
if (e.continentid < 0 || e.continentid == continentid) {
contiItems.add(e);
}
public static MapleMonsterInformationProvider getInstance() {
return instance;
}
private final Map<Integer, List<MonsterDropEntry>> drops = new HashMap<>();
private final List<MonsterGlobalDropEntry> globaldrops = new ArrayList<>();
private final Map<Integer, List<MonsterGlobalDropEntry>> continentdrops = new HashMap<>();
private final Map<Integer, List<Integer>> dropsChancePool = new HashMap<>(); // thanks to ronan
private final Set<Integer> hasNoMultiEquipDrops = new HashSet<>();
private final Map<Integer, List<MonsterDropEntry>> extraMultiEquipDrops = new HashMap<>();
private final Map<Pair<Integer, Integer>, Integer> mobAttackAnimationTime = new HashMap<>();
private final Map<MobSkill, Integer> mobSkillAnimationTime = new HashMap<>();
private final Map<Integer, Pair<Integer, Integer>> mobAttackInfo = new HashMap<>();
private final Map<Integer, Boolean> mobBossCache = new HashMap<>();
private final Map<Integer, String> mobNameCache = new HashMap<>();
protected MapleMonsterInformationProvider() {
retrieveGlobal();
}
public final List<MonsterGlobalDropEntry> getRelevantGlobalDrops(int mapid) {
int continentid = mapid / 100000000;
List<MonsterGlobalDropEntry> contiItems = continentdrops.get(continentid);
if (contiItems == null) { // continent separated global drops found thanks to marcuswoon
contiItems = new ArrayList<>();
for (MonsterGlobalDropEntry e : globaldrops) {
if (e.continentid < 0 || e.continentid == continentid) {
contiItems.add(e);
}
}
continentdrops.put(continentid, contiItems);
}
return contiItems;
}
private void retrieveGlobal() {
PreparedStatement ps = null;
ResultSet rs = null;
Connection con = null;
try {
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT * FROM drop_data_global WHERE chance > 0");
rs = ps.executeQuery();
while (rs.next()) {
globaldrops.add(
new MonsterGlobalDropEntry(
rs.getInt("itemid"),
rs.getInt("chance"),
rs.getByte("continent"),
rs.getInt("minimum_quantity"),
rs.getInt("maximum_quantity"),
rs.getShort("questid")));
}
rs.close();
ps.close();
con.close();
} catch (SQLException e) {
System.err.println("Error retrieving drop" + e);
} finally {
try {
if (ps != null && !ps.isClosed()) {
ps.close();
}
if (rs != null && !rs.isClosed()) {
rs.close();
}
if (con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException ignore) {
ignore.printStackTrace();
}
}
}
public List<MonsterDropEntry> retrieveEffectiveDrop(final int monsterId) {
// this reads the drop entries searching for multi-equip, properly processing them
List<MonsterDropEntry> list = retrieveDrop(monsterId);
if (hasNoMultiEquipDrops.contains(monsterId) || !ServerConstants.USE_MULTIPLE_SAME_EQUIP_DROP) {
return list;
}
List<MonsterDropEntry> multiDrops = extraMultiEquipDrops.get(monsterId), extra = new LinkedList<>();
if (multiDrops == null) {
multiDrops = new LinkedList<>();
for (MonsterDropEntry mde : list) {
if (ItemConstants.isEquipment(mde.itemId) && mde.Maximum > 1) {
multiDrops.add(mde);
int rnd = Randomizer.rand(mde.Minimum, mde.Maximum);
for (int i = 0; i < rnd - 1; i++) {
extra.add(mde); // this passes copies of the equips' MDE with min/max quantity > 1, but idc it'll be unused anyways
}
continentdrops.put(continentid, contiItems);
}
return contiItems;
}
}
private void retrieveGlobal() {
PreparedStatement ps = null;
ResultSet rs = null;
Connection con = null;
try {
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT * FROM drop_data_global WHERE chance > 0");
rs = ps.executeQuery();
while (rs.next()) {
globaldrops.add(
new MonsterGlobalDropEntry(
rs.getInt("itemid"),
rs.getInt("chance"),
rs.getByte("continent"),
rs.getInt("minimum_quantity"),
rs.getInt("maximum_quantity"),
rs.getShort("questid")));
}
rs.close();
ps.close();
con.close();
} catch (SQLException e) {
System.err.println("Error retrieving drop" + e);
} finally {
try {
if (ps != null && !ps.isClosed()) {
ps.close();
}
if (rs != null && !rs.isClosed()) {
rs.close();
}
if (con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException ignore) {
ignore.printStackTrace();
}
}
}
public List<MonsterDropEntry> retrieveEffectiveDrop(final int monsterId) {
// this reads the drop entries searching for multi-equip, properly processing them
List<MonsterDropEntry> list = retrieveDrop(monsterId);
if (hasNoMultiEquipDrops.contains(monsterId) || !ServerConstants.USE_MULTIPLE_SAME_EQUIP_DROP) {
return list;
}
List<MonsterDropEntry> multiDrops = extraMultiEquipDrops.get(monsterId), extra = new LinkedList<>();
if(multiDrops == null) {
multiDrops = new LinkedList<>();
for(MonsterDropEntry mde : list) {
if(ItemConstants.isEquipment(mde.itemId) && mde.Maximum > 1) {
multiDrops.add(mde);
int rnd = Randomizer.rand(mde.Minimum, mde.Maximum);
for(int i = 0; i < rnd - 1; i++) {
extra.add(mde); // this passes copies of the equips' MDE with min/max quantity > 1, but idc it'll be unused anyways
}
}
}
if(!multiDrops.isEmpty()) extraMultiEquipDrops.put(monsterId, multiDrops);
else hasNoMultiEquipDrops.add(monsterId);
} else {
for(MonsterDropEntry mde : multiDrops) {
int rnd = Randomizer.rand(mde.Minimum, mde.Maximum);
for(int i = 0; i < rnd - 1; i++) {
extra.add(mde);
}
}
if (!multiDrops.isEmpty()) {
extraMultiEquipDrops.put(monsterId, multiDrops);
} else {
hasNoMultiEquipDrops.add(monsterId);
}
} else {
for (MonsterDropEntry mde : multiDrops) {
int rnd = Randomizer.rand(mde.Minimum, mde.Maximum);
for (int i = 0; i < rnd - 1; i++) {
extra.add(mde);
}
List<MonsterDropEntry> ret = new LinkedList<>(list);
ret.addAll(extra);
}
}
List<MonsterDropEntry> ret = new LinkedList<>(list);
ret.addAll(extra);
return ret;
}
public final List<MonsterDropEntry> retrieveDrop(final int monsterId) {
if (drops.containsKey(monsterId)) {
return drops.get(monsterId);
}
final List<MonsterDropEntry> ret = new LinkedList<>();
if (monsterId >= 9300127 && monsterId <= 9300136 || monsterId >= 9300315 && monsterId <= 9300324) {
int dropArray[] = {2022157, 2022158, 2022159, 2022160, 2022161, 2022162, 2022163, 2022164, 2022165, 2022166, 2022167, 2022168, 2022169, 2022170, 2022171, 2022172, 2022173, 2022174, 2022175, 2022176, 2022177, 2022178, 4001129}; //These are the drops, -1 means meso :D
for (int id : dropArray) {
ret.add(new MonsterDropEntry(id, 2000, 1, 1, (short) 0));
}
} else {
PreparedStatement ps = null;
ResultSet rs = null;
Connection con = null;
try {
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT itemid, chance, minimum_quantity, maximum_quantity, questid FROM drop_data WHERE dropperid = ?");
ps.setInt(1, monsterId);
rs = ps.executeQuery();
while (rs.next()) {
ret.add(new MonsterDropEntry(rs.getInt("itemid"), rs.getInt("chance"), rs.getInt("minimum_quantity"), rs.getInt("maximum_quantity"), rs.getShort("questid")));
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
return ret;
}
public final List<MonsterDropEntry> retrieveDrop(final int monsterId) {
if (drops.containsKey(monsterId)) {
return drops.get(monsterId);
}
final List<MonsterDropEntry> ret = new LinkedList<>();
PreparedStatement ps = null;
ResultSet rs = null;
Connection con = null;
try {
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT itemid, chance, minimum_quantity, maximum_quantity, questid FROM drop_data WHERE dropperid = ?");
ps.setInt(1, monsterId);
rs = ps.executeQuery();
while (rs.next()) {
ret.add(
new MonsterDropEntry(
rs.getInt("itemid"),
rs.getInt("chance"),
rs.getInt("minimum_quantity"),
rs.getInt("maximum_quantity"),
rs.getShort("questid")));
}
} finally {
try {
if (ps != null && !ps.isClosed()) {
ps.close();
}
if (rs != null && !rs.isClosed()) {
rs.close();
}
if (con != null && !con.isClosed()) {
con.close();
} catch (SQLException e) {
e.printStackTrace();
return ret;
} finally {
try {
if (ps != null && !ps.isClosed()) {
ps.close();
}
if (rs != null && !rs.isClosed()) {
rs.close();
}
if (con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException ignore) {
ignore.printStackTrace();
return ret;
}
}
drops.put(monsterId, ret);
return ret;
}
public final List<Integer> retrieveDropPool(final int monsterId) { // ignores Quest and Party Quest items
if (dropsChancePool.containsKey(monsterId)) {
return dropsChancePool.get(monsterId);
}
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
List<MonsterDropEntry> dropList = retrieveDrop(monsterId);
List<Integer> ret = new ArrayList<>();
int accProp = 0;
for(MonsterDropEntry mde : dropList) {
if(!ii.isQuestItem(mde.itemId) && !ii.isPartyQuestItem(mde.itemId)) {
accProp += mde.chance;
}
ret.add(accProp);
}
} catch (SQLException ignore) {
ignore.printStackTrace();
return ret;
}
if(accProp == 0) ret.clear(); // don't accept mobs dropping no relevant items
dropsChancePool.put(monsterId, ret);
return ret;
}
public final void setMobAttackAnimationTime(int monsterId, int attackPos, int animationTime) {
mobAttackAnimationTime.put(new Pair<>(monsterId, attackPos), animationTime);
}
}
public final Integer getMobAttackAnimationTime(int monsterId, int attackPos) {
Integer time = mobAttackAnimationTime.get(new Pair<>(monsterId, attackPos));
return time == null ? 0 : time;
}
public final void setMobSkillAnimationTime(MobSkill skill, int animationTime) {
mobSkillAnimationTime.put(skill, animationTime);
}
public final Integer getMobSkillAnimationTime(MobSkill skill) {
Integer time = mobSkillAnimationTime.get(skill);
return time == null ? 0 : time;
}
public final void setMobAttackInfo(int monsterId, int attackPos, int mpCon, int coolTime) {
mobAttackInfo.put((monsterId << 3) + attackPos, new Pair<>(mpCon, coolTime));
}
public final Pair<Integer, Integer> getMobAttackInfo(int monsterId, int attackPos) {
if (attackPos < 0 || attackPos > 7) return null;
return mobAttackInfo.get((monsterId << 3) + attackPos);
drops.put(monsterId, ret);
return ret;
}
public final List<Integer> retrieveDropPool(final int monsterId) { // ignores Quest and Party Quest items
if (dropsChancePool.containsKey(monsterId)) {
return dropsChancePool.get(monsterId);
}
public static ArrayList<Pair<Integer, String>> getMobsIDsFromName(String search) {
MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File("wz/String.wz"));
ArrayList<Pair<Integer, String>> retMobs = new ArrayList<Pair<Integer, String>>();
MapleData data = dataProvider.getData("Mob.img");
List<Pair<Integer, String>> mobPairList = new LinkedList<Pair<Integer, String>>();
for (MapleData mobIdData : data.getChildren()) {
int mobIdFromData = Integer.parseInt(mobIdData.getName());
String mobNameFromData = MapleDataTool.getString(mobIdData.getChildByPath("name"), "NO-NAME");
mobPairList.add(new Pair<Integer, String>(mobIdFromData, mobNameFromData));
}
for (Pair<Integer, String> mobPair : mobPairList) {
if (mobPair.getRight().toLowerCase().contains(search.toLowerCase())) {
retMobs.add(mobPair);
}
}
return retMobs;
}
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
public boolean isBoss(int id) {
Boolean boss = mobBossCache.get(id);
if (boss == null) {
try {
boss = MapleLifeFactory.getMonster(id).isBoss();
} catch (NullPointerException npe) {
boss = false;
} catch (Exception e) { //nonexistant mob
boss = false;
e.printStackTrace();
System.err.println("Nonexistant mob id " + id);
}
mobBossCache.put(id, boss);
}
return boss;
}
public String getMobNameFromId(int id) {
String mobName = mobNameCache.get(id);
if (mobName == null) {
try
{
mobName = MapleLifeFactory.getMonster(id).getName();
}
catch (NullPointerException npe)
{
mobName = ""; //nonexistant mob
}
catch (Exception e)
{
e.printStackTrace();
System.err.println("Nonexistant mob id " + id);
mobName = ""; //nonexistant mob
}
mobNameCache.put(id, mobName);
}
return mobName;
}
List<MonsterDropEntry> dropList = retrieveDrop(monsterId);
List<Integer> ret = new ArrayList<>();
public final void clearDrops() {
drops.clear();
hasNoMultiEquipDrops.clear();
extraMultiEquipDrops.clear();
dropsChancePool.clear();
globaldrops.clear();
continentdrops.clear();
retrieveGlobal();
}
}
int accProp = 0;
for (MonsterDropEntry mde : dropList) {
if (!ii.isQuestItem(mde.itemId) && !ii.isPartyQuestItem(mde.itemId)) {
accProp += mde.chance;
}
ret.add(accProp);
}
if (accProp == 0) {
ret.clear(); // don't accept mobs dropping no relevant items
}
dropsChancePool.put(monsterId, ret);
return ret;
}
public final void setMobAttackAnimationTime(int monsterId, int attackPos, int animationTime) {
mobAttackAnimationTime.put(new Pair<>(monsterId, attackPos), animationTime);
}
public final Integer getMobAttackAnimationTime(int monsterId, int attackPos) {
Integer time = mobAttackAnimationTime.get(new Pair<>(monsterId, attackPos));
return time == null ? 0 : time;
}
public final void setMobSkillAnimationTime(MobSkill skill, int animationTime) {
mobSkillAnimationTime.put(skill, animationTime);
}
public final Integer getMobSkillAnimationTime(MobSkill skill) {
Integer time = mobSkillAnimationTime.get(skill);
return time == null ? 0 : time;
}
public final void setMobAttackInfo(int monsterId, int attackPos, int mpCon, int coolTime) {
mobAttackInfo.put((monsterId << 3) + attackPos, new Pair<>(mpCon, coolTime));
}
public final Pair<Integer, Integer> getMobAttackInfo(int monsterId, int attackPos) {
if (attackPos < 0 || attackPos > 7) {
return null;
}
return mobAttackInfo.get((monsterId << 3) + attackPos);
}
public static ArrayList<Pair<Integer, String>> getMobsIDsFromName(String search) {
MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File("wz/String.wz"));
ArrayList<Pair<Integer, String>> retMobs = new ArrayList<Pair<Integer, String>>();
MapleData data = dataProvider.getData("Mob.img");
List<Pair<Integer, String>> mobPairList = new LinkedList<Pair<Integer, String>>();
for (MapleData mobIdData : data.getChildren()) {
int mobIdFromData = Integer.parseInt(mobIdData.getName());
String mobNameFromData = MapleDataTool.getString(mobIdData.getChildByPath("name"), "NO-NAME");
mobPairList.add(new Pair<Integer, String>(mobIdFromData, mobNameFromData));
}
for (Pair<Integer, String> mobPair : mobPairList) {
if (mobPair.getRight().toLowerCase().contains(search.toLowerCase())) {
retMobs.add(mobPair);
}
}
return retMobs;
}
public boolean isBoss(int id) {
Boolean boss = mobBossCache.get(id);
if (boss == null) {
try {
boss = MapleLifeFactory.getMonster(id).isBoss();
} catch (NullPointerException npe) {
boss = false;
} catch (Exception e) { //nonexistant mob
boss = false;
e.printStackTrace();
System.err.println("Nonexistant mob id " + id);
}
mobBossCache.put(id, boss);
}
return boss;
}
public String getMobNameFromId(int id) {
String mobName = mobNameCache.get(id);
if (mobName == null) {
try {
mobName = MapleLifeFactory.getMonster(id).getName();
} catch (NullPointerException npe) {
mobName = ""; //nonexistant mob
} catch (Exception e) {
e.printStackTrace();
System.err.println("Nonexistant mob id " + id);
mobName = ""; //nonexistant mob
}
mobNameCache.put(id, mobName);
}
return mobName;
}
public final void clearDrops() {
drops.clear();
hasNoMultiEquipDrops.clear();
extraMultiEquipDrops.clear();
dropsChancePool.clear();
globaldrops.clear();
continentdrops.clear();
retrieveGlobal();
}
}