Add CShopper

This commit is contained in:
Yuri Moens 2021-10-18 20:44:46 +02:00
parent fac5c7e696
commit f9d49d820b
Signed by: ymo
GPG Key ID: F6D51D6FE15BE924
10 changed files with 232 additions and 0 deletions

9
.idea/artifacts/CShopper_jar.xml generated Normal file
View File

@ -0,0 +1,9 @@
<component name="ArtifactManager">
<artifact type="jar" name="CShopper:jar">
<output-path>$USER_HOME$/DreamBot/Scripts</output-path>
<root id="archive" name="CShopper.jar">
<element id="module-output" name="CShopper" />
<element id="module-output" name="Util" />
</root>
</artifact>
</component>

1
.idea/modules.xml generated
View File

@ -6,6 +6,7 @@
<module fileurl="file://$PROJECT_DIR$/CBlackjack/CBlackjack.iml" filepath="$PROJECT_DIR$/CBlackjack/CBlackjack.iml" />
<module fileurl="file://$PROJECT_DIR$/CDebug/CDebug.iml" filepath="$PROJECT_DIR$/CDebug/CDebug.iml" />
<module fileurl="file://$PROJECT_DIR$/CFisher/CFisher.iml" filepath="$PROJECT_DIR$/CFisher/CFisher.iml" />
<module fileurl="file://$PROJECT_DIR$/CShopper/CShopper.iml" filepath="$PROJECT_DIR$/CShopper/CShopper.iml" />
<module fileurl="file://$PROJECT_DIR$/CWintertodt/CWintertodt.iml" filepath="$PROJECT_DIR$/CWintertodt/CWintertodt.iml" />
<module fileurl="file://$PROJECT_DIR$/DreambotScripts.iml" filepath="$PROJECT_DIR$/DreambotScripts.iml" />
<module fileurl="file://$PROJECT_DIR$/Util/Util.iml" filepath="$PROJECT_DIR$/Util/Util.iml" />

13
CShopper/CShopper.iml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="client" level="project" />
<orderEntry type="module" module-name="Util" />
</component>
</module>

View File

@ -0,0 +1,24 @@
package io.reisub.dreambot.cshopper;
import io.reisub.dreambot.util.Constants;
import org.dreambot.api.script.Category;
import org.dreambot.api.script.ScriptManifest;
import org.dreambot.api.script.impl.TaskScript;
@SuppressWarnings("unused")
@ScriptManifest(category = Category.MISC, name = "CShopper", description = "Shops like a woman with an unlimited Visa card", author = Constants.AUTHOR, version = 1.0)
public class CShopper extends TaskScript {
private static final Configuration configuration = new Configuration(
Constants.LUNDAIL,
new ItemWrapper(Constants.NATURE_RUNE, 6000),
new ItemWrapper(Constants.COSMIC_RUNE, -1)
);
public static Configuration getConfiguration() {
return configuration;
}
@Override
public void onStart() {
}
}

View File

@ -0,0 +1,19 @@
package io.reisub.dreambot.cshopper;
public class Configuration {
private final String traderName;
private final ItemWrapper[] items;
public Configuration(String traderName, ItemWrapper... items) {
this.traderName = traderName;
this.items = items;
}
public String getTraderName() {
return traderName;
}
public ItemWrapper[] getItems() {
return items;
}
}

View File

@ -0,0 +1,28 @@
package io.reisub.dreambot.cshopper;
public class ItemWrapper {
private final String name;
private final int buyTotal, minimumInShop;
public ItemWrapper(String name, int buyTotal, int minimumInShop) {
this.name = name;
this.buyTotal = buyTotal;
this.minimumInShop = minimumInShop;
}
public ItemWrapper(String name, int buyTotal) {
this(name, buyTotal, 0);
}
public String getName() {
return name;
}
public int getBuyTotal() {
return buyTotal;
}
public int getMinimumInShop() {
return minimumInShop;
}
}

View File

