Skip to content

Commit

Permalink
Diminish quest facade
Browse files Browse the repository at this point in the history
  • Loading branch information
m9w committed Mar 10, 2024
1 parent 18543f0 commit 0525d8c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public long getAddress() {
return address;
}

public boolean isValid() {
return address == 0;
}

/**
* Updatable which automatically calls update() after an address change.
* Unless you want different logic in address updates and normal updates, you should use this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.github.manolo8.darkbot.core.objects.facades.BoosterProxy;
import com.github.manolo8.darkbot.core.objects.facades.ChatProxy;
import com.github.manolo8.darkbot.core.objects.facades.ChrominProxy;
import com.github.manolo8.darkbot.core.objects.facades.DiminishQuestMediator;
import com.github.manolo8.darkbot.core.objects.facades.DispatchGateProxy;
import com.github.manolo8.darkbot.core.objects.facades.DispatchProxy;
import com.github.manolo8.darkbot.core.objects.facades.DispatchRetrieverProxy;
Expand Down Expand Up @@ -94,6 +95,7 @@ public FacadeManager(PluginAPI pluginApi) {
registerMediator("AssemblyWindowMediator", AssemblyMediator.class);
registerProxy("InventoryProxy", InventoryProxy.class);
registerProxy("QuestProxy", QuestProxy.class);
registerMediator("diminish_quests", DiminishQuestMediator.class);

npcEvents.put(EventType.GENERIC, this.npcEventProxy = registerProxy("npc_event", NpcEventProxy.class));
npcEvents.put(EventType.AGATUS, registerProxy("agatus_event", NpcEventProxy.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.github.manolo8.darkbot.core.objects.facades.SlotBarsProxy;
import com.github.manolo8.darkbot.core.objects.facades.StatsProxy;
import com.github.manolo8.darkbot.core.objects.gui.ChatGui;
import com.github.manolo8.darkbot.core.objects.gui.DiminishQuestGui;
import com.github.manolo8.darkbot.core.objects.gui.DispatchIconGui;
import com.github.manolo8.darkbot.core.objects.gui.DispatchIconOkGui;
import com.github.manolo8.darkbot.core.objects.gui.DispatchPopupRewardGui;
Expand Down Expand Up @@ -153,6 +154,8 @@ public GuiManager(Main main, PluginAPI pluginAPI, RepairManager repairManager) {
this.assembly = register("assembly");

register("ggBuilder", GateSpinnerGui.class);
register("diminish_quests", DiminishQuestGui.class);
register("refinement_count");

this.commandCenter = register("command_center");

Expand All @@ -164,7 +167,7 @@ private Gui register(String key) {
}

private <T extends Gui> T register(String key, Class<T> gui) {
return (T) guis.putUpdatable(key, pluginAPI.requireInstance(gui));
return guis.putUpdatable(key, pluginAPI.requireInstance(gui));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.github.manolo8.darkbot.core.objects.facades;

import com.github.manolo8.darkbot.core.itf.Updatable;
import com.github.manolo8.darkbot.core.objects.gui.DiminishQuestGui;
import eu.darkbot.api.API;
import eu.darkbot.api.managers.QuestAPI;

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

public class DiminishQuestMediator extends Updatable implements API.Singleton {
private State state = State.NOT_EXIST;
private final DiminishQuestGui diminishQuestGui;
private final QuestProxy.Quest diminishQuest = new QuestProxy.Quest();
private static final State[] STATES = State.values();

public DiminishQuestMediator(DiminishQuestGui diminishQuestGui) {
this.diminishQuestGui = diminishQuestGui;
}

@Override
public void update() {
if (!isValid()) return;
int stateIndex = API.readInt(address, 0x50, 0x40) + 1;
if (stateIndex >= 0 && stateIndex < STATES.length) {
state = STATES[stateIndex];
diminishQuest.update(API.readAtom(address, 0x50, 0x60));
} else {
state = State.NOT_EXIST;
}
}

public QuestAPI.Quest getDiminishQuest() {
return diminishQuest;
}

public boolean isWaitAccepting() {
return isValid() && State.WAIT_ACCEPTING.equals(state);
}

public boolean isAccepted() {
return isValid() && State.ACCEPTED.equals(state);
}

public void accept() {
diminishQuestGui.accept();
}

private enum State {
NOT_EXIST,
WAIT_ACCEPTING,
UNKNOWN,
ACCEPTED,
DONE,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.manolo8.darkbot.core.objects.gui;

import eu.darkbot.api.API;

public class DiminishQuestGui extends SizableGui implements API.Singleton {
public void accept() {
if (address == 0) return;
if (show(true)) click((int) getWidth()/2, (int) getHeight()-10);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.github.manolo8.darkbot.core.objects.gui;

import com.github.manolo8.darkbot.Main;
import com.github.manolo8.darkbot.core.objects.Gui;
import eu.darkbot.api.API;

class PopupGui extends Gui implements API.Singleton {
class PopupGui extends SizableGui implements API.Singleton {
@Override
public void update() {
if (address == 0) return;
super.update();
width = (int) Main.API.readDouble(address + 0x1F8);
height = (int) Main.API.readDouble(address + 0x200);
visible = Main.API.readLong(address + 0x180) != 0; // isVisible, sprite object is set
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.manolo8.darkbot.core.objects.gui;

import com.github.manolo8.darkbot.Main;
import com.github.manolo8.darkbot.core.objects.Gui;

public class SizableGui extends Gui {
public void update() {
if (address == 0) return;
super.update();
width = (int) Main.API.readDouble(address + 0x1F8);
height = (int) Main.API.readDouble(address + 0x200);
}
}

0 comments on commit 0525d8c

Please sign in to comment.