mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2026-08-23 03:15:10 -06:00
Quick Start lobby setup
This commit is contained in:
parent
99a91b1627
commit
cbf8b85767
3 changed files with 191 additions and 28 deletions
|
|
@ -48,10 +48,11 @@ class BarbassaultSession( val activity: BarbassaultActivity ? = null) :LogoutLi
|
|||
val endReason = "left"
|
||||
|
||||
|
||||
fun beginStartingPhase() {
|
||||
fun beginStartingPhase(quickStart: Boolean = false) {
|
||||
if (state != BarbassaultState.PARTY_CREATION) return
|
||||
state = BarbassaultState.STARTING
|
||||
createArena()
|
||||
if (quickStart){ enterArena(); rollNewRoleCalls(); return }
|
||||
startCountdown()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,172 @@
|
|||
package content.minigame.barbassault.lobby
|
||||
|
||||
import content.minigame.barbassault.BarbRole
|
||||
import content.minigame.barbassault.lobby.BarbTeamManager.createTeam
|
||||
import core.api.log
|
||||
import core.api.sendMessage
|
||||
import core.api.setInterfaceText
|
||||
import core.game.activity.ActivityManager
|
||||
import core.game.activity.ActivityPlugin
|
||||
import core.game.node.entity.Entity
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.item.Item
|
||||
import core.game.world.map.Location
|
||||
import core.game.world.map.zone.ZoneRestriction
|
||||
import core.plugin.Initializable
|
||||
import core.tools.Log
|
||||
import org.rs09.consts.Items
|
||||
|
||||
|
||||
//Idea: Everyone in the lobby is under this activity.
|
||||
// Why? If for somereason you DIE! your still protected.
|
||||
// And will use for Quick Start wave room.
|
||||
|
||||
private var activity: BarbassLobbyActivity? = null
|
||||
|
||||
sealed class QueueRole { data class Specific(val role: BarbRole) : QueueRole(); object Any : QueueRole() }
|
||||
data class WaitingPlayer(val player: Player, val role: BarbRole?,val joinTime: Long = System.currentTimeMillis())
|
||||
private val waitingPlayers = mutableListOf<WaitingPlayer>()
|
||||
|
||||
private val waitingRoleCounts = mutableMapOf<BarbRole, Int>().withDefault { 0 }
|
||||
private var waitingAnyCount = 0
|
||||
|
||||
|
||||
@Initializable
|
||||
open class BarbassLobbyActivity : ActivityPlugin("BarbassLobby",false, false, true,
|
||||
ZoneRestriction.CANNON, ZoneRestriction.FIRES, ZoneRestriction.FOLLOWERS, ZoneRestriction.RANDOM_EVENTS) {
|
||||
|
||||
init { activity = this }
|
||||
|
||||
private fun tryCreateTeamFromQueue(): Boolean {
|
||||
|
||||
if (waitingPlayers.size < 5) return false
|
||||
|
||||
val remaining = waitingPlayers.sortedBy { it.joinTime }.toMutableList()
|
||||
|
||||
val selected = mutableListOf<WaitingPlayer>()
|
||||
|
||||
fun takeForRole(role: BarbRole): WaitingPlayer? {
|
||||
val exact = remaining.firstOrNull { it.role == role }
|
||||
if (exact != null) {
|
||||
remaining.remove(exact)
|
||||
return exact
|
||||
}
|
||||
|
||||
val any = remaining.firstOrNull { it.role == null }
|
||||
if (any != null) {
|
||||
remaining.remove(any)
|
||||
return any.copy(role = role)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
for (role in BarbRole.values()) {
|
||||
val picked = takeForRole(role) ?: return false
|
||||
selected.add(picked)
|
||||
}
|
||||
|
||||
val fifth = remaining.firstOrNull() ?: return false
|
||||
remaining.remove(fifth)
|
||||
val assignedFifth = if (fifth.role == null) { fifth.copy(role = BarbRole.ATTACKER) } else fifth
|
||||
selected.add(assignedFifth)
|
||||
|
||||
createQuickTeam(selected)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun giveScroll(player: Player): Boolean {
|
||||
if (!player.inventory.containsItem(Item(Items.SCROLL_10512, 1))) {
|
||||
return player.inventory.add(Item(Items.SCROLL_10512, 1))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun createQuickTeam(players: List<WaitingPlayer>) {
|
||||
waitingPlayers.removeAll { wp -> players.any { it.player == wp.player } }
|
||||
var teamLeader: Player? = null
|
||||
for (wp in players) {
|
||||
if (giveScroll(wp.player)) {
|
||||
teamLeader = wp.player
|
||||
break
|
||||
}
|
||||
}
|
||||
//IF BY CHANCE no one had free inventory space KICK THEM ALL FROM QUEUE!
|
||||
if (teamLeader == null) {
|
||||
players.forEach {
|
||||
sendMessage(it.player, "You could not hold a Scroll and have been removed from queue")
|
||||
player.teleport(Location.create(2602, 5279, 0))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
createTeam(teamLeader)
|
||||
val session = teamLeader.baSession
|
||||
val team = session?.team ?: return
|
||||
|
||||
players.forEach {
|
||||
val role = it.role!!
|
||||
team.setRoleForPlayer(it.player, role)
|
||||
//todo find authentic message for Quick Start Team Formed BarbAssault
|
||||
sendMessage(it.player, "A team has been formed! Your role: ${role.name}")
|
||||
}
|
||||
session.beginStartingPhase(true)
|
||||
}
|
||||
|
||||
override fun death(e: Entity?, killer: Entity?): Boolean {
|
||||
val ename = e?.name
|
||||
log(this.javaClass, Log.FINE,"$ename has died in Barbass Lobby, HOW? killer:$killer")
|
||||
e!!.getProperties().setTeleportLocation(null)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun newInstance(p: Player?): ActivityPlugin {
|
||||
ActivityManager.register(this)
|
||||
return this
|
||||
}
|
||||
//override when !2265 passes (void recovery)
|
||||
fun recover(player: Player){
|
||||
//do nothing, not lost
|
||||
}
|
||||
|
||||
override fun getSpawnLocation(): Location {
|
||||
return Location.create(2593, 5264, 0)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun removeQuickQue(player: Player){
|
||||
val toRemove = waitingPlayers.filter { it.player == player }
|
||||
waitingPlayers.removeAll(toRemove)
|
||||
|
||||
toRemove.forEach { wp ->
|
||||
if (wp.role == null) waitingAnyCount--
|
||||
else waitingRoleCounts[wp.role] = waitingRoleCounts.getValue(wp.role) - 1
|
||||
}
|
||||
|
||||
refreshQuickWaveOverlay()
|
||||
}
|
||||
|
||||
fun addToQueue(player: Player, role: BarbRole?) {
|
||||
waitingPlayers.add(WaitingPlayer(player, role))
|
||||
|
||||
if (role == null) waitingAnyCount++
|
||||
else waitingRoleCounts[role] = waitingRoleCounts.getValue(role) + 1
|
||||
|
||||
//todo find authentic message for Quick Start Wave BarbAssault
|
||||
val roleText = role?.name ?: "ANY"
|
||||
sendMessage(player, "You've joined the queue as ${roleText.lowercase().replaceFirstChar { it.uppercase() }}.")
|
||||
refreshQuickWaveOverlay()
|
||||
}
|
||||
private fun refreshQuickWaveOverlay() {
|
||||
waitingPlayers.forEach {
|
||||
val itplayer = it.player
|
||||
setInterfaceText(itplayer, (waitingRoleCounts[BarbRole.ATTACKER] ?: 0).toString(), 489, 6)
|
||||
setInterfaceText(itplayer, (waitingRoleCounts[BarbRole.DEFENDER] ?: 0).toString(), 489, 7)
|
||||
setInterfaceText(itplayer, (waitingRoleCounts[BarbRole.COLLECTOR] ?: 0).toString(), 489, 8)
|
||||
setInterfaceText(itplayer, (waitingRoleCounts[BarbRole.HEALER] ?: 0).toString(), 489, 9)
|
||||
setInterfaceText(itplayer, waitingAnyCount.toString(), 489, 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ import content.minigame.barbassault.lobby.BarbTeamManager.abandonTeam
|
|||
import content.minigame.barbassault.lobby.BarbTeamManager.createTeam
|
||||
import content.minigame.barbassault.lobby.BarbTeamManager.disbandTeam
|
||||
import content.minigame.barbassault.lobby.BarbTeamManager.joinTeam
|
||||
import content.minigame.barbassault.lobby.BarbassLobbyActivity.Companion.addToQueue
|
||||
import content.minigame.duel.DuelSession
|
||||
import core.api.*
|
||||
import core.game.component.Component
|
||||
|
|
@ -35,10 +36,11 @@ class BarbassaultLobby : InteractionListener, MapArea {
|
|||
}
|
||||
|
||||
override fun areaEnter(entity: Entity) {
|
||||
val enteredZone = areaBorders.firstOrNull { it.insideBorder(entity.location) }
|
||||
if (enteredZone == QUICK_START) { return }
|
||||
updatePlayerWave(entity)
|
||||
openOverlay(entity as Player, 256)
|
||||
PulseManager.cancelDeathTask(entity)
|
||||
// Components.BARBASSAULT_PLAYERSTAT_490
|
||||
}
|
||||
|
||||
override fun areaLeave(entity: Entity, logout: Boolean) {
|
||||
|
|
@ -160,12 +162,14 @@ class BarbassaultLobby : InteractionListener, MapArea {
|
|||
return@on true
|
||||
}
|
||||
on(Scenery.DOOR_20209, IntType.SCENERY, "Pass") { player, node ->
|
||||
if (capeCheck(player)) {}
|
||||
//todo find authentic message no capes
|
||||
// if (capeCheck(player)) { sendMessage(player,"Your not allowed to wear capes."); return@on true }
|
||||
if (!QUICK_START.insideBorder(player.location)){
|
||||
player.setAttribute("/save:barbass:wave", 1)
|
||||
handlePlayerOptionDoor(player) { role ->
|
||||
player.sendMessage("You are a ${role.name.lowercase().replaceFirstChar { it.uppercase() }}.")
|
||||
//player.sendMessage("You are a ${role.name.lowercase().replaceFirstChar { it.uppercase() }}.")
|
||||
handleWaveDoor(player, node, 489)
|
||||
addToQueue(player, role)
|
||||
}
|
||||
}else {
|
||||
handleWaveDoor(player, node, 489)
|
||||
|
|
@ -174,6 +178,8 @@ class BarbassaultLobby : InteractionListener, MapArea {
|
|||
}
|
||||
|
||||
on(BARBDOORS, IntType.SCENERY, "Pass") { player, node ->
|
||||
//todo find authentic message no capes
|
||||
// if (capeCheck(player)) { sendMessage(player,"Your not allowed to wear capes."); return@on true }
|
||||
handleWaveDoor(player, node,256)
|
||||
return@on true
|
||||
}
|
||||
|
|
@ -188,9 +194,7 @@ class BarbassaultLobby : InteractionListener, MapArea {
|
|||
when (buttonId) {
|
||||
2 -> {
|
||||
if (player.inventory.add(Item(Items.SCROLL_10512, 1))) {
|
||||
// if (createTeam(player)){
|
||||
player.sendMessage("You take scroll from table")
|
||||
// }
|
||||
} else {
|
||||
player.sendMessage("You dont have enough inventory space")
|
||||
}
|
||||
|
|
@ -224,10 +228,6 @@ class BarbassaultLobby : InteractionListener, MapArea {
|
|||
}
|
||||
}
|
||||
*/
|
||||
enum class RoomRole {
|
||||
ATTACKER, DEFENDER, COLLECTOR, HEALER, ANYROLE
|
||||
}
|
||||
|
||||
|
||||
fun getModelFromButton(button: Int): Int {
|
||||
return when (button) {
|
||||
|
|
@ -262,19 +262,19 @@ class BarbassaultLobby : InteractionListener, MapArea {
|
|||
|
||||
}
|
||||
|
||||
fun handlePlayerOptionDoor(player: Player, roomRoleOptions:(RoomRole) -> Unit){
|
||||
fun handlePlayerOptionDoor(player: Player, roomRoleOptions:(BarbRole?) -> Unit){
|
||||
sendDialogueOptions(
|
||||
player,
|
||||
"Which role would you like to perform?",
|
||||
"Attacker", "Defender","Collector","Healer","I'll be any role!")
|
||||
addDialogueAction(player) { _, buttonId ->
|
||||
val role = when (buttonId) {
|
||||
2 -> RoomRole.ATTACKER
|
||||
3 -> RoomRole.DEFENDER
|
||||
4 -> RoomRole.COLLECTOR
|
||||
5 -> RoomRole.HEALER
|
||||
6 -> RoomRole.ANYROLE
|
||||
else -> RoomRole.ANYROLE
|
||||
2 -> BarbRole.ATTACKER
|
||||
3 -> BarbRole.DEFENDER
|
||||
4 -> BarbRole.COLLECTOR
|
||||
5 -> BarbRole.HEALER
|
||||
6 -> null
|
||||
else -> null
|
||||
}
|
||||
roomRoleOptions(role)
|
||||
}
|
||||
|
|
@ -309,6 +309,7 @@ class BarbassaultLobby : InteractionListener, MapArea {
|
|||
//player.baSession = null
|
||||
abandonTeam(player)
|
||||
closeOverlay(player)
|
||||
if (node.id == 20209) { BarbassLobbyActivity.removeQuickQue(player) }
|
||||
} else {
|
||||
openOverlay(player, iface)
|
||||
// player.sendMessage("you enter wave ${BARBWAVEDOOR[node.id]}")
|
||||
|
|
@ -401,19 +402,8 @@ class BarbassaultLobby : InteractionListener, MapArea {
|
|||
20208 to 10,
|
||||
20209 to 1)
|
||||
|
||||
// override fun tick() {
|
||||
// TODO("Not yet implemented")
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
PRIVATE_PALDO_5031 -- Big axe barb at entrance to main lobby
|
||||
PRIVATE_PALDON_5034 -- sword -- Above wave 7 and 8 Source:https://youtu.be/VPlIYB1h9KM?t=340
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue