Switch to Maven file structure
This commit is contained in:
106
src/main/java/server/life/AbstractLoadedMapleLife.java
Normal file
106
src/main/java/server/life/AbstractLoadedMapleLife.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import server.maps.AbstractAnimatedMapleMapObject;
|
||||
|
||||
public abstract class AbstractLoadedMapleLife extends AbstractAnimatedMapleMapObject {
|
||||
private final int id;
|
||||
private int f;
|
||||
private boolean hide;
|
||||
private int fh;
|
||||
private int start_fh;
|
||||
private int cy;
|
||||
private int rx0;
|
||||
private int rx1;
|
||||
|
||||
public AbstractLoadedMapleLife(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public AbstractLoadedMapleLife(AbstractLoadedMapleLife life) {
|
||||
this(life.getId());
|
||||
this.f = life.f;
|
||||
this.hide = life.hide;
|
||||
this.fh = life.fh;
|
||||
this.start_fh = life.fh;
|
||||
this.cy = life.cy;
|
||||
this.rx0 = life.rx0;
|
||||
this.rx1 = life.rx1;
|
||||
}
|
||||
|
||||
public int getF() {
|
||||
return f;
|
||||
}
|
||||
|
||||
public void setF(int f) {
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return hide;
|
||||
}
|
||||
|
||||
public void setHide(boolean hide) {
|
||||
this.hide = hide;
|
||||
}
|
||||
|
||||
public int getFh() {
|
||||
return fh;
|
||||
}
|
||||
|
||||
public void setFh(int fh) {
|
||||
this.fh = fh;
|
||||
}
|
||||
|
||||
public int getStartFh() {
|
||||
return start_fh;
|
||||
}
|
||||
|
||||
public int getCy() {
|
||||
return cy;
|
||||
}
|
||||
|
||||
public void setCy(int cy) {
|
||||
this.cy = cy;
|
||||
}
|
||||
|
||||
public int getRx0() {
|
||||
return rx0;
|
||||
}
|
||||
|
||||
public void setRx0(int rx0) {
|
||||
this.rx0 = rx0;
|
||||
}
|
||||
|
||||
public int getRx1() {
|
||||
return rx1;
|
||||
}
|
||||
|
||||
public void setRx1(int rx1) {
|
||||
this.rx1 = rx1;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
54
src/main/java/server/life/ChangeableStats.java
Normal file
54
src/main/java/server/life/ChangeableStats.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 ~ 2010 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import constants.game.GameConstants;
|
||||
|
||||
public class ChangeableStats extends OverrideMonsterStats {
|
||||
|
||||
public int watk, matk, wdef, mdef, level;
|
||||
|
||||
public ChangeableStats(MapleMonsterStats stats, OverrideMonsterStats ostats) {
|
||||
hp = ostats.getHp();
|
||||
exp = ostats.getExp();
|
||||
mp = ostats.getMp();
|
||||
watk = stats.getPADamage();
|
||||
matk = stats.getMADamage();
|
||||
wdef = stats.getPDDamage();
|
||||
mdef = stats.getMDDamage();
|
||||
level = stats.getLevel();
|
||||
}
|
||||
|
||||
public ChangeableStats(MapleMonsterStats stats, int newLevel, boolean pqMob) { // here we go i think
|
||||
final double mod = (double) newLevel / (double) stats.getLevel();
|
||||
final double hpRatio = (double) stats.getHp() / (double) stats.getExp();
|
||||
final double pqMod = (pqMob ? 1.5 : 1.0); // god damn
|
||||
hp = Math.min((int) Math.round((!stats.isBoss() ? GameConstants.getMonsterHP(newLevel) : (stats.getHp() * mod)) * pqMod), Integer.MAX_VALUE); // right here lol
|
||||
exp = Math.min((int) Math.round((!stats.isBoss() ? (GameConstants.getMonsterHP(newLevel) / hpRatio) : (stats.getExp())) * pqMod), Integer.MAX_VALUE);
|
||||
mp = Math.min((int) Math.round(stats.getMp() * mod * pqMod), Integer.MAX_VALUE);
|
||||
watk = Math.min((int) Math.round(stats.getPADamage() * mod), Integer.MAX_VALUE);
|
||||
matk = Math.min((int) Math.round(stats.getMADamage() * mod), Integer.MAX_VALUE);
|
||||
wdef = Math.min(Math.min(stats.isBoss() ? 30 : 20, (int) Math.round(stats.getPDDamage() * mod)), Integer.MAX_VALUE);
|
||||
mdef = Math.min(Math.min(stats.isBoss() ? 30 : 20, (int) Math.round(stats.getMDDamage() * mod)), Integer.MAX_VALUE);
|
||||
level = newLevel;
|
||||
}
|
||||
|
||||
public ChangeableStats(MapleMonsterStats stats, float statModifier, boolean pqMob) {
|
||||
this(stats, (int)(statModifier * stats.getLevel()), pqMob);
|
||||
}
|
||||
}
|
||||
65
src/main/java/server/life/Element.java
Normal file
65
src/main/java/server/life/Element.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
public enum Element {
|
||||
NEUTRAL(0), PHYSICAL(1), FIRE(2, true), ICE(3, true), LIGHTING(4), POISON(5), HOLY(6, true), DARKNESS(7);
|
||||
|
||||
private int value;
|
||||
private boolean special = false;
|
||||
private Element(int v) {
|
||||
this.value = v;
|
||||
}
|
||||
|
||||
private Element(int v, boolean special) {
|
||||
this.value = v;
|
||||
this.special = special;
|
||||
}
|
||||
|
||||
public boolean isSpecial() {
|
||||
return special;
|
||||
}
|
||||
|
||||
public static Element getFromChar(char c) {
|
||||
switch (Character.toUpperCase(c)) {
|
||||
case 'F':
|
||||
return FIRE;
|
||||
case 'I':
|
||||
return ICE;
|
||||
case 'L':
|
||||
return LIGHTING;
|
||||
case 'S':
|
||||
return POISON;
|
||||
case 'H':
|
||||
return HOLY;
|
||||
case 'D':
|
||||
return DARKNESS;
|
||||
case 'P':
|
||||
return NEUTRAL;
|
||||
}
|
||||
throw new IllegalArgumentException("unknown elemnt char " + c);
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
41
src/main/java/server/life/ElementalEffectiveness.java
Normal file
41
src/main/java/server/life/ElementalEffectiveness.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
public enum ElementalEffectiveness {
|
||||
NORMAL, IMMUNE, STRONG, WEAK, NEUTRAL;
|
||||
|
||||
public static ElementalEffectiveness getByNumber(int num) {
|
||||
switch (num) {
|
||||
case 1:
|
||||
return IMMUNE;
|
||||
case 2:
|
||||
return STRONG;
|
||||
case 3:
|
||||
return WEAK;
|
||||
case 4:
|
||||
return NEUTRAL;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unkown effectiveness: " + num);
|
||||
}
|
||||
}
|
||||
}
|
||||
372
src/main/java/server/life/MapleLifeFactory.java
Normal file
372
src/main/java/server/life/MapleLifeFactory.java
Normal file
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import provider.MapleData;
|
||||
import provider.MapleDataProvider;
|
||||
import provider.MapleDataProviderFactory;
|
||||
import provider.MapleDataTool;
|
||||
import provider.wz.MapleDataType;
|
||||
import tools.Pair;
|
||||
import tools.StringUtil;
|
||||
|
||||
public class MapleLifeFactory {
|
||||
|
||||
private static MapleDataProvider data = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Mob.wz"));
|
||||
private final static MapleDataProvider stringDataWZ = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/String.wz"));
|
||||
private static MapleData mobStringData = stringDataWZ.getData("Mob.img");
|
||||
private static MapleData npcStringData = stringDataWZ.getData("Npc.img");
|
||||
private static Map<Integer, MapleMonsterStats> monsterStats = new HashMap<>();
|
||||
private static Set<Integer> hpbarBosses = getHpBarBosses();
|
||||
|
||||
private static Set<Integer> getHpBarBosses() {
|
||||
Set<Integer> ret = new HashSet<>();
|
||||
|
||||
MapleDataProvider uiDataWZ = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/UI.wz"));
|
||||
for (MapleData bossData : uiDataWZ.getData("UIWindow.img").getChildByPath("MobGage/Mob").getChildren()) {
|
||||
ret.add(Integer.valueOf(bossData.getName()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static AbstractLoadedMapleLife getLife(int id, String type) {
|
||||
if (type.equalsIgnoreCase("n")) {
|
||||
return getNPC(id);
|
||||
} else if (type.equalsIgnoreCase("m")) {
|
||||
return getMonster(id);
|
||||
} else {
|
||||
System.out.println("Unknown Life type: " + type);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MobAttackInfoHolder {
|
||||
protected int attackPos;
|
||||
protected int mpCon;
|
||||
protected int coolTime;
|
||||
protected int animationTime;
|
||||
|
||||
protected MobAttackInfoHolder(int attackPos, int mpCon, int coolTime, int animationTime) {
|
||||
this.attackPos = attackPos;
|
||||
this.mpCon = mpCon;
|
||||
this.coolTime = coolTime;
|
||||
this.animationTime = animationTime;
|
||||
}
|
||||
}
|
||||
|
||||
private static void setMonsterAttackInfo(int mid, List<MobAttackInfoHolder> attackInfos) {
|
||||
if (!attackInfos.isEmpty()) {
|
||||
MapleMonsterInformationProvider mi = MapleMonsterInformationProvider.getInstance();
|
||||
|
||||
for (MobAttackInfoHolder attackInfo : attackInfos) {
|
||||
mi.setMobAttackInfo(mid, attackInfo.attackPos, attackInfo.mpCon, attackInfo.coolTime);
|
||||
mi.setMobAttackAnimationTime(mid, attackInfo.attackPos, attackInfo.animationTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Pair<MapleMonsterStats, List<MobAttackInfoHolder>> getMonsterStats(int mid) {
|
||||
MapleData monsterData = data.getData(StringUtil.getLeftPaddedStr(Integer.toString(mid) + ".img", '0', 11));
|
||||
if (monsterData == null) {
|
||||
return null;
|
||||
}
|
||||
MapleData monsterInfoData = monsterData.getChildByPath("info");
|
||||
|
||||
List<MobAttackInfoHolder> attackInfos = new LinkedList<>();
|
||||
MapleMonsterStats stats = new MapleMonsterStats();
|
||||
|
||||
int linkMid = MapleDataTool.getIntConvert("link", monsterInfoData, 0);
|
||||
if (linkMid != 0) {
|
||||
Pair<MapleMonsterStats, List<MobAttackInfoHolder>> linkStats = getMonsterStats(linkMid);
|
||||
if (linkStats == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// thanks resinate for noticing non-propagable infos such as revives getting retrieved
|
||||
attackInfos.addAll(linkStats.getRight());
|
||||
}
|
||||
|
||||
stats.setHp(MapleDataTool.getIntConvert("maxHP", monsterInfoData));
|
||||
stats.setFriendly(MapleDataTool.getIntConvert("damagedByMob", monsterInfoData, stats.isFriendly() ? 1 : 0) == 1);
|
||||
stats.setPADamage(MapleDataTool.getIntConvert("PADamage", monsterInfoData));
|
||||
stats.setPDDamage(MapleDataTool.getIntConvert("PDDamage", monsterInfoData));
|
||||
stats.setMADamage(MapleDataTool.getIntConvert("MADamage", monsterInfoData));
|
||||
stats.setMDDamage(MapleDataTool.getIntConvert("MDDamage", monsterInfoData));
|
||||
stats.setMp(MapleDataTool.getIntConvert("maxMP", monsterInfoData, stats.getMp()));
|
||||
stats.setExp(MapleDataTool.getIntConvert("exp", monsterInfoData, stats.getExp()));
|
||||
stats.setLevel(MapleDataTool.getIntConvert("level", monsterInfoData));
|
||||
stats.setRemoveAfter(MapleDataTool.getIntConvert("removeAfter", monsterInfoData, stats.removeAfter()));
|
||||
stats.setBoss(MapleDataTool.getIntConvert("boss", monsterInfoData, stats.isBoss() ? 1 : 0) > 0);
|
||||
stats.setExplosiveReward(MapleDataTool.getIntConvert("explosiveReward", monsterInfoData, stats.isExplosiveReward() ? 1 : 0) > 0);
|
||||
stats.setFfaLoot(MapleDataTool.getIntConvert("publicReward", monsterInfoData, stats.isFfaLoot() ? 1 : 0) > 0);
|
||||
stats.setUndead(MapleDataTool.getIntConvert("undead", monsterInfoData, stats.isUndead() ? 1 : 0) > 0);
|
||||
stats.setName(MapleDataTool.getString(mid + "/name", mobStringData, "MISSINGNO"));
|
||||
stats.setBuffToGive(MapleDataTool.getIntConvert("buff", monsterInfoData, stats.getBuffToGive()));
|
||||
stats.setCP(MapleDataTool.getIntConvert("getCP", monsterInfoData, stats.getCP()));
|
||||
stats.setRemoveOnMiss(MapleDataTool.getIntConvert("removeOnMiss", monsterInfoData, stats.removeOnMiss() ? 1 : 0) > 0);
|
||||
|
||||
MapleData special = monsterInfoData.getChildByPath("coolDamage");
|
||||
if (special != null) {
|
||||
int coolDmg = MapleDataTool.getIntConvert("coolDamage", monsterInfoData);
|
||||
int coolProb = MapleDataTool.getIntConvert("coolDamageProb", monsterInfoData, 0);
|
||||
stats.setCool(new Pair<>(coolDmg, coolProb));
|
||||
}
|
||||
special = monsterInfoData.getChildByPath("loseItem");
|
||||
if (special != null) {
|
||||
for (MapleData liData : special.getChildren()) {
|
||||
stats.addLoseItem(new loseItem(MapleDataTool.getInt(liData.getChildByPath("id")), (byte) MapleDataTool.getInt(liData.getChildByPath("prop")), (byte) MapleDataTool.getInt(liData.getChildByPath("x"))));
|
||||
}
|
||||
}
|
||||
special = monsterInfoData.getChildByPath("selfDestruction");
|
||||
if (special != null) {
|
||||
stats.setSelfDestruction(new selfDestruction((byte) MapleDataTool.getInt(special.getChildByPath("action")), MapleDataTool.getIntConvert("removeAfter", special, -1), MapleDataTool.getIntConvert("hp", special, -1)));
|
||||
}
|
||||
MapleData firstAttackData = monsterInfoData.getChildByPath("firstAttack");
|
||||
int firstAttack = 0;
|
||||
if (firstAttackData != null) {
|
||||
if (firstAttackData.getType() == MapleDataType.FLOAT) {
|
||||
firstAttack = Math.round(MapleDataTool.getFloat(firstAttackData));
|
||||
} else {
|
||||
firstAttack = MapleDataTool.getInt(firstAttackData);
|
||||
}
|
||||
}
|
||||
stats.setFirstAttack(firstAttack > 0);
|
||||
stats.setDropPeriod(MapleDataTool.getIntConvert("dropItemPeriod", monsterInfoData, stats.getDropPeriod() / 10000) * 10000);
|
||||
|
||||
// thanks yuxaij, Riizade, Z1peR, Anesthetic for noticing some bosses crashing players due to missing requirements
|
||||
boolean hpbarBoss = stats.isBoss() && hpbarBosses.contains(mid);
|
||||
stats.setTagColor(hpbarBoss ? MapleDataTool.getIntConvert("hpTagColor", monsterInfoData, 0) : 0);
|
||||
stats.setTagBgColor(hpbarBoss ? MapleDataTool.getIntConvert("hpTagBgcolor", monsterInfoData, 0) : 0);
|
||||
|
||||
for (MapleData idata : monsterData) {
|
||||
if (!idata.getName().equals("info")) {
|
||||
int delay = 0;
|
||||
for (MapleData pic : idata.getChildren()) {
|
||||
delay += MapleDataTool.getIntConvert("delay", pic, 0);
|
||||
}
|
||||
stats.setAnimationTime(idata.getName(), delay);
|
||||
}
|
||||
}
|
||||
MapleData reviveInfo = monsterInfoData.getChildByPath("revive");
|
||||
if (reviveInfo != null) {
|
||||
List<Integer> revives = new LinkedList<>();
|
||||
for (MapleData data_ : reviveInfo) {
|
||||
revives.add(MapleDataTool.getInt(data_));
|
||||
}
|
||||
stats.setRevives(revives);
|
||||
}
|
||||
decodeElementalString(stats, MapleDataTool.getString("elemAttr", monsterInfoData, ""));
|
||||
|
||||
MapleMonsterInformationProvider mi = MapleMonsterInformationProvider.getInstance();
|
||||
MapleData monsterSkillInfoData = monsterInfoData.getChildByPath("skill");
|
||||
if (monsterSkillInfoData != null) {
|
||||
int i = 0;
|
||||
List<Pair<Integer, Integer>> skills = new ArrayList<>();
|
||||
while (monsterSkillInfoData.getChildByPath(Integer.toString(i)) != null) {
|
||||
int skillId = MapleDataTool.getInt(i + "/skill", monsterSkillInfoData, 0);
|
||||
int skillLv = MapleDataTool.getInt(i + "/level", monsterSkillInfoData, 0);
|
||||
skills.add(new Pair<>(skillId, skillLv));
|
||||
|
||||
MapleData monsterSkillData = monsterData.getChildByPath("skill" + (i + 1));
|
||||
if (monsterSkillData != null) {
|
||||
int animationTime = 0;
|
||||
for (MapleData effectEntry : monsterSkillData.getChildren()) {
|
||||
animationTime += MapleDataTool.getIntConvert("delay", effectEntry, 0);
|
||||
}
|
||||
|
||||
MobSkill skill = MobSkillFactory.getMobSkill(skillId, skillLv);
|
||||
mi.setMobSkillAnimationTime(skill, animationTime);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
stats.setSkills(skills);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
MapleData monsterAttackData;
|
||||
while ((monsterAttackData = monsterData.getChildByPath("attack" + (i + 1))) != null) {
|
||||
int animationTime = 0;
|
||||
for (MapleData effectEntry : monsterAttackData.getChildren()) {
|
||||
animationTime += MapleDataTool.getIntConvert("delay", effectEntry, 0);
|
||||
}
|
||||
|
||||
int mpCon = MapleDataTool.getIntConvert("info/conMP", monsterAttackData, 0);
|
||||
int coolTime = MapleDataTool.getIntConvert("info/attackAfter", monsterAttackData, 0);
|
||||
attackInfos.add(new MobAttackInfoHolder(i, mpCon, coolTime, animationTime));
|
||||
i++;
|
||||
}
|
||||
|
||||
MapleData banishData = monsterInfoData.getChildByPath("ban");
|
||||
if (banishData != null) {
|
||||
stats.setBanishInfo(new BanishInfo(MapleDataTool.getString("banMsg", banishData), MapleDataTool.getInt("banMap/0/field", banishData, -1), MapleDataTool.getString("banMap/0/portal", banishData, "sp")));
|
||||
}
|
||||
|
||||
int noFlip = MapleDataTool.getInt("noFlip", monsterInfoData, 0);
|
||||
if (noFlip > 0) {
|
||||
Point origin = MapleDataTool.getPoint("stand/0/origin", monsterData, null);
|
||||
if (origin != null) {
|
||||
stats.setFixedStance(origin.getX() < 1 ? 5 : 4); // fixed left/right
|
||||
}
|
||||
}
|
||||
|
||||
return new Pair<>(stats, attackInfos);
|
||||
}
|
||||
|
||||
public static MapleMonster getMonster(int mid) {
|
||||
try {
|
||||
MapleMonsterStats stats = monsterStats.get(Integer.valueOf(mid));
|
||||
if (stats == null) {
|
||||
Pair<MapleMonsterStats, List<MobAttackInfoHolder>> mobStats = getMonsterStats(mid);
|
||||
stats = mobStats.getLeft();
|
||||
setMonsterAttackInfo(mid, mobStats.getRight());
|
||||
|
||||
monsterStats.put(Integer.valueOf(mid), stats);
|
||||
}
|
||||
MapleMonster ret = new MapleMonster(mid, stats);
|
||||
return ret;
|
||||
} catch(NullPointerException npe) {
|
||||
System.out.println("[SEVERE] MOB " + mid + " failed to load. Issue: " + npe.getMessage() + "\n\n");
|
||||
npe.printStackTrace();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getMonsterLevel(int mid) {
|
||||
try {
|
||||
MapleMonsterStats stats = monsterStats.get(Integer.valueOf(mid));
|
||||
if (stats == null) {
|
||||
MapleData monsterData = data.getData(StringUtil.getLeftPaddedStr(Integer.toString(mid) + ".img", '0', 11));
|
||||
if (monsterData == null) {
|
||||
return -1;
|
||||
}
|
||||
MapleData monsterInfoData = monsterData.getChildByPath("info");
|
||||
return MapleDataTool.getIntConvert("level", monsterInfoData);
|
||||
} else {
|
||||
return stats.getLevel();
|
||||
}
|
||||
} catch(NullPointerException npe) {
|
||||
System.out.println("[SEVERE] MOB " + mid + " failed to load. Issue: " + npe.getMessage() + "\n\n");
|
||||
npe.printStackTrace();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static void decodeElementalString(MapleMonsterStats stats, String elemAttr) {
|
||||
for (int i = 0; i < elemAttr.length(); i += 2) {
|
||||
stats.setEffectiveness(Element.getFromChar(elemAttr.charAt(i)), ElementalEffectiveness.getByNumber(Integer.valueOf(String.valueOf(elemAttr.charAt(i + 1)))));
|
||||
}
|
||||
}
|
||||
|
||||
public static MapleNPC getNPC(int nid) {
|
||||
return new MapleNPC(nid, new MapleNPCStats(MapleDataTool.getString(nid + "/name", npcStringData, "MISSINGNO")));
|
||||
}
|
||||
|
||||
public static String getNPCDefaultTalk(int nid) {
|
||||
return MapleDataTool.getString(nid + "/d0", npcStringData, "(...)");
|
||||
}
|
||||
|
||||
public static class BanishInfo {
|
||||
|
||||
private int map;
|
||||
private String portal, msg;
|
||||
|
||||
public BanishInfo(String msg, int map, String portal) {
|
||||
this.msg = msg;
|
||||
this.map = map;
|
||||
this.portal = portal;
|
||||
}
|
||||
|
||||
public int getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public String getPortal() {
|
||||
return portal;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
public static class loseItem {
|
||||
|
||||
private int id;
|
||||
private byte chance, x;
|
||||
|
||||
private loseItem(int id, byte chance, byte x) {
|
||||
this.id = id;
|
||||
this.chance = chance;
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public byte getChance() {
|
||||
return chance;
|
||||
}
|
||||
|
||||
public byte getX() {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
public static class selfDestruction {
|
||||
|
||||
private byte action;
|
||||
private int removeAfter;
|
||||
private int hp;
|
||||
|
||||
private selfDestruction(byte action, int removeAfter, int hp) {
|
||||
this.action = action;
|
||||
this.removeAfter = removeAfter;
|
||||
this.hp = hp;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public byte getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public int removeAfter() {
|
||||
return removeAfter;
|
||||
}
|
||||
}
|
||||
}
|
||||
2269
src/main/java/server/life/MapleMonster.java
Normal file
2269
src/main/java/server/life/MapleMonster.java
Normal file
File diff suppressed because it is too large
Load Diff
338
src/main/java/server/life/MapleMonsterInformationProvider.java
Normal file
338
src/main/java/server/life/MapleMonsterInformationProvider.java
Normal file
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 ~ 2010 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import config.YamlConfig;
|
||||
import constants.inventory.ItemConstants;
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import provider.MapleData;
|
||||
import provider.MapleDataProvider;
|
||||
import provider.MapleDataProviderFactory;
|
||||
import provider.MapleDataTool;
|
||||
import server.MapleItemInformationProvider;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.Pair;
|
||||
import tools.Randomizer;
|
||||
|
||||
public class MapleMonsterInformationProvider {
|
||||
// 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<>();
|
||||
|
||||
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) || !YamlConfig.config.server.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 on equips they are 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<>();
|
||||
|
||||
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;
|
||||
} 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);
|
||||
}
|
||||
|
||||
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) {
|
||||
MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File("wz/String.wz"));
|
||||
MapleData mobData = dataProvider.getData("Mob.img");
|
||||
|
||||
mobName = MapleDataTool.getString(mobData.getChildByPath(id + "/name"), "");
|
||||
mobNameCache.put(id, mobName);
|
||||
}
|
||||
|
||||
return mobName;
|
||||
}
|
||||
|
||||
public final void clearDrops() {
|
||||
drops.clear();
|
||||
hasNoMultiEquipDrops.clear();
|
||||
extraMultiEquipDrops.clear();
|
||||
dropsChancePool.clear();
|
||||
globaldrops.clear();
|
||||
continentdrops.clear();
|
||||
retrieveGlobal();
|
||||
}
|
||||
}
|
||||
386
src/main/java/server/life/MapleMonsterStats.java
Normal file
386
src/main/java/server/life/MapleMonsterStats.java
Normal file
@@ -0,0 +1,386 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import server.life.MapleLifeFactory.BanishInfo;
|
||||
import server.life.MapleLifeFactory.loseItem;
|
||||
import server.life.MapleLifeFactory.selfDestruction;
|
||||
import tools.Pair;
|
||||
|
||||
/**
|
||||
* @author Frz
|
||||
*/
|
||||
public class MapleMonsterStats {
|
||||
public boolean changeable;
|
||||
public int exp, hp, mp, level, PADamage, PDDamage, MADamage, MDDamage, dropPeriod, cp, buffToGive = -1, removeAfter;
|
||||
public boolean boss, undead, ffaLoot, isExplosiveReward, firstAttack, removeOnMiss;
|
||||
public String name;
|
||||
public Map<String, Integer> animationTimes = new HashMap<String, Integer>();
|
||||
public Map<Element, ElementalEffectiveness> resistance = new HashMap<Element, ElementalEffectiveness>();
|
||||
public List<Integer> revives = Collections.emptyList();
|
||||
public byte tagColor, tagBgColor;
|
||||
public List<Pair<Integer, Integer>> skills = new ArrayList<Pair<Integer, Integer>>();
|
||||
public Pair<Integer, Integer> cool = null;
|
||||
public BanishInfo banish = null;
|
||||
public List<loseItem> loseItem = null;
|
||||
public selfDestruction selfDestruction = null;
|
||||
public int fixedStance = 0;
|
||||
public boolean friendly;
|
||||
|
||||
public void setChange(boolean change) {
|
||||
this.changeable = change;
|
||||
}
|
||||
|
||||
public boolean isChangeable() {
|
||||
return changeable;
|
||||
}
|
||||
|
||||
public int getExp() {
|
||||
return exp;
|
||||
}
|
||||
|
||||
public void setExp(int exp) {
|
||||
this.exp = exp;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public void setHp(int hp) {
|
||||
this.hp = hp;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
public void setMp(int mp) {
|
||||
this.mp = mp;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public int removeAfter() {
|
||||
return removeAfter;
|
||||
}
|
||||
|
||||
public void setRemoveAfter(int removeAfter) {
|
||||
this.removeAfter = removeAfter;
|
||||
}
|
||||
|
||||
public int getDropPeriod() {
|
||||
return dropPeriod;
|
||||
}
|
||||
|
||||
public void setDropPeriod(int dropPeriod) {
|
||||
this.dropPeriod = dropPeriod;
|
||||
}
|
||||
|
||||
public void setBoss(boolean boss) {
|
||||
this.boss = boss;
|
||||
}
|
||||
|
||||
public boolean isBoss() {
|
||||
return boss;
|
||||
}
|
||||
|
||||
public void setFfaLoot(boolean ffaLoot) {
|
||||
this.ffaLoot = ffaLoot;
|
||||
}
|
||||
|
||||
public boolean isFfaLoot() {
|
||||
return ffaLoot;
|
||||
}
|
||||
|
||||
public void setAnimationTime(String name, int delay) {
|
||||
animationTimes.put(name, delay);
|
||||
}
|
||||
|
||||
public int getAnimationTime(String name) {
|
||||
Integer ret = animationTimes.get(name);
|
||||
if (ret == null) {
|
||||
return 500;
|
||||
}
|
||||
return ret.intValue();
|
||||
}
|
||||
|
||||
public boolean isMobile() {
|
||||
return animationTimes.containsKey("move") || animationTimes.containsKey("fly");
|
||||
}
|
||||
|
||||
public List<Integer> getRevives() {
|
||||
return revives;
|
||||
}
|
||||
|
||||
public void setRevives(List<Integer> revives) {
|
||||
this.revives = revives;
|
||||
}
|
||||
|
||||
public void setUndead(boolean undead) {
|
||||
this.undead = undead;
|
||||
}
|
||||
|
||||
public boolean isUndead() {
|
||||
return undead;
|
||||
}
|
||||
|
||||
public void setEffectiveness(Element e, ElementalEffectiveness ee) {
|
||||
resistance.put(e, ee);
|
||||
}
|
||||
|
||||
public ElementalEffectiveness getEffectiveness(Element e) {
|
||||
ElementalEffectiveness elementalEffectiveness = resistance.get(e);
|
||||
if (elementalEffectiveness == null) {
|
||||
return ElementalEffectiveness.NORMAL;
|
||||
} else {
|
||||
return elementalEffectiveness;
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public byte getTagColor() {
|
||||
return tagColor;
|
||||
}
|
||||
|
||||
public void setTagColor(int tagColor) {
|
||||
this.tagColor = (byte) tagColor;
|
||||
}
|
||||
|
||||
public byte getTagBgColor() {
|
||||
return tagBgColor;
|
||||
}
|
||||
|
||||
public void setTagBgColor(int tagBgColor) {
|
||||
this.tagBgColor = (byte) tagBgColor;
|
||||
}
|
||||
|
||||
public void setSkills(List<Pair<Integer, Integer>> skills) {
|
||||
for (int i = this.skills.size(); i < skills.size(); i++) {
|
||||
this.skills.add(null);
|
||||
}
|
||||
|
||||
for (int i = 0; i < skills.size(); i++) {
|
||||
this.skills.set(i, skills.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public List<Pair<Integer, Integer>> getSkills() {
|
||||
return Collections.unmodifiableList(this.skills);
|
||||
}
|
||||
|
||||
public int getNoSkills() {
|
||||
return this.skills.size();
|
||||
}
|
||||
|
||||
public boolean hasSkill(int skillId, int level) {
|
||||
for (Pair<Integer, Integer> skill : skills) {
|
||||
if (skill.getLeft() == skillId && skill.getRight() == level) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setFirstAttack(boolean firstAttack) {
|
||||
this.firstAttack = firstAttack;
|
||||
}
|
||||
|
||||
public boolean isFirstAttack() {
|
||||
return firstAttack;
|
||||
}
|
||||
|
||||
public void setBuffToGive(int buff) {
|
||||
this.buffToGive = buff;
|
||||
}
|
||||
|
||||
public int getBuffToGive() {
|
||||
return buffToGive;
|
||||
}
|
||||
|
||||
void removeEffectiveness(Element e) {
|
||||
resistance.remove(e);
|
||||
}
|
||||
|
||||
public BanishInfo getBanishInfo() {
|
||||
return banish;
|
||||
}
|
||||
|
||||
public void setBanishInfo(BanishInfo banish) {
|
||||
this.banish = banish;
|
||||
}
|
||||
|
||||
public int getPADamage() {
|
||||
return PADamage;
|
||||
}
|
||||
|
||||
public void setPADamage(int PADamage) {
|
||||
this.PADamage = PADamage;
|
||||
}
|
||||
|
||||
public int getCP() {
|
||||
return cp;
|
||||
}
|
||||
|
||||
public void setCP(int cp) {
|
||||
this.cp = cp;
|
||||
}
|
||||
|
||||
public List<loseItem> loseItem() {
|
||||
return loseItem;
|
||||
}
|
||||
|
||||
public void addLoseItem(loseItem li) {
|
||||
if (loseItem == null) {
|
||||
loseItem = new LinkedList<loseItem>();
|
||||
}
|
||||
loseItem.add(li);
|
||||
}
|
||||
|
||||
public selfDestruction selfDestruction() {
|
||||
return selfDestruction;
|
||||
}
|
||||
|
||||
public void setSelfDestruction(selfDestruction sd) {
|
||||
this.selfDestruction = sd;
|
||||
}
|
||||
|
||||
public void setExplosiveReward(boolean isExplosiveReward) {
|
||||
this.isExplosiveReward = isExplosiveReward;
|
||||
}
|
||||
|
||||
public boolean isExplosiveReward() {
|
||||
return isExplosiveReward;
|
||||
}
|
||||
|
||||
public void setRemoveOnMiss(boolean removeOnMiss) {
|
||||
this.removeOnMiss = removeOnMiss;
|
||||
}
|
||||
|
||||
public boolean removeOnMiss() {
|
||||
return removeOnMiss;
|
||||
}
|
||||
|
||||
public void setCool(Pair<Integer, Integer> cool) {
|
||||
this.cool = cool;
|
||||
}
|
||||
|
||||
public Pair<Integer, Integer> getCool() {
|
||||
return cool;
|
||||
}
|
||||
|
||||
public int getPDDamage() {
|
||||
return PDDamage;
|
||||
}
|
||||
|
||||
public int getMADamage() {
|
||||
return MADamage;
|
||||
}
|
||||
|
||||
public int getMDDamage() {
|
||||
return MDDamage;
|
||||
}
|
||||
|
||||
public boolean isFriendly() {
|
||||
return friendly;
|
||||
}
|
||||
|
||||
public void setFriendly(boolean value) {
|
||||
this.friendly = value;
|
||||
}
|
||||
|
||||
public void setPDDamage(int PDDamage) {
|
||||
this.PDDamage = PDDamage;
|
||||
}
|
||||
|
||||
public void setMADamage(int MADamage) {
|
||||
this.MADamage = MADamage;
|
||||
}
|
||||
|
||||
public void setMDDamage(int MDDamage) {
|
||||
this.MDDamage = MDDamage;
|
||||
}
|
||||
|
||||
public int getFixedStance() {
|
||||
return this.fixedStance;
|
||||
}
|
||||
|
||||
public void setFixedStance(int stance) {
|
||||
this.fixedStance = stance;
|
||||
}
|
||||
|
||||
public MapleMonsterStats copy() {
|
||||
MapleMonsterStats copy = new MapleMonsterStats();
|
||||
try {
|
||||
FieldCopyUtil.setFields(this, copy);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
// FieldCopyUtil src: http://www.codesenior.com/en/tutorial/Java-Copy-Fields-From-One-Object-to-Another-Object-with-Reflection
|
||||
private static class FieldCopyUtil { // thanks to Codesenior dev team
|
||||
private static void setFields(Object from, Object to) {
|
||||
Field[] fields = from.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
try {
|
||||
Field fieldFrom = from.getClass().getDeclaredField(field.getName());
|
||||
Object value = fieldFrom.get(from);
|
||||
to.getClass().getDeclaredField(field.getName()).set(to, value);
|
||||
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
65
src/main/java/server/life/MapleNPC.java
Normal file
65
src/main/java/server/life/MapleNPC.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import client.MapleClient;
|
||||
import server.MapleShopFactory;
|
||||
import server.maps.MapleMapObjectType;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
public class MapleNPC extends AbstractLoadedMapleLife {
|
||||
private MapleNPCStats stats;
|
||||
|
||||
public MapleNPC(int id, MapleNPCStats stats) {
|
||||
super(id);
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
public boolean hasShop() {
|
||||
return MapleShopFactory.getInstance().getShopForNPC(getId()) != null;
|
||||
}
|
||||
|
||||
public void sendShop(MapleClient c) {
|
||||
MapleShopFactory.getInstance().getShopForNPC(getId()).sendShop(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSpawnData(MapleClient client) {
|
||||
client.announce(MaplePacketCreator.spawnNPC(this));
|
||||
client.announce(MaplePacketCreator.spawnNPCRequestController(this, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendDestroyData(MapleClient client) {
|
||||
client.announce(MaplePacketCreator.removeNPCController(getObjectId()));
|
||||
client.announce(MaplePacketCreator.removeNPC(getObjectId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapleMapObjectType getType() {
|
||||
return MapleMapObjectType.NPC;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return stats.getName();
|
||||
}
|
||||
}
|
||||
42
src/main/java/server/life/MapleNPCStats.java
Normal file
42
src/main/java/server/life/MapleNPCStats.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Matze
|
||||
*/
|
||||
public class MapleNPCStats {
|
||||
private String name;
|
||||
|
||||
public MapleNPCStats(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
680
src/main/java/server/life/MaplePlayerNPC.java
Normal file
680
src/main/java/server/life/MaplePlayerNPC.java
Normal file
@@ -0,0 +1,680 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import config.YamlConfig;
|
||||
import server.life.positioner.MaplePlayerNPCPositioner;
|
||||
import server.life.positioner.MaplePlayerNPCPodium;
|
||||
import java.awt.Point;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.inventory.Item;
|
||||
import client.inventory.MapleInventoryType;
|
||||
import constants.game.GameConstants;
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.world.World;
|
||||
import server.maps.AbstractMapleMapObject;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMapObject;
|
||||
import server.maps.MapleMapObjectType;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.Pair;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author XoticStory
|
||||
* @author Ronan
|
||||
*/
|
||||
public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
private static final Map<Byte, List<Integer>> availablePlayerNpcScriptIds = new HashMap<>();
|
||||
private static final AtomicInteger runningOverallRank = new AtomicInteger();
|
||||
private static final List<AtomicInteger> runningWorldRank = new ArrayList<>();
|
||||
private static final Map<Pair<Integer, Integer>, AtomicInteger> runningWorldJobRank = new HashMap<>();
|
||||
|
||||
private Map<Short, Integer> equips = new HashMap<>();
|
||||
private int scriptId, face, hair, gender, job;
|
||||
private byte skin;
|
||||
private String name = "";
|
||||
private int dir, FH, RX0, RX1, CY;
|
||||
private int worldRank, overallRank, worldJobRank, overallJobRank;
|
||||
|
||||
static {
|
||||
getRunningMetadata();
|
||||
}
|
||||
|
||||
public MaplePlayerNPC(String name, int scriptId, int face, int hair, int gender, byte skin, Map<Short, Integer> equips, int dir, int FH, int RX0, int RX1, int CX, int CY, int oid) {
|
||||
this.equips = equips;
|
||||
this.scriptId = scriptId;
|
||||
this.face = face;
|
||||
this.hair = hair;
|
||||
this.gender = gender;
|
||||
this.skin = skin;
|
||||
this.name = name;
|
||||
this.dir = dir;
|
||||
this.FH = FH;
|
||||
this.RX0 = RX0;
|
||||
this.RX1 = RX1;
|
||||
this.CY = CY;
|
||||
this.job = 7777; // supposed to be developer
|
||||
|
||||
setPosition(new Point(CX, CY));
|
||||
setObjectId(oid);
|
||||
}
|
||||
|
||||
public MaplePlayerNPC(ResultSet rs) {
|
||||
try {
|
||||
CY = rs.getInt("cy");
|
||||
name = rs.getString("name");
|
||||
hair = rs.getInt("hair");
|
||||
face = rs.getInt("face");
|
||||
skin = rs.getByte("skin");
|
||||
gender = rs.getInt("gender");
|
||||
dir = rs.getInt("dir");
|
||||
FH = rs.getInt("fh");
|
||||
RX0 = rs.getInt("rx0");
|
||||
RX1 = rs.getInt("rx1");
|
||||
scriptId = rs.getInt("scriptid");
|
||||
|
||||
worldRank = rs.getInt("worldrank");
|
||||
overallRank = rs.getInt("overallrank");
|
||||
worldJobRank = rs.getInt("worldjobrank");
|
||||
overallJobRank = GameConstants.getOverallJobRankByScriptId(scriptId);
|
||||
job = rs.getInt("job");
|
||||
|
||||
setPosition(new Point(rs.getInt("x"), CY));
|
||||
setObjectId(rs.getInt("id"));
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT equippos, equipid FROM playernpcs_equip WHERE npcid = ?");
|
||||
ps.setInt(1, rs.getInt("id"));
|
||||
ResultSet rs2 = ps.executeQuery();
|
||||
while (rs2.next()) {
|
||||
equips.put(rs2.getShort("equippos"), rs2.getInt("equipid"));
|
||||
}
|
||||
rs2.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Short, Integer> getEquips() {
|
||||
return equips;
|
||||
}
|
||||
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
}
|
||||
|
||||
public int getJob() {
|
||||
return job;
|
||||
}
|
||||
|
||||
public int getDirection() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
public int getFH() {
|
||||
return FH;
|
||||
}
|
||||
|
||||
public int getRX0() {
|
||||
return RX0;
|
||||
}
|
||||
|
||||
public int getRX1() {
|
||||
return RX1;
|
||||
}
|
||||
|
||||
public int getCY() {
|
||||
return CY;
|
||||
}
|
||||
|
||||
public byte getSkin() {
|
||||
return skin;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getFace() {
|
||||
return face;
|
||||
}
|
||||
|
||||
public int getHair() {
|
||||
return hair;
|
||||
}
|
||||
|
||||
public int getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public int getWorldRank() {
|
||||
return worldRank;
|
||||
}
|
||||
|
||||
public int getOverallRank() {
|
||||
return overallRank;
|
||||
}
|
||||
|
||||
public int getWorldJobRank() {
|
||||
return worldJobRank;
|
||||
}
|
||||
|
||||
public int getOverallJobRank() {
|
||||
return overallJobRank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapleMapObjectType getType() {
|
||||
return MapleMapObjectType.PLAYER_NPC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSpawnData(MapleClient client) {
|
||||
client.announce(MaplePacketCreator.spawnPlayerNPC(this));
|
||||
client.announce(MaplePacketCreator.getPlayerNPC(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendDestroyData(MapleClient client) {
|
||||
client.announce(MaplePacketCreator.removeNPCController(this.getObjectId()));
|
||||
client.announce(MaplePacketCreator.removePlayerNPC(this.getObjectId()));
|
||||
}
|
||||
|
||||
private static void getRunningMetadata() {
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
|
||||
getRunningOverallRanks(con);
|
||||
getRunningWorldRanks(con);
|
||||
getRunningWorldJobRanks(con);
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void getRunningOverallRanks(Connection con) throws SQLException {
|
||||
PreparedStatement ps = con.prepareStatement("SELECT max(overallrank) FROM playernpcs");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
if(rs.next()) {
|
||||
runningOverallRank.set(rs.getInt(1) + 1);
|
||||
} else {
|
||||
runningOverallRank.set(1);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
private static void getRunningWorldRanks(Connection con) throws SQLException {
|
||||
int numWorlds = Server.getInstance().getWorldsSize();
|
||||
for(int i = 0; i < numWorlds; i++) {
|
||||
runningWorldRank.add(new AtomicInteger(1));
|
||||
}
|
||||
|
||||
PreparedStatement ps = con.prepareStatement("SELECT world, max(worldrank) FROM playernpcs GROUP BY world ORDER BY world");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
while(rs.next()) {
|
||||
int wid = rs.getInt(1);
|
||||
if(wid < numWorlds) {
|
||||
runningWorldRank.get(wid).set(rs.getInt(2) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
private static void getRunningWorldJobRanks(Connection con) throws SQLException {
|
||||
PreparedStatement ps = con.prepareStatement("SELECT world, job, max(worldjobrank) FROM playernpcs GROUP BY world, job ORDER BY world, job");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
while(rs.next()) {
|
||||
runningWorldJobRank.put(new Pair<>(rs.getInt(1), rs.getInt(2)), new AtomicInteger(rs.getInt(3) + 1));
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
private static int getAndIncrementRunningWorldJobRanks(int world, int job) {
|
||||
AtomicInteger wjr = runningWorldJobRank.get(new Pair<>(world, job));
|
||||
if(wjr == null) {
|
||||
wjr = new AtomicInteger(1);
|
||||
runningWorldJobRank.put(new Pair<>(world, job), wjr);
|
||||
}
|
||||
|
||||
return wjr.getAndIncrement();
|
||||
}
|
||||
|
||||
public static boolean canSpawnPlayerNpc(String name, int mapid) {
|
||||
boolean ret = true;
|
||||
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT name FROM playernpcs WHERE name LIKE ? AND map = ?");
|
||||
ps.setString(1, name);
|
||||
ps.setInt(2, mapid);
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(rs.next()) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void updatePlayerNPCPosition(MapleMap map, Point newPos) {
|
||||
setPosition(newPos);
|
||||
RX0 = newPos.x + 50;
|
||||
RX1 = newPos.x - 50;
|
||||
CY = newPos.y;
|
||||
FH = map.getFootholds().findBelow(newPos).getId();
|
||||
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE playernpcs SET x = ?, cy = ?, fh = ?, rx0 = ?, rx1 = ? WHERE id = ?");
|
||||
ps.setInt(1, newPos.x);
|
||||
ps.setInt(2, CY);
|
||||
ps.setInt(3, FH);
|
||||
ps.setInt(4, RX0);
|
||||
ps.setInt(5, RX1);
|
||||
ps.setInt(6, getObjectId());
|
||||
ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void fetchAvailableScriptIdsFromDb(byte branch, List<Integer> list) {
|
||||
try {
|
||||
int branchLen = (branch < 26) ? 100 : 400;
|
||||
int branchSid = 9900000 + (branch * 100);
|
||||
int nextBranchSid = branchSid + branchLen;
|
||||
Set<Integer> usedScriptIds = new HashSet<>();
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT scriptid FROM playernpcs WHERE scriptid >= ? AND scriptid < ? ORDER BY scriptid");
|
||||
ps.setInt(1, branchSid);
|
||||
ps.setInt(2, nextBranchSid);
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while(rs.next()) {
|
||||
usedScriptIds.add(rs.getInt(1));
|
||||
}
|
||||
|
||||
List<Integer> availables = new ArrayList<>(20);
|
||||
int j = 0;
|
||||
for(int i = branchSid; i < nextBranchSid; i++) {
|
||||
if(!usedScriptIds.contains(i)) {
|
||||
if (MaplePlayerNPCFactory.isExistentScriptid(i)) { // thanks Ark, Zein, geno, Ariel, JrCl0wn for noticing client crashes due to use of missing scriptids
|
||||
availables.add(i);
|
||||
j++;
|
||||
|
||||
if(j == 20) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break; // after this point no more scriptids expected...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
|
||||
for(int i = availables.size() - 1; i >= 0; i--) {
|
||||
list.add(availables.get(i));
|
||||
}
|
||||
} catch(SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static int getNextScriptId(byte branch) {
|
||||
List<Integer> availablesBranch = availablePlayerNpcScriptIds.get(branch);
|
||||
|
||||
if(availablesBranch == null) {
|
||||
availablesBranch = new ArrayList<>(20);
|
||||
availablePlayerNpcScriptIds.put(branch, availablesBranch);
|
||||
}
|
||||
|
||||
if(availablesBranch.isEmpty()) {
|
||||
fetchAvailableScriptIdsFromDb(branch, availablesBranch);
|
||||
|
||||
if(availablesBranch.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return availablesBranch.remove(availablesBranch.size() - 1);
|
||||
}
|
||||
|
||||
private static MaplePlayerNPC createPlayerNPCInternal(MapleMap map, Point pos, MapleCharacter chr) {
|
||||
int mapId = map.getId();
|
||||
|
||||
if(!canSpawnPlayerNpc(chr.getName(), mapId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
byte branch = GameConstants.getHallOfFameBranch(chr.getJob(), mapId);
|
||||
|
||||
int scriptId = getNextScriptId(branch);
|
||||
if (scriptId == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(pos == null) {
|
||||
if(GameConstants.isPodiumHallOfFameMap(map.getId())) {
|
||||
pos = MaplePlayerNPCPodium.getNextPlayerNpcPosition(map);
|
||||
} else {
|
||||
pos = MaplePlayerNPCPositioner.getNextPlayerNpcPosition(map);
|
||||
}
|
||||
|
||||
if(pos == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if(YamlConfig.config.server.USE_DEBUG) System.out.println("GOT SID " + scriptId + " POS " + pos);
|
||||
|
||||
int worldId = chr.getWorld();
|
||||
int jobId = (chr.getJob().getId() / 100) * 100;
|
||||
|
||||
MaplePlayerNPC ret;
|
||||
int npcId;
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs WHERE scriptid = ?");
|
||||
ps.setInt(1, scriptId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (!rs.next()) { // creates new playernpc if scriptid doesn't exist
|
||||
rs.close();
|
||||
ps.close();
|
||||
|
||||
ps = con.prepareStatement("INSERT INTO playernpcs (name, hair, face, skin, gender, x, cy, world, map, scriptid, dir, fh, rx0, rx1, worldrank, overallrank, worldjobrank, job) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
|
||||
ps.setString(1, chr.getName());
|
||||
ps.setInt(2, chr.getHair());
|
||||
ps.setInt(3, chr.getFace());
|
||||
ps.setInt(4, chr.getSkinColor().getId());
|
||||
ps.setInt(5, chr.getGender());
|
||||
ps.setInt(6, pos.x);
|
||||
ps.setInt(7, pos.y);
|
||||
ps.setInt(8, worldId);
|
||||
ps.setInt(9, mapId);
|
||||
ps.setInt(10, scriptId);
|
||||
ps.setInt(11, 1); // default direction
|
||||
ps.setInt(12, map.getFootholds().findBelow(pos).getId());
|
||||
ps.setInt(13, pos.x + 50);
|
||||
ps.setInt(14, pos.x - 50);
|
||||
ps.setInt(15, runningWorldRank.get(worldId).getAndIncrement());
|
||||
ps.setInt(16, runningOverallRank.getAndIncrement());
|
||||
ps.setInt(17, getAndIncrementRunningWorldJobRanks(worldId, jobId));
|
||||
ps.setInt(18, jobId);
|
||||
|
||||
ps.executeUpdate();
|
||||
|
||||
rs = ps.getGeneratedKeys();
|
||||
rs.next();
|
||||
npcId = rs.getInt(1);
|
||||
rs.close();
|
||||
ps.close();
|
||||
|
||||
ps = con.prepareStatement("INSERT INTO playernpcs_equip (npcid, equipid, equippos) VALUES (?, ?, ?)");
|
||||
ps.setInt(1, npcId);
|
||||
for (Item equip : chr.getInventory(MapleInventoryType.EQUIPPED)) {
|
||||
int position = Math.abs(equip.getPosition());
|
||||
if ((position < 12 && position > 0) || (position > 100 && position < 112)) {
|
||||
ps.setInt(2, equip.getItemId());
|
||||
ps.setInt(3, equip.getPosition());
|
||||
ps.addBatch();
|
||||
}
|
||||
}
|
||||
ps.executeBatch();
|
||||
ps.close();
|
||||
|
||||
ps = con.prepareStatement("SELECT * FROM playernpcs WHERE id = ?");
|
||||
ps.setInt(1, npcId);
|
||||
rs = ps.executeQuery();
|
||||
|
||||
rs.next();
|
||||
ret = new MaplePlayerNPC(rs);
|
||||
} else {
|
||||
ret = null;
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
|
||||
return ret;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Integer> removePlayerNPCInternal(MapleMap map, MapleCharacter chr) {
|
||||
Set<Integer> updateMapids = new HashSet<>();
|
||||
|
||||
List<Integer> mapids = new LinkedList<>();
|
||||
mapids.add(chr.getWorld());
|
||||
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT id, map FROM playernpcs WHERE name LIKE ?" + (map != null ? " AND map = ?" : ""));
|
||||
ps.setString(1, chr.getName());
|
||||
if(map != null) ps.setInt(2, map.getId());
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while(rs.next()) {
|
||||
updateMapids.add(rs.getInt("map"));
|
||||
int npcId = rs.getInt("id");
|
||||
|
||||
PreparedStatement ps2 = con.prepareStatement("DELETE FROM playernpcs WHERE id = ?");
|
||||
ps2.setInt(1, npcId);
|
||||
ps2.executeUpdate();
|
||||
ps2.close();
|
||||
|
||||
ps2 = con.prepareStatement("DELETE FROM playernpcs_equip WHERE npcid = ?");
|
||||
ps2.setInt(1, npcId);
|
||||
ps2.executeUpdate();
|
||||
ps2.close();
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(Integer i : updateMapids) {
|
||||
mapids.add(i);
|
||||
}
|
||||
|
||||
return mapids;
|
||||
}
|
||||
|
||||
private static synchronized Pair<MaplePlayerNPC, List<Integer>> processPlayerNPCInternal(MapleMap map, Point pos, MapleCharacter chr, boolean create) {
|
||||
if(create) {
|
||||
return new Pair<>(createPlayerNPCInternal(map, pos, chr), null);
|
||||
} else {
|
||||
return new Pair<>(null, removePlayerNPCInternal(map, chr));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean spawnPlayerNPC(int mapid, MapleCharacter chr) {
|
||||
return spawnPlayerNPC(mapid, null, chr);
|
||||
}
|
||||
|
||||
public static boolean spawnPlayerNPC(int mapid, Point pos, MapleCharacter chr) {
|
||||
if(chr == null) return false;
|
||||
|
||||
MaplePlayerNPC pn = processPlayerNPCInternal(chr.getClient().getChannelServer().getMapFactory().getMap(mapid), pos, chr, true).getLeft();
|
||||
if(pn != null) {
|
||||
for (Channel channel : Server.getInstance().getChannelsFromWorld(chr.getWorld())) {
|
||||
MapleMap m = channel.getMapFactory().getMap(mapid);
|
||||
|
||||
m.addPlayerNPCMapObject(pn);
|
||||
m.broadcastMessage(MaplePacketCreator.spawnPlayerNPC(pn));
|
||||
m.broadcastMessage(MaplePacketCreator.getPlayerNPC(pn));
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static MaplePlayerNPC getPlayerNPCFromWorldMap(String name, int world, int map) {
|
||||
World wserv = Server.getInstance().getWorld(world);
|
||||
for(MapleMapObject pnpcObj : wserv.getChannel(1).getMapFactory().getMap(map).getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC))) {
|
||||
MaplePlayerNPC pn = (MaplePlayerNPC) pnpcObj;
|
||||
|
||||
if(name.contentEquals(pn.getName()) && pn.getScriptId() < 9977777) {
|
||||
return pn;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void removePlayerNPC(MapleCharacter chr) {
|
||||
if(chr == null) return;
|
||||
|
||||
List<Integer> updateMapids = processPlayerNPCInternal(null, null, chr, false).getRight();
|
||||
int worldid = updateMapids.remove(0);
|
||||
|
||||
for (Integer mapid : updateMapids) {
|
||||
MaplePlayerNPC pn = getPlayerNPCFromWorldMap(chr.getName(), worldid, mapid);
|
||||
|
||||
if(pn != null) {
|
||||
for (Channel channel : Server.getInstance().getChannelsFromWorld(worldid)) {
|
||||
MapleMap m = channel.getMapFactory().getMap(mapid);
|
||||
m.removeMapObject(pn);
|
||||
|
||||
m.broadcastMessage(MaplePacketCreator.removeNPCController(pn.getObjectId()));
|
||||
m.broadcastMessage(MaplePacketCreator.removePlayerNPC(pn.getObjectId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void multicastSpawnPlayerNPC(int mapid, int world) {
|
||||
World wserv = Server.getInstance().getWorld(world);
|
||||
if (wserv == null) return;
|
||||
|
||||
MapleClient c = new MapleClient(null, null, null); // mock client
|
||||
c.setWorld(world);
|
||||
c.setChannel(1);
|
||||
|
||||
for(MapleCharacter mc : wserv.loadAndGetAllCharactersView()) {
|
||||
mc.setClient(c);
|
||||
spawnPlayerNPC(mapid, mc);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeAllPlayerNPC() {
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
|
||||
PreparedStatement ps = con.prepareStatement("SELECT DISTINCT world, map FROM playernpcs");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
int wsize = Server.getInstance().getWorldsSize();
|
||||
while(rs.next()) {
|
||||
int world = rs.getInt("world"), map = rs.getInt("map");
|
||||
if(world >= wsize) continue;
|
||||
|
||||
for (Channel channel : Server.getInstance().getChannelsFromWorld(world)) {
|
||||
MapleMap m = channel.getMapFactory().getMap(map);
|
||||
|
||||
for(MapleMapObject pnpcObj : m.getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC))) {
|
||||
MaplePlayerNPC pn = (MaplePlayerNPC) pnpcObj;
|
||||
m.removeMapObject(pnpcObj);
|
||||
m.broadcastMessage(MaplePacketCreator.removeNPCController(pn.getObjectId()));
|
||||
m.broadcastMessage(MaplePacketCreator.removePlayerNPC(pn.getObjectId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
|
||||
ps = con.prepareStatement("DELETE FROM playernpcs");
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = con.prepareStatement("DELETE FROM playernpcs_equip");
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = con.prepareStatement("DELETE FROM playernpcs_field");
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
for(World w : Server.getInstance().getWorlds()) {
|
||||
w.resetPlayerNpcMapData();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
140
src/main/java/server/life/MaplePlayerNPCFactory.java
Normal file
140
src/main/java/server/life/MaplePlayerNPCFactory.java
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2019 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
import net.server.Server;
|
||||
import provider.MapleData;
|
||||
import provider.MapleDataProvider;
|
||||
import provider.MapleDataProviderFactory;
|
||||
import provider.MapleDataTool;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RonanLana
|
||||
*/
|
||||
public class MaplePlayerNPCFactory {
|
||||
|
||||
private static MapleDataProvider npcData = MapleDataProviderFactory.getDataProvider(new File("wz/Npc.wz"));
|
||||
|
||||
private static final Map<Integer, List<MaplePlayerNPC>> dnpcMaps = new HashMap<>();
|
||||
private static Integer runningDeveloperOid = 2147483000; // 647 slots, long enough
|
||||
|
||||
public static boolean isExistentScriptid(int scriptid) {
|
||||
return npcData.getData(scriptid + ".img") != null;
|
||||
}
|
||||
|
||||
public static void loadDeveloperRoomMetadata(MapleDataProvider npc) {
|
||||
MapleData thisData = npc.getData("9977777.img");
|
||||
if(thisData != null) {
|
||||
MapleDataProvider map = MapleDataProviderFactory.getDataProvider(new File("wz/Map.wz"));
|
||||
|
||||
thisData = map.getData("Map/Map7/777777777.img");
|
||||
if(thisData != null) {
|
||||
MapleDataProvider sound = MapleDataProviderFactory.getDataProvider(new File("wz/Sound.wz"));
|
||||
|
||||
thisData = sound.getData("Field.img");
|
||||
if(thisData != null) {
|
||||
MapleData md = thisData.getChildByPath("anthem/brazil");
|
||||
if(md != null) {
|
||||
Server.getInstance().setAvailableDeveloperRoom();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadFactoryMetadata() {
|
||||
MapleDataProvider npc = npcData;
|
||||
loadDeveloperRoomMetadata(npc);
|
||||
|
||||
MapleDataProvider etc = MapleDataProviderFactory.getDataProvider(new File("wz/Etc.wz"));
|
||||
MapleData dnpcData = etc.getData("DeveloperNpc.img");
|
||||
if(dnpcData != null) {
|
||||
for (MapleData data : dnpcData.getChildren()) {
|
||||
int scriptId = Integer.parseInt(data.getName());
|
||||
|
||||
String name = MapleDataTool.getString("name", data, "");
|
||||
int face = MapleDataTool.getIntConvert("face", data, 20000);
|
||||
int hair = MapleDataTool.getIntConvert("hair", data, 30000);
|
||||
int gender = MapleDataTool.getIntConvert("gender", data, 0);
|
||||
byte skin = (byte) MapleDataTool.getIntConvert("skin", data, 0);
|
||||
int dir = MapleDataTool.getIntConvert("dir", data, 0);
|
||||
int mapid = MapleDataTool.getIntConvert("map", data, 0);
|
||||
int FH = MapleDataTool.getIntConvert("fh", data, 0);
|
||||
int RX0 = MapleDataTool.getIntConvert("rx0", data, 0);
|
||||
int RX1 = MapleDataTool.getIntConvert("rx1", data, 0);
|
||||
int CX = MapleDataTool.getIntConvert("cx", data, 0);
|
||||
int CY = MapleDataTool.getIntConvert("cy", data, 0);
|
||||
|
||||
Map<Short, Integer> equips = new HashMap<>();
|
||||
for (MapleData edata : data.getChildByPath("equips").getChildren()) {
|
||||
short equippos = (short) MapleDataTool.getIntConvert("pos", edata);
|
||||
int equipid = MapleDataTool.getIntConvert("itemid", edata);
|
||||
|
||||
equips.put(equippos, equipid);
|
||||
}
|
||||
|
||||
List<MaplePlayerNPC> dnpcSet = dnpcMaps.get(mapid);
|
||||
if(dnpcSet == null) {
|
||||
dnpcSet = new LinkedList<>();
|
||||
dnpcMaps.put(mapid, dnpcSet);
|
||||
}
|
||||
|
||||
dnpcSet.add(new MaplePlayerNPC(name, scriptId, face, hair, gender, skin, equips, dir, FH, RX0, RX1, CX, CY, runningDeveloperOid));
|
||||
runningDeveloperOid++;
|
||||
}
|
||||
} else {
|
||||
MapleData thisData = npc.getData("9977777.img");
|
||||
|
||||
if(thisData != null) {
|
||||
byte[] encData = {0x52,0x6F,0x6E,0x61,0x6E};
|
||||
String name = new String(encData);
|
||||
int face = 20104, hair = 30215, gender = 0, skin = 0, dir = 0, mapid = 777777777;
|
||||
int FH = 4, RX0 = -143, RX1 = -243, CX = -193, CY = 117, scriptId = 9977777;
|
||||
|
||||
Map<Short, Integer> equips = new HashMap<>();
|
||||
equips.put((short) -1, 1002067);
|
||||
equips.put((short) -11, 1402046);
|
||||
equips.put((short) -8, 1082140);
|
||||
equips.put((short) -6, 1060091);
|
||||
equips.put((short) -7, 1072154);
|
||||
equips.put((short) -5, 1040103);
|
||||
|
||||
List<MaplePlayerNPC> dnpcSet = dnpcMaps.get(mapid);
|
||||
if(dnpcSet == null) {
|
||||
dnpcSet = new LinkedList<>();
|
||||
dnpcMaps.put(mapid, dnpcSet);
|
||||
}
|
||||
|
||||
dnpcSet.add(new MaplePlayerNPC(name, scriptId, face, hair, gender, (byte) skin, equips, dir, FH, RX0, RX1, CX, CY, runningDeveloperOid));
|
||||
runningDeveloperOid++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<MaplePlayerNPC> getDeveloperNpcsFromMapid(int mapid) {
|
||||
return dnpcMaps.get(mapid);
|
||||
}
|
||||
}
|
||||
77
src/main/java/server/life/MobAttackInfo.java
Normal file
77
src/main/java/server/life/MobAttackInfo.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Danny (Leifde)
|
||||
*/
|
||||
public class MobAttackInfo {
|
||||
private boolean isDeadlyAttack;
|
||||
private int mpBurn;
|
||||
private int diseaseSkill;
|
||||
private int diseaseLevel;
|
||||
private int mpCon;
|
||||
|
||||
public MobAttackInfo(int mobId, int attackId) {
|
||||
}
|
||||
|
||||
public void setDeadlyAttack(boolean isDeadlyAttack) {
|
||||
this.isDeadlyAttack = isDeadlyAttack;
|
||||
}
|
||||
|
||||
public boolean isDeadlyAttack() {
|
||||
return isDeadlyAttack;
|
||||
}
|
||||
|
||||
public void setMpBurn(int mpBurn) {
|
||||
this.mpBurn = mpBurn;
|
||||
}
|
||||
|
||||
public int getMpBurn() {
|
||||
return mpBurn;
|
||||
}
|
||||
|
||||
public void setDiseaseSkill(int diseaseSkill) {
|
||||
this.diseaseSkill = diseaseSkill;
|
||||
}
|
||||
|
||||
public int getDiseaseSkill() {
|
||||
return diseaseSkill;
|
||||
}
|
||||
|
||||
public void setDiseaseLevel(int diseaseLevel) {
|
||||
this.diseaseLevel = diseaseLevel;
|
||||
}
|
||||
|
||||
public int getDiseaseLevel() {
|
||||
return diseaseLevel;
|
||||
}
|
||||
|
||||
public void setMpCon(int mpCon) {
|
||||
this.mpCon = mpCon;
|
||||
}
|
||||
|
||||
public int getMpCon() {
|
||||
return mpCon;
|
||||
}
|
||||
}
|
||||
79
src/main/java/server/life/MobAttackInfoFactory.java
Normal file
79
src/main/java/server/life/MobAttackInfoFactory.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import provider.MapleData;
|
||||
import provider.MapleDataProvider;
|
||||
import provider.MapleDataProviderFactory;
|
||||
import provider.MapleDataTool;
|
||||
import tools.StringUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Danny (Leifde)
|
||||
*/
|
||||
public class MobAttackInfoFactory {
|
||||
private static Map<String, MobAttackInfo> mobAttacks = new HashMap<String, MobAttackInfo>();
|
||||
private static MapleDataProvider dataSource = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Mob.wz"));
|
||||
|
||||
public static MobAttackInfo getMobAttackInfo(MapleMonster mob, int attack) {
|
||||
MobAttackInfo ret = mobAttacks.get(mob.getId() + "" + attack);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
synchronized (mobAttacks) {
|
||||
ret = mobAttacks.get(mob.getId() + "" + attack);
|
||||
if (ret == null) {
|
||||
MapleData mobData = dataSource.getData(StringUtil.getLeftPaddedStr(Integer.toString(mob.getId()) + ".img", '0', 11));
|
||||
if (mobData != null) {
|
||||
// MapleData infoData = mobData.getChildByPath("info");
|
||||
String linkedmob = MapleDataTool.getString("link", mobData, "");
|
||||
if (!linkedmob.equals("")) {
|
||||
mobData = dataSource.getData(StringUtil.getLeftPaddedStr(linkedmob + ".img", '0', 11));
|
||||
}
|
||||
MapleData attackData = mobData.getChildByPath("attack" + (attack + 1) + "/info");
|
||||
|
||||
if (attackData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MapleData deadlyAttack = attackData.getChildByPath("deadlyAttack");
|
||||
int mpBurn = MapleDataTool.getInt("mpBurn", attackData, 0);
|
||||
int disease = MapleDataTool.getInt("disease", attackData, 0);
|
||||
int level = MapleDataTool.getInt("level", attackData, 0);
|
||||
int mpCon = MapleDataTool.getInt("conMP", attackData, 0);
|
||||
ret = new MobAttackInfo(mob.getId(), attack);
|
||||
ret.setDeadlyAttack(deadlyAttack != null);
|
||||
ret.setMpBurn(mpBurn);
|
||||
ret.setDiseaseSkill(disease);
|
||||
ret.setDiseaseLevel(level);
|
||||
ret.setMpCon(mpCon);
|
||||
}
|
||||
mobAttacks.put(mob.getId() + "" + attack, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
424
src/main/java/server/life/MobSkill.java
Normal file
424
src/main/java/server/life/MobSkill.java
Normal file
@@ -0,0 +1,424 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleDisease;
|
||||
import client.status.MonsterStatus;
|
||||
import constants.game.GameConstants;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import net.server.services.type.ChannelServices;
|
||||
import net.server.services.task.channel.OverallService;
|
||||
import tools.Randomizer;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMapObject;
|
||||
import server.maps.MapleMapObjectType;
|
||||
import server.maps.MapleMist;
|
||||
import tools.ArrayMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Danny (Leifde)
|
||||
*/
|
||||
public class MobSkill {
|
||||
|
||||
private int skillId, skillLevel, mpCon;
|
||||
private List<Integer> toSummon = new ArrayList<Integer>();
|
||||
private int spawnEffect, hp, x, y;
|
||||
private long duration, cooltime;
|
||||
private float prop;
|
||||
private Point lt, rb;
|
||||
private int limit;
|
||||
|
||||
public MobSkill(int skillId, int level) {
|
||||
this.skillId = skillId;
|
||||
this.skillLevel = level;
|
||||
}
|
||||
|
||||
public void setMpCon(int mpCon) {
|
||||
this.mpCon = mpCon;
|
||||
}
|
||||
|
||||
public void addSummons(List<Integer> toSummon) {
|
||||
for (Integer summon : toSummon) {
|
||||
this.toSummon.add(summon);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSpawnEffect(int spawnEffect) {
|
||||
this.spawnEffect = spawnEffect;
|
||||
}
|
||||
|
||||
public void setHp(int hp) {
|
||||
this.hp = hp;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setDuration(long duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public void setCoolTime(long cooltime) {
|
||||
this.cooltime = cooltime;
|
||||
}
|
||||
|
||||
public void setProp(float prop) {
|
||||
this.prop = prop;
|
||||
}
|
||||
|
||||
public void setLtRb(Point lt, Point rb) {
|
||||
this.lt = lt;
|
||||
this.rb = rb;
|
||||
}
|
||||
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public void applyDelayedEffect(final MapleCharacter player, final MapleMonster monster, final boolean skill, int animationTime) {
|
||||
Runnable toRun = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (monster.isAlive()) {
|
||||
applyEffect(player, monster, skill, null);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
OverallService service = (OverallService) monster.getMap().getChannelServer().getServiceAccess(ChannelServices.OVERALL);
|
||||
service.registerOverallAction(monster.getMap().getId(), toRun, animationTime);
|
||||
}
|
||||
|
||||
public void applyEffect(MapleCharacter player, MapleMonster monster, boolean skill, List<MapleCharacter> banishPlayers) {
|
||||
MapleDisease disease = null;
|
||||
Map<MonsterStatus, Integer> stats = new ArrayMap<MonsterStatus, Integer>();
|
||||
List<Integer> reflection = new LinkedList<Integer>();
|
||||
switch (skillId) {
|
||||
case 100:
|
||||
case 110:
|
||||
case 150:
|
||||
stats.put(MonsterStatus.WEAPON_ATTACK_UP, Integer.valueOf(x));
|
||||
break;
|
||||
case 101:
|
||||
case 111:
|
||||
case 151:
|
||||
stats.put(MonsterStatus.MAGIC_ATTACK_UP, Integer.valueOf(x));
|
||||
break;
|
||||
case 102:
|
||||
case 112:
|
||||
case 152:
|
||||
stats.put(MonsterStatus.WEAPON_DEFENSE_UP, Integer.valueOf(x));
|
||||
break;
|
||||
case 103:
|
||||
case 113:
|
||||
case 153:
|
||||
stats.put(MonsterStatus.MAGIC_DEFENSE_UP, Integer.valueOf(x));
|
||||
break;
|
||||
case 114:
|
||||
if (lt != null && rb != null && skill) {
|
||||
List<MapleMapObject> objects = getObjectsInRange(monster, MapleMapObjectType.MONSTER);
|
||||
final int hps = (getX() / 1000) * (int) (950 + 1050 * Math.random());
|
||||
for (MapleMapObject mons : objects) {
|
||||
((MapleMonster) mons).heal(hps, getY());
|
||||
}
|
||||
} else {
|
||||
monster.heal(getX(), getY());
|
||||
}
|
||||
break;
|
||||
case 120:
|
||||
disease = MapleDisease.SEAL;
|
||||
break;
|
||||
case 121:
|
||||
disease = MapleDisease.DARKNESS;
|
||||
break;
|
||||
case 122:
|
||||
disease = MapleDisease.WEAKEN;
|
||||
break;
|
||||
case 123:
|
||||
disease = MapleDisease.STUN;
|
||||
break;
|
||||
case 124:
|
||||
disease = MapleDisease.CURSE;
|
||||
break;
|
||||
case 125:
|
||||
disease = MapleDisease.POISON;
|
||||
break;
|
||||
case 126: // Slow
|
||||
disease = MapleDisease.SLOW;
|
||||
break;
|
||||
case 127:
|
||||
if (lt != null && rb != null && skill) {
|
||||
for (MapleCharacter character : getPlayersInRange(monster)) {
|
||||
character.dispel();
|
||||
}
|
||||
} else {
|
||||
player.dispel();
|
||||
}
|
||||
break;
|
||||
case 128: // Seduce
|
||||
disease = MapleDisease.SEDUCE;
|
||||
break;
|
||||
case 129: // Banish
|
||||
if (lt != null && rb != null && skill) {
|
||||
for (MapleCharacter chr : getPlayersInRange(monster)) {
|
||||
banishPlayers.add(chr);
|
||||
}
|
||||
} else {
|
||||
banishPlayers.add(player);
|
||||
}
|
||||
break;
|
||||
case 131: // Mist
|
||||
monster.getMap().spawnMist(new MapleMist(calculateBoundingBox(monster.getPosition()), monster, this), x * 100, false, false, false);
|
||||
break;
|
||||
case 132:
|
||||
disease = MapleDisease.CONFUSE;
|
||||
break;
|
||||
case 133: // zombify
|
||||
disease = MapleDisease.ZOMBIFY;
|
||||
break;
|
||||
case 140:
|
||||
if (makeChanceResult() && !monster.isBuffed(MonsterStatus.MAGIC_IMMUNITY)) {
|
||||
stats.put(MonsterStatus.WEAPON_IMMUNITY, Integer.valueOf(x));
|
||||
}
|
||||
break;
|
||||
case 141:
|
||||
if (makeChanceResult() && !monster.isBuffed(MonsterStatus.WEAPON_IMMUNITY)) {
|
||||
stats.put(MonsterStatus.MAGIC_IMMUNITY, Integer.valueOf(x));
|
||||
}
|
||||
break;
|
||||
case 143: // Weapon Reflect
|
||||
stats.put(MonsterStatus.WEAPON_REFLECT, 10);
|
||||
stats.put(MonsterStatus.WEAPON_IMMUNITY, 10);
|
||||
reflection.add(x);
|
||||
break;
|
||||
case 144: // Magic Reflect
|
||||
stats.put(MonsterStatus.MAGIC_REFLECT, 10);
|
||||
stats.put(MonsterStatus.MAGIC_IMMUNITY, 10);
|
||||
reflection.add(x);
|
||||
break;
|
||||
case 145: // Weapon / Magic reflect
|
||||
stats.put(MonsterStatus.WEAPON_REFLECT, 10);
|
||||
stats.put(MonsterStatus.WEAPON_IMMUNITY, 10);
|
||||
stats.put(MonsterStatus.MAGIC_REFLECT, 10);
|
||||
stats.put(MonsterStatus.MAGIC_IMMUNITY, 10);
|
||||
reflection.add(x);
|
||||
break;
|
||||
case 154:
|
||||
stats.put(MonsterStatus.ACC, Integer.valueOf(x));
|
||||
break;
|
||||
case 155:
|
||||
stats.put(MonsterStatus.AVOID, Integer.valueOf(x));
|
||||
break;
|
||||
case 156:
|
||||
stats.put(MonsterStatus.SPEED, Integer.valueOf(x));
|
||||
break;
|
||||
case 200: // summon
|
||||
int skillLimit = this.getLimit();
|
||||
MapleMap map = monster.getMap();
|
||||
|
||||
if (GameConstants.isDojo(map.getId())) { // spawns in dojo should be unlimited
|
||||
skillLimit = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
if (map.getSpawnedMonstersOnMap() < 80) {
|
||||
List<Integer> summons = getSummons();
|
||||
int summonLimit = monster.countAvailableMobSummons(summons.size(), skillLimit);
|
||||
if (summonLimit >= 1) {
|
||||
boolean bossRushMap = GameConstants.isBossRush(map.getId());
|
||||
|
||||
Collections.shuffle(summons);
|
||||
for (Integer mobId : summons.subList(0, summonLimit)) {
|
||||
MapleMonster toSpawn = MapleLifeFactory.getMonster(mobId);
|
||||
if (toSpawn != null) {
|
||||
if (bossRushMap) {
|
||||
toSpawn.disableDrops(); // no littering on BRPQ pls
|
||||
}
|
||||
toSpawn.setPosition(monster.getPosition());
|
||||
int ypos, xpos;
|
||||
xpos = (int) monster.getPosition().getX();
|
||||
ypos = (int) monster.getPosition().getY();
|
||||
switch (mobId) {
|
||||
case 8500003: // Pap bomb high
|
||||
toSpawn.setFh((int) Math.ceil(Math.random() * 19.0));
|
||||
ypos = -590;
|
||||
break;
|
||||
case 8500004: // Pap bomb
|
||||
xpos = (int) (monster.getPosition().getX() + Randomizer.nextInt(1000) - 500);
|
||||
if (ypos != -590) {
|
||||
ypos = (int) monster.getPosition().getY();
|
||||
}
|
||||
break;
|
||||
case 8510100: //Pianus bomb
|
||||
if (Math.ceil(Math.random() * 5) == 1) {
|
||||
ypos = 78;
|
||||
xpos = (int) Randomizer.nextInt(5) + (Randomizer.nextInt(2) == 1 ? 180 : 0);
|
||||
} else {
|
||||
xpos = (int) (monster.getPosition().getX() + Randomizer.nextInt(1000) - 500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (map.getId()) {
|
||||
case 220080001: //Pap map
|
||||
if (xpos < -890) {
|
||||
xpos = (int) (Math.ceil(Math.random() * 150) - 890);
|
||||
} else if (xpos > 230) {
|
||||
xpos = (int) (230 - Math.ceil(Math.random() * 150));
|
||||
}
|
||||
break;
|
||||
case 230040420: // Pianus map
|
||||
if (xpos < -239) {
|
||||
xpos = (int) (Math.ceil(Math.random() * 150) - 239);
|
||||
} else if (xpos > 371) {
|
||||
xpos = (int) (371 - Math.ceil(Math.random() * 150));
|
||||
}
|
||||
break;
|
||||
}
|
||||
toSpawn.setPosition(new Point(xpos, ypos));
|
||||
if (toSpawn.getId() == 8500004) {
|
||||
map.spawnFakeMonster(toSpawn);
|
||||
} else {
|
||||
map.spawnMonsterWithEffect(toSpawn, getSpawnEffect(), toSpawn.getPosition());
|
||||
}
|
||||
monster.addSummonedMob(toSpawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.out.println("Unhandled Mob skill: " + skillId);
|
||||
break;
|
||||
}
|
||||
if (stats.size() > 0) {
|
||||
if (lt != null && rb != null && skill) {
|
||||
for (MapleMapObject mons : getObjectsInRange(monster, MapleMapObjectType.MONSTER)) {
|
||||
((MapleMonster) mons).applyMonsterBuff(stats, getX(), getSkillId(), getDuration(), this, reflection);
|
||||
}
|
||||
} else {
|
||||
monster.applyMonsterBuff(stats, getX(), getSkillId(), getDuration(), this, reflection);
|
||||
}
|
||||
}
|
||||
if (disease != null) {
|
||||
if (lt != null && rb != null && skill) {
|
||||
int i = 0;
|
||||
for (MapleCharacter character : getPlayersInRange(monster)) {
|
||||
if (!character.hasActiveBuff(2321005)) { // holy shield
|
||||
if (disease.equals(MapleDisease.SEDUCE)) {
|
||||
if (i < 10) {
|
||||
character.giveDebuff(MapleDisease.SEDUCE, this);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
character.giveDebuff(disease, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.giveDebuff(disease, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<MapleCharacter> getPlayersInRange(MapleMonster monster) {
|
||||
return monster.getMap().getPlayersInRange(calculateBoundingBox(monster.getPosition()));
|
||||
}
|
||||
|
||||
public int getSkillId() {
|
||||
return skillId;
|
||||
}
|
||||
|
||||
public int getSkillLevel() {
|
||||
return skillLevel;
|
||||
}
|
||||
|
||||
public int getMpCon() {
|
||||
return mpCon;
|
||||
}
|
||||
|
||||
public List<Integer> getSummons() {
|
||||
return new ArrayList<>(toSummon);
|
||||
}
|
||||
|
||||
public int getSpawnEffect() {
|
||||
return spawnEffect;
|
||||
}
|
||||
|
||||
public int getHP() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public long getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public long getCoolTime() {
|
||||
return cooltime;
|
||||
}
|
||||
|
||||
public Point getLt() {
|
||||
return lt;
|
||||
}
|
||||
|
||||
public Point getRb() {
|
||||
return rb;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public boolean makeChanceResult() {
|
||||
return prop == 1.0 || Math.random() < prop;
|
||||
}
|
||||
|
||||
private Rectangle calculateBoundingBox(Point posFrom) {
|
||||
Point mylt = new Point(lt.x + posFrom.x, lt.y + posFrom.y);
|
||||
Point myrb = new Point(rb.x + posFrom.x, rb.y + posFrom.y);
|
||||
Rectangle bounds = new Rectangle(mylt.x, mylt.y, myrb.x - mylt.x, myrb.y - mylt.y);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
private List<MapleMapObject> getObjectsInRange(MapleMonster monster, MapleMapObjectType objectType) {
|
||||
return monster.getMap().getMapObjectsInBox(calculateBoundingBox(monster.getPosition()), Collections.singletonList(objectType));
|
||||
}
|
||||
}
|
||||
116
src/main/java/server/life/MobSkillFactory.java
Normal file
116
src/main/java/server/life/MobSkillFactory.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.MonitoredReadLock;
|
||||
import net.server.audit.locks.MonitoredReentrantReadWriteLock;
|
||||
import net.server.audit.locks.MonitoredWriteLock;
|
||||
import net.server.audit.locks.factory.MonitoredReadLockFactory;
|
||||
import net.server.audit.locks.factory.MonitoredWriteLockFactory;
|
||||
import provider.MapleData;
|
||||
import provider.MapleDataProvider;
|
||||
import provider.MapleDataProviderFactory;
|
||||
import provider.MapleDataTool;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Danny (Leifde)
|
||||
*/
|
||||
public class MobSkillFactory {
|
||||
|
||||
private static Map<String, MobSkill> mobSkills = new HashMap<String, MobSkill>();
|
||||
private final static MapleDataProvider dataSource = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Skill.wz"));
|
||||
private static MapleData skillRoot = dataSource.getData("MobSkill.img");
|
||||
private final static MonitoredReentrantReadWriteLock dataLock = new MonitoredReentrantReadWriteLock(MonitoredLockType.MOBSKILL_FACTORY);
|
||||
private final static MonitoredReadLock rL = MonitoredReadLockFactory.createLock(dataLock);
|
||||
private final static MonitoredWriteLock wL = MonitoredWriteLockFactory.createLock(dataLock);
|
||||
|
||||
public static MobSkill getMobSkill(final int skillId, final int level) {
|
||||
final String key = skillId + "" + level;
|
||||
rL.lock();
|
||||
try {
|
||||
MobSkill ret = mobSkills.get(key);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
} finally {
|
||||
rL.unlock();
|
||||
}
|
||||
wL.lock();
|
||||
try {
|
||||
MobSkill ret;
|
||||
ret = mobSkills.get(key);
|
||||
if (ret == null) {
|
||||
MapleData skillData = skillRoot.getChildByPath(skillId + "/level/" + level);
|
||||
if (skillData != null) {
|
||||
int mpCon = MapleDataTool.getInt(skillData.getChildByPath("mpCon"), 0);
|
||||
List<Integer> toSummon = new ArrayList<Integer>();
|
||||
for (int i = 0; i > -1; i++) {
|
||||
if (skillData.getChildByPath(String.valueOf(i)) == null) {
|
||||
break;
|
||||
}
|
||||
toSummon.add(Integer.valueOf(MapleDataTool.getInt(skillData.getChildByPath(String.valueOf(i)), 0)));
|
||||
}
|
||||
int effect = MapleDataTool.getInt("summonEffect", skillData, 0);
|
||||
int hp = MapleDataTool.getInt("hp", skillData, 100);
|
||||
int x = MapleDataTool.getInt("x", skillData, 1);
|
||||
int y = MapleDataTool.getInt("y", skillData, 1);
|
||||
long duration = MapleDataTool.getInt("time", skillData, 0) * 1000;
|
||||
long cooltime = MapleDataTool.getInt("interval", skillData, 0) * 1000;
|
||||
int iprop = MapleDataTool.getInt("prop", skillData, 100);
|
||||
float prop = iprop / 100;
|
||||
int limit = MapleDataTool.getInt("limit", skillData, 0);
|
||||
MapleData ltd = skillData.getChildByPath("lt");
|
||||
Point lt = null;
|
||||
Point rb = null;
|
||||
if (ltd != null) {
|
||||
lt = (Point) ltd.getData();
|
||||
rb = (Point) skillData.getChildByPath("rb").getData();
|
||||
}
|
||||
ret = new MobSkill(skillId, level);
|
||||
ret.addSummons(toSummon);
|
||||
ret.setCoolTime(cooltime);
|
||||
ret.setDuration(duration);
|
||||
ret.setHp(hp);
|
||||
ret.setMpCon(mpCon);
|
||||
ret.setSpawnEffect(effect);
|
||||
ret.setX(x);
|
||||
ret.setY(y);
|
||||
ret.setProp(prop);
|
||||
ret.setLimit(limit);
|
||||
ret.setLtRb(lt, rb);
|
||||
}
|
||||
mobSkills.put(skillId + "" + level, ret);
|
||||
}
|
||||
return ret;
|
||||
} finally {
|
||||
wL.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/main/java/server/life/MonsterDropEntry.java
Normal file
38
src/main/java/server/life/MonsterDropEntry.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 ~ 2010 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LightPepsi
|
||||
*/
|
||||
|
||||
public class MonsterDropEntry {
|
||||
public MonsterDropEntry(int itemId, int chance, int Minimum, int Maximum, short questid) {
|
||||
this.itemId = itemId;
|
||||
this.chance = chance;
|
||||
this.questid = questid;
|
||||
this.Minimum = Minimum;
|
||||
this.Maximum = Maximum;
|
||||
}
|
||||
public short questid;
|
||||
public int itemId, chance, Minimum, Maximum;
|
||||
}
|
||||
38
src/main/java/server/life/MonsterGlobalDropEntry.java
Normal file
38
src/main/java/server/life/MonsterGlobalDropEntry.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 ~ 2010 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LightPepsi
|
||||
*/
|
||||
public class MonsterGlobalDropEntry {
|
||||
public MonsterGlobalDropEntry(int itemId, int chance, int continent, int Minimum, int Maximum, short questid) {
|
||||
this.itemId = itemId;
|
||||
this.chance = chance;
|
||||
this.questid = questid;
|
||||
this.continentid = continent;
|
||||
this.Minimum = Minimum;
|
||||
this.Maximum = Maximum;
|
||||
}
|
||||
public int itemId, chance, Minimum, Maximum, continentid;
|
||||
public short questid;
|
||||
}
|
||||
9
src/main/java/server/life/MonsterListener.java
Normal file
9
src/main/java/server/life/MonsterListener.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package server.life;
|
||||
import client.MapleCharacter;
|
||||
|
||||
public interface MonsterListener {
|
||||
|
||||
public void monsterKilled(int aniTime);
|
||||
public void monsterDamaged(MapleCharacter from, int trueDmg);
|
||||
public void monsterHealed(int trueHeal);
|
||||
}
|
||||
64
src/main/java/server/life/OverrideMonsterStats.java
Normal file
64
src/main/java/server/life/OverrideMonsterStats.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 ~ 2010 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
public class OverrideMonsterStats {
|
||||
|
||||
public int hp;
|
||||
public int exp, mp;
|
||||
|
||||
public OverrideMonsterStats() {
|
||||
hp = 1;
|
||||
exp = 0;
|
||||
mp = 0;
|
||||
}
|
||||
|
||||
public OverrideMonsterStats(int hp, int mp, int exp, boolean change) {
|
||||
this.hp = /*change ? (hp * 3L / 2L) : */ hp;
|
||||
this.mp = mp;
|
||||
this.exp = exp;
|
||||
}
|
||||
|
||||
public OverrideMonsterStats(int hp, int mp, int exp) {
|
||||
this(hp, mp, exp, true);
|
||||
}
|
||||
|
||||
public int getExp() {
|
||||
return exp;
|
||||
}
|
||||
|
||||
public void setOExp(int exp) {
|
||||
this.exp = exp;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public void setOHp(int hp) {
|
||||
this.hp = hp;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
public void setOMp(int mp) {
|
||||
this.mp = mp;
|
||||
}
|
||||
}
|
||||
130
src/main/java/server/life/SpawnPoint.java
Normal file
130
src/main/java/server/life/SpawnPoint.java
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
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 as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import java.awt.Point;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import net.server.Server;
|
||||
|
||||
public class SpawnPoint {
|
||||
private int monster, mobTime, team, fh, f;
|
||||
private Point pos;
|
||||
private long nextPossibleSpawn;
|
||||
private int mobInterval = 5000;
|
||||
private AtomicInteger spawnedMonsters = new AtomicInteger(0);
|
||||
private boolean immobile, denySpawn = false;
|
||||
|
||||
public SpawnPoint(final MapleMonster monster, Point pos, boolean immobile, int mobTime, int mobInterval, int team) {
|
||||
this.monster = monster.getId();
|
||||
this.pos = new Point(pos);
|
||||
this.mobTime = mobTime;
|
||||
this.team = team;
|
||||
this.fh = monster.getFh();
|
||||
this.f = monster.getF();
|
||||
this.immobile = immobile;
|
||||
this.mobInterval = mobInterval;
|
||||
this.nextPossibleSpawn = Server.getInstance().getCurrentTime();
|
||||
}
|
||||
|
||||
public int getSpawned() {
|
||||
return spawnedMonsters.intValue();
|
||||
}
|
||||
|
||||
public void setDenySpawn(boolean val) {
|
||||
denySpawn = val;
|
||||
}
|
||||
|
||||
public boolean getDenySpawn() {
|
||||
return denySpawn;
|
||||
}
|
||||
|
||||
public boolean shouldSpawn() {
|
||||
if (denySpawn || mobTime < 0 || spawnedMonsters.get() > 0) {
|
||||
return false;
|
||||
}
|
||||
return nextPossibleSpawn <= Server.getInstance().getCurrentTime();
|
||||
}
|
||||
|
||||
public boolean shouldForceSpawn() {
|
||||
if (mobTime < 0 || spawnedMonsters.get() > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public MapleMonster getMonster() {
|
||||
MapleMonster mob = new MapleMonster(MapleLifeFactory.getMonster(monster));
|
||||
mob.setPosition(new Point(pos));
|
||||
mob.setTeam(team);
|
||||
mob.setFh(fh);
|
||||
mob.setF(f);
|
||||
spawnedMonsters.incrementAndGet();
|
||||
mob.addListener(new MonsterListener() {
|
||||
@Override
|
||||
public void monsterKilled(int aniTime) {
|
||||
nextPossibleSpawn = Server.getInstance().getCurrentTime();
|
||||
if (mobTime > 0) {
|
||||
nextPossibleSpawn += mobTime * 1000;
|
||||
} else {
|
||||
nextPossibleSpawn += aniTime;
|
||||
}
|
||||
spawnedMonsters.decrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void monsterDamaged(MapleCharacter from, int trueDmg) {}
|
||||
|
||||
@Override
|
||||
public void monsterHealed(int trueHeal) {}
|
||||
});
|
||||
if (mobTime == 0) {
|
||||
nextPossibleSpawn = Server.getInstance().getCurrentTime() + mobInterval;
|
||||
}
|
||||
return mob;
|
||||
}
|
||||
|
||||
public int getMonsterId() {
|
||||
return monster;
|
||||
}
|
||||
|
||||
public Point getPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public final int getF() {
|
||||
return f;
|
||||
}
|
||||
|
||||
public final int getFh() {
|
||||
return fh;
|
||||
}
|
||||
|
||||
public int getMobTime() {
|
||||
return mobTime;
|
||||
}
|
||||
|
||||
public int getTeam() {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
155
src/main/java/server/life/positioner/MaplePlayerNPCPodium.java
Normal file
155
src/main/java/server/life/positioner/MaplePlayerNPCPodium.java
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2019 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life.positioner;
|
||||
|
||||
import config.YamlConfig;
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import server.life.MaplePlayerNPC;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMapObject;
|
||||
import server.maps.MapleMapObjectType;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RonanLana
|
||||
*
|
||||
* Note: the podium uses getGroundBelow that in its turn uses inputted posY minus 7.
|
||||
* Podium system will implement increase-by-7 to negate that behaviour.
|
||||
*/
|
||||
public class MaplePlayerNPCPodium {
|
||||
private static int getPlatformPosX(int platform) {
|
||||
switch(platform) {
|
||||
case 0:
|
||||
return -50;
|
||||
|
||||
case 1:
|
||||
return -170;
|
||||
|
||||
default:
|
||||
return 70;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getPlatformPosY(int platform) {
|
||||
switch(platform) {
|
||||
case 0:
|
||||
return -47;
|
||||
|
||||
default:
|
||||
return 40;
|
||||
}
|
||||
}
|
||||
|
||||
private static Point calcNextPos(int rank, int step) {
|
||||
int podiumPlatform = rank / step;
|
||||
int relativePos = (rank % step) + 1;
|
||||
|
||||
Point pos = new Point(getPlatformPosX(podiumPlatform) + ((100 * relativePos) / (step + 1)), getPlatformPosY(podiumPlatform));
|
||||
return pos;
|
||||
}
|
||||
|
||||
private static Point rearrangePlayerNpcs(MapleMap map, int newStep, List<MaplePlayerNPC> pnpcs) {
|
||||
int i = 0;
|
||||
for(MaplePlayerNPC pn : pnpcs) {
|
||||
pn.updatePlayerNPCPosition(map, calcNextPos(i, newStep));
|
||||
i++;
|
||||
}
|
||||
|
||||
return calcNextPos(i, newStep);
|
||||
}
|
||||
|
||||
private static Point reorganizePlayerNpcs(MapleMap map, int newStep, List<MapleMapObject> mmoList) {
|
||||
if(!mmoList.isEmpty()) {
|
||||
if(YamlConfig.config.server.USE_DEBUG) System.out.println("Reorganizing pnpc map, step " + newStep);
|
||||
|
||||
List<MaplePlayerNPC> playerNpcs = new ArrayList<>(mmoList.size());
|
||||
for(MapleMapObject mmo : mmoList) {
|
||||
playerNpcs.add((MaplePlayerNPC) mmo);
|
||||
}
|
||||
|
||||
Collections.sort(playerNpcs, new Comparator<MaplePlayerNPC>() {
|
||||
@Override
|
||||
public int compare(MaplePlayerNPC p1, MaplePlayerNPC p2) {
|
||||
return p1.getScriptId() - p2.getScriptId(); // scriptid as playernpc history
|
||||
}
|
||||
});
|
||||
|
||||
for(Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
MapleMap m = ch.getMapFactory().getMap(map.getId());
|
||||
|
||||
for(MaplePlayerNPC pn : playerNpcs) {
|
||||
m.removeMapObject(pn);
|
||||
m.broadcastMessage(MaplePacketCreator.removeNPCController(pn.getObjectId()));
|
||||
m.broadcastMessage(MaplePacketCreator.removePlayerNPC(pn.getObjectId()));
|
||||
}
|
||||
}
|
||||
|
||||
Point ret = rearrangePlayerNpcs(map, newStep, playerNpcs);
|
||||
|
||||
for(Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
MapleMap m = ch.getMapFactory().getMap(map.getId());
|
||||
|
||||
for(MaplePlayerNPC pn : playerNpcs) {
|
||||
m.addPlayerNPCMapObject(pn);
|
||||
m.broadcastMessage(MaplePacketCreator.spawnPlayerNPC(pn));
|
||||
m.broadcastMessage(MaplePacketCreator.getPlayerNPC(pn));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static int encodePodiumData(int podiumStep, int podiumCount) {
|
||||
return (podiumCount * (1 << 5)) + podiumStep;
|
||||
}
|
||||
|
||||
private static Point getNextPlayerNpcPosition(MapleMap map, int podiumData) { // automated playernpc position thanks to Ronan
|
||||
int podiumStep = podiumData % (1 << 5), podiumCount = (podiumData / (1 << 5));
|
||||
|
||||
if(podiumCount >= 3 * podiumStep) {
|
||||
if(podiumStep >= YamlConfig.config.server.PLAYERNPC_AREA_STEPS) return null;
|
||||
|
||||
List<MapleMapObject> mmoList = map.getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC));
|
||||
map.getWorldServer().setPlayerNpcMapPodiumData(map.getId(), encodePodiumData(podiumStep + 1, podiumCount + 1));
|
||||
return reorganizePlayerNpcs(map, podiumStep + 1, mmoList);
|
||||
} else {
|
||||
map.getWorldServer().setPlayerNpcMapPodiumData(map.getId(), encodePodiumData(podiumStep, podiumCount + 1));
|
||||
return calcNextPos(podiumCount, podiumStep);
|
||||
}
|
||||
}
|
||||
|
||||
public static Point getNextPlayerNpcPosition(MapleMap map) {
|
||||
Point pos = getNextPlayerNpcPosition(map, map.getWorldServer().getPlayerNpcMapPodiumData(map.getId()));
|
||||
if(pos == null) return null;
|
||||
|
||||
return map.getGroundBelow(pos);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2019 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation 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/>.
|
||||
*/
|
||||
package server.life.positioner;
|
||||
|
||||
import config.YamlConfig;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import server.life.MaplePlayerNPC;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMapObject;
|
||||
import server.maps.MapleMapObjectType;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RonanLana
|
||||
*
|
||||
*/
|
||||
public class MaplePlayerNPCPositioner {
|
||||
|
||||
private static boolean isPlayerNpcNearby(List<Point> otherPos, Point searchPos, int xLimit, int yLimit) {
|
||||
int xLimit2 = xLimit / 2, yLimit2 = yLimit / 2;
|
||||
|
||||
Rectangle searchRect = new Rectangle(searchPos.x - xLimit2, searchPos.y - yLimit2, xLimit, yLimit);
|
||||
for(Point pos : otherPos) {
|
||||
Rectangle otherRect = new Rectangle(pos.x - xLimit2, pos.y - yLimit2, xLimit, yLimit);
|
||||
|
||||
if(otherRect.intersects(searchRect)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int calcDx(int newStep) {
|
||||
return YamlConfig.config.server.PLAYERNPC_AREA_X / (newStep + 1);
|
||||
}
|
||||
|
||||
private static int calcDy(int newStep) {
|
||||
return (YamlConfig.config.server.PLAYERNPC_AREA_Y / 2) + (YamlConfig.config.server.PLAYERNPC_AREA_Y / (1 << (newStep + 1)));
|
||||
}
|
||||
|
||||
private static List<Point> rearrangePlayerNpcPositions(MapleMap map, int newStep, int pnpcsSize) {
|
||||
Rectangle mapArea = map.getMapArea();
|
||||
|
||||
int leftPx = mapArea.x + YamlConfig.config.server.PLAYERNPC_INITIAL_X, px, py = mapArea.y + YamlConfig.config.server.PLAYERNPC_INITIAL_Y;
|
||||
int outx = mapArea.x + mapArea.width - YamlConfig.config.server.PLAYERNPC_INITIAL_X, outy = mapArea.y + mapArea.height;
|
||||
int cx = calcDx(newStep), cy = calcDy(newStep);
|
||||
|
||||
List<Point> otherPlayerNpcs = new LinkedList<>();
|
||||
while(py < outy) {
|
||||
px = leftPx;
|
||||
|
||||
while(px < outx) {
|
||||
Point searchPos = map.getPointBelow(new Point(px, py));
|
||||
if(searchPos != null) {
|
||||
if(!isPlayerNpcNearby(otherPlayerNpcs, searchPos, cx, cy)) {
|
||||
otherPlayerNpcs.add(searchPos);
|
||||
|
||||
if(otherPlayerNpcs.size() == pnpcsSize) {
|
||||
return otherPlayerNpcs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
px += cx;
|
||||
}
|
||||
|
||||
py += cy;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Point rearrangePlayerNpcs(MapleMap map, int newStep, List<MaplePlayerNPC> pnpcs) {
|
||||
Rectangle mapArea = map.getMapArea();
|
||||
|
||||
int leftPx = mapArea.x + YamlConfig.config.server.PLAYERNPC_INITIAL_X, px, py = mapArea.y + YamlConfig.config.server.PLAYERNPC_INITIAL_Y;
|
||||
int outx = mapArea.x + mapArea.width - YamlConfig.config.server.PLAYERNPC_INITIAL_X, outy = mapArea.y + mapArea.height;
|
||||
int cx = calcDx(newStep), cy = calcDy(newStep);
|
||||
|
||||
List<Point> otherPlayerNpcs = new LinkedList<>();
|
||||
int i = 0;
|
||||
|
||||
while(py < outy) {
|
||||
px = leftPx;
|
||||
|
||||
while(px < outx) {
|
||||
Point searchPos = map.getPointBelow(new Point(px, py));
|
||||
if(searchPos != null) {
|
||||
if(!isPlayerNpcNearby(otherPlayerNpcs, searchPos, cx, cy)) {
|
||||
if(i == pnpcs.size()) {
|
||||
return searchPos;
|
||||
}
|
||||
|
||||
MaplePlayerNPC pn = pnpcs.get(i);
|
||||
i++;
|
||||
|
||||
pn.updatePlayerNPCPosition(map, searchPos);
|
||||
otherPlayerNpcs.add(searchPos);
|
||||
}
|
||||
}
|
||||
|
||||
px += cx;
|
||||
}
|
||||
|
||||
py += cy;
|
||||
}
|
||||
|
||||
return null; // this area should not be reached under any scenario
|
||||
}
|
||||
|
||||
private static Point reorganizePlayerNpcs(MapleMap map, int newStep, List<MapleMapObject> mmoList) {
|
||||
if(!mmoList.isEmpty()) {
|
||||
if(YamlConfig.config.server.USE_DEBUG) System.out.println("Reorganizing pnpc map, step " + newStep);
|
||||
|
||||
List<MaplePlayerNPC> playerNpcs = new ArrayList<>(mmoList.size());
|
||||
for(MapleMapObject mmo : mmoList) {
|
||||
playerNpcs.add((MaplePlayerNPC) mmo);
|
||||
}
|
||||
|
||||
Collections.sort(playerNpcs, new Comparator<MaplePlayerNPC>() {
|
||||
@Override
|
||||
public int compare(MaplePlayerNPC p1, MaplePlayerNPC p2) {
|
||||
return p1.getScriptId() - p2.getScriptId(); // scriptid as playernpc history
|
||||
}
|
||||
});
|
||||
|
||||
for(Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
MapleMap m = ch.getMapFactory().getMap(map.getId());
|
||||
|
||||
for(MaplePlayerNPC pn : playerNpcs) {
|
||||
m.removeMapObject(pn);
|
||||
m.broadcastMessage(MaplePacketCreator.removeNPCController(pn.getObjectId()));
|
||||
m.broadcastMessage(MaplePacketCreator.removePlayerNPC(pn.getObjectId()));
|
||||
}
|
||||
}
|
||||
|
||||
Point ret = rearrangePlayerNpcs(map, newStep, playerNpcs);
|
||||
|
||||
for(Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
MapleMap m = ch.getMapFactory().getMap(map.getId());
|
||||
|
||||
for(MaplePlayerNPC pn : playerNpcs) {
|
||||
m.addPlayerNPCMapObject(pn);
|
||||
m.broadcastMessage(MaplePacketCreator.spawnPlayerNPC(pn));
|
||||
m.broadcastMessage(MaplePacketCreator.getPlayerNPC(pn));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Point getNextPlayerNpcPosition(MapleMap map, int initStep) { // automated playernpc position thanks to Ronan
|
||||
List<MapleMapObject> mmoList = map.getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC));
|
||||
List<Point> otherPlayerNpcs = new LinkedList<>();
|
||||
for(MapleMapObject mmo : mmoList) {
|
||||
otherPlayerNpcs.add(mmo.getPosition());
|
||||
}
|
||||
|
||||
int cx = calcDx(initStep), cy = calcDy(initStep);
|
||||
Rectangle mapArea = map.getMapArea();
|
||||
int outx = mapArea.x + mapArea.width - YamlConfig.config.server.PLAYERNPC_INITIAL_X, outy = mapArea.y + mapArea.height;
|
||||
boolean reorganize = false;
|
||||
|
||||
int i = initStep;
|
||||
while(i < YamlConfig.config.server.PLAYERNPC_AREA_STEPS) {
|
||||
int leftPx = mapArea.x + YamlConfig.config.server.PLAYERNPC_INITIAL_X, px, py = mapArea.y + YamlConfig.config.server.PLAYERNPC_INITIAL_Y;
|
||||
|
||||
while(py < outy) {
|
||||
px = leftPx;
|
||||
|
||||
while(px < outx) {
|
||||
Point searchPos = map.getPointBelow(new Point(px, py));
|
||||
if(searchPos != null) {
|
||||
if(!isPlayerNpcNearby(otherPlayerNpcs, searchPos, cx, cy)) {
|
||||
if(i > initStep) {
|
||||
map.getWorldServer().setPlayerNpcMapStep(map.getId(), i);
|
||||
}
|
||||
|
||||
if(reorganize && YamlConfig.config.server.PLAYERNPC_ORGANIZE_AREA) {
|
||||
return reorganizePlayerNpcs(map, i, mmoList);
|
||||
}
|
||||
|
||||
return searchPos;
|
||||
}
|
||||
}
|
||||
|
||||
px += cx;
|
||||
}
|
||||
|
||||
py += cy;
|
||||
}
|
||||
|
||||
reorganize = true;
|
||||
i++;
|
||||
|
||||
cx = calcDx(i);
|
||||
cy = calcDy(i);
|
||||
if(YamlConfig.config.server.PLAYERNPC_ORGANIZE_AREA) {
|
||||
otherPlayerNpcs = rearrangePlayerNpcPositions(map, i, mmoList.size());
|
||||
}
|
||||
}
|
||||
|
||||
if(i > initStep) {
|
||||
map.getWorldServer().setPlayerNpcMapStep(map.getId(), YamlConfig.config.server.PLAYERNPC_AREA_STEPS - 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Point getNextPlayerNpcPosition(MapleMap map) {
|
||||
return getNextPlayerNpcPosition(map, map.getWorldServer().getPlayerNpcMapStep(map.getId()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user