Skip to content

Commit

Permalink
reworked damage scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
mklemmingen committed Jan 7, 2024
1 parent 5e30b15 commit 0cca7e8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
38 changes: 25 additions & 13 deletions core/src/com/boomchess/game/backend/Damage.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ public static void dealBigBoom(int positionAttX, int positionAttY, int positionD
// avoids runtime type checks and casts, ensure each soldier object has this method first
if (soldierAttack instanceof calculateDamageInterface) {
damage = ((calculateDamageInterface) soldierAttack).calculateDamage(soldierDefend);
// damage is reduced depending on the health of the attacking piece
damage = damage * (((calculateDamageInterface) soldierAttack).getStandardHealth() /
soldierAttack.getHealth());

// if the currentHealth / standardHealth is lower than 0.5, we 0.75 the damage
if( ( (double) soldierAttack.getHealth() /
((calculateDamageInterface) soldierAttack).getStandardHealth()) < 0.5 ){
damage = (int) (damage * 0.75);
}

//damage is reduced by the amount of enemies surrounding the attacking piece
// for this, we check the surroundings, count enemy figurines and reduce damage by / that amount
int enemyCount = 0;
Expand All @@ -105,9 +109,13 @@ public static void dealBigBoom(int positionAttX, int positionAttY, int positionD
for (int i = startX; i <= endX; i++) {
for (int j = startY; j <= endY; j++) {
if (i == positionAttX && j == positionAttY) continue; // Skip on checking the original piece

if (!(gameBoard[i][j] instanceof Empty)) {

if (!(gameBoard[i][j] instanceof Hill)) {

String hurtColor = gameBoard[i][j].getTeamColor();

if (!hurtColor.equals(soldierAttack.getTeamColor())) {
enemyCount++;
} else {
Expand All @@ -118,16 +126,19 @@ public static void dealBigBoom(int positionAttX, int positionAttY, int positionD
}
}

// lower the damage by the amount of enemies surrounding the attacking piece
if (enemyCount == 0) {
enemyCount = 1;
} // impossible theoretically, but might occur
damage = damage / enemyCount ;
// Adjust damage based on the number of surrounding enemies and friends
double enemyModifier = 1 - (0.05 * enemyCount);
double friendModifier = 1 + (0.1 * friendCount);

// Apply modifiers to the damage
damage *= enemyModifier;
damage *= friendModifier;

// increase the damage by the amount of friends surrounding the attacking piece
if(friendCount != 0) {
damage = damage * friendCount;
// Ensure damage is not negative
if (damage < 0) {
damage = 0;
}

}

damagePiece(damage, positionAttX, positionAttY, positionDefX, positionDefY);
Expand All @@ -154,6 +165,9 @@ public static void damagePiece(int damage, int positionAttX, int positionAttY,
currentHealth = currentHealth - calculatedDamage;
}

// add damageNumber actor if piece hasn't died
BoomChess.addDamageNumber(positionDefX, positionDefY, damage);

// if the defending piece is a general, we need to check if it is dead
// if it is dead, we need to end the game

Expand All @@ -169,8 +183,6 @@ public static void damagePiece(int damage, int positionAttX, int positionAttY,
// add a speech bubble to the attacker
SpeechBubbles.createSpeechDefeatEnemy(positionAttX, positionAttY);
} else {
// add damageNumber actor if piece hasn't died
BoomChess.addDamageNumber(positionDefX, positionDefY, damage);
// set the new health of the piece to the currentHealth variable
gameBoard[positionDefX][positionDefY].setHealth(currentHealth);
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/com/boomchess/game/backend/subsoldier/Artillery.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public Artillery(String teamColor) {

public int calculateDamage(Soldier soldierDefend) {

// deals 1-5 damage
// deals 5-10 damage
// advantages: deals +5 to infantry

int minValue = 1;
int maxValue = 5;
int minValue = 5;
int maxValue = 10;

// we achieve this randomisation using random.Math`s floor and random methods
// that generate a random number between 0 and 1 that we multiply
Expand Down Expand Up @@ -97,6 +97,6 @@ public void makeASound(){
}

public Texture showInterval() {
return BoomChess.oneFive;
return BoomChess.fiveTen;
}
}
6 changes: 3 additions & 3 deletions core/src/com/boomchess/game/backend/subsoldier/Infantry.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public int calculateDamage(Soldier soldierDefend) {
// deals 01-20 damage
// advantages +5 to attacking helicopters

int minValue = 1;
int minValue = 5;
int maxValue = 20;

// we achieve this randomisation using random.Math`s floor and random methods
Expand All @@ -54,7 +54,7 @@ public int getStandardHealth(){
public int defendAndBleed(int damage, Soldier soldierAttack) {
// calculate resistance to attack based on attackingSoldier
if (soldierAttack instanceof Helicopter){
return damage - 5;
return damage - 2;
}

return damage;
Expand Down Expand Up @@ -98,6 +98,6 @@ public void makeASound(){
}

public Texture showInterval() {
return BoomChess.oneTwenty;
return BoomChess.fiveTwenty;
}
}
2 changes: 1 addition & 1 deletion core/src/com/boomchess/game/backend/subsoldier/Tank.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public ArrayList<Coordinates> mathMove(int positionX, int positionY) {
public int defendAndBleed(int damage, Soldier soldierAttack) {
// calculate resistance to attack based on attackingSoldier
if (soldierAttack instanceof Wardog){
return damage - 5;
return damage - 2;
}
return damage;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/boomchess/game/backend/subsoldier/Wardog.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public ArrayList<Coordinates> mathMove(int positionX, int positionY) {
public int defendAndBleed(int damage, Soldier soldierAttack) {
// calculate resistance to attack based on attackingSoldier
if (soldierAttack instanceof Infantry){
return damage - 5;
return damage - 2;
}

return damage;
Expand Down

0 comments on commit 0cca7e8

Please sign in to comment.