Пример #1
0
 public ClanPosition getPosition(String pos) {
   if (pos == null) return null;
   pos = pos.trim();
   if (CMath.isInteger(pos)) {
     int i = CMath.s_int(pos);
     if ((i >= 0) && (i < positions.length)) return positions[i];
   }
   for (ClanPosition P : positions) if (P.getID().equalsIgnoreCase(pos)) return P;
   return null;
 }
Пример #2
0
  public String getHelpStr() {
    if (getLongDesc().length() == 0) return null;
    if (helpStr == null) {
      StringBuilder str = new StringBuilder("\n\rOrganization type: " + getName() + "\n\r\n\r");
      str.append(getLongDesc()).append("\n\r");
      str.append("\n\rAuthority Chart:\n\r\n\r");
      final List<ClanPosition> showablePositions = new Vector<ClanPosition>();
      for (ClanPosition P : getPositions()) {
        boolean showMe = false;
        for (Clan.Authority a : P.getFunctionChart()) if (a == Authority.CAN_DO) showMe = true;
        if (showMe) showablePositions.add(P);
      }
      final List<ClanPosition> sortedPositions = new Vector<ClanPosition>();
      while (sortedPositions.size() < showablePositions.size()) {
        ClanPosition highPos = null;
        for (ClanPosition P : showablePositions)
          if ((!sortedPositions.contains(P))
              && ((highPos == null) || (highPos.getRank() < P.getRank()))) highPos = P;
        sortedPositions.add(highPos);
      }
      final int[] posses = new int[sortedPositions.size()];
      int posTotalLen = 0;
      for (int p = 0; p < sortedPositions.size(); p++) {
        posses[p] = sortedPositions.get(p).getName().length() + 2;
        posTotalLen += posses[p];
      }
      int funcMaxLen = 0;
      int funcTotal = 0;
      String[] functionNames = new String[Clan.Function.values().length];
      for (int f = 0; f < Clan.Function.values().length; f++) {
        Clan.Function func = Clan.Function.values()[f];
        funcTotal += func.name().length() + 1;
        if (func.name().length() > funcMaxLen) funcMaxLen = func.name().length() + 1;
        functionNames[f] = func.name();
      }
      int funcAvg = funcTotal / Clan.Function.values().length;
      int funcMaxAvg = (int) CMath.round((double) funcAvg * 1.3);
      while ((funcMaxLen > funcMaxAvg) && ((funcMaxAvg + posTotalLen) > 78)) funcMaxLen--;
      if (posses.length > 0)
        while ((funcMaxLen + posTotalLen) > 78) {
          int highPos = 0;
          for (int p = 1; p < sortedPositions.size(); p++)
            if (posses[p] > posses[highPos]) highPos = p;
          posTotalLen--;
          posses[highPos]--;
        }

      final int commandColLen = funcMaxLen;
      str.append(CMStrings.padRight("Command", commandColLen - 1)).append("!");
      for (int p = 0; p < posses.length; p++) {
        ClanPosition pos = sortedPositions.get(p);
        String name = CMStrings.capitalizeAndLower(pos.getName().replace('_', ' '));
        str.append(CMStrings.padRight(name, posses[p] - 1));
        if (p < posses.length - 1) str.append("!");
      }
      str.append("\n\r");
      Object lineDraw =
          new Object() {
            private static final String line =
                "----------------------------------------------------------------------------";

            public String toString() {
              StringBuilder s = new StringBuilder("");
              s.append(line.substring(0, commandColLen - 1)).append("+");
              for (int p = 0; p < posses.length; p++) {
                s.append(CMStrings.padRight(line, posses[p] - 1));
                if (p < posses.length - 1) s.append("+");
              }
              return s.toString();
            }
          };
      str.append(lineDraw.toString()).append("\n\r");
      for (Clan.Function func : Clan.Function.values()) {
        String fname = CMStrings.capitalizeAndLower(func.toString().replace('_', ' '));
        str.append(CMStrings.padRight(fname, commandColLen - 1)).append("!");
        for (int p = 0; p < sortedPositions.size(); p++) {
          ClanPosition pos = sortedPositions.get(p);
          Authority auth = pos.getFunctionChart()[func.ordinal()];
          String x = "";
          if (auth == Authority.CAN_DO) x = "X";
          else if (auth == Authority.MUST_VOTE_ON) x = "v";
          str.append(CMStrings.padCenter(x, posses[p] - 1));
          if (p < posses.length - 1) str.append("!");
        }
        str.append("\n\r").append(lineDraw.toString()).append("\n\r");
      }
      /*
      protected String[] 	clanEffectNames			=null;
      protected int[] 	clanEffectLevels		=null;
      protected String[] 	clanEffectParms			=null;
      protected String[] 	clanAbilityNames		=null;
      protected int[] 	clanAbilityLevels		=null;
      protected int[] 	clanAbilityProficiencies=null;
      protected boolean[] clanAbilityQuals		=null;
      */

      if ((clanAbilityLevels != null)
          && (clanEffectLevels != null)
          && (clanAbilityLevels.length > 0)
          && (clanEffectLevels.length > 0)) {
        str.append("\n\rBenefits per Clan Level:\n\r");
        int maxLevel = -1;
        for (int x : clanEffectLevels) if (x > maxLevel) maxLevel = x;
        for (int x : clanAbilityLevels) if (x > maxLevel) maxLevel = x;
        for (int l = 1; l <= maxLevel; l++) {
          final List<String> levelBenefits = new LinkedList<String>();
          for (int x = 0; x < clanEffectLevels.length; x++)
            if (clanEffectLevels[x] == l) {
              final Ability A = CMClass.getAbility(clanEffectNames[x]);
              if (A != null) {
                A.setMiscText(clanEffectParms[x]);
                String desc = A.accountForYourself();
                if ((desc == null) || (desc.length() == 0))
                  desc = "Members gain the following effect: " + A.name();
                levelBenefits.add(desc);
              }
            }
          for (int x = 0; x < clanAbilityLevels.length; x++)
            if (clanAbilityLevels[x] == l) {
              final Ability A = CMClass.getAbility(clanAbilityNames[x]);
              if (A != null) {
                if (clanAbilityQuals[x]) levelBenefits.add("Members qualify for: " + A.name());
                else levelBenefits.add("Members automatically gain: " + A.name());
              }
            }
          for (final String bene : levelBenefits) str.append("Level " + l + ": " + bene + "\n\r");
        }
      }
      helpStr = str.toString();
    }
    return helpStr;
  }
