use of server.life.MobSkill in project HeavenMS by ronancpl.
the class MoveLifeHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int objectid = slea.readInt();
short moveid = slea.readShort();
MapleMapObject mmo = c.getPlayer().getMap().getMapObject(objectid);
if (mmo == null || mmo.getType() != MapleMapObjectType.MONSTER) {
return;
}
MapleMonster monster = (MapleMonster) mmo;
List<LifeMovementFragment> res = null;
List<MapleCharacter> banishPlayers = new ArrayList<>();
byte pNibbles = slea.readByte();
byte rawActivity = slea.readByte();
byte useSkillId = slea.readByte();
byte useSkillLevel = slea.readByte();
short pOption = slea.readShort();
slea.skip(8);
if (rawActivity >= 0) {
rawActivity = (byte) (rawActivity & 0xFF >> 1);
}
boolean isAttack = inRangeInclusive(rawActivity, 12, 20);
boolean isSkill = inRangeInclusive(rawActivity, 21, 25);
byte attackId = (byte) (isAttack ? rawActivity - 12 : -1);
boolean nextMovementCouldBeSkill = (pNibbles & 0x0F) != 0;
boolean pUnk = (pNibbles & 0xF0) != 0;
int nextCastSkill = useSkillId;
int nextCastSkillLevel = useSkillLevel;
MobSkill toUse = null;
int percHpLeft = (int) (((float) monster.getHp() / monster.getMaxHp()) * 100);
if (nextMovementCouldBeSkill && monster.getNoSkills() > 0) {
int Random = Randomizer.nextInt(monster.getNoSkills());
Pair<Integer, Integer> skillToUse = monster.getSkills().get(Random);
nextCastSkill = skillToUse.getLeft();
nextCastSkillLevel = skillToUse.getRight();
toUse = MobSkillFactory.getMobSkill(nextCastSkill, nextCastSkillLevel);
if (isSkill || isAttack) {
if (nextCastSkill != toUse.getSkillId() || nextCastSkillLevel != toUse.getSkillLevel()) {
// toUse.resetAnticipatedSkill();
return;
} else if (toUse.getHP() < percHpLeft) {
toUse = null;
} else if (monster.canUseSkill(toUse)) {
toUse.applyEffect(c.getPlayer(), monster, true, banishPlayers);
// System.out.println("Applied: " + nextCastSkill + " Level: " + nextCastSkillLevel);
}
} else {
MobAttackInfo mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId);
// System.out.println("Attacked");
}
}
slea.readByte();
// whatever
slea.readInt();
// hmm.. startpos?
short start_x = slea.readShort();
// hmm...
short start_y = slea.readShort();
Point startPos = new Point(start_x, start_y);
res = parseMovement(slea);
if (monster.getController() != c.getPlayer()) {
if (monster.isAttackedBy(c.getPlayer())) {
monster.switchController(c.getPlayer(), true);
} else {
return;
}
} else if (rawActivity == -1 && monster.isControllerKnowsAboutAggro() && !monster.isMobile() && !monster.isFirstAttack()) {
monster.setControllerHasAggro(false);
monster.setControllerKnowsAboutAggro(false);
}
boolean aggro = monster.isControllerHasAggro();
if (toUse != null) {
c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro, toUse.getSkillId(), toUse.getSkillLevel()));
} else {
c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro));
}
if (aggro) {
monster.setControllerKnowsAboutAggro(true);
}
if (res != null) {
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.moveMonster(objectid, nextMovementCouldBeSkill, rawActivity, useSkillId, useSkillLevel, pOption, startPos, res), monster.getPosition());
updatePosition(res, monster, -1);
c.getPlayer().getMap().moveMonster(monster, monster.getPosition());
}
for (MapleCharacter chr : banishPlayers) {
chr.changeMapBanish(monster.getBanish().getMap(), monster.getBanish().getPortal(), monster.getBanish().getMsg());
}
}
use of server.life.MobSkill in project HeavenMS by ronancpl.
the class AbstractDealDamageHandler method applyAttack.
protected synchronized void applyAttack(AttackInfo attack, final MapleCharacter player, int attackCount) {
Skill theSkill = null;
MapleStatEffect attackEffect = null;
final int job = player.getJob().getId();
try {
if (player.isBanned()) {
return;
}
if (attack.skill != 0) {
// returns back the skill id if its not a hidden skill so we are gucci
theSkill = SkillFactory.getSkill(GameConstants.getHiddenSkill(attack.skill));
attackEffect = attack.getAttackEffect(player, theSkill);
if (attackEffect == null) {
player.getClient().announce(MaplePacketCreator.enableActions());
return;
}
if (player.getMp() < attackEffect.getMpCon()) {
AutobanFactory.MPCON.addPoint(player.getAutobanManager(), "Skill: " + attack.skill + "; Player MP: " + player.getMp() + "; MP Needed: " + attackEffect.getMpCon());
}
if (attack.skill != Cleric.HEAL) {
if (player.isAlive()) {
if (// Poison Bomb
attack.skill == NightWalker.POISON_BOMB)
attackEffect.applyTo(player, new Point(attack.position.x, attack.position.y));
else if (// prevent BP refreshing
attack.skill != Aran.BODY_PRESSURE)
attackEffect.applyTo(player);
} else {
player.getClient().announce(MaplePacketCreator.enableActions());
}
}
int mobCount = attackEffect.getMobCount();
if (attack.skill == DawnWarrior.FINAL_ATTACK || attack.skill == Page.FINAL_ATTACK_BW || attack.skill == Page.FINAL_ATTACK_SWORD || attack.skill == Fighter.FINAL_ATTACK_SWORD || attack.skill == Fighter.FINAL_ATTACK_AXE || attack.skill == Spearman.FINAL_ATTACK_SPEAR || attack.skill == Spearman.FINAL_ATTACK_POLEARM || attack.skill == WindArcher.FINAL_ATTACK || attack.skill == DawnWarrior.FINAL_ATTACK || attack.skill == Hunter.FINAL_ATTACK || attack.skill == Crossbowman.FINAL_ATTACK) {
// :(
mobCount = 15;
}
if (attack.skill == Aran.HIDDEN_FULL_DOUBLE || attack.skill == Aran.HIDDEN_FULL_TRIPLE || attack.skill == Aran.HIDDEN_OVER_DOUBLE || attack.skill == Aran.HIDDEN_OVER_TRIPLE) {
mobCount = 12;
}
if (attack.numAttacked > mobCount) {
AutobanFactory.MOB_COUNT.autoban(player, "Skill: " + attack.skill + "; Count: " + attack.numAttacked + " Max: " + attackEffect.getMobCount());
return;
}
}
if (!player.isAlive()) {
return;
}
// WTF IS THIS F3,1
/*if (attackCount != attack.numDamage && attack.skill != ChiefBandit.MESO_EXPLOSION && attack.skill != NightWalker.VAMPIRE && attack.skill != WindArcher.WIND_SHOT && attack.skill != Aran.COMBO_SMASH && attack.skill != Aran.COMBO_FENRIR && attack.skill != Aran.COMBO_TEMPEST && attack.skill != NightLord.NINJA_AMBUSH && attack.skill != Shadower.NINJA_AMBUSH) {
return;
}*/
int totDamage = 0;
final MapleMap map = player.getMap();
if (attack.skill == ChiefBandit.MESO_EXPLOSION) {
int delay = 0;
for (Integer oned : attack.allDamage.keySet()) {
MapleMapObject mapobject = map.getMapObject(oned.intValue());
if (mapobject != null && mapobject.getType() == MapleMapObjectType.ITEM) {
final MapleMapItem mapitem = (MapleMapItem) mapobject;
if (mapitem.getMeso() == 0) {
// Maybe it is possible some how?
return;
}
synchronized (mapitem) {
if (mapitem.isPickedUp()) {
return;
}
TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
map.pickItemDrop(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 4, 0), mapitem);
}
}, delay);
delay += 100;
}
} else if (mapobject != null && mapobject.getType() != MapleMapObjectType.MONSTER) {
return;
}
}
}
for (Integer oned : attack.allDamage.keySet()) {
final MapleMonster monster = map.getMonsterByOid(oned.intValue());
if (monster != null) {
double distance = player.getPosition().distanceSq(monster.getPosition());
double distanceToDetect = 200000.0;
if (attack.ranged)
distanceToDetect += 400000;
if (attack.magic)
distanceToDetect += 200000;
if (player.getJob().isA(MapleJob.ARAN1))
// Arans have extra range over normal warriors.
distanceToDetect += 200000;
if (attack.skill == Aran.COMBO_SMASH || attack.skill == Aran.BODY_PRESSURE)
distanceToDetect += 40000;
else if (attack.skill == Bishop.GENESIS || attack.skill == ILArchMage.BLIZZARD || attack.skill == FPArchMage.METEOR_SHOWER)
distanceToDetect += 275000;
else if (attack.skill == Hero.BRANDISH || attack.skill == DragonKnight.SPEAR_CRUSHER || attack.skill == DragonKnight.POLE_ARM_CRUSHER)
distanceToDetect += 40000;
else if (attack.skill == DragonKnight.DRAGON_ROAR || attack.skill == SuperGM.SUPER_DRAGON_ROAR)
distanceToDetect += 250000;
else if (attack.skill == Shadower.BOOMERANG_STEP)
distanceToDetect += 60000;
if (distance > distanceToDetect) {
AutobanFactory.DISTANCE_HACK.alert(player, "Distance Sq to monster: " + distance + " SID: " + attack.skill + " MID: " + monster.getId());
}
int totDamageToOneMonster = 0;
List<Integer> onedList = attack.allDamage.get(oned);
for (Integer eachd : onedList) {
if (eachd < 0)
eachd += Integer.MAX_VALUE;
totDamageToOneMonster += eachd;
}
totDamage += totDamageToOneMonster;
player.checkMonsterAggro(monster);
if (player.getBuffedValue(MapleBuffStat.PICKPOCKET) != null && (attack.skill == 0 || attack.skill == Rogue.DOUBLE_STAB || attack.skill == Bandit.SAVAGE_BLOW || attack.skill == ChiefBandit.ASSAULTER || attack.skill == ChiefBandit.BAND_OF_THIEVES || attack.skill == Shadower.ASSASSINATE || attack.skill == Shadower.TAUNT || attack.skill == Shadower.BOOMERANG_STEP)) {
Skill pickpocket = SkillFactory.getSkill(ChiefBandit.PICKPOCKET);
int picklv = (player.isGM()) ? pickpocket.getMaxLevel() : player.getSkillLevel(pickpocket);
if (picklv > 0) {
int delay = 0;
final int maxmeso = player.getBuffedValue(MapleBuffStat.PICKPOCKET).intValue();
for (Integer eachd : onedList) {
eachd += Integer.MAX_VALUE;
if (pickpocket.getEffect(picklv).makeChanceResult()) {
final Integer eachdf;
if (eachd < 0)
eachdf = eachd + Integer.MAX_VALUE;
else
eachdf = eachd;
TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
player.getMap().spawnMesoDrop(Math.min((int) Math.max(((double) eachdf / (double) 20000) * (double) maxmeso, (double) 1), maxmeso), new Point((int) (monster.getPosition().getX() + Randomizer.nextInt(100) - 50), (int) (monster.getPosition().getY())), monster, player, true, (byte) 2);
}
}, delay);
delay += 100;
}
}
}
} else if (attack.skill == Marauder.ENERGY_DRAIN || attack.skill == ThunderBreaker.ENERGY_DRAIN || attack.skill == NightWalker.VAMPIRE || attack.skill == Assassin.DRAIN) {
player.addHP(Math.min(monster.getMaxHp(), Math.min((int) ((double) totDamage * (double) SkillFactory.getSkill(attack.skill).getEffect(player.getSkillLevel(SkillFactory.getSkill(attack.skill))).getX() / 100.0), player.getMaxHp() / 2)));
} else if (attack.skill == Bandit.STEAL) {
Skill steal = SkillFactory.getSkill(Bandit.STEAL);
if (monster.getStolen().size() < 1) {
// One steal per mob <3
if (steal.getEffect(player.getSkillLevel(steal)).makeChanceResult()) {
MapleMonsterInformationProvider mi = MapleMonsterInformationProvider.getInstance();
List<Integer> dropPool = mi.retrieveDropPool(monster.getId());
if (!dropPool.isEmpty()) {
Integer rndPool = (int) Math.floor(Math.random() * dropPool.get(dropPool.size() - 1));
int i = 0;
while (rndPool >= dropPool.get(i)) i++;
List<MonsterDropEntry> toSteal = new ArrayList<>();
toSteal.add(mi.retrieveDrop(monster.getId()).get(i));
player.getMap().dropItemsFromMonster(toSteal, player, monster);
monster.addStolen(toSteal.get(0).itemId);
}
}
}
} else if (attack.skill == FPArchMage.FIRE_DEMON) {
monster.setTempEffectiveness(Element.ICE, ElementalEffectiveness.WEAK, SkillFactory.getSkill(FPArchMage.FIRE_DEMON).getEffect(player.getSkillLevel(SkillFactory.getSkill(FPArchMage.FIRE_DEMON))).getDuration() * 1000);
} else if (attack.skill == ILArchMage.ICE_DEMON) {
monster.setTempEffectiveness(Element.FIRE, ElementalEffectiveness.WEAK, SkillFactory.getSkill(ILArchMage.ICE_DEMON).getEffect(player.getSkillLevel(SkillFactory.getSkill(ILArchMage.ICE_DEMON))).getDuration() * 1000);
} else if (attack.skill == Outlaw.HOMING_BEACON || attack.skill == Corsair.BULLSEYE) {
player.setMarkedMonster(monster.getObjectId());
player.announce(MaplePacketCreator.giveBuff(1, attack.skill, Collections.singletonList(new Pair<>(MapleBuffStat.HOMING_BEACON, monster.getObjectId()))));
}
if (job == 2111 || job == 2112) {
if (player.getBuffedValue(MapleBuffStat.WK_CHARGE) != null) {
Skill snowCharge = SkillFactory.getSkill(Aran.SNOW_CHARGE);
if (totDamageToOneMonster > 0) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, snowCharge.getEffect(player.getSkillLevel(snowCharge)).getX()), snowCharge, null, false);
monster.applyStatus(player, monsterStatusEffect, false, snowCharge.getEffect(player.getSkillLevel(snowCharge)).getY() * 1000);
}
}
}
if (player.getBuffedValue(MapleBuffStat.HAMSTRING) != null) {
Skill hamstring = SkillFactory.getSkill(Bowmaster.HAMSTRING);
if (hamstring.getEffect(player.getSkillLevel(hamstring)).makeChanceResult()) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, hamstring.getEffect(player.getSkillLevel(hamstring)).getX()), hamstring, null, false);
monster.applyStatus(player, monsterStatusEffect, false, hamstring.getEffect(player.getSkillLevel(hamstring)).getY() * 1000);
}
}
if (player.getBuffedValue(MapleBuffStat.SLOW) != null) {
Skill slow = SkillFactory.getSkill(Evan.SLOW);
if (slow.getEffect(player.getSkillLevel(slow)).makeChanceResult()) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, slow.getEffect(player.getSkillLevel(slow)).getX()), slow, null, false);
monster.applyStatus(player, monsterStatusEffect, false, slow.getEffect(player.getSkillLevel(slow)).getY() * 60 * 1000);
}
}
if (player.getBuffedValue(MapleBuffStat.BLIND) != null) {
Skill blind = SkillFactory.getSkill(Marksman.BLIND);
if (blind.getEffect(player.getSkillLevel(blind)).makeChanceResult()) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.ACC, blind.getEffect(player.getSkillLevel(blind)).getX()), blind, null, false);
monster.applyStatus(player, monsterStatusEffect, false, blind.getEffect(player.getSkillLevel(blind)).getY() * 1000);
}
}
if (job == 121 || job == 122) {
for (int charge = 1211005; charge < 1211007; charge++) {
Skill chargeSkill = SkillFactory.getSkill(charge);
if (player.isBuffFrom(MapleBuffStat.WK_CHARGE, chargeSkill)) {
if (totDamageToOneMonster > 0) {
if (charge == WhiteKnight.BW_ICE_CHARGE || charge == WhiteKnight.SWORD_ICE_CHARGE) {
monster.setTempEffectiveness(Element.ICE, ElementalEffectiveness.WEAK, chargeSkill.getEffect(player.getSkillLevel(chargeSkill)).getY() * 1000);
break;
}
if (charge == WhiteKnight.BW_FIRE_CHARGE || charge == WhiteKnight.SWORD_FIRE_CHARGE) {
monster.setTempEffectiveness(Element.FIRE, ElementalEffectiveness.WEAK, chargeSkill.getEffect(player.getSkillLevel(chargeSkill)).getY() * 1000);
break;
}
}
}
}
if (job == 122) {
for (int charge = 1221003; charge < 1221004; charge++) {
Skill chargeSkill = SkillFactory.getSkill(charge);
if (player.isBuffFrom(MapleBuffStat.WK_CHARGE, chargeSkill)) {
if (totDamageToOneMonster > 0) {
monster.setTempEffectiveness(Element.HOLY, ElementalEffectiveness.WEAK, chargeSkill.getEffect(player.getSkillLevel(chargeSkill)).getY() * 1000);
break;
}
}
}
}
} else if (player.getBuffedValue(MapleBuffStat.COMBO_DRAIN) != null) {
Skill skill;
if (player.getBuffedValue(MapleBuffStat.COMBO_DRAIN) != null) {
skill = SkillFactory.getSkill(21100005);
player.setHp(player.getHp() + ((totDamage * skill.getEffect(player.getSkillLevel(skill)).getX()) / 100), true);
player.updateSingleStat(MapleStat.HP, player.getHp());
}
} else if (job == 412 || job == 422 || job == 1411) {
Skill type = SkillFactory.getSkill(player.getJob().getId() == 412 ? 4120005 : (player.getJob().getId() == 1411 ? 14110004 : 4220005));
if (player.getSkillLevel(type) > 0) {
MapleStatEffect venomEffect = type.getEffect(player.getSkillLevel(type));
for (int i = 0; i < attackCount; i++) {
if (venomEffect.makeChanceResult()) {
if (monster.getVenomMulti() < 3) {
monster.setVenomMulti((monster.getVenomMulti() + 1));
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.POISON, 1), type, null, false);
monster.applyStatus(player, monsterStatusEffect, false, venomEffect.getDuration(), true);
}
}
}
}
} else if (job == 521 || job == 522) {
// from what I can gather this is how it should work
if (!monster.isBoss()) {
Skill type = SkillFactory.getSkill(Outlaw.FLAME_THROWER);
if (player.getSkillLevel(type) > 0) {
MapleStatEffect DoT = type.getEffect(player.getSkillLevel(type));
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.POISON, 1), type, null, false);
monster.applyStatus(player, monsterStatusEffect, true, DoT.getDuration(), false);
}
}
} else if (job >= 311 && job <= 322) {
if (!monster.isBoss()) {
Skill mortalBlow;
if (job == 311 || job == 312) {
mortalBlow = SkillFactory.getSkill(Ranger.MORTAL_BLOW);
} else {
mortalBlow = SkillFactory.getSkill(Sniper.MORTAL_BLOW);
}
if (player.getSkillLevel(mortalBlow) > 0) {
MapleStatEffect mortal = mortalBlow.getEffect(player.getSkillLevel(mortalBlow));
if (monster.getHp() <= (monster.getStats().getHp() * mortal.getX()) / 100) {
if (Randomizer.rand(1, 100) <= mortal.getY()) {
monster.getMap().killMonster(monster, player, true);
}
}
}
}
}
if (attack.skill != 0) {
if (attackEffect.getFixDamage() != -1) {
if (totDamageToOneMonster != attackEffect.getFixDamage() && totDamageToOneMonster != 0) {
AutobanFactory.FIX_DAMAGE.autoban(player, String.valueOf(totDamageToOneMonster) + " damage");
}
if (ServerConstants.USE_ULTRA_THREE_SNAILS) {
AbstractPlayerInteraction api = player.getClient().getAbstractPlayerInteraction();
int shellId;
switch(totDamageToOneMonster) {
case 10:
shellId = 4000019;
break;
case 25:
shellId = 4000000;
break;
default:
shellId = 4000016;
}
if (api.haveItem(shellId, 1)) {
api.gainItem(shellId, (short) -1, false);
totDamageToOneMonster *= player.getLevel();
} else {
player.dropMessage(5, "You ran out of shells to activate the hidden power of Three Snails.");
}
}
}
}
if (totDamageToOneMonster > 0 && attackEffect != null && attackEffect.getMonsterStati().size() > 0) {
if (attackEffect.makeChanceResult()) {
monster.applyStatus(player, new MonsterStatusEffect(attackEffect.getMonsterStati(), theSkill, null, false), attackEffect.isPoison(), attackEffect.getDuration());
}
}
if (attack.isHH && !monster.isBoss()) {
map.damageMonster(player, monster, monster.getHp() - 1);
} else if (attack.isHH) {
int HHDmg = (player.calculateMaxBaseDamage(player.getTotalWatk()) * (SkillFactory.getSkill(Paladin.HEAVENS_HAMMER).getEffect(player.getSkillLevel(SkillFactory.getSkill(Paladin.HEAVENS_HAMMER))).getDamage() / 100));
map.damageMonster(player, monster, (int) (Math.floor(Math.random() * (HHDmg / 5) + HHDmg * .8)));
} else if (attack.isTempest && !monster.isBoss()) {
map.damageMonster(player, monster, monster.getHp());
} else if (attack.isTempest) {
int TmpDmg = (player.calculateMaxBaseDamage(player.getTotalWatk()) * (SkillFactory.getSkill(Aran.COMBO_TEMPEST).getEffect(player.getSkillLevel(SkillFactory.getSkill(Aran.COMBO_TEMPEST))).getDamage() / 100));
map.damageMonster(player, monster, (int) (Math.floor(Math.random() * (TmpDmg / 5) + TmpDmg * .8)));
} else {
map.damageMonster(player, monster, totDamageToOneMonster);
}
if (monster.isBuffed(MonsterStatus.WEAPON_REFLECT)) {
for (int i = 0; i < monster.getSkills().size(); i++) {
if (monster.getSkills().get(i).left == 145) {
MobSkill toUse = MobSkillFactory.getMobSkill(monster.getSkills().get(i).left, monster.getSkills().get(i).right);
player.addHP(-toUse.getX());
map.broadcastMessage(player, MaplePacketCreator.damagePlayer(0, monster.getId(), player.getId(), toUse.getX(), 0, 0, false, 0, true, monster.getObjectId(), 0, 0), true);
}
}
}
if (monster.isBuffed(MonsterStatus.MAGIC_REFLECT)) {
for (int i = 0; i < monster.getSkills().size(); i++) {
if (monster.getSkills().get(i).left == 145) {
MobSkill toUse = MobSkillFactory.getMobSkill(monster.getSkills().get(i).left, monster.getSkills().get(i).right);
player.addMP(-toUse.getY());
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of server.life.MobSkill in project HeavenMS by ronancpl.
the class MCBattlefield method applyGuardians.
private void applyGuardians(MapleMonster mob, List<MCGuardian> guardians) {
for (MCGuardian g : guardians) {
MobSkill sk = MobSkillFactory.getMobSkill(g.getMobSkillID(), g.getLevel());
sk.applyEffect(null, mob, true);
}
}
use of server.life.MobSkill in project HeavenMS by ronancpl.
the class MCParty method applyMCSkill.
/**
* Applies a MCSkill to the entire team. This is used on the team's own players
* because it is called when the enemy team uses a debuff/cube of darkness.
* [MENTION=2000183830]para[/MENTION]m skill Skill to apply.
* [MENTION=850422]return[/MENTION] True if skill was applied, false otherwise.
*/
public boolean applyMCSkill(MCSkill skill) {
MobSkill s = MobSkillFactory.getMobSkill(skill.getMobSkillID(), skill.getLevel());
Disease disease = Disease.getType(skill.getMobSkillID());
if (disease == null) {
disease = Disease.DARKNESS;
// HACK: darkness
s = MobSkillFactory.getMobSkill(121, 6);
} else if (disease == Disease.POISON) {
return false;
}
// We only target players on the battlefield map.
if (skill.getTarget() == 2) {
for (Player chr : getMembers()) {
if (MonsterCarnival.isBattlefieldMap(chr.getMapId())) {
chr.giveDebuff(disease, s);
}
}
return true;
} else {
if (getRandomMember() != null) {
getRandomMember().giveDebuff(disease, 1, 30000L, disease.getDisease(), 1);
return true;
} else {
return false;
}
}
}
use of server.life.MobSkill 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());
}
}
Aggregations