Ejemplo n.º 1
0
  public void testFindEquipmentByBaseKey() {
    TestHelper.makeSizeAdjustments();
    Equipment towel = new Equipment();
    towel.setName("Towel");
    Equipment backpackMed = new Equipment();
    backpackMed.setName("Backpack");
    final Equipment backpackSml = backpackMed.clone();
    backpackSml.put(ObjectKey.BASE_ITEM, CDOMDirectSingleRef.getRef(backpackMed));
    SizeAdjustment small = Globals.getContext().ref.getAbbreviatedObject(SizeAdjustment.class, "S");
    final String newName = backpackSml.createNameForAutoResize(small);
    backpackSml.setName(newName);
    backpackSml.setKeyName(backpackSml.createKeyForAutoResize(small));

    List<Equipment> eqList = new ArrayList<Equipment>();
    eqList.add(towel);
    eqList.add(backpackSml);
    assertEquals(
        "Expected to find backpack",
        backpackSml,
        EquipmentUtilities.findEquipmentByBaseKey(eqList, "backpack"));
    assertEquals(
        "Expected not to find torch",
        null,
        EquipmentUtilities.findEquipmentByBaseKey(eqList, "torch"));
    assertEquals(
        "Expected to find towel",
        towel,
        EquipmentUtilities.findEquipmentByBaseKey(eqList, "ToWeL"));
  }
Ejemplo n.º 2
0
 /**
  * Add the bonus to the character's feat pool that is granted by the class. NB: LEVELSPERFEAT is
  * now handled via PLayerCHaracter.getNumFeatsFromLevels() rather than bonuses. Only the standard
  * feat progression for the gamemode is handled here.
  *
  * @param aPC The character to bonus.
  */
 void addFeatPoolBonus(final PlayerCharacter aPC) {
   Integer mLevPerFeat = get(IntegerKey.LEVELS_PER_FEAT);
   int startLevel;
   int rangeLevel;
   int divisor;
   if (mLevPerFeat == null) {
     String aString = Globals.getBonusFeatString();
     StringTokenizer aTok = new StringTokenizer(aString, "|", false);
     startLevel = Integer.parseInt(aTok.nextToken());
     rangeLevel = Integer.parseInt(aTok.nextToken());
     divisor = rangeLevel;
     if (divisor > 0) {
       StringBuilder aBuf = new StringBuilder("FEAT|PCPOOL|").append("max(CL");
       // Make sure we only take off the startlevel value once
       if (this == aPC.getClassKeyed(aPC.getLevelInfoClassKeyName(0))) {
         aBuf.append("-").append(startLevel);
         aBuf.append("+").append(rangeLevel);
       }
       aBuf.append(",0)/").append(divisor);
       //						Logging.debugPrint("Feat bonus for " + this + " is "
       //							+ aBuf.toString());
       BonusObj bon = Bonus.newBonus(Globals.getContext(), aBuf.toString());
       aPC.addBonus(bon, this);
     }
   }
 }
Ejemplo n.º 3
0
  @Override
  public String getPCCText() {
    final StringBuilder pccTxt = new StringBuilder(200);
    pccTxt.append("CLASS:").append(getDisplayName());
    pccTxt.append("\t");
    pccTxt.append(PrerequisiteWriter.prereqsToString(this));
    pccTxt.append("\t");
    pccTxt.append(StringUtil.joinToStringBuilder(Globals.getContext().unparse(this), "\t"));

    // now all the level-based stuff
    final String lineSep = System.getProperty("line.separator");

    for (Map.Entry<Integer, PCClassLevel> me : levelMap.entrySet()) {
      pccTxt.append(lineSep).append(me.getKey()).append('\t');
      pccTxt.append(PrerequisiteWriter.prereqsToString(me.getValue()));
      pccTxt.append("\t");
      pccTxt.append(
          StringUtil.joinToStringBuilder(Globals.getContext().unparse(me.getValue()), "\t"));
    }

    return pccTxt.toString();
  }
