Пример #1
0
 /**
  * Let all players involved in this action know the action has failed.
  *
  * @param paa the political action attachment that just failed.
  */
 private void notifyFailure(final PoliticalActionAttachment paa) {
   getSoundChannel().playSoundForAll(SoundPath.CLIP_POLITICAL_ACTION_FAILURE, m_player);
   final String transcriptText =
       m_bridge.getPlayerID().getName()
           + " fails on action: "
           + MyFormatter.attachmentNameToText(paa.getName());
   m_bridge.getHistoryWriter().addChildToEvent(transcriptText);
   sendNotification(PoliticsText.getInstance().getNotificationFailure(paa.getText()));
   notifyOtherPlayers(paa, PoliticsText.getInstance().getNotificationFailureOthers(paa.getText()));
 }
Пример #2
0
 /**
  * @param paa the action to check if it succeeds
  * @return true if the action succeeds, usually because the die-roll succeeded.
  */
 private boolean actionRollSucceeds(final PoliticalActionAttachment paa) {
   final int hitTarget = paa.getChanceToHit();
   final int diceSides = paa.getChanceDiceSides();
   if (diceSides <= 0 || hitTarget >= diceSides) {
     paa.changeChanceDecrementOrIncrementOnSuccessOrFailure(m_bridge, true, true);
     return true;
   } else if (hitTarget <= 0) {
     paa.changeChanceDecrementOrIncrementOnSuccessOrFailure(m_bridge, false, true);
     return false;
   }
   final int rollResult =
       m_bridge.getRandom(
               diceSides,
               m_player,
               DiceType.NONCOMBAT,
               "Attempting the Political Action: "
                   + MyFormatter.attachmentNameToText(paa.getName()))
           + 1;
   final boolean success = rollResult <= hitTarget;
   final String notificationMessage =
       "rolling ("
           + hitTarget
           + " out of "
           + diceSides
           + ") result: "
           + rollResult
           + " = "
           + (success ? "Success!" : "Failure!");
   m_bridge
       .getHistoryWriter()
       .addChildToEvent(
           MyFormatter.attachmentNameToText(paa.getName()) + " : " + notificationMessage);
   paa.changeChanceDecrementOrIncrementOnSuccessOrFailure(m_bridge, success, true);
   sendNotification(notificationMessage);
   return success;
 }
Пример #3
0
 /**
  * Subtract money from the players wallet
  *
  * @param paa the politicalactionattachment this the money is charged for.
  */
 private void chargeForAction(final PoliticalActionAttachment paa) {
   final Resource PUs = getData().getResourceList().getResource(Constants.PUS);
   final int cost = paa.getCostPU();
   if (cost > 0) {
     // don't notify user of spending money anymore
     // notifyMoney(paa, true);
     final String transcriptText =
         m_bridge.getPlayerID().getName()
             + " spend "
             + cost
             + " PU on Political Action: "
             + MyFormatter.attachmentNameToText(paa.getName());
     m_bridge.getHistoryWriter().startEvent(transcriptText);
     final Change charge = ChangeFactory.changeResourcesChange(m_bridge.getPlayerID(), PUs, -cost);
     m_bridge.addChange(charge);
   } else {
     final String transcriptText =
         m_bridge.getPlayerID().getName()
             + " takes Political Action: "
             + MyFormatter.attachmentNameToText(paa.getName());
     // we must start an event anyway
     m_bridge.getHistoryWriter().startEvent(transcriptText);
   }
 }
Пример #4
0
 /**
  * Changes all relationships
  *
  * @param paa the political action to change the relationships for
  */
 private void changeRelationships(final PoliticalActionAttachment paa) {
   getMyselfOutOfAlliance(paa, m_player, m_bridge);
   getNeutralOutOfWarWithAllies(paa, m_player, m_bridge);
   final CompositeChange change = new CompositeChange();
   for (final String relationshipChange : paa.getRelationshipChange()) {
     final String[] s = relationshipChange.split(":");
     final PlayerID player1 = getData().getPlayerList().getPlayerID(s[0]);
     final PlayerID player2 = getData().getPlayerList().getPlayerID(s[1]);
     final RelationshipType oldRelation =
         getData().getRelationshipTracker().getRelationshipType(player1, player2);
     final RelationshipType newRelation =
         getData().getRelationshipTypeList().getRelationshipType(s[2]);
     if (oldRelation.equals(newRelation)) {
       continue;
     }
     change.add(ChangeFactory.relationshipChange(player1, player2, oldRelation, newRelation));
     m_bridge
         .getHistoryWriter()
         .addChildToEvent(
             m_bridge.getPlayerID().getName()
                 + " succeeds on action: "
                 + MyFormatter.attachmentNameToText(paa.getName())
                 + ": Changing Relationship for "
                 + player1.getName()
                 + " and "
                 + player2.getName()
                 + " from "
                 + oldRelation.getName()
                 + " to "
                 + newRelation.getName());
     MoveDelegate.getBattleTracker(getData())
         .addRelationshipChangesThisTurn(player1, player2, oldRelation, newRelation);
     /*
      * creation of new battles is handled at the beginning of the battle delegate, in
      * "setupUnitsInSameTerritoryBattles", not here.
      * if (Matches.RelationshipTypeIsAtWar.match(newRelation))
      * TriggerAttachment.triggerMustFightBattle(player1, player2, m_bridge);
      */
   }
   if (!change.isEmpty()) {
     m_bridge.addChange(change);
   }
   chainAlliancesTogether(m_bridge);
 }
