Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved naming 2 - Graphics #597

Merged
merged 8 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package world.gregs.voidps.engine.entity.character
import org.rsmod.game.pathfinder.collision.CollisionStrategy
import world.gregs.voidps.engine.client.variable.Variable
import world.gregs.voidps.engine.client.variable.Variables
import world.gregs.voidps.engine.data.definition.GraphicDefinitions
import world.gregs.voidps.engine.entity.Entity
import world.gregs.voidps.engine.entity.character.mode.Mode
import world.gregs.voidps.engine.entity.character.mode.move.Steps
Expand All @@ -13,9 +14,11 @@ import world.gregs.voidps.engine.entity.character.player.appearance
import world.gregs.voidps.engine.entity.character.player.movementType
import world.gregs.voidps.engine.entity.character.player.skill.level.Levels
import world.gregs.voidps.engine.event.EventDispatcher
import world.gregs.voidps.engine.get
import world.gregs.voidps.engine.queue.ActionQueue
import world.gregs.voidps.engine.suspend.Suspension
import world.gregs.voidps.engine.timer.Timers
import world.gregs.voidps.network.login.protocol.visual.VisualMask
import world.gregs.voidps.network.login.protocol.visual.Visuals
import world.gregs.voidps.network.login.protocol.visual.update.player.MoveType
import world.gregs.voidps.type.Delta
Expand Down Expand Up @@ -43,32 +46,69 @@ interface Character : Entity, Variable, EventDispatcher, Comparable<Character> {
/**
* Gradually move the characters appeared location to [delta] over [delay] time
*/
fun exactMove(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE) {
val start = tile
fun exactMove(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) {
tele(delta)
if (this is Player) {
movementType = MoveType.Walk
}
setExactMovement(Delta.EMPTY, delay, start.delta(tile), direction = direction)
val startDelta = delta.invert()
visuals.exactMovement.apply {
startX = startDelta.x
startY = startDelta.y
this.startDelay = startDelay
endX = 0
endY = 0
endDelay = delay
this.direction = direction.ordinal
}
flagExactMovement()
}

/**
* Gradually move the characters appeared location to [target] over [delay] time
*/
fun exactMove(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) {
val start = tile
tele(target)
if (this is Player) {
movementType = MoveType.Walk
}
setExactMovement(Delta.EMPTY, delay, start.delta(tile), startDelay, direction = direction)
exactMove(target.delta(tile), delay, direction, startDelay)
}

/**
* Force a message to be displayed above character
*/
fun say(message: String) {
visuals.say.text = message
flagSay()
}

/**
* Apply [id] graphical effect (aka spotanim) to the character with optional [delay]
* @see GraphicDefinitions for adjusting height, rotation and refresh
*/
fun gfx(id: String, delay: Int? = null) {
val definition = get<GraphicDefinitions>().getOrNull(id) ?: return
val mask = if (this is Player) VisualMask.PLAYER_GRAPHIC_1_MASK else VisualMask.NPC_GRAPHIC_1_MASK
val graphic = if (visuals.flagged(mask)) visuals.primaryGraphic else visuals.secondaryGraphic
graphic.id = definition.id
graphic.delay = delay ?: definition["delay", 0]
val characterHeight = (this as? NPC)?.def?.get("height", 0) ?: 40
graphic.height = (characterHeight + definition["height", -1000]).coerceAtLeast(0)
graphic.rotation = definition["rotation", 0]
graphic.forceRefresh = definition["force_refresh", false]
if (visuals.flagged(mask)) {
flagPrimaryGraphic()
} else {
flagSecondaryGraphic()
}
}

/**
* Remove any graphical effects in progress
*/
fun clearGfx() {
visuals.primaryGraphic.reset()
flagPrimaryGraphic()
visuals.secondaryGraphic.reset()
flagSecondaryGraphic()
}
}

val Entity.size: Int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package world.gregs.voidps.engine.entity.character

import world.gregs.voidps.engine.data.definition.AnimationDefinitions
import world.gregs.voidps.engine.data.definition.GraphicDefinitions
import world.gregs.voidps.engine.entity.Entity
import world.gregs.voidps.engine.entity.character.move.tele
import world.gregs.voidps.engine.entity.character.npc.NPC
import world.gregs.voidps.engine.entity.character.player.Player
import world.gregs.voidps.engine.entity.character.player.appearance
import world.gregs.voidps.engine.entity.character.player.movementType
import world.gregs.voidps.engine.entity.character.player.skill.Skill
import world.gregs.voidps.engine.entity.obj.GameObject
import world.gregs.voidps.engine.entity.obj.ObjectShape
Expand All @@ -16,7 +13,6 @@ import world.gregs.voidps.engine.suspend.SuspendableContext
import world.gregs.voidps.network.login.protocol.visual.VisualMask
import world.gregs.voidps.network.login.protocol.visual.update.Hitsplat
import world.gregs.voidps.network.login.protocol.visual.update.Turn
import world.gregs.voidps.network.login.protocol.visual.update.player.MoveType
import world.gregs.voidps.type.Delta
import world.gregs.voidps.type.Direction
import world.gregs.voidps.type.Distance
Expand Down Expand Up @@ -94,31 +90,6 @@ fun Character.flagPrimaryGraphic() = visuals.flag(if (this is Player) VisualMask

fun Character.flagSecondaryGraphic() = visuals.flag(if (this is Player) VisualMask.PLAYER_GRAPHIC_2_MASK else VisualMask.NPC_GRAPHIC_2_MASK)

fun Character.setGraphic(id: String, delay: Int? = null) {
val definition = get<GraphicDefinitions>().getOrNull(id) ?: return
val graphic = if (primaryGfxFlagged(this)) visuals.primaryGraphic else visuals.secondaryGraphic
graphic.id = definition.id
graphic.delay = delay ?: definition["delay", 0]
val characterHeight = (this as? NPC)?.def?.get("height", 0) ?: 40
graphic.height = (characterHeight + definition["height", -1000]).coerceAtLeast(0)
graphic.rotation = definition["rotation", 0]
graphic.forceRefresh = definition["force_refresh", false]
if (primaryGfxFlagged(this)) {
flagPrimaryGraphic()
} else {
flagSecondaryGraphic()
}
}

fun Character.clearGraphic() {
if (primaryGfxFlagged(this)) {
visuals.primaryGraphic.reset()
flagPrimaryGraphic()
} else {
visuals.secondaryGraphic.reset()
flagSecondaryGraphic()
}
}

fun Character.hit(source: Character, amount: Int, mark: Hitsplat.Mark, delay: Int = 0, critical: Boolean = false, soak: Int = -1) {
val after = (levels.get(Skill.Constitution) - amount).coerceAtLeast(0)
Expand Down Expand Up @@ -151,32 +122,6 @@ fun Character.clearWatch() {

private fun watchIndex(character: Character) = if (character is Player) character.index or 0x8000 else character.index

/**
* @param endDelta The delta position to move towards
* @param endDelay Number of client ticks to take moving
* @param startDelta The delta position to start at
* @param startDelay Client ticks until starting the movement
* @param direction The cardinal direction to face during movement
*/
fun Character.setExactMovement(
endDelta: Delta = Delta.EMPTY,
endDelay: Int = 0,
startDelta: Delta = Delta.EMPTY,
startDelay: Int = 0,
direction: Direction = Direction.NONE
) {
val move = visuals.exactMovement
check(endDelay > startDelay) { "End delay ($endDelay) must be after start delay ($startDelay)." }
move.startX = startDelta.x
move.startY = startDelta.y
move.startDelay = startDelay
move.endX = endDelta.x
move.endY = endDelta.y
move.endDelay = endDelay
move.direction = direction.ordinal
flagExactMovement()
}

val Character.turn: Delta
get() = Tile(visuals.turn.targetX, visuals.turn.targetY, tile.level).delta(tile)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package world.gregs.voidps.world.activity.achievement

import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.character.setGraphic
import world.gregs.voidps.engine.entity.playerSpawn
import world.gregs.voidps.engine.inv.discharge
import world.gregs.voidps.engine.inv.inventory
Expand All @@ -21,7 +20,7 @@ playerSpawn { player ->
inventoryOption("Run-replenish", "explorers_ring_*") {
if (player.inventory.discharge(player, slot)) {
player.setAnimation("run_replenish")
player.setGraphic("run_replenish")
player.gfx("run_replenish")
player.runEnergy += MAX_RUN_ENERGY / 2
player["explorers_ring_last_use"] = TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis())
player.message("You feel refreshed as the ring revitalises you and a charge is used up.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import world.gregs.voidps.engine.entity.character.player.skill.exp.exp
import world.gregs.voidps.engine.entity.character.player.skill.level.Level
import world.gregs.voidps.engine.entity.character.player.skill.level.Level.has
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.character.setGraphic
import world.gregs.voidps.engine.inject
import world.gregs.voidps.engine.inv.Inventory
import world.gregs.voidps.engine.inv.inventory
Expand Down Expand Up @@ -93,7 +92,7 @@ fun useItemOnItem(
player.setAnimation(def.animation)
}
if (def.graphic.isNotEmpty()) {
player.setGraphic(def.graphic)
player.gfx(def.graphic)
}
if (def.sound.isNotEmpty()) {
player.playSound(def.sound)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import world.gregs.voidps.engine.entity.character.move.tele
import world.gregs.voidps.engine.entity.character.npc.NPC
import world.gregs.voidps.engine.entity.character.player.Player
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.character.setGraphic
import world.gregs.voidps.engine.get
import world.gregs.voidps.engine.inv.inventory
import world.gregs.voidps.engine.inv.replace
Expand All @@ -18,12 +17,12 @@ import world.gregs.voidps.world.interact.entity.proj.shoot
object EssenceMine {
fun teleport(npc: NPC, player: Player) {
npc.say("Senventior Disthine Molenko!")
npc.setGraphic("curse_cast")
npc.gfx("curse_cast")
npc.face(player)
if (!npc.contains("old_model")) {
npc.setAnimation("curse")
}
player.setGraphic("curse_hit")
player.gfx("curse_hit")
player.shoot("curse", player.tile)
player.softQueue("essence_mine_teleport", 3) {
player["last_npc_teleport_to_rune_essence_mine"] = npc.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package world.gregs.voidps.world.activity.skill.runecrafting
import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.data.definition.AreaDefinitions
import world.gregs.voidps.engine.entity.character.move.tele
import world.gregs.voidps.engine.entity.character.setGraphic
import world.gregs.voidps.engine.entity.obj.objectOperate
import world.gregs.voidps.engine.inject
import world.gregs.voidps.engine.queue.softQueue
Expand All @@ -13,7 +12,7 @@ val areas: AreaDefinitions by inject()

objectOperate("Enter", "rune_essence_exit_portal") {
player.message("You step through the portal...")
player.setGraphic("curse_hit", delay = 30)
player.gfx("curse_hit", delay = 30)
target.tile.shoot("curse", player.tile)

player.softQueue("essence_mine_exit", 3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import world.gregs.voidps.engine.entity.character.player.skill.Skill
import world.gregs.voidps.engine.entity.character.player.skill.exp.exp
import world.gregs.voidps.engine.entity.character.player.skill.level.Level.has
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.character.setGraphic
import world.gregs.voidps.engine.entity.obj.objectOperate
import world.gregs.voidps.engine.inject
import world.gregs.voidps.engine.inv.*
Expand Down Expand Up @@ -67,7 +66,7 @@ fun Runecrafting.bindRunes(player: Player, id: String, itemDefinition: ItemDefin
TransactionError.None -> {
player.exp(Skill.Runecrafting, rune.xp * essence)
player.setAnimation("bind_runes")
player.setGraphic("bind_runes")
player.gfx("bind_runes")
player.playSound("bind_runes")
player.message("You bind the temple's power into ${id.toSentenceCase().plural()}.", ChatType.Filter)
}
Expand Down Expand Up @@ -127,7 +126,7 @@ itemOnObjectOperate("*_rune", "*_altar") {
}
}
player.setAnimation("bind_runes")
player.setGraphic("bind_runes")
player.gfx("bind_runes")
player.playSound("bind_runes")
if (successes != count) {
player.message("You partially succeed to bind the temple's power into $combination runes.", ChatType.Filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import world.gregs.voidps.engine.data.definition.data.Smelting
import world.gregs.voidps.engine.entity.character.player.skill.Skill
import world.gregs.voidps.engine.entity.character.player.skill.level.Level.has
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.character.setGraphic
import world.gregs.voidps.engine.inject
import world.gregs.voidps.engine.inv.inventory
import world.gregs.voidps.engine.inv.transact.TransactionError
Expand Down Expand Up @@ -42,7 +41,7 @@ itemOnItem(fromInterface = "modern_spellbook", fromComponent = "superheat_item")
if (player.inventory.transaction.error == TransactionError.None) {
player.playSound("superheat_all")
player.setAnimation(spell)
player.setGraphic(spell)
player.gfx(spell)
val definition = spellDefinitions.get(spell)
player.experience.add(Skill.Magic, definition.experience)
player.experience.add(Skill.Smithing, smelting.exp(player, bar))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import world.gregs.voidps.engine.data.definition.AreaDefinitions
import world.gregs.voidps.engine.entity.character.mode.interact.Interact
import world.gregs.voidps.engine.entity.character.player.chat.ChatType
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.character.setGraphic
import world.gregs.voidps.engine.entity.item.Item
import world.gregs.voidps.engine.entity.obj.GameObjects
import world.gregs.voidps.engine.inject
Expand All @@ -24,7 +23,7 @@ val objects: GameObjects by inject()
inventoryItem("Empty", "ectophial", "inventory") {
player.strongQueue("ectophial") {
player.setAnimation("empty_ectophial")
player.setGraphic("empty_ectophial")
player.gfx("empty_ectophial")
player.message("You empty the ectoplasm onto the ground around your feet...", ChatType.Filter)
player.start("movement_delay", 4)
delay(4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import world.gregs.voidps.engine.client.variable.start
import world.gregs.voidps.engine.data.definition.AreaDefinitions
import world.gregs.voidps.engine.entity.character.move.tele
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.character.setGraphic
import world.gregs.voidps.engine.inject
import world.gregs.voidps.engine.queue.weakQueue
import world.gregs.voidps.engine.timer.epochSeconds
Expand Down Expand Up @@ -40,7 +39,7 @@ interfaceOption("Cast", "lumbridge_home_teleport", "modern_spellbook") {
}
player.start("teleport_delay", 17)
repeat(17) {
player.setGraphic("home_tele_${it + 1}")
player.gfx("home_tele_${it + 1}")
val ticks = player.setAnimation("home_tele_${it + 1}")
pause(ticks)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import world.gregs.voidps.engine.entity.character.clearAnimation
import world.gregs.voidps.engine.entity.character.move.tele
import world.gregs.voidps.engine.entity.character.player.Player
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.character.setGraphic
import world.gregs.voidps.engine.inv.discharge
import world.gregs.voidps.engine.map.collision.random
import world.gregs.voidps.engine.queue.ActionPriority
Expand All @@ -25,14 +24,14 @@ fun itemTeleport(player: Player, inventory: String, slot: Int, area: Area, type:
player.closeInterfaces()
player.queue("teleport_$type", onCancel = null) {
player.playSound("teleport")
player.setGraphic("teleport_$type")
player.gfx("teleport_$type")
player.animate("teleport_$type")
player.tele(area.random(player)!!)
val int = player.setAnimation("teleport_land_$type")
if (int == -1) {
player.clearAnimation()
} else {
player.setGraphic("teleport_land_$type")
player.gfx("teleport_land_$type")
}
}
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import world.gregs.voidps.engine.entity.character.move.tele
import world.gregs.voidps.engine.entity.character.player.skill.Skill
import world.gregs.voidps.engine.entity.character.player.skill.exp.exp
import world.gregs.voidps.engine.entity.character.setAnimation
import world.gregs.voidps.engine.entity.character.setGraphic
import world.gregs.voidps.engine.inject
import world.gregs.voidps.engine.inv.inventory
import world.gregs.voidps.engine.inv.remove
Expand Down Expand Up @@ -41,12 +40,12 @@ interfaceOption("Cast", "*_teleport", "*_spellbook") {
player.exp(Skill.Magic, definition.experience)
val book = id.removeSuffix("_spellbook")
player.playSound("teleport")
player.setGraphic("teleport_$book")
player.gfx("teleport_$book")
player.animate("teleport_$book")
player.tele(areas[component].random(player)!!)
delay(1)
player.playSound("teleport_land")
player.setGraphic("teleport_land_$book")
player.gfx("teleport_land_$book")
player.animate("teleport_land_$book")
if (book == "ancient") {
delay(1)
Expand All @@ -67,7 +66,7 @@ inventoryItem("*", "*_teleport") {
player.queue("teleport", onCancel = null) {
if (player.inventory.remove(item.id)) {
player.playSound("teleport_$type")
player.setGraphic("teleport_$type")
player.gfx("teleport_$type")
player.setAnimation("teleport_$type")
delay(3)
player.tele(map.random(player)!!)
Expand Down
Loading
Loading