mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-10 10:20:41 -07:00
Converted plugin for making gem tipped bolt tips and bolts to listener
This commit is contained in:
parent
a88fde30ed
commit
0fa8a1c87e
2 changed files with 70 additions and 104 deletions
|
|
@ -0,0 +1,70 @@
|
|||
package content.global.skill.fletching
|
||||
|
||||
import content.global.skill.fletching.Fletching.GemBolts
|
||||
import content.global.skill.fletching.items.gem.GemBoltCutPulse
|
||||
import content.global.skill.fletching.items.gem.GemBoltPulse
|
||||
import core.api.amountInInventory
|
||||
import core.game.dialogue.SkillDialogueHandler
|
||||
import core.game.interaction.IntType
|
||||
import core.game.interaction.InteractionListener
|
||||
import core.game.node.item.Item
|
||||
import core.net.packet.PacketRepository
|
||||
import core.net.packet.context.ChildPositionContext
|
||||
import core.net.packet.out.RepositionChild
|
||||
import org.rs09.consts.Items
|
||||
import kotlin.math.min
|
||||
|
||||
class GemBoltListener : InteractionListener {
|
||||
val gems = intArrayOf(
|
||||
Items.OYSTER_PEARL_411,
|
||||
Items.OYSTER_PEARLS_413,
|
||||
Items.OPAL_1609,
|
||||
Items.JADE_1611,
|
||||
Items.RED_TOPAZ_1613,
|
||||
Items.SAPPHIRE_1607,
|
||||
Items.EMERALD_1605,
|
||||
Items.RUBY_1603,
|
||||
Items.DIAMOND_1601,
|
||||
Items.DRAGONSTONE_1615,
|
||||
Items.ONYX_6573
|
||||
)
|
||||
val boltBases = GemBolts.values().map { it.base }.toIntArray()
|
||||
val boltTips = GemBolts.values().map { it.tip }.toIntArray()
|
||||
|
||||
override fun defineListeners() {
|
||||
onUseWith(IntType.ITEM, Items.CHISEL_1755, *gems) { player, used, with ->
|
||||
val gem = Fletching.gemMap[with.id] ?: return@onUseWith true
|
||||
|
||||
object : SkillDialogueHandler(player, SkillDialogue.ONE_OPTION, Item(gem.gem)) {
|
||||
override fun create(amount: Int, index: Int) {
|
||||
player.pulseManager.run(GemBoltCutPulse(player, used as? Item, gem, amount))
|
||||
}
|
||||
|
||||
override fun getAll(index: Int): Int {
|
||||
return player.inventory.getAmount(gem.gem)
|
||||
}
|
||||
}.open()
|
||||
return@onUseWith true
|
||||
}
|
||||
|
||||
onUseWith(IntType.ITEM, boltBases, *boltTips) {player, used, with ->
|
||||
val bolt = Fletching.tipMap[with.id] ?: return@onUseWith true
|
||||
if (used.id != bolt.base || with.id != bolt.tip) return@onUseWith true
|
||||
|
||||
|
||||
val handler: SkillDialogueHandler =
|
||||
object : SkillDialogueHandler(player, SkillDialogue.ONE_OPTION, Item(bolt.product)) {
|
||||
override fun create(amount: Int, index: Int) {
|
||||
player.pulseManager.run(GemBoltPulse(player, used as? Item, bolt, amount))
|
||||
}
|
||||
|
||||
override fun getAll(index: Int): Int {
|
||||
return min(amountInInventory(player, used.id), amountInInventory(player, with.id))
|
||||
}
|
||||
}
|
||||
handler.open()
|
||||
PacketRepository.send(RepositionChild::class.java, ChildPositionContext(player, 309, 2, 210, 10))
|
||||
return@onUseWith true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
package content.global.skill.fletching;
|
||||
|
||||
import content.global.skill.fletching.items.gem.GemBoltCutPulse;
|
||||
import content.global.skill.fletching.items.gem.GemBoltPulse;
|
||||
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;
|
||||
import core.game.dialogue.SkillDialogueHandler;
|
||||
import core.game.dialogue.SkillDialogueHandler.SkillDialogue;
|
||||
import org.rs09.consts.Items;
|
||||
|
||||
/**
|
||||
* Represents the gem bolt creating plugin.
|
||||
* @author Ceikry
|
||||
* @version 2.0
|
||||
*/
|
||||
@Initializable
|
||||
public final class GemBoltPlugin extends UseWithHandler {
|
||||
Fletching.GemBolts bolt;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code GemBoltPlugin} {@code Object}.
|
||||
*/
|
||||
public GemBoltPlugin() {
|
||||
super(Items.OPAL_BOLT_TIPS_45,
|
||||
Items.PEARL_BOLT_TIPS_46,
|
||||
Items.JADE_BOLT_TIPS_9187,
|
||||
Items.TOPAZ_BOLT_TIPS_9188,
|
||||
Items.SAPPHIRE_BOLT_TIPS_9189,
|
||||
Items.EMERALD_BOLT_TIPS_9190,
|
||||
Items.RUBY_BOLT_TIPS_9191,
|
||||
Items.DIAMOND_BOLT_TIPS_9192,
|
||||
Items.DRAGON_BOLT_TIPS_9193,
|
||||
Items.ONYX_BOLT_TIPS_9194,
|
||||
Items.OYSTER_PEARL_411,
|
||||
Items.OYSTER_PEARLS_413,
|
||||
Items.OPAL_1609,
|
||||
Items.JADE_1611,
|
||||
Items.RED_TOPAZ_1613,
|
||||
Items.SAPPHIRE_1607,
|
||||
Items.EMERALD_1605,
|
||||
Items.RUBY_1603,
|
||||
Items.DIAMOND_1601,
|
||||
Items.DRAGONSTONE_1615,
|
||||
Items.ONYX_6573);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin<Object> newInstance(Object arg) throws Throwable {
|
||||
addHandler(Items.CHISEL_1755, ITEM_TYPE, this);
|
||||
for(Fletching.GemBolts gem : Fletching.GemBolts.values()){
|
||||
addHandler(gem.base, ITEM_TYPE,this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(final NodeUsageEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
bolt = Fletching.tipMap.get(event.getUsedItem().getId());
|
||||
if(bolt == null){
|
||||
bolt = Fletching.tipMap.get(event.getUsedWith().getId());
|
||||
}
|
||||
if(bolt != null && (event.getUsedItem().getId() == bolt.tip && event.getUsedWith().getId() == bolt.base)
|
||||
|| event.getUsedItem().getId() == bolt.base && event.getUsedWith().getId() == bolt.tip ) {
|
||||
SkillDialogueHandler handler = new SkillDialogueHandler(player, SkillDialogue.ONE_OPTION, new Item(bolt.product)) {
|
||||
@Override
|
||||
public void create(final int amount, int index) {
|
||||
player.getPulseManager().run(new GemBoltPulse(player, event.getUsedItem(), bolt, amount));
|
||||
}
|
||||
@Override
|
||||
public int getAll(int index) {
|
||||
return player.getInventory().getAmount(event.getUsedItem());
|
||||
}
|
||||
};
|
||||
handler.open();
|
||||
PacketRepository.send(RepositionChild.class, new ChildPositionContext(player, 309, 2, 210, 10));
|
||||
} else {
|
||||
final Fletching.GemBolts gem = Fletching.gemMap.get(event.getUsedItem().getId() == Items.CHISEL_1755 ? event.getBaseItem().getId() : event.getUsedItem().getId());
|
||||
if(gem == null){
|
||||
return false;
|
||||
}
|
||||
new SkillDialogueHandler(player, SkillDialogue.ONE_OPTION, new Item(gem.gem)) {
|
||||
@Override
|
||||
public void create(final int amount, final int index) {
|
||||
player.getPulseManager().run(new GemBoltCutPulse(player, event.getUsedItem(), gem, amount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAll(int index) {
|
||||
return player.getInventory().getAmount(gem.gem);
|
||||
}
|
||||
|
||||
}.open();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue