Fixed infinite lunar cast range
This commit is contained in:
@@ -26,12 +26,12 @@ abstract class SpellListener(val bookName: String) : Listener {
|
|||||||
@JvmField
|
@JvmField
|
||||||
val GROUND_ITEM = -6
|
val GROUND_ITEM = -6
|
||||||
}
|
}
|
||||||
fun onCast(spellID: Int,type: Int,method: (player: Player, node: Node?) -> Unit){
|
fun onCast(spellID: Int, type: Int, range: Int = 10, method: (player: Player, node: Node?) -> Unit){
|
||||||
SpellListeners.add(spellID,type,bookName,method)
|
SpellListeners.add(spellID, type, bookName, range, method)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onCast(spellID: Int, type: Int, vararg ids: Int, method: (player: Player, node: Node?) -> Unit){
|
fun onCast(spellID: Int, type: Int, vararg ids: Int, range: Int = 10, method: (player: Player, node: Node?) -> Unit){
|
||||||
SpellListeners.add(spellID,type,ids,bookName,method)
|
SpellListeners.add(spellID, type, ids, bookName, range, method)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requires(player: Player, magicLevel: Int = 0, runes: Array<Item> = arrayOf<Item>(), specialEquipment: IntArray = intArrayOf()) {
|
fun requires(player: Player, magicLevel: Int = 0, runes: Array<Item> = arrayOf<Item>(), specialEquipment: IntArray = intArrayOf()) {
|
||||||
@@ -95,4 +95,4 @@ abstract class SpellListener(val bookName: String) : Listener {
|
|||||||
fun showMagicTab(player: Player){
|
fun showMagicTab(player: Player){
|
||||||
player.interfaceManager.setViewedTab(6)
|
player.interfaceManager.setViewedTab(6)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,81 @@
|
|||||||
package content.global.skill.magic
|
package content.global.skill.magic
|
||||||
|
|
||||||
import core.game.event.SpellCastEvent
|
import core.game.event.SpellCastEvent
|
||||||
import core.api.log
|
import core.api.*
|
||||||
import core.game.node.Node
|
import core.game.node.Node
|
||||||
import core.game.node.entity.player.Player
|
import core.game.node.entity.player.Player
|
||||||
import core.game.node.entity.player.link.SpellBookManager
|
import core.game.node.entity.player.link.SpellBookManager
|
||||||
import core.tools.Log
|
import core.tools.Log
|
||||||
import core.tools.SystemLogger
|
import core.tools.SystemLogger
|
||||||
|
import core.game.interaction.*
|
||||||
|
import core.game.world.map.path.Pathfinder
|
||||||
|
|
||||||
object SpellListeners {
|
object SpellListeners {
|
||||||
val castMap = HashMap<String,(Player, Node?) -> Unit>()
|
val castMap = HashMap<String,(Player, Node?) -> Unit>()
|
||||||
|
val spellRanges = HashMap<String, Int>()
|
||||||
|
|
||||||
fun add(spellID: Int, type: Int, book: String, method: (Player,Node?) -> Unit){
|
fun add(spellID: Int, type: Int, book: String, distance: Int, method: (Player,Node?) -> Unit){
|
||||||
castMap["$book:$spellID:$type"] = method
|
castMap["$book:$spellID:$type"] = method
|
||||||
|
spellRanges["$book:$spellID:$type"] = distance
|
||||||
}
|
}
|
||||||
|
|
||||||
fun add(spellID: Int, type: Int, ids: IntArray, book: String, method: (Player, Node?) -> Unit){
|
fun add(spellID: Int, type: Int, ids: IntArray, book: String, distance: Int, method: (Player, Node?) -> Unit){
|
||||||
for(id in ids) {
|
for(id in ids) {
|
||||||
castMap["$book:$spellID:$type:$id"] = method
|
castMap["$book:$spellID:$type:$id"] = method
|
||||||
|
spellRanges["$book:$spellID:$type:$id"] = distance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get(spellID: Int, type: Int, book: String): ((Player,Node?) -> Unit)?{
|
fun get(spellID: Int, type: Int, book: String): Pair<Int, ((Player,Node?) -> Unit)?> {
|
||||||
log(this::class.java, Log.FINE, "Getting $book:$spellID:$type")
|
log(this::class.java, Log.FINE, "Getting $book:$spellID:$type")
|
||||||
return castMap["$book:$spellID:$type"]
|
return Pair (spellRanges["$book:$spellID:$type"] ?: 10, castMap["$book:$spellID:$type"])
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get(spellID: Int, type: Int, id: Int, book: String): ((Player,Node?) -> Unit)?{
|
fun get(spellID: Int, type: Int, id: Int, book: String): Pair<Int, ((Player,Node?) -> Unit)?> {
|
||||||
log(this::class.java, Log.FINE, "Getting $book:$spellID:$type:$id")
|
log(this::class.java, Log.FINE, "Getting $book:$spellID:$type:$id")
|
||||||
return castMap["$book:$spellID:$type:$id"]
|
return Pair (spellRanges["$book:$spellID:$type:$id"] ?: 10, castMap["$book:$spellID:$type:$id"])
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun run(button: Int, type: Int, book: String, player: Player, node: Node? = null){
|
fun run(button: Int, type: Int, book: String, player: Player, node: Node? = null){
|
||||||
val method = get(button,type,node?.id ?: 0,book) ?: get(button,type,book) ?: return
|
var (range, method) = get (button, type, node?.id ?: 0, book)
|
||||||
try {
|
if (method == null) {
|
||||||
method.invoke(player, node)
|
var next = get (button, type, book)
|
||||||
player.dispatch(SpellCastEvent(SpellBookManager.SpellBook.valueOf(book.uppercase()), button, node))
|
range = next.first
|
||||||
} catch (e: IllegalStateException){
|
method = next.second ?: return
|
||||||
player.removeAttribute("spell:runes")
|
}
|
||||||
return
|
|
||||||
|
if (type in intArrayOf (SpellListener.NPC, SpellListener.OBJECT, SpellListener.PLAYER, SpellListener.GROUND_ITEM)) {
|
||||||
|
player.pulseManager.run (object : MovementPulse (player, node, Pathfinder.SMART) {
|
||||||
|
override fun pulse() : Boolean {
|
||||||
|
try {
|
||||||
|
method?.invoke (player, node)
|
||||||
|
} catch (e: IllegalStateException) {
|
||||||
|
player.removeAttribute ("spell:runes")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun update () : Boolean {
|
||||||
|
if (player.location.withinMaxnormDistance (node!!.centerLocation, range) && hasLineOfSight (player, node!!)) {
|
||||||
|
player.faceLocation (node.getFaceLocation(player.location))
|
||||||
|
player.walkingQueue.reset()
|
||||||
|
pulse()
|
||||||
|
stop()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return super.update()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
method?.invoke(player, node)
|
||||||
|
player.dispatch(SpellCastEvent(SpellBookManager.SpellBook.valueOf(book.uppercase()), button, node))
|
||||||
|
} catch (e: IllegalStateException){
|
||||||
|
player.removeAttribute("spell:runes")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ import core.net.packet.context.MusicContext
|
|||||||
import core.net.packet.out.MusicPacket
|
import core.net.packet.out.MusicPacket
|
||||||
import core.game.system.timer.*
|
import core.game.system.timer.*
|
||||||
import core.game.system.timer.impl.*
|
import core.game.system.timer.impl.*
|
||||||
|
import core.game.node.entity.combat.CombatSwingHandler
|
||||||
import java.util.regex.*
|
import java.util.regex.*
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import kotlin.math.*
|
import kotlin.math.*
|
||||||
@@ -974,7 +975,7 @@ fun registerTimer (entity: Entity, timer: RSTimer?) {
|
|||||||
entity.timers.registerTimer (timer)
|
entity.timers.registerTimer (timer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to fetch the existing, active, non-abstract and non-anonymous timer with the given identifier, or start a new timer if none exists and return that.
|
* Used to fetch the existing, active, non-abstract and non-anonymous timer with the given identifier, or start a new timer if none exists and return that.
|
||||||
* @param entity the entity whose timers we're retrieving
|
* @param entity the entity whose timers we're retrieving
|
||||||
* @param identifier the identifier of the timer, refer to the individual timer class for this token.
|
* @param identifier the identifier of the timer, refer to the individual timer class for this token.
|
||||||
@@ -1014,7 +1015,7 @@ fun spawnTimer (identifier: String, vararg args: Any) : RSTimer? {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to fetch a new instance of a registered (see: non-anonymous, non-abstract) timer with the given configuration args
|
* Used to fetch a new instance of a registered (see: non-anonymous, non-abstract) timer with the given configuration args
|
||||||
* @param T the type of the timer you're trying to retrieve. The timer registry will be searched for a timer of this type.
|
* @param T the type of the timer you're trying to retrieve. The timer registry will be searched for a timer of this type.
|
||||||
* @param args various arbitrary arguments to be passed to the timer's constructor. Refer to the timer in question for what the args are expected to be.
|
* @param args various arbitrary arguments to be passed to the timer's constructor. Refer to the timer in question for what the args are expected to be.
|
||||||
* @return a timer instance configured with your given args, or null if the timer is not listed in the registry (if this happens, your timer is either abstract or anonymous.)
|
* @return a timer instance configured with your given args, or null if the timer is not listed in the registry (if this happens, your timer is either abstract or anonymous.)
|
||||||
**/
|
**/
|
||||||
@@ -2713,7 +2714,7 @@ fun apRange(entity: Entity, apRange: Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun hasLineOfSight(entity: Entity, target: Node) : Boolean {
|
fun hasLineOfSight(entity: Entity, target: Node) : Boolean {
|
||||||
return ProjectilePathfinder.find(entity, target).isSuccessful
|
return CombatSwingHandler.isProjectileClipped (entity, target, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun animationFinished(entity: Entity) : Boolean {
|
fun animationFinished(entity: Entity) : Boolean {
|
||||||
@@ -2805,7 +2806,7 @@ fun isStunned(entity: Entity) : Boolean {
|
|||||||
**/
|
**/
|
||||||
fun applyPoison (entity: Entity, source: Entity, severity: Int) {
|
fun applyPoison (entity: Entity, source: Entity, severity: Int) {
|
||||||
val existingTimer = getTimer<Poison>(entity)
|
val existingTimer = getTimer<Poison>(entity)
|
||||||
|
|
||||||
if (existingTimer != null) {
|
if (existingTimer != null) {
|
||||||
existingTimer.severity = severity
|
existingTimer.severity = severity
|
||||||
existingTimer.damageSource = source
|
existingTimer.damageSource = source
|
||||||
|
|||||||
Reference in New Issue
Block a user