Egg Hopper logic done, may be missing a few messages

This commit is contained in:
Tooze 2026-02-02 03:23:49 -05:00
parent 5db0a5ea1b
commit c5ba5e8609
3 changed files with 42 additions and 32 deletions

View file

@ -1,9 +1,11 @@
package content.minigame.barbassault.arena
import content.minigame.barbassault.BarbassaultTut
import content.minigame.barbassault.CaptainCainDialogue.Companion.TORSO_PRICE
import content.minigame.barbassault.arena.BaHornSystem.HornHelper.getHealerHorn
import content.minigame.barbassault.arena.scenery.EggCannon
import content.minigame.barbassault.arena.scenery.EggCannon.Companion.loadEggHopper
import content.minigame.barbassault.arena.scenery.EggCannon.Companion.loadHopperEggs
import content.minigame.barbassault.arena.scenery.EggCannon.Companion.showEggHopperCount
import content.minigame.barbassault.getBarbLevels
import content.minigame.barbassault.lobby.baSession
@ -117,12 +119,18 @@ class BarbassaultGameArea : InteractionListener, MapArea {
player.faceLocation(location(loc.x,loc.y+1,0))
return@on true
}
onUseWith(IntType.SCENERY, EggCannon.ALL_EGGS,Scenery.EGG_HOPPER_20264){ player, used, with ->
val loc = player.location
player.faceLocation(location(loc.x,loc.y+1,0))
loadHopperEggs(player,used.id )
return@onUseWith true
}
//wrapperID for hopper
on(20267, IntType.SCENERY, "Load","Look-in") { player, node ->
sendMessage(player,"hopper")
return@on true
}
setDest(IntType.SCENERY, Scenery.EGG_HOPPER_20264) { player, node ->
setDest(IntType.SCENERY, intArrayOf(Scenery.EGG_HOPPER_20264), "use","Load","Look-in") { player, node ->
return@setDest sessionDestination(player as Player,node,Direction.SOUTH)
}

View file

@ -53,7 +53,7 @@ class BarbassaultSession( val activity: BarbassaultActivity ? = null) : MapArea
lateinit var team: BarbTeam
val sessionNpcs = mutableListOf<NPC>()
val groundItems = mutableListOf<GroundItem>()
val eggHopper = EggCannon.EggHopperCount()
val eggHopper = EggCannon.EggHopper()
fun beginStartingPhase() {

View file

@ -1,13 +1,8 @@
package content.minigame.barbassault.arena.scenery
import content.minigame.barbassault.BarbRole
import content.minigame.barbassault.arena.BarbassaultSession
import content.minigame.barbassault.lobby.CurrentTeam
import content.minigame.barbassault.lobby.baSession
import core.api.sendChat
import core.api.sendDialogueLines
import core.api.sendMessage
import core.api.setInterfaceText
import core.api.*
import core.game.component.CloseEvent
import core.game.component.Component
import core.game.component.ComponentDefinition
@ -16,7 +11,6 @@ import core.game.node.entity.player.Player
import core.game.node.item.Item
import core.plugin.Initializable
import core.plugin.Plugin
import org.rs09.consts.Components
import org.rs09.consts.Items
@ -51,44 +45,43 @@ class EggCannon : ComponentPlugin() {
}
}
//END BINKY//
data class EggHopperCount(var red: Int = 0,var blue: Int = 0, var green: Int = 0, var yellow: Int = 0 ){
data class EggHopper(var red: Int = 0, var blue: Int = 0, var green: Int = 0, var yellow: Int = 0 ){
private val maxPerColor = 5
val eggColorMap = mapOf(Items.GREEN_EGG_10531 to "green",Items.RED_EGG_10532 to "red",Items.BLUE_EGG_10533 to "blue",Items.OMEGA_EGG_10537 to "yellow" )
fun totalCount(): Int = red + blue + green + yellow
fun addEggs(redToAdd: Int = 0, blueToAdd: Int = 0, greenToAdd: Int = 0, yellowToAdd: Int = 0): Map<String, Int> {
val added = mutableMapOf<String, Int>()
val newRed = (red + redToAdd).coerceAtMost(5)
val newRed = (red + redToAdd).coerceAtMost(maxPerColor)
added["red"] = newRed - red
red = newRed
val newBlue = (blue + blueToAdd).coerceAtMost(5)
val newBlue = (blue + blueToAdd).coerceAtMost(maxPerColor)
added["blue"] = newBlue - blue
blue = newBlue
val newGreen = (green + greenToAdd).coerceAtMost(5)
val newGreen = (green + greenToAdd).coerceAtMost(maxPerColor)
added["green"] = newGreen - green
green = newGreen
val newYellow = (yellow + yellowToAdd).coerceAtMost(5)
val newYellow = (yellow + yellowToAdd).coerceAtMost(maxPerColor)
added["yellow"] = newYellow - yellow
yellow = newYellow
return added
}
fun consumeGreen(): Boolean {
if (green <= 0) return false
green--
return true
}
fun consumeRed(): Boolean {
if (red <= 0) return false
red--
return true
}
fun consumeBlue(): Boolean {
if (blue <= 0) return false
blue--
return true
fun addEgg(itemId: Int,count: Int = 0): Map<String, Int> {
return when (eggColorMap[itemId]) {
"red" -> addEggs(redToAdd = count)
"blue" -> addEggs(blueToAdd = count)
"green" -> addEggs(greenToAdd = count)
"yellow" -> addEggs(yellowToAdd = count)
else -> emptyMap()
}
}
fun consumeGreen(): Boolean { if (green <= 0) return false; green--; return true }
fun consumeRed(): Boolean { if (red <= 0) return false; red--; return true }
fun consumeBlue(): Boolean { if (blue <= 0) return false; blue--; return true }
fun consumeYellow(): Boolean { if (yellow <= 0) return false; yellow--; return true }
}
override fun newInstance(arg: Any?): Plugin<Any> {
ComponentDefinition.forId(EggTurret.ID).plugin = this
@ -191,6 +184,8 @@ class EggCannon : ComponentPlugin() {
}
companion object {
val ALL_EGGS = intArrayOf(Items.GREEN_EGG_10531,Items.RED_EGG_10532,Items.BLUE_EGG_10533,Items.OMEGA_EGG_10537)
fun openTurretIface(player: Player?) {
player ?: return
if (player.baSession?.eggHopper?.totalCount() == 0) {
@ -206,12 +201,19 @@ class EggCannon : ComponentPlugin() {
val session = player.baSession
val role =session?.team?.getRoleForPlayer(player)
if (role != BarbRole.COLLECTOR) {sendMessage(player,"You need to be a Collector to load eggs.");return}
//get player inv eggs
val eggsAdded = session.eggHopper.addEggs(greenToAdd = 0, redToAdd = 0, blueToAdd = 0, yellowToAdd = 0)
//remove eggs based on eggsAdded from inventory
ALL_EGGS.forEach { loadHopperEggs(player, it) }
//Load hopper emote, Same as place table??
sendMessage(player,"Loading hopper")
}
fun loadHopperEggs(player: Player?,itemId: Int ){
player ?: return
val invCount = amountInInventory(player, itemId)
val result = player.baSession?.eggHopper?.addEgg(itemId,invCount)
val color = player.baSession?.eggHopper?.eggColorMap?.get(itemId)
val added = result?.get(color) ?: 0
removeItem(player, Item(itemId, added))
}
fun showEggHopperCount(player: Player?){
player ?: return
val eggsCount = player.baSession?.eggHopper