Esempio n. 1
0
  public static void removeDomainsForLevel(
      PCClass cl, final int removedLevel, final PlayerCharacter aPC) {

    /*
     * Note this uses ALL of the domains up to and including this level,
     * because there is the possibility (albeit strange) that the PC was
     * qualified at a previous level change, but the PlayerCharacter is now
     * not qualified for the given Domain. Even this has quirks, since it is
     * only applied at the time of level increase, but I think that quirk
     * should be resolved by a CDOM system around 6.0 - thpr 10/23/06
     */
    for (QualifiedObject<CDOMSingleRef<Domain>> qo : cl.getSafeListFor(ListKey.DOMAIN)) {
      CDOMSingleRef<Domain> ref = qo.getObject(aPC, cl);
      if (ref == null) {
        ref = qo.getRawObject();
        aPC.removeDomain(ref.resolvesTo());
      }
    }
    for (int i = 0; i <= removedLevel; i++) {
      // TODO This stinks for really high level characters - can this ever
      // get null back?
      PCClassLevel pcl = aPC.getActiveClassLevel(cl, i);
      for (QualifiedObject<CDOMSingleRef<Domain>> qo : pcl.getSafeListFor(ListKey.DOMAIN)) {
        CDOMSingleRef<Domain> ref = qo.getObject(aPC, cl);
        if ((ref == null) || (i == removedLevel)) {
          ref = qo.getRawObject();
          aPC.removeDomain(ref.resolvesTo());
        }
      }
    }
  }
Esempio n. 2
0
  public static void addDomainsUpToLevel(PCClass cl, final int aLevel, final PlayerCharacter aPC) {

    // any domains set by level would have already been saved
    // and don't need to be re-set at level up time
    if (aPC.isImporting()) {
      return;
    }

    /*
     * Note this uses ALL of the domains up to and including this level,
     * because there is the possibility (albeit strange) that the PC was not
     * qualified at a previous level change, but the PlayerCharacter is now
     * qualified for the given Domain. Even this has quirks, since it is
     * only applied at the time of level increase, but I think that quirk
     * should be resolved by a CDOM system around 6.0 - thpr 10/23/06
     */
    for (QualifiedObject<CDOMSingleRef<Domain>> qo : cl.getSafeListFor(ListKey.DOMAIN)) {
      CDOMSingleRef<Domain> ref = qo.getObject(aPC, cl);
      if (ref != null) {
        addDomain(aPC, cl, ref.resolvesTo());
      }
    }
    for (int i = 0; i <= aLevel; i++) {
      // TODO This stinks for really high level characters - can this ever
      // get null back?
      PCClassLevel pcl = aPC.getActiveClassLevel(cl, i);
      for (QualifiedObject<CDOMSingleRef<Domain>> qo : pcl.getSafeListFor(ListKey.DOMAIN)) {
        CDOMSingleRef<Domain> ref = qo.getObject(aPC, cl);
        if (ref != null) {
          addDomain(aPC, cl, ref.resolvesTo());
        }
      }
    }
  }
Esempio n. 3
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. 4
0
  private KitSkillAdd addRanks(
      PlayerCharacter pc,
      PCClass pcClass,
      Skill aSkill,
      double ranksLeftToAdd,
      boolean isFree,
      List<String> warnings) {
    if (!isFree && pcClass.getSkillPool(pc) == 0) {
      return null;
    }

    double curRank = 0.0;
    if (pc.hasSkill(aSkill)) {
      curRank = pc.getRank(aSkill).doubleValue();
    }
    double ranksToAdd = ranksLeftToAdd;
    if (!Globals.checkRule(RuleConstants.SKILLMAX) && (ranksToAdd > 0.0)) {
      ranksToAdd = Math.min(pc.getMaxRank(aSkill, pcClass).doubleValue(), curRank + ranksLeftToAdd);
      ranksToAdd -= curRank;
      if (!CoreUtility.doublesEqual(ranksToAdd, ranksLeftToAdd)) {
        warnings.add(
            "SKILL: Could not add "
                + (ranksLeftToAdd - ranksToAdd)
                + " to "
                + aSkill.getDisplayName()
                + ". Exceeds MAXRANK of "
                + pc.getMaxRank(aSkill, pcClass)
                + ".");
      }
    }
    int ptsToSpend = 0;
    int[] points = new int[pc.getLevelInfoSize()];
    if (!isFree) {
      double ranksAdded = 0.0;
      int skillCost = pc.getSkillCostForClass(aSkill, pcClass).getCost();
      ptsToSpend = (int) (ranksToAdd * skillCost);
      for (int i = 0; i < pc.getLevelInfoSize(); i++) {
        PCLevelInfo info = pc.getLevelInfo(i);
        if (info.getClassKeyName().equals(pcClass.getKeyName())) {
          // We are spending this class' points.
          points[i] = info.getSkillPointsRemaining();
        } else {
          points[i] = -1;
        }
      }
      for (int i = 0; i < points.length; i++) {
        int remaining = points[i];
        if (remaining <= 0) {
          continue;
        }
        int left = remaining - Math.min(remaining, ptsToSpend);
        points[i] = left;
        int spent = (remaining - left);
        ptsToSpend -= spent;
        ranksAdded += ((double) spent / (double) skillCost);
        if (ranksAdded == ranksToAdd || ptsToSpend <= 0) {
          break;
        }
      }

      ranksToAdd = ranksAdded;
      ptsToSpend = (int) (ranksToAdd * skillCost);
    }
    pc.addSkill(aSkill);

    String ret = SkillRankControl.modRanks(ranksToAdd, pcClass, false, pc, aSkill);
    if (ret.length() > 0) {
      if (isFree && ret.indexOf("You do not have enough skill points.") != -1) {
        SkillRankControl.modRanks(ranksToAdd, pcClass, true, pc, aSkill);
      } else {
        warnings.add(ret);
        return null;
      }
    }
    if (!isFree) {
      for (int i = 0; i < pc.getLevelInfoSize(); i++) {
        PCLevelInfo info = pc.getLevelInfo(i);
        if (points[i] >= 0) {
          info.setSkillPointsRemaining(points[i]);
        }
      }
    }
    List<Language> langList = new ArrayList<Language>();
    if (ChooseActivation.hasChooseToken(aSkill) && !selection.isEmpty()) {
      ChoiceManagerList<Language> controller =
          ChooserUtilities.getConfiguredController(aSkill, pc, null, new ArrayList<String>());
      int limit = (int) ranksToAdd;
      for (CDOMSingleRef<Language> ref : selection) {
        Language lang = ref.resolvesTo();
        if (controller.conditionallyApply(pc, lang)) {
          langList.add(lang);
          limit--;
        }
        if (limit <= 0) {
          break;
        }
      }
    }
    return new KitSkillAdd(aSkill, ranksToAdd, ptsToSpend, langList, pcClass);
  }