Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package net.runelite.client.plugins.jrPlugins.autoChin

import com.google.inject.Provides
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import net.runelite.api.Client
import net.runelite.api.ItemID
import net.runelite.api.ObjectID
import net.runelite.api.Skill
import net.runelite.api.events.GameTick
import net.runelite.client.config.ConfigManager
import net.runelite.client.eventbus.Subscribe
import net.runelite.client.plugins.Plugin
import net.runelite.client.plugins.PluginDescriptor
import net.runelite.client.plugins.microbot.Microbot
import net.runelite.client.plugins.microbot.util.Global.sleep
import net.runelite.client.plugins.microbot.util.gameobject.Rs2GameObject
import net.runelite.client.plugins.microbot.util.grounditem.GroundItem
import net.runelite.client.ui.overlay.OverlayManager
import javax.inject.Inject

@PluginDescriptor(
name = "Auto Chinchompa",
description = "JR - Automatically catches chinchompas",
tags = ["chinchompas", "hunter", "auto", "catching", "jr", "JR", "microbot"],
enabledByDefault = false
)
class AutoChin: Plugin() {
@Inject
private lateinit var client: Client

@Inject
private lateinit var overlayManager: OverlayManager

@Inject
private lateinit var autoChinOverlay: AutoChinOverlay

@Provides
fun getConfig(configManager: ConfigManager): AutoChinConfig {
return configManager.getConfig(AutoChinConfig::class.java)
}

@Subscribe
fun onGameTick(gameTick: GameTick?) {
time = getElapsedTime()
xpGained = client.getSkillExperience(Skill.HUNTER) - startingXp.toLong()
caught = xpGained / 265
lvlsGained = client.getRealSkillLevel(Skill.HUNTER) - startingLvl.toLong()
}

companion object {
@JvmField
var xpGained: Long = 0
@JvmField
var caught: Long = 0
@JvmField
var lvlsGained: Long = 0
lateinit var version: String
lateinit var currentState: State
lateinit var time: String
}

private var running = false
private var startTime: Long = 0L
private var startingXp: Int = 0
private var startingLvl: Int = 0


enum class State {
IDLE,
CATCHING,
LAYING
}

override fun startUp() {
currentState = State.IDLE
version = "1.0.0"
startTime = System.currentTimeMillis()
startingXp = client.getSkillExperience(Skill.HUNTER)
startingLvl = client.getRealSkillLevel(Skill.HUNTER)

if (client.getLocalPlayer() != null) {
running = true
if (overlayManager != null) {
overlayManager.add(autoChinOverlay)
}
GlobalScope.launch { run() }
}
}

private fun run(){
while (running) {
when (currentState) {
State.IDLE -> handleIdleState()
State.CATCHING -> handleCatchingState()
State.LAYING -> handleLayingState()
}
}
}

override fun shutDown() {
running = false
overlayManager.remove(autoChinOverlay)
currentState = State.IDLE
}

private fun handleIdleState() {
try {
// If there are box traps on the floor, interact with them first
if (GroundItem.interact(ItemID.BOX_TRAP, "lay" , 4)) {
currentState = State.LAYING
return
}

// If there are shaking boxes, interact with them
if (Rs2GameObject.interact(ObjectID.SHAKING_BOX_9383, "reset", 4)) {
currentState = State.CATCHING
return
}

// Interact with traps that have not caught anything
if (Rs2GameObject.interact(ObjectID.BOX_TRAP_9385, "reset", 4)) {
currentState = State.CATCHING
return
}
} catch (e: Exception) {
//e.printStackTrace()
}
}

private fun handleCatchingState() {
sleep(8000,8100)
currentState = State.IDLE
}

private fun handleLayingState() {
sleep(6000,6100)
currentState = State.IDLE
}

fun getElapsedTime(): String {
val elapsed = System.currentTimeMillis() - startTime
val hours = elapsed / (1000 * 60 * 60)
val minutes = (elapsed % (1000 * 60 * 60)) / (1000 * 60)
val seconds = (elapsed % (1000 * 60)) / 1000
return "%02d:%02d:%02d".format(hours, minutes, seconds)
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.runelite.client.plugins.jrPlugins.autoChin;


import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;

@ConfigGroup("AutoChin")
public interface AutoChinConfig extends Config {

@ConfigItem(
keyName = "guide",
name = "How to use",
description = "How to use this plugin",
position = 0
)
default String GUIDE() {
return "1. Place your box traps down \n2. Enable Plugin";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package net.runelite.client.plugins.jrPlugins.autoChin;


import net.runelite.client.ui.overlay.OverlayPanel;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;
import javax.inject.Inject;
import java.awt.*;

public class AutoChinOverlay extends OverlayPanel {
@Inject
AutoChinOverlay(AutoChin plugin)
{
super(plugin);
setPosition(OverlayPosition.TOP_LEFT);
}
@Override
public Dimension render(Graphics2D graphics) {
try {
panelComponent.setPreferredSize(new Dimension(200, 300));
panelComponent.getChildren().add(TitleComponent.builder()
.text("Auto Chin V" + AutoChin.version)
.color(Color.GREEN)
.build());
panelComponent.getChildren().add(LineComponent.builder()
.left("Current State: " + AutoChin.currentState.toString())
.build());
panelComponent.getChildren().add(LineComponent.builder()
.left("Caught: " + AutoChin.caught)
.build());
panelComponent.getChildren().add(LineComponent.builder()
.left("XP Gained: " + AutoChin.xpGained)
.build());
panelComponent.getChildren().add(LineComponent.builder()
.left("Lvls Gained: " + AutoChin.lvlsGained)
.build());
panelComponent.getChildren().add(LineComponent.builder()
.left("Running: " + AutoChin.time)
.build());

} catch(Exception ex) {
System.out.println(ex.getMessage());
}
return super.render(graphics);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,37 @@ public static boolean interact(int itemId, String action, int x, int y) {
}
return false;
}

public static boolean exists(String itemName, int range) {
RS2Item[] groundItems = Microbot.getClientThread().runOnClientThread(() -> GroundItem.getAll(range));
for (RS2Item rs2Item : groundItems) {
if (rs2Item.getItem().getName().toLowerCase().equals(itemName.toLowerCase())) {
return true;
}
}
return false;
}

public static boolean exists(int itemId, int range) {
RS2Item[] groundItems = Microbot.getClientThread().runOnClientThread(() -> GroundItem.getAll(range));
for (RS2Item rs2Item : groundItems) {
if (rs2Item.getItem().getId() == itemId) {
return true;
}
}
return false;
}

public static boolean exists(String itemName, int x, int y) {
RS2Item[] itemsAtTile = getAllAt(x, y);
if (itemsAtTile != null) {
for (RS2Item item : itemsAtTile) {
if (item.getItem().getName().equalsIgnoreCase(itemName)) {
return true;
}
}
}
return false;
}

}