here is sethit methods
Code:
public void setSingleHit(int damage, int mask, int icon) {
this.singleDamage = damage;
this.hitMask = mask;
this.hitIcon = icon;
setConstitution(getConstitution() - damage);
getUpdateFlag().flag(Flag.SINGLE_HIT);
if (isPlayer())
((Player) this).getPA().refreshSkill(3);
if (getConstitution() <= 0)
applyDead();
updateRequired = true;
}
public void setDoubleHit(int damage, int mask, int icon) {
this.doubleDamage = damage;
this.hitMask2 = mask;
this.hitIcon2 = icon;
setConstitution(getConstitution() - damage);
getUpdateFlag().flag(Flag.DOUBLE_HIT);
if (isPlayer())
((Player) this).getPA().refreshSkill(3);
if (getConstitution() <= 0)
applyDead();
updateRequired = true;
}
here is the calculate hit method
Code:
public static int calculateHit(Entity attacker, Entity target,
boolean isSpecial) {
int hit = 0;
if (attacker.isPlayer()) {
Player p = (Player) attacker;
if (attacker.getAttackType() == AttackTypes.MELEE)
hit = 1 + Misc.random((int) (CombatFormulas.getMeleeMaxHit(p,
target, p.usingSpecial) - 1));
if (attacker.getAttackType() == AttackTypes.RANGED)
hit = 1 + Misc.random(((int) CombatFormulas.getRangedMaxHit(
attacker, isSpecial) - 1));
if (attacker.getAttackType() == AttackTypes.MAGIC) {
switch (SpellLoader.getSpellDefinitions()[attacker.getFields()
.getSpellIndex(p)].getSpellId()) {
case 1190:
case 1191:
case 1192:
hit = 1 + Misc
.random(SpellLoader.getSpellDefinitions()[attacker
.getFields().getSpellIndex(p)].getMaxHit() - 1);
break;
default:
hit = 1 + Misc
.random(SpellLoader.getSpellDefinitions()[attacker
.getFields().getSpellIndex(p)].getMaxHit() - 1);
break;
}
}
} else {
Npc n = (Npc) attacker;
hit = Misc.random(n.maxHit);
}
return hit;
}
also here is applydamage method
Code:
public static void applyDamage(Entity attacker, Entity target) {
Player p = (Player) attacker;
if (target == null || target.isDead || attacker.isDead
|| target.getConstitution() <= 0
|| attacker.getConstitution() <= 0 || attacker.respawnTimer > 0) {
p.usingMagic = false;
p.faceUpdate(0);
p.setTarget(null);
return;
}
if (target.isPlayer()) {
Player t = (Player) target;
t.setAggressor(attacker);
t.logoutDelay = System.currentTimeMillis();
t.singleCombatDelay = System.currentTimeMillis();
}
target.lastDamageTaken = System.currentTimeMillis();
attacker.attackTimer = WeaponsHandler.getHitDelay(attacker);
int damage = CalculateHit.getAccuracy(attacker, target);
int damage2 = CalculateHit.getAccuracy(attacker, target);
//Curses.applyCurses(attacker, target, damage);
int crit = 0;
int crit2 = 0;
Extras.addCombatExp(p, damage);
if (p.doubleHit)
Extras.addCombatExp(p, damage2);
switch (attacker.getAttackType()) {
case MELEE:
crit = damage * 0.92 > CombatFormulas.getMeleeMaxHit(attacker,
target, p.usingSpecial) ? 1 : 0;
crit2 = damage2 * 0.92 > CombatFormulas.getMeleeMaxHit(attacker,
target, p.usingSpecial) ? 1 : 0;
target.setSingleHit(damage, crit, 0);
if (p.doubleHit)
target.setDoubleHit(damage2, crit2, 0);
p.doubleHit = false;
break;
case MAGIC:
if (p.usingMagic && !attacker.getFields().isAutoCasting())
CombatAssistant.resetPlayerAttack(p);
crit = damage * 0.92 > SpellLoader.getSpellDefinitions()[attacker
.getFields().getSpellIndex(attacker)].getMaxHit() ? 1 : 0;
target.setSingleHit(damage, crit, 2);
target.performGraphic(new Graphic(
SpellLoader.getSpellDefinitions()[attacker.getFields()
.getSpellIndex(attacker)].getEndGraphicId()));
break;
case RANGED:
Ranged.boltEffects(attacker, target, damage);
crit = damage * 0.92 > CombatFormulas.getRangedMaxHit(attacker,
p.usingSpecial) ? 1 : 0;
crit2 = damage2 * 0.92 > CombatFormulas.getRangedMaxHit(attacker,
p.usingSpecial) ? 1 : 0;
target.setSingleHit(damage, crit, 1);
if (p.doubleHit)
target.setDoubleHit(damage2, crit2, 1);
p.doubleHit = false;
break;
default:
break;
}
}