Initial commit

This commit is contained in:
2022-01-08 19:46:18 +01:00
commit 57ba5a5858
207 changed files with 12402 additions and 0 deletions

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2019 Owain van Brakel <https://github.com/Owain94>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
version = "1.0.0"
project.extra["PluginName"] = "Chaos Smelter" // This is the name that is used in the external plugin manager panel
project.extra["PluginDescription"] = "Hot stuff" // This is the description that is used in the external plugin manager panel
dependencies {
compileOnly(project(":util"))
}
tasks {
jar {
manifest {
attributes(mapOf(
"Plugin-Version" to project.version,
"Plugin-Id" to nameToId(project.extra["PluginName"] as String),
"Plugin-Provider" to project.extra["PluginProvider"],
"Plugin-Description" to project.extra["PluginDescription"],
"Plugin-Dependencies" to
arrayOf(
nameToId("Chaos Util"),
nameToId("iUtils")
).joinToString(),
"Plugin-License" to project.extra["PluginLicense"]
))
}
}
}

View File

@ -0,0 +1,6 @@
package io.reisub.openosrs.smelter;
public enum Activity {
IDLE,
SMELTING;
}

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2018, Andrew EP | ElPinche256 <https://github.com/ElPinche256>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.reisub.openosrs.smelter;
import net.runelite.client.config.Button;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("ChaosSmelterConfig")
public interface Config extends net.runelite.client.config.Config {
@ConfigItem(
keyName = "targetProduct",
name = "Smelt",
description = "Choose what to smelt.",
position = 0
)
default Product targetProduct() { return Product.MOLTEN_GLASS; }
@ConfigItem(
keyName = "startButton",
name = "Start/Stop",
description = "Start the script",
position = 100
)
default Button startButton() {
return new Button();
}
}

View File

@ -0,0 +1,11 @@
package io.reisub.openosrs.smelter;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public class Ingredient {
private final int id;
private final int amount;
}

View File

@ -0,0 +1,18 @@
package io.reisub.openosrs.smelter;
import lombok.Getter;
import net.runelite.api.ItemID;
@Getter
public enum Product {
MOLTEN_GLASS(ItemID.MOLTEN_GLASS, new Ingredient(ItemID.SODA_ASH, 14), new Ingredient(ItemID.BUCKET_OF_SAND, 14)),
CANNONBALLS(ItemID.CANNONBALL, new Ingredient(ItemID.STEEL_BAR, 27));
private final int id;
private final Ingredient[] ingredients;
Product(int id, Ingredient... ingredients) {
this.id = id;
this.ingredients = ingredients;
}
}

View File

@ -0,0 +1,161 @@
package io.reisub.openosrs.smelter;
import com.google.inject.Provides;
import io.reisub.openosrs.smelter.tasks.HandleBank;
import io.reisub.openosrs.smelter.tasks.Smelt;
import io.reisub.openosrs.util.Task;
import io.reisub.openosrs.util.Util;
import io.reisub.openosrs.util.tasks.Eat;
import io.reisub.openosrs.util.tasks.KittenTask;
import io.reisub.openosrs.util.tasks.Run;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.AnimationID;
import net.runelite.api.ChatMessageType;
import net.runelite.api.GameState;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigButtonClicked;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.iutils.iUtils;
import net.runelite.client.plugins.iutils.scripts.iScript;
import org.pf4j.Extension;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import static net.runelite.api.AnimationID.IDLE;
@Extension
@PluginDependency(Util.class)
@PluginDependency(iUtils.class)
@PluginDescriptor(
name = "Chaos Smelter",
description = "Hot stuff",
enabledByDefault = false
)
@Slf4j
public class Smelter extends iScript {
private List<Task> tasks;
private KittenTask kittenTask;
@Getter
private Activity currentActivity;
private Instant lastActionTime;
@Provides
Config provideConfig(ConfigManager configManager) {
return configManager.getConfig(Config.class);
}
@Override
protected void loop() {
for (Task t : tasks) {
if (t.validate()) {
log.info(t.getStatus());
t.execute();
break;
}
}
checkActionTimeout();
game.sleepDelay();
}
@Override
protected void onStart() {
log.info("Starting Chaos Smelter");
Eat eatTask = injector.getInstance(Eat.class);
eatTask.setInterval(14, 24);
Run runTask = injector.getInstance(Run.class);
runTask.setInterval(70, 95);
kittenTask = KittenTask.getInstance(injector);
currentActivity = Activity.IDLE;
tasks = new ArrayList<>();
tasks.add(eatTask);
tasks.add(runTask);
tasks.add(kittenTask);
tasks.add(injector.getInstance(HandleBank.class));
tasks.add(injector.getInstance(Smelt.class));
}
@Override
protected void onStop() {
log.info("Stopping Chaos Smelter");
if (tasks != null) {
tasks.clear();
}
KittenTask.handleKitten = false;
}
@SuppressWarnings("unused")
@Subscribe
private void onAnimationChanged(AnimationChanged event) {
if (game.client().getGameState() != GameState.LOGGED_IN) return;
if (event.getActor() != game.client().getLocalPlayer()) return;
int animId = game.localPlayer().animation();
switch (animId) {
case AnimationID.SMITHING_SMELTING:
case AnimationID.SMITHING_CANNONBALL:
setActivity(Activity.SMELTING);
break;
}
}
@Subscribe
private void onConfigButtonPressed(ConfigButtonClicked configButtonClicked) {
if (configButtonClicked.getKey().equals("startButton")) {
execute();
}
}
@Subscribe
private void onChatMessage(ChatMessage chatMessage) {
if (kittenTask != null) {
kittenTask.onChatMessage(chatMessage);
}
if (chatMessage.getType() == ChatMessageType.GAMEMESSAGE) {
if (chatMessage.getMessage().startsWith("Congratulations, you've just advanced your")) {
setActivity(Activity.IDLE);
}
}
}
private void setActivity(Activity action) {
currentActivity = action;
if (action != Activity.IDLE) {
lastActionTime = Instant.now();
}
}
private void checkActionTimeout() {
if (currentActivity == Activity.IDLE) return;
int animId = game.localPlayer().animation();
if (animId != IDLE || lastActionTime == null) return;
Duration timeout = Duration.ofSeconds(5);
Duration sinceAction = Duration.between(lastActionTime, Instant.now());
if (sinceAction.compareTo(timeout) >= 0) {
setActivity(Activity.IDLE);
}
}
}

