Esempio n. 1
0
  @Override
  public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
    skillsToAdd = new ArrayList<KitSkillAdd>();
    List<Skill> skillChoices = getSkillChoices(aPC);

    if (skillChoices == null || skillChoices.size() == 0) {
      // They didn't make a choice so don't add any ranks.
      return false;
    }
    for (Skill skill : skillChoices) {
      BigDecimal ranksLeftToAdd = getRank();
      if (ranksLeftToAdd == null) {
        ranksLeftToAdd = BigDecimal.ONE;
      }
      double ranksLeft = ranksLeftToAdd.doubleValue();
      List<PCClass> classList = new ArrayList<PCClass>();
      if (className != null) {
        String classKey = className.resolvesTo().getKeyName();
        // Make sure if they specified a class to add from we try that
        // class first.
        PCClass pcClass = aPC.getClassKeyed(classKey);
        if (pcClass != null) {
          classList.add(pcClass);
        } else {
          warnings.add(
              "SKILL: Could not find specified class " + classKey + " in PC to add ranks from.");
        }
      }
      for (PCClass pcClass : aPC.getClassSet()) {
        if (!classList.contains(pcClass)) {
          classList.add(pcClass);
        }
      }

      // Try and find a class we can add them from.
      boolean oldImporting = aPC.isImporting();
      aPC.setImporting(true);
      for (PCClass pcClass : classList) {
        final KitSkillAdd sta = addRanks(aPC, pcClass, skill, ranksLeft, isFree(), warnings);
        if (sta != null) {
          skillsToAdd.add(sta);
          ranksLeft -= sta.getRanks();
          if (ranksLeft <= 0.0) {
            break;
          }
        }
      }
      aPC.setImporting(oldImporting);
      if (ranksLeft > 0.0) {
        warnings.add(
            "SKILL: Could not add "
                + ranksLeft
                + " ranks to "
                + skill.getKeyName()
                + ". Not enough points.");
      }
    }
    return true;
  }
Esempio n. 2
0
  /**
   * Needs documentation.
   *
   * @param pc update skills for this PC
   * @param aSkill Skill to update
   * @param aRank Number of ranks to add
   * @param aCost Cost of added ranks
   * @param langList Languages to be selected for a language skill
   * @param pcClass skills apply to this class
   * @return <code>true</code> for success TODO What about throwing on failure?
   */
  private boolean updatePCSkills(
      final PlayerCharacter pc,
      final Skill aSkill,
      final int aRank,
      final double aCost,
      List<Language> langList,
      final PCClass pcClass) {
    pc.addSkill(aSkill);

    boolean oldImporting = pc.isImporting();
    pc.setImporting(true);
    final String aString = SkillRankControl.modRanks(aRank, pcClass, true, pc, aSkill);
    pc.setImporting(oldImporting);

    if (aString.length() > 0) {
      Logging.errorPrint("SKILL: " + aString);
      return false;
    }

    // Add any supplied languages
    ChoiceManagerList<Language> controller =
        ChooserUtilities.getConfiguredController(aSkill, pc, null, new ArrayList<String>());
    for (Language lang : langList) {
      if (!controller.conditionallyApply(pc, lang)) {
        Logging.errorPrint("Failed to apply Language into Skill: " + lang.getLSTformat());
      }
    }

    //
    // Fix up the skill pools to reflect what we just spent.
    //
    double ptsToSpend = aCost;
    if (ptsToSpend >= 0.0) {
      for (PCLevelInfo info : pc.getLevelInfo()) {
        if (info.getClassKeyName().equals(pcClass.getKeyName())) {
          // We are spending this class' points.
          int remaining = info.getSkillPointsRemaining();
          if (remaining == 0) {
            continue;
          }
          int left = remaining - (int) Math.min(remaining, ptsToSpend);
          info.setSkillPointsRemaining(left);
          ptsToSpend -= (remaining - left);
          if (ptsToSpend <= 0) {
            break;
          }
        }
      }
    }
    return true;
  }