public static final void handleTemporaryCounters(final String type, final String encounter) { String temp = Preferences.getString("_tempRelayCounters"); if (temp.equals("")) { return; } int snarfblat = KoLAdventure.lastAdventureId(); if (snarfblat == 0 || snarfblat == AdventurePool.THE_SHORE || snarfblat == AdventurePool.TRAINING_SNOWMAN || snarfblat == AdventurePool.DIRE_WARREN || (snarfblat >= AdventurePool.GINGERBREAD_CIVIC && snarfblat <= AdventurePool.GINGERBREAD_SEWERS)) { return; } if (type.equals("Combat")) { if (EncounterManager.isNoWanderMonster(encounter)) { return; } } String[] counters = temp.split("\\|"); for (String counter : counters) { if (counter.equals("")) continue; String[] values = counter.split(":"); TurnCounter.startCounting(StringUtilities.parseInt(values[0]), values[1], values[2]); } Preferences.setString("_tempRelayCounters", ""); }
public static final int parseRevision(String version) { if (version == null) { return 0; } if (version.startsWith("KoLmafia r")) { version = version.substring(10); } return StringUtilities.isNumeric(version) ? StringUtilities.parseInt(version) : 0; }
public static final int getRevision() { if (KoLConstants.REVISION == null) { return 0; } int colonIndex = KoLConstants.REVISION.indexOf(":"); String revision = KoLConstants.REVISION; if (colonIndex != -1) { revision = KoLConstants.REVISION.substring(0, colonIndex); } else if (KoLConstants.REVISION.endsWith("M")) { revision = KoLConstants.REVISION.substring(0, KoLConstants.REVISION.length() - 1); } return StringUtilities.isNumeric(revision) ? StringUtilities.parseInt(revision) : 0; }
@Override public void run() { if (this.trophies == null) { super.run(); this.trophies = new ArrayList(); if (this.responseText == null) { return; } Matcher m = TrophyRequest.TROPHY_PATTERN.matcher(this.responseText); while (m.find()) { this.trophies.add( new Trophy( m.group(1), m.group(2), StringUtilities.parseInt(m.group(3)), m.group(4) != null)); } return; } this.addFormField("action", "Yup."); Iterator i = this.trophies.iterator(); while (i.hasNext()) { Trophy t = (Trophy) i.next(); if (t.visible) { this.addFormField("public" + t.id, "on"); } } super.run(); // Multiple trophy moving only works via GET, not POST. StringBuilder buf = new StringBuilder("trophies.php?moveall=yes"); i = this.trophies.iterator(); int pos = 1; while (i.hasNext()) { Trophy t = (Trophy) i.next(); buf.append("&trophy"); buf.append(t.id); buf.append("="); buf.append(pos++); } this.constructURLString("blah", false); // clear out cached URL data this.constructURLString(buf.toString(), false); super.run(); }
public static final void loadCounters() { synchronized (TurnCounter.relayCounters) { TurnCounter.relayCounters.clear(); String counters = Preferences.getString("relayCounters"); if (counters.length() == 0) { return; } StringTokenizer tokens = new StringTokenizer(counters, ":"); while (tokens.hasMoreTokens()) { int turns = StringUtilities.parseInt(tokens.nextToken()) - KoLCharacter.getCurrentRun(); if (!tokens.hasMoreTokens()) break; String name = tokens.nextToken(); if (!tokens.hasMoreTokens()) break; String image = tokens.nextToken(); startCountingInternal(turns, name, image); } } }
@Override public void run(final String cmd, final String parameters) { String[] split = parameters.split(" "); // Cure "HP" or "MP" String typeString = split[0]; String type; if (typeString.equalsIgnoreCase("hp")) { type = GalaktikRequest.HP; } else if (typeString.equalsIgnoreCase("mp")) { type = GalaktikRequest.MP; } else { KoLmafia.updateDisplay(MafiaState.ERROR, "Unknown Doc Galaktik request <" + parameters + ">"); return; } int amount = split.length == 1 ? 0 : StringUtilities.parseInt(split[1]); RequestThread.postRequest(new GalaktikRequest(type, amount)); }
public static boolean makeChezSnooteeRequest(final String parameters) { if (!KoLCharacter.canadiaAvailable()) { KoLmafia.updateDisplay( "Since you have no access to Little Canadia, you may not visit the restaurant."); return false; } if (KoLConstants.restaurantItems.isEmpty()) { ChezSnooteeRequest.getMenu(); } if (parameters.equals("")) { RequestLogger.printLine("Today's Special: " + ChezSnooteeRequest.getDailySpecial()); return false; } String[] splitParameters = AbstractCommand.splitCountAndName(parameters); String countString = splitParameters[0]; String nameString = splitParameters[1]; if (nameString.equalsIgnoreCase("daily special")) { nameString = ChezSnooteeRequest.getDailySpecial().getName(); } else if (nameString.startsWith("\u00B6")) { String name = ItemDatabase.getItemName(StringUtilities.parseInt(nameString.substring(1))); if (name != null) { nameString = name; } } nameString = nameString.toLowerCase(); for (int i = 0; i < KoLConstants.restaurantItems.size(); ++i) { String name = (String) KoLConstants.restaurantItems.get(i); if (!StringUtilities.substringMatches(name.toLowerCase(), nameString, false)) { continue; } if (KoLmafiaCLI.isExecutingCheckOnlyCommand) { RequestLogger.printLine(name); return true; } int count = countString == null || countString.length() == 0 ? 1 : StringUtilities.parseInt(countString); if (count == 0) { int fullness = ItemDatabase.getFullness(name); if (fullness > 0) { count = (KoLCharacter.getFullnessLimit() - KoLCharacter.getFullness()) / fullness; } } for (int j = 0; j < count; ++j) { RequestThread.postRequest(new ChezSnooteeRequest(name)); } return true; } return false; }