Пример #5
0
 /**
  * Get a list of players that should accept this action and then ask each player if it accepts
  * this action.
  *
  * @param paa the politicalActionAttachment that should be accepted
  */
 private boolean actionIsAccepted(final PoliticalActionAttachment paa) {
   final GameData data = getData();
   final CompositeMatchOr<PoliticalActionAttachment> intoAlliedChainOrIntoOrOutOfWar =
       new CompositeMatchOr<PoliticalActionAttachment>(
           Matches.politicalActionIsRelationshipChangeOf(
               null,
               Matches.RelationshipTypeIsAlliedAndAlliancesCanChainTogether.invert(),
               Matches.RelationshipTypeIsAlliedAndAlliancesCanChainTogether,
               data),
           Matches.politicalActionIsRelationshipChangeOf(
               null,
               Matches.RelationshipTypeIsAtWar.invert(),
               Matches.RelationshipTypeIsAtWar,
               data),
           Matches.politicalActionIsRelationshipChangeOf(
               null,
               Matches.RelationshipTypeIsAtWar,
               Matches.RelationshipTypeIsAtWar.invert(),
               data));
   if (!games.strategy.triplea.Properties.getAlliancesCanChainTogether(data)
       || !intoAlliedChainOrIntoOrOutOfWar.match(paa)) {
     for (final PlayerID player : paa.getActionAccept()) {
       if (!(getRemotePlayer(player))
           .acceptAction(
               m_player, PoliticsText.getInstance().getAcceptanceQuestion(paa.getText()), true)) {
         return false;
       }
     }
   } else {
     // if alliances chain together, then our allies must have a say in anyone becoming a new
     // ally/enemy
     final LinkedHashSet<PlayerID> playersWhoNeedToAccept = new LinkedHashSet<PlayerID>();
     playersWhoNeedToAccept.addAll(paa.getActionAccept());
     playersWhoNeedToAccept.addAll(
         Match.getMatches(
             data.getPlayerList().getPlayers(),
             Matches.isAlliedAndAlliancesCanChainTogether(m_player, data)));
     for (final PlayerID player : paa.getActionAccept()) {
       playersWhoNeedToAccept.addAll(
           Match.getMatches(
               data.getPlayerList().getPlayers(),
               Matches.isAlliedAndAlliancesCanChainTogether(player, data)));
     }
     final HashSet<PlayerID> alliesWhoMustAccept = playersWhoNeedToAccept;
     alliesWhoMustAccept.removeAll(paa.getActionAccept());
     for (final PlayerID player : playersWhoNeedToAccept) {
       String actionText = PoliticsText.getInstance().getAcceptanceQuestion(paa.getText());
       if (actionText.equals("NONE")) {
         actionText =
             m_player.getName()
                 + " wants to take the following action: "
                 + MyFormatter.attachmentNameToText(paa.getName())
                 + " \r\n Do you approve?";
       } else {
         actionText =
             m_player.getName()
                 + " wants to take the following action: "
                 + MyFormatter.attachmentNameToText(paa.getName())
                 + ".  Do you approve? \r\n\r\n "
                 + m_player.getName()
                 + " will ask "
                 + MyFormatter.defaultNamedToTextList(paa.getActionAccept())
                 + ", the following question: \r\n "
                 + actionText;
       }
       if (!(getRemotePlayer(player)).acceptAction(m_player, actionText, true)) {
         return false;
       }
     }
     for (final PlayerID player : paa.getActionAccept()) {
       if (!(getRemotePlayer(player))
           .acceptAction(
               m_player, PoliticsText.getInstance().getAcceptanceQuestion(paa.getText()), true)) {
         return false;
       }
     }
   }
   return true;
 }