Add various new scripts

This commit is contained in:
2022-01-19 12:35:11 +01:00
parent fb86f97efa
commit 78786709eb
84 changed files with 2674 additions and 76 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 Fighter" // This is the name that is used in the external plugin manager panel
project.extra["PluginDescription"] = "Wham! Bam! Thank you Ma'am!" // 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,114 @@
/*
* 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.fighter;
import net.runelite.client.config.*;
@ConfigGroup("chaosfighter")
public interface Config extends net.runelite.client.config.Config {
@ConfigSection(
keyName = "targetConfiguration",
name = "Target Configuration",
description = "Configure target to fight",
position = 0
)
String targetConfiguration = "targetConfiguration";
@ConfigItem(
keyName = "targetNames",
name = "Target names",
description = "The names of your targets, separated with a semicolon.",
section = "targetConfiguration",
position = 1
)
default String targetNames() {
return "";
}
@ConfigItem(
keyName = "targetIds",
name = "Target IDs",
description = "The IDs of your targets, separated with a semicolon.",
section = "targetConfiguration",
position = 2
)
default String targetIds() {
return "";
}
@Range(
min = 1,
max = 64
)
@ConfigItem(
keyName = "searchRadius",
name = "Search radius",
description = "Search radius in which to search the target NPC.",
section = "targetConfiguration",
position = 3
)
default int searchRadius() {
return 20;
}
@ConfigItem(
keyName = "usePathfinding",
name = "Use pathfinding",
description = "Use pathfinding to find nearest target. This is a lot more expensive CPU-wise but is recommended when fighting in an area with obstacles.",
section = "targetConfiguration",
position = 4
)
default boolean usePathfinding() {
return false;
}
@Range(
min = 1,
max = 64
)
@ConfigItem(
keyName = "pathfindingSearchRadius",
name = "Pathfinding search radius",
description = "Search radius in which to search the target NPC using pathfinding. Be careful, setting this too high will freeze the game. If no NPC is found within the pathfinding radius it will fall back to the non-pathfinding radius.",
section = "targetConfiguration",
hidden = true,
unhide = "usePathfinding",
position = 5
)
default int pathfindingSearchRadius() {
return 8;
}
@ConfigItem(
keyName = "startButton",
name = "Start/Stop",
description = "Start the script",
position = 100
)
default Button startButton() {
return new Button();
}
}

View File

@ -0,0 +1,116 @@
package io.reisub.openosrs.fighter;
import com.google.inject.Provides;
import io.reisub.openosrs.util.CScript;
import io.reisub.openosrs.util.Util;
import io.reisub.openosrs.util.tasks.Run;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.NPC;
import net.runelite.api.events.ActorDeath;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.plugins.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.iutils.game.iNPC;
import net.runelite.client.plugins.iutils.iUtils;
import org.pf4j.Extension;
import javax.inject.Inject;
@Extension
@PluginDependency(Util.class)
@PluginDependency(iUtils.class)
@PluginDescriptor(
name = "Chaos Fighter",
description = "Wham! Bam! Thank you Ma'am!",
enabledByDefault = false
)
@Slf4j
public class Fighter extends CScript {
@Inject
@Getter
private Config config;
@Provides
Config provideConfig(ConfigManager configManager) {
return configManager.getConfig(Config.class);
}
@Getter
private String[] targetNames;
@Getter
private int[] targetIds;
@Getter
@Setter
private iNPC currentTarget;
@Override
protected void onStart() {
super.onStart();
parseTargets();
Run runTask = injector.getInstance(Run.class);
runTask.setInterval(70, 95);
tasks.add(runTask);
}
@SuppressWarnings("unused")
@Subscribe
private void onConfigChanged(ConfigChanged event) {
if (!event.getGroup().equals("chaosfighter")) return;
if (event.getKey().equals("targetNames") || event.getKey().equals("targetIds")) {
parseTargets();
}
}
@SuppressWarnings("unused")
@Subscribe
private void onActorDeath(ActorDeath event) {
if (!(event.getActor() instanceof NPC)) return;
NPC actor = (NPC) event.getActor();
if (actor.getIndex() == currentTarget.index()) {
log.info("Our target died");
currentTarget = null;
}
}
private void parseTargets() {
if (!config.targetIds().equals("")) {
String[] rawTargetIds = config.targetIds().split(";");
targetIds = new int[rawTargetIds.length];
int i = 0;
for (String id : rawTargetIds) {
try {
targetIds[i++] = Integer.parseInt(id.trim());
} catch (NumberFormatException e) {
log.error("Error parsing target ID: " + id.trim());
targetIds[i-1] = 0;
}
}
} else {
targetIds = new int[0];
}
if (!config.targetNames().equals("")) {
String[] rawTargetNames = config.targetNames().split(";");
targetNames = new String[rawTargetNames.length];
int i = 0;
for (String name : rawTargetNames) {
targetNames[i++] = name.trim();
}
} else {
targetNames = new String[0];
}
}
}

View File

@ -0,0 +1,48 @@
package io.reisub.openosrs.fighter.tasks;
import io.reisub.openosrs.fighter.Fighter;
import io.reisub.openosrs.util.Task;
import io.reisub.openosrs.util.enums.Activity;
import net.runelite.client.plugins.iutils.actor.NpcStream;
import net.runelite.client.plugins.iutils.game.iNPC;
import javax.inject.Inject;
import java.util.stream.Stream;
public class Fight extends Task {
@Inject
private Fighter plugin;
@Override
public String getStatus() {
return "Fighting";
}
@Override
public boolean validate() {
if (plugin.getCurrentActivity() != Activity.IDLE) return false;
NpcStream idStream = game.npcs().withId(plugin.getTargetIds()).withoutTarget();
NpcStream nameStream = game.npcs().withName(plugin.getTargetNames()).withoutTarget();
NpcStream targetStream = (NpcStream) Stream.concat(idStream, nameStream);
if (plugin.getConfig().usePathfinding()) {
plugin.setCurrentTarget(targetStream.within(plugin.getConfig().pathfindingSearchRadius()).nearestPath());
}
if (plugin.getCurrentActivity() == null) {
plugin.setCurrentTarget(targetStream.within(plugin.getConfig().searchRadius()).nearest());
}
return plugin.getCurrentTarget() != null;
}
@Override
public void execute() {
if (plugin.getCurrentTarget() == null) return;
plugin.getCurrentTarget().interact(0);
game.waitUntil(() -> game.localPlayer().target() != null && game.localPlayer().target().name().equals(plugin.getCurrentTarget().name()), 15);
}
}