Пример #3
0
 public void setStat(String code, String val) {
   int num = 0;
   int numDex = code.length();
   while ((numDex > 0) && (Character.isDigit(code.charAt(numDex - 1)))) numDex--;
   if (numDex < code.length()) {
     num = CMath.s_int(code.substring(numDex));
     code = code.substring(0, numDex);
   }
   final GOVT_STAT_CODES stat = getStatIndex(code);
   if (stat == null) {
     return;
   }
   switch (stat) {
     case NAME:
       name = val;
       break;
     case AUTOROLE:
       {
         ClanPosition P = getPosition(val);
         if (P != null) autoRole = P.getRoleID();
         break;
       }
     case ACCEPTPOS:
       {
         ClanPosition P = getPosition(val);
         if (P != null) acceptPos = P.getRoleID();
         break;
       }
     case SHORTDESC:
       shortDesc = val;
       break;
     case LONGDESC:
       longDesc = val;
       break;
     case XPLEVELFORMULA:
       setXpCalculationFormulaStr(val);
       break;
     case REQUIREDMASK:
       requiredMaskStr = val;
       break;
     case ISPUBLIC:
       isPublic = CMath.s_bool(val);
       break;
     case ISFAMILYONLY:
       isFamilyOnly = CMath.s_bool(val);
       break;
     case OVERRIDEMINMEMBERS:
       {
         if (val.length() == 0) overrideMinMembers = null;
         else overrideMinMembers = Integer.valueOf(CMath.s_int(val));
         break;
       }
     case CONQUESTENABLED:
       conquestEnabled = CMath.s_bool(val);
       break;
     case CONQUESTITEMLOYALTY:
       conquestItemLoyalty = CMath.s_bool(val);
       break;
     case CONQUESTDEITYBASIS:
       conquestByWorship = CMath.s_bool(val);
       break;
     case MAXVOTEDAYS:
       maxVoteDays = CMath.s_int(val);
       break;
     case VOTEQUORUMPCT:
       voteQuorumPct = CMath.s_int(val);
       break;
     case AUTOPROMOTEBY:
       {
         Clan.AutoPromoteFlag flag =
             (Clan.AutoPromoteFlag) CMath.s_valueOf(Clan.AutoPromoteFlag.values(), val);
         if (flag != null) autoPromoteBy = flag;
         break;
       }
     case VOTEFUNCS:
       {
         final Vector<String> funcs = CMParms.parseCommas(val.toUpperCase().trim(), true);
         for (ClanPosition pos : positions) {
           for (int a = 0; a < Function.values().length; a++)
             if (pos.getFunctionChart()[a] == Authority.MUST_VOTE_ON)
               pos.getFunctionChart()[a] = Authority.CAN_NOT_DO;
           for (final String funcName : funcs) {
             Authority auth = (Authority) CMath.s_valueOf(Function.values(), funcName);
             if (auth != null) pos.getFunctionChart()[auth.ordinal()] = Authority.MUST_VOTE_ON;
           }
         }
         break;
       }
     case NUMRABLE:
       clanAbilityMap = null;
       if (CMath.s_int(val) == 0) {
         clanAbilityNames = null;
         clanAbilityProficiencies = null;
         clanAbilityQuals = null;
         clanAbilityLevels = null;
       } else {
         clanAbilityNames = new String[CMath.s_int(val)];
         clanAbilityProficiencies = new int[CMath.s_int(val)];
         clanAbilityQuals = new boolean[CMath.s_int(val)];
         clanAbilityLevels = new int[CMath.s_int(val)];
       }
       break;
     case GETRABLE:
       {
         if (clanAbilityNames == null) clanAbilityNames = new String[num + 1];
         clanAbilityNames[num] = val;
         break;
       }
     case GETRABLEPROF:
       {
         if (clanAbilityProficiencies == null) clanAbilityProficiencies = new int[num + 1];
         clanAbilityProficiencies[num] = CMath.s_parseIntExpression(val);
         break;
       }
     case GETRABLEQUAL:
       {
         if (clanAbilityQuals == null) clanAbilityQuals = new boolean[num + 1];
         clanAbilityQuals[num] = CMath.s_bool(val);
         break;
       }
     case GETRABLELVL:
       {
         if (clanAbilityLevels == null) clanAbilityLevels = new int[num + 1];
         clanAbilityLevels[num] = CMath.s_parseIntExpression(val);
         break;
       }
     case NUMREFF:
       clanEffectMap = null;
       if (CMath.s_int(val) == 0) {
         clanEffectNames = null;
         clanEffectParms = null;
         clanEffectLevels = null;
       } else {
         clanEffectNames = new String[CMath.s_int(val)];
         clanEffectParms = new String[CMath.s_int(val)];
         clanEffectLevels = new int[CMath.s_int(val)];
       }
       break;
     case GETREFF:
       {
         if (clanEffectNames == null) clanEffectNames = new String[num + 1];
         clanEffectNames[num] = val;
         break;
       }
     case GETREFFPARM:
       {
         if (clanEffectParms == null) clanEffectParms = new String[num + 1];
         clanEffectParms[num] = val;
         break;
       }
     case GETREFFLVL:
       {
         if (clanEffectLevels == null) clanEffectLevels = new int[num + 1];
         clanEffectLevels[num] = CMath.s_int(val);
         break;
       }
     default:
       Log.errOut("Clan", "setStat:Unhandled:" + stat.toString());
       break;
   }
 }
