From 0cca7e81a88f8ab1ed9e268de179de8bd906a111 Mon Sep 17 00:00:00 2001 From: Marty <104225647+mklemmingen@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:55:55 +0100 Subject: [PATCH] reworked damage scaling --- .../com/boomchess/game/backend/Damage.java | 38 ++++++++++++------- .../game/backend/subsoldier/Artillery.java | 8 ++-- .../game/backend/subsoldier/Infantry.java | 6 +-- .../game/backend/subsoldier/Tank.java | 2 +- .../game/backend/subsoldier/Wardog.java | 2 +- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/core/src/com/boomchess/game/backend/Damage.java b/core/src/com/boomchess/game/backend/Damage.java index 83ba785..d1926af 100644 --- a/core/src/com/boomchess/game/backend/Damage.java +++ b/core/src/com/boomchess/game/backend/Damage.java @@ -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; @@ -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 { @@ -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); @@ -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 @@ -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); } diff --git a/core/src/com/boomchess/game/backend/subsoldier/Artillery.java b/core/src/com/boomchess/game/backend/subsoldier/Artillery.java index 0d4546f..28d6c63 100644 --- a/core/src/com/boomchess/game/backend/subsoldier/Artillery.java +++ b/core/src/com/boomchess/game/backend/subsoldier/Artillery.java @@ -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 @@ -97,6 +97,6 @@ public void makeASound(){ } public Texture showInterval() { - return BoomChess.oneFive; + return BoomChess.fiveTen; } } diff --git a/core/src/com/boomchess/game/backend/subsoldier/Infantry.java b/core/src/com/boomchess/game/backend/subsoldier/Infantry.java index 750430e..015b1c8 100644 --- a/core/src/com/boomchess/game/backend/subsoldier/Infantry.java +++ b/core/src/com/boomchess/game/backend/subsoldier/Infantry.java @@ -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 @@ -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; @@ -98,6 +98,6 @@ public void makeASound(){ } public Texture showInterval() { - return BoomChess.oneTwenty; + return BoomChess.fiveTwenty; } } diff --git a/core/src/com/boomchess/game/backend/subsoldier/Tank.java b/core/src/com/boomchess/game/backend/subsoldier/Tank.java index c494f39..277d3f1 100644 --- a/core/src/com/boomchess/game/backend/subsoldier/Tank.java +++ b/core/src/com/boomchess/game/backend/subsoldier/Tank.java @@ -138,7 +138,7 @@ public ArrayList 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; } diff --git a/core/src/com/boomchess/game/backend/subsoldier/Wardog.java b/core/src/com/boomchess/game/backend/subsoldier/Wardog.java index c154ba0..9526ae4 100644 --- a/core/src/com/boomchess/game/backend/subsoldier/Wardog.java +++ b/core/src/com/boomchess/game/backend/subsoldier/Wardog.java @@ -176,7 +176,7 @@ public ArrayList 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;