use of server.life.MapleMonster in project HeavenMS by ronancpl.
the class TakeDamageHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
List<MapleCharacter> banishPlayers = new ArrayList<>();
MapleCharacter chr = c.getPlayer();
slea.readInt();
byte damagefrom = slea.readByte();
// Element
slea.readByte();
int damage = slea.readInt();
int oid = 0, monsteridfrom = 0, pgmr = 0, direction = 0;
int pos_x = 0, pos_y = 0, fake = 0;
boolean is_pgmr = false, is_pg = true, is_deadly = false;
int mpattack = 0;
MapleMonster attacker = null;
final MapleMap map = chr.getMap();
if (damagefrom != -3 && damagefrom != -4) {
monsteridfrom = slea.readInt();
oid = slea.readInt();
try {
MapleMapObject mmo = map.getMapObject(oid);
if (mmo instanceof MapleMonster) {
attacker = (MapleMonster) mmo;
if (attacker.getId() != monsteridfrom) {
attacker = null;
}
}
if (attacker != null) {
List<loseItem> loseItems;
if (attacker.isBuffed(MonsterStatus.NEUTRALISE)) {
return;
}
if (damage > 0) {
MapleMonster assaulter = map.getMonsterById(monsteridfrom);
if (assaulter != null) {
loseItems = assaulter.getStats().loseItem();
if (loseItems != null) {
MapleInventoryType type;
final int playerpos = chr.getPosition().x;
byte d = 1;
Point pos = new Point(0, chr.getPosition().y);
for (loseItem loseItem : loseItems) {
type = ItemConstants.getInventoryType(loseItem.getId());
for (byte b = 0; b < loseItem.getX(); b++) {
// LOL?
if (Randomizer.nextInt(101) >= loseItem.getChance()) {
if (chr.haveItem(loseItem.getId())) {
pos.x = (int) (playerpos + ((d % 2 == 0) ? (25 * (d + 1) / 2) : -(25 * (d / 2))));
MapleInventoryManipulator.removeById(c, type, loseItem.getId(), 1, false, false);
map.spawnItemDrop(chr, chr, new Item(loseItem.getId(), (short) 0, (short) 1), map.calcDropPos(pos, chr.getPosition()), true, true);
d++;
} else {
break;
}
}
}
}
map.removeMapObject(attacker);
}
}
}
} else {
return;
}
} catch (ClassCastException e) {
// this happens due to mob on last map damaging player just before changing maps
e.printStackTrace();
FilePrinter.printError(FilePrinter.EXCEPTION_CAUGHT, "Attacker is not a mob-type, rather is a " + map.getMapObject(oid).getClass().getName() + " entity.");
return;
}
direction = slea.readByte();
}
if (damagefrom != -1 && damagefrom != -2 && attacker != null) {
MobAttackInfo attackInfo = MobAttackInfoFactory.getMobAttackInfo(attacker, damagefrom);
if (attackInfo != null) {
if (attackInfo.isDeadlyAttack()) {
mpattack = chr.getMp() - 1;
is_deadly = true;
}
mpattack += attackInfo.getMpBurn();
MobSkill mobSkill = MobSkillFactory.getMobSkill(attackInfo.getDiseaseSkill(), attackInfo.getDiseaseLevel());
if (mobSkill != null && damage > 0) {
mobSkill.applyEffect(chr, attacker, false, banishPlayers);
}
attacker.setMp(attacker.getMp() - attackInfo.getMpCon());
if (chr.getBuffedValue(MapleBuffStat.MANA_REFLECTION) != null && damage > 0 && !attacker.isBoss()) {
int jobid = chr.getJob().getId();
if (jobid == 212 || jobid == 222 || jobid == 232) {
int id = jobid * 10000 + 1002;
Skill manaReflectSkill = SkillFactory.getSkill(id);
if (chr.isBuffFrom(MapleBuffStat.MANA_REFLECTION, manaReflectSkill) && chr.getSkillLevel(manaReflectSkill) > 0 && manaReflectSkill.getEffect(chr.getSkillLevel(manaReflectSkill)).makeChanceResult()) {
int bouncedamage = (damage * manaReflectSkill.getEffect(chr.getSkillLevel(manaReflectSkill)).getX() / 100);
if (bouncedamage > attacker.getMaxHp() / 5) {
bouncedamage = attacker.getMaxHp() / 5;
}
map.damageMonster(chr, attacker, bouncedamage);
map.broadcastMessage(chr, MaplePacketCreator.damageMonster(oid, bouncedamage), true);
chr.getClient().announce(MaplePacketCreator.showOwnBuffEffect(id, 5));
map.broadcastMessage(chr, MaplePacketCreator.showBuffeffect(chr.getId(), id, 5), false);
}
}
}
}
}
if (damage == -1) {
fake = 4020002 + (chr.getJob().getId() / 10 - 40) * 100000;
}
// in dojo player cannot use pot, so deadly attacks should be turned off as well
if (is_deadly && chr.getMap().isDojoMap() && !ServerConstants.USE_DEADLY_DOJO) {
damage = 0;
mpattack = 0;
}
if (damage == 0) {
chr.getAutobanManager().addMiss();
} else {
chr.getAutobanManager().resetMisses();
}
if (damage > 0 && !chr.isHidden()) {
if (attacker != null && damagefrom == -1 && chr.getBuffedValue(MapleBuffStat.POWERGUARD) != null) {
// PG works on bosses, but only at half of the rate.
int bouncedamage = (int) (damage * (chr.getBuffedValue(MapleBuffStat.POWERGUARD).doubleValue() / (attacker.isBoss() ? 200 : 100)));
bouncedamage = Math.min(bouncedamage, attacker.getMaxHp() / 10);
damage -= bouncedamage;
map.damageMonster(chr, attacker, bouncedamage);
map.broadcastMessage(chr, MaplePacketCreator.damageMonster(oid, bouncedamage), false, true);
chr.checkMonsterAggro(attacker);
}
if (attacker != null && damagefrom == -1 && chr.getBuffedValue(MapleBuffStat.BODY_PRESSURE) != null) {
Skill skill = SkillFactory.getSkill(Aran.BODY_PRESSURE);
final MapleStatEffect eff = skill.getEffect(chr.getSkillLevel(skill));
if (!attacker.alreadyBuffedStats().contains(MonsterStatus.NEUTRALISE)) {
if (!attacker.isBoss() && eff.makeChanceResult()) {
attacker.applyStatus(chr, new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.NEUTRALISE, 1), skill, null, false), false, (eff.getDuration() / 10) * 2, false);
}
}
}
if (damagefrom != -3 && damagefrom != -4) {
int achilles = 0;
Skill achilles1 = null;
int jobid = chr.getJob().getId();
if (jobid < 200 && jobid % 10 == 2) {
achilles1 = SkillFactory.getSkill(jobid * 10000 + (jobid == 112 ? 4 : 5));
achilles = chr.getSkillLevel(achilles1);
}
if (achilles != 0 && achilles1 != null) {
damage *= (achilles1.getEffect(achilles).getX() / 1000.0);
}
}
Integer mesoguard = chr.getBuffedValue(MapleBuffStat.MESOGUARD);
if (chr.getBuffedValue(MapleBuffStat.MAGIC_GUARD) != null && mpattack == 0) {
int mploss = (int) (damage * (chr.getBuffedValue(MapleBuffStat.MAGIC_GUARD).doubleValue() / 100.0));
int hploss = damage - mploss;
int curmp = chr.getMp();
if (mploss > curmp) {
hploss += mploss - curmp;
mploss = curmp;
}
chr.addMPHP(-hploss, -mploss);
} else if (mesoguard != null) {
damage = Math.round(damage / 2);
int mesoloss = (int) (damage * (mesoguard.doubleValue() / 100.0));
if (chr.getMeso() < mesoloss) {
chr.gainMeso(-chr.getMeso(), false);
chr.cancelBuffStats(MapleBuffStat.MESOGUARD);
} else {
chr.gainMeso(-mesoloss, false);
}
chr.addMPHP(-damage, -mpattack);
} else {
if (chr.getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null) {
if (chr.getBuffedValue(MapleBuffStat.MONSTER_RIDING).intValue() == Corsair.BATTLE_SHIP) {
chr.decreaseBattleshipHp(damage);
}
}
chr.addMPHP(-damage, -mpattack);
}
}
if (!chr.isHidden()) {
map.broadcastMessage(chr, MaplePacketCreator.damagePlayer(damagefrom, monsteridfrom, chr.getId(), damage, fake, direction, is_pgmr, pgmr, is_pg, oid, pos_x, pos_y), false);
chr.checkBerserk(true);
} else {
map.broadcastGMMessage(chr, MaplePacketCreator.damagePlayer(damagefrom, monsteridfrom, chr.getId(), damage, fake, direction, is_pgmr, pgmr, is_pg, oid, pos_x, pos_y), false);
chr.checkBerserk(false);
}
if (GameConstants.isDojo(map.getId())) {
chr.setDojoEnergy(chr.getDojoEnergy() + ServerConstants.DOJO_ENERGY_DMG);
c.announce(MaplePacketCreator.getEnergy("energy", chr.getDojoEnergy()));
}
for (MapleCharacter player : banishPlayers) {
// chill, if this list ever gets non-empty an attacker does exist, trust me :)
player.changeMapBanish(attacker.getBanish().getMap(), attacker.getBanish().getPortal(), attacker.getBanish().getMsg());
}
}
use of server.life.MapleMonster in project HeavenMS by ronancpl.
the class UseCatchItemHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
AutobanManager abm = chr.getAutobanManager();
abm.setTimestamp(5, slea.readInt(), 3);
slea.readShort();
int itemId = slea.readInt();
int monsterid = slea.readInt();
MapleMonster mob = chr.getMap().getMonsterByOid(monsterid);
if (chr.getInventory(ItemConstants.getInventoryType(itemId)).countById(itemId) <= 0) {
return;
}
if (mob == null) {
return;
}
switch(itemId) {
case 2270000:
if (mob.getId() == 9300101) {
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);
MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, true);
MapleInventoryManipulator.addById(c, 1902000, (short) 1, "", -1);
}
c.announce(MaplePacketCreator.enableActions());
break;
case 2270001:
if (mob.getId() == 9500197) {
if ((abm.getLastSpam(10) + 1000) < System.currentTimeMillis()) {
if (mob.getHp() < ((mob.getMaxHp() / 10) * 4)) {
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);
MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, true);
MapleInventoryManipulator.addById(c, 4031830, (short) 1, "", -1);
} else {
abm.spam(10);
c.announce(MaplePacketCreator.catchMessage(0));
}
}
c.announce(MaplePacketCreator.enableActions());
}
break;
case 2270002:
if (mob.getId() == 9300157) {
if ((abm.getLastSpam(10) + 800) < System.currentTimeMillis()) {
if (mob.getHp() < ((mob.getMaxHp() / 10) * 4)) {
if (Math.random() < 0.5) {
// 50% chance
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);
MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, true);
MapleInventoryManipulator.addById(c, 4031868, (short) 1, "", -1);
} else {
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 0));
}
abm.spam(10);
} else {
c.announce(MaplePacketCreator.catchMessage(0));
}
}
c.announce(MaplePacketCreator.enableActions());
}
break;
case 2270003:
if (mob.getId() == 9500320) {
if (mob.getHp() < ((mob.getMaxHp() / 10) * 4)) {
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);
MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, true);
MapleInventoryManipulator.addById(c, 4031887, (short) 1, "", -1);
} else {
c.announce(MaplePacketCreator.catchMessage(0));
}
}
c.announce(MaplePacketCreator.enableActions());
break;
case 2270005:
if (mob.getId() == 9300187) {
if (mob.getHp() < ((mob.getMaxHp() / 10) * 3)) {
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);
MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, true);
MapleInventoryManipulator.addById(c, 2109001, (short) 1, "", -1);
} else {
c.announce(MaplePacketCreator.catchMessage(0));
}
}
c.announce(MaplePacketCreator.enableActions());
break;
case 2270006:
if (mob.getId() == 9300189) {
if (mob.getHp() < ((mob.getMaxHp() / 10) * 3)) {
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);
MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, true);
MapleInventoryManipulator.addById(c, 2109002, (short) 1, "", -1);
} else {
c.announce(MaplePacketCreator.catchMessage(0));
}
}
c.announce(MaplePacketCreator.enableActions());
break;
case 2270007:
if (mob.getId() == 9300191) {
if (mob.getHp() < ((mob.getMaxHp() / 10) * 3)) {
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);
MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, true);
MapleInventoryManipulator.addById(c, 2109003, (short) 1, "", -1);
} else {
c.announce(MaplePacketCreator.catchMessage(0));
}
}
c.announce(MaplePacketCreator.enableActions());
break;
case 2270004:
if (mob.getId() == 9300175) {
if (mob.getHp() < ((mob.getMaxHp() / 10) * 4)) {
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);
MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, true);
MapleInventoryManipulator.addById(c, 4001169, (short) 1, "", -1);
} else {
c.announce(MaplePacketCreator.catchMessage(0));
}
}
c.announce(MaplePacketCreator.enableActions());
break;
case 2270008:
if (mob.getId() == 9500336) {
if ((abm.getLastSpam(10) + 3000) < System.currentTimeMillis()) {
abm.spam(10);
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);
MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, true);
MapleInventoryManipulator.addById(c, 2022323, (short) 1, "", -1);
} else {
chr.message("You cannot use the Fishing Net yet.");
}
c.announce(MaplePacketCreator.enableActions());
}
break;
default:
}
}
use of server.life.MapleMonster in project HeavenMS by ronancpl.
the class MapleMap method killMonster.
public void killMonster(final MapleMonster monster, final MapleCharacter chr, final boolean withDrops, int animation) {
if (monster == null)
return;
if (chr == null) {
spawnedMonstersOnMap.decrementAndGet();
monster.setHpZero();
removeMapObject(monster);
monster.dispatchMonsterKilled(false);
broadcastMessage(MaplePacketCreator.killMonster(monster.getObjectId(), animation), monster.getPosition());
return;
}
if (monster.getStats().getLevel() >= chr.getLevel() + 30 && !chr.isGM()) {
AutobanFactory.GENERAL.alert(chr, " for killing a " + monster.getName() + " which is over 30 levels higher.");
}
/*if (chr.getQuest(MapleQuest.getInstance(29400)).getStatus().equals(MapleQuestStatus.Status.STARTED)) {
if (chr.getLevel() >= 120 && monster.getStats().getLevel() >= 120) {
//FIX MEDAL SHET
} else if (monster.getStats().getLevel() >= chr.getLevel()) {
}
}*/
int buff = monster.getBuffToGive();
if (buff > -1) {
MapleItemInformationProvider mii = MapleItemInformationProvider.getInstance();
for (MapleMapObject mmo : this.getPlayers()) {
MapleCharacter character = (MapleCharacter) mmo;
if (character.isAlive()) {
MapleStatEffect statEffect = mii.getItemEffect(buff);
character.getClient().announce(MaplePacketCreator.showOwnBuffEffect(buff, 1));
broadcastMessage(character, MaplePacketCreator.showBuffeffect(character.getId(), buff, 1), false);
statEffect.applyTo(character);
}
}
}
spawnedMonstersOnMap.decrementAndGet();
monster.setHpZero();
removeMapObject(monster);
if (monster.getCP() > 0 && chr.getCarnival() != null) {
chr.getCarnivalParty().addCP(chr, monster.getCP());
chr.announce(MaplePacketCreator.updateCP(chr.getCP(), chr.getObtainedCP()));
broadcastMessage(MaplePacketCreator.updatePartyCP(chr.getCarnivalParty()));
// they drop items too ):
}
if (monster.getId() >= 8800003 && monster.getId() <= 8800010) {
boolean makeZakReal = true;
Collection<MapleMapObject> objects = getMapObjects();
for (MapleMapObject object : objects) {
MapleMonster mons = getMonsterByOid(object.getObjectId());
if (mons != null) {
if (mons.getId() >= 8800003 && mons.getId() <= 8800010) {
makeZakReal = false;
break;
}
}
}
if (makeZakReal) {
MapleMap map = chr.getMap();
for (MapleMapObject object : objects) {
MapleMonster mons = map.getMonsterByOid(object.getObjectId());
if (mons != null) {
if (mons.getId() == 8800000) {
makeMonsterReal(mons);
updateMonsterController(mons);
break;
}
}
}
}
}
MapleCharacter dropOwner = monster.killBy(chr);
if (withDrops && !monster.dropsDisabled()) {
if (dropOwner == null) {
dropOwner = chr;
}
dropFromMonster(dropOwner, monster, false);
}
if (monster.hasBossHPBar()) {
for (MapleCharacter mc : this.getAllPlayers()) {
if (mc.getTargetHpBarHash() == monster.hashCode()) {
mc.resetPlayerAggro();
}
}
}
monster.dispatchMonsterKilled(true);
broadcastMessage(MaplePacketCreator.killMonster(monster.getObjectId(), animation), monster.getPosition());
}
use of server.life.MapleMonster in project HeavenMS by ronancpl.
the class MapleMap method sendObjectPlacement.
private void sendObjectPlacement(MapleClient mapleClient) {
MapleCharacter chr = mapleClient.getPlayer();
Collection<MapleMapObject> objects;
objectRLock.lock();
try {
objects = Collections.unmodifiableCollection(mapobjects.values());
} finally {
objectRLock.unlock();
}
for (MapleMapObject o : objects) {
if (o.getType() == MapleMapObjectType.SUMMON) {
MapleSummon summon = (MapleSummon) o;
if (summon.getOwner() == chr) {
if (chr.isSummonsEmpty() || !chr.containsSummon(summon)) {
objectWLock.lock();
try {
mapobjects.remove(o.getObjectId());
} finally {
objectWLock.unlock();
}
continue;
}
}
}
if (isNonRangedType(o.getType())) {
o.sendSpawnData(mapleClient);
} else if (o.getType() == MapleMapObjectType.MONSTER) {
updateMonsterController((MapleMonster) o);
}
}
if (chr != null) {
for (MapleMapObject o : getMapObjectsInRange(chr.getPosition(), getRangedDistance(), rangedMapobjectTypes)) {
if (o.getType() == MapleMapObjectType.REACTOR) {
if (((MapleReactor) o).isAlive()) {
o.sendSpawnData(chr.getClient());
chr.addVisibleMapObject(o);
}
} else {
o.sendSpawnData(chr.getClient());
chr.addVisibleMapObject(o);
}
}
}
}
use of server.life.MapleMonster in project HeavenMS by ronancpl.
the class MapleMap method damageMonster.
public boolean damageMonster(final MapleCharacter chr, final MapleMonster monster, final int damage) {
if (monster.getId() == 8800000) {
for (MapleMapObject object : chr.getMap().getMapObjects()) {
MapleMonster mons = chr.getMap().getMonsterByOid(object.getObjectId());
if (mons != null) {
if (mons.getId() >= 8800003 && mons.getId() <= 8800010) {
return true;
}
}
}
}
if (monster.isAlive()) {
boolean killed = false;
monster.lockMonster();
try {
if (!monster.isAlive()) {
return false;
}
if (damage > 0) {
monster.damage(chr, damage, false);
if (!monster.isAlive()) {
// monster just died
killed = true;
}
}
} finally {
monster.unlockMonster();
}
if (monster.getStats().selfDestruction() != null && monster.getStats().selfDestruction().getHp() > -1) {
// should work ;p
if (monster.getHp() <= monster.getStats().selfDestruction().getHp()) {
killMonster(monster, chr, true, monster.getStats().selfDestruction().getAction());
return true;
}
}
if (killed) {
killMonster(monster, chr, true);
}
return true;
}
return false;
}
Aggregations