BATeam small changes

This commit is contained in:
Tooze 2026-05-22 23:15:17 -04:00
parent 36811828e0
commit ed44e5bde9

View file

@ -34,28 +34,15 @@ class BarbTeam(val session: BarbassaultSession, leader: Player) {
var recruit: PendingRecruit? = null
private val slots: Array<PartySlot?> = arrayOfNulls(MAX_SLOTS)
init {
slots[LEADER_SLOT] = PartySlot(LEADER_SLOT, leader)
wave = getBAWave(leader)!!
}
fun slotOf(player: Player): Int =
slots.indexOfFirst { it?.player == player }
init { slots[LEADER_SLOT] = PartySlot(LEADER_SLOT, leader); wave = getBAWave(leader)!! }
fun slotOf(player: Player): Int = slots.indexOfFirst { it?.player == player }
fun getSlot(index: Int): PartySlot? = slots.getOrNull(index)
fun allPlayers(): List<Player> = slots.filterNotNull().map { it.player }
fun isLeader(player: Player): Boolean = slotOf(player) == LEADER_SLOT
fun isHealer(player: Player): Boolean = getRoleForPlayer(player) == BarbRole.HEALER
fun isFull(): Boolean = slots.all { it != null }
fun addRecruit(player: Player): Boolean {
recruit = PendingRecruit(player)
return true
}
fun addPlayer(player: Player): Boolean {
if (slotOf(player) != -1) return false
@ -81,63 +68,43 @@ class BarbTeam(val session: BarbassaultSession, leader: Player) {
return true
}
fun getPlayersByRole(barbRole: BarbRole): List<Player> {
return slots.filterNotNull().map { it.player }.filter { getRoleForPlayer(it) == barbRole }
}
fun getPlayersByRole(barbRole: BarbRole): List<Player> = slots.filterNotNull().map { it.player }.filter { getRoleForPlayer(it) == barbRole }
fun getRoleForPlayer(player: Player): BarbRole = slots.getOrNull(slotOf(player))?.role!!
fun getLeader(): PartySlot? = slots[0]
fun getRoleForPlayer(player: Player): BarbRole {
val idx = slotOf(player)
return slots.getOrNull(idx)?.role!!
}
fun getLeader(): PartySlot? {
return slots[0]
}
fun roleCounts(): RoleCounts {
var att = 0
var def = 0
var coll = 0
var heal = 0
var counts = RoleCounts(0, 0, 0, 0)
slots.forEach { slot ->
when (slot?.role) {
BarbRole.ATTACKER -> att++
BarbRole.DEFENDER -> def++
BarbRole.COLLECTOR -> coll++
BarbRole.HEALER -> heal++
null -> {}
BarbRole.ATTACKER -> counts.att++
BarbRole.DEFENDER -> counts.def++
BarbRole.COLLECTOR -> counts.coll++
BarbRole.HEALER -> counts.heal++
null -> null
}
}
return RoleCounts(att, def, coll, heal)
return RoleCounts(counts.att, counts.def, counts.coll, counts.heal)
}
fun updateRoleAvailabilityFor(player: Player) {
updateRoleAvailability(roleCounts(),assignedRoleCount(),player )
}
fun assignedRoleCount(): Int =
slots.count { it?.role != null }
fun updateRoleAvailabilityFor(player: Player) = updateRoleAvailability(roleCounts(),assignedRoleCount(),player )
fun assignedRoleCount(): Int = slots.count { it?.role != null }
fun spawnLocationFor(player: Player): Location {
val idx = slotOf(player)
val (x, y) = PartySpawns[idx]
val (x, y) = PartySpawns[slotOf(player)]
return session.base.transform(x, y, 0)
}
}
data class RoleCounts(val att: Int, val def: Int, val coll: Int, val heal: Int )
data class RoleCounts(var att: Int, var def: Int, var coll: Int, var heal: Int )
object BarbTeamManager {
fun createTeam(leader: Player): Boolean {
val session = BAActivity.createSession(leader)
// if (session.team != null) return false
val team = BarbTeam(session, leader)
session.team = team
sendMessage(leader, "TeamCreated")
leader.debug("[DEBUG] TeamCreated")
updateTeam(team)
return true
}
@ -162,7 +129,7 @@ object BarbTeamManager {
val team = session.team
team.recruit = null
if (!team.addPlayer(player)) {
player.sendMessage("That party is full.")
player.debug("[DEBUG] That party is full.")
return false
}
team.setRoleForPlayer(player, role)
@ -188,11 +155,8 @@ object BarbTeamManager {
//session.cancleStartingPhase()
}
fun updateTeam(team: BarbTeam) {
team.allPlayers().forEach {
updateCurrentTeam(it)
}
}
fun updateTeam(team: BarbTeam) = team.allPlayers().forEach { updateCurrentTeam(it) }
}
//Leader leaving room and causing disband "Your leader has left the room and therefore cleared the team!"