Skip to content

Commit

Permalink
add EffectEvent for EightDiagramTactic
Browse files Browse the repository at this point in the history
  • Loading branch information
scolleyHuang committed Apr 27, 2024
1 parent d8b2ee3 commit c125ea7
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 9 deletions.
8 changes: 8 additions & 0 deletions LegendsOfTheThreeKingdoms/domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.3</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,11 @@ public void updateTopBehavior(Behavior behavior) {
public boolean isTopBehaviorEmpty() {
return topBehavior.empty();
}

public HandCard drawCardForEightDiagramTactic() {
refreshDeckWhenCardsNumLessThen(1);
List<HandCard> cards = deck.deal(1);
return cards.get(0);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import com.gaas.threeKingdoms.gamephase.GeneralDying;
import com.gaas.threeKingdoms.handcard.HandCard;
import com.gaas.threeKingdoms.handcard.PlayType;
import com.gaas.threeKingdoms.handcard.equipmentcard.armorcard.ArmorCard;
import com.gaas.threeKingdoms.player.Player;

import java.util.ArrayList;
import java.util.List;

import static com.gaas.threeKingdoms.handcard.PlayCard.isDodgeCard;
import static com.gaas.threeKingdoms.handcard.PlayCard.isEightDiagramTacticCard;


public class NormalActiveKillBehavior extends Behavior {
Expand Down Expand Up @@ -76,6 +78,15 @@ public List<DomainEvent> doAcceptedTargetPlayerPlayCard(String playerId, String
List<PlayerEvent> playerEvents = game.getPlayers().stream().map(PlayerEvent::new).toList();
PlayCardEvent playCardEvent = new PlayCardEvent("出牌", playerId, targetPlayerId, cardId, playType, game.getGameId(), playerEvents, roundEvent, game.getGamePhase().getPhaseName());
return List.of(playCardEvent, playerDamagedEvent);
} else if (isEquipment(playType) && isEightDiagramTacticCard(cardId)) {
ArmorCard armorCard = damagedPlayer.getEquipment().getArmor();
List<DomainEvent> domainEvents = armorCard.equipmentEffect(game);

isOneRound = domainEvents.stream()
.map(EffectEvent.class::cast)
.allMatch(EffectEvent::isSuccess);

return domainEvents;
} else {
//TODO:怕有其他效果或殺的其他case
return null;
Expand All @@ -91,6 +102,10 @@ private boolean isSkip(String playType) {
return PlayType.SKIP.getPlayType().equals(playType);
}

private boolean isEquipment(String playType) {
return PlayType.EQUIPMENT_ACTIVE.getPlayType().equals(playType);
}

private PlayerDamagedEvent createPlayerDamagedEvent(int originalHp, Player damagedPlayer) {
return new PlayerDamagedEvent(damagedPlayer.getId(), originalHp, damagedPlayer.getHP());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import com.gaas.threeKingdoms.behavior.Behavior;
import com.gaas.threeKingdoms.behavior.PlayCardBehaviorHandler;
import com.gaas.threeKingdoms.behavior.behavior.EightDiagramTacticBehavior;
import com.gaas.threeKingdoms.behavior.behavior.MinusMountsBehavior;
import com.gaas.threeKingdoms.handcard.HandCard;
import com.gaas.threeKingdoms.handcard.equipmentcard.armorcard.EightDiagramTactic;
import com.gaas.threeKingdoms.handcard.equipmentcard.mountscard.MinusMountsCard;
import com.gaas.threeKingdoms.player.Player;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gaas.threeKingdoms.events;

import lombok.Getter;

@Getter
public class EffectEvent extends DomainEvent {
private final boolean isSuccess;
public EffectEvent(String name, String message, boolean isSuccess) {
super(name, message);
this.isSuccess = isSuccess;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.gaas.threeKingdoms.events;


import lombok.Getter;

@Getter
public class EightDiagramTacticEffectEvent extends EffectEvent {
private final String drawCardId;

public EightDiagramTacticEffectEvent(String message, String drawCardId, boolean isSuccess) {
super("EightDiagramTacticEffectEvent", message, isSuccess);
this.drawCardId = drawCardId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public Deck() {
shuffle();
}

public Deck(List<HandCard> handCards) {
cardDeck.addAll(handCards);
}

public void shuffle() {
ShuffleWrapper.shuffle(cardDeck);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,11 @@ public static boolean isPeachCard(String cardId){
.anyMatch(c->c.getCardId().equals(cardId));
}

public static boolean isEightDiagramTacticCard(String cardId){
return Arrays.stream(PlayCard.values())
.filter(c->c.getCardName().equals("八卦陣"))
.anyMatch(c->c.getCardId().equals(cardId));
}


}
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.gaas.threeKingdoms.handcard.equipmentcard;

import com.gaas.threeKingdoms.Game;
import com.gaas.threeKingdoms.events.DomainEvent;
import com.gaas.threeKingdoms.events.EffectEvent;
import com.gaas.threeKingdoms.handcard.HandCard;
import com.gaas.threeKingdoms.handcard.PlayCard;
import lombok.Getter;

import java.util.List;

@Getter
public abstract class EquipmentCard extends HandCard {
protected boolean hasSpecialEffect = false;

public EquipmentCard(PlayCard playCard) {
super(playCard);
}

public abstract List<DomainEvent> equipmentEffect(Game game);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.gaas.threeKingdoms.handcard.equipmentcard.EquipmentCard;
import com.gaas.threeKingdoms.player.Player;

public class ArmorCard extends EquipmentCard {
public abstract class ArmorCard extends EquipmentCard {

public ArmorCard(PlayCard playCard) {
super(playCard);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.gaas.threeKingdoms.handcard.equipmentcard.armorcard;

import com.gaas.threeKingdoms.Game;
import com.gaas.threeKingdoms.events.DomainEvent;
import com.gaas.threeKingdoms.events.EffectEvent;
import com.gaas.threeKingdoms.events.EightDiagramTacticEffectEvent;
import com.gaas.threeKingdoms.handcard.HandCard;
import com.gaas.threeKingdoms.handcard.PlayCard;
import com.gaas.threeKingdoms.player.Equipment;
import com.gaas.threeKingdoms.player.Player;
import com.gaas.threeKingdoms.handcard.Suit;

import java.util.List;

public class EightDiagramTactic extends ArmorCard {

Expand All @@ -11,4 +17,14 @@ public EightDiagramTactic(PlayCard playCard) {
hasSpecialEffect = true;
}

@Override
public List<DomainEvent> equipmentEffect(Game game) {
HandCard card = game.drawCardForEightDiagramTactic();
boolean isEffectSuccess = isEffectSuccess(card);
return List.of(new EightDiagramTacticEffectEvent("發動八卦陣效果", card.getId(), isEffectSuccess));
}

private boolean isEffectSuccess(HandCard card) {
return Suit.DIAMOND == card.getSuit() || Suit.HEART == card.getSuit();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package com.gaas.threeKingdoms.handcard.equipmentcard.armorcard;

import com.gaas.threeKingdoms.Game;
import com.gaas.threeKingdoms.events.DomainEvent;
import com.gaas.threeKingdoms.handcard.PlayCard;

import java.util.List;

/**
* 諸葛連弩
* */
public class RepeatingCrossbowArmorCard extends ArmorCard {
public RepeatingCrossbowArmorCard(PlayCard playCard) {
super(playCard);
}

@Override
public List<DomainEvent> equipmentEffect(Game game) {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package com.gaas.threeKingdoms.handcard.equipmentcard.mountscard;

import com.gaas.threeKingdoms.Game;
import com.gaas.threeKingdoms.events.DomainEvent;
import com.gaas.threeKingdoms.handcard.PlayCard;
import com.gaas.threeKingdoms.handcard.equipmentcard.EquipmentCard;
import com.gaas.threeKingdoms.player.Player;

import java.util.List;

public class MinusMountsCard extends EquipmentCard {
public MinusMountsCard(PlayCard playCard) {
super(playCard);
}

@Override
public List<DomainEvent> equipmentEffect(Game game) {
return null;
}

@Override
public void effect(Player player) {
player.getEquipment().setMinusOne(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package com.gaas.threeKingdoms.handcard.equipmentcard.mountscard;

import com.gaas.threeKingdoms.Game;
import com.gaas.threeKingdoms.events.DomainEvent;
import com.gaas.threeKingdoms.handcard.equipmentcard.EquipmentCard;
import com.gaas.threeKingdoms.handcard.PlayCard;
import com.gaas.threeKingdoms.player.Player;

import java.util.List;

public class PlusMountsCard extends EquipmentCard {

public PlusMountsCard(PlayCard playCard) {
super(playCard);
}

@Override
public List<DomainEvent> equipmentEffect(Game game) {
return null;
}

@Override
public void effect(Player player) {
player.getEquipment().setPlusOne(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public boolean hasSpecialEffect() {
boolean weaponHasSpecialEffect = weapon != null && weapon.isHasSpecialEffect();
return plusOneHasSpecialEffect || minusOneHasSpecialEffect || armorHasSpecialEffect || weaponHasSpecialEffect;
}

}

0 comments on commit c125ea7

Please sign in to comment.