Exemple #1
0
 private DVector getDeityData(HTTPRequest httpReq, String deityName) {
   DVector folData =
       (DVector) httpReq.getRequestObjects().get("DEITYDATAFOR-" + deityName.toUpperCase().trim());
   if (folData != null) return folData;
   folData = CMLib.database().worshippers(deityName);
   httpReq.getRequestObjects().put("DEITYDATAFOR-" + deityName.toUpperCase().trim(), folData);
   return folData;
 }
Exemple #2
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public String runMacro(HTTPRequest httpReq, String parm) {
    java.util.Map<String, String> parms = parseParms(parm);
    String last = httpReq.getUrlParameter("HELPTOPIC");
    if (parms.containsKey("RESET")) {
      if (last != null) httpReq.removeUrlParameter("HELPTOPIC");
      httpReq.removeUrlParameter("HELPFIRSTLETTER");
      return "";
    } else if (parms.containsKey("DATA")) {
      int limit = 78;
      if (parms.containsKey("LIMIT")) limit = CMath.s_int(parms.get("LIMIT"));
      if ((last != null) && (last.length() > 0)) {
        StringBuilder s = CMLib.help().getHelpText(last, null, parms.containsKey("AHELP"));
        if (s != null) return clearWebMacros(helpHelp(s, limit).toString());
      }
      return "";
    } else if (parms.containsKey("NEXTLETTER")) {
      String fletter = httpReq.getUrlParameter("HELPFIRSTLETTER");
      if ((fletter == null) || (fletter.length() == 0)) fletter = "A";
      else if (fletter.charAt(0) >= 'Z') {
        httpReq.addFakeUrlParameter("HELPFIRSTLETTER", "");
        return " @break@";
      } else fletter = Character.toString((char) (fletter.charAt(0) + 1));
      httpReq.addFakeUrlParameter("HELPFIRSTLETTER", fletter);
    } else if (parms.containsKey("NEXT")) {
      List<String> topics = null;
      if (parms.containsKey("ARCHON")) {
        topics = (List) httpReq.getRequestObjects().get("HELP_ARCHONTOPICS");
        if (topics == null) {
          topics = CMLib.help().getTopics(true, false);
          httpReq.getRequestObjects().put("HELP_ARCHONTOPICS", topics);
        }
      } else if (parms.containsKey("BOTH")) {
        topics = (List) httpReq.getRequestObjects().get("HELP_BOTHTOPICS");
        if (topics == null) {
          topics = CMLib.help().getTopics(true, true);
          httpReq.getRequestObjects().put("HELP_BOTHTOPICS", topics);
        }
      } else {
        topics = (List) httpReq.getRequestObjects().get("HELP_HELPTOPICS");
        if (topics == null) {
          topics = CMLib.help().getTopics(false, true);
          httpReq.getRequestObjects().put("HELP_HELPTOPICS", topics);
        }
      }

      boolean noables = parms.containsKey("SHORT");
      String fletter = parms.get("FIRSTLETTER");
      if (fletter == null) fletter = httpReq.getUrlParameter("FIRSTLETTER");
      if (fletter == null) fletter = "";

      String lastID = "";
      for (int h = 0; h < topics.size(); h++) {
        String topic = topics.get(h);
        if (noables && CMLib.help().isPlayerSkill(topic)) continue;
        if (topic.startsWith(fletter) || (fletter.length() == 0))
          if ((last == null)
              || ((last.length() > 0) && (last.equals(lastID)) && (!topic.equals(lastID)))) {
            httpReq.addFakeUrlParameter("HELPTOPIC", topic);
            return "";
          }
        lastID = topic;
      }
      httpReq.addFakeUrlParameter("HELPTOPIC", "");
      if (parms.containsKey("EMPTYOK")) return "<!--EMPTY-->";
      return " @break@";
    } else if (last != null) return last;
    return "<!--EMPTY-->";
  }