@ -0,0 +1,46 @@
package io.reisub.dreambot.cshopper.tasks;
import io.reisub.dreambot.cshopper.CShopper;
import io.reisub.dreambot.cshopper.ItemWrapper;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.container.impl.Shop;
import org.dreambot.api.script.TaskNode;
public class Buy extends TaskNode {
@Override
public boolean accept() {
if (!Shop.isOpen()) return false;
for (ItemWrapper iw : CShopper.getConfiguration().getItems()) {
int shopCount = Shop.get(iw.getName()).getAmount();
int inventoryCount = 0;
if (Inventory.get(iw.getName()) != null) {
inventoryCount = Inventory.get(iw.getName()).getAmount();
}
if (shopCount > iw.getMinimumInShop() && inventoryCount < iw.getBuyTotal()) return true;
}
return false;
}
@Override
public int execute() {
for (ItemWrapper iw : CShopper.getConfiguration().getItems()) {
int shopCount = Shop.get(iw.getName()).getAmount();
int inventoryCount = 0;
if (Inventory.get(iw.getName()) != null) {
inventoryCount = Inventory.get(iw.getName()).getAmount();
}
if (shopCount > iw.getMinimumInShop() && inventoryCount < iw.getBuyTotal()) {
int toBuy = shopCount - iw.getMinimumInShop();
// TODO finish while testing at shop
}
}
return 0;
}
}

View File

@ -0,0 +1,59 @@
package io.reisub.dreambot.cshopper.tasks;
import io.reisub.dreambot.cshopper.CShopper;
import io.reisub.dreambot.cshopper.ItemWrapper;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.container.impl.Shop;
import org.dreambot.api.methods.world.World;
import org.dreambot.api.methods.world.Worlds;
import org.dreambot.api.methods.worldhopper.WorldHopper;
import org.dreambot.api.script.TaskNode;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
public class Hop extends TaskNode {
private final Queue<World> worlds;
public Hop(boolean members) {
List<World> worldsList = Worlds.all(world -> world.isMembers() == members && world.isNormal() && !world.isHighRisk() && !world.isPVP());
worlds = new LinkedList<>(worldsList);
}
public Hop() {
this(true);
}
@Override
public boolean accept() {
if (!Shop.isOpen()) return false;
for (ItemWrapper iw : CShopper.getConfiguration().getItems()) {
int shopCount = Shop.get(iw.getName()).getAmount();
int inventoryCount = 0;
if (Inventory.get(iw.getName()) != null) {
inventoryCount = Inventory.get(iw.getName()).getAmount();
}
if (shopCount > iw.getMinimumInShop() && inventoryCount < iw.getBuyTotal()) return false;
}
return true;
}
@Override
public int execute() {
World world = worlds.poll();
worlds.add(world);
if (world != null) {
WorldHopper.hopWorld(world);
}
return Calculations.random(200, 400);
}
}

View File

@ -0,0 +1,29 @@
package io.reisub.dreambot.cshopper.tasks;
import io.reisub.dreambot.cshopper.CShopper;
import io.reisub.dreambot.util.Constants;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.MethodContext;
import org.dreambot.api.methods.container.impl.Shop;
import org.dreambot.api.methods.interactive.NPCs;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.interactive.NPC;
public class Open extends TaskNode {
@Override
public boolean accept() {
return !Shop.isOpen();
}
@Override
public int execute() {
NPC trader = NPCs.closest(CShopper.getConfiguration().getTraderName());
if (trader == null) return 0;
trader.interact(Constants.TRADE);
MethodContext.sleepUntil(Shop::isOpen, Calculations.random(6000, 7000));
return Calculations.random(200, 400);
}
}

View File

@ -49,6 +49,9 @@ public class Constants {
public static final String BRAZIER = "Brazier";
public static final String BURNING_BRAZIER = "Burning brazier";
public static final String MARK_OF_GRACE = "Mark of grace";
public static final String LUNDAIL = "Lundail";
public static final String COSMIC_RUNE = "Cosmic rune";
public static final String NATURE_RUNE = "Nature rune";
// Actions
public static final String USE = "Use";
@ -61,6 +64,7 @@ public class Constants {
public static final String DRINK = "Drink";
public static final String LIGHT = "Light";
public static final String FIX = "Fix";
public static final String TRADE = "Trade";
// Messages
public static final String KITTEN_WANTS_ATTENTION_MSG = "Your kitten wants attention.";