Moved most fletching option handlers and use with handlers to FletchingListeners.kt

This commit is contained in:
Ceikry
2021-03-13 17:29:39 -06:00
parent c2a3496b31
commit 154d570569
18 changed files with 563 additions and 819 deletions
@@ -1,102 +0,0 @@
package core.game.content.dialogue;
import core.plugin.Initializable;
import core.game.node.entity.skill.fletching.items.grapple.GrapplePulse;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.RunScript;
import core.game.node.item.Item;
import core.net.packet.PacketRepository;
import core.net.packet.context.ChildPositionContext;
import core.net.packet.out.RepositionChild;
/**
* Represents the dialogue used to create a mith grapple.
* @author 'Vexia
* @version 1.0
*/
@Initializable
public final class MithGrappleDialogue extends DialoguePlugin {
/**
* Represents the mith grapple tip.
*/
private static final Item MITH_GRAPPLE = new Item(9418);
/**
* Represents the first item used.
*/
private Item first;
/**
* Represents the second item used.
*/
private Item second;
/**
* Constructs a new {@code MithGrappleDialogue} {@code Object}.
*/
public MithGrappleDialogue() {
/**
* empty.
*/
}
/**
* Constructs a new {@code MithGrappleDialogue} {@code Object}.
* @param player the player.
*/
public MithGrappleDialogue(Player player) {
super(player);
}
@Override
public DialoguePlugin newInstance(Player player) {
return new MithGrappleDialogue(player);
}
@Override
public boolean open(Object... args) {
first = (Item) args[0];
second = (Item) args[1];
player.getInterfaceManager().openChatbox(309);
player.getPacketDispatch().sendString("<br><br><br><br>Mith Grapple", 309, 6);
PacketRepository.send(RepositionChild.class, new ChildPositionContext(player, 309, 2, 215, 26));
player.getPacketDispatch().sendItemZoomOnInterface(MITH_GRAPPLE.getId(), 175, 309, 2);
return true;
}
@Override
public boolean handle(int interfaceId, int buttonId) {
player.getInterfaceManager().closeChatbox();
int amount = 0;
switch (buttonId) {
case 6:
amount = 1;
break;
case 5:
amount = 5;
break;
case 4:
player.setAttribute("runscript", new RunScript() {
@Override
public boolean handle() {
int ammount = (int) value;
player.getPulseManager().run(new GrapplePulse(player, first, ammount));
return false;
}
});
player.getDialogueInterpreter().sendInput(false, "Enter the amount");
return true;
case 3:
amount = player.getInventory().getAmount(second);
break;
}
player.getPulseManager().run(new GrapplePulse(player, first, amount));
return true;
}
@Override
public int[] getIds() {
return new int[] { 903213 };
}
}
@@ -1,50 +0,0 @@
package core.game.node.entity.skill.fishing;
import core.cache.def.impl.NPCDefinition;
import core.game.interaction.OptionHandler;
import core.game.node.Node;
import core.game.node.entity.npc.NPC;
import core.game.node.entity.player.Player;
import core.game.world.map.Location;
import core.plugin.Initializable;
import core.plugin.Plugin;
/**
* Represents the plugin used to start fishing.
* @author Ceikry
* @version 1.2
*/
@Initializable
public final class FishingOptionPlugin extends OptionHandler {
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
NPCDefinition.setOptionHandler("net", this);
NPCDefinition.setOptionHandler("bait", this);
NPCDefinition.setOptionHandler("lure", this);
NPCDefinition.setOptionHandler("cage", this);
NPCDefinition.setOptionHandler("harpoon", this);
return this;
}
@Override
public boolean handle(Player player, Node node, String option) {
NPC npc = (NPC) node;
FishingSpot spot = FishingSpot.forId(npc.getId());
if (spot == null) {
return false;
}
FishingOption opt = spot.getOptionByName(option);
if (opt == null) {
return false;
}
player.getPulseManager().run(new FishingPulse(player, npc, opt));
return true;
}
@Override
public Location getDestination(Node node, Node n) {
return null;
}
}
@@ -1,114 +0,0 @@
package core.game.node.entity.skill.fletching;
import core.plugin.Initializable;
import rs09.game.content.dialogue.SkillDialogueHandler;
import rs09.game.content.dialogue.SkillDialogueHandler.SkillDialogue;
import core.game.node.entity.skill.fletching.items.arrow.ArrowHeadPulse;
import core.game.node.entity.skill.fletching.items.arrow.HeadlessArrowPulse;
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.net.packet.PacketRepository;
import core.net.packet.context.ChildPositionContext;
import core.net.packet.out.RepositionChild;
import core.plugin.Plugin;
/**
* Represents the plugin used to create arrows.
* @author Angle
*/
@Initializable
public class ArrowCreatePlugin extends UseWithHandler {
/**
* Represents the headless arrow item.
*/
private static final Item HEADLESS_ARROW = new Item(53);
/**
* Constructs a new {@code ArrowCreatePlugin} {@code Object}.
*/
public ArrowCreatePlugin() {
super(314, 53, 52);
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
// Feathers plus colored feathers
addHandler(314, ITEM_TYPE, this);
addHandler(10087, ITEM_TYPE, this);
addHandler(10088, ITEM_TYPE, this);
addHandler(10089, ITEM_TYPE, this);
addHandler(10090, ITEM_TYPE, this);
addHandler(10091, ITEM_TYPE, this);
// Headless Arrows
addHandler(53, ITEM_TYPE, this);
// Arrow heads
for (Fletching.ArrowHeads head : Fletching.ArrowHeads.values()) {
addHandler(head.unfinished, ITEM_TYPE, this);
}
return this;
}
@Override
public boolean handle(final NodeUsageEvent event) {
event.getPlayer().debug("Trying to handle: " + event.getUsedItem() + " with " + event.getUsedWith());
final Player player = event.getPlayer();
// If the player uses a feather on headless arrows, do headless arrow crafting
final int itemId = event.getUsedItem().getId();
final int otherId = event.getUsedWith().getId();
final boolean hasFeather = (itemId == 314 || (itemId >= 10087 && itemId <= 10091)) || (otherId == 314 || (otherId >= 10087 && otherId <= 10091));
final boolean hasShaft = (itemId == 52 || otherId == 52);
// If the item used was feathers and the target was arrow shafts
if (hasFeather && hasShaft) {
// Creating headless arrows
final int featherId = itemId == 52 ? otherId : itemId;
SkillDialogueHandler handler = new SkillDialogueHandler(player, SkillDialogue.ONE_OPTION, HEADLESS_ARROW) {
@Override
public void create(final int amount, int index) {
player.getPulseManager().run(new HeadlessArrowPulse(player, event.getUsedItem(), new Item(featherId), amount));
}
@Override
public int getAll(int index) {
return player.getInventory().getAmount(HEADLESS_ARROW);
}
};
handler.open();
PacketRepository.send(RepositionChild.class, new ChildPositionContext(player, 309, 2, 210, 10));
return true;
}
// Otherwise, fletch normally
boolean firstIsHead = Fletching.isArrowHead(itemId);
if (!firstIsHead && !Fletching.isArrowHead(otherId)) {
return false;
} else if (hasFeather || hasShaft) {
// Disallow crafting feathers with arrowheads or shafts with arrowheads.
// It will fail anyway but this makes sure
// that the gui doesn't pop up on the client.
return true;
}
final Fletching.ArrowHeads head = Fletching.arrowHeadMap.get(firstIsHead ? itemId : otherId);
SkillDialogueHandler handler = new SkillDialogueHandler(player, SkillDialogue.ONE_OPTION, head.getFinished()) {
@Override
public void create(final int amount, int index) {
player.getPulseManager().run(new ArrowHeadPulse(player, event.getUsedItem(), head, amount));
}
@Override
public int getAll(int index) {
return player.getInventory().getAmount(head.getUnfinished());
}
};
handler.open();
PacketRepository.send(RepositionChild.class, new ChildPositionContext(player, 309, 2, 210, 10));
return true;
}
}
@@ -1,62 +0,0 @@
package core.game.node.entity.skill.fletching;
import rs09.game.content.dialogue.SkillDialogueHandler;
import core.game.node.entity.skill.fletching.items.crossbow.LimbPulse;
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.net.packet.PacketRepository;
import core.net.packet.context.ChildPositionContext;
import core.net.packet.out.RepositionChild;
import core.plugin.Initializable;
import core.plugin.Plugin;
/**
* Represents the plugin used to make a crossbow.
* @author Ceikry
*/
@Initializable
public class MakeCrossbowPlugin extends UseWithHandler {
Fletching.Limb limb;
Item whichItem;
/**
* Constructs a new {@code StringcrossbowPlugin} {@code Object}.
*/
public MakeCrossbowPlugin() {
super(9420, 9423, 9422, 9425, 9427, 9429, 9431);
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
for (Fletching.Limb l : Fletching.Limb.values()) {
addHandler(new Item(l.stock).getId(), ITEM_TYPE, this);
}
return this;
}
@Override
public boolean handle(NodeUsageEvent event) {
final Player player = event.getPlayer();
limb = Fletching.limbMap.get(event.getBaseItem().getId());
whichItem = (Item)event.getUsedWith();
if(limb == null){
limb = Fletching.limbMap.get(event.getUsed().getId());
whichItem = (Item)event.getUsed();
}
SkillDialogueHandler handler = new SkillDialogueHandler(player, SkillDialogueHandler.SkillDialogue.ONE_OPTION, new Item(limb.product)) {
@Override
public void create(final int amount, int index) {
player.getPulseManager().run(new LimbPulse(player, whichItem, limb, amount));
}
@Override
public int getAll(int index) {
return player.getInventory().getAmount(whichItem);
}
};
handler.open();
PacketRepository.send(RepositionChild.class, new ChildPositionContext(player, 309, 2, 210, 10));
return true;
}
}
@@ -1,69 +0,0 @@
package core.game.node.entity.skill.fletching;
import core.game.node.entity.skill.Skills;
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.plugin.Initializable;
import core.plugin.Plugin;
/**
* Represents the plugin used to make a mithril grapple.
* @author 'Vexia
* @version 1.0
*/
@Initializable
public final class MithGrapplePlugin extends UseWithHandler {
/**
* Represents the rope grapple.
*/
private static final Item ROPE_GRAPPLE = new Item(9419);
/**
* Represents the mith grapple.
*/
private static final Item MITH_GRAPPLE = new Item(9418);
/**
* Represents the rope item.
*/
private static final Item ROPE = new Item(954);
/**
* Constructs a new {@code MithGrapplePlugin} {@code Object}.
*/
public MithGrapplePlugin() {
super(9416, 954);
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
addHandler(9142, ITEM_TYPE, this);
addHandler(9418, ITEM_TYPE, this);
return this;
}
@Override
public boolean handle(NodeUsageEvent event) {
final Player player = event.getPlayer();
final Item first = event.getUsedItem();
final Item second = event.getBaseItem();
if (first.getId() == 9418 && second.getId() != 954) {
return false;
} else if (first.getId() == 9418 && second.getId() == 954) {
if (player.getInventory().remove(ROPE) && player.getInventory().remove(MITH_GRAPPLE)) {
player.getInventory().add(ROPE_GRAPPLE);
}
return true;
}
if (player.getSkills().getLevel(Skills.FLETCHING) < 59) {
player.getDialogueInterpreter().sendDialogue("You need a fletching level of 59 in order to do that.");
return true;
}
player.getDialogueInterpreter().open(903213, first, second);
return true;
}
}
@@ -1,65 +0,0 @@
package core.game.node.entity.skill.fletching;
import core.plugin.Initializable;
import rs09.game.content.dialogue.SkillDialogueHandler;
import core.game.node.entity.skill.fletching.items.bow.StringPulse;
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.net.packet.PacketRepository;
import core.net.packet.context.ChildPositionContext;
import core.net.packet.out.RepositionChild;
import core.plugin.Plugin;
/**
* Represents the plugin used to string a bow.
* @author Ceikry
* @version 2.0
*/
@Initializable
public final class StringbowPlugin extends UseWithHandler {
Fletching.String string;
/**
* Constructs a new {@code StringbowPlugin} {@code Object}.
*/
public StringbowPlugin() {
super(1777, 9438);
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
for (Fletching.String bw : Fletching.String.values()) {
addHandler(bw.unfinished, ITEM_TYPE, this);
}
return this;
}
@Override
public boolean handle(NodeUsageEvent event) {
final Player player = event.getPlayer();
Fletching.String string = Fletching.stringMap.get(event.getUsedItem().getId());
if(string == null){
string = Fletching.stringMap.get(event.getUsedWith().getId());
}
final Fletching.String bow = string;
if(!(player.getInventory().containsItem(new Item(bow.string)))){
player.getDialogueInterpreter().sendDialogue("That's not the correct type of string.");
return true;
}
SkillDialogueHandler handler = new SkillDialogueHandler(player, SkillDialogueHandler.SkillDialogue.ONE_OPTION, new Item(bow.product)) {
@Override
public void create(final int amount, int index) {
player.getPulseManager().run(new StringPulse(player, event.getUsedItem(), bow, amount));
}
@Override
public int getAll(int index) {
return player.getInventory().getAmount(event.getUsedItem());
}
};
handler.open();
PacketRepository.send(RepositionChild.class, new ChildPositionContext(player, 309, 2, 215, 10));
return true;
}
}
@@ -94,7 +94,7 @@ public final class HeadlessArrowPulse extends SkillPulse<Item> {
ARROW_SHAFT.setAmount(15);
player.getPacketDispatch().sendMessage("You attach feathers to 15 arrow shafts.");
} else {
int amount = featherAmount > shaftAmount ? shaftAmount : featherAmount;
int amount = Math.min(featherAmount, shaftAmount);
feather.setAmount(amount);
ARROW_SHAFT.setAmount(amount);
player.getPacketDispatch().sendMessage(amount == 1
@@ -33,7 +33,6 @@ public class StringPulse extends SkillPulse<Item> {
*/
public StringPulse(Player player, Item node, final Fletching.String bow, int amount) {
super(player, node);
setDelay(bow.string == 1777 ? 9 : 7);
this.bow = bow;
this.amount = amount;
}
@@ -1,79 +1,52 @@
package core.game.node.entity.skill.fletching.items.crossbow;
package core.game.node.entity.skill.fletching.items.crossbow
import core.game.node.entity.skill.SkillPulse;
import core.game.node.entity.skill.Skills;
import core.game.node.entity.skill.fletching.Fletching;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
import core.game.node.entity.player.Player
import core.game.node.entity.skill.SkillPulse
import core.game.node.entity.skill.Skills
import core.game.node.entity.skill.fletching.Fletching
import core.game.node.item.Item
/**
* Represents the skill pulse of attaching limbs.
* @author Ceikry
*/
public class LimbPulse extends SkillPulse<Item> {
class LimbPulse(player: Player?, node: Item, private val limb: Fletching.Limb ,private var amount: Int) : SkillPulse<Item?>(player, node) {
override fun checkRequirements(): Boolean {
if (player.skills.getLevel(Skills.FLETCHING) < limb.level) {
player.dialogueInterpreter.sendDialogue("You need a fletching level of " + limb.level + " to attach these limbs.")
return false
}
if (!player.inventory.containsItem(Item(limb.limb))) {
player.dialogueInterpreter.sendDialogue("That's not the correct limb to attach.")
return false
}
if(!player.inventory.containsItem(Item(limb.stock))){
player.dialogueInterpreter.sendDialogue("That's not the correct stock for that limb.")
return false
}
return player.inventory.containsItem(Item(limb.stock))
}
/**
* Represents the limbs.
*/
private final Fletching.Limb limb;
override fun animate() {
player.animate(limb.animation)
}
/**
* Represents the amount.
*/
private int amount;
override fun reward(): Boolean {
if (delay == 1) {
super.setDelay(6)
return false
}
if (player.inventory.remove(Item(limb.stock), Item(limb.limb))) {
player.inventory.add(Item(limb.product))
player.skills.addExperience(Skills.FLETCHING, limb.experience, true)
player.packetDispatch.sendMessage("You attach the metal limbs to the stock.")
}
if (!player.inventory.containsItem(Item(limb.limb))) {
return true
}
amount--
return amount == 0
}
/**
* Constructs a new {@code StringcrossbowPlugin.java} {@code Object}.
* @param player the player.
* @param node the node.
*/
public LimbPulse(Player player, Item node, final Fletching.Limb limb, int amount) {
super(player, node);
this.limb = limb;
this.amount = amount;
}
@Override
public boolean checkRequirements() {
if (player.getSkills().getLevel(Skills.FLETCHING) < limb.level) {
player.getDialogueInterpreter().sendDialogue("You need a fletching level of " + limb.level + " to attach these limbs.");
return false;
}
if (!player.getInventory().containsItem(new Item(limb.limb))) {
player.getDialogueInterpreter().sendDialogue("That's not the correct limb to attach.");
return false;
}
if (!player.getInventory().containsItem(new Item(limb.stock))) {
return false;
}
return true;
}
@Override
public void animate() {
player.animate(limb.animation);
}
@Override
public boolean reward() {
if (getDelay() == 1) {
super.setDelay(6);
return false;
}
if (player.getInventory().remove(new Item(limb.stock), new Item(limb.limb))) {
player.getInventory().add(new Item(limb.product));
player.getSkills().addExperience(Skills.FLETCHING, limb.experience, true);
player.getPacketDispatch().sendMessage("You attach the metal limbs to the stock.");
}
if (!player.getInventory().containsItem(new Item(limb.limb))) {
return true;
}
amount--;
return amount == 0;
}
@Override
public void message(int type) {
}
}
override fun message(type: Int) {}
}