Match: add extra Event Loop to Match for Events when the Game is closed

This commit is contained in:
Hans Mackowiak
2020-11-28 20:22:45 +01:00
parent 88c017f962
commit 81bfaf2a15
5 changed files with 25 additions and 17 deletions

View File

@@ -126,6 +126,8 @@ public class HostedMatch {
title = TextUtil.concatNoSpace("Multiplayer Game (", String.valueOf(sortedPlayers.size()), " players)");
}
this.match = new Match(gameRules, sortedPlayers, title);
this.match.subscribeToEvents(SoundSystem.instance);
this.match.subscribeToEvents(visitor);
startGame();
}

View File

@@ -269,7 +269,7 @@ public class InputAttack extends InputSyncronizedBase {
combat.addAttacker(card, currentDefender, activeBand);
activateBand(activeBand);
card.getGame().fireEvent(new UiEventAttackerDeclared(
card.getGame().getMatch().fireEvent(new UiEventAttackerDeclared(
CardView.get(card),
GameEntityView.get(currentDefender)));
}
@@ -280,7 +280,7 @@ public class InputAttack extends InputSyncronizedBase {
// When removing an attacker clear the attacking band
activateBand(null);
card.getGame().fireEvent(new UiEventAttackerDeclared(
card.getGame().getMatch().fireEvent(new UiEventAttackerDeclared(
CardView.get(card), null));
return true;
}

View File

@@ -122,7 +122,7 @@ public class InputBlock extends InputSyncronizedBase {
boolean isCorrectAction = false;
if (triggerEvent != null && triggerEvent.getButton() == 3 && card.getController() == defender) {
combat.removeFromCombat(card);
card.getGame().fireEvent(new UiEventBlockerAssigned(CardView.get(card), null));
card.getGame().getMatch().fireEvent(new UiEventBlockerAssigned(CardView.get(card), null));
isCorrectAction = true;
}
else {
@@ -137,14 +137,14 @@ public class InputBlock extends InputSyncronizedBase {
if (combat.isBlocking(card, currentAttacker)) {
//if creature already blocking current attacker, remove blocker from combat
combat.removeBlockAssignment(currentAttacker, card);
card.getGame().fireEvent(new UiEventBlockerAssigned(CardView.get(card), null));
card.getGame().getMatch().fireEvent(new UiEventBlockerAssigned(CardView.get(card), null));
isCorrectAction = true;
}
else {
isCorrectAction = CombatUtil.canBlock(currentAttacker, card, combat);
if (isCorrectAction) {
combat.addBlocker(currentAttacker, card);
card.getGame().fireEvent(new UiEventBlockerAssigned(
card.getGame().getMatch().fireEvent(new UiEventBlockerAssigned(
CardView.get(card),
CardView.get(currentAttacker)));
}

View File

@@ -2936,11 +2936,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
@Override
public void nextGameDecision(final NextGameDecision decision) {
Game game = getGame();
// in case the game ended before the button is pressed, then match doesn't remember the game anymore
if (game != null) {
game.fireEvent(new UiEventNextGameDecision(this, decision));
}
gameView.getMatch().fireEvent(new UiEventNextGameDecision(this, decision));
}
@Override