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.entity.player.link.quest.Quest;
import core.game.node.item.Item; import core.game.node.item.Item;
import static rs09.tools.DialogueConstKt.END_DIALOGUE;
/** /**
* Handles the LadyOfTheLake dialogue. * Handles the LadyOfTheLake dialogue.
* *
@@ -52,7 +54,7 @@ public class TheLadyOfTheLake extends DialoguePlugin {
public boolean handle(int interfaceId, int buttonId) { public boolean handle(int interfaceId, int buttonId) {
final Quest quest = player.getQuestRepository().getQuest("Merlin's Crystal"); final Quest quest = player.getQuestRepository().getQuest("Merlin's Crystal");
switch (stage) { switch (stage) {
case 999: case END_DIALOGUE:
end(); end();
break; break;
case 0: case 0:
@@ -75,13 +77,13 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break; break;
case 3: case 3:
player("Good day."); player("Good day.");
stage = 999; stage = END_DIALOGUE;
break; break;
} }
break; break;
case 250: case 250:
npc("I am afraid I do not know what you are talking about."); npc("I am afraid I do not know what you are talking about.");
stage = 171; stage = END_DIALOGUE;
break; break;
case 100: case 100:
npc("I am the Lady of the Lake."); npc("I am the Lady of the Lake.");
@@ -131,7 +133,7 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break; break;
case 117: case 117:
player("Thanks!"); player("Thanks!");
stage = 999; stage = END_DIALOGUE;
break; break;
case 145: case 145:
options("I seek the sword Excalibur.", "Good day."); options("I seek the sword Excalibur.", "Good day.");
@@ -145,7 +147,7 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break; break;
case 2: case 2:
player("Good day."); player("Good day.");
stage = 999; stage = END_DIALOGUE;
break; break;
} }
break; break;
@@ -181,12 +183,12 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break; break;
case 167: case 167:
npc("Well, come back when you do."); npc("Well, come back when you do.");
stage = 999; stage = END_DIALOGUE;
break; break;
case 168: case 168:
if (player.getInventory().freeSlots() == 0) { if (player.getInventory().freeSlots() == 0) {
player("Sorry, I don't seem to have enough inventory space."); player("Sorry, I don't seem to have enough inventory space.");
stage = 999; stage = END_DIALOGUE;
} else if (player.getInventory().contains(995, 500)) { } else if (player.getInventory().contains(995, 500)) {
player.getInventory().remove(new Item(995, 500)); player.getInventory().remove(new Item(995, 500));
player.getInventory().add(new Item(35, 1)); player.getInventory().add(new Item(35, 1));
@@ -199,7 +201,7 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break; break;
case 170: case 170:
interpreter.sendDialogue("The lady of the Lake hands you Excalibur."); interpreter.sendDialogue("The lady of the Lake hands you Excalibur.");
stage = 999; stage = END_DIALOGUE;
break; break;
case 300: case 300:
npc("'Tis very valuable, and not an artefact to be given", "away lightly."); npc("'Tis very valuable, and not an artefact to be given", "away lightly.");
@@ -224,7 +226,7 @@ public class TheLadyOfTheLake extends DialoguePlugin {
case 305: case 305:
player("Ok. That seems easy enough."); player("Ok. That seems easy enough.");
quest.setStage(player, 60); quest.setStage(player, 60);
stage = 171; stage = END_DIALOGUE;
break; break;
case 699: case 699:
options("Who are you?", "Good day."); options("Who are you?", "Good day.");
@@ -238,13 +240,13 @@ public class TheLadyOfTheLake extends DialoguePlugin {
break; break;
case 2: case 2:
player("Good day."); player("Good day.");
stage = 999; stage = END_DIALOGUE;
break; break;
} }
break; break;
case 720: case 720:
npc("I am the Lady of the Lake."); npc("I am the Lady of the Lake.");
stage = 999; stage = END_DIALOGUE;
break; break;
} }
return true; return true;
@@ -154,10 +154,10 @@ public class Fletching {
this.animation = animation; this.animation = animation;
switch(indicator & 0xFF){ switch(indicator & 0xFF){
case 1: case 1:
this.string = 1777; this.string = org.rs09.consts.Items.BOW_STRING_1777;
break; break;
case 2: case 2:
this.string = 9438; this.string = org.rs09.consts.Items.CROSSBOW_STRING_9438;
break; break;
} }
} }
@@ -97,6 +97,10 @@ public class RandomFunction {
return RANDOM.nextInt(maxValue); 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){ public static final double randomDouble(double min, double max){
return ThreadLocalRandom.current().nextDouble(min,max); return ThreadLocalRandom.current().nextDouble(min,max);
} }
@@ -1,46 +1,23 @@
package rs09.game.content.ame.events package rs09.game.content.ame.events
import core.game.component.Component 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.Initializable
import core.plugin.Plugin import org.rs09.consts.NPCs
import rs09.game.interaction.InteractionListener
@Initializable class SandwichLadyHandler : InteractionListener(){
class SandwichLadyHandler : PluginInteraction(3117){
override fun handle(player: Player?, npc: NPC?, option: Option?): Boolean { val SANDWICH_LADY = NPCs.SANDWICH_LADY_3117
class MoveTo : MovementPulse(player,DestinationFlag.ENTITY.getDestination(player,npc)){ override fun defineListeners() {
override fun pulse(): Boolean {
if(player?.antiMacroHandler?.hasEvent()!! && player.antiMacroHandler.event.name == "Sandwich Lady") { on(NPC,SANDWICH_LADY,"talk-to"){player, node ->
player.interfaceManager?.open(Component(297)) if(player.antiMacroHandler?.hasEvent()!! && player.antiMacroHandler.event.name == "Sandwich Lady") {
npc?.clear() player.interfaceManager?.open(Component(297))
} else { node.asNpc().clear()
player.sendMessage("She isn't interested in you.") } else {
} player.sendMessage("She isn't interested in you.")
return true
} }
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 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.GroundItemManager
import core.game.node.item.Item import core.game.node.item.Item
import core.plugin.Initializable
import core.plugin.Plugin
import org.rs09.consts.Items import org.rs09.consts.Items
import rs09.game.interaction.InterfaceListener
@Initializable class SandwichLadyInterface : InterfaceListener(){
class SandwichLadyInterface : ComponentPlugin(){
val SANDWICH_INTERFACE = 297
val baguette = Items.BAGUETTE_6961 val baguette = Items.BAGUETTE_6961
val triangle_sandwich = Items.TRIANGLE_SANDWICH_6962 val triangle_sandwich = Items.TRIANGLE_SANDWICH_6962
val sandwich = Items.SQUARE_SANDWICH_6965 val sandwich = Items.SQUARE_SANDWICH_6965
@@ -20,29 +16,27 @@ class SandwichLadyInterface : ComponentPlugin(){
val kebab = Items.KEBAB_1971 val kebab = Items.KEBAB_1971
val chocobar = Items.CHOCOLATE_BAR_1973 val chocobar = Items.CHOCOLATE_BAR_1973
override fun handle(player: Player?, component: Component?, opcode: Int, button: Int, slot: Int, itemId: Int): Boolean { override fun defineListeners() {
var item = Item(0) on(SANDWICH_INTERFACE){player, _, _, buttonID, _, _ ->
when(button) { val item =
7 -> {item = Item(baguette)} when(buttonID) {
8 -> {item = Item(triangle_sandwich)} 7 -> {Item(baguette)}
9 -> {item = Item(sandwich)} 8 -> {Item(triangle_sandwich)}
10 -> {item = Item(roll)} 9 -> {Item(sandwich)}
11 -> {item = Item(pie)} 10 -> {Item(roll)}
12 -> {item = Item(kebab)} 11 -> {Item(pie)}
13 -> {item = Item(chocobar)} 12 -> {Item(kebab)}
} 13 -> {Item(chocobar)}
if(item.id != 0){ else -> {Item(baguette)}
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 newInstance(arg: Any?): Plugin<Any> { if(!player.inventory.add(item)){
ComponentDefinition.put(297,this) GroundItemManager.create(item,player)
return this }
}
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.entity.player.Player
import core.game.node.item.Item import core.game.node.item.Item
import core.tools.RandomFunction
class WeightBasedTable : ArrayList<WeightedItem>() { open class WeightBasedTable : ArrayList<WeightedItem>() {
var totalWeight = 0.0 var totalWeight = 0.0
val guaranteedItems = ArrayList<WeightedItem>(5) val guaranteedItems = ArrayList<WeightedItem>(5)
@@ -13,9 +14,9 @@ class WeightBasedTable : ArrayList<WeightedItem>() {
else super.add(element) else super.add(element)
} }
fun roll(player: Player): ArrayList<Item>{ open fun roll(player: Player): ArrayList<Item>{
val items= ArrayList<Item>(3) val items= ArrayList<Item>(3)
var tempWeight = totalWeight var tempWeight = RandomFunction.randomDouble(totalWeight)
items.addAll(guaranteedItems.map { it.getItem() }.toList()) items.addAll(guaranteedItems.map { it.getItem() }.toList())
if(player.inventory.isFull){ if(player.inventory.isFull){
@@ -34,7 +35,7 @@ class WeightBasedTable : ArrayList<WeightedItem>() {
return items return items
} }
fun canRoll(player: Player): Boolean{ open fun canRoll(player: Player): Boolean{
val guaranteed = guaranteedItems.map { it.getItem() }.toTypedArray() val guaranteed = guaranteedItems.map { it.getItem() }.toTypedArray()
return (player.inventory.hasSpaceFor(*guaranteed) && guaranteed.isNotEmpty()) || !player.inventory.isFull 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){ when(stage){
START_DIALOGUE -> player( START_DIALOGUE -> player(
"I spoke to the goblin generals in the goblin village. They", "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 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 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 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() { override fun defineListeners() {