Пример #4
0
 public String getStat(String code) {
   int num = 0;
   int numDex = code.length();
   while ((numDex > 0) && (Character.isDigit(code.charAt(numDex - 1)))) numDex--;
   if (numDex < code.length()) {
     num = CMath.s_int(code.substring(numDex));
     code = code.substring(0, numDex);
   }
   final GOVT_STAT_CODES stat = getStatIndex(code);
   if (stat == null) {
     return "";
   }
   switch (stat) {
     case NAME:
       return name;
     case AUTOROLE:
       return (autoRole < 0 || autoRole > positions.length) ? "" : positions[autoRole].getID();
     case ACCEPTPOS:
       return (acceptPos < 0 || acceptPos > positions.length) ? "" : positions[acceptPos].getID();
     case SHORTDESC:
       return shortDesc;
     case LONGDESC:
       return longDesc;
     case XPLEVELFORMULA:
       return xpCalculationFormulaStr == null ? "" : xpCalculationFormulaStr;
     case REQUIREDMASK:
       return requiredMaskStr;
     case ISPUBLIC:
       return Boolean.toString(isPublic);
     case ISFAMILYONLY:
       return Boolean.toString(isFamilyOnly);
     case OVERRIDEMINMEMBERS:
       return overrideMinMembers == null ? "" : overrideMinMembers.toString();
     case CONQUESTENABLED:
       return Boolean.toString(conquestEnabled);
     case CONQUESTITEMLOYALTY:
       return Boolean.toString(conquestItemLoyalty);
     case CONQUESTDEITYBASIS:
       return Boolean.toString(conquestByWorship);
     case MAXVOTEDAYS:
       return Integer.toString(maxVoteDays);
     case VOTEQUORUMPCT:
       return Integer.toString(voteQuorumPct);
     case AUTOPROMOTEBY:
       return autoPromoteBy.toString();
     case VOTEFUNCS:
       {
         final StringBuilder str = new StringBuilder("");
         for (ClanPosition pos : positions) {
           for (int a = 0; a < Function.values().length; a++)
             if (pos.getFunctionChart()[a] == Authority.MUST_VOTE_ON) {
               if (str.length() > 0) str.append(",");
               str.append(Function.values()[a]);
             }
           break;
         }
         return str.toString();
       }
     case NUMRABLE:
       return (clanAbilityNames == null) ? "0" : ("" + clanAbilityNames.length);
     case GETRABLE:
       return (clanAbilityNames == null) ? "" : ("" + clanAbilityNames[num]);
     case GETRABLEPROF:
       return (clanAbilityProficiencies == null) ? "0" : ("" + clanAbilityProficiencies[num]);
     case GETRABLEQUAL:
       return (clanAbilityQuals == null) ? "false" : ("" + clanAbilityQuals[num]);
     case GETRABLELVL:
       return (clanAbilityLevels == null) ? "0" : ("" + clanAbilityLevels[num]);
     case NUMREFF:
       return (clanEffectNames == null) ? "0" : ("" + clanEffectNames.length);
     case GETREFF:
       return (clanEffectNames == null) ? "" : ("" + clanEffectNames[num]);
     case GETREFFPARM:
       return (clanEffectParms == null) ? "0" : ("" + clanEffectParms[num]);
     case GETREFFLVL:
       return (clanEffectLevels == null) ? "0" : ("" + clanEffectLevels[num]);
     default:
       Log.errOut("Clan", "getStat:Unhandled:" + stat.toString());
       break;
   }
   return "";
 }
