All pastes #40620 Raw Edit

New skill success

public text v1 · immutable
#40620 ·published 2006-02-07 22:44 UTC
rendered paste body
Index: /java/net/sf/l2j/gameserver/skills/Formulas.java
===================================================================
--- /java/net/sf/l2j/gameserver/skills/Formulas.java	(revision 2263)
+++ /java/net/sf/l2j/gameserver/skills/Formulas.java	(working copy)
@@ -993,23 +993,18 @@
         if(attacker instanceof L2PcInstance && target instanceof L2PcInstance) damage *= 0.9; // PvP modifier (-10%)
 		if(mcrit) damage *= 2;
 
-        if (Config.ALT_GAME_MAGICFAILURES) // Failure calculation
+        // Failure calculation
+        if (Config.ALT_GAME_MAGICFAILURES && !calcSkillSuccess(attacker, target, skill, false, ss, bss))
         {
             /* Level difference: 
-             *  less then 7 : full chance
-             *  7 - 20      : reduced chance
-             *  20 and more : min chance
+             *  less then 10 : full chance
+             *  10 - 20      : reduced chance
+             *  20 and more  : min chance
              */
-            // TODO: Temporary fix for skills with Power = 0 or LevelDepend not set
-            int rate = (int)(200 - 10 * (target.getLevel() - (skill.getMagicLevel()>0?skill.getMagicLevel():attacker.getLevel())));
 
-            if (target.isRaid()) rate /= 2; // chance is reduced for RaidBoss
-
-            if (rate > 123) rate = 123;
-            if (rate < 1) rate = 1;
-            int check = _rnd.nextInt(100);
-            if (rate <= check) damage = 1;
-            else if (rate <= check +25) damage /= 2;
+            if (calcSkillSuccess(attacker, target, skill, false, ss, bss))
+                damage /= 2;
+            else damage = 1;
         }
          
 		return damage;
@@ -1083,7 +1078,7 @@
 		return d > 0;
     }
 
-    public boolean calcSkillSuccess(L2Character player, L2Character target, L2Skill skill, boolean ss, boolean sps, boolean bss )
+    public boolean calcSkillSuccessOld(L2Character player, L2Character target, L2Skill skill, boolean ss, boolean sps, boolean bss )
     {
         if(Config.ALT_GAME_SKILL_FORMULAS.equalsIgnoreCase("alt") ||
         	Config.ALT_GAME_SKILL_FORMULAS.equalsIgnoreCase("true"))
@@ -1198,6 +1193,93 @@
     	return success;
     }
 
