mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-15 19:10:18 -07:00
decant
This commit is contained in:
parent
ac24828478
commit
593fc2927f
2 changed files with 55 additions and 56 deletions
|
|
@ -1,56 +0,0 @@
|
|||
|
||||
package core.game.node.entity.skill.herblore;
|
||||
|
||||
import core.cache.def.impl.NPCDefinition;
|
||||
import core.game.interaction.OptionHandler;
|
||||
import core.game.node.Node;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.item.Item;
|
||||
|
||||
import core.plugin.Initializable;
|
||||
import core.plugin.Plugin;
|
||||
import core.game.content.consumable.Consumables;
|
||||
import core.game.content.consumable.Potion;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Initializable
|
||||
public class MassDecantingPlugin extends OptionHandler {
|
||||
|
||||
@Override
|
||||
public Plugin<Object> newInstance(Object arg) throws Throwable {
|
||||
NPCDefinition.setOptionHandler("decant",this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(Player player, Node node, String option) {
|
||||
decant(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void decant(Player p){
|
||||
HashMap<Potion,Integer> potcounts = new HashMap<>();
|
||||
final List<Item> results;
|
||||
for(int i = 0; i < 28; i++){
|
||||
Potion pot = (Potion) Consumables.getConsumableById(p.getInventory().getId(i));
|
||||
if(pot != null){
|
||||
int dosage = Integer.parseInt(p.getInventory().get(i).getName().replaceAll("[^\\d.]",""));
|
||||
if(potcounts.get(pot) != null){
|
||||
potcounts.replace(pot,potcounts.get(pot) + dosage);
|
||||
} else {
|
||||
potcounts.putIfAbsent(pot,dosage);
|
||||
}
|
||||
p.getInventory().remove(new Item(p.getInventory().getId(i)));
|
||||
}
|
||||
}
|
||||
potcounts.keySet().forEach(pot -> {
|
||||
int full_count = (potcounts.get(pot) / pot.getIds().length);
|
||||
int partial_dose_amt = (potcounts.get(pot) % pot.getIds().length);
|
||||
p.getInventory().add(new Item(pot.getIds()[0],full_count));
|
||||
if(partial_dose_amt > 0) p.getInventory().add(new Item(pot.getIds()[pot.getIds().length - partial_dose_amt]));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package rs09.game.interaction.npc
|
||||
|
||||
import core.game.content.consumable.Consumables
|
||||
import core.game.content.consumable.Potion
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.item.Item
|
||||
import rs09.game.content.dialogue.DialogueFile
|
||||
import rs09.game.interaction.InteractionListener
|
||||
import rs09.tools.END_DIALOGUE
|
||||
|
||||
class DecantListener : InteractionListener() {
|
||||
|
||||
override fun defineListeners() {
|
||||
on(NPC,"decant"){player, node ->
|
||||
decant(player)
|
||||
player.dialogueInterpreter.open(DecantingDialogue(),node.asNpc())
|
||||
return@on true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun decant(p: Player) {
|
||||
val potcounts = HashMap<Potion, Int>()
|
||||
val results: List<Item>
|
||||
for (i in 0..27) {
|
||||
val pot = (Consumables.getConsumableById(p.inventory.getId(i)) ?: continue) as Potion
|
||||
if (pot != null) {
|
||||
val dosage = p.inventory[i].name.replace("[^\\d.]".toRegex(), "").toInt()
|
||||
if (potcounts[pot] != null) {
|
||||
potcounts.replace(pot, potcounts[pot]!! + dosage)
|
||||
} else {
|
||||
potcounts.putIfAbsent(pot, dosage)
|
||||
}
|
||||
p.inventory.remove(Item(p.inventory.getId(i)))
|
||||
}
|
||||
}
|
||||
potcounts.keys.forEach{ pot: Potion ->
|
||||
val full_count = potcounts[pot]!! / pot.ids.size
|
||||
val partial_dose_amt = potcounts[pot]!! % pot.ids.size
|
||||
p.inventory.add(Item(pot.ids[0], full_count))
|
||||
if (partial_dose_amt > 0) p.inventory
|
||||
.add(Item(pot.ids[pot.ids.size - partial_dose_amt]))
|
||||
}
|
||||
}
|
||||
|
||||
internal class DecantingDialogue : DialogueFile(){
|
||||
override fun handle(componentID: Int, buttonID: Int) {
|
||||
when(stage++){
|
||||
0 -> npc("There you go!")
|
||||
1 -> player("Thanks!").also { stage = END_DIALOGUE }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue