Skip to content

Commit

Permalink
[BUG] Fix direction in effect controller
Browse files Browse the repository at this point in the history
  • Loading branch information
klaa97 committed Jun 29, 2019
1 parent f855261 commit bf65771
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/main/java/it/polimi/se2019/controller/EffectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,25 @@ void nextStep() {
orderIndex += 1;
//Checks if effect completed
if (orderIndex < curEffect.getOrder().size()) {
Target target;
curActionType = curEffect.getOrder().get(orderIndex);
if (curActionType == MOVE) {
moveIndex += 1;
curMove = curEffect.getMoves().get(moveIndex);
//Check if the move need to compute the source or destination first
if (curMove.getTargetSource() != null && curMove.getTargetSource().getVisibility() != null && curMove.getObjectToMove().equals(ObjectToMove.TARGETSOURCE))
processDirection(curMove.getTargetSource());
target = curMove.getTargetSource();
else
processDirection(curMove.getTargetDestination());
target = curMove.getTargetDestination();
} else {
dealDamageIndex += 1;
curDealDamage = curEffect.getDamages().get(dealDamageIndex);
processDirection(curDealDamage.getTarget());
target = curDealDamage.getTarget();
}
//Asks the player for a direction if the target needs it, block the flow if the player didn't answer
if (!updateDirection(target))
return;
processStep();
}
//Notifies the upper level controller of conclusion.
else {
Expand Down Expand Up @@ -225,17 +230,6 @@ public void updateOnStopSelection(ThreeState skip) {
controller.updateOnStopSelection(skip);
}

/**
* Ask the player for a Direction if the current target requires one,
* then go on with the effect
* @param target the target of the current SubAction
*/
private void processDirection(Target target) {
if ((target.getCardinal() == TRUE || target.getCardinal() == ThreeState.FALSE) && curEffect.getDirection() == null)
updateDirection();
processStep();
}

/**
* Ask the player for the proper target after checking the current Move
* Supports:
Expand Down Expand Up @@ -549,22 +543,27 @@ private void checkPowerUps(List<Player> players){

/**
* Utility method to update the current {@link Effect#direction}.
* It asks to the current player for a direction, and updates the related attribute.
* If direction need to be asked, asks to the current player for a direction, and updates the related attribute.
* @return false if the player didn't answer and flow need to be stopped
*/
public void updateDirection() {
AcceptableTypes acceptableTypes = new AcceptableTypes(Collections.singletonList(DIRECTION));
List<Direction> directions = new ArrayList<>(Arrays.asList(Direction.values()));
acceptableTypes.setSelectableDirections(new SelectableOptions<>(directions, 1, 1, "Select a direction for the target!"));
Choice directionRequest = new Choice(player.getVirtualView().getRequestDispatcher(), acceptableTypes, curMatch);
switch (directionRequest.getReceivingType()) {
case STOP:
updateOnStopSelection(TRUE);
break;
case DIRECTION:
Direction direction = directionRequest.getDirection();
curEffect.setDirection(direction);
break;
public boolean updateDirection(Target target) {
//Check if direction need to be asked
if (target.getCardinal() == TRUE && curEffect.getDirection() == null) {
acceptableTypes = new AcceptableTypes(Collections.singletonList(DIRECTION));
List<Direction> directions = new ArrayList<>(Arrays.asList(Direction.values()));
acceptableTypes.setSelectableDirections(new SelectableOptions<>(directions, 1, 1, "Select a direction for the target!"));
Choice directionRequest = new Choice(player.getVirtualView().getRequestDispatcher(), acceptableTypes, curMatch);
switch (directionRequest.getReceivingType()) {
case STOP:
updateOnStopSelection(TRUE);
return false;
case DIRECTION:
Direction direction = directionRequest.getDirection();
curEffect.setDirection(direction);
break;
}
}
return true;
}

/**
Expand All @@ -581,8 +580,9 @@ private void updateMoveOnPlayers(List<Player> players){
}
if (curMove.getTargetDestination().getPointOfView() == PointOfView.TARGET)
pointOfView = players.get(0).getTile();
if (curMove.getTargetDestination().getCardinal() == TRUE && curEffect.getDirection() == null)
updateDirection();
//Check if direction need to be asked, if so ask it and block the flow if the player didn't answer
if (!updateDirection(curMove.getTargetDestination()))
return;
askingForSource = false;
playersToMove = players;
List<ReceivingType> receivingTypes = new ArrayList<>(Arrays.asList(ReceivingType.TILES));
Expand Down

0 comments on commit bf65771

Please sign in to comment.