Skip to content

Commit

Permalink
Introduce TARGET versions of failure/success notifications. (#3572)
Browse files Browse the repository at this point in the history
* Add ability for notifications to only go to accepters.

This allows for fixing #3558
with a corresponding chsange to the Feudal Japan map setting the
new property.

* Introduce PARTICIPANTS versions of failure/success notifications.

* Change terminology to TARGET.

* Fix refactoring issue.

* Address comment.
  • Loading branch information
asvitkine authored and ron-murhammer committed Jul 18, 2018
1 parent 2c70470 commit 5e2a3f3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private boolean checkEnoughMoney(final UserActionAttachment uaa) {
}

/**
* Subtract money from the players wallet
* Subtract money from the player's wallet.
*
* @param uaa
* the UserActionAttachment this the money is charged for.
Expand Down Expand Up @@ -189,19 +189,6 @@ private void activateTriggers(final UserActionAttachment uaa) {
UserActionAttachment.fireTriggers(uaa, getTestedConditions(), bridge);
}

/**
* Let all players involved in this action know the action was successful
*
* @param uaa
* the UserActionAttachment that just succeeded.
*/
private void notifySuccess(final UserActionAttachment uaa) {
// play a sound
getSoundChannel().playSoundForAll(SoundPath.CLIP_USER_ACTION_SUCCESSFUL, player);
sendNotification(UserActionText.getInstance().getNotificationSucccess(uaa.getText()));
notifyOtherPlayers(UserActionText.getInstance().getNotificationSuccessOthers(uaa.getText()));
}

/**
* Send a notification to the current player.
*
Expand All @@ -215,19 +202,44 @@ private void sendNotification(final String text) {
}
}

private void sendNotificationToPlayers(final Collection<PlayerID> toPlayers, final Collection<PlayerID> dontSendTo,
final String text) {
if (!"NONE".equals(text)) {
this.getDisplay().reportMessageToPlayers(toPlayers, dontSendTo, text, text);
}
}

/**
* Send a notification to the other players involved in this action (all
* players except the player starting the action).
* Send notifications to the other players (all players except the player starting the action).
*/
private void notifyOtherPlayers(final String notification) {
if (!"NONE".equals(notification)) {
// we can send it to just uaa.getOtherPlayers(), or we can send it to all players. both are good options.
final Collection<PlayerID> currentPlayer = new ArrayList<>();
currentPlayer.add(player);
final Collection<PlayerID> otherPlayers = getData().getPlayerList().getPlayers();
otherPlayers.removeAll(currentPlayer);
this.getDisplay().reportMessageToPlayers(otherPlayers, currentPlayer, notification, notification);
}
private void notifyOtherPlayers(final UserActionAttachment uaa, final String notification,
final String targetNotification) {
final Collection<PlayerID> dontSendTo = new ArrayList<>();
dontSendTo.add(player);

final Collection<PlayerID> targets = uaa.getActionAccept();
sendNotificationToPlayers(targets, dontSendTo, targetNotification);

final Collection<PlayerID> otherPlayers = getData().getPlayerList().getPlayers();
otherPlayers.remove(player);
otherPlayers.removeAll(targets);
dontSendTo.addAll(targets);
sendNotificationToPlayers(otherPlayers, dontSendTo, notification);
}

/**
* Let all players involved in this action know the action was successful.
*
* @param uaa
* the UserActionAttachment that just succeeded.
*/
private void notifySuccess(final UserActionAttachment uaa) {
// play a sound
getSoundChannel().playSoundForAll(SoundPath.CLIP_USER_ACTION_SUCCESSFUL, player);
final UserActionText uat = UserActionText.getInstance();
final String text = uaa.getText();
sendNotification(uat.getNotificationSucccess(text));
notifyOtherPlayers(uaa, uat.getNotificationSuccessOthers(text), uat.getNotificationSuccessTarget(text));
}

/**
Expand All @@ -242,8 +254,10 @@ private void notifyFailure(final UserActionAttachment uaa) {
final String transcriptText =
bridge.getPlayerId().getName() + " fails on action: " + MyFormatter.attachmentNameToText(uaa.getName());
bridge.getHistoryWriter().addChildToEvent(transcriptText);
sendNotification(UserActionText.getInstance().getNotificationFailure(uaa.getText()));
notifyOtherPlayers(UserActionText.getInstance().getNotificationFailureOthers(uaa.getText()));
final UserActionText uat = UserActionText.getInstance();
final String text = uaa.getText();
sendNotification(uat.getNotificationFailure(text));
notifyOtherPlayers(uaa, uat.getNotificationFailureOthers(text), uat.getNotificationFailureTarget(text));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public class UserActionText {
private static final String BUTTON = "BUTTON";
private static final String DESCRIPTION = "DESCRIPTION";
private static final String NOTIFICATION_SUCCESS = "NOTIFICATION_SUCCESS";
private static final String TARGET_NOTIFICATION_SUCCESS = "TARGET_NOTIFICATION_SUCCESS";
private static final String OTHER_NOTIFICATION_SUCCESS = "OTHER_NOTIFICATION_SUCCESS";
private static final String NOTIFICATION_FAILURE = "NOTIFICATION_FAILURE";
private static final String TARGET_NOTIFICATION_FAILURE = "TARGET_NOTIFICATION_FAILURE";
private static final String OTHER_NOTIFICATION_FAILURE = "OTHER_NOTIFICATION_FAILURE";
private static final String ACCEPT_QUESTION = "ACCEPT_QUESTION";

Expand Down Expand Up @@ -59,6 +61,10 @@ private String getMessage(final String actionKey, final String messageKey) {
return getString(actionKey + "." + messageKey);
}

private boolean hasMessage(final String actionKey, final String messageKey) {
return properties.containsKey(actionKey + "." + messageKey);
}

public String getButtonText(final String actionKey) {
return getMessage(actionKey, BUTTON);
}
Expand All @@ -75,6 +81,14 @@ public String getNotificationSuccessOthers(final String actionKey) {
return getMessage(actionKey, OTHER_NOTIFICATION_SUCCESS);
}

public String getNotificationSuccessTarget(final String actionKey) {
if (hasMessage(actionKey, TARGET_NOTIFICATION_SUCCESS)) {
return getMessage(actionKey, TARGET_NOTIFICATION_SUCCESS);
} else {
return getNotificationSuccessOthers(actionKey);
}
}

public String getNotificationFailure(final String actionKey) {
return getMessage(actionKey, NOTIFICATION_FAILURE);
}
Expand All @@ -83,6 +97,14 @@ public String getNotificationFailureOthers(final String actionKey) {
return getMessage(actionKey, OTHER_NOTIFICATION_FAILURE);
}

public String getNotificationFailureTarget(final String actionKey) {
if (hasMessage(actionKey, TARGET_NOTIFICATION_FAILURE)) {
return getMessage(actionKey, TARGET_NOTIFICATION_FAILURE);
} else {
return getNotificationFailureOthers(actionKey);
}
}

public String getAcceptanceQuestion(final String actionKey) {
return getMessage(actionKey, ACCEPT_QUESTION);
}
Expand Down

0 comments on commit 5e2a3f3

Please sign in to comment.