Example #1
0
  /**
   * select various stuff, that improves AC
   *
   * @param index
   * @param type
   * @param subtype
   * @param property
   * @param equipped
   * @param merge
   * @param aPC
   * @param eh The ExportHandler to advise if there are no more items.
   * @return int
   */
  private static String _replaceTokenArmorVarious(
      int index,
      String type,
      String subtype,
      String property,
      int equipped,
      int merge,
      PlayerCharacter aPC,
      ExportHandler eh) {
    final List<Equipment> aArrayList = new ArrayList<>();

    for (Equipment eq : aPC.getEquipmentOfTypeInOutputOrder(type, subtype, equipped, merge)) {
      if (eq.getACMod(aPC).intValue() > 0) {
        aArrayList.add(eq);
      } else if (eq.altersAC(aPC)) {
        aArrayList.add(eq);
      }
    }

    if (index < aArrayList.size()) {
      final Equipment eq = aArrayList.get(index);
      return _writeArmorProperty(eq, property, aPC);
    }
    eh.setNoMoreItems(true);
    return "";
  }
  /**
   * Check that EquipmentSetFacadeImpl when initialised with a dataset containing equipment hides
   * and shows the correct weapon slots.
   */
  public void testSlotManagementOnInitWithEquipment() {
    PlayerCharacter pc = getCharacter();
    EquipSet es = new EquipSet("0.1", "Unit Test Equip");
    Equipment weapon = new Equipment();
    weapon.setName("Morningstar");

    addEquipToEquipSet(pc, es, weapon, 1.0f, LOC_PRIMARY);

    EquipmentSetFacadeImpl esfi = new EquipmentSetFacadeImpl(uiDelegate, pc, es, dataset);
    ListFacade<EquipNode> nodes = esfi.getNodes();
    Map<String, EquipNode> nodeMap = new HashMap<String, EquipNode>();
    for (EquipNode equipNode : nodes) {
      nodeMap.put(equipNode.toString(), equipNode);
    }

    EquipNode testNode = nodeMap.get("Morningstar");
    assertNotNull("Morningstar should be present", testNode);
    assertEquals("Morningstar type", EquipNode.NodeType.EQUIPMENT, testNode.getNodeType());
    assertEquals("Morningstar location", LOC_PRIMARY, esfi.getLocation(testNode));

    // Test for removed slots
    String removedSlots[] = new String[] {"Primary Hand", "Double Weapon", "Both Hands"};
    for (String slotName : removedSlots) {
      testNode = nodeMap.get(slotName);
      assertNull(slotName + " should not be present", testNode);
    }

    // Test for still present slots
    String retainedSlots[] = new String[] {"Secondary Hand", "Ring"};
    for (String slotName : retainedSlots) {
      testNode = nodeMap.get(slotName);
      assertNotNull(slotName + " should be present", testNode);
    }
  }
 public EquipmentListFacadeImpl(List<Equipment> list) {
   equipmentList = new ArrayList<>(list);
   quantityMap = new HashMap<>();
   for (Equipment equipment : list) {
     quantityMap.put(equipment, equipment.getQty().intValue());
   }
 }
 /**
  * Refresh the equipment list facade with the supplied data.
  *
  * @param list The new list of equipment.
  */
 public void refresh(List<Equipment> list) {
   equipmentList = new ArrayList<>(list);
   quantityMap = new HashMap<>();
   for (Equipment equipment : list) {
     quantityMap.put(equipment, equipment.getQty().intValue());
   }
   fireElementsChanged(this);
 }
 /**
  * Add the equipment item to the equipset.
  *
  * @param pc The character owning the set
  * @param es The set to add the item to
  * @param item The item of equipment
  * @param qty The number to be placed in the location.
  * @return The new EquipSet object for the item.
  */
 private EquipSet addEquipToEquipSet(
     PlayerCharacter pc, EquipSet es, Equipment item, float qty, String locName) {
   String id = EquipmentSetFacadeImpl.getNewIdPath(pc, es);
   EquipSet newSet = new EquipSet(id, locName, item.getName(), item);
   item.setQty(qty);
   newSet.setQty(1.0f);
   pc.addEquipSet(newSet);
   return newSet;
 }
  @Override
  public Float resolve(PlayerCharacter pc) {
    if (ControlUtilities.hasControlToken(Globals.getContext(), "EQACCHECK")) {
      Logging.errorPrint(
          originalText
              + " term is deprecated (does not function)"
              + " when EQACCHECK CodeControl is used");
    }
    int maxCheck = 0;

    for (Equipment eq : pc.getEquipmentOfType("Armor", 1)) {
      maxCheck += eq.preFormulaAcCheck(pc);
    }

    return (float) maxCheck;
  }