Exemple #3
0
  public String runMacro(HTTPRequest httpReq, String parm) {
    java.util.Map<String, String> parms = parseParms(parm);
    String last = httpReq.getUrlParameter("DEITY");
    if (last == null) return " @break@";
    if (last.length() > 0) {
      Deity D = CMLib.map().getDeity(last);
      if (D != null) {
        StringBuffer str = new StringBuffer("");
        if (parms.containsKey("DESCRIPTION")) str.append(D.description() + ", ");
        if (parms.containsKey("NAME")) str.append(D.Name() + ", ");
        if (parms.containsKey("LOCATION")) {
          if (D.getStartRoom() == null) str.append("Nowhere, ");
          else
            str.append(
                CMLib.map().getExtendedRoomID(D.getStartRoom())
                    + ": "
                    + D.getStartRoom().displayText()
                    + ", ");
        }
        if (parms.containsKey("AREA") && (D.getStartRoom() != null))
          if (parms.containsKey("ENCODED"))
            try {
              str.append(URLEncoder.encode(D.getStartRoom().getArea().Name(), "UTF-8") + ", ");
            } catch (Exception e) {
            }
          else str.append(D.getStartRoom().getArea().Name() + ", ");
        if (parms.containsKey("ROOM") && (D.getStartRoom() != null))
          if (parms.containsKey("ENCODED"))
            try {
              str.append(URLEncoder.encode(D.getStartRoom().roomID(), "UTF-8") + ", ");
            } catch (Exception e) {
            }
          else str.append(D.getStartRoom().roomID() + ", ");
        if (parms.containsKey("MOBCODE")) {
          String roomID = D.getStartRoom().roomID();
          List classes = (List) httpReq.getRequestObjects().get("DEITYLIST-" + roomID);
          if (classes == null) {
            classes = new Vector();
            Room R = (Room) httpReq.getRequestObjects().get(roomID);
            if (R == null) {
              R = CMLib.map().getRoom(roomID);
              if (R == null) return "No Room?!";
              Vector restoreDeities = new Vector();
              for (Enumeration e = CMLib.map().deities(); e.hasMoreElements(); ) {
                Deity D2 = (Deity) e.nextElement();
                if ((D2.getStartRoom() != null)
                    && (CMLib.map()
                        .getExtendedRoomID(D2.getStartRoom())
                        .equalsIgnoreCase(CMLib.map().getExtendedRoomID(R))))
                  restoreDeities.addElement(D2);
              }
              CMLib.map().resetRoom(R);
              R = CMLib.map().getRoom(roomID);
              for (int d = restoreDeities.size() - 1; d >= 0; d--) {
                Deity D2 = (Deity) restoreDeities.elementAt(d);
                if (CMLib.map().getDeity(D2.Name()) != null) restoreDeities.removeElementAt(d);
              }
              for (Enumeration e = restoreDeities.elements(); e.hasMoreElements(); ) {
                Deity D2 = (Deity) e.nextElement();
                for (int i = 0; i < R.numInhabitants(); i++) {
                  MOB M = R.fetchInhabitant(i);
                  if ((M instanceof Deity) && (M.Name().equals(D2.Name())))
                    CMLib.map().registerWorldObjectLoaded(R.getArea(), R, M);
                }
              }
              httpReq.getRequestObjects().put(roomID, R);
              D = CMLib.map().getDeity(last);
            }
            synchronized (("SYNC" + roomID).intern()) {
              R = CMLib.map().getRoom(R);
              for (int m = 0; m < R.numInhabitants(); m++) {
                MOB M = R.fetchInhabitant(m);
                if (M.isSavable()) classes.add(M);
              }
              RoomData.contributeMOBs(classes);
            }
            httpReq.getRequestObjects().put("DEITYLIST-" + roomID, classes);
          }
          if (parms.containsKey("ENCODED"))
            try {
              str.append(URLEncoder.encode(RoomData.getMOBCode(classes, D), "UTF-8") + ", ");
            } catch (Exception e) {
            }
          else str.append(RoomData.getMOBCode(classes, D) + ", ");
        }
        if (parms.containsKey("WORSHIPREQ")) str.append(D.getWorshipRequirementsDesc() + ", ");
        if (parms.containsKey("CLERICREQ")) str.append(D.getClericRequirementsDesc() + ", ");
        if (parms.containsKey("SERVICETRIG")) str.append(D.getServiceTriggerDesc() + ", ");
        if (D.numCurses() > 0) {
          if (parms.containsKey("WORSHIPSINTRIG")) str.append(D.getWorshipSinDesc() + ", ");
          if (parms.containsKey("CLERICSINTRIG")) str.append(D.getClericSinDesc() + ", ");
        }

        if (D.numPowers() > 0)
          if (parms.containsKey("POWERTRIG")) str.append(D.getClericPowerupDesc() + ", ");
        if (D.numBlessings() > 0) {
          if (parms.containsKey("WORSHIPTRIG")) str.append(D.getWorshipTriggerDesc() + ", ");
          if (parms.containsKey("CLERICTRIG")) str.append(D.getClericTriggerDesc() + ", ");
        }
        if (parms.containsKey("NUMFOLLOWERS")) {
          DVector data = getDeityData(httpReq, D.Name());
          int num = data.size();
          str.append(num + ", ");
        }
        if (parms.containsKey("NUMPRIESTS")) {
          DVector data = getDeityData(httpReq, D.Name());
          int num = 0;
          // DV.addElement(username, cclass, ""+level, race);
          for (int d = 0; d < data.size(); d++) {
            CharClass C = CMClass.getCharClass((String) data.elementAt(d, 2));
            if ((C != null) && (C.baseClass().equalsIgnoreCase("CLERIC"))) num++;
          }
          str.append(num + ", ");
        }
        String strstr = str.toString();
        if (strstr.endsWith(", ")) strstr = strstr.substring(0, strstr.length() - 2);
        return clearWebMacros(strstr);
      }
    }
    return "";
  }