Skip to content

Commit

Permalink
Improved naming 1 - ForceChat, RenderEmote (#596)
Browse files Browse the repository at this point in the history
* Rename forceChat encoder to say

* Rename forceChat to say

* Change render emote to setter

* Move say

* Simplify gfx flagging

* Rename setExactMove

* Move exactMoveDelay into SuspendableContext

* Move exactMove into Character
  • Loading branch information
GregHib authored Jan 23, 2025
1 parent cad1007 commit c194e0f
Show file tree
Hide file tree
Showing 40 changed files with 159 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import world.gregs.voidps.engine.client.variable.Variables
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
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.level.Levels
import world.gregs.voidps.engine.event.EventDispatcher
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.Visuals
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.Tile
import kotlin.coroutines.Continuation

interface Character : Entity, Variable, EventDispatcher, Comparable<Character> {
Expand All @@ -33,6 +39,36 @@ interface Character : Entity, Variable, EventDispatcher, Comparable<Character> {
override fun compareTo(other: Character): Int {
return index.compareTo(other.index)
}

/**
* 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
tele(delta)
if (this is Player) {
movementType = MoveType.Walk
}
setExactMovement(Delta.EMPTY, delay, start.delta(tile), direction = direction)
}

/**
* 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)
}

fun say(message: String) {
visuals.say.text = message
flagSay()
}

}

val Entity.size: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import world.gregs.voidps.engine.entity.obj.ObjectShape
import world.gregs.voidps.engine.get
import world.gregs.voidps.engine.suspend.SuspendableContext
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.Hitsplat
import world.gregs.voidps.network.login.protocol.visual.update.Turn
import world.gregs.voidps.network.login.protocol.visual.update.player.MoveType
Expand All @@ -27,7 +26,7 @@ fun Character.flagAnimation() = visuals.flag(if (this is Player) VisualMask.PLAY

fun Character.flagColourOverlay() = visuals.flag(if (this is Player) VisualMask.PLAYER_COLOUR_OVERLAY_MASK else VisualMask.NPC_COLOUR_OVERLAY_MASK)

fun Character.flagForceChat() = visuals.flag(if (this is Player) VisualMask.PLAYER_FORCE_CHAT_MASK else VisualMask.NPC_FORCE_CHAT_MASK)
fun Character.flagSay() = visuals.flag(if (this is Player) VisualMask.PLAYER_SAY_MASK else VisualMask.NPC_SAY_MASK)

fun Character.flagHits() = visuals.flag(if (this is Player) VisualMask.PLAYER_HITS_MASK else VisualMask.NPC_HITS_MASK)

Expand Down Expand Up @@ -89,54 +88,36 @@ fun Character.colourOverlay(colour: Int, delay: Int, duration: Int) {
softTimers.start("colour_overlay")
}

var Character.forceChat: String
get() = visuals.forceChat.text
set(value) {
visuals.forceChat.text = value
flagForceChat()
}

private fun getPlayerMask(index: Int) = when (index) {
1 -> VisualMask.PLAYER_GRAPHIC_2_MASK
else -> VisualMask.PLAYER_GRAPHIC_1_MASK
}
private fun primaryGfxFlagged(character: Character) = character.visuals.flagged(if (character is Player) VisualMask.PLAYER_GRAPHIC_1_MASK else VisualMask.NPC_GRAPHIC_1_MASK)

private fun getNPCMask(index: Int) = when (index) {
1 -> VisualMask.NPC_GRAPHIC_2_MASK
else -> VisualMask.NPC_GRAPHIC_1_MASK
}

private fun index(character: Character) = if (character is Player) character.visuals.getIndex(::getPlayerMask) else character.visuals.getIndex(::getNPCMask)
fun Character.flagPrimaryGraphic() = visuals.flag(if (this is Player) VisualMask.PLAYER_GRAPHIC_1_MASK else VisualMask.NPC_GRAPHIC_1_MASK)

fun Character.flagGraphic(index: Int) = visuals.flag(if (this is Player) getPlayerMask(index) else getNPCMask(index))

private fun Visuals.getIndex(indexer: (Int) -> Int): Int {
for (i in 0 until 2) {
if (!flagged(indexer(i))) {
return i
}
}
return -1
}
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 index = index(this)
val graphic = if (index == 0) visuals.primaryGraphic else visuals.secondaryGraphic
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]
flagGraphic(index)
if (primaryGfxFlagged(this)) {
flagPrimaryGraphic()
} else {
flagSecondaryGraphic()
}
}

fun Character.clearGraphic() {
val index = index(this)
val graphic = if (index == 0) visuals.primaryGraphic else visuals.secondaryGraphic
graphic.reset()
flagGraphic(index)
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) {
Expand Down Expand Up @@ -196,34 +177,6 @@ fun Character.setExactMovement(
flagExactMovement()
}

fun Character.setExactMove(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE) {
val start = tile
tele(delta)
if (this is Player) {
movementType = MoveType.Walk
}
setExactMovement(Delta.EMPTY, delay, start.delta(tile), direction = direction)
}

context(SuspendableContext<*>) suspend fun Character.exactMove(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE) {
character.setExactMove(delta, delay, direction)
delay(delay / 30)
}

fun Character.setExactMove(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)
}

context(SuspendableContext<*>) suspend fun Character.exactMove(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) {
character.setExactMove(target, delay, direction, startDelay)
delay((startDelay + delay) / 30)
}

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 @@ -58,11 +58,10 @@ var Player.headIcon: Int
headIcon = value
}

var Player.renderEmote: String
get() = get<RenderEmoteDefinitions>().get(appearance.emote).stringId
set(value) = flag {
emote = get<RenderEmoteDefinitions>().get(value).id
}
fun Player.renderEmote(id: String) = flag {
val definition = get<RenderEmoteDefinitions>().get(id)
appearance.emote = definition.id
}

fun Player.clearRenderEmote() = flag {
emote = 1426
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package world.gregs.voidps.engine.suspend
import kotlinx.coroutines.suspendCancellableCoroutine
import world.gregs.voidps.engine.entity.character.Character
import world.gregs.voidps.engine.event.Context
import world.gregs.voidps.type.Delta
import world.gregs.voidps.type.Direction
import world.gregs.voidps.type.Tile

interface SuspendableContext<C : Character> : Context<C> {
/**
Expand All @@ -25,4 +28,20 @@ interface SuspendableContext<C : Character> : Context<C> {
character.delay = it
}
}

/**
* Delay until the appeared location of the character has moved [delta] in [delay] time
*/
suspend fun Character.exactMoveDelay(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE) {
character.exactMove(delta, delay, direction)
delay(delay / 30)
}

/**
* Delay until the appeared location of the character has moved to [target] in [delay] time
*/
suspend fun Character.exactMoveDelay(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) {
character.exactMove(target, delay, direction, startDelay)
delay((startDelay + delay) / 30)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import world.gregs.voidps.engine.data.Settings
import world.gregs.voidps.engine.data.definition.data.Rock
import world.gregs.voidps.engine.data.settingsReload
import world.gregs.voidps.engine.entity.World
import world.gregs.voidps.engine.entity.character.setExactMove
import world.gregs.voidps.engine.entity.character.mode.interact.Interact
import world.gregs.voidps.engine.entity.character.move.walkTo
import world.gregs.voidps.engine.entity.character.npc.NPC
Expand Down Expand Up @@ -120,7 +119,7 @@ fun startCrashedStarEvent() {
for (player in under) {
player.damage(random.nextInt(10, 50))
val direction = Direction.all.first { !player.blocked(it) }
player.setExactMove(direction.delta, 1, direction = direction.inverse())
player.exactMove(direction.delta, 1, direction = direction.inverse())
player.setAnimation("step_back_startled")
}
World.queue("falling_star_object_removal", 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package world.gregs.voidps.world.activity.skill.agility.course

import world.gregs.voidps.engine.entity.character.exactMove
import world.gregs.voidps.engine.entity.character.setExactMove
import world.gregs.voidps.engine.entity.character.face
import world.gregs.voidps.engine.entity.character.move.tele
import world.gregs.voidps.engine.entity.character.move.walkTo
Expand All @@ -25,7 +23,7 @@ objectOperate("Run-up", "barbarian_outpost_run_wall") {
player.setAnimation("barbarian_wall_jump_climb")
delay(7)
player.setAnimation("barbarian_wall_jump")
player.exactMove(Tile(2538, 3545, 2), 30, Direction.NORTH)
player.exactMoveDelay(Tile(2538, 3545, 2), 30, Direction.NORTH)
delay(1)
player.exp(Skill.Agility, 15.0)
player.agilityStage(3)
Expand Down Expand Up @@ -53,7 +51,7 @@ objectOperate("Fire", "barbarian_outpost_spring") {
delay(1)
player.tele(2533, 3547, 3)
player.setAnimation("barbarian_spring_shoot")
player.exactMove(Tile(2532, 3553, 3), 60, Direction.NORTH)
player.exactMoveDelay(Tile(2532, 3553, 3), 60, Direction.NORTH)
target.animate("barbarian_spring_reset")
delay(2)
player.exp(Skill.Agility, 15.0)
Expand All @@ -65,8 +63,8 @@ objectOperate("Cross", "barbarian_outpost_balance_beam") {
delay()
player.setAnimation("circus_cartwheel")
delay()
player.exactMove(Tile(2536, 3553, 3), 45, Direction.EAST)
player.renderEmote = "beam_balance"
player.exactMoveDelay(Tile(2536, 3553, 3), 45, Direction.EAST)
player.renderEmote("beam_balance")
delay()
player.exp(Skill.Agility, 15.0)
player.agilityStage(6)
Expand All @@ -85,9 +83,9 @@ objectOperate("Jump-over", "barbarian_outpost_gap") {

objectOperate("Slide-down", "barbarian_outpost_roof") {
player.setAnimation("barbarian_slide_start")
player.exactMove(player.tile.copy(x = 2540), 30, Direction.EAST)
player.exactMoveDelay(player.tile.copy(x = 2540), 30, Direction.EAST)
player.setAnimation("barbarian_slide")
player.setExactMove(player.tile.copy(x = 2543, level = 1), 90, Direction.EAST)
player.exactMove(player.tile.copy(x = 2543, level = 1), 90, Direction.EAST)
delay()
player.setAnimation("barbarian_slide")
delay()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package world.gregs.voidps.world.activity.skill.agility.course

import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.data.Settings
import world.gregs.voidps.engine.entity.character.exactMove
import world.gregs.voidps.engine.entity.character.setExactMove
import world.gregs.voidps.engine.entity.character.face
import world.gregs.voidps.engine.entity.character.move.tele
import world.gregs.voidps.engine.entity.character.move.walkOver
Expand Down Expand Up @@ -36,7 +34,7 @@ objectOperate("Squeeze-through", "barbarian_outpost_entrance") {
}
player.setAnimation("climb_through_pipe")
val end = if (player.tile.y >= 3560) 3558 else 3561
player.exactMove(Tile(2552, end), 60, direction = if (player.tile.y >= 3560) Direction.SOUTH else Direction.NORTH)
player.exactMoveDelay(Tile(2552, end), 60, direction = if (player.tile.y >= 3560) Direction.SOUTH else Direction.NORTH)
}

objectOperate("Swing-on", "barbarian_outpost_rope_swing") {
Expand All @@ -51,12 +49,12 @@ objectOperate("Swing-on", "barbarian_outpost_rope_swing") {
target.animate("swing_rope")
delay()
if (success) {
player.setExactMove(player.tile.copy(y = 3549), 60, Direction.SOUTH)
player.exactMove(player.tile.copy(y = 3549), 60, Direction.SOUTH)
delay()
player.exp(Skill.Agility, 22.0)
player.message("You skillfully swing across.", ChatType.Filter)
} else {
player.exactMove(player.tile.copy(y = 3550), 50, Direction.SOUTH)
player.exactMoveDelay(player.tile.copy(y = 3550), 50, Direction.SOUTH)
delay(1)
player.tele(player.tile.copy(y = 9950))
player.damage(50)
Expand All @@ -74,7 +72,7 @@ objectOperate("Walk-across", "barbarian_outpost_log_balance") {
val disable = Settings["agility.disableCourseFailure", false]
val success = disable || Level.success(player.levels.get(Skill.Agility), 93) // 62.1% success rate at 35
player.message("You walk carefully across the slippery log...", ChatType.Filter)
player.renderEmote = "rope_balance"
player.renderEmote("rope_balance")
if (success) {
player.walkOver(Tile(2541, 3546))
player.clearRenderEmote()
Expand All @@ -88,7 +86,7 @@ objectOperate("Walk-across", "barbarian_outpost_log_balance") {
delay()
player.message("... but you lose your footing and fall into the water.", ChatType.Filter)
player.tele(2545, 3545)
player.renderEmote = "tread_water"
player.renderEmote("tread_water")
delay()
player.walkOver(Tile(2545, 3543))
player.message("Something in the water bites you.", ChatType.Filter)
Expand All @@ -114,7 +112,7 @@ objectOperate("Walk-across", "barbarian_outpost_balancing_ledge") {
val disable = Settings["agility.disableCourseFailure", false]
val success = disable || Level.success(player.levels.get(Skill.Agility), 93) // 62.1% success rate
delay()
player.renderEmote = "ledge_balance"
player.renderEmote("ledge_balance")
player.message("You put your foot on the ledge and try to edge across...", ChatType.Filter)
if (success) {
player.walkOver(Tile(2532, 3547, 1))
Expand All @@ -131,7 +129,7 @@ objectOperate("Walk-across", "barbarian_outpost_balancing_ledge") {
delay()
player.tele(2534, 3546, 1)
player.face(Direction.SOUTH)
player.renderEmote = "falling"
player.renderEmote("falling")
delay()
player.tele(2534, 3546, 0)
player.clearRenderEmote()
Expand All @@ -156,7 +154,7 @@ objectOperate("Climb-over", "barbarian_outpost_crumbling_wall") {
}
player.message("You climb the low wall...", ChatType.Filter)
player.setAnimation("climb_over_wall")
player.setExactMove(target.tile.addX(1), 60, Direction.EAST)
player.exactMove(target.tile.addX(1), 60, Direction.EAST)
delay()
if (target.tile.equals(2542, 3553)) {
if (player.agilityStage == 5) {
Expand Down
Loading

0 comments on commit c194e0f

Please sign in to comment.