Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Calculates the chance to hit out of 1.0
- * @param opponent The entity being attacked.
- * @return The chance to hit.
- */
- public double chanceToHit(Entity opponent) {
- /*
- * Calculate the entity's base attack value.
- */
- int attackBonus = entity.getCombat().getBonus(entity.getCombat().getAttackType().getAttackBonus());
- if (attackBonus < 1) {
- attackBonus = 1;
- }
- int attackLevel = entity.getSkills().getLevel(Skills.ATTACK);
- switch (entity.getCombat().getAttackStyle()) {
- case ACCURATE:
- attackLevel += 3;
- break;
- case CONTROLLED:
- attackLevel += 1;
- break;
- default:
- break;
- }
- double attackCalculation = attackBonus * attackLevel;
- /*
- * Calculate the opponent's base defence value.
- */
- int defenceBonus = opponent.getCombat().getBonus(entity.getCombat().getAttackType().getDefenceBonus());
- if (defenceBonus < 1) {
- defenceBonus = 1;
- }
- int defenceLevel = opponent.getSkills().getLevel(Skills.DEFENCE);
- switch (opponent.getCombat().getAttackStyle()) {
- case DEFENSIVE:
- defenceLevel += 3;
- break;
- case CONTROLLED:
- defenceLevel += 1;
- break;
- default:
- break;
- }
- double defenceCalculation = defenceBonus * defenceLevel;
- final double MAGIC_NUMBER = 133;
- double chanceToHit = MAGIC_NUMBER * (attackCalculation / defenceCalculation);
- if (chanceToHit > 1.0) {
- chanceToHit = 1.0;
- }
- // TODO: prayer modifiers, verac effect
- return chanceToHit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement