Browse Source

custom hit chance formula

lakebane-strongholds
FatBoy-DOTC 4 months ago
parent
commit
3fb29f8e2b
  1. 31
      src/engine/gameManager/CombatManager.java
  2. 26
      src/engine/gameManager/PowersManager.java
  3. 25
      src/engine/mobileAI/utilities/CombatUtilities.java

31
src/engine/gameManager/CombatManager.java

@ -660,32 +660,11 @@ public enum CombatManager { @@ -660,32 +660,11 @@ public enum CombatManager {
//calculate hit/miss
//int roll = ThreadLocalRandom.current().nextInt(100);
DeferredPowerJob dpj = null;
int max = (int)atr;
if(max < 10)
max = 10;
int min = (int)(max * 0.5f);
if(max < min){
min = max - 1;
}
int atrRoll = ThreadLocalRandom.current().nextInt(min,max);
int defRoll = 0;
if(AbstractCharacter.IsAbstractCharacter(target)){
AbstractCharacter tar = (AbstractCharacter) target;
max = tar.defenseRating;
if(max < 1)
max = 10;
min = (int)(max * 0.5f);
if(max < min){
min = max - 1;
}
defRoll = ThreadLocalRandom.current().nextInt(min,max);
}
if (atrRoll > defRoll) {
if (LandHit((int)atr,(int)defense)) {
if (ac.getObjectType().equals(GameObjectType.PlayerCharacter))
updateAttackTimers((PlayerCharacter) ac, target, true);
@ -1464,4 +1443,12 @@ public enum CombatManager { @@ -1464,4 +1443,12 @@ public enum CombatManager {
((AbstractCharacter) awo).getCharItemManager().damageRandomArmor(1);
}
public static boolean LandHit(int atr, int defense){
int roll = ThreadLocalRandom.current().nextInt(100);
float chance = (float)((atr-((atr+defense)*0.315))/((defense-((atr+defense)*0.315))+(atr-((atr+defense)*0.315))));
boolean hit = false;
if(chance > roll)
hit = true;
return hit;
}
}

26
src/engine/gameManager/PowersManager.java

@ -2375,30 +2375,8 @@ public enum PowersManager { @@ -2375,30 +2375,8 @@ public enum PowersManager {
//}
// calculate hit/miss
//int roll = ThreadLocalRandom.current().nextInt(100);
boolean disable = true;
int max = (int)atr;
if(max < 10)
max = 10;
int min = (int)(max * 0.5f);
if(max < min){
min = max - 1;
}
int atrRoll = ThreadLocalRandom.current().nextInt(min,max);
int defRoll = 0;
if(AbstractCharacter.IsAbstractCharacter(awo)){
AbstractCharacter tar = (AbstractCharacter) awo;
max = tar.defenseRating;
if(max < 10)
max = 10;
min = (int)(max * 0.5f);
if(max < min){
min = max - 1;
}
defRoll = ThreadLocalRandom.current().nextInt(min,max);
}
if (atrRoll > defRoll) {
if (CombatManager.LandHit((int)atr,(int)defense)) {
// Hit, check if dodge kicked in
if (awo instanceof AbstractCharacter) {
AbstractCharacter tarAc = (AbstractCharacter) awo;

25
src/engine/mobileAI/utilities/CombatUtilities.java

@ -139,37 +139,22 @@ public class CombatUtilities { @@ -139,37 +139,22 @@ public class CombatUtilities {
}
public static boolean triggerDefense(Mob agent, AbstractWorldObject target) {
int defenseScore = 0;
int attackScore = agent.getAtrHandOne();
int defense = 0;
int atr = agent.getAtrHandOne();
switch (target.getObjectType()) {
case PlayerCharacter:
defenseScore = ((AbstractCharacter) target).getDefenseRating();
defense = ((AbstractCharacter) target).getDefenseRating();
break;
case Mob:
Mob mob = (Mob) target;
if (mob.isSiege())
defenseScore = attackScore;
defense = atr;
break;
case Building:
return false;
}
int hitChance;
if (attackScore > defenseScore || defenseScore == 0)
hitChance = 94;
else if (attackScore == defenseScore && target.getObjectType() == GameObjectType.Mob)
hitChance = 10;
else {
float dif = attackScore / defenseScore;
if (dif <= 0.8f)
hitChance = 4;
else
hitChance = ((int) (450 * (dif - 0.8f)) + 4);
if (target.getObjectType() == GameObjectType.Building)
hitChance = 100;
}
return ThreadLocalRandom.current().nextInt(100) > hitChance;
return CombatManager.LandHit(atr,defense);
}
public static boolean triggerBlock(Mob agent, AbstractWorldObject ac) {

Loading…
Cancel
Save