Example #7
0
 @Override
 public String evaluate(Equipment eq, boolean primary, PlayerCharacter pc) {
   if (ControlUtilities.hasControlToken(Globals.getContext(), "EQACCHECK")) {
     Logging.errorPrint(
         "EQACCHECK term is deprecated (does not function)" + " when ACCHECK CodeControl is used");
   }
   return Integer.toString(eq.getSafe(IntegerKey.AC_CHECK));
 }
Example #8
0
  /**
   * select items, which improve AC but are not type ARMOR
   *
   * @param item
   * @param subtype
   * @param property
   * @param equipped
   * @param merge
   * @param aPC
   * @param eh The ExportHandler to advise if there are no more items.
   * @return int
   */
  private static String _replaceTokenArmorItem(
      int item,
      String subtype,
      String property,
      int equipped,
      int merge,
      PlayerCharacter aPC,
      ExportHandler eh) {
    // select all pieces of equipment of status==equipped
    // filter all AC relevant stuff
    final List<Equipment> aArrayList = new ArrayList<>();

    for (Equipment eq : aPC.getEquipmentListInOutputOrder(merge)) {
      if (("".equals(subtype) || eq.isType(subtype))
          && ((equipped == 3)
              || ((equipped == 2) && !eq.isEquipped())
              || ((equipped == 1) && eq.isEquipped()))) {
        if (eq.altersAC(aPC) && !eq.isArmor() && !eq.isShield()) {
          aArrayList.add(eq);
        }
      }
    }

    if (item < aArrayList.size()) {
      final Equipment eq = aArrayList.get(item);
      return _writeArmorProperty(eq, property, aPC);
    }
    eh.setNoMoreItems(true);
    return "";
  }
 @Override
 public void dataAdded(DataFacetChangeEvent<CharID, VarScoped> dfce) {
   CharID id = dfce.getCharID();
   VarScoped vs = dfce.getCDOMObject();
   /*
    * If this can have local variables, find what may have been modified by
    * previous objects
    */
   for (RemoteModifier<?> rm : getSet(id)) {
     VarScoped src = get(id, rm);
     ScopeInstance inst = scopeFacet.get(id, src);
     processAdd(id, rm, vs, inst);
     if (vs instanceof Equipment) {
       Equipment e = (Equipment) vs;
       for (EquipmentHead head : e.getEquipmentHeads()) {
         processAdd(id, rm, head, inst);
       }
     }
   }
   /*
    * Look at what newly added object can modify on others
    */
   if (vs instanceof CDOMObject) {
     ScopeInstance inst = scopeFacet.get(id, vs);
     List<RemoteModifier<?>> list = ((CDOMObject) vs).getListFor(ListKey.REMOTE_MODIFIER);
     if (list != null) {
       Set<? extends VarScoped> targets = varScopedFacet.getSet(id);
       for (RemoteModifier<?> rm : list) {
         set(id, rm, vs);
         // Apply to existing as necessary
         for (VarScoped obj : targets) {
           processAdd(id, rm, obj, inst);
           if (obj instanceof Equipment) {
             Equipment e = (Equipment) obj;
             for (EquipmentHead head : e.getEquipmentHeads()) {
               processAdd(id, rm, head, inst);
             }
           }
         }
       }
     }
   }
 }
 /**
  * Update the stored spellbook details in response to a spellbook item of equipment changing.
  * Changes to equipment other than spellbooks will be ignored.
  *
  * @param equip The equipment item that changed.
  */
 private void updateSpellBooks(Equipment equip) {
   if (equip == null || equip.isType("SPELLBOOK")) {
     buildKnownPreparedNodes();
     for (Iterator<SpellNode> iterator = bookSpellNodes.iterator(); iterator.hasNext(); ) {
       SpellNode spell = iterator.next();
       if (!spellBookNames.containsElement(spell.getRootNode().getName())) {
         iterator.remove();
       }
     }
   }
 }
  @Override
  public Float resolve(PlayerCharacter pc) {
    if (ControlUtilities.hasControlToken(Globals.getContext(), CControl.EQACCHECK)) {
      Logging.errorPrint(
          originalText
              + " term is deprecated (does not function)"
              + " when EQACCHECK CodeControl is used");
    }
    if ("".equals(eqKey)) {
      return 0.0f;
    } else {
      final Equipment eq =
          Globals.getContext()
              .getReferenceContext()
              .silentlyGetConstructedCDOMObject(Equipment.class, eqKey);

      if (eq == null || pc.isProficientWith(eq)) {
        return 0.0f;
      } else {
        return (float) eq.preFormulaAcCheck(pc);
      }
    }
  }
  /** Check that EquipmentSetFacadeImpl can be initialised with a dataset containing equipment. */
  public void testInitWithEquipment() {
    PlayerCharacter pc = getCharacter();
    EquipSet es = new EquipSet("0.1", "Unit Test Equip");
    Equipment item = new Equipment();
    item.setName("Satchel");
    Equipment item2 = new Equipment();
    item2.setName("Book");
    Equipment item3 = new Equipment();
    item3.setName("Quarterstaff");

    EquipSet satchelEs = addEquipToEquipSet(pc, es, item, 1.0f);
    addEquipToEquipSet(pc, satchelEs, item2, 1.0f);
    addEquipToEquipSet(pc, es, item3, 1.0f, LOC_BOTH_HANDS);
    int adjustedBaseNodes = NUM_BASE_NODES - 4;
    EquipmentSetFacadeImpl esfi = new EquipmentSetFacadeImpl(uiDelegate, pc, es, dataset);
    ListFacade<EquipNode> nodeList = esfi.getNodes();
    assertFalse("Expected a non empty path set", nodeList.isEmpty());
    EquipNodeImpl node = (EquipNodeImpl) nodeList.getElementAt(0);
    assertEquals("Incorrect body struct name", Constants.EQUIP_LOCATION_EQUIPPED, node.toString());
    assertEquals("Incorrect body struct type", NodeType.BODY_SLOT, node.getNodeType());
    assertEquals("Incorrect sort key", "00", node.getSortKey());
    assertEquals("Incorrect parent", null, node.getParent());
    node = (EquipNodeImpl) nodeList.getElementAt(adjustedBaseNodes);
    assertEquals("Incorrect container name", item.getName(), node.toString());
    assertEquals("Incorrect container type", NodeType.EQUIPMENT, node.getNodeType());
    assertEquals("Incorrect sort key", "00|" + item.getName(), node.getSortKey());
    assertEquals("Incorrect parent", nodeList.getElementAt(0), node.getParent());
    node = (EquipNodeImpl) nodeList.getElementAt(adjustedBaseNodes + 2);
    assertEquals("Incorrect item name", item2.getName(), node.toString());
    assertEquals("Incorrect item type", NodeType.EQUIPMENT, node.getNodeType());
    assertEquals(
        "Incorrect sort key", "00|" + item.getName() + "|" + item2.getName(), node.getSortKey());
    assertEquals("Incorrect parent", nodeList.getElementAt(adjustedBaseNodes), node.getParent());
    node = (EquipNodeImpl) nodeList.getElementAt(adjustedBaseNodes + 1);
    assertEquals("Incorrect item name", item3.getName(), node.toString());
    assertEquals("Incorrect item type", NodeType.EQUIPMENT, node.getNodeType());
    assertEquals("Incorrect sort key", "01|" + item3.getName(), node.getSortKey());
    assertEquals("Incorrect parent", LOC_HANDS, node.getParent().toString());
    node = (EquipNodeImpl) nodeList.getElementAt(adjustedBaseNodes + 2);
    EquipNode parent = node.getParent();
    assertEquals(
        "Root incorrect", Constants.EQUIP_LOCATION_EQUIPPED, parent.getParent().toString());
    assertEquals("Leaf incorrect", item.getName(), parent.toString());
    assertEquals("Incorrect nuber of paths found", adjustedBaseNodes + 3, nodeList.getSize());
  }
  /** Check that EquipmentSetFacadeImpl can manage addition and removal of equipment. */
  public void testAddRemove() {
    EquipSet es = new EquipSet("0.1", "Unit Test Equip");
    EquipmentSetFacadeImpl esfi =
        new EquipmentSetFacadeImpl(uiDelegate, getCharacter(), es, dataset);
    EquipNode root = esfi.getNodes().getElementAt(0);
    Equipment item = new Equipment();
    item.setName("Dart");
    assertEquals("Initial num carried", 0, item.getCarried(), 0.01);
    assertEquals("Initial num equipped", 0, item.getNumberEquipped());
    assertEquals("Initial node list size", NUM_BASE_NODES, esfi.getNodes().getSize());

    Equipment addedEquip = (Equipment) esfi.addEquipment(root, item, 2);
    assertEquals("First add num carried", 2, addedEquip.getCarried(), 0.01);
    assertEquals("First add num equipped", 2, addedEquip.getNumberEquipped());
    assertEquals("Should be no sideeffects to num carried", 0, item.getCarried(), 0.01);
    assertEquals("Should be no sideeffects to equipped", 0, item.getNumberEquipped());
    assertEquals("First add node list size", NUM_BASE_NODES + 1, esfi.getNodes().getSize());
    assertEquals(
        "generated equip set id",
        "0.1.1",
        ((EquipNodeImpl) esfi.getNodes().getElementAt(NUM_BASE_NODES)).getIdPath());

    Equipment secondEquip = (Equipment) esfi.addEquipment(root, item, 1);
    assertEquals("Second add num carried", 3, secondEquip.getCarried(), 0.01);
    assertEquals("Second add num equipped", 3, secondEquip.getNumberEquipped());
    assertEquals("Should be no sideeffects to num carried", 0, item.getCarried(), 0.01);
    assertEquals("Should be no sideeffects to equipped", 0, item.getNumberEquipped());
    assertTrue("Same equipment item should have been used", addedEquip == secondEquip);
    assertEquals("First add node list size", NUM_BASE_NODES + 1, esfi.getNodes().getSize());

    EquipNode target = esfi.getNodes().getElementAt(NUM_BASE_NODES);
    Equipment removedEquip = (Equipment) esfi.removeEquipment(target, 2);
    assertEquals("First add num carried", 1, removedEquip.getCarried(), 0.01);
    assertEquals("First add num equipped", 1, removedEquip.getNumberEquipped());
    assertTrue("Same equipment item should have been used", addedEquip == removedEquip);
    assertEquals("Should be no sideeffects to num carried", 0, item.getCarried(), 0.01);
    assertEquals("Should be no sideeffects to equipped", 0, item.getNumberEquipped());
    assertEquals("First add node list size", NUM_BASE_NODES + 1, esfi.getNodes().getSize());

    esfi.removeEquipment(target, 1);
    assertEquals("First add num carried", 0, addedEquip.getCarried(), 0.01);
    assertEquals("First add num equipped", 0, addedEquip.getNumberEquipped());
    assertEquals("Should be no sideeffects to num carried", 0, item.getCarried(), 0.01);
    assertEquals("Should be no sideeffects to equipped", 0, item.getNumberEquipped());
    assertEquals("First add node list size", NUM_BASE_NODES, esfi.getNodes().getSize());
  }
