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.game.component.Component
|
||||
import core.game.content.dialogue.FacialExpression
|
||||
import core.game.node.Node
|
||||
import core.game.node.`object`.GameObject
|
||||
import core.game.node.`object`.ObjectBuilder
|
||||
@@ -833,4 +834,68 @@ object ContentAPI {
|
||||
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
|
||||
|
||||
import api.ContentAPI
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.item.Item
|
||||
import org.rs09.consts.Components
|
||||
@@ -16,7 +17,7 @@ class CreditShopInterface : InterfaceListener() {
|
||||
val item = getItem(buttonID)
|
||||
|
||||
if(opcode == 155){
|
||||
player.dialogueInterpreter.sendDialogue("This item costs ${item.price} credits.")
|
||||
ContentAPI.sendDialogue(player, "This item costs ${item.price} credits.")
|
||||
return@on true
|
||||
}
|
||||
|
||||
@@ -58,19 +59,19 @@ class CreditShopInterface : InterfaceListener() {
|
||||
}
|
||||
|
||||
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){
|
||||
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
|
||||
}
|
||||
|
||||
if(player.inventory.add(Item(item))){
|
||||
player.details.credits -= price
|
||||
} 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)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package rs09.game.interaction.inter
|
||||
|
||||
import api.ContentAPI
|
||||
import core.game.component.Component
|
||||
import core.game.component.ComponentDefinition
|
||||
import core.game.component.ComponentPlugin
|
||||
@@ -40,8 +41,8 @@ class ExperienceInterface() : ComponentPlugin() {
|
||||
if(caller is Plugin<*>)
|
||||
caller.handleSelectionCallback(confirmedSkill, player)
|
||||
else (caller as (Int,Player) -> Unit).invoke(confirmedSkill,player)
|
||||
player.audioManager.send(SOUND)
|
||||
player.interfaceManager.close()
|
||||
ContentAPI.playAudio(player, SOUND)
|
||||
ContentAPI.closeInterface(player)
|
||||
}
|
||||
} else {
|
||||
val skill = when (button) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package rs09.game.interaction.inter
|
||||
|
||||
import api.ContentAPI
|
||||
import core.game.component.Component
|
||||
import core.game.content.dialogue.FacialExpression
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.entity.player.link.TeleportManager
|
||||
import core.game.system.task.Pulse
|
||||
@@ -35,13 +37,13 @@ class FairyRingInterface : InterfaceListener(){
|
||||
}
|
||||
|
||||
onClose(RINGS){player, _ ->
|
||||
player.interfaceManager.closeSingleTab()
|
||||
ContentAPI.closeTabInterface(player)
|
||||
player.removeAttribute("fr:ring1")
|
||||
player.removeAttribute("fr:ring2")
|
||||
player.removeAttribute("fr:ring3")
|
||||
player.varpManager.get(816).clearBitRange(0,31)
|
||||
player.varpManager.get(816).send(player)
|
||||
player.interfaceManager.closeSingleTab()
|
||||
ContentAPI.clearVarp(player, 816)
|
||||
ContentAPI.setVarbit(player, 816, 0, 0)
|
||||
ContentAPI.closeTabInterface(player)
|
||||
return@onClose true
|
||||
}
|
||||
|
||||
@@ -74,7 +76,7 @@ class FairyRingInterface : InterfaceListener(){
|
||||
toSet = !toSet
|
||||
player.setAttribute("fr:sortorder",toSet)
|
||||
if(toSet) {
|
||||
player.configManager.forceSet(816, ring1index, false)
|
||||
ContentAPI.setVarbit(player, 816, 0, ring1index)
|
||||
player.setAttribute("fr:ring2",0)
|
||||
player.setAttribute("fr:ring3",0)
|
||||
}
|
||||
@@ -108,7 +110,7 @@ class FairyRingInterface : InterfaceListener(){
|
||||
val ring: FairyRing? = FairyRing.valueOf(code.toUpperCase())
|
||||
var tile = ring?.tile
|
||||
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) {
|
||||
val center = Location(2412, 4434, 0)
|
||||
@@ -122,7 +124,7 @@ class FairyRingInterface : InterfaceListener(){
|
||||
}
|
||||
GameWorld.Pulser.submit(object : Pulse(4, player) {
|
||||
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
|
||||
}
|
||||
})
|
||||
@@ -131,8 +133,8 @@ class FairyRingInterface : InterfaceListener(){
|
||||
player.savedData.globalData.setTravelLog(ring.ordinal)
|
||||
}
|
||||
}
|
||||
player.interfaceManager.close()
|
||||
player.teleporter.send(tile,TeleportManager.TeleportType.FAIRY_RING)
|
||||
ContentAPI.closeInterface(player)
|
||||
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) {
|
||||
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
|
||||
|
||||
import api.ContentAPI
|
||||
import core.game.component.Component
|
||||
import core.game.component.ComponentDefinition
|
||||
import core.game.component.ComponentPlugin
|
||||
@@ -96,8 +97,8 @@ class FurClothingInterface : ComponentPlugin(){
|
||||
val checkedFurs = arrayListOf<String>()
|
||||
for(CLOTHING in FUR_CLOTHING.values()){
|
||||
if(checkedFurs.contains(CLOTHING.textContent)) continue
|
||||
if(player.inventory.containsItem(CLOTHING.requiredFur)){
|
||||
player.packetDispatch.sendString(colorize("%G" + CLOTHING.textContent), FUR_CLOTHING_COMPONENT_ID,CLOTHING.textChildID)
|
||||
if(ContentAPI.inInventory(player, CLOTHING.requiredFur.id, CLOTHING.requiredFur.amount)){
|
||||
ContentAPI.setInterfaceText(player, colorize("%G${CLOTHING.textContent}"), FUR_CLOTHING_COMPONENT_ID, CLOTHING.textChildID)
|
||||
checkedFurs.add(CLOTHING.textContent)
|
||||
}
|
||||
}
|
||||
@@ -143,7 +144,7 @@ class FurClothingInterface : ComponentPlugin(){
|
||||
}
|
||||
|
||||
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){
|
||||
@@ -151,19 +152,19 @@ class FurClothingInterface : ComponentPlugin(){
|
||||
val amtFurRequired = clothing.requiredFur.amount * amount
|
||||
val requiredFur = Item(clothing.requiredFur.id,amtFurRequired)
|
||||
|
||||
if(!player.inventory.containsItem(requiredFur)){
|
||||
player.dialogueInterpreter.sendDialogue("You don't have enough fur for that.")
|
||||
if(!ContentAPI.inInventory(player, requiredFur.id, requiredFur.amount)){
|
||||
ContentAPI.sendDialogue(player, "You don't have enough fur for that.")
|
||||
return
|
||||
}
|
||||
|
||||
if(!player.inventory.containsItem(coins)){
|
||||
player.dialogueInterpreter.sendDialogue("You can't afford that.")
|
||||
if(!ContentAPI.inInventory(player, coins.id, coins.amount)){
|
||||
ContentAPI.sendDialogue(player,"You can't afford that.")
|
||||
return
|
||||
}
|
||||
|
||||
player.inventory.remove(requiredFur)
|
||||
player.inventory.remove(coins)
|
||||
player.inventory.add(Item(clothing.product.id,amount))
|
||||
ContentAPI.removeItem(player, requiredFur, api.Container.INVENTORY)
|
||||
ContentAPI.removeItem(player, coins, api.Container.INVENTORY)
|
||||
ContentAPI.addItem(player, clothing.product.id, amount)
|
||||
}
|
||||
|
||||
override fun newInstance(arg: Any?): Plugin<Any> {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package rs09.game.interaction.inter
|
||||
|
||||
import api.ContentAPI
|
||||
import core.game.component.Component
|
||||
import core.game.component.ComponentDefinition
|
||||
import core.game.component.ComponentPlugin
|
||||
@@ -141,9 +142,9 @@ class HairDresserInterface : ComponentPlugin(){
|
||||
HAIRDRESSER_MALE_COMPONENT_ID -> 61
|
||||
else -> 0
|
||||
}
|
||||
player.packetDispatch.sendPlayerOnInterface(usedInterface,player_model_child)
|
||||
player.packetDispatch.sendAnimationInterface(FacialExpression.HAPPY.animationId,usedInterface,player_head_child)
|
||||
player.packetDispatch.sendPlayerOnInterface(usedInterface,player_head_child)
|
||||
ContentAPI.sendPlayerOnInterface(player, usedInterface, player_model_child)
|
||||
ContentAPI.sendPlayerOnInterface(player, usedInterface, player_head_child)
|
||||
ContentAPI.sendAnimationOnInterface(player, FacialExpression.HAPPY.animationId, usedInterface, player_head_child)
|
||||
player.toggleWardrobe(true)
|
||||
|
||||
component?.setCloseEvent{pl,_ ->
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package rs09.game.interaction.inter
|
||||
|
||||
import api.ContentAPI
|
||||
import core.game.component.CloseEvent
|
||||
import core.game.component.Component
|
||||
import core.game.content.quest.tutorials.tutorialisland.TutorialSession
|
||||
@@ -32,12 +33,12 @@ class MainGameInterface : InterfaceListener() {
|
||||
|
||||
on(TOPLEVEL_FS){player, _, _, 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. ",
|
||||
182,
|
||||
0
|
||||
)
|
||||
49 -> player.packetDispatch.sendString(
|
||||
49 -> ContentAPI.setInterfaceText(player,
|
||||
"Friends List - " + settings!!.name + " " + settings!!.worldId,
|
||||
550,
|
||||
3
|
||||
|
||||
Reference in New Issue
Block a user