wait, this can be ArrayList rather than MutableList, which greg prefers

This commit is contained in:
Player Name 2026-07-31 22:34:43 +02:00
parent 09344d4d66
commit 3d626fac46
10 changed files with 35 additions and 32 deletions

View file

@ -56,7 +56,7 @@ public final class ChinchompaSwingHandler extends RangeSwingHandler {
}
boolean accurate = isAccurateImpact(entity, victim, CombatStyle.RANGE);
List<Entity> targetCandidates = findMultihitTargetsForChinchompa(victim.getLocation(), entity, victim);
List<Entity> targetCandidates = findMultihitTargetsForChinchompa(victim, entity);
BattleState[] targets = new BattleState[targetCandidates.size()];
int count = 0;
for (Entity e : targetCandidates) {

View file

@ -73,7 +73,7 @@ public final class PowerstabSpecialHandler extends MeleeSwingHandler implements
if (!multi) {
return super.swing(entity, victim, state);
}
List<Entity> list = findMultihitTargetsForD2h(entity.getLocation(), entity, CombatStyle.MELEE);
List<Entity> list = findMultihitTargetsForD2h(entity, CombatStyle.MELEE);
BattleState[] targets = new BattleState[list.size()];
int count = 0;
for (Entity e : list) {

View file

@ -19,7 +19,7 @@ import core.tools.RandomFunction;
import org.rs09.consts.Sounds;
import static core.api.ContentAPIKt.playGlobalAudio;
import static core.game.node.entity.combat.MultihitTargetsKt.findMultihitTargets;
import static core.game.node.entity.combat.MultihitTargetsKt.findMultihitTargetsForDragonHalberd;
/**
* Handles the Dragon halberd special attack.
@ -96,17 +96,9 @@ public final class SweepSpecialHandler extends MeleeSwingHandler implements Plug
Direction dir = Direction.getDirection(x - entity.getLocation().getX(), y - entity.getLocation().getY());
List<BattleState> l = new ArrayList<>(20);
l.add(new BattleState(entity, victim));
List<Entity> list = findMultihitTargets(vl, entity, CombatStyle.RANGE); //RANGE is correct because halberds are able to attack from a distance
List<Entity> list = findMultihitTargetsForDragonHalberd(victim, entity);
for (Entity n : list) {
if (n == victim) {
continue;
}
if (n.getLocation().equals(vl.transform(dir.getStepY(), dir.getStepX(), 0)) || n.getLocation().equals(vl.transform(-dir.getStepY(), -dir.getStepX(), 0))) {
l.add(new BattleState(entity, n));
if (l.size() >= 3) {
break;
}
}
l.add(new BattleState(entity, n));
}
return l.toArray(new BattleState[l.size()]);
}

View file

@ -121,7 +121,7 @@ public final class BloodSpells extends CombatSpell {
return super.getTargets(entity, target);
}
List<Entity> list = MultihitTargetsKt.findMultihitTargets(target.getLocation(), entity, CombatStyle.MAGIC);
List<Entity> list = MultihitTargetsKt.findMultihitTargets(target, entity, CombatStyle.MAGIC);
BattleState[] targets = new BattleState[list.size()];
int index = 0;
for (Entity e : list) {

View file

@ -146,7 +146,7 @@ public final class IceSpells extends CombatSpell {
return super.getTargets(entity, target);
}
List<Entity> list = MultihitTargetsKt.findMultihitTargets(target.getLocation(), entity, CombatStyle.MAGIC);
List<Entity> list = MultihitTargetsKt.findMultihitTargets(target, entity, CombatStyle.MAGIC);
BattleState[] targets = new BattleState[list.size()];
int index = 0;
for (Entity e : list) {

View file

@ -160,7 +160,7 @@ public final class MiasmicSpells extends CombatSpell {
return super.getTargets(entity, target);
}
List<Entity> list = MultihitTargetsKt.findMultihitTargets(target.getLocation(), entity, CombatStyle.MAGIC);
List<Entity> list = MultihitTargetsKt.findMultihitTargets(target, entity, CombatStyle.MAGIC);
BattleState[] targets = new BattleState[list.size()];
int index = 0;
for (Entity e : list) {

View file

@ -117,7 +117,7 @@ public final class ShadowSpells extends CombatSpell {
return super.getTargets(entity, target);
}
List<Entity> list = MultihitTargetsKt.findMultihitTargets(target.getLocation(), entity, CombatStyle.MAGIC);
List<Entity> list = MultihitTargetsKt.findMultihitTargets(target, entity, CombatStyle.MAGIC);
BattleState[] targets = new BattleState[list.size()];
int index = 0;
for (Entity e : list) {

View file

@ -125,7 +125,7 @@ public final class SmokeSpells extends CombatSpell {
return super.getTargets(entity, target);
}
List<Entity> list = MultihitTargetsKt.findMultihitTargets(target.getLocation(), entity, CombatStyle.MAGIC);
List<Entity> list = MultihitTargetsKt.findMultihitTargets(target, entity, CombatStyle.MAGIC);
BattleState[] targets = new BattleState[list.size()];
int index = 0;
for (Entity e : list) {

View file

@ -4,7 +4,7 @@ import content.global.skill.summoning.familiar.Familiar
import core.game.node.entity.Entity
import core.game.node.entity.npc.NPC
import core.game.node.entity.player.Player
import core.game.world.map.Location
import core.game.world.map.Direction.getDirection
import core.game.world.map.RegionManager.getLocalEntities
import core.game.world.map.zone.impl.WildernessZone
@ -15,20 +15,30 @@ private fun isAttackable(victim: Entity, attacker: Entity, combatStyle: CombatSt
return victim.isAttackable(attacker, combatStyle, false)
}
fun findMultihitTargets(center: Location, attacker: Entity, combatStyle: CombatStyle): List<Entity> {
val targets = getLocalEntities(center, 1).filter { it != attacker && isAttackable(it, attacker, combatStyle, false) }
return targets.take(9) //https://runescape.wiki/w/Vesta%27s_spear "the opponent and up to 9 additional targets in a 3x3 area around the player"; https://oldschool.runescape.wiki/w/Ice_Barrage "up to nine targets"
fun findMultihitTargets(target: Entity, attacker: Entity, combatStyle: CombatStyle): List<Entity> {
val targets = getLocalEntities(target.location, 1).filter { it != attacker && it != target && isAttackable(it, attacker, combatStyle, false) }
return listOf(target) + targets.take(9) //https://runescape.wiki/w/Vesta%27s_spear "the opponent and up to 9 additional targets in a 3x3 area around the player"; https://oldschool.runescape.wiki/w/Ice_Barrage "up to nine targets"
}
fun findMultihitTargetsForD2h(center: Location, attacker: Entity, combatStyle: CombatStyle): List<Entity> {
val targets = getLocalEntities(center, 1).filter { it != attacker && isAttackable(it, attacker, combatStyle, false) }
return targets.filter { it.location.withinDistance(center, 1) } .take(14) //runescape.wiki/w/Dragon_2h_sword?oldid=859949 "up to 14 enemies in the squares around the player (Only directly in front of and to the sides, it does not attack those diagonal of the player)"
fun findMultihitTargetsForDragonHalberd(target: Entity, attacker: Entity): List<Entity> {
val direction = getDirection(target.location.x - attacker.location.x, target.location.y - attacker.location.y)
val targets = ArrayList<Entity>() //should not add the victim here
for (delta in listOf(-1, 1)) {
val add = getLocalEntities(target.location.transform(delta * direction.stepY, delta * direction.stepX, 0), 0)
targets += add.filter { it != attacker && isAttackable(it, attacker, CombatStyle.RANGE, false) }.take(1) //RANGE is correct because halberds are able to attack from a distance
}
return targets
}
fun findMultihitTargetsForChinchompa(center: Location, attacker: Entity, victim: Entity): List<Entity> {
val targetCandidates = getLocalEntities(center, 1).filter { it != attacker && isAttackable(it, attacker, CombatStyle.RANGE, false) }
fun findMultihitTargetsForD2h(attacker: Entity, combatStyle: CombatStyle): List<Entity> {
val targets = getLocalEntities(attacker.location, 1).filter { it != attacker && isAttackable(it, attacker, combatStyle, false) }
return targets.filter { it.location.withinDistance(attacker.location, 1) }.take(14) //runescape.wiki/w/Dragon_2h_sword?oldid=859949 "up to 14 enemies in the squares around the player (Only directly in front of and to the sides, it does not attack those diagonal of the player)"
}
fun findMultihitTargetsForChinchompa(target: Entity, attacker: Entity): List<Entity> {
val targetCandidates = getLocalEntities(target.location, 1).filter { it != attacker && it != target && isAttackable(it, attacker, CombatStyle.RANGE, false) }
val targets: List<Entity>?
if (victim is Player) {
if (target is Player) {
val players = targetCandidates.filterIsInstance<Player>()
fun isFamiliarOf(entity: Entity, players: List<Player>): Boolean {
if (entity !is Familiar) {
@ -52,5 +62,5 @@ fun findMultihitTargetsForChinchompa(center: Location, attacker: Entity, victim:
}
targets = targetCandidates.filter { it is NPC || isOwnerOf(it, npcs) }
}
return targets.take(9) //https://runescape.wiki/w/Chinchompa "up to 9 enemies"
return listOf(target) + targets.take(9) //https://runescape.wiki/w/Chinchompa "up to 9 enemies"
}

View file

@ -394,9 +394,10 @@ object RegionManager {
* @return the list.
*/
private inline fun<reified T: Entity> getLocalEntitiesOfType(location: Location, distance: Int): List<T> {
val entities: MutableList<T> = ArrayList(20)
for (cx in (location.absChunkX - 8)..(location.absChunkX + 8)) {
for (cy in (location.absChunkY - 8)..(location.absChunkY + 8)) {
val entities: ArrayList<T> = ArrayList(20)
val radius = (distance / 8) + 1
for (cx in (location.absChunkX - radius)..(location.absChunkX + radius)) {
for (cy in (location.absChunkY - radius)..(location.absChunkY + radius)) {
val chunk = Location(cx shl 3, cy shl 3, location.z).chunk
if (T::class.java.isAssignableFrom(Player::class.java)) {
entities.addAll(chunk.players.filterIsInstance<T>())