Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static final double calcPhysicalAttackDamage(Creature attacker, Creature target, ShieldDefense sDef, boolean crit, boolean ss)
- {
- // If the attacker can't attack, return.
- final Player attackerPlayer = attacker.getActingPlayer();
- if (attackerPlayer != null && !attackerPlayer.getAccessLevel().canGiveDamage())
- return 0.;
- double defence = target.getStatus().getPDef(attacker);
- switch (sDef)
- {
- case SUCCESS:
- defence += target.getStatus().getShldDef();
- break;
- case PERFECT:
- return 1.;
- }
- final boolean isPvP = attacker instanceof Playable && target instanceof Playable;
- final double attackPower = attacker.getStatus().getPAtk(target);
- double addCritPower = 0.;
- final double pvpMul = (isPvP) ? attacker.getStatus().calcStat(Stats.PVP_PHYSICAL_DMG, 1, null, null) : 1.;
- final double posMul = getPosMul(attacker, target, crit);
- final double elemMul = calcElementalPhysicalAttackModifier(attacker, target);
- final double rndMul = attacker.getRandomDamageMultiplier();
- double raceMul = 1.;
- double weaponMul = 1.;
- double critDamMul = 1.;
- double critDamPosMul = 1.;
- double critVuln = 1.;
- // Critic multiplier.
- if (crit)
- {
- critDamMul = attacker.getStatus().calcStat(Stats.CRITICAL_DAMAGE, 1, target, null);
- critDamPosMul = attacker.getStatus().calcStat(Stats.CRITICAL_DAMAGE_POS, 1, target, null);
- critVuln = target.getStatus().calcStat(Stats.CRIT_VULN, 1, target, null);
- addCritPower = attacker.getStatus().calcStat(Stats.CRITICAL_DAMAGE_ADD, 0, target, null) * 77. / defence;
- }
- // Weapon multiplier.
- final Weapon weapon = attacker.getActiveWeaponItem();
- if (weapon != null)
- {
- final Stats stat = weapon.getItemType().getVulnStat();
- if (stat != null)
- weaponMul = target.getStatus().calcStat(stat, 1, target, null);
- }
- // Race multiplier.
- if (target instanceof Npc)
- {
- final NpcRace race = ((Npc) target).getTemplate().getRace();
- if (race.getAtkStat() != null && race.getResStat() != null)
- raceMul = 1 + ((attacker.getStatus().calcStat(race.getAtkStat(), 1, target, null) - target.getStatus().calcStat(race.getResStat(), 1, target, null)) / 100);
- }
- // End calculation.
- double damage = 0;
- if (crit)
- damage = ((attackPower * 2. * critDamMul * critDamPosMul * critVuln * posMul * rndMul * raceMul * pvpMul * elemMul * weaponMul) + addCritPower) * 77. / defence;
- else
- damage = (attackPower * posMul * rndMul * raceMul * pvpMul * elemMul * weaponMul) * 77. / defence;
- // If using ss, the damages are multiplied by 2.
- if (ss)
- damage *= 2.;
- if (Config.DEVELOPER)
- {
- StringUtil.printSection("Physical attack damage");
- LOGGER.info("crit:{}, ss:{}, shield:{}, isPvp:{}, defence:{}", crit, ss, sDef, isPvP, defence);
- LOGGER.info("Basic powers: attack: {}, addCrit: {}", attackPower, addCritPower);
- LOGGER.info("Multipliers: critDam: {}, critPos: {}, pos: {}, rnd: {}, race: {}, pvp: {}, elem: {}, weapon: {}", critDamMul, critDamPosMul, posMul, rndMul, raceMul, pvpMul, elemMul, weaponMul);
- LOGGER.info("Vulnerabilities: criticalVuln: {}", critVuln);
- LOGGER.info("Final damage: {}", damage);
- }
- if (damage < 0)
- damage = 0;
- else if (damage < 1)
- damage = 1;
- return damage;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement