Advertisement
Guest User

pdam

a guest
Aug 21st, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.27 KB | None | 0 0
  1. /*
  2.  * This program is free software: you can redistribute it and/or modify it under
  3.  * the terms of the GNU General Public License as published by the Free Software
  4.  * Foundation, either version 3 of the License, or (at your option) any later
  5.  * version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful, but WITHOUT
  8.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10.  * details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License along with
  13.  * this program. If not, see <http://www.gnu.org/licenses/>.
  14.  */
  15. package handlers.skillhandlers;
  16.  
  17. import java.util.logging.Level;
  18. import java.util.logging.LogRecord;
  19. import java.util.logging.Logger;
  20.  
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.datatables.SkillTable;
  23. import com.l2jserver.gameserver.handler.ISkillHandler;
  24. import com.l2jserver.gameserver.model.L2Effect;
  25. import com.l2jserver.gameserver.model.L2ItemInstance;
  26. import com.l2jserver.gameserver.model.L2Object;
  27. import com.l2jserver.gameserver.model.L2Skill;
  28. import com.l2jserver.gameserver.model.actor.L2Character;
  29. import com.l2jserver.gameserver.model.actor.L2Playable;
  30. import com.l2jserver.gameserver.model.actor.L2Summon;
  31. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  32. import com.l2jserver.gameserver.network.SystemMessageId;
  33. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  34. import com.l2jserver.gameserver.skills.BaseStats;
  35. import com.l2jserver.gameserver.skills.Env;
  36. import com.l2jserver.gameserver.skills.Formulas;
  37. import com.l2jserver.gameserver.templates.item.L2WeaponType;
  38. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  39.  
  40.  
  41. /**
  42.  * This class ...
  43.  *
  44.  * @version $Revision: 1.1.2.7.2.16 $ $Date: 2005/04/06 16:13:49 $
  45.  */
  46.  
  47. public class Pdam implements ISkillHandler
  48. {
  49.     private static final Logger _log = Logger.getLogger(Pdam.class.getName());
  50.     private static final Logger _logDamage = Logger.getLogger("damage");
  51.    
  52.     private static final L2SkillType[] SKILL_IDS =
  53.     {
  54.         L2SkillType.PDAM, L2SkillType.FATAL
  55.     };
  56.    
  57.     /**
  58.      *
  59.      * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
  60.      */
  61.     public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  62.     {
  63.         if (activeChar.isAlikeDead())
  64.             return;
  65.        
  66.         int damage = 0;
  67.        
  68.         if (Config.DEBUG)
  69.         {
  70.             _log.fine("Begin Skill processing in Pdam.java " + skill.getSkillType());
  71.         }
  72.        
  73.         L2ItemInstance weapon = activeChar.getActiveWeaponInstance();
  74.         boolean soul = (weapon != null && weapon.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT && weapon.getItemType() != L2WeaponType.DAGGER);
  75.        
  76.         // If there is no weapon equipped, check for an active summon.
  77.         if (weapon == null && activeChar instanceof L2Summon)
  78.         {
  79.             L2Summon activeSummon = (L2Summon) activeChar;
  80.             if (activeSummon.getChargedSoulShot() == L2ItemInstance.CHARGED_SOULSHOT)
  81.             {
  82.                 soul = true;
  83.                 activeSummon.setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
  84.             }
  85.         }
  86.        
  87.         for (L2Character target: (L2Character[]) targets)
  88.         {
  89.            
  90.             if (activeChar instanceof L2PcInstance && target instanceof L2PcInstance && ((L2PcInstance)target).isFakeDeath())
  91.             {
  92.                 target.stopFakeDeath(true);
  93.             }
  94.             else if (target.isDead())
  95.                 continue;
  96.            
  97.             final boolean dual = activeChar.isUsingDualWeapon();
  98.             final byte shld = Formulas.calcShldUse(activeChar, target, skill);
  99.             // PDAM critical chance not affected by buffs, only by STR. Only some skills are meant to crit.
  100.             boolean crit = false;
  101.             if (skill.getBaseCritRate() > 0)
  102.                 crit = Formulas.calcCrit(skill.getBaseCritRate() * 10 * BaseStats.STR.calcBonus(activeChar), target);
  103.            
  104.            
  105.             if (!crit && (skill.getCondition() & L2Skill.COND_CRIT) != 0)
  106.                 damage = 0;
  107.             else
  108.                 damage = (int) Formulas.calcPhysDam(activeChar, target, skill, shld, false, dual, soul);
  109.             if (skill.getMaxSoulConsumeCount() > 0 && activeChar instanceof L2PcInstance)
  110.             {
  111.                 switch (((L2PcInstance) activeChar).getSouls())
  112.                 {
  113.                     case 0:
  114.                         break;
  115.                     case 1:
  116.                         damage *= 1.10;
  117.                         break;
  118.                     case 2:
  119.                         damage *= 1.12;
  120.                         break;
  121.                     case 3:
  122.                         damage *= 1.15;
  123.                         break;
  124.                     case 4:
  125.                         damage *= 1.18;
  126.                         break;
  127.                     default:
  128.                         damage *= 1.20;
  129.                         break;
  130.                 }
  131.             }
  132.             if (crit)
  133.                 damage *= 2; // PDAM Critical damage always 2x and not affected by buffs
  134.            
  135.            
  136.             final boolean skillIsEvaded = Formulas.calcPhysicalSkillEvasion(target, skill);
  137.             final byte reflect = Formulas.calcSkillReflect(target, skill);
  138.            
  139.             if (!skillIsEvaded)
  140.             {
  141.                 if (skill.hasEffects())
  142.                 {
  143.                     L2Effect[] effects;
  144.                     if ((reflect & Formulas.SKILL_REFLECT_SUCCEED) != 0)
  145.                     {
  146.                         activeChar.stopSkillEffects(skill.getId());
  147.                         effects = skill.getEffects(target, activeChar);
  148.                         if (effects != null && effects.length > 0)
  149.                         {
  150.                             SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  151.                             sm.addSkillName(skill);
  152.                             activeChar.sendPacket(sm);
  153.                         }
  154.                     }
  155.                     else
  156.                     {
  157.                         // activate attacked effects, if any
  158.                         target.stopSkillEffects(skill.getId());
  159.                         effects = skill.getEffects(activeChar, target, new Env(shld, false, false, false));
  160.                         if (effects != null && effects.length > 0)
  161.                         {
  162.                             SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  163.                             sm.addSkillName(skill);
  164.                             target.sendPacket(sm);
  165.                         }
  166.                     }
  167.                 }
  168.  
  169.                 if (damage > 0)
  170.                 {
  171.                     activeChar.sendDamageMessage(target, damage, false, crit, false);
  172.                    
  173.                     if (Config.LOG_GAME_DAMAGE
  174.                             && activeChar instanceof L2Playable
  175.                             && damage > Config.LOG_GAME_DAMAGE_THRESHOLD)
  176.                     {
  177.                         LogRecord record = new LogRecord(Level.INFO, "");
  178.                         record.setParameters(new Object[]{activeChar, " did damage ", damage, skill, " to ", target});
  179.                         record.setLoggerName("pdam");
  180.                         _logDamage.log(record);
  181.                     }
  182.  
  183.                     // Possibility of a lethal strike
  184.                     Formulas.calcLethalHit(activeChar, target, skill);
  185.  
  186.                     target.reduceCurrentHp(damage, activeChar, skill);
  187.  
  188.                     // vengeance reflected damage
  189.                     if ((reflect & Formulas.SKILL_REFLECT_VENGEANCE) != 0)
  190.                     {
  191.                         if (target instanceof L2PcInstance)
  192.                         {
  193.                             SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.COUNTERED_C1_ATTACK);
  194.                             sm.addCharName(activeChar);
  195.                             target.sendPacket(sm);
  196.                         }
  197.                         if (activeChar instanceof L2PcInstance)
  198.                         {
  199.                             SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_PERFORMING_COUNTERATTACK);
  200.                             sm.addCharName(target);
  201.                             activeChar.sendPacket(sm);
  202.                         }
  203.                         // Formula from Diego post, 700 from rpg tests
  204.                         double vegdamage = (700 * target.getPAtk(activeChar) / activeChar.getPDef(target));
  205.                         activeChar.reduceCurrentHp(vegdamage, target, skill);
  206.                     }
  207.                 }
  208.                 else // No damage
  209.                     activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ATTACK_FAILED));
  210.             }
  211.             else
  212.             {
  213.                 if (activeChar instanceof L2PcInstance)
  214.                 {
  215.                     SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_DODGES_ATTACK);
  216.                     sm.addString(target.getName());
  217.                     ((L2PcInstance) activeChar).sendPacket(sm);
  218.                 }
  219.                 if (target instanceof L2PcInstance)
  220.                 {
  221.                     SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVOIDED_C1_ATTACK);
  222.                     sm.addString(activeChar.getName());
  223.                     ((L2PcInstance) target).sendPacket(sm);
  224.                 }
  225.                
  226.                 // Possibility of a lethal strike despite skill is evaded
  227.                 Formulas.calcLethalHit(activeChar, target, skill);
  228.             }
  229.            
  230.             if (activeChar instanceof L2PcInstance)
  231.             {
  232.                 int soulMasteryLevel = activeChar.getSkillLevel(467);
  233.                 if (soulMasteryLevel > 0)
  234.                 {
  235.                     L2Skill soulmastery = SkillTable.getInstance().getInfo(467, soulMasteryLevel);
  236.                     if (soulmastery != null)
  237.                     {
  238.                         if (((L2PcInstance) activeChar).getSouls() < soulmastery.getNumSouls())
  239.                         {
  240.                             int count = 0;
  241.                            
  242.                             if (((L2PcInstance) activeChar).getSouls() + skill.getNumSouls() <= soulmastery.getNumSouls())
  243.                                 count = skill.getNumSouls();
  244.                             else
  245.                                 count = soulmastery.getNumSouls() - ((L2PcInstance) activeChar).getSouls();
  246.                             ((L2PcInstance) activeChar).increaseSouls(count);
  247.                         }
  248.                         else
  249.                         {
  250.                             SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.SOUL_CANNOT_BE_INCREASED_ANYMORE);
  251.                             ((L2PcInstance) activeChar).sendPacket(sm);
  252.                         }
  253.                     }
  254.                 }
  255.             }
  256.         }
  257.        
  258.         //self Effect :]
  259.         if (skill.hasSelfEffects())
  260.         {
  261.             final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  262.             if (effect != null && effect.isSelfEffect())
  263.             {
  264.                 //Replace old effect with new one.
  265.                 effect.exit();
  266.             }
  267.             skill.getEffectsSelf(activeChar);
  268.         }
  269.        
  270.         if (soul && weapon != null)
  271.             weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  272.        
  273.         if (skill.isSuicideAttack())
  274.             activeChar.doDie(activeChar);
  275.     }
  276.    
  277.     /**
  278.      *
  279.      * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  280.      */
  281.     public L2SkillType[] getSkillIds()
  282.     {
  283.         return SKILL_IDS;
  284.     }
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement