示例#1
0
  protected Condition parseTargetCondition(Node n, Object template) {
    Condition cond = null;
    NamedNodeMap attrs = n.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
      Node a = attrs.item(i);
      switch (a.getNodeName().toLowerCase()) {
        case "aggro":
          {
            boolean val = Boolean.parseBoolean(a.getNodeValue());
            cond = joinAnd(cond, new ConditionTargetAggro(val));
            break;
          }
        case "siegezone":
          {
            int value = Integer.decode(getValue(a.getNodeValue(), null));
            cond = joinAnd(cond, new ConditionSiegeZone(value, false));
            break;
          }
        case "level":
          {
            int lvl = Integer.decode(getValue(a.getNodeValue(), template));
            cond = joinAnd(cond, new ConditionTargetLevel(lvl));
            break;
          }
        case "levelrange":
          {
            String[] range = getValue(a.getNodeValue(), template).split(";");
            if (range.length == 2) {
              int[] lvlRange = new int[2];
              lvlRange[0] = Integer.decode(getValue(a.getNodeValue(), template).split(";")[0]);
              lvlRange[1] = Integer.decode(getValue(a.getNodeValue(), template).split(";")[1]);
              cond = joinAnd(cond, new ConditionTargetLevelRange(lvlRange));
            }
            break;
          }
        case "mypartyexceptme":
          {
            cond =
                joinAnd(
                    cond,
                    new ConditionTargetMyPartyExceptMe(Boolean.parseBoolean(a.getNodeValue())));
            break;
          }
        case "playable":
          {
            cond = joinAnd(cond, new ConditionTargetPlayable());
            break;
          }
        case "class_id_restriction":
          {
            StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
            List<Integer> array = new ArrayList<>(st.countTokens());
            while (st.hasMoreTokens()) {
              String item = st.nextToken().trim();
              array.add(Integer.decode(getValue(item, null)));
            }
            cond = joinAnd(cond, new ConditionTargetClassIdRestriction(array));
            break;
          }
        case "active_effect_id":
          {
            int effect_id = Integer.decode(getValue(a.getNodeValue(), template));
            cond = joinAnd(cond, new ConditionTargetActiveEffectId(effect_id));
            break;
          }
        case "active_effect_id_lvl":
          {
            String val = getValue(a.getNodeValue(), template);
            int effect_id = Integer.decode(getValue(val.split(",")[0], template));
            int effect_lvl = Integer.decode(getValue(val.split(",")[1], template));
            cond = joinAnd(cond, new ConditionTargetActiveEffectId(effect_id, effect_lvl));
            break;
          }
        case "active_skill_id":
          {
            int skill_id = Integer.decode(getValue(a.getNodeValue(), template));
            cond = joinAnd(cond, new ConditionTargetActiveSkillId(skill_id));
            break;
          }
        case "active_skill_id_lvl":
          {
            String val = getValue(a.getNodeValue(), template);
            int skill_id = Integer.decode(getValue(val.split(",")[0], template));
            int skill_lvl = Integer.decode(getValue(val.split(",")[1], template));
            cond = joinAnd(cond, new ConditionTargetActiveSkillId(skill_id, skill_lvl));
            break;
          }
        case "abnormal":
          {
            int abnormalId = Integer.decode(getValue(a.getNodeValue(), template));
            cond = joinAnd(cond, new ConditionTargetAbnormal(abnormalId));
            break;
          }
        case "mindistance":
          {
            int distance = Integer.decode(getValue(a.getNodeValue(), null));
            cond = joinAnd(cond, new ConditionMinDistance(distance * distance));
            break;
          }
        case "race":
          {
            cond = joinAnd(cond, new ConditionTargetRace(Race.valueOf(a.getNodeValue())));
            break;
          }
        case "using":
          {
            int mask = 0;
            StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
            while (st.hasMoreTokens()) {
              String item = st.nextToken().trim();
              for (WeaponType wt : WeaponType.values()) {
                if (wt.name().equals(item)) {
                  mask |= wt.mask();
                  break;
                }
              }
              for (ArmorType at : ArmorType.values()) {
                if (at.name().equals(item)) {
                  mask |= at.mask();
                  break;
                }
              }
            }
            cond = joinAnd(cond, new ConditionTargetUsesWeaponKind(mask));
            break;
          }
        case "npcid":
          {
            StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
            List<Integer> array = new ArrayList<>(st.countTokens());
            while (st.hasMoreTokens()) {
              String item = st.nextToken().trim();
              array.add(Integer.decode(getValue(item, null)));
            }
            cond = joinAnd(cond, new ConditionTargetNpcId(array));
            break;
          }
        case "npctype":
          {
            String values = getValue(a.getNodeValue(), template).trim();
            String[] valuesSplit = values.split(",");
            InstanceType[] types = new InstanceType[valuesSplit.length];
            InstanceType type;
            for (int j = 0; j < valuesSplit.length; j++) {
              type = Enum.valueOf(InstanceType.class, valuesSplit[j]);
              if (type == null) {
                throw new IllegalArgumentException(
                    "Instance type not recognized: " + valuesSplit[j]);
              }
              types[j] = type;
            }
            cond = joinAnd(cond, new ConditionTargetNpcType(types));
            break;
          }
        case "weight":
          {
            int weight = Integer.decode(getValue(a.getNodeValue(), null));
            cond = joinAnd(cond, new ConditionTargetWeight(weight));
            break;
          }
        case "invsize":
          {
            int size = Integer.decode(getValue(a.getNodeValue(), null));
            cond = joinAnd(cond, new ConditionTargetInvSize(size));
            break;
          }
      }
    }

    if (cond == null) {
      _log.severe("Unrecognized <target> condition in " + _file);
    }
    return cond;
  }
