Crafting guild no longer gives "welcome" messages on leave

Refactored crafting guild
This commit is contained in:
bushtail 2022-03-21 00:54:14 +00:00 committed by Ryan
parent fa13d165d2
commit 3270388f8d
6 changed files with 204 additions and 294 deletions

View file

@ -1,293 +0,0 @@
package core.game.content.activity.guild;
import core.cache.def.impl.NPCDefinition;
import core.cache.def.impl.SceneryDefinition;
import core.game.content.dialogue.DialoguePlugin;
import core.game.content.global.Skillcape;
import core.game.content.global.action.DoorActionHandler;
import core.game.node.entity.skill.Skills;
import core.game.node.entity.skill.crafting.TanningProduct;
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.node.item.Item;
import core.game.node.scenery.Scenery;
import core.game.world.map.Location;
import core.plugin.Initializable;
import core.plugin.Plugin;
/**
* Represents the plugin used for the crafting guild.
* @author 'Vexia
* @version 1.0
*/
@Initializable
public final class CraftingGuildPlugin extends OptionHandler {
/**
* Represents the brown apron item.
*/
private static final Item BROWN_APRON = new Item(1757);
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
SceneryDefinition.forId(2647).getHandlers().put("option:open", this);
NPCDefinition.forId(804).getHandlers().put("option:trade", this);
new MasterCrafterDialogue().init();
new TannerDialogue().init();
return this;
}
@Override
public boolean handle(Player player, Node node, String option) {
final int id = node instanceof Scenery ? ((Scenery) node).getId() : ((NPC) node).getId();
switch (option) {
case "open":
switch (id) {
case 2647:
if (player.getLocation().getY() >= 3289) {
if (player.getSkills().getStaticLevel(Skills.CRAFTING) < 40) {
player.getDialogueInterpreter().sendDialogues(805, null, "Sorry, only experienced crafters are allowed in here.", "You must be level 40 or above to enter.");
return true;
}
if (!player.getEquipment().containsItem(BROWN_APRON)) {
player.getDialogueInterpreter().open(805, true, true);
return true;
}
player.getDialogueInterpreter().sendDialogues(805, null, "Welcome to the Guild of Master Craftsmen.");
DoorActionHandler.handleAutowalkDoor(player, (Scenery) node);
} else {
DoorActionHandler.handleAutowalkDoor(player, (Scenery) node);
return true;
}
break;
}
return true;
case "trade":
switch (id) {
case 804:
TanningProduct.open(player, 804);
break;
}
return true;
}
return true;
}
@Override
public Location getDestination(Node node, Node n) {
if (n instanceof Scenery) {
return DoorActionHandler.getDestination((Player) node, (Scenery) n);
}
return null;
}
/**
* Represents the dialogue plugin used for the crafting master.
* @author 'Vexia
* @version 1.0
*/
public final class MasterCrafterDialogue extends DialoguePlugin {
/**
* Constructs a new {@code MasterCrafterDialogue} {@code Object}.
*/
public MasterCrafterDialogue() {
/**
* empty.
*/
}
/**
* Constructs a new {@code MasterCrafterDialogue} {@code Object}.
* @param player the player.
*/
public MasterCrafterDialogue(final Player player) {
super(player);
}
@Override
public DialoguePlugin newInstance(Player player) {
return new MasterCrafterDialogue(player);
}
@Override
public boolean open(Object... args) {
if (args.length == 2) {
npc("Where's your brown apron? You can't come in here", "unless you're wearing one.");
stage = 100;
return true;
}
npc = (NPC) args[0];
npc("Hello, and welcome to the Crafting Guild. Accomplished", "crafters from all over the land come here to use our", "top notch workshops.");
stage = 0;
return true;
}
@Override
public boolean handle(int interfaceId, int buttonId) {
switch (stage) {
case 0:
if (npc.getId() == 805) {
if (Skillcape.isMaster(player, Skills.CRAFTING)) {
player("Hey, could I buy a Skillcape of Crafting?");
stage = 3;
} else {
player("Hey, what is that cape you're wearing?", "I don't recognise it.");
stage = 1;
}
} else {
end();
}
break;
case 1:
npc("This? This is a Skillcape of Crafting. It is a symbol of", "my ability and standing here in the Crafting Guild. If", "you should ever achieve level 99 Crafting come and talk", "to me and we'll see if we can sort you out with one.");
stage = 2;
break;
case 2:
end();
break;
case 3:
npc("Certainly! Right after you pay me 99000 coins.");
stage = 4;
break;
case 4:
options("Okay, here you go.", "No, thanks.");
stage = 5;
break;
case 5:
switch (buttonId) {
case 1:
player("Okay, here you go.");
stage = 6;
break;
case 2:
end();
break;
}
break;
case 6:
if (Skillcape.purchase(player, Skills.CRAFTING)) {
npc("There you go! Enjoy.");
}
stage = 7;
break;
case 7:
end();
break;
case 100:
npc("Where's your borwn apron? You can't come in here", "unless you're wearing one.");
stage = 101;
break;
case 101:
player("Err... I haven't got one.");
stage = 102;
break;
case 102:
end();
break;
}
return true;
}
@Override
public int[] getIds() {
return new int[] { 805, 2732, 2733 };
}
}
/**
* Represents the dialogue used for the tanner npc.
* @author 'Vexia
* @version 1.0
*/
public final class TannerDialogue extends DialoguePlugin {
/**
* Constructs a new {@code TannerDialogue} {@code Object}.
*/
public TannerDialogue() {
/**
* empty.
*/
}
/**
* Constructs a new {@code TannerDialogue} {@code Object}.
* @param player the player.
*/
public TannerDialogue(final Player player) {
super(player);
}
@Override
public DialoguePlugin newInstance(Player player) {
return new TannerDialogue(player);
}
@Override
public boolean open(Object... args) {
npc("Greetings friend. I am a manufacturer of leather.");
stage = 0;
return true;
}
@Override
public boolean handle(int interfaceId, int buttonId) {
switch (stage) {
case 0:
options("Can I buy some leather then?", "Leather is rather weak stuff.");
stage = 1;
break;
case 1:
switch (buttonId) {
case 1:
player("Can I buy some leather then?");
stage = 10;
break;
case 2:
player("Leather is rather weak stuff.");
stage = 20;
break;
}
break;
case 10:
npc("Certainly!");
stage = 11;
break;
case 11:
end();
TanningProduct.open(player, 804);
break;
case 20:
npc("Normal leather may be quite weak, but it's very cheap -", "I make it from cowhides for only 1 gp per hide - and", "it's so easy to craft that anyone can work with it.");
stage = 21;
break;
case 21:
npc("Alternatively you could try hard leather. It's not so", "easy to craft, but I only charge 3gp per cowhide to", "prepare it, and it makes much studier armour.");
stage = 22;
break;
case 22:
npc("I can also tan snake hides and dragonhides, suitable for", "crafting into the highest quality armour for rangers.");
stage = 23;
break;
case 23:
player("Thanks, I'll bear it in mind.");
stage = 24;
break;
case 24:
end();
break;
}
return true;
}
@Override
public int[] getIds() {
return new int[] { 804 };
}
}
}

