Skip to content

Commit

Permalink
Fake entities API
Browse files Browse the repository at this point in the history
Plugin class loader changes
Implemented cross-application interface
Implemented dropdown list for configs over ConfigAPI
Config API changes
  • Loading branch information
m9w committed Dec 11, 2023
1 parent 74b3bf0 commit 2deab68
Show file tree
Hide file tree
Showing 13 changed files with 465 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ publishing {
}

dependencies {
val apiVersion = "0.8.3"
val apiVersion = "0.8.4"
val flatLafVersion = "3.1.1"

// use this if you want to use local(mavenLocal) darkbot API
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/github/manolo8/darkbot/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,11 @@ public static class Performance {

public @Option @Visibility(Level.INTERMEDIATE) Other OTHER = new Other();
public static class Other {
public @Option boolean SHOW_INSTRUCTIONS = true;
public @Option boolean DISABLE_MASTER_PASSWORD = false;
public @Option @Number(min = 10, max = 300) int ZONE_RESOLUTION = 30;
public @Option @Visibility(Level.ADVANCED) boolean DEV_STUFF = false;
public @Option @Visibility(Level.ADVANCED) String CROSS_APP_EVENTS_ROUTER_ADDRESS;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.manolo8.darkbot.config;

import com.github.manolo8.darkbot.Main;
import com.github.manolo8.darkbot.config.tree.ConfigBuilder;
import com.github.manolo8.darkbot.core.utils.Lazy;
import com.github.manolo8.darkbot.extensions.features.FeatureDefinition;
import com.github.manolo8.darkbot.extensions.features.FeatureRegistry;
import com.github.manolo8.darkbot.utils.ReflectionUtils;
Expand All @@ -15,7 +17,10 @@
import eu.darkbot.api.utils.Inject;

import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ConfigHandler implements ConfigAPI, Listener {

Expand All @@ -25,15 +30,18 @@ public class ConfigHandler implements ConfigAPI, Listener {
private final ConfigBuilder builder;

private final ConfigSetting.Parent<Config> configuration;
private final Lazy.Sync<String> configChange;

public ConfigHandler(PluginAPI api,
ConfigManager loader,
ConfigBuilder builder) {
ConfigBuilder builder,
Main main) {
this.pluginAPI = api;
this.loader = loader;
this.builder = builder;
this.configuration = builder.of(Config.class, "Configuration", null);
this.configuration.setValue(loader.getConfig());
this.configChange = main.configChange;
}

@Inject
Expand Down Expand Up @@ -120,4 +128,13 @@ public void onPluginUnload(ExtensionsAPI.PluginLifetimeEvent e) {
}
}

@Override
public Collection<String> options() {
return Stream.concat(Stream.of("(none)"), loader.getAvailableConfigs().stream()).collect(Collectors.toList());
}

public void changeConfig(String config) {
if (loader.getAvailableConfigs().contains(config))
configChange.send(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static DropdownHandler of(Field field, PluginInfo namespace, PluginAPI ap

Class<? extends Dropdown.Options<?>> optionCl = dropdown.options();
LazyValue<Dropdown.Options<?>> options = optionCl != Dropdown.NullOptions.class ?
LazyValue.of(() -> api.requireInstance(optionCl)) :
LazyValue.of(() -> optionCl.isInterface() ? api.requireAPI(optionCl) : api.requireInstance(optionCl)) :
LazyValue.resolved(optionsOf(api, namespace, field.getGenericType()));

return new DropdownHandler(field, dropdown.multi(), options);
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/com/github/manolo8/darkbot/core/entities/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.github.manolo8.darkbot.config.BoxInfo;
import com.github.manolo8.darkbot.config.ConfigEntity;
import com.github.manolo8.darkbot.core.api.Capability;
import com.github.manolo8.darkbot.core.manager.HeroManager;
import com.github.manolo8.darkbot.utils.Offsets;
import eu.darkbot.api.game.other.Location;
import eu.darkbot.util.Timer;
import org.jetbrains.annotations.Nullable;

Expand All @@ -26,6 +28,10 @@ public class Box extends Entity implements eu.darkbot.api.game.entities.Box {
public BoxInfo boxInfo;


private Box(int id) {
super(id);
}

public Box(int id, long address) {
super(id);
this.update(address);
Expand Down Expand Up @@ -135,4 +141,61 @@ public Beacon(int id, long address) {
super(id, address);
}
}

public static class FakeBox extends Box implements eu.darkbot.api.game.entities.FakeEntity.FakeBox {
private Timer timeout;
private long removeDistance;
private boolean isRemoveWhenAttemptSelect;

public FakeBox(String boxName, Location loc, long removeDistance, long keepAlive, boolean isRemoveWhenAttemptSelect) {
super(Integer.MIN_VALUE);
super.locationInfo.updatePosition(loc.x(), loc.y());
super.main = HeroManager.instance.main;
super.address = -1;
super.type = boxName;
super.boxInfo = ConfigEntity.INSTANCE.getOrCreateBoxInfo(type);
super.removed = false;
setRemoveDistance(removeDistance);
setTimeout(keepAlive);
setRemoveWhenAttemptSelect(isRemoveWhenAttemptSelect);
}

public void setTimeout(long keepAlive) {
if (keepAlive != -1) {
timeout = Timer.get(keepAlive);
timeout.activate();
}
else timeout = null;
}

public void setRemoveDistance(long removeDistance) {
this.removeDistance = removeDistance;
}

public void setRemoveWhenAttemptSelect(boolean removeWhenAttemptSelect) {
isRemoveWhenAttemptSelect = removeWhenAttemptSelect;
}

public String getHash() {
return type + locationInfo.getCurrent();
}

public boolean tryCollect() {
return trySelect(false);
}

public boolean isInvalid(long mapAddress) {
if (timeout != null && timeout.isInactive()) return false;
return HeroManager.instance.distanceTo(this) < removeDistance;
}

public boolean trySelect(boolean tryAttack) {
if (isRemoveWhenAttemptSelect) removed();
return false;
}

public void update() {}

public void update(long address) {}
}
}
45 changes: 45 additions & 0 deletions src/main/java/com/github/manolo8/darkbot/core/entities/Mine.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.github.manolo8.darkbot.core.entities;

import com.github.manolo8.darkbot.core.itf.Obstacle;
import com.github.manolo8.darkbot.core.manager.HeroManager;
import com.github.manolo8.darkbot.core.utils.pathfinder.AreaImpl;
import com.github.manolo8.darkbot.core.utils.pathfinder.CircleImpl;
import eu.darkbot.api.game.other.Location;
import eu.darkbot.util.Timer;

import static com.github.manolo8.darkbot.Main.API;

Expand All @@ -14,6 +17,10 @@ public class Mine extends Entity implements Obstacle, eu.darkbot.api.game.entiti

private final CircleImpl area = new CircleImpl(0, 0, 200);

private Mine(int id) {
super(id);
}

public Mine(int id, long address) {
super(id);
this.update(address);
Expand Down Expand Up @@ -58,4 +65,42 @@ public String toString() {
public int getTypeId() {
return typeId;
}

public static class FakeMine extends Mine implements eu.darkbot.api.game.entities.FakeEntity.FakeMine {
private Timer timeout;
private long removeDistance;

public FakeMine(int typeId, Location loc, long removeDistance, long keepAlive) {
super(Integer.MIN_VALUE);
super.locationInfo.updatePosition(loc.x(), loc.y());
super.main = HeroManager.instance.main;
super.address = -1;
super.typeId = typeId;
super.area.set(locationInfo.now, typeId == FROZEN_LAB_MINE ? 500 : 200);
super.removed = false;
setTimeout(keepAlive);
setRemoveDistance(removeDistance);
}

public void setTimeout(long keepAlive) {
if (keepAlive != -1) {
timeout = Timer.get(keepAlive);
timeout.activate();
}
else timeout = null;
}

public void setRemoveDistance(long removeDistance) {
this.removeDistance = removeDistance;
}

public boolean isInvalid(long mapAddress) {
if (timeout != null && timeout.isInactive()) return true;
return removeDistance == -1 || HeroManager.instance.distanceTo(this) < removeDistance;
}

public void update() {}

public void update(long address) {}
}
}
Loading

0 comments on commit 2deab68

Please sign in to comment.