Ejemplo n.º 4
0
  /**
   * Get the unarmed Damage for this class at the given level.
   *
   * @param aLevel the given level.
   * @param aPC the PC with the level.
   * @param adjustForPCSize whether to adjust the result for the PC's size.
   * @return the unarmed damage string
   */
  String getUDamForEffLevel(int aLevel, final PlayerCharacter aPC, boolean adjustForPCSize) {
    int pcSize = adjustForPCSize ? aPC.sizeInt() : aPC.getDisplay().racialSizeInt();

    //
    // Check "Unarmed Strike", then default to "1d3"
    //
    String aDamage;

    AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
    final Equipment eq =
        ref.silentlyGetConstructedCDOMObject(Equipment.class, "KEY_Unarmed Strike");

    if (eq != null) {
      aDamage = eq.getDamage(aPC);
    } else {
      aDamage = "1d3";
    }

    // resize the damage as if it were a weapon
    if (adjustForPCSize) {
      int defSize = SizeUtilities.getDefaultSizeAdjustment().get(IntegerKey.SIZEORDER);
      aDamage = Globals.adjustDamage(aDamage, defSize, pcSize);
    }

    //
    // Check the UDAM list for monk-like damage
    //
    List<CDOMObject> classObjects = new ArrayList<>();
    // Negative increment to start at highest level until an UDAM is found
    for (int i = aLevel; i >= 1; i--) {
      classObjects.add(aPC.getActiveClassLevel(this, i));
    }
    classObjects.add(this);
    for (CDOMObject cdo : classObjects) {
      List<String> udam = cdo.getListFor(ListKey.UNARMED_DAMAGE);
      if (udam != null) {
        if (udam.size() == 1) {
          aDamage = udam.get(0);
        } else {
          aDamage = udam.get(pcSize);
        }
        break;
      }
    }
    return aDamage;
  }
Ejemplo n.º 5
0
  public void testURL() throws Exception {
    final String eCommerceName = "Barcommerce";
    final String eCommerceURL =
        "http://www.barcommercesite.com/product_info.php?products_id=12345&affiliate_id=54321";
    final String eCommerceDesc = "Support PCGen by buying this source now!";

    assertEquals(
        "No URLs in the campaign to start",
        true,
        testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).isEmpty());

    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(testCamp, "URL", "WEBSITE|http://pcgen.sf.net|PCGen Main Site");
    assertEquals(
        "New URL in the campaign", 1, testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).size());
    CampaignURL theURL = testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).get(0);
    assertEquals("Checking kind", CampaignURL.URLKind.WEBSITE, theURL.getUrlKind());
    assertEquals("Checking name", "", theURL.getUrlName());
    assertEquals("Checking URL", "http://pcgen.sf.net", theURL.getUri().toString());
    assertEquals("Checking description", "PCGen Main Site", theURL.getUrlDesc());

    context.unconditionallyProcess(
        testCamp, "URL", "SURVEY|http://pcgen.sf.net/survey|PCGen Survey");
    assertEquals(
        "Second new URL in the campaign", 2, testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).size());
    theURL = testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).get(1);
    assertEquals("Checking kind", CampaignURL.URLKind.SURVEY, theURL.getUrlKind());
    assertEquals("Checking name", "", theURL.getUrlName());
    assertEquals("Checking URL", "http://pcgen.sf.net/survey", theURL.getUri().toString());
    assertEquals("Checking description", "PCGen Survey", theURL.getUrlDesc());

    context.unconditionallyProcess(
        testCamp, "URL", eCommerceName + "|" + eCommerceURL + "|" + eCommerceDesc);
    assertEquals(
        "Third new URL in the campaign", 3, testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).size());
    theURL = testCamp.getSafeListFor(ListKey.CAMPAIGN_URL).get(2);
    assertEquals("Checking kind", CampaignURL.URLKind.PURCHASE, theURL.getUrlKind());
    assertEquals("Checking name", eCommerceName, theURL.getUrlName());
    assertEquals("Checking URL", eCommerceURL, theURL.getUri().toString());
    assertEquals("Checking description", eCommerceDesc, theURL.getUrlDesc());
  }