View File

@ -0,0 +1,67 @@
package io.reisub.openosrs.smelter.tasks;
import io.reisub.openosrs.smelter.Config;
import io.reisub.openosrs.smelter.Ingredient;
import io.reisub.openosrs.smelter.Product;
import io.reisub.openosrs.util.Task;
import net.runelite.api.ItemID;
import net.runelite.client.plugins.iutils.game.iObject;
import javax.inject.Inject;
import java.time.Duration;
import java.time.Instant;
public class HandleBank extends Task {
@Inject
private Config config;
private Instant lastBanking = Instant.EPOCH;
@Override
public String getStatus() {
return "Banking";
}
@Override
public boolean validate() {
boolean hasAllIngredients = true;
for (Ingredient ingredient : config.targetProduct().getIngredients()) {
if (!game.inventory().withId(ingredient.getId()).exists()) {
hasAllIngredients = false;
}
}
return !hasAllIngredients
&& game.localPlayer().isIdle()
&& Duration.between(lastBanking, Instant.now()).getSeconds() > 5;
}
@Override
public void execute() {
if (!bank.isOpen()) {
iObject bankObj = game.objects().withName("Bank booth").nearest();
if (bankObj == null) return;
bankObj.interact("Bank");
game.waitUntil(() -> bank.isOpen(), 15);
}
if (config.targetProduct() == Product.CANNONBALLS) {
bank.depositExcept(false, ItemID.AMMO_MOULD);
} else {
bank.depositInventory();
}
game.tick();
game.sleepDelay();
for (Ingredient ingredient : config.targetProduct().getIngredients()) {
bank.withdraw(ingredient.getId(), ingredient.getAmount(), false);
game.sleepDelay();
}
bank.close();
game.sleepDelay();
lastBanking = Instant.now();
}
}

View File

@ -0,0 +1,58 @@
package io.reisub.openosrs.smelter.tasks;
import io.reisub.openosrs.smelter.Activity;
import io.reisub.openosrs.smelter.Config;
import io.reisub.openosrs.smelter.Ingredient;
import io.reisub.openosrs.smelter.Smelter;
import io.reisub.openosrs.util.Task;
import net.runelite.client.plugins.iutils.game.iObject;
import net.runelite.client.plugins.iutils.ui.Chatbox;
import javax.inject.Inject;
public class Smelt extends Task {
@Inject
private Smelter plugin;
@Inject
private Config config;
@Override
public String getStatus() {
return "Smelting";
}
@Override
public boolean validate() {
boolean hasAllIngredients = true;
for (Ingredient ingredient : config.targetProduct().getIngredients()) {
if (!game.inventory().withId(ingredient.getId()).exists()) {
hasAllIngredients = false;
}
}
return hasAllIngredients && plugin.getCurrentActivity() == Activity.IDLE;
}
@Override
public void execute() {
iObject furnace = game.objects().withName("Furnace").nearest();
if (furnace == null) return;
furnace.interact("Smelt");
game.waitUntil(() -> chatbox.chatState() == Chatbox.ChatState.MAKE, 15);
int quantity = 28;
for (Ingredient ingredient : config.targetProduct().getIngredients()) {
int count = (int) game.inventory().withId(ingredient.getId()).count();
if (quantity > count) {
quantity = count;
}
}
chatbox.make(0, quantity);
game.waitUntil(() -> plugin.getCurrentActivity() == Activity.SMELTING, 5);
}
}