Esempio n. 1
0
  public void newDay(Campaign campaign) {
    ArrayList<IAcquisitionWork> newShoppingList = new ArrayList<IAcquisitionWork>();
    boolean noStaff = false;
    for (IAcquisitionWork shoppingItem : shoppingList) {
      shoppingItem.decrementDaysToWait();

      if (shoppingItem.getDaysToWait() <= 0 && !noStaff) {
        boolean canAfford = true;
        if (campaign.getFunds() < getTrueBuyCost(shoppingItem, campaign)) {
          campaign.addReport(
              "<font color='red'><b>You cannot afford to purchase "
                  + shoppingItem.getAcquisitionName()
                  + "</b></font>");
          canAfford = false;
        }
        while (canAfford
            && shoppingItem.getQuantity() > 0
            && campaign.acquireEquipment(shoppingItem)) {
          shoppingItem.decrementQuantity();
          if (shoppingItem.getQuantity() > 0
              && campaign.getFunds() < getTrueBuyCost(shoppingItem, campaign)) {
            canAfford = false;
            campaign.addReport(
                "<font color='red'><b>You cannot afford to purchase "
                    + shoppingItem.getAcquisitionName()
                    + "</b></font>");
          }
        }
      }
      if (shoppingItem.getQuantity() > 0 || shoppingItem.getDaysToWait() > 0) {
        newShoppingList.add(shoppingItem);
      }
    }
    shoppingList = newShoppingList;
  }
  protected void spendXP() {
    String skillName = (String) choiceSkill.getSelectedItem();
    if (choiceNoSkill.equals(skillName)) {
      // This shouldn't happen, but guard against it anyway.
      return;
    }
    int rows = personnelTable.getRowCount();
    int improvedPersonnelCount = rows;
    while (rows > 0) {
      for (int i = 0; i < rows; ++i) {
        Person p = personnelModel.getPerson(personnelTable.convertRowIndexToModel(i));
        int cost = 0;
        if (p.hasSkill(skillName)) {
          cost = p.getCostToImprove(skillName);
        } else {
          cost = SkillType.getType(skillName).getCost(0);
        }
        int experience = p.getExperienceLevel(false);

        // Improve the skill and deduce the cost
        p.improveSkill(skillName);
        campaign.personUpdated(p);
        p.setXp(p.getXp() - cost);

        // The next part is bollocks and doesn't belong here, but as long as we hardcode AtB ...
        if (campaign.getCampaignOptions().getUseAtB()) {
          if ((p.getPrimaryRole() > Person.T_NONE)
              && (p.getPrimaryRole() <= Person.T_CONV_PILOT)
              && (p.getExperienceLevel(false) > experience)
              && (experience >= SkillType.EXP_REGULAR)) {
            String spa = campaign.rollSPA(p.getPrimaryRole(), p);
            if (null == spa) {
              if (campaign.getCampaignOptions().useEdge()) {
                p.acquireAbility(
                    PilotOptions.EDGE_ADVANTAGES, "edge", p.getEdge() + 1); // $NON-NLS-1$
                p.addLogEntry(
                    campaign.getDate(),
                    String.format(resourceMap.getString("gainedEdge.text"))); // $NON-NLS-1$
              }
            } else {
              p.addLogEntry(
                  campaign.getDate(),
                  String.format(resourceMap.getString("gained.format"), spa)); // $NON-NLS-1$
            }
          }
        }
      }
      // Refresh the filter and continue if we still have anyone available
      updatePersonnelTable();
      rows = personnelTable.getRowCount();
      dataChanged = true;
    }
    if (improvedPersonnelCount > 0) {
      campaign.addReport(
          String.format(
              resourceMap.getString("improvedSkills.format"),
              skillName,
              improvedPersonnelCount)); //$NON-NLS-1$
    }
  }
Esempio n. 3
0
 public void addShoppingItem(IAcquisitionWork newWork, int quantity, Campaign campaign) {
   // ammo bins need a little extra work here
   if (newWork instanceof AmmoBin) {
     newWork = ((AmmoBin) newWork).getAcquisitionWork();
   }
   for (IAcquisitionWork shoppingItem : shoppingList) {
     if (isSameEquipment(shoppingItem.getNewEquipment(), newWork.getNewEquipment())) {
       campaign.addReport(newWork.getShoppingListReport(quantity));
       while (quantity > 0) {
         shoppingItem.incrementQuantity();
         quantity--;
       }
       return;
     }
   }
   boolean canAfford = true;
   if (campaign.getFunds() < getTrueBuyCost(newWork, campaign)) {
     campaign.addReport(
         "<font color='red'><b>You cannot afford to purchase "
             + newWork.getAcquisitionName()
             + "</b></font>");
     canAfford = false;
   }
   while (canAfford && quantity > 0 && campaign.acquireEquipment(newWork)) {
     quantity--;
     if (quantity > 0 && campaign.getFunds() < getTrueBuyCost(newWork, campaign)) {
       canAfford = false;
       campaign.addReport(
           "<font color='red'><b>You cannot afford to purchase "
               + newWork.getAcquisitionName()
               + "</b></font>");
     }
   }
   if (quantity > 0) {
     campaign.addReport(newWork.getShoppingListReport(quantity));
     while (quantity > 1) {
       newWork.incrementQuantity();
       quantity--;
     }
     shoppingList.add(newWork);
   }
 }