|
| 1 | +package com.chromascape.utils.actions; |
| 2 | + |
| 3 | +import com.chromascape.base.BaseScript; |
| 4 | +import com.chromascape.utils.core.screen.colour.ColourObj; |
| 5 | +import com.chromascape.utils.domain.ocr.Ocr; |
| 6 | +import java.awt.Rectangle; |
| 7 | +import java.io.IOException; |
| 8 | +import org.bytedeco.opencv.opencv_core.Scalar; |
| 9 | + |
| 10 | +/** |
| 11 | + * Class for retrieving information from the minimap area, such as orb data (HP, prayer, run, and |
| 12 | + * spec) and XP data. |
| 13 | + */ |
| 14 | +public class Minimap { |
| 15 | + |
| 16 | + private static final ColourObj textColour = |
| 17 | + new ColourObj("green", new Scalar(0, 254, 254, 0), new Scalar(60, 255, 255, 0)); |
| 18 | + |
| 19 | + private static final ColourObj white = |
| 20 | + new ColourObj("White", new Scalar(0, 0, 255, 0), new Scalar(0, 0, 255, 0)); |
| 21 | + |
| 22 | + /** |
| 23 | + * Returns the character's current hitpoints, or -1 if not found. |
| 24 | + * |
| 25 | + * @param script The current running script (typically pass {@code this}) |
| 26 | + * @throws IOException if the OCR failed to load the font |
| 27 | + */ |
| 28 | + public static int getHp(BaseScript script) throws IOException { |
| 29 | + Rectangle textArea = script.controller().zones().getMinimap().get("hpText"); |
| 30 | + String hpText = Ocr.extractText(textArea, "Plain 11", textColour, true); |
| 31 | + if (hpText.isEmpty()) { |
| 32 | + return -1; |
| 33 | + } |
| 34 | + return Integer.parseInt(hpText); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Returns the character's current prayer, or -1 if not found. |
| 39 | + * |
| 40 | + * @param script The current running script (typically pass {@code this}) |
| 41 | + * @throws IOException if the OCR failed to load the font |
| 42 | + */ |
| 43 | + public static int getPrayer(BaseScript script) throws IOException { |
| 44 | + Rectangle textArea = script.controller().zones().getMinimap().get("prayerText"); |
| 45 | + String prayerText = Ocr.extractText(textArea, "Plain 11", textColour, true); |
| 46 | + if (prayerText.isEmpty()) { |
| 47 | + return -1; |
| 48 | + } |
| 49 | + return Integer.parseInt(prayerText); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Returns the character's current run energy, or -1 if not found. |
| 54 | + * |
| 55 | + * @param script The current running script (typically pass {@code this}) |
| 56 | + * @throws IOException if the OCR failed to load the font |
| 57 | + */ |
| 58 | + public static int getRun(BaseScript script) throws IOException { |
| 59 | + Rectangle textArea = script.controller().zones().getMinimap().get("runText"); |
| 60 | + String runText = Ocr.extractText(textArea, "Plain 11", textColour, true); |
| 61 | + if (runText.isEmpty()) { |
| 62 | + return -1; |
| 63 | + } |
| 64 | + return Integer.parseInt(runText); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Returns the character's current special attack energy, or -1 if not found. |
| 69 | + * |
| 70 | + * @param script The current running script (typically pass {@code this}) |
| 71 | + * @throws IOException if the OCR failed to load the font |
| 72 | + */ |
| 73 | + public static int getSpec(BaseScript script) throws IOException { |
| 74 | + Rectangle textArea = script.controller().zones().getMinimap().get("specText"); |
| 75 | + String specText = Ocr.extractText(textArea, "Plain 11", textColour, true); |
| 76 | + if (specText.isEmpty()) { |
| 77 | + return -1; |
| 78 | + } |
| 79 | + return Integer.parseInt(specText); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Retrieves the current XP from beside the minimap UI element. |
| 84 | + * |
| 85 | + * <p>It is highly recommended to set the XP bar to permanent, as seen here: |
| 86 | + * https://github.com/StaticSweep/ChromaScape/wiki/Requirements |
| 87 | + * |
| 88 | + * @param script The current running script (typically pass {@code this}) |
| 89 | + * @return the XP string, or empty if not found |
| 90 | + * @throws IOException if the OCR failed to load the font |
| 91 | + */ |
| 92 | + public static String getXp(BaseScript script) throws IOException { |
| 93 | + Rectangle xpZone = script.controller().zones().getMinimap().get("totalXP"); |
| 94 | + return Ocr.extractText(xpZone, "Plain 12", white, true); |
| 95 | + } |
| 96 | +} |
0 commit comments