Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/main/java/com/logmaster/LogMasterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface LogMasterConfig extends Config

String PLUGIN_VERSION_KEY = "plugin-version";
String IS_COMMAND_ENABLED_KEY = "isCommandEnabled";
String REROLLS_ENABLED_KEY = "rerollsEnabled";

@Range(
min = 1000,
Expand Down Expand Up @@ -105,4 +106,55 @@ default boolean isCommandReminderEnabled()
{
return true;
}

@ConfigSection(
name = "Unofficial taskman config",
description = "Configuration options for unofficial taskman",
position = 20
)
String unofficial = "unofficial";

@ConfigItem(
keyName = REROLLS_ENABLED_KEY,
name = "Re-rolls enabled",
description = "Do you want re-rolls enabled? when enabled, current re-roll count will be set to the increment amount.",
section = unofficial,
position = 1
)
default boolean rerollsEnabled()
{
return false;
}

@ConfigItem(
keyName = "rerollMaximum",
name = "Re-rolls maximum",
description = "Maximum amount of re-rolls you can have.",
section = unofficial,
position = 2
)
@Range(
min = 1,
max = 10000
)
default int rerollsMaximum()
{
return 3;
}

@ConfigItem(
keyName = "rerollIncrement",
name = "Re-roll increment",
description = "How many re-rolls you want to gain per task completion. Set to 0 to restore to full.",
section = unofficial,
position = 3
)
@Range(
min = 0,
max = 10000
)
default int rerollsIncrement()
{
return 0;
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/logmaster/domain/savedata/SaveData.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ public SaveData() {

@Setter
private @Nullable Task activeTask = null;

@Setter
private int rerolls = 0;
}
23 changes: 21 additions & 2 deletions src/main/java/com/logmaster/task/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public Task getActiveTask() {
return saveDataStorage.get().getActiveTask();
}

public int getRerolls() {
return config.rerollsEnabled() ? saveDataStorage.get().getRerolls() : 0;
}

public int setRerolls(int rerolls) {
SaveData data = saveDataStorage.get();
data.setRerolls(rerolls);
return rerolls;
}

public Task getTaskById(String taskId) {
for (TaskTier t : TaskTier.values()) {
List<Task> tasks = getTierTasks(t);
Expand Down Expand Up @@ -124,8 +134,13 @@ public Task generate() {

Task activeTask = data.getActiveTask();
if (activeTask != null) {
log.warn("Tried to generate task when previous one wasn't completed yet");
return null;
// We only count as a reroll if there is an active task
if (config.rerollsEnabled() && this.getRerolls() > 0) {
this.setRerolls(getRerolls() - 1);
} else {
log.warn("Tried to generate task when previous one wasn't completed yet, no rerolls left");
return null;
}
}

TaskTier currentTier = getCurrentTier();
Expand Down Expand Up @@ -162,6 +177,10 @@ public void complete(String taskId) {
Task activeTask = getActiveTask();
if (activeTask != null && taskId.equals(activeTask.getId())) {
data.setActiveTask(null);
// Update our rerolls when we complete our active task
if (config.rerollsEnabled()) {
this.setRerolls(config.rerollsIncrement() > 0 ? Math.min(this.getRerolls() + config.rerollsIncrement(), config.rerollsMaximum()) : config.rerollsMaximum());
}
}

saveDataStorage.save();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/logmaster/ui/InterfaceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ public void onConfigChanged(ConfigChanged e) {
return;
}

// Refresh our rerolls when the config changes to be the amount set in our increments
if (e.getKey().equals(LogMasterConfig.REROLLS_ENABLED_KEY)) {
if (config.rerollsEnabled()) {
taskService.setRerolls(config.rerollsIncrement() > 0 ? Math.min(config.rerollsIncrement(), config.rerollsMaximum()) : config.rerollsMaximum());
} else {
taskService.setRerolls(0);
}
if (this.taskDashboard != null) {
this.taskDashboard.updateRerolls();
}
return;
}

if (!isTaskDashboardEnabled() || this.taskDashboard == null || this.tabManager == null) {
return;
}
Expand Down
62 changes: 57 additions & 5 deletions src/main/java/com/logmaster/ui/component/TaskDashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class TaskDashboard extends UIPage {
private UILabel title;
private UILabel taskLabel;
private UILabel percentCompletion;
private UILabel rerollLabel;

private UIGraphic taskImage;
private UIGraphic taskBg;
Expand Down Expand Up @@ -90,9 +91,16 @@ public TaskDashboard(LogMasterPlugin plugin, LogMasterConfig config, Widget wind
this.percentCompletion = new UILabel(percentWidget);
this.percentCompletion.setFont(FontID.BOLD_12);
this.percentCompletion.setSize(COLLECTION_LOG_WINDOW_WIDTH, 25);
this.percentCompletion.setPosition(getCenterX(window, COLLECTION_LOG_WINDOW_WIDTH), COLLECTION_LOG_WINDOW_HEIGHT - 91);
this.percentCompletion.setPosition(getCenterX(window, COLLECTION_LOG_WINDOW_WIDTH), COLLECTION_LOG_WINDOW_HEIGHT - 97);
updatePercentages();

Widget rerollWidget = window.createChild(-1, WidgetType.TEXT);
this.rerollLabel = new UILabel(rerollWidget);
this.rerollLabel.setFont(FontID.BOLD_12);
this.rerollLabel.setSize(COLLECTION_LOG_WINDOW_WIDTH, 25);
this.rerollLabel.setPosition(getCenterX(window, COLLECTION_LOG_WINDOW_WIDTH), COLLECTION_LOG_WINDOW_HEIGHT - 75);
updateRerolls();

Widget completeTaskWidget = window.createChild(-1, WidgetType.GRAPHIC);
this.completeTaskBtn = new UIButton(completeTaskWidget);
this.completeTaskBtn.setSize(DEFAULT_BUTTON_WIDTH, DEFAULT_BUTTON_HEIGHT);
Expand Down Expand Up @@ -125,6 +133,7 @@ public TaskDashboard(LogMasterPlugin plugin, LogMasterConfig config, Widget wind
this.add(this.completeTaskBtn);
this.add(this.generateTaskBtn);
this.add(this.percentCompletion);
this.add(this.rerollLabel);
this.add(faqBtn);
this.add(syncBtn);
}
Expand Down Expand Up @@ -180,6 +189,9 @@ public void clearTask() {

public void setTask(Task task, List<Task> cyclingTasks) {
this.disableGenerateTask();
this.disableCompleteTask();
this.taskBg.getWidget().clearActions();
this.taskBg.clearActions();

if (cyclingTasks != null) {
for (int i = 0; i < 250; i++) {
Expand Down Expand Up @@ -207,6 +219,10 @@ public void setTask(Task task, List<Task> cyclingTasks) {
this.taskLabel.setText(task.getName());
this.taskImage.setItem(task.getDisplayItemId());
this.taskBg.addAction("View task info", () -> taskInfo.showTask(task.getId()));

if (taskService.getRerolls() > 0) {
this.enableGenerateTask();
}
this.enableCompleteTask();
this.enableFaqButton();
}
Expand All @@ -216,9 +232,11 @@ private void generateTask() {
Task generatedTask = taskService.generate();

List<Task> rollTaskList = config.rollPastCompleted() ? taskService.getTierTasks() : taskService.getIncompleteTierTasks();
setTask(generatedTask, rollTaskList);
disableGenerateTask();
disableCompleteTask();
updatePercentages();
setTask(generatedTask, rollTaskList);
updateRerolls();
}

public void updatePercentages() {
Expand All @@ -235,6 +253,26 @@ public void updatePercentages() {
percentCompletion.setText(text);
}

public void updateRerolls() {
String color;
switch (taskService.getRerolls()) {
case 0:
color = "e74c3c";
break;
case 1:
color = "e67e22";
break;
case 2:
color = "f1c40f";
break;
default:
color = "2ecc71";
break;
}
String rerollsText = config.rerollsEnabled() ? "Re-rolls available: <col=" + color + ">" + taskService.getRerolls() + "</col>" : "";
this.rerollLabel.setText(rerollsText);
}

private String getCompletionColor(double percent) {
int max = 255;
int amount = (int) Math.round(((percent % 50) / 50) * max);
Expand All @@ -258,29 +296,40 @@ else if(percent == 50) {

public void disableGenerateTask() {
this.generateTaskBtn.setSprites(GENERATE_TASK_DISABLED_SPRITE_ID);
this.generateTaskBtn.getWidget().clearActions();
this.generateTaskBtn.clearActions();

this.generateTaskBtn.addAction("Disabled", this::playFailSound);
updateRerolls();
}

public void enableGenerateTask() {
this.generateTaskBtn.getWidget().clearActions();
this.generateTaskBtn.clearActions();
this.generateTaskBtn.setSprites(GENERATE_TASK_SPRITE_ID, GENERATE_TASK_HOVER_SPRITE_ID);
this.generateTaskBtn.addAction("Generate task", this::generateTask);
if (taskService.getRerolls() > 0 && taskService.getActiveTask() != null) {
this.generateTaskBtn.addAction("Right click to re-roll", this::playFailSound);
this.generateTaskBtn.addAction("<col=2ecc71>Re-roll task</col>", this::generateTask);
} else {
this.generateTaskBtn.addAction("Generate task", this::generateTask);
}

this.disableCompleteTask();
updateRerolls();
}

public void disableCompleteTask() {
this.completeTaskBtn.setSprites(COMPLETE_TASK_DISABLED_SPRITE_ID);
this.completeTaskBtn.clearActions();
this.completeTaskBtn.addAction("Disabled", this::playFailSound);
updateRerolls();
}

public void enableCompleteTask() {
this.completeTaskBtn.clearActions();
this.completeTaskBtn.setSprites(COMPLETE_TASK_SPRITE_ID, COMPLETE_TASK_HOVER_SPRITE_ID);
this.completeTaskBtn.addAction("Complete", plugin::completeTask);
updateRerolls();
}

public void enableFaqButton() {
Expand Down Expand Up @@ -351,10 +400,12 @@ public void updateBounds() {

// Update percentage completion position - force widget position update
int percentX = getCenterX(window, COLLECTION_LOG_WINDOW_WIDTH);
int percentY = getCenterY(window, DEFAULT_BUTTON_HEIGHT) + 112; // Same Y as FAQ button
int percentY = getCenterY(window, DEFAULT_BUTTON_HEIGHT) + 106;
this.percentCompletion.setPosition(percentX, percentY);
this.percentCompletion.getWidget().setPos(percentX, percentY);

this.rerollLabel.setPosition(getCenterX(window, COLLECTION_LOG_WINDOW_WIDTH), percentY + 16);
this.rerollLabel.getWidget().setPos(getCenterX(window, COLLECTION_LOG_WINDOW_WIDTH), percentY + 16);

// Force revalidation of all widgets
this.title.getWidget().revalidate();
this.taskBg.getWidget().revalidate();
Expand All @@ -365,6 +416,7 @@ public void updateBounds() {
this.faqBtn.getWidget().revalidate();
this.syncBtn.getWidget().revalidate();
this.percentCompletion.getWidget().revalidate();
this.rerollLabel.getWidget().revalidate();
}

private int getCenterX(Widget window, int width) {
Expand Down