Advertisement
Guest User

kapuk99

a guest
Jan 1st, 2010
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.69 KB | None | 0 0
  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.  
  7.     This program is free software: you can redistribute it and/or modify
  8.     it under the terms of the GNU Affero General Public License version 3
  9.     as published by the Free Software Foundation. You may not use, modify
  10.     or distribute this program under any other version of the
  11.     GNU Affero General Public License.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU Affero General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU Affero General Public License
  19.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20. */
  21.  
  22. package net.sf.odinms.net.channel.handler;
  23.  
  24. import java.util.concurrent.ScheduledFuture;
  25. import net.sf.odinms.client.ISkill;
  26. import net.sf.odinms.client.MapleBuffStat;
  27. import net.sf.odinms.client.MapleCharacter;
  28. import net.sf.odinms.client.MapleCharacter.CancelCooldownAction;
  29. import net.sf.odinms.client.MapleClient;
  30. import net.sf.odinms.client.MapleStat;
  31. import net.sf.odinms.client.SkillFactory;
  32. import net.sf.odinms.server.constants.Skills;
  33. import net.sf.odinms.net.MaplePacket;
  34. import net.sf.odinms.server.MapleStatEffect;
  35. import net.sf.odinms.server.TimerManager;
  36. import net.sf.odinms.tools.MaplePacketCreator;
  37. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  38.  
  39. public class CloseRangeDamageHandler extends AbstractDealDamageHandler {
  40.     private boolean isFinisher(int skillId) {
  41.         switch(skillId) {
  42.             case Skills.Crusader.AxeComa:
  43.             case Skills.Crusader.AxePanic:
  44.             case Skills.Crusader.SwordComa:
  45.             case Skills.Crusader.SwordPanic:
  46.             case Skills.DawnWarrior3.Coma:
  47.             case Skills.DawnWarrior3.Panic:
  48.                 return true;
  49.             default:
  50.                 return false;
  51.         }
  52.     }
  53.    
  54.     @Override
  55.     public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
  56.         AttackInfo attack = parseDamage(c.getPlayer(), slea, false);
  57.         MapleCharacter player = c.getPlayer();
  58.  
  59.         MaplePacket packet = MaplePacketCreator.closeRangeAttack(player.getId(), attack.skill, attack.stance,
  60.         attack.numAttackedAndDamage, attack.allDamage, attack.speed);
  61.         player.getMap().broadcastMessage(player, packet, false, true);
  62.  
  63.         // handle combo orbconsume
  64.         int numFinisherOrbs = 0;
  65.         Integer comboBuff = player.getBuffedValue(MapleBuffStat.COMBO);
  66.         if (isFinisher(attack.skill)) {
  67.             if (comboBuff != null) {
  68.                 numFinisherOrbs = comboBuff.intValue() - 1;
  69.             }
  70.             player.handleOrbconsume();
  71.         } else if (attack.numAttacked > 0 && comboBuff != null) {
  72.             // handle combo orbgain
  73.             if (attack.skill != 1111008) { // shout should not give orbs
  74.                 player.handleOrbGain();
  75.             }
  76.         }
  77.  
  78.         // handle sacrifice hp loss
  79.         if(attack.numAttacked > 0 && attack.skill == 1311005) {
  80.             int totDamageToOneMonster = attack.allDamage.get(0).getRight().get(0).intValue(); // sacrifice attacks only 1 mob with 1 attack
  81.             player.setHp(player.getHp() - totDamageToOneMonster * attack.getAttackEffect(player).getX() / 100);
  82.             player.updateSingleStat(MapleStat.HP, player.getHp());
  83.         }
  84.  
  85.         // handle charged blow
  86.         if (attack.numAttacked > 0 && attack.skill == 1211002) {
  87.             boolean advcharge_prob = false;
  88.             int advcharge_level = player.getSkillLevel(SkillFactory.getSkill(1220010));
  89.             if (advcharge_level > 0) {
  90.                 MapleStatEffect advcharge_effect = SkillFactory.getSkill(1220010).getEffect(advcharge_level);
  91.                 advcharge_prob = advcharge_effect.makeChanceResult();
  92.             } else {
  93.                 advcharge_prob = false;
  94.             }
  95.             if (!advcharge_prob) {
  96.                 player.cancelEffectFromBuffStat(MapleBuffStat.WK_CHARGE);
  97.             }
  98.         }
  99.        
  100.         int maxdamage = c.getPlayer().getCurrentMaxBaseDamage();
  101.         int attackCount = 1;
  102.         if (attack.skill != 0) {
  103.             MapleStatEffect effect = attack.getAttackEffect(c.getPlayer());
  104.             attackCount = effect.getAttackCount();
  105.             maxdamage *= effect.getDamage() / 100.0;
  106.             maxdamage *= attackCount;
  107.         }
  108.         maxdamage = Math.min(maxdamage, 199999);
  109.         if (attack.skill == 4211006) {
  110.             maxdamage = 700000;
  111.         } else if (numFinisherOrbs > 0) {
  112.             maxdamage *= numFinisherOrbs;
  113.         } else if (comboBuff != null) {
  114.             ISkill combo = SkillFactory.getSkill(Skills.Crusader.ComboAttack);
  115.             int comboLevel = player.getSkillLevel(combo);
  116.             if (comboLevel == 0) {
  117.                 combo = SkillFactory.getSkill(Skills.DawnWarrior3.ComboAttack);
  118.                 comboLevel = player.getSkillLevel(combo);
  119.             }
  120.             MapleStatEffect comboEffect = combo.getEffect(comboLevel);
  121.             double comboMod = 1.0 + (comboEffect.getDamage() / 100.0 - 1.0) * (comboBuff.intValue() - 1);
  122.             maxdamage *= comboMod;
  123.         }
  124.         if (numFinisherOrbs == 0 && isFinisher(attack.skill)) {
  125.             return; // can only happen when lagging o.o
  126.         }
  127.         if (isFinisher(attack.skill)) {
  128.             maxdamage = 199999; // FIXME reenable damage calculation for finishers
  129.         }
  130.         if (attack.skill > 0) {
  131.             ISkill skill = SkillFactory.getSkill(attack.skill);
  132.             int skillLevel = c.getPlayer().getSkillLevel(skill);
  133.             MapleStatEffect effect_ = skill.getEffect(skillLevel);
  134.             if (effect_.getCooldown() > 0) {
  135.                 c.getSession().write(MaplePacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
  136.                 ScheduledFuture<?> timer = TimerManager.getInstance().schedule(new CancelCooldownAction(c.getPlayer(), attack.skill), effect_.getCooldown() * 1000);
  137.                 c.getPlayer().addCooldown(attack.skill, System.currentTimeMillis(), effect_.getCooldown() * 1000, timer);
  138.             }
  139.         }
  140.         applyAttack(attack, player, maxdamage, attackCount);
  141.     }
  142. }
  143.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement