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

Remove Events from entities #462

Merged
merged 15 commits into from
Feb 25, 2024
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ allprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")

group = "world.gregs.void"
version = "1.1.5"
version = "1.1.6"

java.sourceCompatibility = JavaVersion.VERSION_19
java.targetCompatibility = java.sourceCompatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import world.gregs.voidps.engine.entity.item.drop.DropTables
import world.gregs.voidps.engine.entity.item.floor.FloorItemTracking
import world.gregs.voidps.engine.entity.item.floor.FloorItems
import world.gregs.voidps.engine.entity.obj.GameObjects
import world.gregs.voidps.engine.event.EventHandlerStore
import world.gregs.voidps.engine.map.collision.CollisionStrategyProvider
import world.gregs.voidps.engine.map.collision.Collisions
import world.gregs.voidps.engine.map.collision.GameObjectCollision
Expand All @@ -28,14 +27,14 @@ import world.gregs.yaml.read.YamlReaderConfiguration

val engineModule = module {
// Entities
single { NPCs(get(), get(), get(), get()) }
single { NPCs(get(), get(), get()) }
single { Players() }
single { GameObjects(get(), get(), get(), getProperty<String>("loadUnusedObjects") == "true").apply { get<ZoneBatchUpdates>().register(this) } }
single { FloorItems(get(), get(), get()).apply { get<ZoneBatchUpdates>().register(this) } }
single { FloorItems(get(), get()).apply { get<ZoneBatchUpdates>().register(this) } }
single { FloorItemTracking(get(), get(), get()) }
single { Hunting(get(), get(), get(), get(), get(), get()) }
single {
PlayerAccounts(get(), get(), get(), get(), get(), get(), getProperty("savePath"), get(), get(), Tile(
PlayerAccounts(get(), get(), get(), get(), get(), getProperty("savePath"), get(), get(), Tile(
getIntProperty("homeX", 0), getIntProperty("homeY", 0), getIntProperty("homeLevel", 0)
), getProperty("experienceRate", "1.0").toDouble())
}
Expand All @@ -44,7 +43,6 @@ val engineModule = module {
// Map
single { ZoneBatchUpdates() }
single { DynamicZones(get(), get(), get()) }
single { EventHandlerStore() }
single(createdAtStart = true) { AreaDefinitions().load() }
// Network
single {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class InstructionHandlers(

fun handle(player: Player, instruction: Instruction) {
when (instruction) {
is Event -> player.events.emit(instruction)
is Event -> player.emit(instruction)
is InteractInterfaceItem -> interactInterfaceItem.validate(player, instruction)
is InteractInterfacePlayer -> interactInterfacePlayer.validate(player, instruction)
is InteractInterfaceObject -> interactInterfaceObject.validate(player, instruction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.ChatPrivate
class ChatPrivateHandler : InstructionHandler<ChatPrivate>() {

override fun validate(player: Player, instruction: ChatPrivate) {
player.events.emit(PrivateChat(instruction.friend, instruction.message))
player.emit(PrivateChat(instruction.friend, instruction.message))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.ChatPublic
class ChatPublicHandler : InstructionHandler<ChatPublic>() {

override fun validate(player: Player, instruction: ChatPublic) {
player.events.emit(PublicChat(instruction.message, instruction.effects))
player.emit(PublicChat(instruction.message, instruction.effects))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class ClanChatJoinHandler : InstructionHandler<ClanChatJoin>() {

override fun validate(player: Player, instruction: ClanChatJoin) {
if (instruction.name.isBlank()) {
player.events.emit(LeaveClanChat(forced = false))
player.emit(LeaveClanChat(forced = false))
} else {
player.events.emit(JoinClanChat(instruction.name))
player.emit(JoinClanChat(instruction.name))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.ClanChatKick
class ClanChatKickHandler : InstructionHandler<ClanChatKick>() {

override fun validate(player: Player, instruction: ClanChatKick) {
player.events.emit(KickClanChat(instruction.name))
player.emit(KickClanChat(instruction.name))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.ClanChatRank
class ClanChatRankHandler : InstructionHandler<ClanChatRank>() {

override fun validate(player: Player, instruction: ClanChatRank) {
player.events.emit(UpdateClanChatRank(instruction.name, instruction.rank))
player.emit(UpdateClanChatRank(instruction.name, instruction.rank))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DialogueContinueHandler(
return
}

player.events.emit(
player.emit(
ContinueDialogue(
id,
component.stringId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.EnterInt
class EnterIntHandler : InstructionHandler<EnterInt>() {

override fun validate(player: Player, instruction: EnterInt) {
player.events.emit(IntEntered(instruction.value))
player.emit(IntEntered(instruction.value))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.EnterString
class EnterStringHandler : InstructionHandler<EnterString>() {

override fun validate(player: Player, instruction: EnterString) {
player.events.emit(StringEntered(instruction.value))
player.emit(StringEntered(instruction.value))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.ExecuteCommand
class ExecuteCommandHandler : InstructionHandler<ExecuteCommand>() {

override fun validate(player: Player, instruction: ExecuteCommand) {
player.events.emit(Command(player, instruction.prefix, instruction.content))
player.emit(Command(player, instruction.prefix, instruction.content))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.FriendAdd
class FriendAddHandler : InstructionHandler<FriendAdd>() {

override fun validate(player: Player, instruction: FriendAdd) {
player.events.emit(AddFriend(instruction.friendsName))
player.emit(AddFriend(instruction.friendsName))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.FriendDelete
class FriendDeleteHandler : InstructionHandler<FriendDelete>() {

override fun validate(player: Player, instruction: FriendDelete) {
player.events.emit(DeleteFriend(instruction.friendsName))
player.emit(DeleteFriend(instruction.friendsName))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.IgnoreAdd
class IgnoreAddHandler : InstructionHandler<IgnoreAdd>() {

override fun validate(player: Player, instruction: IgnoreAdd) {
player.events.emit(AddIgnore(instruction.name))
player.emit(AddIgnore(instruction.name))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.IgnoreDelete
class IgnoreDeleteHandler : InstructionHandler<IgnoreDelete>() {

override fun validate(player: Player, instruction: IgnoreDelete) {
player.events.emit(DeleteIgnore(instruction.name))
player.emit(DeleteIgnore(instruction.name))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class InterfaceOnInterfaceOptionHandler(
val (toId, toComponent, toItem, toInventory) = handler.getInterfaceItem(player, toInterfaceId, toComponentId, toItemId, toSlot) ?: return

player.closeInterfaces()
player.events.emit(
player.emit(
ItemOnItem(
fromItem,
toItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class InterfaceOptionHandler(
}

val selectedOption = options.getOrNull(option) ?: ""
player.events.emit(
player.emit(
InterfaceOption(
character = player,
id = id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InterfaceSwitchHandler(
val (fromId, fromComponent, fromItem, fromInventory) = handler.getInterfaceItem(player, fromInterfaceId, fromComponentId, fromItemId, fromSlot) ?: return
val (toId, toComponent, toItem, toInventory) = handler.getInterfaceItem(player, toInterfaceId, toComponentId, toItemId, toSlot) ?: return

player.events.emit(
player.emit(
InterfaceSwitch(
id = fromId,
component = fromComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.QuickChatPrivate
class QuickChatPrivateHandler : InstructionHandler<QuickChatPrivate>() {

override fun validate(player: Player, instruction: QuickChatPrivate) {
player.events.emit(PrivateQuickChat(instruction.name, instruction.file, instruction.data))
player.emit(PrivateQuickChat(instruction.name, instruction.file, instruction.data))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import world.gregs.voidps.network.instruct.QuickChatPublic
class QuickChatPublicHandler : InstructionHandler<QuickChatPublic>() {

override fun validate(player: Player, instruction: QuickChatPublic) {
player.events.emit(PublicQuickChat(instruction.script, instruction.file, instruction.data))
player.emit(PublicQuickChat(instruction.script, instruction.file, instruction.data))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import world.gregs.voidps.engine.data.definition.InterfaceDefinitions
import world.gregs.voidps.engine.entity.character.Character
import world.gregs.voidps.engine.entity.character.player.Player
import world.gregs.voidps.engine.entity.item.Item
import world.gregs.voidps.engine.event.Events
import world.gregs.voidps.engine.event.EventDispatcher
import world.gregs.voidps.engine.get
import world.gregs.voidps.network.client.Client
import world.gregs.voidps.network.encode.*
Expand All @@ -21,7 +21,7 @@ import world.gregs.voidps.network.encode.*
* API for the interacting and tracking of client interfaces
*/
class Interfaces(
private val events: Events,
private val events: EventDispatcher,
internal var client: Client? = null,
internal val definitions: InterfaceDefinitions,
private val openInterfaces: MutableSet<String> = ObjectOpenHashSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package world.gregs.voidps.engine.client.variable

import world.gregs.voidps.engine.data.config.VariableDefinition.Companion.persist
import world.gregs.voidps.engine.data.definition.VariableDefinitions
import world.gregs.voidps.engine.event.Events
import world.gregs.voidps.engine.event.EventDispatcher
import world.gregs.voidps.network.client.Client

class PlayerVariables(
events: Events,
events: EventDispatcher,
data: MutableMap<String, Any>,
var definitions: VariableDefinitions = VariableDefinitions(),
val temp: MutableMap<String, Any> = mutableMapOf()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package world.gregs.voidps.engine.client.variable

import it.unimi.dsi.fastutil.objects.ObjectArrayList
import world.gregs.voidps.engine.event.Events
import world.gregs.voidps.engine.event.EventDispatcher

class VariableBits(
private val variables: Variables,
private val events: Events
private val events: EventDispatcher
) {

fun contains(key: String, id: Any): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package world.gregs.voidps.engine.client.variable

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
import world.gregs.voidps.engine.event.Events
import world.gregs.voidps.engine.event.EventDispatcher

open class Variables(
private var events: Events,
private var events: EventDispatcher,
val data: MutableMap<String, Any> = Object2ObjectOpenHashMap(2)
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import world.gregs.voidps.engine.entity.character.player.skill.exp.Experience
import world.gregs.voidps.engine.entity.character.player.skill.level.Levels
import world.gregs.voidps.engine.entity.character.player.skill.level.PlayerLevels
import world.gregs.voidps.engine.entity.item.Item
import world.gregs.voidps.engine.event.EventHandlerStore
import world.gregs.voidps.engine.map.collision.CollisionStrategyProvider
import world.gregs.voidps.network.visual.PlayerVisuals
import world.gregs.voidps.type.Direction
Expand All @@ -31,7 +30,6 @@ import world.gregs.yaml.Yaml
import java.io.File

class PlayerAccounts(
private val store: EventHandlerStore,
private val interfaceDefinitions: InterfaceDefinitions,
private val inventoryDefinitions: InventoryDefinitions,
private val itemDefinitions: ItemDefinitions,
Expand Down Expand Up @@ -103,21 +101,20 @@ class PlayerAccounts(
}

fun initPlayer(player: Player, index: Int) {
store.populate(player)
player.index = index
player.visuals = PlayerVisuals(index, player.body)
player.interfaces = Interfaces(player.events, player.client, interfaceDefinitions)
player.interfaces = Interfaces(player, player.client, interfaceDefinitions)
player.interfaceOptions = InterfaceOptions(player, interfaceDefinitions, inventoryDefinitions)
player.options = PlayerOptions(player)
(player.variables as PlayerVariables).definitions = variableDefinitions
player.inventories.definitions = inventoryDefinitions
player.inventories.itemDefinitions = itemDefinitions
player.inventories.validItemRule = validItems
player.inventories.normalStack = DependentOnItem(itemDefinitions)
player.inventories.events = player.events
player.inventories.events = player
player.previousTile = player.tile.add(Direction.WEST.delta)
player.experience.events = player.events
player.levels.link(player.events, PlayerLevels(player.experience))
player.experience.events = player
player.levels.link(player, PlayerLevels(player.experience))
player.body.link(player.equipment)
player.body.updateAll()
player.appearance.displayName = player.name
Expand Down
14 changes: 4 additions & 10 deletions engine/src/main/kotlin/world/gregs/voidps/engine/entity/World.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import world.gregs.voidps.engine.GameLoop
import world.gregs.voidps.engine.client.variable.Variable
import world.gregs.voidps.engine.client.variable.Variables
import world.gregs.voidps.engine.event.EventDispatcher
import world.gregs.voidps.engine.event.EventHandlerStore
import world.gregs.voidps.engine.event.Events
import world.gregs.voidps.engine.get
import world.gregs.voidps.engine.timer.TimerQueue
import world.gregs.voidps.engine.timer.Timers
import world.gregs.voidps.type.Tile
Expand All @@ -19,9 +16,8 @@ const val MAX_NPCS = 0x8000 // 32768

object World : Entity, Variable, EventDispatcher, Runnable, KoinComponent {
override var tile = Tile.EMPTY
override val events: Events = Events(this)

override val variables = Variables(events)
override val variables = Variables(this)

var id = 0
private set(value) {
Expand All @@ -42,12 +38,10 @@ object World : Entity, Variable, EventDispatcher, Runnable, KoinComponent {
fun start(members: Boolean = true, id: Int = 16) {
this.members = members
this.id = id
val store: EventHandlerStore = get()
store.populate(World)
events.emit(Registered)
emit(Registered)
}

val timers: Timers = TimerQueue(events)
val timers: Timers = TimerQueue(this)

private val actions = ConcurrentHashMap<String, Pair<Int, () -> Unit>>()

Expand Down Expand Up @@ -78,6 +72,6 @@ object World : Entity, Variable, EventDispatcher, Runnable, KoinComponent {
}

fun shutdown() {
events.emit(Unregistered)
emit(Unregistered)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CombatMovement(
val attackRange = attackRange()
if (arrived(if (attackRange == 1) -1 else attackRange)) {
clearSteps()
character.events.emit(CombatReached(target))
character.emit(CombatReached(target))
return true
}
return false
Expand Down Expand Up @@ -103,6 +103,6 @@ class CombatMovement(
}

override fun stop() {
character.events.emit(CombatStop(target))
character.emit(CombatStop(target))
}
}
Loading
Loading