LordPanic

DmgSim.java

Oct 12th, 2021 (edited)
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.74 KB | None | 0 0
  1. package net.sf.l2j.gameserver.custom.damagesim;
  2.  
  3. import net.sf.l2j.commons.lang.StringUtil;
  4. import net.sf.l2j.gameserver.model.L2Skill;
  5. import net.sf.l2j.gameserver.model.actor.instance.Player;
  6. import net.sf.l2j.gameserver.model.item.type.WeaponType;
  7. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  8. import net.sf.l2j.gameserver.skills.Formulas;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. /**
  13.  * LordPanic
  14.  */
  15. public class DmgSim {
  16.     private final List<L2Skill> _skills = new ArrayList<>();
  17.     private int _skillID = 0;
  18.     private Player _target = null;
  19.     private String _attackType = "";
  20.  
  21.     public DmgSim(){
  22.  
  23.     }
  24.  
  25.     public void showSimPage(Player player){
  26.         if(_skills.isEmpty())
  27.         getPlayerskills(player);
  28.  
  29.         final StringBuilder sb = new StringBuilder();
  30.         int i = 0;
  31.  
  32.         StringUtil.append(sb, "<font color=b09979>Available Skills</font> <br><center><table width=260>");
  33.          for(L2Skill skill : _skills){
  34.                 final boolean isNextLine = i % 6 == 0;
  35.                 if (isNextLine)
  36.                     sb.append("<tr>");
  37.                     StringUtil.append(sb,displayIcons(skill));
  38.                     if (isNextLine)
  39.                     sb.append("</tr>");
  40.                 i++;
  41.         }
  42.         StringUtil.append(sb, "</center></table><br>");
  43.         StringUtil.append(sb, selectedSkill(_skillID));
  44.         StringUtil.append(sb, "<table width=170><tr><td><center><font color=b09979>Target</font></center></td><td><font color=b09979>Attack Type</font></td></tr>" +
  45.                         "<tr><td><edit var=target width=80 height=10></td><td><combobox width=70 height=10 var=atktype list=AUTOHIT;MAGICAL;PHYSICAL</td></tr></table><br><br>");
  46.         StringUtil.append(sb, damageDisplay(player,_target));
  47.         StringUtil.append(sb, "<button value=\"Simulate\" action=\"bypass _menuDoSim ", _skillID, " $atktype $target\" width=55 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
  48.  
  49.         NpcHtmlMessage html = new NpcHtmlMessage(0);
  50.         html.setFile("data/html/mods/user/simulation.htm");
  51.         html.replace("%simpage%", sb.toString());
  52.         player.sendPacket(html);
  53.     }
  54.  
  55.  
  56.     private L2Skill idToSkillConv(int skillID){
  57.         for(L2Skill skill : _skills){
  58.             if(skill.getId() == skillID){
  59.                 return skill;
  60.             }
  61.         }
  62.         return null;
  63.     }
  64.  
  65.     private String calcDamage(Player activePlayer,L2Skill skill,Player target,String atkType){
  66.             String dmgMsg = "";
  67.             int damage = 0;
  68.             byte shld = Formulas.calcShldUse(activePlayer, target, null);
  69.             boolean pCrit = Formulas.calcCrit(activePlayer.getStat().getCriticalHit(target, null));
  70.             boolean mCrit = Formulas.calcCrit(activePlayer.getStat().getMCriticalHit(target, skill));
  71.             final WeaponType weapon = activePlayer.getAttackType();
  72.  
  73.  
  74.             switch(atkType){
  75.                 case "AUTOHIT":
  76.                     damage = getAutohitDmg(activePlayer,target,shld,pCrit, weapon);
  77.                     if(pCrit)
  78.                         dmgMsg = "<font color=b09979>You used</font> <font color=LEVEL>Normal Hit</font><br1> <font color=LEVEL> Critical</font> <font color=26BEF5>" + damage + "</font> <font color=b09979>damage to</font> <font color=26BEF5>" + target.getName() + "</font><br>";
  79.                     else if(shld == 1 || shld == 2)
  80.                         dmgMsg = "<font color=b09979>You used</font> <font color=LEVEL>Normal Hit</font><br1> <font color=D02B2B> Shield Block</font> <font color=26BEF5>" + damage + "</font> <font color=b09979>damage to</font> <font color=26BEF5>" + target.getName() + "</font><br>";
  81.                     else
  82.                         dmgMsg = "<font color=b09979>You used</font> <font color=LEVEL>Normal Hit</font><br1> <font color=26BEF5> " + damage + "</font> <font color=b09979>damage to</font> <font color=26BEF5>" + target.getName() + "</font><br>";
  83.                     break;
  84.                 case "MAGICAL":
  85.                     if(skill == null)
  86.                         dmgMsg = "<font color=b09979>You need to select a skill.</font><br>";
  87.                     else
  88.                     if(skill.isMagic()) {
  89.                         damage = getMagicalDmg(activePlayer,target,skill,shld,mCrit,weapon);
  90.                         if(mCrit)
  91.                         dmgMsg = "<font color=b09979>You used</font> <font color=LEVEL>" + skill.getName() + "</font><br1><font color=LEVEL> Critical</font> <font color=26BEF5>" + damage + "</font> <font color=b09979>damage to</font> <font color=26BEF5>" + target.getName() + "</font><br>";
  92.                         else if(shld == 1 || shld == 2)
  93.                         dmgMsg = "<font color=b09979>You used</font> <font color=LEVEL>" + skill.getName() + "</font><br1><font color=D02B2B> Shield Block</font> <font color=26BEF5>" + damage + "</font> <font color=b09979>damage to</font> <font color=26BEF5>" + target.getName() + "</font><br>";
  94.                         else
  95.                         dmgMsg = "<font color=b09979>You used</font> <font color=LEVEL>" + skill.getName() + "</font><br1><font color=26BEF5>" + damage + "</font> <font color=b09979>damage to</font> <font color=26BEF5>" + target.getName() + "</font><br>";
  96.                     }else
  97.                         dmgMsg = "<font color=b09979>Wrong type of skill.</font><br>";
  98.                     break;
  99.                 case "PHYSICAL":
  100.                     if(skill == null)
  101.                         dmgMsg = "<font color=b09979>You need to select a skill.</font><br>";
  102.                     else
  103.                     if(!skill.isMagic()) {
  104.                         damage = getPhysicalDmg(activePlayer,target,skill,shld,pCrit,weapon);
  105.                         if(pCrit)
  106.                         dmgMsg = "<font color=b09979>You used</font> <font color=LEVEL>" + skill.getName() + "</font><br1><font color=LEVEL> Critical</font> <font color=26BEF5> " + damage + "</font> <font color=b09979>damage to</font> <font color=26BEF5>" + target.getName() + "</font><br>";
  107.                         else if(shld == 1 || shld == 2)
  108.                          dmgMsg = "<font color=b09979>You used</font> <font color=LEVEL>" + skill.getName() + "</font><br1><font color=D02B2B> Shield Block</font> <font color=26BEF5> " + damage + "</font> <font color=b09979>damage to</font> <font color=26BEF5>" + target.getName() + "</font><br>";
  109.                         else
  110.                          dmgMsg = "<font color=b09979>You used</font> <font color=LEVEL>" + skill.getName() + "</font><br1><font color=26BEF5> " + damage + "</font> <font color=b09979>damage to</font> <font color=26BEF5>" + target.getName() + "</font><br>";
  111.                     }else
  112.                         dmgMsg = "<font color=b09979>Wrong type of skill.</font><br>";
  113.                     break;
  114.             }
  115.             return dmgMsg;
  116.     }
  117.  
  118.     private void getPlayerskills(Player player){
  119.         for(L2Skill skill : player.getSkills().values()){
  120.             if(skillCondition(skill))
  121.                 _skills.add(skill);
  122.         }
  123.     }
  124.  
  125.     /**
  126.      * Calculate simple hits depending on worn weapon
  127.      * Currently checking naked hands, duals , dual fists
  128.      * @return damage
  129.      */
  130.     private int getAutohitDmg(Player attacker,Player target,byte shield,boolean crit, WeaponType wtype){
  131.         int damage = 0;
  132.  
  133.         switch(wtype){
  134.             case DUAL:
  135.             case DUALFIST:
  136.                 damage = (int) Formulas.calcPhysDam(attacker, target, null, shield, crit, true) / 2;
  137.                 break;
  138.             case FIST:
  139.                 damage = (int) Formulas.calcPhysDam(attacker, target, null, shield, crit, false) / 2;
  140.                 break;
  141.             default:
  142.                 damage = (int) Formulas.calcPhysDam(attacker, target, null, shield, crit, true);
  143.                 break;
  144.         }
  145.         return damage;
  146.     }
  147.  
  148.     private int getMagicalDmg(Player attacker,Player target,L2Skill skill,byte shield,boolean crit, WeaponType wtype){
  149.         int damage = 0;
  150.         if(wtype == WeaponType.FIST)
  151.         damage = (int) Formulas.calcMagicDam(attacker, target, skill, shield, false, false, crit);
  152.         else
  153.         damage = (int) Formulas.calcMagicDam(attacker, target, skill, shield, false, true, crit);
  154.  
  155.         return damage;
  156.     }
  157.  
  158.     /**
  159.      * Todo Add condition checks for all physical skill usages ex. dagger for blow type skills etc..etc..
  160.      */
  161.     private int getPhysicalDmg(Player attacker,Player target,L2Skill skill,byte shield,boolean crit, WeaponType wtype){
  162.         int damage = 0;
  163.             if(wtype == WeaponType.FIST)
  164.             damage = 0;
  165.             else
  166.             damage = (int) Formulas.calcPhysDam(attacker, target, skill, shield, crit, true);
  167.  
  168.         return damage;
  169.     }
  170.  
  171.     public String displayIcons(L2Skill skill){
  172.         String tempHolder = "";
  173.             if(skill.getId() < 10)
  174.                 tempHolder = "<td><button action=\"bypass  _menuSelectSkill "+ skill.getId()+ "\" width=32 height=32 back=\"icon.skill000"+skill.getId()+"\" fore=\"icon.skill000"+skill.getId()+"\"></td>";
  175.             else if(skill.getId() < 100)
  176.                 tempHolder = "<td><button action=\"bypass  _menuSelectSkill "+ skill.getId()+ "\" width=32 height=32 back=\"icon.skill00"+skill.getId()+"\" fore=\"icon.skill00"+skill.getId()+"\"></td>";
  177.             else if(skill.getId() < 1000)
  178.                 tempHolder = "<td><button action=\"bypass  _menuSelectSkill "+ skill.getId()+ "\" width=32 height=32 back=\"icon.skill0"+skill.getId()+"\" fore=\"icon.skill0"+skill.getId()+"\"></td>";
  179.             else
  180.                 tempHolder = "<td><button action=\"bypass  _menuSelectSkill "+ skill.getId()+ "\" width=32 height=32 back=\"icon.skill"+skill.getId()+"\" fore=\"icon.skill"+skill.getId()+"\"></td>";
  181.  
  182.         return tempHolder;
  183.     }
  184.  
  185.     /**
  186.      * Check for the selected skill to display, 0 for the default display msg which is word empty
  187.      * @param skillid to make the checks
  188.      * @return the message to display
  189.      */
  190.     public String selectedSkill(int skillid){
  191.         String result = "";
  192.         if(skillid == 0)
  193.             result = "<font color=b09979>Selected Skill</font> [Empty]<br1>";
  194.         else
  195.             result = "<font color=b09979>Selected Skill</font> [<font color=LEVEL>"+idToSkillConv(skillid).getName()+"</font>]<br1>";
  196.  
  197.         return result;
  198.     }
  199.  
  200.  
  201.     /**
  202.      * Simple checks for target
  203.      * @param target
  204.      * @return the damage to display if the field is not empty
  205.      */
  206.     public String damageDisplay(Player attacker,Player target){
  207.         String result = "";
  208.         if(target != null && target instanceof Player){
  209.            result = calcDamage(attacker,idToSkillConv(_skillID),target,_attackType);
  210.         }else
  211.             result = "<br1><font color=b09979>Target field is Empty.</font><br>";
  212.  
  213.         return result;
  214.     }
  215.  
  216.     /**
  217.      * Which skills to allow for display
  218.      * @param skill to make checks on
  219.      * @return true or false
  220.      */
  221.     public boolean skillCondition(L2Skill skill){
  222.         boolean tempHolder = false;
  223.         switch(skill.getSkillType()){
  224.             case CHARGEDAM:
  225.             case PDAM:
  226.             case MDAM:
  227.             case BLOW:
  228.             case DRAIN:
  229.             case DRAIN_SOUL:
  230.                 tempHolder = true;
  231.                 break;
  232.             case BLEED:
  233.             case MANADAM:
  234.             case POISON:
  235.             case PASSIVE:
  236.             case DEBUFF:
  237.             case BUFF:
  238.             case WARRIOR_BANE:
  239.             case MAGE_BANE:
  240.             case CANCEL:
  241.             case SUMMON:
  242.             case EXTRACTABLE_FISH:
  243.             case EXTRACTABLE:
  244.             case CREATE_ITEM:
  245.             case DWARVEN_CRAFT:
  246.             case COMMON_CRAFT:
  247.             case GIVE_SP:
  248.             case MANAHEAL_PERCENT:
  249.             case HEAL_PERCENT:
  250.             case MANARECHARGE:
  251.             case HEAL_STATIC:
  252.             case BALANCE_LIFE:
  253.             case CPHOT:
  254.             case MPHOT:
  255.             case HOT:
  256.             case COMBATPOINTHEAL:
  257.             case MANAHEAL:
  258.             case HEAL:
  259.             case WEAKNESS:
  260.             case PARALYZE:
  261.             case MUTE:
  262.             case SLEEP:
  263.             case FEAR:
  264.             case CONFUSION:
  265.             case ROOT:
  266.             case STUN:
  267.                 tempHolder = false;
  268.                 break;
  269.         }
  270.         return tempHolder;
  271.     }
  272.  
  273.     public void setTarget(Player target){
  274.         _target = target;
  275.     }
  276.  
  277.     public void setAttackType(String atktyp){
  278.         _attackType = atktyp;
  279.     }
  280.     public void setskillIDD(int skillid){
  281.         _skillID = skillid;
  282.     }
  283.  
  284.     public int getskillID(){
  285.         return _skillID;
  286.     }
  287.  
  288.     public Player getTarget(){
  289.         return _target;
  290.     }
  291.  
  292.  
  293. }
Add Comment
Please, Sign In to add comment