diff --git a/Server/src/main/content/minigame/barbassault/Barbassault.kt b/Server/src/main/content/minigame/barbassault/Barbassault.kt index 55ef821aa..296b75dad 100644 --- a/Server/src/main/content/minigame/barbassault/Barbassault.kt +++ b/Server/src/main/content/minigame/barbassault/Barbassault.kt @@ -7,6 +7,7 @@ import content.minigame.barbassault.arena.HEALER_ICON import core.game.node.item.Item import org.rs09.consts.Items +val LureItems = intArrayOf(Items.WORMS_10515, Items.CRACKERS_10513, Items.TOFU_10514) enum class BarbRole { ATTACKER, COLLECTOR,DEFENDER, HEALER } data class BarbAssaultPoints( val atk: Int = 0, val col: Int = 0, val def: Int = 0, val heal: Int = 0) { val total: Int get() = atk + col + def + heal diff --git a/Server/src/main/content/minigame/barbassault/BarbassaultPlayerExtensions.kt b/Server/src/main/content/minigame/barbassault/BarbassaultPlayerExtensions.kt index 051e1fe02..3ac4576ae 100644 --- a/Server/src/main/content/minigame/barbassault/BarbassaultPlayerExtensions.kt +++ b/Server/src/main/content/minigame/barbassault/BarbassaultPlayerExtensions.kt @@ -3,7 +3,7 @@ package content.minigame.barbassault import content.minigame.barbassault.arena.BarbassaultSession import core.game.node.entity.player.Player -private const val BA_SESSION_KEY = "ba-session" +const val BA_SESSION_KEY = "ba-session" /** * Gets or sets the player's current Barbarian Assault session. * diff --git a/Server/src/main/content/minigame/barbassault/arena/BarbassaultArenaListener.kt b/Server/src/main/content/minigame/barbassault/arena/BarbassaultArenaListener.kt index b39af4f43..3f77ba9d6 100644 --- a/Server/src/main/content/minigame/barbassault/arena/BarbassaultArenaListener.kt +++ b/Server/src/main/content/minigame/barbassault/arena/BarbassaultArenaListener.kt @@ -1,6 +1,7 @@ package content.minigame.barbassault.arena import content.minigame.barbassault.BarbRole +import content.minigame.barbassault.LureItems import content.minigame.barbassault.arena.BaHornSystem.HornHelper.getHealerHorn import content.minigame.barbassault.arena.BarbassaultSession.AttackerStyle import content.minigame.barbassault.arena.scenery.EggCannon @@ -173,26 +174,21 @@ class BarbassaultArenaListener : InteractionListener { return@onEquip true } on(LureItems, IntType.GROUNDITEM, "Take") { player, node -> - //if (getItemFromEquipment(player, EquipmentSlot.CAPE)?.id != DEFENDER_ICON) { return@on false } - // only a defender can interact with lure food. - val groundLureItem = findClosestLure(node.location) - if (groundLureItem == null) return@on true - removeLure(groundLureItem) + val session = player.baSession ?: return@on true + if (session.team.getRoleForPlayer(player) != BarbRole.DEFENDER) { + sendMessage(player,"not a Defender") + } + session.pickUpGroundItem(player, node as GroundItem) return@on true } on(LureItems, IntType.ITEM, "Drop") { player, node -> - val dropedItem = node as Item DropListener.drop(player, node.asItem()) - sendMessage(player,dropedItem.name) - //addItemNode(dropedItem,player.location,true) - + val session = player.baSession ?: return@on true val gItem = player.getAttribute("droppedItem:${node.id}") - addItemNode(gItem,player.location,true) - //DropListener.drop(player, dropedItem) - //with values for good and bad. - //structure table with intent of being looped trough by a runner to check distance, compared to it. - //and to check if its good or bad when they get to that one. + (gItem as SessionGroundSpawn).flag = true + session.BAgroundItems.add(gItem) + //delete from ground as runner "eats" return@on true } @@ -202,15 +198,8 @@ class BarbassaultArenaListener : InteractionListener { if (session.team.getRoleForPlayer(player) != BarbRole.COLLECTOR) { sendMessage(player,"not a collector") } - if (!player.inventory.add(node)) { - node.isActive = false - (node as SessionGroundSpawn).isAutoSpawn = false - session.BAgroundItems.remove(node) - GroundItemManager.destroy(node) - return@on true - } + session.pickUpGroundItem(player,node) //todo find correct message - sendMessage(player,"You can not pick up any more EGGGS!") return@on true } } diff --git a/Server/src/main/content/minigame/barbassault/arena/BarbassaultSession.kt b/Server/src/main/content/minigame/barbassault/arena/BarbassaultSession.kt index c85076ee7..129532cfb 100644 --- a/Server/src/main/content/minigame/barbassault/arena/BarbassaultSession.kt +++ b/Server/src/main/content/minigame/barbassault/arena/BarbassaultSession.kt @@ -1,8 +1,10 @@ package content.minigame.barbassault.arena import content.minigame.barbassault.ALL_BARBASS_ITEMS +import content.minigame.barbassault.BA_SESSION_KEY import content.minigame.barbassault.BarbRole import content.minigame.barbassault.BarbassaultActivity +import content.minigame.barbassault.LureItems import content.minigame.barbassault.arena.scenery.EggCannon import content.minigame.barbassault.arena.scenery.GloryHorn import content.minigame.barbassault.baSession @@ -15,6 +17,7 @@ import core.game.node.entity.Entity import core.game.node.entity.impl.PulseManager import core.game.node.entity.npc.NPC import core.game.node.entity.player.Player +import core.game.node.item.GroundItem import core.game.node.item.GroundItemManager import core.game.node.item.Item import core.game.system.config.GroundSpawnLoader @@ -189,6 +192,7 @@ class BarbassaultSession( val activity: BarbassaultActivity ? = null) :LogoutLi var thisNpc = sessionNPCSpawn(npcId, location(30,31,0), spawn.direction) thisNpc?.location = base.transform(spawn.toLocation()) + thisNpc?.setAttribute(BA_SESSION_KEY, this) increment() } @@ -207,6 +211,27 @@ class BarbassaultSession( val activity: BarbassaultActivity ? = null) :LogoutLi } } + fun pickUpGroundItem(player: Player,node:GroundItem){ + if (!player.inventory.add(node)) { + node.isActive = false + (node as SessionGroundSpawn).isAutoSpawn = false + BAgroundItems.remove(node) + removeGroundItem(node) + return + } + sendMessage(player,"You don't have enough inventory space to hold that item.") + } + fun findClosestLure(target: Location): SessionGroundSpawn? { + return BAgroundItems + .asSequence() + .filter { it.id in LureItems } + .minByOrNull { node -> + val dx = node.location.x - target.x + val dy = node.location.y - target.y + Math.abs(dx) + Math.abs(dy) + } + } + fun forfeit(){ state = BarbassaultState.FORFEIT } diff --git a/Server/src/main/content/minigame/barbassault/arena/LureItems.kt b/Server/src/main/content/minigame/barbassault/arena/LureItems.kt deleted file mode 100644 index 7dd1bdd98..000000000 --- a/Server/src/main/content/minigame/barbassault/arena/LureItems.kt +++ /dev/null @@ -1,35 +0,0 @@ -package content.minigame.barbassault.arena - -import core.game.node.Node -import core.game.node.item.GroundItem -import core.game.node.item.Item -import core.game.world.map.Location -import org.rs09.consts.Items - - -data class LureItem(val item: Node, val location: Location, val isGood: Boolean) - -val LureItems = intArrayOf(Items.WORMS_10515, Items.CRACKERS_10513, Items.TOFU_10514) -val LureItemNodes = mutableListOf() - -//todo make this part of miniGame instance instead of global. - -fun addItemNode(item: GroundItem, location: Location, isGood: Boolean) { - LureItemNodes.add(LureItem(item, location, isGood)) -} - -fun findClosestLure(target: Location): LureItem? { - return LureItemNodes.minByOrNull { node -> - val dx = node.location.x - target.x - val dy = node.location.y - target.y - Math.abs(dx) + Math.abs(dy) - } -} - -fun removeLure(lure: LureItem) { - LureItemNodes.remove(lure) -} - -fun removeLureAtLocation(item: Item, location: Location): Boolean { - return LureItemNodes.removeIf { it.item == item && it.location == location } -} diff --git a/Server/src/main/content/minigame/barbassault/arena/Npcs/PenanceRunnerNPC.kt b/Server/src/main/content/minigame/barbassault/arena/Npcs/PenanceRunnerNPC.kt index 159f4d65c..4551dc379 100644 --- a/Server/src/main/content/minigame/barbassault/arena/Npcs/PenanceRunnerNPC.kt +++ b/Server/src/main/content/minigame/barbassault/arena/Npcs/PenanceRunnerNPC.kt @@ -1,5 +1,6 @@ package content.minigame.barbassault.arena.Npcs +import content.minigame.barbassault.BA_SESSION_KEY import content.minigame.barbassault.BarbRole import core.game.node.entity.Entity import core.game.node.entity.npc.NPC @@ -44,22 +45,27 @@ class PenanceRunnerNPC : NPCBehavior(*PENANCE_RUNNER_IDS.toIntArray()) { } override fun tick(self: NPC): Boolean { - val gotohere = findClosestLure(self.location) - if (gotohere != null) { - forceWalk(self,gotohere.location ,"DUMB") - if (self.location == gotohere.location) { - sendChat(self,if (gotohere.isGood) GOOD_EAT else BAD_EAT) - removeGroundItem(gotohere.item as GroundItem) - //GroundItemManager.destroy(gotohere.item) - removeLure(gotohere) - self.resetWalk() - } - } + val session = self.getAttribute(BA_SESSION_KEY) + if (session == null) return false + seekFood(self,session) return true } + fun seekFood(self:NPC,session: BarbassaultSession) { + val groundItem = session.findClosestLure(self.location) + if (groundItem != null) { + forceWalk(self,groundItem.location ,"DUMB") + if (self.location == groundItem.location) { + sendChat(self,if (groundItem.flag == true) GOOD_EAT else BAD_EAT) + removeGroundItem(groundItem) + self.resetWalk() + } + } + return + } - fun seekFood(){ + fun nosyTowardPlayers(self: NPC,session: BarbassaultSession) { + return } override fun onDeathFinished(self: NPC, killer: Entity) { diff --git a/Server/src/main/content/minigame/barbassault/arena/SessionGroundSpawn.kt b/Server/src/main/content/minigame/barbassault/arena/SessionGroundSpawn.kt index e5e24de1b..ae2b97be5 100644 --- a/Server/src/main/content/minigame/barbassault/arena/SessionGroundSpawn.kt +++ b/Server/src/main/content/minigame/barbassault/arena/SessionGroundSpawn.kt @@ -6,8 +6,7 @@ import core.game.node.item.Item import core.game.world.GameWorld import core.game.world.map.Location - -class SessionGroundSpawn(private var session: BarbassaultSession, private var respawnRate: Int, item: Item?,location: Location?) : GroundItem(item, location) { +class SessionGroundSpawn(private var session: BarbassaultSession, private var respawnRate: Int, item: Item?,location: Location?,var flag: Boolean? = null) : GroundItem(item, location) { private var active = true private var autoSpawn = true