Implemented make-x for potatoes/pizzas/breads

This commit is contained in:
Avi Weinstock
2022-03-10 02:16:12 +00:00
committed by Ryan
parent ebc91b522b
commit 8887351ed8
3 changed files with 75 additions and 5 deletions
@@ -1,11 +1,15 @@
package core.game.node.entity.skill.cooking;
import core.plugin.Initializable;
import core.game.node.entity.skill.cooking.recipe.Recipe;
import core.game.interaction.NodeUsageEvent;
import core.game.interaction.UseWithHandler;
import core.game.node.entity.player.Player;
import core.game.node.entity.skill.cooking.recipe.Recipe;
import core.game.node.item.Item;
import core.game.system.task.Pulse;
import core.plugin.Initializable;
import core.plugin.Plugin;
import rs09.game.content.dialogue.SkillDialogueHandler.SkillDialogue;
import rs09.game.content.dialogue.SkillDialogueHandler;
import java.util.ArrayList;
import java.util.List;
@@ -40,6 +44,7 @@ public final class CookingRecipePlugin extends UseWithHandler {
@Override
public boolean handle(NodeUsageEvent event) {
Recipe recipe = null;
// TODO: Transitioning to a Listener would save an O(n) pass through the recipes list on every use-with
for (Recipe temp : Recipe.RECIPES) {
if (temp.isSingular()) {
if (temp.getBase().getId() == event.getUsedItem().getId() || temp.getBase().getId() == event.getBaseItem().getId()) {
@@ -69,7 +74,31 @@ public final class CookingRecipePlugin extends UseWithHandler {
}
}
if (recipe != null) {
recipe.mix(event.getPlayer(), event);
final Player player = event.getPlayer();
final Recipe recipe_ = recipe;
SkillDialogueHandler handler = new SkillDialogueHandler(player, SkillDialogue.ONE_OPTION, recipe.getProduct()) {
@Override
public void create(final int amount, int index) {
player.getPulseManager().run(new Pulse(2) {
int count = 0;
@Override
public boolean pulse() {
recipe_.mix(player, event);
return ++count >= amount;
}
});
}
@Override
public int getAll(int index) {
return player.getInventory().getAmount(recipe_.getBase());
}
};
if (player.getInventory().getAmount(recipe.getBase()) == 1) {
recipe_.mix(player, event);
} else {
handler.open();
}
return true;
}
return false;
@@ -1,6 +1,5 @@
package core.game.node.entity.skill.cooking;
import core.plugin.Initializable;
import core.game.content.dialogue.DialoguePlugin;
import core.game.content.quest.tutorials.tutorialisland.TutorialSession;
import core.game.content.quest.tutorials.tutorialisland.TutorialStage;
@@ -8,7 +7,11 @@ import core.game.interaction.NodeUsageEvent;
import core.game.interaction.UseWithHandler;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
import core.game.system.task.Pulse;
import core.plugin.Initializable;
import core.plugin.Plugin;
import rs09.game.content.dialogue.SkillDialogueHandler.SkillDialogue;
import rs09.game.content.dialogue.SkillDialogueHandler;
/**
* Represents the plugin used to make dough.
@@ -130,13 +133,47 @@ public final class MakeDoughPlugin extends UseWithHandler {
public boolean handle(int interfaceId, int buttonId) {
switch (stage) {
case 0:
makeDough(DOUGHS[buttonId - 1]);
makeDoughPulse(DOUGHS[buttonId - 1]);
end();
break;
}
return true;
}
private void makeDoughPulse(final Item dough) {
SkillDialogueHandler handler = new SkillDialogueHandler(player, SkillDialogue.ONE_OPTION, dough) {
@Override
public void create(final int amount, int index) {
player.getPulseManager().run(new Pulse(2) {
int count = 0;
@Override
public boolean pulse() {
makeDough(dough);
return ++count >= amount;
}
});
}
@Override
public int getAll(int index) {
return player.getInventory().getAmount(waterData[0]);
}
};
if (player.getInventory().getAmount(waterData[0]) == 1) {
makeDough(dough);
} else {
// Defer the creation of the SkillDialogueHandler creation to a pulse since otherwise the dialogue doesn't open (is this dialogue in the way?)
player.getPulseManager().run(new Pulse(0) {
@Override
public boolean pulse() {
handler.open();
return true;
}
});
end();
}
}
/**
* Method used to make a dough item.
* @param dough the dough.
@@ -25,6 +25,10 @@ public abstract class Recipe {
/**
* Represents the array of active recipes in Keldagrim..
*/
// TODO:
// - Making this an enum would drastically save on file/line count, since the recipes seem to mostly be plain-old-data classes
// - Making pie shells a recipe would make make-x for them just work
// - Making pineapple cutting a recipe would probably fix their make-x making all with any option
public static final Recipe[] RECIPES = new Recipe[] {
new RedberryPie(), new MeatPie(), new ApplePie(), new MudPie(), new GardenPie(), new FishPie(), new AdmiralPie(), new WildPie(), new SummerPie(),
new StewRecipe(), new CurryRecipe(),