Various bugfixes

This commit is contained in:
Ceikry
2021-03-16 21:53:58 -05:00
parent 96f38e4a0c
commit 85f4c973f5
9 changed files with 106 additions and 87 deletions
@@ -9,6 +9,8 @@ import core.game.node.entity.player.Player;
import core.game.node.entity.player.link.quest.Quest;
import core.game.node.item.Item;
import static rs09.tools.DialogueConstKt.END_DIALOGUE;
/**
* Handles the LadyOfTheLake dialogue.
*
@@ -52,7 +54,7 @@ public class TheLadyOfTheLake extends DialoguePlugin {
public boolean handle(int interfaceId, int buttonId) {
final Quest quest = player.getQuestRepository().getQuest("Merlin's Crystal");
switch (stage) {
case 999:
case END_DIALOGUE:
end();
break;
case 0:
@@ -75,13 +77,13 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break;
case 3:
player("Good day.");
stage = 999;
stage = END_DIALOGUE;
break;
}
break;
case 250:
npc("I am afraid I do not know what you are talking about.");
stage = 171;
stage = END_DIALOGUE;
break;
case 100:
npc("I am the Lady of the Lake.");
@@ -131,7 +133,7 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break;
case 117:
player("Thanks!");
stage = 999;
stage = END_DIALOGUE;
break;
case 145:
options("I seek the sword Excalibur.", "Good day.");
@@ -145,7 +147,7 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break;
case 2:
player("Good day.");
stage = 999;
stage = END_DIALOGUE;
break;
}
break;
@@ -181,12 +183,12 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break;
case 167:
npc("Well, come back when you do.");
stage = 999;
stage = END_DIALOGUE;
break;
case 168:
if (player.getInventory().freeSlots() == 0) {
player("Sorry, I don't seem to have enough inventory space.");
stage = 999;
stage = END_DIALOGUE;
} else if (player.getInventory().contains(995, 500)) {
player.getInventory().remove(new Item(995, 500));
player.getInventory().add(new Item(35, 1));
@@ -199,7 +201,7 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break;
case 170:
interpreter.sendDialogue("The lady of the Lake hands you Excalibur.");
stage = 999;
stage = END_DIALOGUE;
break;
case 300:
npc("'Tis very valuable, and not an artefact to be given", "away lightly.");
@@ -224,7 +226,7 @@ public class TheLadyOfTheLake extends DialoguePlugin {
case 305:
player("Ok. That seems easy enough.");
quest.setStage(player, 60);
stage = 171;
stage = END_DIALOGUE;
break;
case 699:
options("Who are you?", "Good day.");
@@ -238,13 +240,13 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break;
case 2:
player("Good day.");
stage = 999;
stage = END_DIALOGUE;
break;
}
break;
case 720:
npc("I am the Lady of the Lake.");
stage = 999;
stage = END_DIALOGUE;
break;
}
return true;
@@ -154,10 +154,10 @@ public class Fletching {
this.animation = animation;
switch(indicator & 0xFF){
case 1:
this.string = 1777;
this.string = org.rs09.consts.Items.BOW_STRING_1777;
break;
case 2:
this.string = 9438;
this.string = org.rs09.consts.Items.CROSSBOW_STRING_9438;
break;
}
}
@@ -97,6 +97,10 @@ public class RandomFunction {
return RANDOM.nextInt(maxValue);
}
public static final double randomDouble(double maxValue) {
return ThreadLocalRandom.current().nextDouble(0.0,maxValue);
}
public static final double randomDouble(double min, double max){
return ThreadLocalRandom.current().nextDouble(min,max);
}
@@ -1,46 +1,23 @@
package rs09.game.content.ame.events
import core.game.component.Component
import core.game.content.quest.PluginInteraction
import core.game.content.quest.PluginInteractionManager
import core.game.interaction.DestinationFlag
import core.game.interaction.MovementPulse
import core.game.interaction.Option
import core.game.node.entity.npc.NPC
import core.game.node.entity.player.Player
import rs09.game.world.GameWorld
import core.plugin.Initializable
import core.plugin.Plugin
import org.rs09.consts.NPCs
import rs09.game.interaction.InteractionListener
@Initializable
class SandwichLadyHandler : PluginInteraction(3117){
override fun handle(player: Player?, npc: NPC?, option: Option?): Boolean {
class MoveTo : MovementPulse(player,DestinationFlag.ENTITY.getDestination(player,npc)){
override fun pulse(): Boolean {
if(player?.antiMacroHandler?.hasEvent()!! && player.antiMacroHandler.event.name == "Sandwich Lady") {
player.interfaceManager?.open(Component(297))
npc?.clear()
} else {
player.sendMessage("She isn't interested in you.")
}
return true
class SandwichLadyHandler : InteractionListener(){
val SANDWICH_LADY = NPCs.SANDWICH_LADY_3117
override fun defineListeners() {
on(NPC,SANDWICH_LADY,"talk-to"){player, node ->
if(player.antiMacroHandler?.hasEvent()!! && player.antiMacroHandler.event.name == "Sandwich Lady") {
player.interfaceManager?.open(Component(297))
node.asNpc().clear()
} else {
player.sendMessage("She isn't interested in you.")
}
return@on true
}
if(option?.name?.toLowerCase() == "talk-to"){
GameWorld.submit(MoveTo())
return true
}
return false
}
override fun fireEvent(identifier: String?, vararg args: Any?): Any {
return Unit
}
override fun newInstance(arg: Any?): Plugin<Any> {
PluginInteractionManager.register(this,PluginInteractionManager.InteractionType.NPC)
return this
}
}
@@ -1,17 +1,13 @@
package rs09.game.content.ame.events
import core.game.component.Component
import core.game.component.ComponentDefinition
import core.game.component.ComponentPlugin
import core.game.node.entity.player.Player
import core.game.node.item.GroundItemManager
import core.game.node.item.Item
import core.plugin.Initializable
import core.plugin.Plugin
import org.rs09.consts.Items
import rs09.game.interaction.InterfaceListener
@Initializable
class SandwichLadyInterface : ComponentPlugin(){
class SandwichLadyInterface : InterfaceListener(){
val SANDWICH_INTERFACE = 297
val baguette = Items.BAGUETTE_6961
val triangle_sandwich = Items.TRIANGLE_SANDWICH_6962
val sandwich = Items.SQUARE_SANDWICH_6965
@@ -20,29 +16,27 @@ class SandwichLadyInterface : ComponentPlugin(){
val kebab = Items.KEBAB_1971
val chocobar = Items.CHOCOLATE_BAR_1973
override fun handle(player: Player?, component: Component?, opcode: Int, button: Int, slot: Int, itemId: Int): Boolean {
var item = Item(0)
when(button) {
7 -> {item = Item(baguette)}
8 -> {item = Item(triangle_sandwich)}
9 -> {item = Item(sandwich)}
10 -> {item = Item(roll)}
11 -> {item = Item(pie)}
12 -> {item = Item(kebab)}
13 -> {item = Item(chocobar)}
}
if(item.id != 0){
player?.let { if(it.inventory.add(item)) else GroundItemManager.create(item,it) }
player?.interfaceManager?.close()
player?.antiMacroHandler?.event?.terminate()
return true
}
return false
}
override fun defineListeners() {
on(SANDWICH_INTERFACE){player, _, _, buttonID, _, _ ->
val item =
when(buttonID) {
7 -> {Item(baguette)}
8 -> {Item(triangle_sandwich)}
9 -> {Item(sandwich)}
10 -> {Item(roll)}
11 -> {Item(pie)}
12 -> {Item(kebab)}
13 -> {Item(chocobar)}
else -> {Item(baguette)}
}
override fun newInstance(arg: Any?): Plugin<Any> {
ComponentDefinition.put(297,this)
return this
}
if(!player.inventory.add(item)){
GroundItemManager.create(item,player)
}
player.interfaceManager.close()
player.antiMacroHandler.event.terminate()
return@on true
}
}
}
@@ -0,0 +1,41 @@
package rs09.game.content.global
import core.game.node.entity.player.Player
import core.game.node.item.Item
import core.tools.RandomFunction
import org.rs09.consts.Items
private val CHARMS = intArrayOf(Items.CRIMSON_CHARM_12160,Items.BLUE_CHARM_12163,Items.GREEN_CHARM_12159,Items.GOLD_CHARM_12158)
class NPCDropTable : WeightBasedTable() {
val charmDrops = WeightBasedTable()
override fun add(element: WeightedItem): Boolean {
return if(CHARMS.contains(element.id)) charmDrops.add(element)
else super.add(element)
}
override fun roll(player: Player): ArrayList<Item> {
val items= ArrayList<Item>(3)
var tempWeight = RandomFunction.randomDouble(totalWeight)
items.addAll(guaranteedItems.map { it.getItem() }.toList())
if(RandomFunction.random(1,15) == 5){
items.addAll(charmDrops.roll(player))
}
if(size == 1){
items.add(get(0).getItem())
return items
}
if(isNotEmpty()) {
for (item in shuffled()) {
tempWeight -= item.weight
if (tempWeight <= 0) {
items.add(item.getItem())
break
}
}
}
return items
}
}
@@ -2,8 +2,9 @@ package rs09.game.content.global
import core.game.node.entity.player.Player
import core.game.node.item.Item
import core.tools.RandomFunction
class WeightBasedTable : ArrayList<WeightedItem>() {
open class WeightBasedTable : ArrayList<WeightedItem>() {
var totalWeight = 0.0
val guaranteedItems = ArrayList<WeightedItem>(5)
@@ -13,9 +14,9 @@ class WeightBasedTable : ArrayList<WeightedItem>() {
else super.add(element)
}
fun roll(player: Player): ArrayList<Item>{
open fun roll(player: Player): ArrayList<Item>{
val items= ArrayList<Item>(3)
var tempWeight = totalWeight
var tempWeight = RandomFunction.randomDouble(totalWeight)
items.addAll(guaranteedItems.map { it.getItem() }.toList())
if(player.inventory.isFull){
@@ -34,7 +35,7 @@ class WeightBasedTable : ArrayList<WeightedItem>() {
return items
}
fun canRoll(player: Player): Boolean{
open fun canRoll(player: Player): Boolean{
val guaranteed = guaranteedItems.map { it.getItem() }.toTypedArray()
return (player.inventory.hasSpaceFor(*guaranteed) && guaranteed.isNotEmpty()) || !player.inventory.isFull
}
@@ -113,7 +113,7 @@ class DukeHoracioTLTDialogue(val questStage: Int) : DialogueFile() {
}
}
else if(stage == 44){
else if(questStage == 44){
when(stage){
START_DIALOGUE -> player(
"I spoke to the goblin generals in the goblin village. They",
@@ -35,7 +35,7 @@ class FletchingListeners : InteractionListener() {
val UNFINISHED_ARROWS = Fletching.ArrowHeads.values().map(Fletching.ArrowHeads::unfinished).toIntArray()
val FEATHERS = intArrayOf(FEATHER_314,STRIPY_FEATHER_10087,RED_FEATHER_10088,BLUE_FEATHER_10089,YELLOW_FEATHER_10090,ORANGE_FEATHER_10091)
val UNSTRUNG_BOWS = Fletching.String.values().map(Fletching.String::unfinished).toIntArray()
val STRINGS = intArrayOf(Items.BOW_STRING_1777,Items.SINEW_9436)
val STRINGS = intArrayOf(Items.BOW_STRING_1777,Items.CROSSBOW_STRING_9438)
override fun defineListeners() {