From fd5d5e7e701d468e3d9afa0cd394ca327052c62a Mon Sep 17 00:00:00 2001 From: ceikry Date: Fri, 9 Jul 2021 20:14:37 -0500 Subject: [PATCH] Ice trolls can now attack the miner NPCs. Removed debug code from the packet write queue --- Server/src/main/kotlin/api/ContentAPI.kt | 10 ++++++ .../entity/npc/other/IceTrollJatizsoCaves.kt | 34 +++++++++++++++++++ .../rs09/net/packet/PacketWriteQueue.kt | 1 - 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Server/src/main/kotlin/rs09/game/node/entity/npc/other/IceTrollJatizsoCaves.kt diff --git a/Server/src/main/kotlin/api/ContentAPI.kt b/Server/src/main/kotlin/api/ContentAPI.kt index 710d404a9..df3981d11 100644 --- a/Server/src/main/kotlin/api/ContentAPI.kt +++ b/Server/src/main/kotlin/api/ContentAPI.kt @@ -593,6 +593,16 @@ object ContentAPI { return RegionManager.getLocalNpcs(entity).firstOrNull { it.id == id } } + /** + * Gets a list of nearby NPCs that match the given IDs. + * @param entity the entity to check around + * @param ids the IDs of the NPCs to look for + */ + @JvmStatic + fun findLocalNPCs(entity: Entity, ids: IntArray): List{ + return RegionManager.getSurroundingNPCs(entity).filter { it.id in ids }.toList() + } + /** * Gets the value of an attribute key from the Entity's attributes store * @param entity the entity to get the attribute from diff --git a/Server/src/main/kotlin/rs09/game/node/entity/npc/other/IceTrollJatizsoCaves.kt b/Server/src/main/kotlin/rs09/game/node/entity/npc/other/IceTrollJatizsoCaves.kt new file mode 100644 index 000000000..3cbd154a5 --- /dev/null +++ b/Server/src/main/kotlin/rs09/game/node/entity/npc/other/IceTrollJatizsoCaves.kt @@ -0,0 +1,34 @@ +package rs09.game.node.entity.npc.other + +import api.ContentAPI +import core.game.node.entity.npc.AbstractNPC +import core.game.world.map.Location +import core.plugin.Initializable +import core.tools.RandomFunction +import org.rs09.consts.NPCs +import rs09.game.system.SystemLogger + +@Initializable +class IceTrollJatizsoCaves : AbstractNPC { + //Constructor spaghetti because Arios I guess + constructor() : super(NPCs.ICE_TROLL_MALE_5474, null, true) {} + private constructor(id: Int, location: Location) : super(id, location) {} + + override fun construct(id: Int, location: Location, vararg objects: Any?): AbstractNPC { + return IceTrollJatizsoCaves(id, location) + } + + override fun getIds(): IntArray { + return intArrayOf(NPCs.ICE_TROLL_MALE_5474,NPCs.ICE_TROLL_RUNT_5473,NPCs.ICE_TROLL_FEMALE_5475) + } + + override fun tick() { + val nearbyMiner = ContentAPI.findLocalNPC(this, NPCs.MINER_5497) ?: return super.tick() + if(!inCombat() && nearbyMiner.location.withinDistance(location, 8)){ + attack(nearbyMiner) + } + super.tick() + } + + +} \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/net/packet/PacketWriteQueue.kt b/Server/src/main/kotlin/rs09/net/packet/PacketWriteQueue.kt index e25fbf0eb..cd20b29f9 100644 --- a/Server/src/main/kotlin/rs09/net/packet/PacketWriteQueue.kt +++ b/Server/src/main/kotlin/rs09/net/packet/PacketWriteQueue.kt @@ -23,7 +23,6 @@ object PacketWriteQueue { @JvmStatic fun queue(packet: OutgoingPacket, context: T){ - SystemLogger.logInfo("Queueing ${packet.javaClass.simpleName}") PacketsToWrite.add(QueuedPacket(packet,context)) }