View file

@ -0,0 +1,47 @@
package rs09.game.content.activity.guild.crafting
import api.*
import core.game.content.global.action.DoorActionHandler
import core.game.node.entity.skill.Skills
import core.game.world.map.Location
import org.rs09.consts.Items
import org.rs09.consts.Scenery
import rs09.game.content.dialogue.region.craftingguild.TheDoorDialogues
import rs09.game.interaction.InteractionListener
/**
* @author bushtail
*/
class CraftingGuildListeners : InteractionListener() {
private val GUILD_DOOR = Scenery.GUILD_DOOR_2647
private val APRON = Items.BROWN_APRON_1757
private val CAPE = Items.CRAFTING_CAPE_9780
override fun defineListeners() {
on(GUILD_DOOR, SCENERY, "open") { player, door ->
if (player.location == Location.create(2933, 3289, 0)) {
if (hasLevelStat(player, Skills.CRAFTING, 40)) {
if (inEquipment(player, APRON)) {
openDialogue(player, TheDoorDialogues(0))
DoorActionHandler.handleAutowalkDoor(player, door.asScenery())
return@on true
} else if (inEquipment(player, CAPE)) {
openDialogue(player, TheDoorDialogues(0))
DoorActionHandler.handleAutowalkDoor(player, door.asScenery())
return@on true
} else {
openDialogue(player, TheDoorDialogues(1))
return@on false
}
} else {
openDialogue(player, TheDoorDialogues(2))
return@on false
}
} else {
DoorActionHandler.handleAutowalkDoor(player, door.asScenery())
return@on true
}
}
}
}