示例#2
0
  protected Condition parseUsingCondition(Node n) {
    Condition cond = null;
    NamedNodeMap attrs = n.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
      Node a = attrs.item(i);
      switch (a.getNodeName().toLowerCase()) {
        case "kind":
          {
            int mask = 0;
            StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
            while (st.hasMoreTokens()) {
              int old = mask;
              String item = st.nextToken().trim();
              for (WeaponType wt : WeaponType.values()) {
                if (wt.name().equals(item)) {
                  mask |= wt.mask();
                }
              }

              for (ArmorType at : ArmorType.values()) {
                if (at.name().equals(item)) {
                  mask |= at.mask();
                }
              }

              if (old == mask) {
                _log.info("[parseUsingCondition=\"kind\"] Unknown item type name: " + item);
              }
            }
            cond = joinAnd(cond, new ConditionUsingItemType(mask));
            break;
          }
        case "slot":
          {
            int mask = 0;
            StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
            while (st.hasMoreTokens()) {
              int old = mask;
              String item = st.nextToken().trim();
              if (ItemTable.SLOTS.containsKey(item)) {
                mask |= ItemTable.SLOTS.get(item);
              }

              if (old == mask) {
                _log.info("[parseUsingCondition=\"slot\"] Unknown item slot name: " + item);
              }
            }
            cond = joinAnd(cond, new ConditionUsingSlotType(mask));
            break;
          }
        case "skill":
          {
            int id = Integer.parseInt(a.getNodeValue());
            cond = joinAnd(cond, new ConditionUsingSkill(id));
            break;
          }
        case "slotitem":
          {
            StringTokenizer st = new StringTokenizer(a.getNodeValue(), ";");
            int id = Integer.parseInt(st.nextToken().trim());
            int slot = Integer.parseInt(st.nextToken().trim());
            int enchant = 0;
            if (st.hasMoreTokens()) {
              enchant = Integer.parseInt(st.nextToken().trim());
            }
            cond = joinAnd(cond, new ConditionSlotItemId(slot, id, enchant));
            break;
          }
        case "weaponchange":
          {
            boolean val = Boolean.parseBoolean(a.getNodeValue());
            cond = joinAnd(cond, new ConditionChangeWeapon(val));
            break;
          }
      }
    }

    if (cond == null) {
      _log.severe("Unrecognized <using> condition in " + _file);
    }
    return cond;
  }