/**
  * 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;
 }
  /** 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());
  }
Example #3
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);
  }