View file

@ -0,0 +1,68 @@
package rs09.game.content.dialogue.region.craftingguild
import api.*
import core.game.content.dialogue.DialoguePlugin
import core.game.content.dialogue.FacialExpression
import core.game.node.entity.npc.NPC
import core.game.node.entity.player.Player
import core.game.node.entity.skill.Skills
import core.game.node.item.Item
import core.plugin.Initializable
import org.rs09.consts.Items
import org.rs09.consts.NPCs
import rs09.tools.END_DIALOGUE
/**
* @author bushtail
*/
@Initializable
class MasterCrafterDialogue(player: Player? = null) : DialoguePlugin(player) {
var CAPE = Items.CRAFTING_CAPE_9780
var COIN = Items.COINS_995
override fun newInstance(player: Player) : DialoguePlugin {
return MasterCrafterDialogue(player)
}
override fun open(vararg args: Any?) : Boolean {
npc = args[0] as NPC
stage = 0
return true
}
override fun handle(interfaceId: Int, buttonId: Int) : Boolean {
when(stage) {
0 -> if(hasLevelStat(player, Skills.CRAFTING, 99)) {
player(FacialExpression.ASKING, "Hey, could I buy a Skillcape of Crafting?").also{ stage = 10 }
} else {
player(FacialExpression.ASKING,"Hey, what is that cape you're wearing? I don't recognize it.").also { stage++ }
}
1 -> npcl(FacialExpression.FRIENDLY, "This? This is a Skillcape of Crafting. It is a symbol of my ability " +
"and standing here in the Crafting Guild. If you should ever achieve level 99 Crafting come and talk to me " +
"and we'll see if we can sort you out with one.").also{ stage = END_DIALOGUE }
10 -> npcl(FacialExpression.HAPPY, "Certainly! Right after you pay me 99000 coins.").also{ stage++ }
11 -> options("Okay, here you go.", "No thanks.").also{ stage++ }
12 -> when(buttonId) {
1 -> player(FacialExpression.FRIENDLY, "Okay, here you go.").also{ stage++ }
2 -> player(FacialExpression.HALF_THINKING, "No, thanks.").also{ stage = END_DIALOGUE }
}
13 -> if(inInventory(player, COIN, 99000)) {
removeItem(player, Item(COIN, 99000), Container.INVENTORY)
addItem(player, CAPE, 1)
npcl(FacialExpression.HAPPY, "There you go! Enjoy.").also{ stage = END_DIALOGUE }
} else {
npcl(FacialExpression.NEUTRAL, "You don't have enough coins for a cape.").also{ stage = END_DIALOGUE }
}
20 -> npcl(FacialExpression.NEUTRAL, "Where's your brown apron? You can't come in here unless you're wearing one.").also{ stage++ }
21 -> player(FacialExpression.HALF_GUILTY, "Err... I haven't got one.").also{ stage = END_DIALOGUE }
}
return true
}
override fun getIds() : IntArray {
return intArrayOf(NPCs.MASTER_CRAFTER_805)
}
}

View file