Example #14
0
 @Override
 public String encodeChoice(Equipment choice) {
   return choice.getKeyName();
 }
Example #15
0
  private static String _writeArmorProperty(Equipment eq, String property, PlayerCharacter aPC) {
    CharacterDisplay display = aPC.getDisplay();
    StringBuilder ret = new StringBuilder();

    if (property.startsWith("NAME")) {
      if (eq.isEquipped() && !property.equals("NAMENOSTAR")) {
        ret.append("*");
      }

      ret.append(OutputNameFormatting.parseOutputName(eq, aPC));
      ret.append(eq.getAppliedName());
    } else if (property.startsWith("OUTPUTNAME")) {
      // TODO this appears to be the same as above.  Should be refactored
      if (eq.isEquipped()) {
        ret.append("*");
      }

      ret.append(OutputNameFormatting.parseOutputName(eq, aPC));
      ret.append(eq.getAppliedName());
    } else if (property.startsWith("TOTALAC") || property.startsWith("ACBONUS")) {
      // adjustments for new equipment modifier
      // EQMARMOR|AC|x|TYPE=ENHANCEMENT changed to COMBAT|AC|x|TYPE=Armor.ENHANCEMENT
      // FileAccess.write(output, Delta.toString(eq.getACMod()));
      String acMod = aPC.getControl(CControl.EQACMOD);
      if (acMod != null) {
        Object o = aPC.getLocal(eq, acMod);
        int intValue = ((Number) o).intValue();
        ret.append(Delta.toString(intValue));
      } else {
        ret.append(Delta.toString((int) eq.bonusTo(aPC, "COMBAT", "AC", true)));
      }
    } else if (property.startsWith("BASEAC")) {
      // adjustments for new equipment modifier
      // EQMARMOR|AC|x|TYPE=ENHANCEMENT changed to COMBAT|AC|x|TYPE=Armor.ENHANCEMENT
      // FileAccess.write(output, Delta.toString(eq.getACMod()));
      String baseMod = aPC.getControl(CControl.EQBASEACMOD);
      if (baseMod != null) {
        Object o = aPC.getLocal(eq, baseMod);
        int intValue = ((Number) o).intValue();
        ret.append(Delta.toString(intValue));
      } else {
        ret.append(Delta.toString((int) BonusCalc.charBonusTo(eq, "COMBAT", "AC", aPC)));
      }
    } else if (property.startsWith("MAXDEX")) {
      final int iMax = EqToken.getMaxDexTokenInt(aPC, eq);
      if (iMax != Constants.MAX_MAXDEX) {
        ret.append(Delta.toString(iMax));
      }
    } else if (property.startsWith("ACCHECK")) {
      ret.append(Delta.toString(EqToken.getAcCheckTokenInt(aPC, eq)));
    } else if (property.startsWith("EDR")) {
      ret.append(Delta.toString(EqToken.getEdrTokenInt(aPC, eq)));
    } else if (property.startsWith("ISTYPE")) {
      if (eq.isType(property.substring(property.indexOf(".") + 1))) {
        ret.append("TRUE");
      } else {
        ret.append("FALSE");
      }
    } else if (property.startsWith("SPELLFAIL")) {
      ret.append(EqToken.getSpellFailureTokenInt(aPC, eq));
    } else if (property.startsWith("MOVE")) {
      final StringTokenizer aTok = new StringTokenizer(eq.moveString(), ",", false);
      String tempString = "";

      if (("M".equals(display.getSize()) || "S".equals(display.getSize()))
          && (aTok.countTokens() > 0)) {
        tempString = aTok.nextToken();

        if ("S".equals(display.getSize()) && (aTok.countTokens() > 1)) {
          tempString = aTok.nextToken();
        }
      }

      ret.append(tempString);
    } else if (property.startsWith("SPROP")) {
      ret.append(eq.getSpecialProperties(aPC));
    } else if (property.startsWith("TYPE")) {
      String typeString = "";

      if (eq.isLight()) {
        typeString = "Light";
      } else if (eq.isMedium()) {
        typeString = "Medium";
      } else if (eq.isHeavy()) {
        typeString = "Heavy";
      } else if (eq.isShield()) {
        typeString = "Shield";
      } else if (eq.isExtra()) {
        typeString = "Extra";
      }

      ret.append(typeString);
    } else if (property.startsWith("WT")) {
      ret.append(BigDecimalHelper.trimZeros(eq.getWeight(aPC).toString()));
    }
    return ret.toString();
  }
