From 93cbd8aae28f49057426e75d0a70753079ab663f Mon Sep 17 00:00:00 2001 From: Georg Reisinger Date: Thu, 31 Dec 2020 04:26:32 +0100 Subject: [PATCH] Battle Bugfixes --- src/main/java/at/reisinger/Battle.java | 608 +++++++++--------- .../at/reisinger/server/objects/Response.java | 36 +- 2 files changed, 322 insertions(+), 322 deletions(-) diff --git a/src/main/java/at/reisinger/Battle.java b/src/main/java/at/reisinger/Battle.java index b34eb3b..8a93c6d 100644 --- a/src/main/java/at/reisinger/Battle.java +++ b/src/main/java/at/reisinger/Battle.java @@ -73,338 +73,346 @@ public class Battle { deckPlayer1.setCards(d2); //Runden - int maxroundcount = 100; - for(int i = 0; d1.size()>i && d2.size()>i && i 0 && d2.size() > 0 && counter<=maxroundcount) { + //GLEICHER TYP Monster + if (!c1.getCardType().name().toUpperCase().equals("SPELL") && !c2.getCardType().name().toUpperCase().equals("SPELL")) { + System.out.println("Same Monster"); + //Check ob eine der beiden Carten ein Dragon ist + if ((c1.getCardType().name().toUpperCase().equals("DRANGON") && !c2.getCardType().name().toUpperCase().equals("DRANGON") || (!c1.getCardType().name().toUpperCase().equals("DRANGON") && c2.getCardType().name().toUpperCase().equals("DRANGON")))) { + //Eine der Karten is Dragon + System.out.println("Eine ist ein dragon"); + Card dragon = null; + int dragonOwner = 0; + if (c1.getCardType().name().toUpperCase().equals("DRAGON")) { + dragon = c1; + dragonOwner = 1; + } else if (c2.getCardType().name().toUpperCase().equals("DRAGON")) { + dragon = c2; + dragonOwner = 2; } else { - System.out.println("KEIN GOBLIN GEFUNDEN"); + System.out.println("KEIN DRAGON GEFUNDEN"); return false; } - if (dragon.getDamage() > goblin.getDamage()) { - //Drache ist stärker + if ((c1.getCardType().name().toUpperCase().equals("GOBLIN") && !c2.getCardType().name().toUpperCase().equals("GOBLIN") || (!c1.getCardType().name().toUpperCase().equals("GOBLIN") && c2.getCardType().name().toUpperCase().equals("GOBLIN")))) { + //Eine der Karten ist Goblin + System.out.println("Andere ist ein goblin"); + Card goblin = null; + if (c1.getCardType().name().toUpperCase().equals("GOBLIN")) { + goblin = c1; + } else if (c2.getCardType().name().toUpperCase().equals("GOBLIN")) { + goblin = c2; + } else { + System.out.println("KEIN GOBLIN GEFUNDEN"); + return false; + } + if (dragon.getDamage() > goblin.getDamage()) { + //Drache ist stärker + if (dragonOwner == 1) { + d1.add(c2); + d2.remove(c2); + this.scorePlayer1 += 3; + this.scorePlayer2 -= 5; + } else if (dragonOwner == 2) { + d2.add(c1); + d1.remove(c1); + this.scorePlayer1 -= 5; + this.scorePlayer2 += 3; + } + log.add("Player " + dragonOwner + " gewinnt!\nDrache ist stärker! Drache: " + dragon.getDamage() + " vs Goblin: " + goblin.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } else { + System.out.println("DRAW: Drache zu schwach um anzugreifen und GOBLIN zu feige."); + } + } else if ((c1.getCardType().name().toUpperCase().equals("ELF") && c1.getElementTyp().name().toUpperCase().equals("FIRE") && !c2.getCardType().name().toUpperCase().equals("ELF") || (!c1.getCardType().name().toUpperCase().equals("ELF") && c2.getElementTyp().name().toUpperCase().equals("FIRE") && c2.getCardType().name().toUpperCase().equals("ELF")))) { + //Eine der Karten ist der Fire Elf die andere Karte ist der drache + System.out.println("Andere ist ein elf"); + Card fireelf = null; if (dragonOwner == 1) { + fireelf = c2; + } else if (dragonOwner == 2) { + fireelf = c1; + } + + if (fireelf.getDamage() > dragon.getDamage()) { + //Fireelf ist stärker + if (dragonOwner == 1) { + d2.add(c1); + d1.remove(c1); + this.scorePlayer2 += 3; + this.scorePlayer1 -= 5; + } else if (dragonOwner == 2) { + d1.add(c2); + d2.remove(c2); + this.scorePlayer2 -= 5; + this.scorePlayer1 += 3; + } + log.add("Player " + dragonOwner + " gewinnt!\nWizzard ist stärker! Drache: " + dragon.getDamage() + " vs FireElves: " + fireelf.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } + //Sonst nix tun, weil der drache den elf ned angreifen kann + } else { + if (c1.getDamage() > c2.getDamage()) { d1.add(c2); d2.remove(c2); - this.scorePlayer1 += 3; - this.scorePlayer2 -= 5; - } else if (dragonOwner == 2) { + this.scorePlayer1 += 3; + this.scorePlayer2 -= 5; + log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } else if (c1.getDamage() < c2.getDamage()) { d2.add(c1); d1.remove(c1); - this.scorePlayer1 -= 5; - this.scorePlayer2 += 3; + this.scorePlayer2 += 3; + this.scorePlayer1 -= 5; + log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); } - log.add("Player "+dragonOwner+" gewinnt!\nDrache ist stärker! Drache: " + dragon.getDamage() + " vs Goblin: " + goblin.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - } else { - System.out.println("DRAW: Drache zu schwach um anzugreifen und GOBLIN zu feige."); - } - } else if ((c1.getCardType().name().toUpperCase().equals("ELF") && c1.getElementTyp().name().toUpperCase().equals("FIRE") && !c2.getCardType().name().toUpperCase().equals("ELF") || (!c1.getCardType().name().toUpperCase().equals("ELF") && c2.getElementTyp().name().toUpperCase().equals("FIRE") && c2.getCardType().name().toUpperCase().equals("ELF")))) { - //Eine der Karten ist der Fire Elf die andere Karte ist der drache - System.out.println("Andere ist ein elf"); - Card fireelf = null; - if (dragonOwner == 1) { - fireelf = c2; - } else if (dragonOwner == 2) { - fireelf = c1; } - if (fireelf.getDamage() > dragon.getDamage()) { - //Fireelf ist stärker - if (dragonOwner == 1) { - d2.add(c1); - d1.remove(c1); - this.scorePlayer2 += 3; - this.scorePlayer1 -= 5; - } else if (dragonOwner == 2) { + //Checkt ob eine der beiden karten ein wizzard ist und der andere ein ork + } else if ((c1.getCardType().name().toUpperCase().equals("WIZZARD") && c2.getCardType().name().toUpperCase().equals("ORK") || (c2.getCardType().name().toUpperCase().equals("WIZZARD") && c1.getCardType().name().toUpperCase().equals("ORK")))) { + System.out.println("Eine wizzard Andere ist ein ork"); + Card wizzard = null; + Card ork = null; + int wizzardOwner = 0; + if (c1.getCardType().name().toUpperCase().equals("WIZZARD")) { + wizzardOwner = 1; + wizzard = c1; + ork = c2; + } else if (c1.getCardType().name().toUpperCase().equals("WIZZARD")) { + wizzardOwner = 2; + wizzard = c2; + ork = c1; + } + if (wizzard.getDamage() > ork.getDamage()) { + if (wizzardOwner == 1) { d1.add(c2); d2.remove(c2); - this.scorePlayer2 -= 5; - this.scorePlayer1 += 3; + this.scorePlayer1 += 3; + this.scorePlayer2 -= 5; + } else if (wizzardOwner == 2) { + d2.add(c1); + d1.remove(c1); + this.scorePlayer2 += 3; + this.scorePlayer1 -= 5; } - log.add("Player "+dragonOwner+" gewinnt!\nWizzard ist stärker! Drache: " + dragon.getDamage() + " vs FireElves: " + fireelf.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); + + log.add("Player " + wizzardOwner + " gewinnt!\nWizzard ist stärker! Wizzard: " + wizzard.getDamage() + " vs Ork: " + ork.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); } - //Sonst nix tun, weil der drache den elf ned angreifen kann - }else{ - if(c1.getDamage() > c2.getDamage()){ + //Sonst nix tun, weil der ork dem wizzard keinen schaden machen kann + } else { + //PURE MONSTER + if (c1.getDamage() > c2.getDamage()) { d1.add(c2); d2.remove(c2); this.scorePlayer1 += 3; this.scorePlayer2 -= 5; - log.add("Player 1 gewinnt!\n"+c1.getElementTyp()+c1.getCardType()+" ist stärker! "+c1.getElementTyp()+c1.getCardType()+": " + c1.getDamage() + " vs "+c2.getElementTyp()+c2.getCardType()+": " + c2.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - }else if (c1.getDamage() < c2.getDamage()){ + log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } else if (c1.getDamage() < c2.getDamage()) { d2.add(c1); d1.remove(c1); this.scorePlayer2 += 3; this.scorePlayer1 -= 5; - log.add("Player 2 gewinnt!\n"+c2.getElementTyp()+c2.getCardType()+" ist stärker! "+c2.getElementTyp()+c2.getCardType()+": " + c2.getDamage() + " vs "+c1.getElementTyp()+c1.getCardType()+": " + c1.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); + log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); } + //sonst nix weil bei gleichen damage --> draw } + } else {//PURE SPELL & mixed + double damagePlayer1 = -1, damagePlayer2 = -1; - //Checkt ob eine der beiden karten ein wizzard ist und der andere ein ork - } else if((c1.getCardType().name().toUpperCase().equals("WIZZARD") && c2.getCardType().name().toUpperCase().equals("ORK") || (c2.getCardType().name().toUpperCase().equals("WIZZARD") && c1.getCardType().name().toUpperCase().equals("ORK")))){ - System.out.println("Eine wizzard Andere ist ein ork"); - Card wizzard = null; - Card ork = null; - int wizzardOwner = 0; - if(c1.getCardType().name().toUpperCase().equals("WIZZARD")){ - wizzardOwner = 1; - wizzard = c1; - ork = c2; - }else if(c1.getCardType().name().toUpperCase().equals("WIZZARD")){ - wizzardOwner = 2; - wizzard = c2; - ork = c1; - } - if(wizzard.getDamage() > ork.getDamage()){ - if(wizzardOwner == 1){ + if (c1.getCardType().name().toUpperCase().equals("KNIGHT") || c2.getCardType().name().toUpperCase().equals("KNIGHT")) { + //Mixed mit "Spezialeffekt" KNIGHT + System.out.println("Spell und knight"); + Card knight = null, other = null; + int knightOwner = 0; + if (c1.getCardType().name().toUpperCase().equals("KNIGHT")) { + knight = c1; + other = c2; + knightOwner = 1; + } else if (c2.getCardType().name().toUpperCase().equals("KNIGHT")) { + knight = c2; + other = c1; + knightOwner = 2; + } + double damageKnight = -1, damageOther = -1; + if (other.getElementTyp().name().toUpperCase().equals("WATER")) { + //tot + damageKnight = 0; + damageOther = other.getDamage(); + } else if (other.getElementTyp().name().toUpperCase().equals("FIRE") && knight.getElementTyp().name().equals("REGULAR")) { + //not effective + damageKnight = knight.getDamage() / 2; + //effective + damageOther = other.getDamage() * 2; + } else if (other.getElementTyp().name().toUpperCase().equals("FIRE") && knight.getElementTyp().name().equals("FIRE")) { + //no effect + damageKnight = knight.getDamage(); + //no effect + damageOther = other.getDamage(); + } else if (other.getElementTyp().name().toUpperCase().equals("FIRE") && knight.getElementTyp().name().equals("WATER")) { + //effective + damageKnight = knight.getDamage() * 2; + //not effective + damageOther = other.getDamage() / 2; + } else if (other.getElementTyp().name().toUpperCase().equals("REGULAR") && knight.getElementTyp().name().equals("REGULAR")) { + //no effect + damageKnight = knight.getDamage(); + //no effect + damageOther = other.getDamage(); + } else if (other.getElementTyp().name().toUpperCase().equals("REGULAR") && knight.getElementTyp().name().equals("FIRE")) { + //effective + damageKnight = knight.getDamage() * 2; + //not effective + damageOther = other.getDamage() / 2; + } else if (other.getElementTyp().name().toUpperCase().equals("REGULAR") && knight.getElementTyp().name().equals("WATER")) { + //not effective + damageKnight = knight.getDamage() / 2; + //effective + damageOther = other.getDamage() * 2; + } + if (damageKnight > damageOther) { + if (knightOwner == 1) { + d1.add(c2); + d2.remove(c2); + this.scorePlayer1 += 3; + this.scorePlayer2 -= 5; + log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + damageKnight + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + damageOther + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } else if (knightOwner == 2) { + d2.add(c1); + d1.remove(c1); + this.scorePlayer2 += 3; + this.scorePlayer1 -= 5; + log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + damageKnight + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + damageOther + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } + } else if (damageKnight < damageOther) { + if (knightOwner == 2) { + d1.add(c2); + d2.remove(c2); + this.scorePlayer1 += 3; + this.scorePlayer2 -= 5; + log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + damageOther + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + damageKnight + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } else if (knightOwner == 1) { + d2.add(c1); + d1.remove(c1); + this.scorePlayer2 += 3; + this.scorePlayer1 -= 5; + log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + damageOther + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + damageKnight + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } + } + } else if (c1.getCardType().name().toUpperCase().equals("KRAKEN") || c2.getCardType().name().toUpperCase().equals("KRAKEN")) { + //Mixed mit "Spezialeffekt" KRAKEN + if (c1.getCardType().name().toUpperCase().equals("KRAKEN")) { d1.add(c2); d2.remove(c2); - this.scorePlayer1 += 3; - this.scorePlayer2 -= 5; - }else if (wizzardOwner == 2){ + this.scorePlayer1 += 3; + this.scorePlayer2 -= 5; + log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + " vs " + c2.getElementTyp() + c2.getCardType() + ": 0\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } else if (c2.getCardType().name().toUpperCase().equals("KRAKEN")) { d2.add(c1); d1.remove(c1); - this.scorePlayer2 += 3; - this.scorePlayer1 -= 5; - } - - log.add("Player "+wizzardOwner+" gewinnt!\nWizzard ist stärker! Wizzard: " + wizzard.getDamage() + " vs Ork: " + ork.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - } - //Sonst nix tun, weil der ork dem wizzard keinen schaden machen kann - }else{ - //PURE MONSTER - if(c1.getDamage() > c2.getDamage()){ - d1.add(c2); - d2.remove(c2); - this.scorePlayer1 += 3; - this.scorePlayer2 -= 5; - log.add("Player 1 gewinnt!\n"+c1.getElementTyp()+c1.getCardType()+" ist stärker! "+c1.getElementTyp()+c1.getCardType()+": " + c1.getDamage() + " vs "+c2.getElementTyp()+c2.getCardType()+": " + c2.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - }else if (c1.getDamage() < c2.getDamage()){ - d2.add(c1); - d1.remove(c1); - this.scorePlayer2 += 3; - this.scorePlayer1 -= 5; - log.add("Player 2 gewinnt!\n"+c2.getElementTyp()+c2.getCardType()+" ist stärker! "+c2.getElementTyp()+c2.getCardType()+": " + c2.getDamage() + " vs "+c1.getElementTyp()+c1.getCardType()+": " + c1.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - } - //sonst nix weil bei gleichen damage --> draw - } - } else {//PURE SPELL & mixed - double damagePlayer1 = -1, damagePlayer2 = -1; - - if(c1.getCardType().name().toUpperCase().equals("KNIGHT") || c2.getCardType().name().toUpperCase().equals("KNIGHT")){ - //Mixed mit "Spezialeffekt" KNIGHT - System.out.println("Spell und knight"); - Card knight =null, other = null; - int knightOwner = 0; - if(c1.getCardType().name().toUpperCase().equals("KNIGHT")){ - knight = c1; - other = c2; - knightOwner = 1; - }else if(c2.getCardType().name().toUpperCase().equals("KNIGHT")){ - knight = c2; - other = c1; - knightOwner = 2; - } - double damageKnight = -1, damageOther = -1; - if (other.getElementTyp().name().toUpperCase().equals("WATER")){ - //tot - damageKnight = 0; - damageOther = other.getDamage(); - }else if (other.getElementTyp().name().toUpperCase().equals("FIRE") && knight.getElementTyp().name().equals("REGULAR")) { - //not effective - damageKnight = knight.getDamage() / 2; - //effective - damageOther = other.getDamage() *2; - } else if (other.getElementTyp().name().toUpperCase().equals("FIRE") && knight.getElementTyp().name().equals("FIRE")) { - //no effect - damageKnight = knight.getDamage(); - //no effect - damageOther = other.getDamage(); - }else if (other.getElementTyp().name().toUpperCase().equals("FIRE") && knight.getElementTyp().name().equals("WATER")) { - //effective - damageKnight = knight.getDamage() * 2; - //not effective - damageOther = other.getDamage() / 2; - }else if (other.getElementTyp().name().toUpperCase().equals("REGULAR") && knight.getElementTyp().name().equals("REGULAR")) { - //no effect - damageKnight = knight.getDamage(); - //no effect - damageOther = other.getDamage(); - } else if (other.getElementTyp().name().toUpperCase().equals("REGULAR") && knight.getElementTyp().name().equals("FIRE")) { - //effective - damageKnight = knight.getDamage() * 2; - //not effective - damageOther = other.getDamage() / 2; - }else if (other.getElementTyp().name().toUpperCase().equals("REGULAR") && knight.getElementTyp().name().equals("WATER")) { - //not effective - damageKnight = knight.getDamage() / 2; - //effective - damageOther = other.getDamage() * 2; - } - if(damageKnight > damageOther){ - if(knightOwner == 1){ - d1.add(c2); - d2.remove(c2); - this.scorePlayer1 += 3; - this.scorePlayer2 -= 5; - log.add("Player 1 gewinnt!\n"+c1.getElementTyp()+c1.getCardType()+" ist stärker! "+c1.getElementTyp()+c1.getCardType()+": " + damageKnight + " vs "+c2.getElementTyp()+c2.getCardType()+": " + damageOther + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - }else if(knightOwner == 2){ - d2.add(c1); - d1.remove(c1); - this.scorePlayer2 += 3; - this.scorePlayer1 -= 5; - log.add("Player 2 gewinnt!\n"+c2.getElementTyp()+c2.getCardType()+" ist stärker! "+c2.getElementTyp()+c2.getCardType()+": " + damageKnight + " vs "+c1.getElementTyp()+c1.getCardType()+": " + damageOther + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - } - }else if(damageKnight < damageOther){ - if(knightOwner == 2){ - d1.add(c2); - d2.remove(c2); - this.scorePlayer1 += 3; - this.scorePlayer2 -= 5; - log.add("Player 1 gewinnt!\n"+c1.getElementTyp()+c1.getCardType()+" ist stärker! "+c1.getElementTyp()+c1.getCardType()+": " + damageOther + " vs "+c2.getElementTyp()+c2.getCardType()+": " + damageKnight + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - }else if(knightOwner == 1){ - d2.add(c1); - d1.remove(c1); - this.scorePlayer2 += 3; - this.scorePlayer1 -= 5; - log.add("Player 2 gewinnt!\n"+c2.getElementTyp()+c2.getCardType()+" ist stärker! "+c2.getElementTyp()+c2.getCardType()+": " + damageOther + " vs "+c1.getElementTyp()+c1.getCardType()+": " + damageKnight + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - } - } - }else if(c1.getCardType().name().toUpperCase().equals("KRAKEN") || c2.getCardType().name().toUpperCase().equals("KRAKEN")){ - //Mixed mit "Spezialeffekt" KRAKEN - if(c1.getCardType().name().toUpperCase().equals("KRAKEN")){ - d1.add(c2); - d2.remove(c2); - this.scorePlayer1 += 3; - this.scorePlayer2 -= 5; - log.add("Player 1 gewinnt!\n"+c1.getElementTyp()+c1.getCardType()+" ist stärker! "+c1.getElementTyp()+c1.getCardType()+": " + c1.getDamage() + " vs "+c2.getElementTyp()+c2.getCardType()+": 0\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - }else if(c2.getCardType().name().toUpperCase().equals("KRAKEN")){ - d2.add(c1); - d1.remove(c1); - this.scorePlayer2 += 3; - this.scorePlayer1 -= 5; - log.add("Player 2 gewinnt!\n"+c2.getElementTyp()+c2.getCardType()+" ist stärker! "+c2.getElementTyp()+c2.getCardType()+": " + c2.getDamage() + " vs "+c1.getElementTyp()+c1.getCardType()+": 0\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - } - }else{ - ////PURE SPELL & mixed mit elementen - System.out.println("Spell und mixed mit elementen"); - //Player 1 Damage berechnen - if (c1.getElementTyp().name().toUpperCase().equals("FIRE")) { - if (c2.getElementTyp().name().toUpperCase().equals("REGULAR")) { - //effective - damagePlayer1 = c1.getDamage() * 2; - } else if (c2.getElementTyp().name().toUpperCase().equals("WATER")) { - //not effective - damagePlayer1 = c1.getDamage() / 2; - } else if (c2.getElementTyp().name().toUpperCase().equals("FIRE")) { - //no effect - damagePlayer1 = c1.getDamage(); - } - } else if (c1.getElementTyp().name().toUpperCase().equals("WATER")) { - if (c2.getElementTyp().name().toUpperCase().equals("FIRE")) { - //effective - damagePlayer1 = c1.getDamage() * 2; - } else if (c2.getElementTyp().name().toUpperCase().equals("WATER")) { - //no effect - damagePlayer1 = c1.getDamage(); - } else if (c2.getElementTyp().name().toUpperCase().equals("REGULAR")) { - //not effective - damagePlayer1 = c1.getDamage() / 2; - } - } else if (c1.getElementTyp().name().toUpperCase().equals("REGULAR")) { - if (c2.getElementTyp().name().toUpperCase().equals("WATER")) { - //effective - damagePlayer1 = c1.getDamage() * 2; - } else if (c2.getElementTyp().name().toUpperCase().equals("FIRE")) { - //not effective - damagePlayer1 = c1.getDamage() / 2; - } else if (c2.getElementTyp().name().toUpperCase().equals("REGULAR")) { - //no effect - damagePlayer1 = c1.getDamage(); - } - } - //P2 damage - if (c2.getElementTyp().name().toUpperCase().equals("FIRE")) { - if (c1.getElementTyp().name().toUpperCase().equals("REGULAR")) { - //effective - damagePlayer2 = c2.getDamage() * 2; - } else if (c1.getElementTyp().name().toUpperCase().equals("WATER")) { - //not effective - damagePlayer2 = c2.getDamage() / 2; - } else if (c1.getElementTyp().name().toUpperCase().equals("FIRE")) { - //no effect - damagePlayer2 = c2.getDamage(); - } - } else if (c2.getElementTyp().name().toUpperCase().equals("WATER")) { - if (c1.getElementTyp().name().toUpperCase().equals("FIRE")) { - //effective - damagePlayer2 = c2.getDamage() * 2; - } else if (c1.getElementTyp().name().toUpperCase().equals("WATER")) { - //no effect - damagePlayer2 = c2.getDamage(); - } else if (c1.getElementTyp().name().toUpperCase().equals("REGULAR")) { - //not effective - damagePlayer2 = c2.getDamage() / 2; - } - } else if (c2.getElementTyp().name().toUpperCase().equals("REGULAR")) { - if (c1.getElementTyp().name().toUpperCase().equals("WATER")) { - //effective - damagePlayer2 = c2.getDamage() * 2; - } else if (c1.getElementTyp().name().toUpperCase().equals("FIRE")) { - //not effective - damagePlayer2 = c2.getDamage() / 2; - } else if (c1.getElementTyp().name().toUpperCase().equals("REGULAR")) { - //no effect - damagePlayer2 = c2.getDamage(); - } - } - - if (damagePlayer1 > -1 && damagePlayer2 > -1) { - if (damagePlayer1 > damagePlayer2) { - d1.add(c2); - d2.remove(c2); - this.scorePlayer1 += 3; - this.scorePlayer2 -= 5; - log.add("Player 1 gewinnt!\n"+c1.getElementTyp()+c1.getCardType()+" ist stärker! "+c1.getElementTyp()+c1.getCardType()+": " + damagePlayer1 + " vs "+c2.getElementTyp()+c2.getCardType()+": " + damagePlayer2 + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); - } else if (damagePlayer2 > damagePlayer1) { - d2.add(c1); - d1.remove(c1); - this.scorePlayer2 += 3; - this.scorePlayer1 -= 5; - log.add("Player 2 gewinnt!\n"+c2.getElementTyp()+c2.getCardType()+" ist stärker! "+c2.getElementTyp()+c2.getCardType()+": " + damagePlayer2 + " vs "+c1.getElementTyp()+c1.getCardType()+": " + damagePlayer1 + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: "+ scorePlayer2); + this.scorePlayer2 += 3; + this.scorePlayer1 -= 5; + log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + " vs " + c1.getElementTyp() + c1.getCardType() + ": 0\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); } } else { - System.out.println("Damage konnte nicht berechnet werden"); - return false; + ////PURE SPELL & mixed mit elementen + System.out.println("Spell und mixed mit elementen"); + //Player 1 Damage berechnen + if (c1.getElementTyp().name().toUpperCase().equals("FIRE")) { + if (c2.getElementTyp().name().toUpperCase().equals("REGULAR")) { + //effective + damagePlayer1 = c1.getDamage() * 2; + } else if (c2.getElementTyp().name().toUpperCase().equals("WATER")) { + //not effective + damagePlayer1 = c1.getDamage() / 2; + } else if (c2.getElementTyp().name().toUpperCase().equals("FIRE")) { + //no effect + damagePlayer1 = c1.getDamage(); + } + } else if (c1.getElementTyp().name().toUpperCase().equals("WATER")) { + if (c2.getElementTyp().name().toUpperCase().equals("FIRE")) { + //effective + damagePlayer1 = c1.getDamage() * 2; + } else if (c2.getElementTyp().name().toUpperCase().equals("WATER")) { + //no effect + damagePlayer1 = c1.getDamage(); + } else if (c2.getElementTyp().name().toUpperCase().equals("REGULAR")) { + //not effective + damagePlayer1 = c1.getDamage() / 2; + } + } else if (c1.getElementTyp().name().toUpperCase().equals("REGULAR")) { + if (c2.getElementTyp().name().toUpperCase().equals("WATER")) { + //effective + damagePlayer1 = c1.getDamage() * 2; + } else if (c2.getElementTyp().name().toUpperCase().equals("FIRE")) { + //not effective + damagePlayer1 = c1.getDamage() / 2; + } else if (c2.getElementTyp().name().toUpperCase().equals("REGULAR")) { + //no effect + damagePlayer1 = c1.getDamage(); + } + } + //P2 damage + if (c2.getElementTyp().name().toUpperCase().equals("FIRE")) { + if (c1.getElementTyp().name().toUpperCase().equals("REGULAR")) { + //effective + damagePlayer2 = c2.getDamage() * 2; + } else if (c1.getElementTyp().name().toUpperCase().equals("WATER")) { + //not effective + damagePlayer2 = c2.getDamage() / 2; + } else if (c1.getElementTyp().name().toUpperCase().equals("FIRE")) { + //no effect + damagePlayer2 = c2.getDamage(); + } + } else if (c2.getElementTyp().name().toUpperCase().equals("WATER")) { + if (c1.getElementTyp().name().toUpperCase().equals("FIRE")) { + //effective + damagePlayer2 = c2.getDamage() * 2; + } else if (c1.getElementTyp().name().toUpperCase().equals("WATER")) { + //no effect + damagePlayer2 = c2.getDamage(); + } else if (c1.getElementTyp().name().toUpperCase().equals("REGULAR")) { + //not effective + damagePlayer2 = c2.getDamage() / 2; + } + } else if (c2.getElementTyp().name().toUpperCase().equals("REGULAR")) { + if (c1.getElementTyp().name().toUpperCase().equals("WATER")) { + //effective + damagePlayer2 = c2.getDamage() * 2; + } else if (c1.getElementTyp().name().toUpperCase().equals("FIRE")) { + //not effective + damagePlayer2 = c2.getDamage() / 2; + } else if (c1.getElementTyp().name().toUpperCase().equals("REGULAR")) { + //no effect + damagePlayer2 = c2.getDamage(); + } + } + + if (damagePlayer1 > -1 && damagePlayer2 > -1) { + if (damagePlayer1 > damagePlayer2) { + d1.add(c2); + d2.remove(c2); + this.scorePlayer1 += 3; + this.scorePlayer2 -= 5; + log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + damagePlayer1 + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + damagePlayer2 + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } else if (damagePlayer2 > damagePlayer1) { + d2.add(c1); + d1.remove(c1); + this.scorePlayer2 += 3; + this.scorePlayer1 -= 5; + log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + damagePlayer2 + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + damagePlayer1 + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2); + } + } else { + System.out.println("Damage konnte nicht berechnet werden"); + return false; + } } } } diff --git a/src/main/java/at/reisinger/server/objects/Response.java b/src/main/java/at/reisinger/server/objects/Response.java index 4e010de..80928e3 100644 --- a/src/main/java/at/reisinger/server/objects/Response.java +++ b/src/main/java/at/reisinger/server/objects/Response.java @@ -410,42 +410,34 @@ public class Response { if(new DBConnection().addBattleLog(openBattle.getId()+"", openBattle.getPlayer1().getName(), openBattle.getPlayer2().getName(), openBattle.getScorePlayer1()+"", openBattle.getScorePlayer2() +"")){ if(new DBConnection().delDeck(openBattle.getPlayer1().getCredentials().getUsername()) && new DBConnection().delDeck(openBattle.getPlayer2().getCredentials().getUsername())) { //DEL OLD DECK CARDS + ArrayList oldDeck1 = new ArrayList(); for (Card ca: openBattle.getDeckPlayer1Init().getCards()){ - if(!new DBConnection().delUserCard(openBattle.getPlayer1().getCredentials().getUsername(), ca.getName())){ - sendResponse("Error Deleting user card1: " + ca.getName(), "500"); - } + oldDeck1.add(ca.getName()); } + ArrayList oldDeck2 = new ArrayList(); for (Card ca: openBattle.getDeckPlayer2Init().getCards()){ - if(!new DBConnection().delUserCard(openBattle.getPlayer2().getCredentials().getUsername(), ca.getName())){ - sendResponse("Error Deleting user card2: " + ca.getName(), "500"); - } + oldDeck2.add(ca.getName()); } //DEL NEW CARDS IF EXIST Cards player1cards = new DBConnection().getCards(openBattle.getPlayer1().getCredentials().getUsername()); - ArrayList player1CardsList = new ArrayList(); - for(Card ca:player1cards.getCards()){ - player1CardsList.add(ca.getName()); + for(Card ca:openBattle.getDeckPlayer1().getCards()){ + oldDeck1.add(ca.getName()); } if(player1cards.getCards() != null && !player1cards.getCards().isEmpty()) { - for (Card ca : openBattle.getDeckPlayer1().getCards()) { - if (player1CardsList.contains(ca.getName())){ - if(!new DBConnection().delUserCard(openBattle.getPlayer1().getCredentials().getUsername(), ca.getName())){ - sendResponse("Error Deleting user card1: " + ca.getName(), "500"); - } + for (String ca : oldDeck1) { + if(!new DBConnection().delUserCard(openBattle.getPlayer1().getCredentials().getUsername(), ca)){ + sendResponse("Error Deleting user card1: " + ca, "500"); } } } Cards player2cards = new DBConnection().getCards(openBattle.getPlayer2().getCredentials().getUsername()); - ArrayList player2CardsList = new ArrayList(); - for(Card ca:player2cards.getCards()){ - player2CardsList.add(ca.getName()); + for(Card ca:openBattle.getDeckPlayer2().getCards()){ + oldDeck2.add(ca.getName()); } if(player2cards.getCards() != null && !player2cards.getCards().isEmpty()) { - for (Card ca : openBattle.getDeckPlayer2().getCards()) { - if (player2CardsList.contains(ca.getName())){ - if(!new DBConnection().delUserCard(openBattle.getPlayer2().getCredentials().getUsername(), ca.getName())){ - sendResponse("Error Deleting user card2: " + ca.getName(), "500"); - } + for (String ca : oldDeck2) { + if(!new DBConnection().delUserCard(openBattle.getPlayer2().getCredentials().getUsername(), ca)){ + sendResponse("Error Deleting user card2: " + ca, "500"); } } }