TakeDamageHandler.java
上传用户:gwt600
上传日期:2021-06-03
资源大小:704k
文件大小:11k
源码类别:

游戏

开发平台:

Java

  1. /*
  2. This file is part of the OdinMS Maple Story Server
  3. Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
  4. Matthias Butz <matze@odinms.de>
  5. Jan Christian Meyer <vimes@odinms.de>
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Affero General Public License version 3
  8. as published by the Free Software Foundation. You may not use, modify
  9. or distribute this program under any other version of the
  10. GNU Affero General Public License.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18. package net.sf.odinms.net.channel.handler;
  19. import java.util.Collections;
  20. import net.sf.odinms.client.ISkill;
  21. import net.sf.odinms.client.MapleBuffStat;
  22. import net.sf.odinms.client.MapleCharacter;
  23. import net.sf.odinms.client.MapleStat;
  24. import net.sf.odinms.client.MapleClient;
  25. import net.sf.odinms.client.SkillFactory;
  26. import net.sf.odinms.client.status.MonsterStatus;
  27. import net.sf.odinms.client.status.MonsterStatusEffect;
  28. import net.sf.odinms.net.MaplePacket;
  29. import net.sf.odinms.server.AutobanManager;
  30. import net.sf.odinms.client.MapleInventoryType;
  31. import net.sf.odinms.net.AbstractMaplePacketHandler;
  32. import net.sf.odinms.server.life.MapleMonster;
  33. import net.sf.odinms.server.life.MobAttackInfo;
  34. import net.sf.odinms.server.life.MobAttackInfoFactory;
  35. import net.sf.odinms.server.life.MobSkill;
  36. import net.sf.odinms.server.life.MobSkillFactory;
  37. import net.sf.odinms.server.maps.MapleMapObject;
  38. import net.sf.odinms.server.maps.MapleMapObjectType;
  39. import net.sf.odinms.server.maps.MapleMist;
  40. import net.sf.odinms.tools.MaplePacketCreator;
  41. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  42. public class TakeDamageHandler extends AbstractMaplePacketHandler {
  43.     private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TakeDamageHandler.class);
  44.     @Override
  45.     public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
  46.         MapleCharacter player = c.getPlayer();
  47.         slea.readInt();
  48.         int damagefrom = slea.readByte();
  49.         slea.readByte();
  50.         int damage = slea.readInt();
  51.         int oid = 0;
  52.         int monsteridfrom = 0;
  53.         int pgmr = 0;
  54.         int direction = 0;
  55.         int pos_x = 0;
  56.         int pos_y = 0;
  57.         int fake = 0;
  58.         boolean is_pgmr = false;
  59.         boolean is_pg = true;
  60.         int mpattack = 0;
  61.         MapleMonster attacker = null;
  62.         if (damagefrom != -2) {
  63.             monsteridfrom = slea.readInt();
  64.             oid = slea.readInt();
  65.             attacker = (MapleMonster) player.getMap().getMapObject(oid);
  66.             direction = slea.readByte();
  67.         }
  68.         if (damagefrom != -1 && damagefrom != -2 && attacker != null) {
  69.             MobAttackInfo attackInfo = MobAttackInfoFactory.getMobAttackInfo(attacker, damagefrom);
  70.             if (attackInfo.isDeadlyAttack()) {
  71.                 mpattack = player.getMp() - 1;
  72.             }
  73.             mpattack += attackInfo.getMpBurn();
  74.             MobSkill skill = MobSkillFactory.getMobSkill(attackInfo.getDiseaseSkill(), attackInfo.getDiseaseLevel());
  75.             if (skill != null && damage > 0) {
  76.                 skill.applyEffect(player, attacker, false);
  77.             }
  78.             if (attacker != null) {
  79.                 attacker.setMp(attacker.getMp() - attackInfo.getMpCon());
  80.                 if (player.getBuffedValue(MapleBuffStat.MANA_REFLECTION) != null && damage > 0 && !attacker.isBoss()) {
  81.                     int[] manaReflectSkillId = {2121002, 2221002, 2321002};
  82.                     for (int manaReflect : manaReflectSkillId) {
  83.                         ISkill manaReflectSkill = SkillFactory.getSkill(manaReflect);
  84.                         if (player.isBuffFrom(MapleBuffStat.MANA_REFLECTION, manaReflectSkill) && player.getSkillLevel(manaReflectSkill) > 0 && manaReflectSkill.getEffect(player.getSkillLevel(manaReflectSkill)).makeChanceResult()) {
  85.                             int bouncedamage = (int) (damage * (manaReflectSkill.getEffect(player.getSkillLevel(manaReflectSkill)).getX() / 100));
  86.                             if (bouncedamage > attacker.getMaxHp() * .2) {
  87.                                 bouncedamage = (int) (attacker.getMaxHp() * .2);
  88.                             }
  89.                             player.getMap().damageMonster(player, attacker, bouncedamage);
  90.                             player.getMap().broadcastMessage(player, MaplePacketCreator.damageMonster(oid, bouncedamage), true);
  91.                             player.getClient().getSession().write(MaplePacketCreator.showOwnBuffEffect(manaReflect, 5));
  92.                             player.getMap().broadcastMessage(player, MaplePacketCreator.showBuffeffect(player.getId(), manaReflect, 5, (byte) 3), false);
  93.                             break;
  94.                         }
  95.                     }
  96.                 }
  97.             }
  98.         }
  99.         if (damage == -1) {
  100.             int job = (int) (player.getJob().getId() / 10 - 40);
  101.             fake = 4020002 + (job * 100000);
  102.         }
  103.         if (damage < -1 || damage > 60000) {
  104.             AutobanManager.getInstance().addPoints(c, 1000, 60000, "Taking abnormal amounts of damage from " + monsteridfrom + ": " + damage);
  105.             return;
  106.         }
  107.         player.getCheatTracker().checkTakeDamage();
  108.         if (damage > 0) {
  109.             player.getCheatTracker().setAttacksWithoutHit(0);
  110.             player.getCheatTracker().resetHPRegen();
  111.         }
  112.         if (attacker != null) {
  113. if (attacker.getTeam() == c.getPlayer().getTeam() &&
  114. c.getPlayer().getMap().isCPQMap()) {
  115. return;
  116. }
  117. }
  118.         boolean smokescreen = false;
  119.         for (MapleMapObject mmo : player.getMap().getMapObjects()) {
  120.             if (mmo instanceof MapleMist) {
  121.                 MapleMist mist = (MapleMist) mmo;
  122.                 if (mist.getSourceSkill().getId() == 4221006) {
  123.                     for (MapleMapObject mmoplayer : player.getMap().getMapObjectsInBox(mist.getBox(), Collections.singletonList(MapleMapObjectType.PLAYER))) {
  124.                         if (player == (MapleCharacter) mmoplayer) {
  125.                             smokescreen = true;
  126.                         }
  127.                     }
  128.                 }
  129.             }
  130.         }
  131.         if (damage > 0 && !player.isHidden() && !smokescreen ) {
  132.             if (attacker != null && !attacker.isBoss()) {
  133.                 if (damagefrom == -1 && player.getBuffedValue(MapleBuffStat.POWERGUARD) != null) {
  134.                     int bouncedamage = (int) (damage * (player.getBuffedValue(MapleBuffStat.POWERGUARD).doubleValue() / 100));
  135.                     bouncedamage = Math.min(bouncedamage, attacker.getMaxHp() / 10);
  136.                     player.getMap().damageMonster(player, attacker, bouncedamage);
  137.                     damage -= bouncedamage;
  138.                     player.getMap().broadcastMessage(player, MaplePacketCreator.damageMonster(oid, bouncedamage), true, true);
  139.                     player.checkMonsterAggro(attacker);
  140.                 }
  141.             }
  142.             if (damagefrom != -2) {
  143.                 Integer achilles = 0;
  144.                 ISkill achilles1 = null;
  145.                 switch (player.getJob().getId()) {
  146.                     case 112:
  147.                         achilles = player.getSkillLevel(SkillFactory.getSkill(1120004));
  148.                         achilles1 = SkillFactory.getSkill(1120004);
  149.                         break;
  150.                     case 122:
  151.                         achilles = player.getSkillLevel(SkillFactory.getSkill(1220005));
  152.                         achilles1 = SkillFactory.getSkill(1220005);
  153.                         break;
  154.                     case 132:
  155.                         achilles = player.getSkillLevel(SkillFactory.getSkill(1320005));
  156.                         achilles1 = SkillFactory.getSkill(1320005);
  157.                         break;
  158.                 }
  159.                 if (achilles != 0 && achilles1 != null) {
  160.                     double multiplier = achilles1.getEffect(achilles).getX() / 1000.0;
  161.                     int newdamage = (int) (multiplier * damage);
  162.                     damage = newdamage;
  163.                 }
  164.             }
  165.             Integer mesoguard = player.getBuffedValue(MapleBuffStat.MESOGUARD);
  166.             if (player.getBuffedValue(MapleBuffStat.MAGIC_GUARD) != null && mpattack == 0) {
  167.                 int mploss = (int) (damage * (player.getBuffedValue(MapleBuffStat.MAGIC_GUARD).doubleValue() / 100.0));
  168.                 int hploss = damage - mploss;
  169.                 if (mploss > player.getMp()) {
  170.                     hploss += mploss - player.getMp();
  171.                     mploss = player.getMp();
  172.                 }
  173.                 player.addMPHP(-hploss, -mploss);
  174.             } else if (mesoguard != null) {
  175.                 damage = (damage % 2 == 0) ? damage / 2 : (damage / 2) + 1;
  176.                 int mesoloss = (int) (damage * (mesoguard.doubleValue() / 100.0));
  177.                 if (player.getMeso() < mesoloss) {
  178.                     player.gainMeso(-player.getMeso(), false);
  179.                     player.cancelBuffStats(MapleBuffStat.MESOGUARD);
  180.                 } else {
  181.                     player.gainMeso(-mesoloss, false);
  182.                 }
  183.                 player.addMPHP(-damage, -mpattack);
  184.             } else {
  185.                 player.addMPHP(-damage, -mpattack);
  186.             }
  187.         }
  188.         if (!player.isHidden() && !smokescreen) {
  189.             if (monsteridfrom == 9300166) {
  190.                 player.setBombPoints(player.getBombPoints() - 1);
  191.                 if (player.getBombPoints() < 1) {
  192.                     player.setHp(0);
  193.                     player.updateSingleStat(MapleStat.HP, 0);
  194.                     player.setBombPoints(5);
  195.                     MaplePacket packet = MaplePacketCreator.serverNotice(0, "[Update] Player " + player.getName() + " is dead");
  196.                     c.getPlayer().getMap().broadcastMessage(packet);
  197.                     return;
  198.                 } else {
  199.                     MaplePacket packet = MaplePacketCreator.serverNotice(0, "[Update] Player " + player.getName() + " now has " + player.getBombPoints() + " points");
  200.                     c.getPlayer().getMap().broadcastMessage(packet);
  201.                     return;
  202.                 }
  203.             } else {
  204.                 player.getMap().broadcastMessage(player, MaplePacketCreator.damagePlayer(damagefrom, monsteridfrom, player.getId(), damage, fake, direction, is_pgmr, pgmr, is_pg, oid, pos_x, pos_y), false);
  205.                 player.checkBerserk();
  206.             }
  207.         }
  208.     }
  209. }