Rewrote stiles

Added a new ContentAPI function, animationCycles, that returns the exact number of cycles an animation lasts for (useful for forced movement)
Added a new function to Vector objects that allows convertion into Direction objects (useful for transforming locations)
This commit is contained in:
Ceikry
2023-09-04 06:46:10 +00:00
committed by Ryan
parent d4e62c0e96
commit 895c41756a
7 changed files with 177 additions and 109 deletions
+7 -1
View File
@@ -64,6 +64,7 @@ import core.game.world.repository.Repository
import core.game.consumable.*
import core.ServerConstants
import core.api.utils.Vector
import core.cache.def.impl.AnimationDefinition
import core.game.node.entity.player.link.quest.Quest
import core.tools.*
import core.game.world.update.flag.*
@@ -431,7 +432,12 @@ fun resetAnimator(player: Player) {
* @return the number of ticks the given animation lasts for
*/
fun animationDuration(animation: Animation): Int {
return animation.definition.durationTicks
return cyclesToTicks(animation.definition.cycles)
}
fun animationCycles (animation: Int) : Int {
val def = AnimationDefinition.forId(animation)
return def.cycles
}
/**
+16
View File
@@ -1,5 +1,6 @@
package core.api.utils
import core.game.world.map.Direction
import core.game.world.map.Location
import kotlin.math.*
@@ -45,6 +46,21 @@ class Vector (val x: Double, val y: Double) {
return Location.create(floor(x).toInt(), floor(y).toInt(), plane)
}
fun toDirection() : Direction {
val norm = normalized()
if (norm.x >= 0.85) return Direction.EAST
else if (norm.x <= -0.85) return Direction.WEST
if (norm.y > 0) {
if (norm.y >= 0.85) return Direction.NORTH
return if (norm.x > 0) Direction.NORTH_EAST else Direction.NORTH_WEST
} else {
if (norm.y <= -0.85) return Direction.SOUTH
return if (norm.x > 0) Direction.SOUTH_EAST else Direction.SOUTH_WEST
}
}
companion object {
@JvmStatic fun betweenLocs (from: Location, to: Location) : Vector {
val xDiff = to.x - from.x
@@ -88,6 +88,14 @@ public final class AnimationDefinition {
return duration;
}
public int getCycles() {
if (durations == null) return 0;
int duration = 0;
for (int i : durations)
duration += i;
return duration;
}
/**
* Gets the duration of this animation in (600ms) ticks.
* @return The duration in ticks.