Пример #5
0
 public ClanPosition addPosition() {
   Authority[] pows = new Authority[Function.values().length];
   for (int i = 0; i < pows.length; i++) pows[i] = Authority.CAN_NOT_DO;
   Set<Integer> roles = new HashSet<Integer>();
   int highestRank = 0;
   for (ClanPosition pos : positions) {
     roles.add(Integer.valueOf(pos.getRoleID()));
     if (highestRank < pos.getRank()) highestRank = pos.getRank();
   }
   if (positions.length > 0)
     for (int i = 0; i < pows.length; i++) pows[i] = positions[0].getFunctionChart()[i];
   positions = Arrays.copyOf(positions, positions.length + 1);
   ClanPosition P = (ClanPosition) CMClass.getCommon("DefaultClanPosition");
   P.setID(positions.length + "" + Math.random());
   P.setRoleID(0);
   P.setRank(highestRank);
   P.setName("Unnamed");
   P.setPluralName("Unnameds");
   P.setMax(Integer.MAX_VALUE);
   P.setInnerMaskStr("");
   P.setFunctionChart(pows);
   P.setPublic(true);
   positions[positions.length - 1] = P;
   for (int i = 0; i < positions.length; i++)
     if (!roles.contains(Integer.valueOf(i))) {
       P.setRoleID(i);
       break;
     }
   return P;
 }