I want to know what is the best way to write my own code without modifying existing code,
or if modified, I want it in a seperate file, so I can find it quickly, or when an update occurs, I can easily patch
the files with the updated ones without harming my code.
I thought something about function overriding. For example whenever I need a change in a function or some variable declarations, I will copy them in a new file and override them, and add my own code in it. I'm a little confused of how these methods work, and what is the best one, that's why I'm posting here.
Here's some code from the file Formulas.java and function calcSkillSuccess()
Code: Select all
public static boolean calcSkillSuccess(L2Character attacker, L2Character target, L2Skill skill, byte shld, boolean ss, boolean sps, boolean bss) { /*if (skill.getPower() == -1) { return true; } final boolean isPvP = (attacker instanceof L2Playable) && (target instanceof L2Playable); final boolean isPvE = (attacker instanceof L2Playable) && (target instanceof L2Attackable); if (skill.ignoreResists()) { if (attacker.isDebug()) { attacker.sendDebugMessage(skill.getName() + " ignoring resists"); } return (Rnd.get(100) < skill.getPower(isPvP, isPvE)); } else if ((target.calcStat(Stats.DEBUFF_IMMUNITY, 0, null, skill) > 0) && skill.isDebuff()) { return false; } if (shld == SHIELD_DEFENSE_PERFECT_BLOCK) // perfect block { if (attacker.isDebug()) { attacker.sendDebugMessage(skill.getName() + " blocked by shield"); } return false; } int value = (int) skill.getPower(isPvP, isPvE); double statModifier = calcSkillStatModifier(skill, target); // Calculate BaseRate. int rate = (int) (value * statModifier); // Add Matk/Mdef Bonus double mAtkModifier = 0; int ssModifier = 0; if (skill.isMagic()) { mAtkModifier = target.getMDef(target, skill); if (shld == SHIELD_DEFENSE_SUCCEED) { mAtkModifier += target.getShldDef(); } // Add Bonus for Sps/SS if (bss) { ssModifier = 4; } else if (sps) { ssModifier = 2; } else { ssModifier = 1; } mAtkModifier = (14 * Math.sqrt(ssModifier * attacker.getMAtk(target, skill))) / mAtkModifier; rate = (int) (rate * mAtkModifier); } // Resists double vulnModifier = calcSkillVulnerability(attacker, target, skill); double profModifier = calcSkillProficiency(skill, attacker, target); double res = vulnModifier + profModifier; double resMod = 1; if (res != 0) { if (res < 0) { resMod = 1 - (0.075 * res); resMod = 1 / resMod; } else { resMod = 1 + (0.02 * res); } rate *= resMod; } int elementModifier = calcElementModifier(attacker, target, skill); rate += elementModifier; // lvl modifier. int deltamod = calcLvlDependModifier(attacker, target, skill); rate += deltamod; if (rate > skill.getMaxChance()) { rate = skill.getMaxChance(); } else if (rate < skill.getMinChance()) { rate = skill.getMinChance(); } if (attacker.isDebug() || Config.DEVELOPER) { final StringBuilder stat = new StringBuilder(100); StringUtil.append(stat, skill.getName(), " type:", skill.getSkillType().toString(), " power:", String.valueOf(value), " stat:", String.format("%1.2f", statModifier), " res:", String.format("%1.2f", resMod), "(", String.format("%1.2f", profModifier), "/", String.format("%1.2f", vulnModifier), ") elem:", String.valueOf(elementModifier), " mAtk:", String.format("%1.2f", mAtkModifier), " ss:", String.valueOf(ssModifier), " lvl:", String.valueOf(deltamod), " total:", String.valueOf(rate)); final String result = stat.toString(); if (attacker.isDebug()) { attacker.sendDebugMessage(result); } if (Config.DEVELOPER) { _log.info(result); } } return (Rnd.get(100) < rate);*/ return true; }
Code: Select all
public static boolean calcSkillSuccess(L2Character attacker, L2Character target, L2Skill skill, byte shld, boolean ss, boolean sps, boolean bss){ return true;}
I hope I was clear.
Any help would be appreciated