+    public int calcSkillResistance(SkillType type, L2Character target)
+    {
+        switch(type)
+        {
+            case BLEED: return (int) target.calcStat(Stats.BLEED_RES, 0, target, null);
+            case POISON: return (int) target.calcStat(Stats.POISON_RES, 0, target, null);
+            case STUN: return (int) target.calcStat(Stats.STUN_RES, 0, target, null);
+            case PARALYZE: return (int) target.calcStat(Stats.PARALYZE_RES, 0, target, null); 
+            case ROOT: return (int) target.calcStat(Stats.ROOT_RES, 0, target, null);
+            case SLEEP: return (int) target.calcStat(Stats.SLEEP_RES, 0, target, null);
+            case MUTE: return (int) target.calcStat(Stats.MUTE_RES, 0, target, null); 
+            case FEAR:
+            case CONFUSION: return (int) target.calcStat(Stats.CONFUSION_RES, 0, target, null);
+            default: return 0;
+        }
+    }
+
+    public int calcSkillStatModifier(SkillType type, L2Character target)
+    {
+        switch(type)
+        {
+            case STUN: return target.getCON();
+            case ROOT: return target.getDEX();
+            case SLEEP: return target.getWIT();
+            case MUTE:
+            case CONFUSION: 
+            case PARALYZE: return target.getMEN();
+            default: return 0;
+        }
+    }
+
+    public boolean calcSkillSuccess(L2Character player, L2Character target, L2Skill skill, boolean ss, boolean sps, boolean bss)
+    {
+        if(Config.ALT_GAME_SKILL_FORMULAS.equalsIgnoreCase("alt") || Config.ALT_GAME_SKILL_FORMULAS.equalsIgnoreCase("true"))
+        	return calcAltSkillSuccess(player, target, skill);
+
+    	SkillType type = skill.getSkillType();
+
+        if (target.isRaid() && (type == SkillType.CONFUSION || type == SkillType.MUTE || type == SkillType.PARALYZE || type == SkillType.ROOT)) 
+            return false; // these skills should not work on RaidBoss
+
+        int value = (int)skill.getPower();
+        int lvlDepend = skill.getLevelDepend();
+        
+        if (type == SkillType.PDAM) // For additional effects on PDAM skills (like STUN, SHOCK,...)
+        {
+            value = 50;
+            type = SkillType.STUN;
+        }
+        if (type == SkillType.MDAM) // Used for Magic attack failure calc
+        {
+            value = target.isRaid()? 100 : 200; // chance is reduced for RaidBoss
+            lvlDepend = 10;
+        }
+
+        // TODO: Temporary fix for skills with Power = 0 or LevelDepend not set
+        if(value == 0) value = (type == SkillType.PARALYZE)? 50 : 80;
+        if(lvlDepend == 0) lvlDepend = (type == SkillType.PARALYZE)? 1 : 2;
+
+        // TODO: Temporary fix for NPC skills with MagicLevel not set
+        // int lvlmodifier = (skill.getMagicLevel() - target.getLevel()) * lvlDepend;
+        int lvlmodifier = ((skill.getMagicLevel()>0?skill.getMagicLevel():player.getLevel()) - target.getLevel()) * lvlDepend;
+        int statmodifier = calcSkillStatModifier(type, target);
+
+        int ssmodifier = 100;
+        if (bss) ssmodifier = 200;
+        else if (sps) ssmodifier = 150;        
+        else if (ss) ssmodifier = 150;
+
+        if(Config.DEVELOPER) System.out.println(skill.getName() + ": " + value + ", " + lvlmodifier + ", " + calcSkillResistance(type, target) + ", " + statmodifier);
+        int rate = value + lvlmodifier - calcSkillResistance(type, target);
+        if (skill.isMagic()) rate *= Math.sqrt(player.getMAtk(target, skill)/target.getMDef(player, skill));
+        if (statmodifier > 0) rate = rate * (100 - statmodifier) / 100;
+
+        if (rate > 99) rate = 99;
+        else if (rate < 1) rate = 1;
+
+        if (ssmodifier != 100)
+        {
+            if (rate > 10000/(100+ssmodifier))
+                rate = 100-(100-rate)*100/ssmodifier;
+            else rate = rate*ssmodifier/100;
+        }
+
+        return (_rnd.nextInt(100) < rate);
+    }
+
     public boolean calcAltSkillSuccess(L2Character activeChar, L2Character target, L2Skill skill)
     {
         // Get our numbers and base success rate
Index: /java/net/sf/l2j/gameserver/skills/Stats.java
===================================================================
--- /java/net/sf/l2j/gameserver/skills/Stats.java	(revision 2263)
+++ /java/net/sf/l2j/gameserver/skills/Stats.java	(working copy)
@@ -98,10 +98,12 @@
 	BLEED_RES,
 	POISON_RES,
 	STUN_RES,
+    PARALYZE_RES, 
 	ROOT_RES,
-	MOVEMENT_RES,
+    SLEEP_RES,
 	CONFUSION_RES,
-	SLEEP_RES,
+    MUTE_RES, 
+    MOVEMENT_RES,
 	FIRE_RES,
 	WIND_RES,
 	WATER_RES,
@@ -181,10 +183,12 @@
 		if (name == "bleedRes"     ) return BLEED_RES;
 		if (name == "poisonRes"    ) return POISON_RES;
 		if (name == "stunRes"      ) return STUN_RES;
+        if (name == "paralyzeRes"  ) return PARALYZE_RES;
 		if (name == "rootRes"      ) return ROOT_RES;
-		if (name == "movementRes"  ) return MOVEMENT_RES;
+        if (name == "sleepRes"     ) return SLEEP_RES;
 		if (name == "confusionRes" ) return CONFUSION_RES;
-		if (name == "sleepRes"     ) return SLEEP_RES;
+        if (name == "muteRes"      ) return MUTE_RES;
+        if (name == "movementRes"  ) return MOVEMENT_RES;
 		if (name == "fireRes"      ) return FIRE_RES;
 		if (name == "windRes"      ) return WIND_RES;
 		if (name == "waterRes"     ) return WATER_RES;
Index: /data/stats/skills/1000-1099.xml
===================================================================
--- /data/stats/skills/1000-1099.xml	(revision 1138)
+++ /data/stats/skills/1000-1099.xml	(working copy)
@@ -531,7 +531,7 @@
 </skill>
 <skill id="1032" levels="3" name="Invigor">
   <table name="#mpConsume"> 35 44 52 </table>
-  <table name="#bleedRes"> 20 30 45 </table>
+  <table name="#res"> 30 40 50 </table>
   <set name="mpConsume" val="#mpConsume"/>
   <set name="power" val="0.0"/>
   <set name="target" val="TARGET_ONE"/>
@@ -545,13 +545,13 @@
   <set name="castRange" val="400"/>
   <for>
     <effect name="Buff" time="1200" count="1" val="0">
-      <add order="0x40" stat="bleedRes" val="#bleedRes"/>
+      <add stat="bleedRes" val="#res" order="0x50"/>
     </effect>
   </for>
 </skill>
 <skill id="1033" levels="3" name="Resist Poison">
   <table name="#mpConsume"> 30 35 39 </table>
-  <table name="#res"> 1.25 1.3 1.35 </table>
+  <table name="#res"> 35 40 44 </table>
   <set name="mpConsume" val="#mpConsume"/>
   <set name="power" val="0.0"/>
   <set name="target" val="TARGET_ONE"/>
@@ -565,7 +565,7 @@
   <set name="castRange" val="400"/>
   <for>
      <effect count="1" name="Buff" time="1200" val="0">
-      <mul stat="poisonRes" val="#res" order="0x05"/>
+      <add stat="poisonRes" val="#res" order="0x50"/>
      </effect>
   </for>
 </skill>
@@ -588,10 +588,7 @@
 </skill>
 <skill id="1035" levels="4" name="Mental Aegis">
   <table name="#mpConsume"> 23 35 44 52 </table>
-  <table name="#sleepRes"> 1.1 1.2 1.3 1.4 </table>
-  <table name="#fearRes"> 1.1 1.2 1.3 1.4 </table>
-  <table name="#holdRes"> 1.1 1.2 1.3 1.4 </table>
-  <table name="#silenceRes"> 1.1 1.2 1.3 1.4 </table>
+  <table name="#res"> 50 60 70 80 </table>
   <set name="mpConsume" val="#mpConsume"/>
   <set name="power" val="0.0"/>
   <set name="target" val="TARGET_ONE"/>
@@ -605,9 +602,10 @@
   <set name="castRange" val="400"/>
   <for>
     <effect count="1" name="Buff" time="1200" val="0">
-	 <mul stat="sleepRes" val="#sleepRes" order="0x50"/>
-	 <mul stat="confusionRes" val="#fearRes" order="0x50"/>
-	 <mul stat="rootRes" val="#holdRes" order="0x50"/>
+	 <add stat="rootRes" val="#res" order="0x50"/>
+	 <add stat="sleepRes" val="#res" order="0x50"/>
+	 <add stat="confusionRes" val="#res" order="0x50"/>
+	 <add stat="muteRes" val="#res" order="0x50"/>
 	</effect>
   </for>
 </skill>
Index: /data/stats/skills/0100-0199.xml
===================================================================
--- /data/stats/skills/0100-0199.xml	(revision 1138)
+++ /data/stats/skills/0100-0199.xml	(working copy)
@@ -678,9 +678,9 @@
   <set name="operateType" val="OP_PASSIVE"/>
   <set name="castRange" val="-1"/>
   <for>
-    <mul stat="rootRes" val="1.2" order="0x05"/>
-  	<mul stat="sleepRes" val="1.2" order="0x05"/>
-	<mul stat="stunRes" val="1.2" order="0x05"/>
+    <add stat="rootRes" val="20" order="0x05"/>
+  	<add stat="sleepRes" val="20" order="0x05"/>
+	<add stat="poisonRes" val="20" order="0x05"/>
   </for>
 </skill>
 <skill id="135" levels="2" name="Heroism">
Index: /data/stats/skills/0200-0299.xml
===================================================================
--- /data/stats/skills/0200-0299.xml	(revision 1138)
+++ /data/stats/skills/0200-0299.xml	(working copy)
@@ -1642,9 +1642,7 @@
 </skill>
 <skill id="287" levels="3" name="Lionheart">
  <table name="#mpConsume"> 31 44 58 </table>
- <table name="#sleepRes"> 1.1 1.2 1.3 </table>
- <table name="#stunRes"> 1.1 1.2 1.3 </table>
- <table name="#holdRes"> 1.1 1.2 1.3 </table>
+ <table name="#res"> 40 60 80 </table>
   <set name="mpConsume" val="#mpConsume"/>
   <set name="power" val="0.0"/>
   <set name="target" val="TARGET_SELF"/>
@@ -1657,9 +1655,10 @@
   <set name="castRange" val="-1"/>
   <for>
     <effect count="1" name="Buff" time="3000" val="0">
-      <mul stat="sleepRes" val="#sleepRes" order="0x50"/>
-      <mul stat="stunRes" val="#stunRes" order="0x50"/>
-      <mul stat="rootRes" val="#holdRes" order="0x50"/>
+      <add stat="stunRes" val="#res" order="0x50"/>
+      <add stat="rootRes" val="#res" order="0x50"/>
+      <add stat="sleepRes" val="#res" order="0x50"/>
+      <add stat="paralyzeRes" val="#res" order="0x50"/>
     </effect>
   </for>
 </skill>
Index: /data/stats/skills/1200-1299.xml
===================================================================
--- /data/stats/skills/1200-1299.xml	(revision 1138)
+++ /data/stats/skills/1200-1299.xml	(working copy)
@@ -1165,25 +1165,24 @@
   </for>
 </skill>
 <skill id="1259" levels="4" name="Resist Shock">
-<table name="#mpConsume">36 44 58 65 </table>
-<table name="#res">1.2 1.25 1.3 1.35</table>
-<set name="mpConsume" val="#mpConsume"/>
-<set name="power" val="0.0"/>
-<set name="target" val="TARGET_ONE"/>
-<set name="hitTime" val="4000"/>
-<set name="reuseDelay" val="6000"/>
-<set name="skillTime" val="4000"/>
-<set name="skillType" val="BUFF"/>
-<set name="isMagic" val="true"/>
-<set name="operateType" val="OP_ACTIVE"/>
-<set name="buffDuration" val="1200000"/>
-<set name="castRange" val="400"/>
-<!-- Fixed by Pela -->
-<for>
-        <effect count="1" name="Buff" time="1200" val="0">
-        <mul stat="stunRes" val="#res" order="0x50"/>
-        </effect>
-</for>
+  <table name="#mpConsume">36 44 58 65 </table>
+  <table name="#res">20 25 30 35</table>
+  <set name="mpConsume" val="#mpConsume"/>
+  <set name="power" val="0.0"/>
+  <set name="target" val="TARGET_ONE"/>
+  <set name="hitTime" val="4000"/>
+  <set name="reuseDelay" val="6000"/>
+  <set name="skillTime" val="4000"/>
+  <set name="skillType" val="BUFF"/>
+  <set name="isMagic" val="true"/>
+  <set name="operateType" val="OP_ACTIVE"/>
+  <set name="buffDuration" val="1200000"/>
+  <set name="castRange" val="400"/>
+  <for>
+    <effect count="1" name="Buff" time="1200" val="0">
+      <add stat="stunRes" val="#res" order="0x50"/>
+    </effect>
+  </for>
 </skill>
 <skill id="1260" levels="3" name="Tact of Paagrio">
 <!-- Done by dc -->