Some more improvements to ContentAPI, more stuff converted
This commit is contained in:
@@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import core.cache.def.impl.ItemDefinition
|
import core.cache.def.impl.ItemDefinition
|
||||||
import core.game.component.Component
|
import core.game.component.Component
|
||||||
|
import core.game.content.dialogue.FacialExpression
|
||||||
import core.game.node.Node
|
import core.game.node.Node
|
||||||
import core.game.node.`object`.GameObject
|
import core.game.node.`object`.GameObject
|
||||||
import core.game.node.`object`.ObjectBuilder
|
import core.game.node.`object`.ObjectBuilder
|
||||||
@@ -833,4 +834,68 @@ object ContentAPI {
|
|||||||
Container.INVENTORY -> player.inventory.remove(Item(it, amountInInventory(player, it)))
|
Container.INVENTORY -> player.inventory.remove(Item(it, amountInInventory(player, it)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a string to a specific interface child
|
||||||
|
* @param player the player to send the packet to
|
||||||
|
* @param string the string to send to the child
|
||||||
|
* @param iface the ID of the interface to use
|
||||||
|
* @param child the index of the child to send the string to
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun setInterfaceText(player: Player, string: String, iface: Int, child: Int){
|
||||||
|
player.packetDispatch.sendString(string,iface,child)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes any open (non-chat) interfaces for the player
|
||||||
|
* @param player the player to close the interface for
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun closeInterface(player: Player){
|
||||||
|
player.interfaceManager.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes any opened tab interfaces for the player
|
||||||
|
* @param player the player to close the tab for
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun closeTabInterface(player: Player){
|
||||||
|
player.interfaceManager.closeSingleTab()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a dialogue that uses the player's chathead.
|
||||||
|
* @param player the player to send the dialogue to
|
||||||
|
* @param msg the message to send.
|
||||||
|
* @param expr the FacialExpression to use. An enum exists for these called FacialExpression. Defaults to FacialExpression.FRIENDLY
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun sendPlayerDialogue(player: Player, msg: String, expr: FacialExpression = FacialExpression.FRIENDLY){
|
||||||
|
player.dialogueInterpreter.sendDialogues(player, expr, *DialUtils.splitLines(msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a player model to a specific interface child
|
||||||
|
* @param player the player to send the packet to and whose model to use
|
||||||
|
* @param iface the ID of the interface to send it to
|
||||||
|
* @param child the index of the child on the interface to send the model to
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun sendPlayerOnInterface(player: Player, iface: Int, child: Int){
|
||||||
|
player.packetDispatch.sendPlayerOnInterface(iface,child)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an animation to a specific interface child
|
||||||
|
* @param player the player to send the packet to
|
||||||
|
* @param anim the ID of the animation to send to the interface
|
||||||
|
* @param iface the ID of the interface to send the animation to
|
||||||
|
* @param child the index of the child on the interface to send the model to
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun sendAnimationOnInterface(player: Player, anim: Int, iface: Int, child: Int){
|
||||||
|
player.packetDispatch.sendAnimationInterface(anim,iface,child)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package rs09.game.interaction.inter
|
package rs09.game.interaction.inter
|
||||||
|
|
||||||
|
import api.ContentAPI
|
||||||
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 org.rs09.consts.Components
|
import org.rs09.consts.Components
|
||||||
@@ -16,7 +17,7 @@ class CreditShopInterface : InterfaceListener() {
|
|||||||
val item = getItem(buttonID)
|
val item = getItem(buttonID)
|
||||||
|
|
||||||
if(opcode == 155){
|
if(opcode == 155){
|
||||||
player.dialogueInterpreter.sendDialogue("This item costs ${item.price} credits.")
|
ContentAPI.sendDialogue(player, "This item costs ${item.price} credits.")
|
||||||
return@on true
|
return@on true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,19 +59,19 @@ class CreditShopInterface : InterfaceListener() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun sendCredits(player: Player){
|
fun sendCredits(player: Player){
|
||||||
player.packetDispatch.sendString("You have ${player.details.credits} credits to spend.",CREDIT_SHOP,TEXT_CHILD)
|
ContentAPI.setInterfaceText(player, "You have ${player.details.credits} credits to spend.", CREDIT_SHOP, TEXT_CHILD)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun attemptPurchase(player: Player, item: Int, price: Int){
|
fun attemptPurchase(player: Player, item: Int, price: Int){
|
||||||
if(player.details.credits < price){
|
if(player.details.credits < price){
|
||||||
player.dialogueInterpreter.sendDialogue("You don't have enough credits for that.")
|
ContentAPI.sendDialogue(player, "You don't have enough credits for that.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if(player.inventory.add(Item(item))){
|
if(player.inventory.add(Item(item))){
|
||||||
player.details.credits -= price
|
player.details.credits -= price
|
||||||
} else {
|
} else {
|
||||||
player.dialogueInterpreter.sendDialogue("You don't have enough inventory space for that.")
|
ContentAPI.sendDialogue(player, "You don't have enough inventory space for that.")
|
||||||
}
|
}
|
||||||
sendCredits(player)
|
sendCredits(player)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package rs09.game.interaction.inter
|
package rs09.game.interaction.inter
|
||||||
|
|
||||||
|
import api.ContentAPI
|
||||||
import core.game.component.Component
|
import core.game.component.Component
|
||||||
import core.game.component.ComponentDefinition
|
import core.game.component.ComponentDefinition
|
||||||
import core.game.component.ComponentPlugin
|
import core.game.component.ComponentPlugin
|
||||||
@@ -40,8 +41,8 @@ class ExperienceInterface() : ComponentPlugin() {
|
|||||||
if(caller is Plugin<*>)
|
if(caller is Plugin<*>)
|
||||||
caller.handleSelectionCallback(confirmedSkill, player)
|
caller.handleSelectionCallback(confirmedSkill, player)
|
||||||
else (caller as (Int,Player) -> Unit).invoke(confirmedSkill,player)
|
else (caller as (Int,Player) -> Unit).invoke(confirmedSkill,player)
|
||||||
player.audioManager.send(SOUND)
|
ContentAPI.playAudio(player, SOUND)
|
||||||
player.interfaceManager.close()
|
ContentAPI.closeInterface(player)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val skill = when (button) {
|
val skill = when (button) {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package rs09.game.interaction.inter
|
package rs09.game.interaction.inter
|
||||||
|
|
||||||
|
import api.ContentAPI
|
||||||
import core.game.component.Component
|
import core.game.component.Component
|
||||||
|
import core.game.content.dialogue.FacialExpression
|
||||||
import core.game.node.entity.player.Player
|
import core.game.node.entity.player.Player
|
||||||
import core.game.node.entity.player.link.TeleportManager
|
import core.game.node.entity.player.link.TeleportManager
|
||||||
import core.game.system.task.Pulse
|
import core.game.system.task.Pulse
|
||||||
@@ -35,13 +37,13 @@ class FairyRingInterface : InterfaceListener(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
onClose(RINGS){player, _ ->
|
onClose(RINGS){player, _ ->
|
||||||
player.interfaceManager.closeSingleTab()
|
ContentAPI.closeTabInterface(player)
|
||||||
player.removeAttribute("fr:ring1")
|
player.removeAttribute("fr:ring1")
|
||||||
player.removeAttribute("fr:ring2")
|
player.removeAttribute("fr:ring2")
|
||||||
player.removeAttribute("fr:ring3")
|
player.removeAttribute("fr:ring3")
|
||||||
player.varpManager.get(816).clearBitRange(0,31)
|
ContentAPI.clearVarp(player, 816)
|
||||||
player.varpManager.get(816).send(player)
|
ContentAPI.setVarbit(player, 816, 0, 0)
|
||||||
player.interfaceManager.closeSingleTab()
|
ContentAPI.closeTabInterface(player)
|
||||||
return@onClose true
|
return@onClose true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +76,7 @@ class FairyRingInterface : InterfaceListener(){
|
|||||||
toSet = !toSet
|
toSet = !toSet
|
||||||
player.setAttribute("fr:sortorder",toSet)
|
player.setAttribute("fr:sortorder",toSet)
|
||||||
if(toSet) {
|
if(toSet) {
|
||||||
player.configManager.forceSet(816, ring1index, false)
|
ContentAPI.setVarbit(player, 816, 0, ring1index)
|
||||||
player.setAttribute("fr:ring2",0)
|
player.setAttribute("fr:ring2",0)
|
||||||
player.setAttribute("fr:ring3",0)
|
player.setAttribute("fr:ring3",0)
|
||||||
}
|
}
|
||||||
@@ -108,7 +110,7 @@ class FairyRingInterface : InterfaceListener(){
|
|||||||
val ring: FairyRing? = FairyRing.valueOf(code.toUpperCase())
|
val ring: FairyRing? = FairyRing.valueOf(code.toUpperCase())
|
||||||
var tile = ring?.tile
|
var tile = ring?.tile
|
||||||
if(ring == FairyRing.CIP){
|
if(ring == FairyRing.CIP){
|
||||||
player.dialogueInterpreter.sendDialogue("The ring seems to reject you.")
|
ContentAPI.sendDialogue(player, "The ring seems to reject you.")
|
||||||
}
|
}
|
||||||
if (ring == null || tile == null) {
|
if (ring == null || tile == null) {
|
||||||
val center = Location(2412, 4434, 0)
|
val center = Location(2412, 4434, 0)
|
||||||
@@ -122,7 +124,7 @@ class FairyRingInterface : InterfaceListener(){
|
|||||||
}
|
}
|
||||||
GameWorld.Pulser.submit(object : Pulse(4, player) {
|
GameWorld.Pulser.submit(object : Pulse(4, player) {
|
||||||
override fun pulse(): Boolean {
|
override fun pulse(): Boolean {
|
||||||
player.dialogueInterpreter.sendDialogues(player, null, "Wow, fairy magic sure is useful, I hardly moved at all!")
|
ContentAPI.sendPlayerDialogue(player, "Wow, fairy magic sure is useful, I hardly moved at all!", FacialExpression.AMAZED)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -131,8 +133,8 @@ class FairyRingInterface : InterfaceListener(){
|
|||||||
player.savedData.globalData.setTravelLog(ring.ordinal)
|
player.savedData.globalData.setTravelLog(ring.ordinal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.interfaceManager.close()
|
ContentAPI.closeInterface(player)
|
||||||
player.teleporter.send(tile,TeleportManager.TeleportType.FAIRY_RING)
|
ContentAPI.teleport(player, tile!!, TeleportManager.TeleportType.FAIRY_RING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +192,7 @@ enum class FairyRing(val tile: Location?, val tip: String = "", val childId: Int
|
|||||||
if (ring.childId == -1) {
|
if (ring.childId == -1) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
player.packetDispatch.sendString("<br>" + ring.tip, 735, ring.childId)
|
ContentAPI.setInterfaceText(player, "<br>${ring.tip}", 735, ring.childId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package rs09.game.interaction.inter
|
package rs09.game.interaction.inter
|
||||||
|
|
||||||
|
import api.ContentAPI
|
||||||
import core.game.component.Component
|
import core.game.component.Component
|
||||||
import core.game.component.ComponentDefinition
|
import core.game.component.ComponentDefinition
|
||||||
import core.game.component.ComponentPlugin
|
import core.game.component.ComponentPlugin
|
||||||
@@ -96,8 +97,8 @@ class FurClothingInterface : ComponentPlugin(){
|
|||||||
val checkedFurs = arrayListOf<String>()
|
val checkedFurs = arrayListOf<String>()
|
||||||
for(CLOTHING in FUR_CLOTHING.values()){
|
for(CLOTHING in FUR_CLOTHING.values()){
|
||||||
if(checkedFurs.contains(CLOTHING.textContent)) continue
|
if(checkedFurs.contains(CLOTHING.textContent)) continue
|
||||||
if(player.inventory.containsItem(CLOTHING.requiredFur)){
|
if(ContentAPI.inInventory(player, CLOTHING.requiredFur.id, CLOTHING.requiredFur.amount)){
|
||||||
player.packetDispatch.sendString(colorize("%G" + CLOTHING.textContent), FUR_CLOTHING_COMPONENT_ID,CLOTHING.textChildID)
|
ContentAPI.setInterfaceText(player, colorize("%G${CLOTHING.textContent}"), FUR_CLOTHING_COMPONENT_ID, CLOTHING.textChildID)
|
||||||
checkedFurs.add(CLOTHING.textContent)
|
checkedFurs.add(CLOTHING.textContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,7 +144,7 @@ class FurClothingInterface : ComponentPlugin(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun value(player: Player, clothing: FUR_CLOTHING){
|
private fun value(player: Player, clothing: FUR_CLOTHING){
|
||||||
player.sendMessage("${clothing.product.name} requires ${clothing.requiredFur.amount} ${clothing.requiredFur.name.toLowerCase()} and costs ${clothing.price} coins.")
|
ContentAPI.sendMessage(player,"${clothing.product.name} requires ${clothing.requiredFur.amount} ${clothing.requiredFur.name.toLowerCase()} and costs ${clothing.price} coins.")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buy(player: Player, clothing: FUR_CLOTHING, amount: Int){
|
private fun buy(player: Player, clothing: FUR_CLOTHING, amount: Int){
|
||||||
@@ -151,19 +152,19 @@ class FurClothingInterface : ComponentPlugin(){
|
|||||||
val amtFurRequired = clothing.requiredFur.amount * amount
|
val amtFurRequired = clothing.requiredFur.amount * amount
|
||||||
val requiredFur = Item(clothing.requiredFur.id,amtFurRequired)
|
val requiredFur = Item(clothing.requiredFur.id,amtFurRequired)
|
||||||
|
|
||||||
if(!player.inventory.containsItem(requiredFur)){
|
if(!ContentAPI.inInventory(player, requiredFur.id, requiredFur.amount)){
|
||||||
player.dialogueInterpreter.sendDialogue("You don't have enough fur for that.")
|
ContentAPI.sendDialogue(player, "You don't have enough fur for that.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!player.inventory.containsItem(coins)){
|
if(!ContentAPI.inInventory(player, coins.id, coins.amount)){
|
||||||
player.dialogueInterpreter.sendDialogue("You can't afford that.")
|
ContentAPI.sendDialogue(player,"You can't afford that.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
player.inventory.remove(requiredFur)
|
ContentAPI.removeItem(player, requiredFur, api.Container.INVENTORY)
|
||||||
player.inventory.remove(coins)
|
ContentAPI.removeItem(player, coins, api.Container.INVENTORY)
|
||||||
player.inventory.add(Item(clothing.product.id,amount))
|
ContentAPI.addItem(player, clothing.product.id, amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun newInstance(arg: Any?): Plugin<Any> {
|
override fun newInstance(arg: Any?): Plugin<Any> {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package rs09.game.interaction.inter
|
package rs09.game.interaction.inter
|
||||||
|
|
||||||
|
import api.ContentAPI
|
||||||
import core.game.component.Component
|
import core.game.component.Component
|
||||||
import core.game.component.ComponentDefinition
|
import core.game.component.ComponentDefinition
|
||||||
import core.game.component.ComponentPlugin
|
import core.game.component.ComponentPlugin
|
||||||
@@ -141,9 +142,9 @@ class HairDresserInterface : ComponentPlugin(){
|
|||||||
HAIRDRESSER_MALE_COMPONENT_ID -> 61
|
HAIRDRESSER_MALE_COMPONENT_ID -> 61
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
player.packetDispatch.sendPlayerOnInterface(usedInterface,player_model_child)
|
ContentAPI.sendPlayerOnInterface(player, usedInterface, player_model_child)
|
||||||
player.packetDispatch.sendAnimationInterface(FacialExpression.HAPPY.animationId,usedInterface,player_head_child)
|
ContentAPI.sendPlayerOnInterface(player, usedInterface, player_head_child)
|
||||||
player.packetDispatch.sendPlayerOnInterface(usedInterface,player_head_child)
|
ContentAPI.sendAnimationOnInterface(player, FacialExpression.HAPPY.animationId, usedInterface, player_head_child)
|
||||||
player.toggleWardrobe(true)
|
player.toggleWardrobe(true)
|
||||||
|
|
||||||
component?.setCloseEvent{pl,_ ->
|
component?.setCloseEvent{pl,_ ->
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package rs09.game.interaction.inter
|
package rs09.game.interaction.inter
|
||||||
|
|
||||||
|
import api.ContentAPI
|
||||||
import core.game.component.CloseEvent
|
import core.game.component.CloseEvent
|
||||||
import core.game.component.Component
|
import core.game.component.Component
|
||||||
import core.game.content.quest.tutorials.tutorialisland.TutorialSession
|
import core.game.content.quest.tutorials.tutorialisland.TutorialSession
|
||||||
@@ -32,12 +33,12 @@ class MainGameInterface : InterfaceListener() {
|
|||||||
|
|
||||||
on(TOPLEVEL_FS){player, _, _, buttonID, _, _ ->
|
on(TOPLEVEL_FS){player, _, _, buttonID, _, _ ->
|
||||||
when (buttonID) {
|
when (buttonID) {
|
||||||
12 -> player.packetDispatch.sendString(
|
12 -> ContentAPI.setInterfaceText(player,
|
||||||
"When you have finished playing " + settings!!.name + ", always use the button below to logout safely. ",
|
"When you have finished playing " + settings!!.name + ", always use the button below to logout safely. ",
|
||||||
182,
|
182,
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
49 -> player.packetDispatch.sendString(
|
49 -> ContentAPI.setInterfaceText(player,
|
||||||
"Friends List - " + settings!!.name + " " + settings!!.worldId,
|
"Friends List - " + settings!!.name + " " + settings!!.worldId,
|
||||||
550,
|
550,
|
||||||
3
|
3
|
||||||
|
|||||||
Reference in New Issue
Block a user