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

52
cooker/cooker.gradle.kts Normal file
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 = "0.0.1"
project.extra["PluginName"] = "Chaos Cooker" // This is the name that is used in the external plugin manager panel
project.extra["PluginDescription"] = "Cooks better than Gordon Ramsay" // 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.cooker;
public enum Activity {
IDLE,
COOKING;
}

View File

@ -0,0 +1,53 @@
/*
* 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.cooker;
import net.runelite.client.config.Button;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("ChaosCookerConfig")
public interface Config extends net.runelite.client.config.Config {
@ConfigItem(
keyName = "rawFood",
name = "Food ID",
description = "ID of the raw food to cook.",
position = 1
)
default int rawFood() {
return 361;
}
@ConfigItem(
keyName = "startButton",
name = "Start/Stop",
description = "Start the script",
position = 100
)
default Button startButton() {
return new Button();
}
}

View File

@ -0,0 +1,159 @@
package io.reisub.openosrs.cooker;
import com.google.inject.Provides;
import io.reisub.openosrs.cooker.tasks.Cook;
import io.reisub.openosrs.cooker.tasks.HandleBank;
import io.reisub.openosrs.cooker.tasks.SkipLevel;
import io.reisub.openosrs.util.Task;
import io.reisub.openosrs.util.Util;
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.api.events.ItemContainerChanged;
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 javax.inject.Inject;
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 Cooker",
description = "Cooks better than Gordon Ramsay",
enabledByDefault = false
)
@Slf4j
public class Cooker extends iScript {
private List<Task> tasks;
@Getter
private Activity currentActivity;
private Instant lastActionTime;
@Inject
private Config config;
@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 Cooker");
Run runTask = injector.getInstance(Run.class);
runTask.setInterval(70, 95);
tasks = new ArrayList<>();
tasks.add(runTask);
tasks.add(injector.getInstance(SkipLevel.class));
tasks.add(injector.getInstance(HandleBank.class));
tasks.add(injector.getInstance(Cook.class));
}
@Override
protected void onStop() {
log.info("Stopping Chaos Cooker");
if (tasks != null) {
tasks.clear();
}
setActivity(Activity.IDLE);
}
@SuppressWarnings("unused")
@Subscribe
private void onConfigButtonPressed(ConfigButtonClicked configButtonClicked) {
if (configButtonClicked.getKey().equals("startButton")) {
execute();
}
}
@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.COOKING_FIRE:
case AnimationID.COOKING_RANGE:
setActivity(Activity.COOKING);
}
}
@SuppressWarnings("unused")
@Subscribe
private void onItemContainerChanged(ItemContainerChanged event) {
if (!game.inventory().withId(config.rawFood()).exists()) {
setActivity(Activity.IDLE);
}
}
@SuppressWarnings("unused")
@Subscribe
private void onChatMessage(ChatMessage 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(3);
Duration sinceAction = Duration.between(lastActionTime, Instant.now());
if (sinceAction.compareTo(timeout) >= 0) {
setActivity(Activity.IDLE);
}
}
}

View File

@ -0,0 +1,58 @@
package io.reisub.openosrs.cooker.tasks;
import io.reisub.openosrs.cooker.Activity;
import io.reisub.openosrs.cooker.Config;
import io.reisub.openosrs.cooker.Cooker;
import io.reisub.openosrs.util.Task;
import net.runelite.client.plugins.iutils.game.InventoryItem;
import net.runelite.client.plugins.iutils.game.iObject;
import net.runelite.client.plugins.iutils.ui.Chatbox;
import javax.inject.Inject;
public class Cook extends Task {
@Inject
private Cooker plugin;
@Inject
private Config config;
@Override
public String getStatus() {
return "Cooking";
}
@Override
public boolean validate() {
return plugin.getCurrentActivity() == Activity.IDLE
&& game.inventory().withId(config.rawFood()).exists();
}
@Override
public void execute() {
iObject oven = game.objects().withName("Clay oven").nearest();
iObject fire = game.objects().withName("Fire").nearest();
if (oven == null && fire == null) return;
if (oven != null) {
oven.interact(0);
} else {
InventoryItem rawFood = game.inventory().withId(config.rawFood()).first();
if (rawFood == null) return;
rawFood.useOn(fire);
}
game.waitUntil(() -> chatbox.chatState() == Chatbox.ChatState.MAKE, 20);
if (chatbox.chatState() == Chatbox.ChatState.MAKE) {
if (calc.random(0, 4) == 1) {
game.sleepDelay();
}
int count = (int) game.inventory().withId(config.rawFood()).count();
chatbox.make(0, count);
game.waitUntil(() -> plugin.getCurrentActivity() == Activity.COOKING, 5);
}
}
}

View File

@ -0,0 +1,56 @@
package io.reisub.openosrs.cooker.tasks;
import io.reisub.openosrs.cooker.Config;
import io.reisub.openosrs.util.Task;
import net.runelite.api.ItemID;
import net.runelite.client.plugins.iutils.game.iNPC;
import net.runelite.client.plugins.iutils.game.iObject;
import javax.inject.Inject;
public class HandleBank extends Task {
@Inject
private Config config;
@Override
public String getStatus() {
return "Banking";
}
@Override
public boolean validate() {
return !game.inventory().withId(config.rawFood()).exists();
}
@Override
public void execute() {
if (!bank.isOpen()) {
iNPC banker = game.npcs().withName("Emerald Benedict").first();
iObject bankObj = game.objects().withName("Bank chest", "Bank booth").nearest();;
if (banker == null && bankObj == null) return;
if (banker != null) {
banker.interact("Bank");
} else {
bankObj.interact(0);
}
game.waitUntil(() -> bank.isOpen(), 20);
}
if (game.inventory().findAny().isPresent()) {
bank.depositInventory();
game.tick();
game.sleepDelay();
}
if (config.rawFood() == ItemID.GIANT_SEAWEED) {
bank.withdraw(config.rawFood(), 4, false);
} else {
bank.withdraw(config.rawFood(), 28, false);
}
game.sleepDelay();
bank.close();
game.sleepDelay();
}
}

View File

@ -0,0 +1,22 @@
package io.reisub.openosrs.cooker.tasks;
import io.reisub.openosrs.util.Task;
import net.runelite.client.plugins.iutils.ui.Chatbox;
public class SkipLevel extends Task {
@Override
public String getStatus() {
return "Skipping level chatbox";
}
@Override
public boolean validate() {
return chatbox.chatState() == Chatbox.ChatState.LEVEL_UP;
}
@Override
public void execute() {
chatbox.continueChats();
game.tick();
}
}