public ChameleonList<Ability> getClanLevelEffects(final MOB mob, final Integer level) { if (level == null) return getEmptyClanLevelEffects(mob); final DefaultClanGovernment myGovt = this; final List<Ability> myList = getClanLevelEffectsList(mob, level); final List<Ability> finalV = new Vector<Ability>(myList.size()); for (final Ability A : myList) { Ability finalA = (Ability) A.copyOf(); finalA.makeNonUninvokable(); finalA.setSavable(false); // must come AFTER the above finalA.setAffectedOne(mob); finalV.add(finalA); } final ChameleonList<Ability> finalFinalV; if (mob == null) { finalFinalV = new ChameleonList<Ability>( finalV, new ChameleonList.Signaler<Ability>(myList) { public boolean isDeprecated() { return false; } public void rebuild(final ChameleonList<Ability> me) {} }); } else { finalFinalV = new ChameleonList<Ability>( finalV, new ChameleonList.Signaler<Ability>(myList) { public boolean isDeprecated() { if ((mob == null) || (mob.amDestroyed())) return true; final Clan C = mob.getMyClan(); if (C == null) return true; if ((C.getGovernment() != myGovt) || (getClanLevelEffectsList(mob, Integer.valueOf(C.getClanLevel())) != oldReferenceListRef.get())) return true; return false; } public void rebuild(final ChameleonList<Ability> me) { final Clan C = (mob != null) ? mob.getMyClan() : null; if ((mob == null) || (mob.amDestroyed()) || (C == null)) me.changeMeInto(getEmptyClanLevelEffects(mob)); else me.changeMeInto( C.getGovernment() .getClanLevelEffects(mob, Integer.valueOf(C.getClanLevel()))); } }); } return finalFinalV; }
public void delPosition(ClanPosition pos) { List<ClanPosition> newPos = new LinkedList<ClanPosition>(); for (ClanPosition P : positions) if (P != pos) newPos.add(P); positions = newPos.toArray(new ClanPosition[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; }
public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException { if (commands.size() < 2) { mob.tell("Wear what?"); return false; } Wearable.CODES codes = Wearable.CODES.instance(); commands.removeElementAt(0); if (commands.firstElement() instanceof Item) { Item wearWhat = (Item) commands.firstElement(); boolean quietly = false; int wearLocationIndex = 0; commands.removeElementAt(0); if (commands.size() > 0) { if (commands.firstElement() instanceof Integer) { wearLocationIndex = ((Integer) commands.firstElement()).intValue(); commands.removeElementAt(0); } else if (commands.firstElement() instanceof String) { int newDex = codes.findDex_ignoreCase((String) commands.firstElement()); if (newDex > 0) { wearLocationIndex = newDex; commands.removeElementAt(0); } } if ((commands.size() > 0) && (commands.lastElement() instanceof String) && (((String) commands.lastElement()).equalsIgnoreCase("QUIETLY"))) quietly = true; } return wear(mob, wearWhat, wearLocationIndex, quietly); } // discover if a wear location was specified int wearLocationIndex = 0; for (int i = commands.size() - 2; i > 0; i--) if (((String) commands.elementAt(i)).equalsIgnoreCase("on")) { if ((i < commands.size() - 2) && ((String) commands.elementAt(i + 1)).equalsIgnoreCase("my")) commands.removeElementAt(i + 1); String possibleWearLocation = CMParms.combine(commands, i + 1).toLowerCase().trim(); int possIndex = CMParms.indexOfIgnoreCase(Wearable.CODES.NAMES(), possibleWearLocation); if (possIndex < 0) possIndex = Wearable.CODES.FINDDEX_endsWith(" " + possibleWearLocation); if (possIndex > 0) { wearLocationIndex = possIndex; while (commands.size() > i) commands.removeElementAt(commands.size() - 1); break; } else { mob.tell("You can't wear anything on your '" + possibleWearLocation + "'"); return false; } // will always break out here, one way or the other. } List<Item> items = CMLib.english().fetchItemList(mob, mob, null, commands, Wearable.FILTER_UNWORNONLY, true); if (items.size() == 0) mob.tell("You don't seem to be carrying that."); else { // sort hold-onlys down. Item I = null; for (int i = items.size() - 2; i >= 0; i--) { I = (Item) items.get(i); if (I.rawProperLocationBitmap() == Wearable.WORN_HELD) { items.remove(i); items.add(I); } } for (int i = 0; i < items.size(); i++) { I = (Item) items.get(i); if ((items.size() == 1) || (I.canWear(mob, 0))) wear(mob, I, wearLocationIndex, false); } } return false; }