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

游戏

开发平台:

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.concurrent.ScheduledFuture;
  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.MapleCharacter.CancelCooldownAction;
  24. import net.sf.odinms.client.MapleClient;
  25. import net.sf.odinms.client.MapleJob;
  26. import net.sf.odinms.client.MapleStat;
  27. import net.sf.odinms.client.SkillFactory;
  28. import net.sf.odinms.client.anticheat.CheatingOffense;
  29. import net.sf.odinms.net.MaplePacket;
  30. import net.sf.odinms.server.MapleStatEffect;
  31. import net.sf.odinms.server.TimerManager;
  32. import net.sf.odinms.server.maps.FakeCharacter;
  33. import net.sf.odinms.tools.MaplePacketCreator;
  34. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  35. public class CloseRangeDamageHandler extends AbstractDealDamageHandler {
  36.     private boolean isFinisher(int skillId) {
  37.         return skillId >= 1111003 && skillId <= 1111006;
  38.     }
  39.     @Override
  40.     public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
  41.         AttackInfo attack = parseDamage(slea, false);
  42.         MapleCharacter player = c.getPlayer();
  43.         player.resetAfkTime();
  44.         MaplePacket packet = MaplePacketCreator.closeRangeAttack(player.getId(), attack.skill, attack.stance, attack.numAttackedAndDamage, attack.allDamage, attack.speed);
  45.         player.getMap().broadcastMessage(player, packet, false, true);
  46.        // handle combo orbconsume
  47.         int numFinisherOrbs = 0;
  48.         Integer comboBuff = player.getBuffedValue(MapleBuffStat.COMBO);
  49.         ISkill energycharge = SkillFactory.getSkill(5110001);
  50.         int energyChargeSkillLevel = player.getSkillLevel(energycharge);
  51.         if (isFinisher(attack.skill)) {
  52.             if (comboBuff != null) {
  53.                 numFinisherOrbs = comboBuff.intValue() - 1;
  54.             }
  55.             player.handleOrbconsume();
  56.         } else if (attack.numAttacked > 0) {
  57.             // handle combo orbgain
  58.             if (attack.skill != 1111008 && comboBuff != null) { // shout should not give orbs
  59.                 player.handleOrbgain();
  60.             }
  61.             if (energyChargeSkillLevel > 0) {
  62.                 for (int i = 0; i < attack.numAttacked; i++) {
  63.                    player.handleEnergyChargeGain();
  64.                 }
  65.             }
  66.         }
  67.         // handle sacrifice hp loss
  68.         if (attack.numAttacked > 0 && attack.skill == 1311005) {
  69.             int totDamageToOneMonster = attack.allDamage.get(0).getRight().get(0).intValue(); // sacrifice attacks only 1 mob with 1 attack
  70.             int remainingHP = player.getHp() - totDamageToOneMonster * attack.getAttackEffect(player).getX() / 100;
  71.             if (remainingHP > 1) {
  72.                 player.setHp(remainingHP);
  73.             } else {
  74.                 player.setHp(1);
  75.             }
  76.             player.updateSingleStat(MapleStat.HP, player.getHp());
  77.         }
  78.         // handle charged blow
  79.         if (attack.numAttacked > 0 && attack.skill == 1211002) {
  80.             boolean advcharge_prob = false;
  81.             int advcharge_level = player.getSkillLevel(SkillFactory.getSkill(1220010));
  82.             if (advcharge_level > 0) {
  83.                 MapleStatEffect advcharge_effect = SkillFactory.getSkill(1220010).getEffect(advcharge_level);
  84.                 advcharge_prob = advcharge_effect.makeChanceResult();
  85.             } else {
  86.                 advcharge_prob = false;
  87.             }
  88.             if (!advcharge_prob) {
  89.                 player.cancelEffectFromBuffStat(MapleBuffStat.WK_CHARGE);
  90.             }
  91.         }
  92.         int maxdamage = c.getPlayer().getCurrentMaxBaseDamage();
  93.         int attackCount = 1;
  94.         if (attack.skill != 0) {
  95.             MapleStatEffect effect = attack.getAttackEffect(c.getPlayer());
  96.             attackCount = effect.getAttackCount();
  97.             maxdamage *= effect.getDamage() / 100.0;
  98.             maxdamage *= attackCount;
  99.         }
  100.         maxdamage = Math.min(maxdamage, 99999);
  101.         if (attack.skill == 4211006) {
  102.             maxdamage = 700000;
  103.         } else if (numFinisherOrbs > 0) {
  104.             maxdamage *= numFinisherOrbs;
  105.         } else if (comboBuff != null) {
  106.             ISkill combo = SkillFactory.getSkill(1111002);
  107.             int comboLevel = player.getSkillLevel(combo);
  108.             MapleStatEffect comboEffect = combo.getEffect(comboLevel);
  109.             double comboMod = 1.0 + (comboEffect.getDamage() / 100.0 - 1.0) * (comboBuff.intValue() - 1);
  110.             maxdamage *= comboMod;
  111.         }
  112.         if (numFinisherOrbs == 0 && isFinisher(attack.skill)) {
  113.             return; // can only happen when lagging o.o
  114.         }
  115.         if (isFinisher(attack.skill)) {
  116.             maxdamage = 99999; // FIXME reenable damage calculation for finishers
  117.         }
  118.         if (attack.skill > 0) {
  119.             ISkill skill = SkillFactory.getSkill(attack.skill);
  120.             int skillLevel = c.getPlayer().getSkillLevel(skill);
  121.             MapleStatEffect effect_ = skill.getEffect(skillLevel);
  122.             if (effect_.getCooldown() > 0) {
  123.                 if (player.skillisCooling(attack.skill)) {
  124.                     player.getCheatTracker().registerOffense(CheatingOffense.COOLDOWN_HACK);
  125.                     return;
  126.                 } else {
  127.                     c.getSession().write(MaplePacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
  128.                     ScheduledFuture<?> timer = TimerManager.getInstance().schedule(new CancelCooldownAction(c.getPlayer(), attack.skill), effect_.getCooldown() * 1000);
  129.                     player.addCooldown(attack.skill, System.currentTimeMillis(), effect_.getCooldown() * 1000, timer);
  130.                 }
  131.             }
  132.         }
  133.         applyAttack(attack, player, maxdamage, attackCount);
  134.         if (c.getPlayer().hasFakeChar()) {
  135.             for (FakeCharacter ch : c.getPlayer().getFakeChars()) {
  136.                 player.getMap().broadcastMessage(ch.getFakeChar(), MaplePacketCreator.closeRangeAttack(ch.getFakeChar().getId(), attack.skill, attack.stance, attack.numAttackedAndDamage, attack.allDamage, attack.speed), false, true);
  137.                 applyAttack(attack, ch.getFakeChar(), maxdamage, attackCount);
  138.             }
  139.         }
  140.     }
  141. }