Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int calculateDamage(IMonster iSource, IMonsterMove iMove, IMonster iTarge

float monsterAttackDefence = (0.2f * sourceAttack + 3 + 20 ) / (targetDefence + 50);

int damage = Math.round( monsterAttackDefence * moveDamage * attack_bonus * calculateTypeAdvantage(move.getType(), target.getMonsterType()) );
int damage = Math.round( monsterAttackDefence * moveDamage * attack_bonus * calculateTypeAdvantage(move.getType(), target.getMonsterType()) * calculateCriticalHit(source) );
return damage;
}

Expand Down Expand Up @@ -95,10 +95,34 @@ public float calculateTypeAdvantage(MonsterType source, MonsterType target) {
}
}

public float calculateCriticalHit (Monster monster) {
float baseSpeed = (float) monster.getSpeed();

float threshold = (float) (baseSpeed / 0.5);

// To ensure threshold doesn't go above 255
if (threshold > 255) {
threshold = 255;
}

Random random = new Random();
//Generate random number between 0-255
float randomVal = random.nextInt(256);
//true if the generated number is less than the threshold
boolean criticalHit = randomVal >= threshold;

if (criticalHit) {
System.out.println("critical hit");
return 1.5f;
} else {
return 1f;
}

public boolean doAccuracyHit(float factor) {
//Generates a random value
Random random = new Random();
//Ensures that the next move will always be below our factor and between(0-1)
return random.nextFloat() <= factor;

}
}