@ -0,0 +1,53 @@
package rs09.game.content.dialogue.region.craftingguild
import core.game.content.dialogue.DialoguePlugin
import core.game.content.dialogue.FacialExpression
import core.game.node.entity.npc.NPC
import core.game.node.entity.player.Player
import core.plugin.Initializable
import org.rs09.consts.NPCs
import rs09.tools.END_DIALOGUE
/**
* @author bushtail
*/
@Initializable
class TannerDialogue(player: Player? = null) : DialoguePlugin(player) {
override fun newInstance(player: Player) : DialoguePlugin {
return TannerDialogue(player)
}
override fun open(vararg args: Any?) : Boolean {
npc = args[0] as NPC
npcl(FacialExpression.NEUTRAL, "Greetings friend. I am a manufacturer of leather.")
stage = 0
return true
}
override fun handle(interfaceId: Int, buttonId: Int) : Boolean {
when(stage) {
0 -> options("Can I buy some leather then?", "Leather is rather weak stuff.").also{ stage++ }
1 -> when(buttonId) {
1 -> player(FacialExpression.ASKING,"Can I buy some leather then?").also{ stage = 10 }
2 -> player(FacialExpression.SUSPICIOUS, "Leather is rather weak stuff.").also { stage = 20 }
}
10 -> npcl(FacialExpression.FRIENDLY, "Certainly!").also { stage = END_DIALOGUE }.also{ npc.openShop(player) }
20 -> npcl(FacialExpression.NOD_YES, "Normal leather may be quite weak, but it's very cheap - I " +
"make it from cowhides for only 1 gp per hide - and it's so easy to craft that anyone can work with it.").also{ stage++ }
21 -> npcl(FacialExpression.HALF_THINKING, "Alternatively you could try hard leather. It's not so easy " +
"to craft, but I only charge 3 gp per cowhide to prepare it, and it makes much sturdier armour.").also{ stage++ }
22 -> npcl(FacialExpression.FRIENDLY, "I can also tan snake hides and dragonhides, suitable for crafting" +
"into the highest quality armour for rangers.").also{ stage++ }
23 -> player(FacialExpression.NEUTRAL, "Thanks, I'll bear it in mind.").also { stage = END_DIALOGUE }
}
return true
}
override fun getIds() : IntArray {
return intArrayOf(NPCs.TANNER_804)
}
}

View file

@ -0,0 +1,32 @@
package rs09.game.content.dialogue.region.craftingguild
import core.game.content.dialogue.FacialExpression
import core.game.node.entity.npc.NPC
import org.rs09.consts.NPCs
import rs09.game.content.dialogue.DialogueFile
import rs09.tools.END_DIALOGUE
/**
* @author bushtail
*/
class TheDoorDialogues(val it: Int) : DialogueFile() {
override fun handle(interfaceId: Int, buttonId: Int) {
npc = NPC(NPCs.MASTER_CRAFTER_805)
when(it) {
0 -> when(stage) {
0 -> npcl(FacialExpression.FRIENDLY, "Welcome to the Guild of Master craftsmen.").also{ stage = END_DIALOGUE }
}
1 -> when(stage) {
0 -> npcl(FacialExpression.ASKING, "Where's your brown apron? You can't come in here unless you're wearing one.").also{ stage++ }
1 -> player(FacialExpression.SAD, "Err... I haven't got one.").also { stage = END_DIALOGUE }
}
2 -> when(stage) {
0 -> npcl(FacialExpression.NEUTRAL, "Sorry, only experienced crafters are allowed in here. You must be level 40 or above to enter.").also{ stage = END_DIALOGUE }
}
}
}
}

View file

@ -10,10 +10,13 @@ import core.game.world.map.Location
import core.plugin.Initializable
import rs09.tools.END_DIALOGUE
/**
* @author bushtail
*/
@Initializable
class ZandarHorfyreDialogue(player: Player? = null) : DialoguePlugin(player) {
override fun newInstance(player: Player): DialoguePlugin {
override fun newInstance(player: Player) : DialoguePlugin {
return ZandarHorfyreDialogue(player)
}