Example #16
0
  // TODO Refactor this with all the equipment tests.
  @Override
  public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source)
      throws PrerequisiteException {
    final int number;
    try {
      number = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException e) {
      throw new PrerequisiteException(
          LanguageBundle.getFormattedString(
              "PreItem.error.bad_operand", prereq.toString())); // $NON-NLS-1$
    }

    int runningTotal = 0;

    if (display.hasEquipment()) {
      // Work out exactlywhat we are going to test.
      final String aString = prereq.getKey();
      List<String> typeList = null;
      if (aString.startsWith(Constants.LST_TYPE_EQUAL)
          || aString.startsWith(Constants.LST_TYPE_DOT)) {
        String stripped = aString.substring(Constants.SUBSTRING_LENGTH_FIVE);
        typeList = CoreUtility.split(stripped, '.');
      }

      for (Equipment eq : display.getEquipmentSet()) {
        if (typeList != null) {
          // Check to see if the equipment matches
          // all of the types in the requested list;
          boolean bMatches = true;
          for (int i = 0, x = typeList.size(); i < x; ++i) {
            if (!eq.isType(typeList.get(i))) {
              bMatches = false;
              break;
            }
          }
          if (bMatches) {
            runningTotal++;
          }
        } else { // not a TYPE string
          final String eqName = eq.getName().toUpperCase();

          if (aString.indexOf('%') >= 0) {
            // handle wildcards (always assume
            // they end the line)
            final int percentPos = aString.indexOf('%');
            final String substring = aString.substring(0, percentPos).toUpperCase();
            if ((eqName.startsWith(substring))) {
              ++runningTotal;
              break;
            }
          } else if (eqName.equalsIgnoreCase(aString)) {
            // just a straight String compare
            ++runningTotal;
            break;
          }
        }
      }
    }

    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
  }