diff --git a/src/main/java/dk/sdu/mmmi/modulemon/Monster/BattleMonsterProcessor.java b/src/main/java/dk/sdu/mmmi/modulemon/Monster/BattleMonsterProcessor.java index 5f95ff3d..78e15493 100644 --- a/src/main/java/dk/sdu/mmmi/modulemon/Monster/BattleMonsterProcessor.java +++ b/src/main/java/dk/sdu/mmmi/modulemon/Monster/BattleMonsterProcessor.java @@ -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; } @@ -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; + } }