From 05c89f08ea2a1fdc2d65f6255f97852eca8b442a Mon Sep 17 00:00:00 2001 From: GregHib Date: Sat, 24 Feb 2024 21:42:13 +0000 Subject: [PATCH 01/15] Fix abyssal whip special attack --- .../player/combat/melee/special/AbyssalWhip.kts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/AbyssalWhip.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/AbyssalWhip.kts index 526c3818a..a4e409bb6 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/AbyssalWhip.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/AbyssalWhip.kts @@ -8,19 +8,20 @@ import world.gregs.voidps.engine.event.Priority import world.gregs.voidps.world.interact.entity.combat.attackType import world.gregs.voidps.world.interact.entity.combat.hit.block import world.gregs.voidps.world.interact.entity.combat.hit.hit +import world.gregs.voidps.world.interact.entity.combat.specialAttackSwing import world.gregs.voidps.world.interact.entity.combat.weaponSwing import world.gregs.voidps.world.interact.entity.player.combat.special.MAX_SPECIAL_ATTACK import world.gregs.voidps.world.interact.entity.player.combat.special.drainSpecialEnergy import world.gregs.voidps.world.interact.entity.player.combat.special.specialAttack import world.gregs.voidps.world.interact.entity.player.energy.runEnergy -weaponSwing("abyssal_whip*", Priority.LOW) { player -> - if (player.specialAttack && !drainSpecialEnergy(player, MAX_SPECIAL_ATTACK / 2)) { +specialAttackSwing("abyssal_whip*", priority = Priority.LOW) { player -> + if (!drainSpecialEnergy(player, MAX_SPECIAL_ATTACK / 2)) { delay = -1 - return@weaponSwing + return@specialAttackSwing } - player.setAnimation("whip_${if (player.specialAttack) "special" else player.attackType}") - if (player.hit(target) != -1 && player.specialAttack) { + player.setAnimation("whip_special") + if (player.hit(target) != -1) { if (target is Player) { val tenPercent = (target.runEnergy / 100) * 10 if (tenPercent > 0) { From 8f44557e9821aaff6306d049511caf4a10854125 Mon Sep 17 00:00:00 2001 From: GregHib Date: Sat, 24 Feb 2024 21:42:29 +0000 Subject: [PATCH 02/15] Fix combat under attack resetting --- .../world/gregs/voidps/world/interact/entity/combat/Combat.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts index 526a8d63b..6334b3c26 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts @@ -79,6 +79,7 @@ onCharacter { character -> } characterDeath { character -> + character.stop("under_attack") for (attacker in character.attackers) { if (attacker.target == character) { attacker.stop("under_attack") From 00c415cacc9ff5e79cda6e61e3707c192f185908 Mon Sep 17 00:00:00 2001 From: GregHib Date: Sat, 24 Feb 2024 22:03:43 +0000 Subject: [PATCH 03/15] Add event emitting helper --- .../client/instruction/InstructionHandlers.kt | 3 ++- .../instruction/handle/ChatPrivateHandler.kt | 3 ++- .../instruction/handle/ChatPublicHandler.kt | 3 ++- .../instruction/handle/ClanChatJoinHandler.kt | 5 +++-- .../instruction/handle/ClanChatKickHandler.kt | 3 ++- .../instruction/handle/ClanChatRankHandler.kt | 3 ++- .../handle/DialogueContinueHandler.kt | 3 ++- .../instruction/handle/EnterIntHandler.kt | 3 ++- .../instruction/handle/EnterStringHandler.kt | 3 ++- .../handle/ExecuteCommandHandler.kt | 3 ++- .../instruction/handle/FriendAddHandler.kt | 3 ++- .../instruction/handle/FriendDeleteHandler.kt | 3 ++- .../instruction/handle/IgnoreAddHandler.kt | 3 ++- .../instruction/handle/IgnoreDeleteHandler.kt | 3 ++- .../InterfaceOnInterfaceOptionHandler.kt | 3 ++- .../handle/InterfaceOptionHandler.kt | 3 ++- .../handle/InterfaceSwitchHandler.kt | 3 ++- .../handle/QuickChatPrivateHandler.kt | 3 ++- .../handle/QuickChatPublicHandler.kt | 3 ++- .../world/gregs/voidps/engine/entity/World.kt | 5 +++-- .../character/mode/combat/CombatMovement.kt | 5 +++-- .../character/mode/interact/Interact.kt | 3 ++- .../entity/character/mode/move/Movement.kt | 7 ++++--- .../engine/entity/character/npc/NPCs.kt | 5 +++-- .../entity/character/npc/hunt/Hunting.kt | 9 +++++---- .../engine/entity/character/player/Player.kt | 9 +++++---- .../engine/entity/character/player/Players.kt | 3 ++- .../engine/entity/item/floor/FloorItems.kt | 7 ++++--- .../voidps/engine/event/EventHandlerStore.kt | 8 ++++++++ .../voidps/engine/map/zone/DynamicZones.kt | 3 ++- .../kotlin/world/gregs/voidps/GameTick.kt | 3 ++- .../world/gregs/voidps/bot/BotSpawns.kts | 5 +++-- .../world/activity/skill/ItemOnItems.kts | 3 ++- .../world/command/admin/AdminCommands.kts | 3 ++- .../voidps/world/community/chat/Chat.kts | 7 ++++--- .../voidps/world/community/chat/QuickChat.kts | 7 ++++--- .../voidps/world/community/clan/ClanChat.kts | 9 +++++---- .../voidps/world/community/clan/ClanSetup.kts | 3 ++- .../world/interact/dialogue/type/LevelUp.kts | 3 ++- .../world/interact/entity/combat/Combat.kts | 3 ++- .../world/interact/entity/combat/hit/Hit.kt | 5 +++-- .../interact/entity/death/DeathCharacter.kts | 3 ++- .../world/interact/entity/death/DeathNPC.kts | 5 +++-- .../interact/entity/npc/shop/OpenShop.kt | 3 ++- .../world/interact/entity/obj/Teleports.kt | 5 +++-- .../world/interact/entity/obj/door/Doors.kts | 3 ++- .../entity/player/combat/consume/Eating.kts | 5 +++-- .../player/combat/prayer/PrayerToggle.kts | 9 +++++---- .../entity/player/equip/EquipmentBonuses.kts | 5 +++-- .../entity/player/equip/Inventory.kts | 3 ++- .../entity/player/equip/WornEquipment.kts | 3 ++- .../gregs/voidps/world/map/varrock/Aubury.kts | 5 +++-- .../community/friend/PrivateChatStatusTest.kt | 7 ++++--- .../voidps/world/community/trade/LendTest.kt | 19 ++++++++++--------- .../player/combat/MagicCombatFormulaTest.kt | 5 +++-- .../player/combat/MeleeCombatFormulaTest.kt | 5 +++-- .../player/combat/RangedCombatFormulaTest.kt | 5 +++-- .../voidps/world/script/InstructionCalls.kt | 13 +++++++------ 58 files changed, 171 insertions(+), 106 deletions(-) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionHandlers.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionHandlers.kt index f0218f709..d78c14c38 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionHandlers.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionHandlers.kt @@ -11,6 +11,7 @@ import world.gregs.voidps.engine.entity.character.player.Players import world.gregs.voidps.engine.entity.item.floor.FloorItems import world.gregs.voidps.engine.entity.obj.GameObjects import world.gregs.voidps.engine.event.Event +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.Instruction import world.gregs.voidps.network.instruct.* @@ -62,7 +63,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) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPrivateHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPrivateHandler.kt index 49635cf6c..98458e1f1 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPrivateHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPrivateHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.friend.PrivateChat +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ChatPrivate class ChatPrivateHandler : InstructionHandler() { override fun validate(player: Player, instruction: ChatPrivate) { - player.events.emit(PrivateChat(instruction.friend, instruction.message)) + player.emit(PrivateChat(instruction.friend, instruction.message)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPublicHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPublicHandler.kt index 0bd259206..5f16855e9 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPublicHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPublicHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.global.PublicChat +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ChatPublic class ChatPublicHandler : InstructionHandler() { override fun validate(player: Player, instruction: ChatPublic) { - player.events.emit(PublicChat(instruction.message, instruction.effects)) + player.emit(PublicChat(instruction.message, instruction.effects)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatJoinHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatJoinHandler.kt index d2809c63e..6221dd6d5 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatJoinHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatJoinHandler.kt @@ -4,15 +4,16 @@ import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.clan.JoinClanChat import world.gregs.voidps.engine.entity.character.player.chat.clan.LeaveClanChat +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ClanChatJoin class ClanChatJoinHandler : InstructionHandler() { 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)) } } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatKickHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatKickHandler.kt index 2ffe5e602..24cf265e8 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatKickHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatKickHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.clan.KickClanChat +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ClanChatKick class ClanChatKickHandler : InstructionHandler() { override fun validate(player: Player, instruction: ClanChatKick) { - player.events.emit(KickClanChat(instruction.name)) + player.emit(KickClanChat(instruction.name)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatRankHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatRankHandler.kt index b3edff415..308497867 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatRankHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatRankHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.clan.UpdateClanChatRank +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ClanChatRank class ClanChatRankHandler : InstructionHandler() { override fun validate(player: Player, instruction: ClanChatRank) { - player.events.emit(UpdateClanChatRank(instruction.name, instruction.rank)) + player.emit(UpdateClanChatRank(instruction.name, instruction.rank)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/DialogueContinueHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/DialogueContinueHandler.kt index 9f51cc3f5..727b3bbfa 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/DialogueContinueHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/DialogueContinueHandler.kt @@ -5,6 +5,7 @@ import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.ui.dialogue.ContinueDialogue import world.gregs.voidps.engine.data.definition.InterfaceDefinitions import world.gregs.voidps.engine.entity.character.player.Player +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.InteractDialogue class DialogueContinueHandler( @@ -27,7 +28,7 @@ class DialogueContinueHandler( return } - player.events.emit( + player.emit( ContinueDialogue( id, component.stringId, diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterIntHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterIntHandler.kt index f6e61e889..95725bb96 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterIntHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterIntHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.ui.event.IntEntered import world.gregs.voidps.engine.entity.character.player.Player +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.EnterInt class EnterIntHandler : InstructionHandler() { override fun validate(player: Player, instruction: EnterInt) { - player.events.emit(IntEntered(instruction.value)) + player.emit(IntEntered(instruction.value)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterStringHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterStringHandler.kt index 9aa88723f..2616f11ff 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterStringHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterStringHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.ui.event.StringEntered import world.gregs.voidps.engine.entity.character.player.Player +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.EnterString class EnterStringHandler : InstructionHandler() { override fun validate(player: Player, instruction: EnterString) { - player.events.emit(StringEntered(instruction.value)) + player.emit(StringEntered(instruction.value)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ExecuteCommandHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ExecuteCommandHandler.kt index 60ab5639f..ac47e8031 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ExecuteCommandHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ExecuteCommandHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.ui.event.Command import world.gregs.voidps.engine.entity.character.player.Player +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ExecuteCommand class ExecuteCommandHandler : InstructionHandler() { override fun validate(player: Player, instruction: ExecuteCommand) { - player.events.emit(Command(player, instruction.prefix, instruction.content)) + player.emit(Command(player, instruction.prefix, instruction.content)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendAddHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendAddHandler.kt index da5968338..37ca5ee63 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendAddHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendAddHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.friend.AddFriend +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.FriendAdd class FriendAddHandler : InstructionHandler() { override fun validate(player: Player, instruction: FriendAdd) { - player.events.emit(AddFriend(instruction.friendsName)) + player.emit(AddFriend(instruction.friendsName)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendDeleteHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendDeleteHandler.kt index 65998dfb0..dcaa3ee1b 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendDeleteHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendDeleteHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.friend.DeleteFriend +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.FriendDelete class FriendDeleteHandler : InstructionHandler() { override fun validate(player: Player, instruction: FriendDelete) { - player.events.emit(DeleteFriend(instruction.friendsName)) + player.emit(DeleteFriend(instruction.friendsName)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreAddHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreAddHandler.kt index 1979b7ab2..cd496448c 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreAddHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreAddHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.ignore.AddIgnore +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.IgnoreAdd class IgnoreAddHandler : InstructionHandler() { override fun validate(player: Player, instruction: IgnoreAdd) { - player.events.emit(AddIgnore(instruction.name)) + player.emit(AddIgnore(instruction.name)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreDeleteHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreDeleteHandler.kt index ab011e5ec..fae31cd33 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreDeleteHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreDeleteHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.ignore.DeleteIgnore +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.IgnoreDelete class IgnoreDeleteHandler : InstructionHandler() { override fun validate(player: Player, instruction: IgnoreDelete) { - player.events.emit(DeleteIgnore(instruction.name)) + player.emit(DeleteIgnore(instruction.name)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt index d742d64a6..bbe637a9f 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt @@ -5,6 +5,7 @@ import world.gregs.voidps.engine.client.instruction.InterfaceHandler import world.gregs.voidps.engine.client.ui.closeInterfaces import world.gregs.voidps.engine.client.ui.interact.ItemOnItem import world.gregs.voidps.engine.entity.character.player.Player +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.InteractInterfaceItem /** @@ -22,7 +23,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, diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOptionHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOptionHandler.kt index 6bab79a33..439b0d416 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOptionHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOptionHandler.kt @@ -5,6 +5,7 @@ import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.instruction.InterfaceHandler import world.gregs.voidps.engine.client.ui.InterfaceOption import world.gregs.voidps.engine.entity.character.player.Player +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.InteractInterface class InterfaceOptionHandler( @@ -28,7 +29,7 @@ class InterfaceOptionHandler( } val selectedOption = options.getOrNull(option) ?: "" - player.events.emit( + player.emit( InterfaceOption( character = player, id = id, diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceSwitchHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceSwitchHandler.kt index fdc2d2945..e7a84f24b 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceSwitchHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceSwitchHandler.kt @@ -4,6 +4,7 @@ import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.instruction.InterfaceHandler import world.gregs.voidps.engine.client.ui.InterfaceSwitch import world.gregs.voidps.engine.entity.character.player.Player +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.MoveInventoryItem class InterfaceSwitchHandler( @@ -21,7 +22,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, diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPrivateHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPrivateHandler.kt index 71bb26fb4..c46e7b00f 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPrivateHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPrivateHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.friend.PrivateQuickChat +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.QuickChatPrivate class QuickChatPrivateHandler : InstructionHandler() { 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)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPublicHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPublicHandler.kt index eedf5f6ff..4d38ba056 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPublicHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPublicHandler.kt @@ -3,12 +3,13 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.global.PublicQuickChat +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.QuickChatPublic class QuickChatPublicHandler : InstructionHandler() { 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)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/World.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/World.kt index 142d24103..3508791ae 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/World.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/World.kt @@ -7,6 +7,7 @@ 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.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.timer.TimerQueue import world.gregs.voidps.engine.timer.Timers @@ -44,7 +45,7 @@ object World : Entity, Variable, EventDispatcher, Runnable, KoinComponent { this.id = id val store: EventHandlerStore = get() store.populate(World) - events.emit(Registered) + emit(Registered) } val timers: Timers = TimerQueue(events) @@ -78,6 +79,6 @@ object World : Entity, Variable, EventDispatcher, Runnable, KoinComponent { } fun shutdown() { - events.emit(Unregistered) + emit(Unregistered) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/combat/CombatMovement.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/combat/CombatMovement.kt index 8b12886c6..607f968af 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/combat/CombatMovement.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/combat/CombatMovement.kt @@ -14,6 +14,7 @@ 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.chat.cantReach import world.gregs.voidps.engine.entity.character.watch +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.type.Direction import world.gregs.voidps.type.Tile @@ -75,7 +76,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 @@ -103,6 +104,6 @@ class CombatMovement( } override fun stop() { - character.events.emit(CombatStop(target)) + character.emit(CombatStop(target)) } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/Interact.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/Interact.kt index 390e6ea3f..f3ec51feb 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/Interact.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/Interact.kt @@ -12,6 +12,7 @@ import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.cantReach import world.gregs.voidps.engine.entity.character.player.chat.noInterest import world.gregs.voidps.engine.entity.character.watch +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.suspend.resumeSuspension /** @@ -155,7 +156,7 @@ class Interact( character.resumeSuspension() return true } - if (!event.launched && character.events.emit(event)) { + if (!event.launched && character.emit(event)) { event.launched = true return true } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/move/Movement.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/move/Movement.kt index 572498e36..d28a27ab1 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/move/Movement.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/move/Movement.kt @@ -19,6 +19,7 @@ import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.movementType import world.gregs.voidps.engine.entity.character.player.temporaryMoveType import world.gregs.voidps.engine.entity.character.size +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.map.Overlap import world.gregs.voidps.engine.map.region.RegionRetry @@ -56,7 +57,7 @@ open class Movement( override fun tick() { if (character is Player && character.viewport?.loaded == false) { if (character.viewport != null && character.inc("fail_load_count") > 10) { - character.events.emit(RegionRetry) + character.emit(RegionRetry) character.clear("fail_load_count") } return @@ -204,12 +205,12 @@ open class Movement( val to = character.tile for (def in definitions.get(from.zone)) { if (from in def.area && to !in def.area) { - character.events.emit(AreaExited(character, def.name, def.tags, def.area)) + character.emit(AreaExited(character, def.name, def.tags, def.area)) } } for (def in definitions.get(to.zone)) { if (to in def.area && from !in def.area) { - character.events.emit(AreaEntered(character, def.name, def.tags, def.area)) + character.emit(AreaEntered(character, def.name, def.tags, def.area)) } } } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPCs.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPCs.kt index 71fc38ed2..b61e1fdee 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPCs.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPCs.kt @@ -11,6 +11,7 @@ import world.gregs.voidps.engine.entity.character.face import world.gregs.voidps.engine.entity.character.mode.Wander import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.event.EventHandlerStore +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.getProperty import world.gregs.voidps.engine.map.collision.CollisionStrategyProvider import world.gregs.voidps.engine.map.collision.Collisions @@ -88,7 +89,7 @@ data class NPCs( npc["respawn_delay"] = respawnDelay npc["respawn_direction"] = direction } - npc.events.emit(Registered) + npc.emit(Registered) return npc } @@ -122,7 +123,7 @@ data class NPCs( override fun clear() { for (npc in this) { - npc.events.emit(Unregistered) + npc.emit(Unregistered) } super.clear() } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/hunt/Hunting.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/hunt/Hunting.kt index 0bb827809..5237d45c7 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/hunt/Hunting.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/hunt/Hunting.kt @@ -20,6 +20,7 @@ import world.gregs.voidps.engine.entity.item.floor.FloorItem import world.gregs.voidps.engine.entity.item.floor.FloorItems import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.obj.GameObjects +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.type.Direction import world.gregs.voidps.type.Tile import world.gregs.voidps.type.Zone @@ -56,22 +57,22 @@ class Hunting( "player" -> { val targets = getCharacters(npc, players, range, definition) val target = targets.randomOrNull() ?: continue - npc.events.emit(HuntPlayer(mode, target)) + npc.emit(HuntPlayer(mode, target)) } "npc" -> { val targets = getCharacters(npc, npcs, range, definition) val target = targets.randomOrNull() ?: continue - npc.events.emit(HuntNPC(mode, target)) + npc.emit(HuntNPC(mode, target)) } "object" -> { val targets = getObjects(npc, definition) val target = targets.randomOrNull() ?: continue - npc.events.emit(HuntObject(mode, target)) + npc.emit(HuntObject(mode, target)) } "floor_item" -> { val targets = getItems(npc, range, definition) val target = targets.randomOrNull() ?: continue - npc.events.emit(HuntFloorItem(mode, target)) + npc.emit(HuntFloorItem(mode, target)) } } } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt index 8faba62af..99c4ffb6a 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt @@ -23,6 +23,7 @@ import world.gregs.voidps.engine.entity.character.player.equip.BodyParts 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.event.Events +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.inv.Inventories import world.gregs.voidps.engine.queue.ActionQueue @@ -117,11 +118,11 @@ class Player( logout(false) } } - events.emit(Registered) + emit(Registered) val definitions = get() for (def in definitions.get(tile.zone)) { if (tile in def.area) { - events.emit(AreaEntered(this, def.name, def.tags, def.area)) + emit(AreaEntered(this, def.name, def.tags, def.area)) } } } @@ -153,10 +154,10 @@ class Player( val definitions = get() for (def in definitions.get(tile.zone)) { if (tile in def.area) { - events.emit(AreaExited(this@Player, def.name, def.tags, def.area)) + emit(AreaExited(this@Player, def.name, def.tags, def.area)) } } - events.emit(Unregistered) + emit(Unregistered) } } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Players.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Players.kt index 4e6688b80..c4e1a9926 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Players.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Players.kt @@ -3,6 +3,7 @@ package world.gregs.voidps.engine.entity.character.player import world.gregs.voidps.engine.entity.MAX_PLAYERS import world.gregs.voidps.engine.entity.Unregistered import world.gregs.voidps.engine.entity.character.CharacterList +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.type.Tile import world.gregs.voidps.type.Zone @@ -22,7 +23,7 @@ class Players : CharacterList(MAX_PLAYERS) { override fun clear() { for (player in this) { - player.events.emit(Unregistered) + player.emit(Unregistered) } super.clear() } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItems.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItems.kt index f7bce9d55..fc2aba61b 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItems.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItems.kt @@ -12,6 +12,7 @@ import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.name import world.gregs.voidps.engine.entity.item.floor.FloorItems.Companion.MAX_TILE_ITEMS import world.gregs.voidps.engine.event.EventHandlerStore +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.encode.send import world.gregs.voidps.network.encode.zone.FloorItemAddition import world.gregs.voidps.network.encode.zone.FloorItemRemoval @@ -62,7 +63,7 @@ class FloorItems( } if (list.add(item)) { batches.add(item.tile.zone, FloorItemAddition(item.tile.id, item.def.id, item.amount, item.owner)) - item.events.emit(Registered) + item.emit(Registered) } } @@ -115,7 +116,7 @@ class FloorItems( zonePool.recycle(zone) } } - item.events.emit(Unregistered) + item.emit(Unregistered) return true } return false @@ -126,7 +127,7 @@ class FloorItems( for ((_, items) in zone) { for (item in items) { batches.add(item.tile.zone, FloorItemRemoval(item.tile.id, item.def.id, item.owner)) - item.events.emit(Unregistered) + item.emit(Unregistered) } tilePool.recycle(items) } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt index f58a37f62..c77b2a737 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt @@ -51,6 +51,14 @@ class EventHandlerStore { } } +fun EventDispatcher.emit(event: E): Boolean { + return events.emit(event) +} + +fun EventDispatcher.emit(event: E): Boolean { + return events.emit(event) +} + @Suppress("UNCHECKED_CAST") inline fun addEvent(noinline condition: E.(T) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(T) -> Unit) { get().add(T::class, E::class, condition as Event.(EventDispatcher) -> Boolean, priority, block as suspend Event.(EventDispatcher) -> Unit) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/map/zone/DynamicZones.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/map/zone/DynamicZones.kt index 0deda7dad..dbd3a6991 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/map/zone/DynamicZones.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/map/zone/DynamicZones.kt @@ -5,6 +5,7 @@ import it.unimi.dsi.fastutil.ints.IntOpenHashSet import world.gregs.voidps.engine.data.definition.MapDefinitions import world.gregs.voidps.engine.entity.World import world.gregs.voidps.engine.entity.obj.GameObjects +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.map.collision.Collisions import world.gregs.voidps.engine.map.collision.clear import world.gregs.voidps.type.Region @@ -72,7 +73,7 @@ class DynamicZones( regions.remove(region.id) } } - World.events.emit(ReloadZone(to)) + World.emit(ReloadZone(to)) } companion object { diff --git a/game/src/main/kotlin/world/gregs/voidps/GameTick.kt b/game/src/main/kotlin/world/gregs/voidps/GameTick.kt index bd5fedf51..56cc7e3a7 100644 --- a/game/src/main/kotlin/world/gregs/voidps/GameTick.kt +++ b/game/src/main/kotlin/world/gregs/voidps/GameTick.kt @@ -28,6 +28,7 @@ import world.gregs.voidps.engine.entity.character.player.Players 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.emit import world.gregs.voidps.engine.get import world.gregs.voidps.network.NetworkQueue import world.gregs.voidps.network.visual.NPCVisuals @@ -91,7 +92,7 @@ fun getTickStages( private class AiTick : Runnable { override fun run() { - World.events.emit(AiTick) + World.emit(AiTick) } } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts b/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts index 42bfd77dc..393ca22ad 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts @@ -17,6 +17,7 @@ import world.gregs.voidps.engine.entity.character.player.sex import world.gregs.voidps.engine.entity.worldSpawn import world.gregs.voidps.engine.event.Event import world.gregs.voidps.engine.event.EventHandlerStore +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.getIntProperty import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.add @@ -88,7 +89,7 @@ adminCommand("bot") { if (content.isNotBlank()) { player["task"] = content } - bot.events.emit(StartBot) + bot.emit(StartBot) } } @@ -105,7 +106,7 @@ fun spawn() { val client = if (TaskManager.DEBUG) DummyClient() else null bot.initBot() bot.login(client, 0) - bot.events.emit(StartBot) + bot.emit(StartBot) bot.viewport?.loaded = true delay(3) bots.add(bot) diff --git a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/ItemOnItems.kts b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/ItemOnItems.kts index 71380a46d..659857c8c 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/ItemOnItems.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/ItemOnItems.kts @@ -18,6 +18,7 @@ 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.event.emit import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.inventory @@ -137,7 +138,7 @@ fun replaceItems( for (add in def.add) { player.inventory.add(add.id, add.amount) } - player.events.emit(ItemUsedOnItem(def)) + player.emit(ItemUsedOnItem(def)) } else { if (def.failure.isNotEmpty()) { player.message(def.failure, ChatType.Filter) diff --git a/game/src/main/kotlin/world/gregs/voidps/world/command/admin/AdminCommands.kts b/game/src/main/kotlin/world/gregs/voidps/world/command/admin/AdminCommands.kts index 39d605481..d86c521ce 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/command/admin/AdminCommands.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/command/admin/AdminCommands.kts @@ -40,6 +40,7 @@ import world.gregs.voidps.engine.entity.item.drop.DropTables import world.gregs.voidps.engine.entity.item.drop.ItemDrop import world.gregs.voidps.engine.entity.obj.GameObjects import world.gregs.voidps.engine.entity.worldSpawn +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.* @@ -354,7 +355,7 @@ adminCommand("reload") { } adminCommand("shop") { - player.events.emit(OpenShop(content)) + player.emit(OpenShop(content)) } adminCommand("debug") { diff --git a/game/src/main/kotlin/world/gregs/voidps/world/community/chat/Chat.kts b/game/src/main/kotlin/world/gregs/voidps/world/community/chat/Chat.kts index d89e2b3dd..24edfbd31 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/community/chat/Chat.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/community/chat/Chat.kts @@ -12,6 +12,7 @@ import world.gregs.voidps.engine.entity.character.player.chat.global.PublicChat import world.gregs.voidps.engine.entity.character.player.chat.global.PublicChatMessage import world.gregs.voidps.engine.entity.character.player.name import world.gregs.voidps.engine.entity.character.player.rights +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.event.on import world.gregs.voidps.engine.inject import world.gregs.voidps.network.encode.clanChat @@ -28,7 +29,7 @@ val huffman: Huffman by inject() on({ it.chatType == "public" }) { player -> val message = PublicChatMessage(player, effects, text, huffman) players.filter { it.tile.within(player.tile, VIEW_RADIUS) && !it.ignores(player) }.forEach { - it.events.emit(message) + it.emit(message) } } @@ -44,7 +45,7 @@ on { player -> } val message = PrivateChatMessage(player, message, huffman) player.client?.privateChatTo(target.name, message.compressed) - target.events.emit(message) + target.emit(message) } on({ it.networked }) { player -> @@ -63,7 +64,7 @@ on({ it.chatType == "clan" }) { player -> } val message = ClanChatMessage(player, effects, text, huffman) clan.members.filterNot { it.ignores(player) }.forEach { - it.events.emit(message) + it.emit(message) } } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/community/chat/QuickChat.kts b/game/src/main/kotlin/world/gregs/voidps/world/community/chat/QuickChat.kts index b31f75aaa..b4e0379cf 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/community/chat/QuickChat.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/community/chat/QuickChat.kts @@ -15,6 +15,7 @@ import world.gregs.voidps.engine.entity.character.player.chat.friend.PrivateQuic import world.gregs.voidps.engine.entity.character.player.chat.global.PublicQuickChat import world.gregs.voidps.engine.entity.character.player.chat.global.PublicQuickChatMessage import world.gregs.voidps.engine.entity.character.player.skill.Skill +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.event.on import world.gregs.voidps.engine.inject import world.gregs.voidps.network.encode.clanQuickChat @@ -42,7 +43,7 @@ on { player -> val text = definition.buildString(enums.definitions, items.definitions, data) val message = PrivateQuickChatMessage(player, file, text, data) - target.events.emit(message) + target.emit(message) } on({ it.networked }) { player -> @@ -55,7 +56,7 @@ on({ chatType == 0 }) { player -> val text = definition.buildString(enums.definitions, items.definitions, data) val message = PublicQuickChatMessage(player, chatType, file, text, data) players.filter { it.tile.within(player.tile, VIEW_RADIUS) && !it.ignores(player) }.forEach { - it.events.emit(message) + it.emit(message) } } @@ -78,7 +79,7 @@ on({ chatType == 1 }) { player -> val text = definition.buildString(enums.definitions, items.definitions, data) val message = ClanQuickChatMessage(player, chatType, file, text, data) clan.members.filterNot { it.ignores(player) }.forEach { - it.events.emit(message) + it.emit(message) } } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanChat.kts b/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanChat.kts index 876caed96..65109e5f0 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanChat.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanChat.kts @@ -17,6 +17,7 @@ import world.gregs.voidps.engine.entity.character.player.name import world.gregs.voidps.engine.entity.playerDespawn import world.gregs.voidps.engine.entity.playerSpawn import world.gregs.voidps.engine.event.Priority +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.event.on import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.timer.epochSeconds @@ -36,7 +37,7 @@ playerSpawn { player -> val current = player["clan_chat", ""] if (current.isNotEmpty()) { val account = accountDefinitions.getByAccount(current) - player.events.emit(JoinClanChat(account?.displayName ?: "")) + player.emit(JoinClanChat(account?.displayName ?: "")) } val ownClan = accounts.clan(player.name) ?: return@playerSpawn player.ownClan = ownClan @@ -74,7 +75,7 @@ on { player -> } if (clan.members.contains(target)) { - target.events.emit(LeaveClanChat(forced = true)) + target.emit(LeaveClanChat(forced = true)) } player.message("Your request to kick/ban this user was successful.", ChatType.ClanChat) } @@ -135,7 +136,7 @@ fun join(player: Player, clan: Clan) { if (clan.hasRank(player, ClanRank.Recruit)) { val victim = clan.members.minByOrNull { clan.getRank(it).value } if (victim != null) { - victim.events.emit(LeaveClanChat(forced = true)) + victim.emit(LeaveClanChat(forced = true)) space = true } } @@ -229,7 +230,7 @@ on(priority = Priority.LOWER) { player -> member.client?.appendClanChat(toMember(target, ClanRank.None)) } if (!clan.hasRank(target, clan.joinRank)) { - target.events.emit(LeaveClanChat(forced = true)) + target.emit(LeaveClanChat(forced = true)) } } } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanSetup.kts b/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanSetup.kts index d97954da6..1f2da3f46 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanSetup.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanSetup.kts @@ -13,6 +13,7 @@ import world.gregs.voidps.engine.entity.character.player.chat.clan.Clan import world.gregs.voidps.engine.entity.character.player.chat.clan.ClanRank import world.gregs.voidps.engine.entity.character.player.chat.clan.LeaveClanChat import world.gregs.voidps.engine.entity.character.player.name +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.encode.Member import world.gregs.voidps.network.encode.leaveClanChat import world.gregs.voidps.network.encode.updateClanChat @@ -53,7 +54,7 @@ interfaceOption(component = "enter", id = "clan_chat_setup") { player.interfaces.sendText(id, component, option) for (member in clan.members) { if (!clan.hasRank(member, rank)) { - member.events.emit(LeaveClanChat(forced = true)) + member.emit(LeaveClanChat(forced = true)) } } } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/dialogue/type/LevelUp.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/dialogue/type/LevelUp.kts index 91ce02f16..360832fce 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/dialogue/type/LevelUp.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/dialogue/type/LevelUp.kts @@ -11,6 +11,7 @@ import world.gregs.voidps.engine.entity.character.player.skill.exp.experience import world.gregs.voidps.engine.entity.character.player.skill.level.MaxLevelChanged import world.gregs.voidps.engine.entity.character.player.skill.level.maxLevelUp import world.gregs.voidps.engine.entity.character.setGraphic +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.queue.weakQueue import world.gregs.voidps.world.interact.entity.combat.hit.combatHit import world.gregs.voidps.world.interact.entity.sound.playJingle @@ -20,7 +21,7 @@ experience { player -> val currentLevel = Experience.level(skill, to) if (currentLevel != previousLevel) { player.levels.restore(skill, 1) - player.events.emit(MaxLevelChanged(skill, previousLevel, currentLevel)) + player.emit(MaxLevelChanged(skill, previousLevel, currentLevel)) } } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts index 6334b3c26..f9278dfbf 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts @@ -12,6 +12,7 @@ import world.gregs.voidps.engine.entity.character.mode.combat.CombatReached import world.gregs.voidps.engine.entity.character.mode.combat.CombatStop import world.gregs.voidps.engine.entity.character.mode.interact.Interact import world.gregs.voidps.engine.entity.character.player.Player +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.event.onCharacter import world.gregs.voidps.world.interact.entity.death.characterDeath @@ -52,7 +53,7 @@ fun combat(character: Character, target: Character) { return } val swing = CombatSwing(target) - character.events.emit(swing) + character.emit(swing) val nextDelay = swing.delay if (nextDelay == null || nextDelay < 0) { character.mode = EmptyMode diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/hit/Hit.kt b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/hit/Hit.kt index 6ef28235e..8564dbe5f 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/hit/Hit.kt +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/hit/Hit.kt @@ -7,6 +7,7 @@ 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.skill.Skill import world.gregs.voidps.engine.entity.item.Item +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.queue.strongQueue import world.gregs.voidps.engine.timer.TICKS import world.gregs.voidps.type.random @@ -130,7 +131,7 @@ fun Character.hit( ): Int { val actualDamage = Damage.modify(this, target, type, damage, weapon, spell, special) .coerceAtMost(target.levels.get(Skill.Constitution)) - events.emit(CombatAttack(target, type, actualDamage, weapon, spell, special, TICKS.toClientTicks(delay))) + emit(CombatAttack(target, type, actualDamage, weapon, spell, special, TICKS.toClientTicks(delay))) target.strongQueue("hit", delay) { target.directHit(this@hit, actualDamage, type, weapon, spell, special) } @@ -150,5 +151,5 @@ fun Character.directHit(source: Character, damage: Int, type: String = "damage", if (source.dead) { return } - events.emit(CombatHit(source, type, damage, weapon, spell, special)) + emit(CombatHit(source, type, damage, weapon, spell, special)) } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathCharacter.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathCharacter.kts index 07be034da..d3179ba63 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathCharacter.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathCharacter.kts @@ -2,9 +2,10 @@ package world.gregs.voidps.world.interact.entity.death import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.character.player.skill.level.characterLevelChange +import world.gregs.voidps.engine.event.emit characterLevelChange(Skill.Constitution) { character -> if (to <= 0 && !character.queue.contains("death")) { - character.events.emit(Death) + character.emit(Death) } } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathNPC.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathNPC.kts index 46720ba60..611a4abaa 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathNPC.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathNPC.kts @@ -20,6 +20,7 @@ import world.gregs.voidps.engine.entity.character.setAnimation import world.gregs.voidps.engine.entity.item.Item import world.gregs.voidps.engine.entity.item.drop.DropTables import world.gregs.voidps.engine.entity.item.floor.FloorItems +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.queue.strongQueue import world.gregs.voidps.type.Direction @@ -69,7 +70,7 @@ npcDeath { npc -> npcs.remove(npc) npcs.releaseIndex(npc) } - npc.events.emit(Unregistered) + npc.emit(Unregistered) } } } @@ -96,7 +97,7 @@ fun dropLoot(npc: NPC, killer: Character?, name: String, tile: Tile) { .map { it.toItem() } .filter { World.members || !it.def.members } .toMutableList() - npc.events.emit(DropItems(killer, drops)) + npc.emit(DropItems(killer, drops)) if (npc.inMultiCombat && killer is Player && killer["loot_share", false]) { shareLoot(killer, npc, tile, drops) } else { diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/OpenShop.kt b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/OpenShop.kt index ec0313aed..068d3629d 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/OpenShop.kt +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/OpenShop.kt @@ -2,9 +2,10 @@ package world.gregs.voidps.world.interact.entity.npc.shop import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.event.Event +import world.gregs.voidps.engine.event.emit data class OpenShop(val id: String): Event fun Player.openShop(id: String) { - events.emit(OpenShop(id)) + emit(OpenShop(id)) } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/Teleports.kt b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/Teleports.kt index be75cb3e2..f0e1b18e0 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/Teleports.kt +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/Teleports.kt @@ -3,6 +3,7 @@ package world.gregs.voidps.world.interact.entity.obj import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap import world.gregs.voidps.engine.entity.character.move.tele import world.gregs.voidps.engine.entity.obj.ObjectOption +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.getProperty import world.gregs.voidps.engine.suspend.delay @@ -27,7 +28,7 @@ class Teleports { } val player = objectOption.player val teleport = Teleport(player, definition.id, definition.tile, objectOption.def, definition.option) - player.events.emit(teleport) + player.emit(teleport) if (teleport.cancelled) { return false } @@ -42,7 +43,7 @@ class Teleports { } player.tele(tile) teleport.land = true - player.events.emit(teleport) + player.emit(teleport) return true } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/door/Doors.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/door/Doors.kts index 1ac1cf8ad..ce538216f 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/door/Doors.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/door/Doors.kts @@ -6,6 +6,7 @@ import world.gregs.voidps.engine.client.variable.remaining import world.gregs.voidps.engine.client.variable.start import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.obj.objectOperate +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.suspend.pause import world.gregs.voidps.engine.timer.epochSeconds import world.gregs.voidps.world.interact.entity.obj.door.Door.closeDoor @@ -32,7 +33,7 @@ objectOperate("Open") { } if (openDoor(player, target, def)) { pause(1) - player.events.emit(DoorOpened) + player.emit(DoorOpened) } } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/consume/Eating.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/consume/Eating.kts index 84277010c..999c56812 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/consume/Eating.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/consume/Eating.kts @@ -7,6 +7,7 @@ import world.gregs.voidps.engine.entity.character.player.chat.ChatType import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.character.setAnimation import world.gregs.voidps.engine.event.Priority +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.inventory import world.gregs.voidps.engine.inv.remove import world.gregs.voidps.engine.inv.replace @@ -34,7 +35,7 @@ inventoryOptions("Eat", "Drink", "Heal") { } player.start(delay, ticks) val consumable = Consumable(item) - player.events.emit(consumable) + player.emit(consumable) if (consumable.cancelled) { return@inventoryOptions } @@ -52,7 +53,7 @@ inventoryOptions("Eat", "Drink", "Heal") { player.message("You ${if (drink) "drink" else "eat"} the ${item.def.name.lowercase()}.") } player.playSound(if (drink) "pour_tea" else "eat") - player.events.emit(Consume(item, slot)) + player.emit(Consume(item, slot)) } consume(priority = Priority.LOW) { player -> diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/prayer/PrayerToggle.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/prayer/PrayerToggle.kts index d8ae3492a..4fe79f97c 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/prayer/PrayerToggle.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/prayer/PrayerToggle.kts @@ -7,6 +7,7 @@ import world.gregs.voidps.engine.client.ui.closeInterfaces import world.gregs.voidps.engine.client.variable.variableAdded import world.gregs.voidps.engine.client.variable.variableRemoved import world.gregs.voidps.engine.client.variable.variableSet +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.world.interact.entity.player.combat.prayer.PrayerConfigs.ACTIVE_CURSES import world.gregs.voidps.world.interact.entity.player.combat.prayer.PrayerConfigs.ACTIVE_PRAYERS @@ -15,19 +16,19 @@ variableSet("activated_*") { player -> val from = (from as? List)?.toSet() ?: emptySet() val to = (to as? List)?.toSet() ?: emptySet() for (prayer in from.subtract(to)) { - player.events.emit(PrayerStop(prayer)) + player.emit(PrayerStop(prayer)) } for (prayer in to.subtract(from)) { - player.events.emit(PrayerStart(prayer)) + player.emit(PrayerStart(prayer)) } } variableAdded(ACTIVE_PRAYERS, ACTIVE_CURSES) { player -> player.closeInterfaces() - player.events.emit(PrayerStart((value as String).toSnakeCase())) + player.emit(PrayerStart((value as String).toSnakeCase())) } variableRemoved(ACTIVE_PRAYERS, ACTIVE_CURSES) { player -> player.closeInterfaces() - player.events.emit(PrayerStop((value as String).toSnakeCase())) + player.emit(PrayerStop((value as String).toSnakeCase())) } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/EquipmentBonuses.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/EquipmentBonuses.kts index 6bed30aeb..bb75bcd40 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/EquipmentBonuses.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/EquipmentBonuses.kts @@ -12,6 +12,7 @@ import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.appearance import world.gregs.voidps.engine.entity.item.Item import world.gregs.voidps.engine.entity.playerSpawn +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.equipment import world.gregs.voidps.engine.inv.itemChange @@ -71,14 +72,14 @@ interfaceOption("Done", "stats_done", "equipment_*") { interfaceOption("Equip", "inventory", "equipment_side") { if (player.equipping()) { - player.events.emit(InventoryOption(player, "inventory", item, itemSlot, "Wield")) + player.emit(InventoryOption(player, "inventory", item, itemSlot, "Wield")) checkEmoteUpdate(player) } } interfaceOption("Remove", "inventory", "equipment_bonuses") { if (player.equipping()) { - player.events.emit(InventoryOption(player, "worn_equipment", item, itemSlot, "Remove")) + player.emit(InventoryOption(player, "worn_equipment", item, itemSlot, "Remove")) checkEmoteUpdate(player) } } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/Inventory.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/Inventory.kts index 25ed3207d..b340da43d 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/Inventory.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/Inventory.kts @@ -7,6 +7,7 @@ import world.gregs.voidps.engine.client.ui.interfaceOption import world.gregs.voidps.engine.client.ui.interfaceSwap import world.gregs.voidps.engine.entity.character.mode.EmptyMode import world.gregs.voidps.engine.entity.character.mode.combat.CombatMovement +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.inventory import world.gregs.voidps.engine.inv.sendInventory import world.gregs.voidps.engine.inv.swap @@ -49,7 +50,7 @@ interfaceOption(component = "inventory", id = "inventory") { if (player.mode is CombatMovement) { player.mode = EmptyMode } - player.events.emit( + player.emit( InventoryOption( player, id, diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/WornEquipment.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/WornEquipment.kts index b1b725122..3093845a7 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/WornEquipment.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/WornEquipment.kts @@ -6,6 +6,7 @@ import world.gregs.voidps.engine.client.ui.closeInterfaces import world.gregs.voidps.engine.client.ui.event.interfaceRefresh import world.gregs.voidps.engine.client.ui.interfaceOption import world.gregs.voidps.engine.client.ui.open +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.sendInventory import world.gregs.voidps.network.visual.update.player.EquipSlot @@ -36,7 +37,7 @@ interfaceOption(component = "*_slot", id = "worn_equipment") { } val slot = EquipSlot.by(component.removeSuffix("_slot")) player.closeInterfaces() - player.events.emit(InventoryOption(player, id, item, slot.index, equipOption)) + player.emit(InventoryOption(player, id, item, slot.index, equipOption)) } fun getEquipmentOption(itemDef: ItemDefinition, optionId: Int): String? { diff --git a/game/src/main/kotlin/world/gregs/voidps/world/map/varrock/Aubury.kts b/game/src/main/kotlin/world/gregs/voidps/world/map/varrock/Aubury.kts index 4a177b139..c9cccbf05 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/map/varrock/Aubury.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/map/varrock/Aubury.kts @@ -2,6 +2,7 @@ package world.gregs.voidps.world.map.varrock import world.gregs.voidps.engine.entity.character.CharacterContext import world.gregs.voidps.engine.entity.character.npc.npcOperate +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.inventory import world.gregs.voidps.engine.inv.remove @@ -35,7 +36,7 @@ npcOperate("Talk-to", "aubury") { } fun PlayerChoice.openShop(): Unit = option("Yes please!") { - player.events.emit(OpenShop("auburys_rune_shop")) + player.emit(OpenShop("auburys_rune_shop")) } suspend fun PlayerChoice.noThanks(message: String = "Oh, it's a rune shop. No thank you, then."): Unit = option(message) { @@ -115,7 +116,7 @@ suspend fun PlayerChoice.skillcapes(): Unit = option("Can you tell me about your npc("The Cape of Runecrafting has been upgraded with each talisman, allowing you to access all Runecrafting altars. Is there anything else I can help you with?") choice { option("I'd like to view your store please.") { - player.events.emit(OpenShop("runecrafting_skillcape")) + player.emit(OpenShop("runecrafting_skillcape")) } noThanks("No thank you.") } diff --git a/game/src/test/kotlin/world/gregs/voidps/world/community/friend/PrivateChatStatusTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/community/friend/PrivateChatStatusTest.kt index e99e3df59..bcdd124c4 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/community/friend/PrivateChatStatusTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/community/friend/PrivateChatStatusTest.kt @@ -11,6 +11,7 @@ import world.gregs.voidps.engine.entity.Registered import world.gregs.voidps.engine.entity.World import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.clan.ClanRank +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.client.Client import world.gregs.voidps.network.encode.Friend import world.gregs.voidps.network.encode.sendFriendsList @@ -48,7 +49,7 @@ internal class PrivateChatStatusTest : WorldTest() { player["private_status"] = "off" runBlocking(Dispatchers.Default) { - player.events.emit(Registered) + player.emit(Registered) } verify { @@ -67,7 +68,7 @@ internal class PrivateChatStatusTest : WorldTest() { player["private_status"] = "friends" runBlocking(Dispatchers.Default) { - player.events.emit(Registered) + player.emit(Registered) } verify { @@ -86,7 +87,7 @@ internal class PrivateChatStatusTest : WorldTest() { player["private_status"] = "on" runBlocking(Dispatchers.Default) { - player.events.emit(Registered) + player.emit(Registered) } verify { diff --git a/game/src/test/kotlin/world/gregs/voidps/world/community/trade/LendTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/community/trade/LendTest.kt index f9fd1185e..afafa9517 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/community/trade/LendTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/community/trade/LendTest.kt @@ -10,6 +10,7 @@ import world.gregs.voidps.engine.entity.Unregistered import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.item.Item +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.equipment import world.gregs.voidps.engine.inv.inventory @@ -72,7 +73,7 @@ internal class LendTest : WorldTest() { acceptTrade(lender, borrower) assertTrue(borrower.inventory.contains("abyssal_whip_lent")) - lender.events.emit(Unregistered) + lender.emit(Unregistered) assertFalse(lender.softTimers.contains("loan_message")) assertFalse(borrower.inventory.contains("abyssal_whip_lent")) } @@ -84,7 +85,7 @@ internal class LendTest : WorldTest() { acceptTrade(lender, borrower) assertTrue(borrower.inventory.contains("abyssal_whip_lent")) - borrower.events.emit(Unregistered) + borrower.emit(Unregistered) assertFalse(lender.softTimers.contains("loan_message")) assertFalse(borrower.inventory.contains("abyssal_whip_lent")) } @@ -94,7 +95,7 @@ internal class LendTest : WorldTest() { val (lender, borrower) = setupTradeWithLend() lender.interfaceOption("trade_side", "offer", "Lend", item = Item("abyssal_whip"), slot = 0) lender.interfaceOption("trade_main", "loan_time", option = "Specify") - lender.events.emit(IntEntered(1)) + lender.emit(IntEntered(1)) acceptTrade(lender, borrower) assertTrue(borrower.inventory.contains("abyssal_whip_lent")) assertTrue(borrower.softTimers.contains("borrow_message")) @@ -112,7 +113,7 @@ internal class LendTest : WorldTest() { val (lender, borrower) = setupTradeWithLend() lender.interfaceOption("trade_side", "offer", "Lend", item = Item("abyssal_whip"), slot = 0) lender.interfaceOption("trade_main", "loan_time", option = "Specify") - lender.events.emit(IntEntered(1)) + lender.emit(IntEntered(1)) acceptTrade(lender, borrower) assertTrue(borrower.inventory.contains("abyssal_whip_lent")) assertTrue(borrower.softTimers.contains("borrow_message")) @@ -138,7 +139,7 @@ internal class LendTest : WorldTest() { val (lender, borrower) = setupTradeWithLend() lender.interfaceOption("trade_side", "offer", "Lend", item = Item("abyssal_whip"), slot = 0) lender.interfaceOption("trade_main", "loan_time", option = "Specify") - lender.events.emit(IntEntered(1)) + lender.emit(IntEntered(1)) acceptTrade(lender, borrower) assertTrue(borrower.inventory.contains("abyssal_whip_lent")) assertTrue(borrower.softTimers.contains("borrow_message")) @@ -181,7 +182,7 @@ internal class LendTest : WorldTest() { val item = Item("abyssal_whip", 1) lender.interfaceOption("trade_side", "offer", "Lend", item = item, slot = 0) lender.interfaceOption("trade_main", "loan_time", option = "Specify") - lender.events.emit(IntEntered(1)) + lender.emit(IntEntered(1)) acceptTrade(lender, borrower) assertTrue(borrower.inventory.contains("abyssal_whip_lent")) @@ -213,7 +214,7 @@ internal class LendTest : WorldTest() { val item = Item("abyssal_whip", 1) lender.interfaceOption("trade_side", "offer", "Lend", item = item, slot = 0) lender.interfaceOption("trade_main", "loan_time", option = "Specify") - lender.events.emit(IntEntered(1)) + lender.emit(IntEntered(1)) acceptTrade(lender, borrower) borrower["borrow_timeout"] = epochSeconds() lender["lend_timeout"] = epochSeconds() @@ -228,11 +229,11 @@ internal class LendTest : WorldTest() { private fun login(lender: Player) { players.add(lender) - lender.events.emit(Registered) + lender.emit(Registered) } private fun logout(borrower: Player) { - borrower.events.emit(Unregistered) + borrower.emit(Unregistered) players.remove(borrower) } diff --git a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MagicCombatFormulaTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MagicCombatFormulaTest.kt index db82dae0e..26d0a7254 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MagicCombatFormulaTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MagicCombatFormulaTest.kt @@ -3,6 +3,7 @@ package world.gregs.voidps.world.interact.entity.player.combat import org.junit.jupiter.api.Test import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.item.Item +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.equipment import world.gregs.voidps.engine.inv.inventory @@ -74,7 +75,7 @@ internal class MagicCombatFormulaTest : CombatFormulaTest() { player.equipment.set(EquipSlot.Weapon.index, weapon.id) val potion = Item("super_magic_potion_4") player.inventory.add(potion.id) - player.events.emit(InventoryOption(player, "inventory", potion, 0, "Drink")) + player.emit(InventoryOption(player, "inventory", potion, 0, "Drink")) val npc = createNPC("giant_rat") val (offensiveRating, defensiveRating, maxHit, chance) = calculate(player, npc, "magic", weapon, "water_blast") @@ -107,7 +108,7 @@ internal class MagicCombatFormulaTest : CombatFormulaTest() { player.equipment.set(EquipSlot.Weapon.index, weapon.id) val potion = Item("super_magic_potion_4") player.inventory.add(potion.id) - player.events.emit(InventoryOption(player, "inventory", potion, 0, "Drink")) + player.emit(InventoryOption(player, "inventory", potion, 0, "Drink")) val npc = createNPC("giant_rat") val (offensiveRating, defensiveRating, maxHit, chance) = calculate(player, npc, "magic", weapon, "fire_wave") diff --git a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MeleeCombatFormulaTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MeleeCombatFormulaTest.kt index aac42ddd1..5f29a3952 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MeleeCombatFormulaTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MeleeCombatFormulaTest.kt @@ -3,6 +3,7 @@ package world.gregs.voidps.world.interact.entity.player.combat import org.junit.jupiter.api.Test import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.item.Item +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.equipment import world.gregs.voidps.engine.inv.inventory @@ -78,9 +79,9 @@ internal class MeleeCombatFormulaTest : CombatFormulaTest() { val strengthPotion = Item("super_strength_4") player.inventory.add(attackPotion.id) player.inventory.add(strengthPotion.id) - player.events.emit(InventoryOption(player, "inventory", attackPotion, 0, "Drink")) + player.emit(InventoryOption(player, "inventory", attackPotion, 0, "Drink")) tick(2) - player.events.emit(InventoryOption(player, "inventory", strengthPotion, 1, "Drink")) + player.emit(InventoryOption(player, "inventory", strengthPotion, 1, "Drink")) val npc = createNPC("giant_rat") val (offensiveRating, defensiveRating, maxHit, chance) = calculate(player, npc, "melee", weapon) diff --git a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/RangedCombatFormulaTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/RangedCombatFormulaTest.kt index e03cd147f..b6fd84991 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/RangedCombatFormulaTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/RangedCombatFormulaTest.kt @@ -3,6 +3,7 @@ package world.gregs.voidps.world.interact.entity.player.combat import org.junit.jupiter.api.Test import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.item.Item +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.equipment import world.gregs.voidps.engine.inv.inventory @@ -71,7 +72,7 @@ internal class RangedCombatFormulaTest : CombatFormulaTest() { player.equipment.set(EquipSlot.Ammo.index, "rune_arrow") val potion = Item("super_ranging_potion_4") player.inventory.add(potion.id) - player.events.emit(InventoryOption(player, "inventory", potion, 0, "Drink")) + player.emit(InventoryOption(player, "inventory", potion, 0, "Drink")) val npc = createNPC("giant_rat") val (offensiveRating, defensiveRating, maxHit, chance) = calculate(player, npc, "range", weapon) @@ -108,7 +109,7 @@ internal class RangedCombatFormulaTest : CombatFormulaTest() { player.ammo = "dragon_arrow" val potion = Item("super_ranging_potion_4") player.inventory.add(potion.id) - player.events.emit(InventoryOption(player, "inventory", potion, 0, "Drink")) + player.emit(InventoryOption(player, "inventory", potion, 0, "Drink")) val npc = createNPC("giant_rat") val (offensiveRating, defensiveRating, maxHit, chance) = calculate(player, npc, "range", weapon) diff --git a/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt b/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt index 24846c4db..677265fec 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt @@ -16,6 +16,7 @@ import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.item.Item import world.gregs.voidps.engine.entity.item.floor.FloorItem import world.gregs.voidps.engine.entity.obj.GameObject +import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.inv.Inventory import world.gregs.voidps.engine.inv.inventory @@ -36,7 +37,7 @@ fun Player.interfaceOption( inventory: String = "" ) { Assertions.assertTrue(hasOpen(id)) { "Player $this doesn't have interface $id open" } - events.emit(InterfaceOption(this, id = id, component = component, optionIndex = optionIndex, option = option, item = item, itemSlot = slot, inventory = inventory)) + emit(InterfaceOption(this, id = id, component = component, optionIndex = optionIndex, option = option, item = item, itemSlot = slot, inventory = inventory)) } fun Player.interfaceUse( @@ -49,7 +50,7 @@ fun Player.interfaceUse( toSlot: Int = -1 ) { Assertions.assertTrue(hasOpen(id)) { "Player $this doesn't have interface $id open" } - events.emit(ItemOnItem( + emit(ItemOnItem( fromItem = fromItem, toItem = toItem, fromSlot = fromSlot, @@ -73,7 +74,7 @@ fun Player.interfaceSwitch( toSlot: Int = -1 ) { Assertions.assertTrue(hasOpen(id)) { "Player $this doesn't have interface $id open" } - events.emit(InterfaceSwitch( + emit(InterfaceSwitch( id = id, component = component, fromItem = fromItem, @@ -99,7 +100,7 @@ fun Player.dialogueOption( component: String, option: Int = -1 ) { - events.emit(ContinueDialogue(id, component, option)) + emit(ContinueDialogue(id, component, option)) } private fun getOptionIndex(id: String, componentId: String, option: String): Int? { @@ -119,13 +120,13 @@ fun Player.walk(toTile: Tile) = runTest { fun Player.itemOnObject(obj: GameObject, itemSlot: Int, id: String, component: String = "inventory", inventory: String = "inventory") { val item = inventories.inventory(inventory)[itemSlot] - events.emit(ItemOnObject(this, obj, id, component, item, itemSlot, inventory)) + emit(ItemOnObject(this, obj, id, component, item, itemSlot, inventory)) } fun Player.itemOnItem(firstSlot: Int, secondSlot: Int, firstInventory: String = "inventory", firstComponent: String = "inventory", secondInventory: String = firstInventory, secondComponent: String = firstComponent) { val one = inventories.inventory(firstInventory) val two = inventories.inventory(secondInventory) - events.emit(ItemOnItem( + emit(ItemOnItem( one[firstSlot], two[secondSlot], firstSlot, From 56e0233c050221dd6d7a03408d949d9fede6e496 Mon Sep 17 00:00:00 2001 From: GregHib Date: Sat, 24 Feb 2024 23:02:32 +0000 Subject: [PATCH 04/15] Remove EventHandlerStore.kt and Events.kt in favour of EventStore --- .../gregs/voidps/engine/EngineModules.kt | 8 +- .../client/instruction/InstructionHandlers.kt | 1 - .../instruction/handle/ChatPrivateHandler.kt | 1 - .../instruction/handle/ChatPublicHandler.kt | 1 - .../instruction/handle/ClanChatJoinHandler.kt | 1 - .../instruction/handle/ClanChatKickHandler.kt | 1 - .../instruction/handle/ClanChatRankHandler.kt | 1 - .../handle/DialogueContinueHandler.kt | 1 - .../instruction/handle/EnterIntHandler.kt | 1 - .../instruction/handle/EnterStringHandler.kt | 1 - .../handle/ExecuteCommandHandler.kt | 1 - .../instruction/handle/FriendAddHandler.kt | 1 - .../instruction/handle/FriendDeleteHandler.kt | 1 - .../instruction/handle/IgnoreAddHandler.kt | 1 - .../instruction/handle/IgnoreDeleteHandler.kt | 1 - .../InterfaceOnInterfaceOptionHandler.kt | 1 - .../handle/InterfaceOptionHandler.kt | 1 - .../handle/InterfaceSwitchHandler.kt | 1 - .../handle/QuickChatPrivateHandler.kt | 1 - .../handle/QuickChatPublicHandler.kt | 1 - .../voidps/engine/client/ui/Interfaces.kt | 4 +- .../engine/client/variable/PlayerVariables.kt | 4 +- .../engine/client/variable/VariableBits.kt | 4 +- .../engine/client/variable/Variables.kt | 4 +- .../voidps/engine/data/PlayerAccounts.kt | 11 +-- .../world/gregs/voidps/engine/entity/World.kt | 11 +-- .../character/mode/combat/CombatMovement.kt | 1 - .../character/mode/interact/Interact.kt | 6 +- .../entity/character/mode/move/Movement.kt | 3 +- .../voidps/engine/entity/character/npc/NPC.kt | 6 +- .../engine/entity/character/npc/NPCs.kt | 6 +- .../entity/character/npc/hunt/Hunting.kt | 1 - .../engine/entity/character/player/Player.kt | 9 +- .../engine/entity/character/player/Players.kt | 1 - .../character/player/skill/exp/Experience.kt | 4 +- .../character/player/skill/level/Levels.kt | 6 +- .../engine/entity/item/floor/FloorItem.kt | 2 - .../engine/entity/item/floor/FloorItems.kt | 6 +- .../voidps/engine/event/EventDispatcher.kt | 8 +- .../voidps/engine/event/EventHandlerStore.kt | 62 +++----------- .../gregs/voidps/engine/event/EventStore.kt | 82 +++++++++++++++++++ .../world/gregs/voidps/engine/event/Events.kt | 69 ---------------- .../gregs/voidps/engine/inv/Inventories.kt | 4 +- .../engine/inv/transact/ChangeManager.kt | 8 +- .../voidps/engine/map/zone/DynamicZones.kt | 1 - .../gregs/voidps/engine/timer/TimerQueue.kt | 4 +- .../gregs/voidps/engine/timer/TimerSlot.kt | 4 +- .../engine/client/ConnectionGatekeeperTest.kt | 2 - .../engine/client/ConnectionQueueTest.kt | 2 - .../voidps/engine/client/ui/InterfaceTest.kt | 4 +- .../client/update/CharacterUpdateTaskTest.kt | 4 +- .../client/update/npc/NPCUpdateTaskTest.kt | 4 +- .../update/player/PlayerUpdateTaskTest.kt | 6 +- .../engine/client/variable/ClocksTest.kt | 3 +- .../engine/client/variable/VariablesTest.kt | 5 +- .../character/player/skill/ExperienceTest.kt | 4 +- .../character/player/skill/LevelsTest.kt | 11 ++- .../item/floor/FloorItemTrackingTest.kt | 2 +- .../entity/item/floor/FloorItemsTest.kt | 2 +- .../engine/event/EventHandlerStoreTest.kt | 48 ----------- .../gregs/voidps/engine/event/EventsTest.kt | 59 ------------- .../gregs/voidps/engine/inv/InventoryTest.kt | 4 +- .../engine/inv/transact/ChangeManagerTest.kt | 6 +- .../engine/inv/transact/TransactionTest.kt | 4 +- .../engine/map/zone/ZoneBatchUpdatesTest.kt | 5 -- .../gregs/voidps/engine/timer/TimersTest.kt | 24 ++++-- .../kotlin/world/gregs/voidps/GameTick.kt | 1 - .../main/kotlin/world/gregs/voidps/bot/Bot.kt | 3 - .../world/gregs/voidps/bot/BotSpawns.kts | 11 +-- .../world/gregs/voidps/bot/DecisionMaking.kts | 2 +- .../world/gregs/voidps/script/ScriptLoader.kt | 2 + .../world/activity/skill/ItemOnItems.kts | 1 - .../world/command/admin/AdminCommands.kts | 1 - .../voidps/world/community/chat/Chat.kts | 1 - .../voidps/world/community/chat/QuickChat.kts | 1 - .../voidps/world/community/clan/ClanChat.kts | 1 - .../voidps/world/community/clan/ClanSetup.kts | 1 - .../world/interact/dialogue/type/LevelUp.kts | 1 - .../world/interact/entity/combat/Combat.kts | 1 - .../interact/entity/combat/CombatDebug.kts | 5 +- .../world/interact/entity/combat/hit/Hit.kt | 1 - .../interact/entity/death/DeathCharacter.kts | 1 - .../world/interact/entity/death/DeathNPC.kts | 1 - .../interact/entity/npc/shop/GeneralStores.kt | 4 +- .../interact/entity/npc/shop/OpenShop.kt | 1 - .../world/interact/entity/obj/Teleports.kt | 1 - .../world/interact/entity/obj/door/Doors.kts | 1 - .../entity/player/combat/consume/Eating.kts | 1 - .../player/combat/prayer/PrayerToggle.kts | 1 - .../entity/player/equip/EquipmentBonuses.kts | 1 - .../entity/player/equip/Inventory.kts | 1 - .../entity/player/equip/WornEquipment.kts | 1 - .../gregs/voidps/world/map/varrock/Aubury.kts | 1 - .../community/friend/PrivateChatStatusTest.kt | 1 - .../voidps/world/community/trade/LendTest.kt | 1 - .../interact/entity/combat/CombatTest.kt | 2 +- .../player/combat/MagicCombatFormulaTest.kt | 1 - .../player/combat/MeleeCombatFormulaTest.kt | 1 - .../player/combat/RangedCombatFormulaTest.kt | 1 - .../voidps/world/script/InstructionCalls.kt | 1 - .../gregs/voidps/world/script/WorldTest.kt | 7 +- 101 files changed, 198 insertions(+), 422 deletions(-) create mode 100644 engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt delete mode 100644 engine/src/main/kotlin/world/gregs/voidps/engine/event/Events.kt delete mode 100644 engine/src/test/kotlin/world/gregs/voidps/engine/event/EventHandlerStoreTest.kt delete mode 100644 engine/src/test/kotlin/world/gregs/voidps/engine/event/EventsTest.kt diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt index 63dde4239..b79eb6595 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt @@ -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 @@ -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("loadUnusedObjects") == "true").apply { get().register(this) } } - single { FloorItems(get(), get(), get()).apply { get().register(this) } } + single { FloorItems(get(), get()).apply { get().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()) } @@ -44,7 +43,6 @@ val engineModule = module { // Map single { ZoneBatchUpdates() } single { DynamicZones(get(), get(), get()) } - single { EventHandlerStore() } single(createdAtStart = true) { AreaDefinitions().load() } // Network single { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionHandlers.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionHandlers.kt index d78c14c38..3a589b438 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionHandlers.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/InstructionHandlers.kt @@ -11,7 +11,6 @@ import world.gregs.voidps.engine.entity.character.player.Players import world.gregs.voidps.engine.entity.item.floor.FloorItems import world.gregs.voidps.engine.entity.obj.GameObjects import world.gregs.voidps.engine.event.Event -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.Instruction import world.gregs.voidps.network.instruct.* diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPrivateHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPrivateHandler.kt index 98458e1f1..9cdb4d626 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPrivateHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPrivateHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.friend.PrivateChat -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ChatPrivate class ChatPrivateHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPublicHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPublicHandler.kt index 5f16855e9..ddc62f50b 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPublicHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ChatPublicHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.global.PublicChat -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ChatPublic class ChatPublicHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatJoinHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatJoinHandler.kt index 6221dd6d5..9f81a4c59 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatJoinHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatJoinHandler.kt @@ -4,7 +4,6 @@ import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.clan.JoinClanChat import world.gregs.voidps.engine.entity.character.player.chat.clan.LeaveClanChat -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ClanChatJoin class ClanChatJoinHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatKickHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatKickHandler.kt index 24cf265e8..b1d7eeb44 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatKickHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatKickHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.clan.KickClanChat -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ClanChatKick class ClanChatKickHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatRankHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatRankHandler.kt index 308497867..20f10d3c7 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatRankHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ClanChatRankHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.clan.UpdateClanChatRank -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ClanChatRank class ClanChatRankHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/DialogueContinueHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/DialogueContinueHandler.kt index 727b3bbfa..14b92139f 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/DialogueContinueHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/DialogueContinueHandler.kt @@ -5,7 +5,6 @@ import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.ui.dialogue.ContinueDialogue import world.gregs.voidps.engine.data.definition.InterfaceDefinitions import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.InteractDialogue class DialogueContinueHandler( diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterIntHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterIntHandler.kt index 95725bb96..7b8336a25 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterIntHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterIntHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.ui.event.IntEntered import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.EnterInt class EnterIntHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterStringHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterStringHandler.kt index 2616f11ff..126d460c0 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterStringHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/EnterStringHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.ui.event.StringEntered import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.EnterString class EnterStringHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ExecuteCommandHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ExecuteCommandHandler.kt index ac47e8031..3c3a3fd95 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ExecuteCommandHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/ExecuteCommandHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.ui.event.Command import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.ExecuteCommand class ExecuteCommandHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendAddHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendAddHandler.kt index 37ca5ee63..2e8c40770 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendAddHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendAddHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.friend.AddFriend -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.FriendAdd class FriendAddHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendDeleteHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendDeleteHandler.kt index dcaa3ee1b..8b2fe0a82 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendDeleteHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/FriendDeleteHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.friend.DeleteFriend -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.FriendDelete class FriendDeleteHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreAddHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreAddHandler.kt index cd496448c..1e9c88d2b 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreAddHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreAddHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.ignore.AddIgnore -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.IgnoreAdd class IgnoreAddHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreDeleteHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreDeleteHandler.kt index fae31cd33..baa668088 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreDeleteHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/IgnoreDeleteHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.ignore.DeleteIgnore -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.IgnoreDelete class IgnoreDeleteHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt index bbe637a9f..ee1d21e68 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOnInterfaceOptionHandler.kt @@ -5,7 +5,6 @@ import world.gregs.voidps.engine.client.instruction.InterfaceHandler import world.gregs.voidps.engine.client.ui.closeInterfaces import world.gregs.voidps.engine.client.ui.interact.ItemOnItem import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.InteractInterfaceItem /** diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOptionHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOptionHandler.kt index 439b0d416..f9b66789e 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOptionHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceOptionHandler.kt @@ -5,7 +5,6 @@ import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.instruction.InterfaceHandler import world.gregs.voidps.engine.client.ui.InterfaceOption import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.InteractInterface class InterfaceOptionHandler( diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceSwitchHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceSwitchHandler.kt index e7a84f24b..db4fab16b 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceSwitchHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/InterfaceSwitchHandler.kt @@ -4,7 +4,6 @@ import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.client.instruction.InterfaceHandler import world.gregs.voidps.engine.client.ui.InterfaceSwitch import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.MoveInventoryItem class InterfaceSwitchHandler( diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPrivateHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPrivateHandler.kt index c46e7b00f..29d6b4541 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPrivateHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPrivateHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.friend.PrivateQuickChat -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.QuickChatPrivate class QuickChatPrivateHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPublicHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPublicHandler.kt index 4d38ba056..5875ba82d 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPublicHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/instruction/handle/QuickChatPublicHandler.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.client.instruction.handle import world.gregs.voidps.engine.client.instruction.InstructionHandler import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.global.PublicQuickChat -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.instruct.QuickChatPublic class QuickChatPublicHandler : InstructionHandler() { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/ui/Interfaces.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/ui/Interfaces.kt index ed85c367a..2c28086ae 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/ui/Interfaces.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/ui/Interfaces.kt @@ -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.* @@ -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 = ObjectOpenHashSet() diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/PlayerVariables.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/PlayerVariables.kt index bb32a8a62..6cbc1501d 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/PlayerVariables.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/PlayerVariables.kt @@ -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, var definitions: VariableDefinitions = VariableDefinitions(), val temp: MutableMap = mutableMapOf() diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/VariableBits.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/VariableBits.kt index 1e0be7d90..f3858cd2c 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/VariableBits.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/VariableBits.kt @@ -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 { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/Variables.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/Variables.kt index 9af4450ce..292625271 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/Variables.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/variable/Variables.kt @@ -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 = Object2ObjectOpenHashMap(2) ) { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/data/PlayerAccounts.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/data/PlayerAccounts.kt index 22fe22e67..c214a6fd5 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/data/PlayerAccounts.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/data/PlayerAccounts.kt @@ -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 @@ -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, @@ -103,10 +101,9 @@ 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 @@ -114,10 +111,10 @@ class PlayerAccounts( 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 diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/World.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/World.kt index 3508791ae..14ce53851 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/World.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/World.kt @@ -5,10 +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.event.emit -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 @@ -20,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) { @@ -43,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) emit(Registered) } - val timers: Timers = TimerQueue(events) + val timers: Timers = TimerQueue(this) private val actions = ConcurrentHashMap Unit>>() diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/combat/CombatMovement.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/combat/CombatMovement.kt index 607f968af..4c1c6a55b 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/combat/CombatMovement.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/combat/CombatMovement.kt @@ -14,7 +14,6 @@ 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.chat.cantReach import world.gregs.voidps.engine.entity.character.watch -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.type.Direction import world.gregs.voidps.type.Tile diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/Interact.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/Interact.kt index f3ec51feb..c7797bc9c 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/Interact.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/Interact.kt @@ -12,7 +12,7 @@ import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.cantReach import world.gregs.voidps.engine.entity.character.player.chat.noInterest import world.gregs.voidps.engine.entity.character.watch -import world.gregs.voidps.engine.event.emit +import world.gregs.voidps.engine.event.EventStore import world.gregs.voidps.engine.suspend.resumeSuspension /** @@ -137,8 +137,8 @@ class Interact( val withinMelee = arrived() val withinRange = arrived(approachRange ?: 10) when { - withinMelee && character.events.contains(operate) -> if (launch(operate) && afterMovement) updateRange = false - withinRange && character.events.contains(approach) -> if (launch(approach) && afterMovement) updateRange = false + withinMelee && EventStore.events.contains(character, operate) -> if (launch(operate) && afterMovement) updateRange = false + withinRange && EventStore.events.contains(character, approach) -> if (launch(approach) && afterMovement) updateRange = false withinMelee -> { character.noInterest() clear() diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/move/Movement.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/move/Movement.kt index d28a27ab1..b81ed68bb 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/move/Movement.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/mode/move/Movement.kt @@ -19,7 +19,6 @@ import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.movementType import world.gregs.voidps.engine.entity.character.player.temporaryMoveType import world.gregs.voidps.engine.entity.character.size -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.map.Overlap import world.gregs.voidps.engine.map.region.RegionRetry @@ -199,7 +198,7 @@ open class Movement( val from = character.tile character.tile = character.tile.add(delta) character.visuals.moved = true - character.events.emit(Moved(character, from, character.tile)) + character.emit(Moved(character, from, character.tile)) if (character is Player) { val definitions = get() val to = character.tile diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPC.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPC.kt index 53aab5074..871199cb9 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPC.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPC.kt @@ -8,7 +8,6 @@ import world.gregs.voidps.engine.entity.character.mode.EmptyMode 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.player.skill.level.Levels -import world.gregs.voidps.engine.event.Events import world.gregs.voidps.type.Tile import world.gregs.voidps.engine.queue.ActionQueue import world.gregs.voidps.engine.suspend.Suspension @@ -32,17 +31,16 @@ data class NPC( field = value value.start() } - override val events: Events = Events(this) lateinit var def: NPCDefinition override var queue = ActionQueue(this) - override var softTimers: Timers = TimerSlot(events) + override var softTimers: Timers = TimerSlot(this) override var delay: Continuation? = null override var suspension: Suspension? = null set(value) { field?.cancel() field = value } - override var variables: Variables = Variables(events) + override var variables: Variables = Variables(this) override val steps: Steps = Steps(this) override lateinit var collision: CollisionStrategy diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPCs.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPCs.kt index b61e1fdee..119ba6cca 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPCs.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/NPCs.kt @@ -10,8 +10,6 @@ import world.gregs.voidps.engine.entity.character.CharacterMap import world.gregs.voidps.engine.entity.character.face import world.gregs.voidps.engine.entity.character.mode.Wander import world.gregs.voidps.engine.entity.character.player.skill.Skill -import world.gregs.voidps.engine.event.EventHandlerStore -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.getProperty import world.gregs.voidps.engine.map.collision.CollisionStrategyProvider import world.gregs.voidps.engine.map.collision.Collisions @@ -23,7 +21,6 @@ import world.gregs.voidps.type.Zone data class NPCs( private val definitions: NPCDefinitions, private val collisions: Collisions, - private val store: EventHandlerStore, private val collision: CollisionStrategyProvider ) : CharacterList(MAX_NPCS) { override val indexArray: Array = arrayOfNulls(MAX_NPCS) @@ -101,7 +98,7 @@ data class NPCs( } val npc = NPC(id, tile) npc.def = def - npc.levels.link(npc.events, NPCLevels(def)) + npc.levels.link(npc, NPCLevels(def)) npc.levels.clear(Skill.Constitution) npc.levels.clear(Skill.Attack) npc.levels.clear(Skill.Strength) @@ -112,7 +109,6 @@ data class NPCs( if (Wander.wanders(npc)) { npc.mode = Wander(npc, tile) } - store.populate(npc) val dir = if (direction == Direction.NONE) Direction.all.random() else direction npc.index = indexer.obtain() ?: return null npc.face(dir) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/hunt/Hunting.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/hunt/Hunting.kt index 5237d45c7..0f673fb06 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/hunt/Hunting.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/npc/hunt/Hunting.kt @@ -20,7 +20,6 @@ import world.gregs.voidps.engine.entity.item.floor.FloorItem import world.gregs.voidps.engine.entity.item.floor.FloorItems import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.obj.GameObjects -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.type.Direction import world.gregs.voidps.type.Tile import world.gregs.voidps.type.Zone diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt index 99c4ffb6a..066cbdc50 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Player.kt @@ -22,8 +22,6 @@ import world.gregs.voidps.engine.entity.character.player.chat.clan.ClanRank import world.gregs.voidps.engine.entity.character.player.equip.BodyParts 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.event.Events -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.inv.Inventories import world.gregs.voidps.engine.queue.ActionQueue @@ -67,7 +65,6 @@ class Player( override lateinit var visuals: PlayerVisuals val instructions = MutableSharedFlow(replay = 20) - override val events: Events = Events(this) lateinit var options: PlayerOptions lateinit var interfaces: Interfaces lateinit var interfaceOptions: InterfaceOptions @@ -95,14 +92,14 @@ class Player( /** * Always ticks */ - override var softTimers: Timers = TimerQueue(events) + override var softTimers: Timers = TimerQueue(this) /** * Ticks while not delayed or has interface open */ - var timers = TimerQueue(events) + var timers = TimerQueue(this) - override var variables: Variables = PlayerVariables(events, variables) + override var variables: Variables = PlayerVariables(this, variables) override val steps = Steps(this) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Players.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Players.kt index c4e1a9926..873fb6890 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Players.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/Players.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.engine.entity.character.player import world.gregs.voidps.engine.entity.MAX_PLAYERS import world.gregs.voidps.engine.entity.Unregistered import world.gregs.voidps.engine.entity.character.CharacterList -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.type.Tile import world.gregs.voidps.type.Zone diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/skill/exp/Experience.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/skill/exp/Experience.kt index 31eb95d7f..407a27213 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/skill/exp/Experience.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/skill/exp/Experience.kt @@ -3,7 +3,7 @@ package world.gregs.voidps.engine.entity.character.player.skill.exp import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.character.player.skill.level.Level -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher class Experience( val experience: DoubleArray = defaultExperience.clone(), @@ -12,7 +12,7 @@ class Experience( private val rate: Double = DEFAULT_EXPERIENCE_RATE ) { - lateinit var events: Events + lateinit var events: EventDispatcher fun get(skill: Skill): Double { return experience[skill.ordinal] diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/skill/level/Levels.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/skill/level/Levels.kt index 247cc9019..f820ce558 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/skill/level/Levels.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/character/player/skill/level/Levels.kt @@ -2,7 +2,7 @@ package world.gregs.voidps.engine.entity.character.player.skill.level import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.character.player.skill.exp.Experience -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher import kotlin.math.max import kotlin.math.min @@ -15,9 +15,9 @@ class Levels( } private lateinit var level: Level - private lateinit var events: Events + private lateinit var events: EventDispatcher - fun link(events: Events, level: Level) { + fun link(events: EventDispatcher, level: Level) { this.events = events this.level = level } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItem.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItem.kt index 2104a844e..8f318774a 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItem.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItem.kt @@ -4,7 +4,6 @@ import world.gregs.voidps.cache.definition.data.ItemDefinition import world.gregs.voidps.engine.entity.Entity import world.gregs.voidps.engine.entity.item.Item import world.gregs.voidps.engine.event.EventDispatcher -import world.gregs.voidps.engine.event.Events import world.gregs.voidps.type.Tile /** @@ -20,7 +19,6 @@ class FloorItem( var owner: String? = null ) : Entity, EventDispatcher { - override val events: Events = Events(this) lateinit var def: ItemDefinition val value: Long diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItems.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItems.kt index fc2aba61b..7c7b4c0b4 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItems.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItems.kt @@ -11,8 +11,6 @@ import world.gregs.voidps.engine.entity.Unregistered import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.name import world.gregs.voidps.engine.entity.item.floor.FloorItems.Companion.MAX_TILE_ITEMS -import world.gregs.voidps.engine.event.EventHandlerStore -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.encode.send import world.gregs.voidps.network.encode.zone.FloorItemAddition import world.gregs.voidps.network.encode.zone.FloorItemRemoval @@ -25,8 +23,7 @@ import world.gregs.voidps.type.Zone */ class FloorItems( private val batches: ZoneBatchUpdates, - private val definitions: ItemDefinitions, - private val store: EventHandlerStore + private val definitions: ItemDefinitions ) : ZoneBatchUpdates.Sender { internal val data = Int2ObjectOpenHashMap>>() @@ -48,7 +45,6 @@ class FloorItems( } val item = FloorItem(tile, id, amount, revealTicks, disappearTicks, if (revealTicks == 0) null else owner) item.def = definition - store.populate(item) add(item) return item } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventDispatcher.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventDispatcher.kt index 75270669c..07fe28dcb 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventDispatcher.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventDispatcher.kt @@ -1,5 +1,11 @@ package world.gregs.voidps.engine.event interface EventDispatcher { - val events: Events + fun emit(event: E): Boolean { + return EventStore.events.emit(this, event) + } + + fun emit(event: E): Boolean { + return EventStore.events.emit(this, event) + } } \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt index c77b2a737..d388318ab 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt @@ -9,59 +9,21 @@ import world.gregs.voidps.engine.entity.item.floor.FloorItem import world.gregs.voidps.engine.get import kotlin.reflect.KClass -/** - * Handles the storage and delivery of global [EventHandler]'s - */ -class EventHandlerStore { - - private val handlers = Object2ObjectOpenHashMap, MutableMap, MutableList>>() - - private val parents = Object2ObjectOpenHashMap(mapOf, List>>( - EventDispatcher::class to listOf(World::class, FloorItem::class, Character::class), - Character::class to listOf(Player::class, NPC::class) - )) - - fun populate(clazz: KClass, events: Events) { - events.set(get(clazz)) - } - - fun populate(entity: T) { - populate(entity::class, entity.events) - } - - fun get(entity: KClass): Map, MutableList> { - return handlers[entity] ?: emptyMap() - } - - fun add(entity: KClass, event: KClass, handler: EventHandler) { - val list = handlers.getOrPut(entity) { Object2ObjectOpenHashMap(2) }.getOrPut(event) { mutableListOf() } - list.add(handler) - list.sort() - } - - fun add(dispatcher: KClass, event: KClass, condition: Event.(EventDispatcher) -> Boolean, priority: Priority, block: suspend Event.(EventDispatcher) -> Unit) { - add(dispatcher, event, EventHandler(event, condition, priority, block)) - for (parent in parents[dispatcher] ?: return) { - add(parent, event, EventHandler(event, condition, priority, block)) - } - } - - fun clear() { - handlers.clear() - } -} - -fun EventDispatcher.emit(event: E): Boolean { - return events.emit(event) -} - -fun EventDispatcher.emit(event: E): Boolean { - return events.emit(event) -} +private val parents = Object2ObjectOpenHashMap(mapOf, List>>( + EventDispatcher::class to listOf(World::class, FloorItem::class, Character::class), + Character::class to listOf(Player::class, NPC::class) +)) @Suppress("UNCHECKED_CAST") inline fun addEvent(noinline condition: E.(T) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(T) -> Unit) { - get().add(T::class, E::class, condition as Event.(EventDispatcher) -> Boolean, priority, block as suspend Event.(EventDispatcher) -> Unit) + add(T::class, E::class, condition as Event.(EventDispatcher) -> Boolean, priority, block as suspend Event.(EventDispatcher) -> Unit) +} + +fun add(dispatcher: KClass, event: KClass, condition: Event.(EventDispatcher) -> Boolean, priority: Priority, block: suspend Event.(EventDispatcher) -> Unit) { + EventStore.events.add(dispatcher, event, EventHandler(event, condition, priority, block)) + for (parent in parents[dispatcher] ?: return) { + EventStore.events.add(parent, event, EventHandler(event, condition, priority, block)) + } } inline fun on(noinline condition: E.(Player) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(Player) -> Unit) = diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt new file mode 100644 index 000000000..76595328c --- /dev/null +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt @@ -0,0 +1,82 @@ +package world.gregs.voidps.engine.event + +import com.github.michaelbull.logging.InlineLogger +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap +import kotlinx.coroutines.* +import kotlin.coroutines.CoroutineContext +import kotlin.reflect.KClass + +class EventStore : CoroutineScope { + override val coroutineContext: CoroutineContext = Dispatchers.Unconfined + errorHandler + private val handlers: MutableMap, MutableMap, MutableList>> = Object2ObjectOpenHashMap() + + fun add(dispatcher: KClass, event: KClass, handler: EventHandler) { + handlers.getOrPut(dispatcher) { Object2ObjectOpenHashMap(2) }.getOrPut(event) { mutableListOf() }.add(handler) + } + + fun init() { + for ((_, map) in handlers) { + for ((_, list) in map) { + list.sort() + } + } + } + + fun clear() { + handlers.clear() + } + + var all: ((Event) -> Unit)? = null + + fun emit(dispatcher: EventDispatcher, event: E): Boolean { + val handlers = handlers[dispatcher::class]?.get(event::class) ?: return false + all?.invoke(event) + var called = false + for (handler in handlers) { + if (event is CancellableEvent && event.cancelled) { + return true + } + if (handler.condition(event, dispatcher)) { + called = true + runBlocking { + handler.block(event, dispatcher) + } + } + } + return called + } + + fun emit(dispatcher: EventDispatcher, event: E): Boolean { + val handlers = handlers[dispatcher::class]?.get(event::class) ?: return false + if (handlers.none { it.condition(event, dispatcher) }) { + return false + } + launch { + for (handler in handlers) { + if (event is CancellableEvent && event.cancelled) { + return@launch + } + if (handler.condition(event, dispatcher)) { + handler.block(event, dispatcher) + } + } + } + return true + } + + fun contains(dispatcher: EventDispatcher, event: E): Boolean { + val eventHandlers = handlers[dispatcher::class]?.get(event::class) + return eventHandlers != null && eventHandlers.any { it.condition(event, dispatcher) } + } + + companion object { + private val logger = InlineLogger() + private val errorHandler = CoroutineExceptionHandler { _, throwable -> + if (throwable !is CancellationException) { + logger.warn(throwable) { "Error in event." } + } + } + var events = EventStore() + private set + } +} \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/Events.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/Events.kt deleted file mode 100644 index 7459b5ed8..000000000 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/Events.kt +++ /dev/null @@ -1,69 +0,0 @@ -package world.gregs.voidps.engine.event - -import kotlinx.coroutines.* -import kotlin.coroutines.CoroutineContext -import kotlin.reflect.KClass - -class Events( - private val dispatcher: EventDispatcher, -) : CoroutineScope { - override val coroutineContext: CoroutineContext = Dispatchers.Unconfined + errorHandler - private var events: Map, List> = emptyMap() - var all: ((Event) -> Unit)? = null - - operator fun get(klass: KClass) = events[klass] - - fun set(events: Map, List>) { - this.events = events - } - - fun emit(event: E): Boolean { - all?.invoke(event) - var called = false - events[event::class] - ?.forEach { handler -> - if (event is CancellableEvent && event.cancelled) { - return true - } - if (handler.condition(event, dispatcher)) { - called = true - runBlocking { - handler.block(event, dispatcher) - } - } - } - return called - } - - fun emit(event: E): Boolean { - all?.invoke(event) - val eventHandlers = events[event::class] - if (eventHandlers == null || eventHandlers.none { it.condition(event, dispatcher) }) { - return false - } - launch { - for (handler in eventHandlers) { - if (event is CancellableEvent && event.cancelled) { - return@launch - } - if (handler.condition(event, dispatcher)) { - handler.block(event, dispatcher) - } - } - } - return true - } - - fun contains(event: E): Boolean { - val eventHandlers = events[event::class] - return eventHandlers != null && eventHandlers.any { it.condition(event, dispatcher) } - } - - companion object { - private val errorHandler = CoroutineExceptionHandler { _, throwable -> - if (throwable !is CancellationException) { - throwable.printStackTrace() - } - } - } -} \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/inv/Inventories.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/inv/Inventories.kt index a20a9a974..0a7dea0b2 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/inv/Inventories.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/inv/Inventories.kt @@ -6,7 +6,7 @@ import world.gregs.voidps.engine.data.definition.InventoryDefinitions import world.gregs.voidps.engine.data.definition.ItemDefinitions 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.engine.inv.remove.DefaultItemRemovalChecker import world.gregs.voidps.engine.inv.remove.ShopItemRemovalChecker @@ -25,7 +25,7 @@ class Inventories( lateinit var definitions: InventoryDefinitions lateinit var itemDefinitions: ItemDefinitions lateinit var validItemRule: ItemRestrictionRule - lateinit var events: Events + lateinit var events: EventDispatcher lateinit var normalStack: DependentOnItem fun inventory(definition: InventoryDefinition, secondary: Boolean = false): Inventory { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/inv/transact/ChangeManager.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/inv/transact/ChangeManager.kt index ec5d64bfa..f40bee43c 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/inv/transact/ChangeManager.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/inv/transact/ChangeManager.kt @@ -1,7 +1,7 @@ package world.gregs.voidps.engine.inv.transact 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.inv.Inventory import world.gregs.voidps.engine.inv.InventoryUpdate import world.gregs.voidps.engine.inv.ItemChanged @@ -14,7 +14,7 @@ class ChangeManager( private val inventory: Inventory ) { private val changes: Stack = Stack() - private val events = mutableSetOf() + private val events = mutableSetOf() /** * Track a change of an item in the inventory. @@ -31,14 +31,14 @@ class ChangeManager( /** * Adds [events] to the list of recipients of [ItemChanged] updates in this inventory. */ - fun bind(events: Events) { + fun bind(events: EventDispatcher) { this.events.add(events) } /** * Removes [events] to the list of recipients of [ItemChanged] updates in this inventory. */ - fun unbind(events: Events) { + fun unbind(events: EventDispatcher) { this.events.remove(events) } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/map/zone/DynamicZones.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/map/zone/DynamicZones.kt index dbd3a6991..da1448ff9 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/map/zone/DynamicZones.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/map/zone/DynamicZones.kt @@ -5,7 +5,6 @@ import it.unimi.dsi.fastutil.ints.IntOpenHashSet import world.gregs.voidps.engine.data.definition.MapDefinitions import world.gregs.voidps.engine.entity.World import world.gregs.voidps.engine.entity.obj.GameObjects -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.map.collision.Collisions import world.gregs.voidps.engine.map.collision.clear import world.gregs.voidps.type.Region diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/timer/TimerQueue.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/timer/TimerQueue.kt index 38e2ae859..53d3a3246 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/timer/TimerQueue.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/timer/TimerQueue.kt @@ -1,10 +1,10 @@ package world.gregs.voidps.engine.timer -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher import java.util.* class TimerQueue( - private val events: Events + private val events: EventDispatcher ) : Timers { val queue = PriorityQueue() diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/timer/TimerSlot.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/timer/TimerSlot.kt index 150ec66e5..3034f5079 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/timer/TimerSlot.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/timer/TimerSlot.kt @@ -1,9 +1,9 @@ package world.gregs.voidps.engine.timer -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher class TimerSlot( - private val events: Events + private val events: EventDispatcher ) : Timers { private var timer: Timer? = null diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/client/ConnectionGatekeeperTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/client/ConnectionGatekeeperTest.kt index d432949ec..fc4d5c68b 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/client/ConnectionGatekeeperTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/client/ConnectionGatekeeperTest.kt @@ -9,7 +9,6 @@ import org.junit.jupiter.api.Test import org.koin.dsl.module import world.gregs.voidps.engine.entity.character.IndexAllocator import world.gregs.voidps.engine.entity.character.player.Players -import world.gregs.voidps.engine.event.EventHandlerStore import world.gregs.voidps.engine.getIntProperty import world.gregs.voidps.engine.script.KoinMock import world.gregs.voidps.network.NetworkGatekeeper @@ -21,7 +20,6 @@ internal class ConnectionGatekeeperTest : KoinMock() { override val modules = listOf( module { - single { EventHandlerStore() } single { ConnectionQueue(getIntProperty("connectionPerTickCap", 1)) } diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/client/ConnectionQueueTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/client/ConnectionQueueTest.kt index 47c161ebf..ffca78556 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/client/ConnectionQueueTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/client/ConnectionQueueTest.kt @@ -8,7 +8,6 @@ import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.koin.dsl.module -import world.gregs.voidps.engine.event.EventHandlerStore import world.gregs.voidps.engine.getIntProperty import world.gregs.voidps.engine.script.KoinMock import world.gregs.voidps.network.NetworkQueue @@ -20,7 +19,6 @@ internal class ConnectionQueueTest : KoinMock() { override val modules = listOf( module { - single { EventHandlerStore() } single { ConnectionQueue(getIntProperty("connectionPerTickCap", 1)) } diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/client/ui/InterfaceTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/client/ui/InterfaceTest.kt index 0b0c96d4c..e7c52bab2 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/client/ui/InterfaceTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/client/ui/InterfaceTest.kt @@ -6,14 +6,14 @@ import io.mockk.spyk import org.junit.jupiter.api.BeforeEach import org.koin.test.mock.declare import world.gregs.voidps.engine.data.definition.InterfaceDefinitions -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher import world.gregs.voidps.engine.script.KoinMock import world.gregs.voidps.network.client.Client abstract class InterfaceTest : KoinMock() { internal lateinit var client: Client - internal lateinit var events: Events + internal lateinit var events: EventDispatcher internal lateinit var interfaces: Interfaces internal lateinit var open: MutableSet internal lateinit var definitions: InterfaceDefinitions diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/CharacterUpdateTaskTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/CharacterUpdateTaskTest.kt index ed948f7fb..8b286715f 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/CharacterUpdateTaskTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/CharacterUpdateTaskTest.kt @@ -14,7 +14,6 @@ import world.gregs.voidps.engine.client.update.player.PlayerUpdateTask import world.gregs.voidps.engine.entity.character.npc.NPCs import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.Players -import world.gregs.voidps.engine.event.EventHandlerStore import world.gregs.voidps.engine.script.KoinMock internal class CharacterUpdateTaskTest : KoinMock() { @@ -27,8 +26,7 @@ internal class CharacterUpdateTaskTest : KoinMock() { private lateinit var batches: ZoneBatchUpdates override val modules = listOf( module { - single { EventHandlerStore() } - single { NPCs(get(), get(), get(), get()) } + single { NPCs(get(), get(), get()) } single { Players() } } ) diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/npc/NPCUpdateTaskTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/npc/NPCUpdateTaskTest.kt index 7f306e21a..914f94763 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/npc/NPCUpdateTaskTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/npc/NPCUpdateTaskTest.kt @@ -16,7 +16,6 @@ import world.gregs.voidps.engine.client.update.view.Viewport import world.gregs.voidps.engine.entity.character.npc.NPC import world.gregs.voidps.engine.entity.character.npc.NPCs import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.EventHandlerStore import world.gregs.voidps.type.Tile import world.gregs.voidps.engine.script.KoinMock import world.gregs.voidps.engine.value @@ -33,8 +32,7 @@ internal class NPCUpdateTaskTest : KoinMock() { private lateinit var viewport: Viewport override val modules = listOf( module { - single { EventHandlerStore() } - single { NPCs(get(), get(), get(), get()) } + single { NPCs(get(), get(), get()) } } ) private lateinit var encoder: VisualEncoder diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/player/PlayerUpdateTaskTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/player/PlayerUpdateTaskTest.kt index efa2ee8c5..a5a80cca1 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/player/PlayerUpdateTaskTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/client/update/player/PlayerUpdateTaskTest.kt @@ -17,7 +17,6 @@ import world.gregs.voidps.engine.client.update.view.PlayerTrackingSet import world.gregs.voidps.engine.client.update.view.Viewport import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.Players -import world.gregs.voidps.engine.event.EventHandlerStore import world.gregs.voidps.engine.script.KoinMock import world.gregs.voidps.engine.value import world.gregs.voidps.network.client.Client @@ -29,12 +28,11 @@ import world.gregs.voidps.type.Tile internal class PlayerUpdateTaskTest : KoinMock() { - lateinit var task: PlayerUpdateTask - lateinit var players: Players + private lateinit var task: PlayerUpdateTask + private lateinit var players: Players private lateinit var encoder: VisualEncoder override val modules = listOf( module { - single { EventHandlerStore() } single { Players() } } ) diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/client/variable/ClocksTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/client/variable/ClocksTest.kt index 0c844d01d..c3f2c6cf8 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/client/variable/ClocksTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/client/variable/ClocksTest.kt @@ -5,7 +5,6 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import world.gregs.voidps.engine.GameLoop import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.Events internal class ClocksTest { @@ -15,7 +14,7 @@ internal class ClocksTest { @BeforeEach fun setup() { player = Player() - variables = Variables(Events(player), mutableMapOf()) + variables = Variables(player, mutableMapOf()) player.variables = variables GameLoop.tick = 0 } diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/client/variable/VariablesTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/client/variable/VariablesTest.kt index 8e722ee07..8b77228d6 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/client/variable/VariablesTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/client/variable/VariablesTest.kt @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test import world.gregs.voidps.engine.data.config.VariableDefinition import world.gregs.voidps.engine.data.definition.VariableDefinitions import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher import world.gregs.voidps.network.client.Client internal class VariablesTest { @@ -17,7 +17,7 @@ internal class VariablesTest { private lateinit var variable: VariableDefinition private lateinit var player: Player private lateinit var client: Client - private lateinit var events: Events + private lateinit var events: EventDispatcher private lateinit var map: MutableMap private lateinit var defs: MutableMap @@ -43,7 +43,6 @@ internal class VariablesTest { player = mockk(relaxed = true) client = mockk(relaxed = true) every { player.variables } returns variables - every { player.events } returns events every { definitions.get(key) } returns variable variables.definitions = definitions variables.client = client diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/player/skill/ExperienceTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/player/skill/ExperienceTest.kt index 93904c3e3..09091398c 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/player/skill/ExperienceTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/player/skill/ExperienceTest.kt @@ -12,12 +12,12 @@ import world.gregs.voidps.engine.entity.character.player.skill.exp.BlockedExperi import world.gregs.voidps.engine.entity.character.player.skill.exp.Experience import world.gregs.voidps.engine.entity.character.player.skill.exp.GrantExp import world.gregs.voidps.engine.entity.character.player.skill.exp.exp -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher internal class ExperienceTest { private lateinit var experience: Experience - private lateinit var events: Events + private lateinit var events: EventDispatcher @BeforeEach fun setup() { diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/player/skill/LevelsTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/player/skill/LevelsTest.kt index 3ead1c6a1..45a863edb 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/player/skill/LevelsTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/player/skill/LevelsTest.kt @@ -7,24 +7,23 @@ import io.mockk.verifyOrder import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.skill.exp.Experience import world.gregs.voidps.engine.entity.character.player.skill.level.CurrentLevelChanged import world.gregs.voidps.engine.entity.character.player.skill.level.Levels import world.gregs.voidps.engine.entity.character.player.skill.level.MaxLevelChanged import world.gregs.voidps.engine.entity.character.player.skill.level.PlayerLevels -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher internal class LevelsTest { - lateinit var exp: Experience - lateinit var levels: Levels - lateinit var events: Events + private lateinit var exp: Experience + private lateinit var levels: Levels + private lateinit var events: EventDispatcher @BeforeEach fun setup() { exp = Experience(maximum = 10000.0) - events = spyk(Events(mockk(relaxed = true))) + events = mockk(relaxed = true) levels = Levels() exp.events = events levels.link(events, PlayerLevels(exp)) diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItemTrackingTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItemTrackingTest.kt index a005e2b37..c270ad25c 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItemTrackingTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItemTrackingTest.kt @@ -20,7 +20,7 @@ class FloorItemTrackingTest { fun setup() { players = mockk(relaxed = true) batches = mockk(relaxed = true) - items = FloorItems(batches, mockk(relaxed = true), mockk(relaxed = true)) + items = FloorItems(batches, mockk(relaxed = true)) tracking = FloorItemTracking(items, players, batches) } diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItemsTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItemsTest.kt index 7096ccfe3..d3b250244 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItemsTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/item/floor/FloorItemsTest.kt @@ -21,7 +21,7 @@ class FloorItemsTest { @BeforeEach fun setup() { batches = mockk(relaxed = true) - items = FloorItems(batches, mockk(relaxed = true), mockk()) + items = FloorItems(batches, mockk(relaxed = true)) } @Test diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/event/EventHandlerStoreTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/event/EventHandlerStoreTest.kt deleted file mode 100644 index 1eacb4319..000000000 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/event/EventHandlerStoreTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package world.gregs.voidps.engine.event - -import io.mockk.mockk -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -import kotlin.reflect.KClass - -internal class EventHandlerStoreTest { - - @Test - fun `Populated event handlers are in priority order`() { - val events = Events(mockk()) - - val entity: KClass = EventDispatcher::class - val event: KClass = Event::class - val handler1 = EventHandler(event, { true }, Priority.HIGHISH, {}) - val handler2 = EventHandler(event, { true }, Priority.LOW, {}) - val handler3 = EventHandler(event, { true }, Priority.MEDIUM, {}) - val store = EventHandlerStore() - store.add(entity, event, handler1) - store.add(entity, event, handler2) - store.add(entity, event, handler3) - - store.populate(entity, events) - - val ordered = events[Event::class]!! - assertEquals(handler2, ordered[2]) - assertEquals(handler3, ordered[1]) - assertEquals(handler1, ordered[0]) - } - - @Test - fun `Populated two handlers of same priority`() { - val events = Events(mockk()) - - val entity: KClass = EventDispatcher::class - val event: KClass = Event::class - val handler1 = EventHandler(event, { true }, Priority.LOW, {}) - val handler2 = EventHandler(event, { true }, Priority.LOW, {}) - val store = EventHandlerStore() - store.add(entity, event, handler1) - store.add(entity, event, handler2) - - store.populate(entity, events) - - assertEquals(2, events[Event::class]!!.size) - } -} \ No newline at end of file diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/event/EventsTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/event/EventsTest.kt deleted file mode 100644 index d9d981907..000000000 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/event/EventsTest.kt +++ /dev/null @@ -1,59 +0,0 @@ -package world.gregs.voidps.engine.event - -import io.mockk.mockk -import org.junit.jupiter.api.Test -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -internal class EventsTest { - - @Test - @Suppress("UNCHECKED_CAST") - fun `Cancelled events stops processing`() { - val events = Events(mockk()) - val event = object : CancellableEvent() {} - val klass = event::class - var cancelled = false - val block: CancellableEvent.(EventDispatcher) -> Unit = { - cancelled = true - cancel() - } - val handler1 = EventHandler(klass, { true }, Priority.HIGH, block as Event.(EventDispatcher) -> Unit) - var called = false - val handler2 = EventHandler(klass, { true }, Priority.MEDIUM, { called = true }) - events.set(mapOf(klass to listOf(handler1, handler2))) - - assertTrue(events.emit(event)) - - assertTrue(cancelled) - assertFalse(called) - } - - @Test - fun `Handlers with conditions not met aren't called`() { - val events = Events(mockk()) - val event = object : Event {} - val klass = event::class - var called1 = false - var called2 = false - val handler1 = EventHandler(klass, { false }, Priority.HIGH, { called1 = true }) - val handler2 = EventHandler(klass, { true }, Priority.MEDIUM, { called2 = true }) - events.set(mapOf(klass to listOf(handler1, handler2))) - - assertTrue(events.emit(event)) - - assertFalse(called1) - assertTrue(called2) - } - - @Test - fun `Emit returns false if nothing executed`() { - val events = Events(mockk()) - val event = object : Event {} - val klass = event::class - val handler = EventHandler(klass, { false }, Priority.HIGH, {}) - events.set(mapOf(klass to listOf(handler))) - - assertFalse(events.emit(event)) - } -} \ No newline at end of file diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/inv/InventoryTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/inv/InventoryTest.kt index caca35dbf..6daa551db 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/inv/InventoryTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/inv/InventoryTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test import world.gregs.voidps.cache.definition.data.ItemDefinition import world.gregs.voidps.engine.data.definition.ItemDefinitions 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.inv.remove.DefaultItemRemovalChecker import world.gregs.voidps.engine.inv.remove.ItemRemovalChecker import world.gregs.voidps.engine.inv.remove.ShopItemRemovalChecker @@ -22,7 +22,7 @@ internal class InventoryTest { private lateinit var inventory: Inventory private lateinit var items: Array private lateinit var minimumAmounts: IntArray - private lateinit var events: Events + private lateinit var events: EventDispatcher @BeforeEach fun setup() { diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/inv/transact/ChangeManagerTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/inv/transact/ChangeManagerTest.kt index 5fc2f07b5..159c46118 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/inv/transact/ChangeManagerTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/inv/transact/ChangeManagerTest.kt @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test import world.gregs.voidps.cache.definition.data.ItemDefinition import world.gregs.voidps.engine.entity.item.Item import world.gregs.voidps.engine.event.Event -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher import world.gregs.voidps.engine.inv.Inventory import world.gregs.voidps.engine.inv.InventoryUpdate import world.gregs.voidps.engine.inv.ItemChanged @@ -25,7 +25,7 @@ internal class ChangeManagerTest { @Test fun `Track and send changes`() { - val events = mockk(relaxed = true) + val events = mockk(relaxed = true) change.bind(events) change.track("inventory", 1, Item.EMPTY, 1, Item("item", 1, def = ItemDefinition.EMPTY)) change.send() @@ -37,7 +37,7 @@ internal class ChangeManagerTest { @Test fun `Clear tracked changes`() { - val events = mockk(relaxed = true) + val events = mockk(relaxed = true) change.bind(events) change.track("inventory", 1, Item.EMPTY, 1, Item("item", 1, def = ItemDefinition.EMPTY)) change.clear() diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/inv/transact/TransactionTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/inv/transact/TransactionTest.kt index 9f421708c..5dde37070 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/inv/transact/TransactionTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/inv/transact/TransactionTest.kt @@ -8,7 +8,7 @@ import world.gregs.voidps.engine.inv.Inventory import world.gregs.voidps.engine.inv.ItemChanged import world.gregs.voidps.engine.inv.transact.operation.TransactionOperationTest import world.gregs.voidps.engine.entity.item.Item -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -18,7 +18,7 @@ class TransactionTest : TransactionOperationTest() { @Test fun `Set tracks changes`() { val inventory = Inventory.debug(1) - val events: Events = mockk(relaxed = true) + val events: EventDispatcher = mockk(relaxed = true) val transaction = inventory.transaction transaction.changes.bind(events) transaction.set(0, Item("item", 1, def = ItemDefinition.EMPTY)) diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/map/zone/ZoneBatchUpdatesTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/map/zone/ZoneBatchUpdatesTest.kt index 285becb1b..adcc2531a 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/map/zone/ZoneBatchUpdatesTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/map/zone/ZoneBatchUpdatesTest.kt @@ -15,7 +15,6 @@ import world.gregs.voidps.engine.entity.character.player.name import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.obj.GameObjects import world.gregs.voidps.engine.entity.obj.ObjectShape -import world.gregs.voidps.engine.event.EventHandlerStore import world.gregs.voidps.engine.map.collision.Collisions import world.gregs.voidps.engine.map.collision.GameObjectCollision import world.gregs.voidps.engine.script.KoinMock @@ -36,10 +35,6 @@ internal class ZoneBatchUpdatesTest : KoinMock() { private lateinit var client: Client private lateinit var update: ZoneUpdate - override val modules = listOf(module { - single { EventHandlerStore() } - }) - @BeforeEach fun setup() { player = Player() diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/timer/TimersTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/timer/TimersTest.kt index 318cc9627..f8b43e20c 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/timer/TimersTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/timer/TimersTest.kt @@ -3,27 +3,35 @@ package world.gregs.voidps.engine.timer import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import world.gregs.voidps.engine.GameLoop -import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.event.Event -import world.gregs.voidps.engine.event.Events +import world.gregs.voidps.engine.event.EventDispatcher +import world.gregs.voidps.engine.event.SuspendableEvent import java.util.* abstract class TimersTest { lateinit var emitted: LinkedList - lateinit var events: Events + lateinit var events: EventDispatcher lateinit var timers: Timers internal var block: ((Event) -> Unit)? = null open fun setup() { GameLoop.tick = 0 emitted = LinkedList() - events = Events(Player()) - block = null - events.all = { - block?.invoke(it) - this.emitted.add(it) + events = object : EventDispatcher { + override fun emit(event: E): Boolean { + block?.invoke(event) + emitted.add(event) + return super.emit(event) + } + + override fun emit(event: E): Boolean { + block?.invoke(event) + emitted.add(event) + return super.emit(event) + } } + block = null } @Test diff --git a/game/src/main/kotlin/world/gregs/voidps/GameTick.kt b/game/src/main/kotlin/world/gregs/voidps/GameTick.kt index 56cc7e3a7..917219178 100644 --- a/game/src/main/kotlin/world/gregs/voidps/GameTick.kt +++ b/game/src/main/kotlin/world/gregs/voidps/GameTick.kt @@ -28,7 +28,6 @@ import world.gregs.voidps.engine.entity.character.player.Players 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.emit import world.gregs.voidps.engine.get import world.gregs.voidps.network.NetworkQueue import world.gregs.voidps.network.visual.NPCVisuals diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/Bot.kt b/game/src/main/kotlin/world/gregs/voidps/bot/Bot.kt index 7829533c4..3d739058b 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/Bot.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/Bot.kt @@ -3,15 +3,12 @@ package world.gregs.voidps.bot import world.gregs.voidps.engine.entity.character.Character import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.event.Event -import world.gregs.voidps.engine.event.Events import world.gregs.voidps.engine.event.Priority import world.gregs.voidps.engine.event.addEvent import world.gregs.voidps.network.Instruction data class Bot(val player: Player) : Character by player { - val botEvents = Events(this) - var step: Instruction? = null } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts b/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts index 393ca22ad..5192358a3 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts @@ -16,8 +16,6 @@ import world.gregs.voidps.engine.entity.character.player.appearance import world.gregs.voidps.engine.entity.character.player.sex import world.gregs.voidps.engine.entity.worldSpawn import world.gregs.voidps.engine.event.Event -import world.gregs.voidps.engine.event.EventHandlerStore -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.getIntProperty import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.add @@ -116,14 +114,13 @@ fun spawn() { fun Player.initBot(): Bot { val bot = Bot(this) - world.gregs.voidps.engine.get().populate(Bot::class, bot.botEvents) this["bot"] = bot val e = ConcurrentLinkedQueue() this["events"] = e - events.all = { event -> - e.add(event) - handleSuspensions(bot.player, event) - } +// events.all = { event -> +// e.add(event) +// handleSuspensions(bot.player, event) +// } return bot } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts b/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts index 2a0025af8..db92dc6bd 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts @@ -38,7 +38,7 @@ onWorld { val events: ConcurrentLinkedQueue = player["events"]!! while (events.isNotEmpty()) { val event = events.poll() - bot.botEvents.emit(event) + bot.emit(event) } bot.resume("tick") } diff --git a/game/src/main/kotlin/world/gregs/voidps/script/ScriptLoader.kt b/game/src/main/kotlin/world/gregs/voidps/script/ScriptLoader.kt index 2b5c9c442..19216bf21 100644 --- a/game/src/main/kotlin/world/gregs/voidps/script/ScriptLoader.kt +++ b/game/src/main/kotlin/world/gregs/voidps/script/ScriptLoader.kt @@ -4,6 +4,7 @@ import com.github.michaelbull.logging.InlineLogger import io.github.classgraph.ClassGraph import world.gregs.voidps.Main import world.gregs.voidps.engine.client.ui.chat.plural +import world.gregs.voidps.engine.event.EventStore import world.gregs.voidps.engine.getProperty import kotlin.system.measureTimeMillis @@ -36,5 +37,6 @@ fun loadScripts(scriptPackage: String = getProperty("scriptPackage"), botScriptP if (scriptCount == 0) { logger.warn { "No scripts found." } } + EventStore.events.init() logger.info { "Loaded $scriptCount ${"script".plural(scriptCount)} in ${time}ms" } } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/ItemOnItems.kts b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/ItemOnItems.kts index 659857c8c..d4197508e 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/ItemOnItems.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/activity/skill/ItemOnItems.kts @@ -18,7 +18,6 @@ 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.event.emit import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.inventory diff --git a/game/src/main/kotlin/world/gregs/voidps/world/command/admin/AdminCommands.kts b/game/src/main/kotlin/world/gregs/voidps/world/command/admin/AdminCommands.kts index d86c521ce..573aed8ad 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/command/admin/AdminCommands.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/command/admin/AdminCommands.kts @@ -40,7 +40,6 @@ import world.gregs.voidps.engine.entity.item.drop.DropTables import world.gregs.voidps.engine.entity.item.drop.ItemDrop import world.gregs.voidps.engine.entity.obj.GameObjects import world.gregs.voidps.engine.entity.worldSpawn -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.* diff --git a/game/src/main/kotlin/world/gregs/voidps/world/community/chat/Chat.kts b/game/src/main/kotlin/world/gregs/voidps/world/community/chat/Chat.kts index 24edfbd31..fdbe5a589 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/community/chat/Chat.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/community/chat/Chat.kts @@ -12,7 +12,6 @@ import world.gregs.voidps.engine.entity.character.player.chat.global.PublicChat import world.gregs.voidps.engine.entity.character.player.chat.global.PublicChatMessage import world.gregs.voidps.engine.entity.character.player.name import world.gregs.voidps.engine.entity.character.player.rights -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.event.on import world.gregs.voidps.engine.inject import world.gregs.voidps.network.encode.clanChat diff --git a/game/src/main/kotlin/world/gregs/voidps/world/community/chat/QuickChat.kts b/game/src/main/kotlin/world/gregs/voidps/world/community/chat/QuickChat.kts index b4e0379cf..1aab95517 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/community/chat/QuickChat.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/community/chat/QuickChat.kts @@ -15,7 +15,6 @@ import world.gregs.voidps.engine.entity.character.player.chat.friend.PrivateQuic import world.gregs.voidps.engine.entity.character.player.chat.global.PublicQuickChat import world.gregs.voidps.engine.entity.character.player.chat.global.PublicQuickChatMessage import world.gregs.voidps.engine.entity.character.player.skill.Skill -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.event.on import world.gregs.voidps.engine.inject import world.gregs.voidps.network.encode.clanQuickChat diff --git a/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanChat.kts b/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanChat.kts index 65109e5f0..a5597c884 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanChat.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanChat.kts @@ -17,7 +17,6 @@ import world.gregs.voidps.engine.entity.character.player.name import world.gregs.voidps.engine.entity.playerDespawn import world.gregs.voidps.engine.entity.playerSpawn import world.gregs.voidps.engine.event.Priority -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.event.on import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.timer.epochSeconds diff --git a/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanSetup.kts b/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanSetup.kts index 1f2da3f46..ead2d8fde 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanSetup.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/community/clan/ClanSetup.kts @@ -13,7 +13,6 @@ import world.gregs.voidps.engine.entity.character.player.chat.clan.Clan import world.gregs.voidps.engine.entity.character.player.chat.clan.ClanRank import world.gregs.voidps.engine.entity.character.player.chat.clan.LeaveClanChat import world.gregs.voidps.engine.entity.character.player.name -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.encode.Member import world.gregs.voidps.network.encode.leaveClanChat import world.gregs.voidps.network.encode.updateClanChat diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/dialogue/type/LevelUp.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/dialogue/type/LevelUp.kts index 360832fce..b9fd54f1b 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/dialogue/type/LevelUp.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/dialogue/type/LevelUp.kts @@ -11,7 +11,6 @@ import world.gregs.voidps.engine.entity.character.player.skill.exp.experience import world.gregs.voidps.engine.entity.character.player.skill.level.MaxLevelChanged import world.gregs.voidps.engine.entity.character.player.skill.level.maxLevelUp import world.gregs.voidps.engine.entity.character.setGraphic -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.queue.weakQueue import world.gregs.voidps.world.interact.entity.combat.hit.combatHit import world.gregs.voidps.world.interact.entity.sound.playJingle diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts index f9278dfbf..d075ba3d9 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/Combat.kts @@ -12,7 +12,6 @@ import world.gregs.voidps.engine.entity.character.mode.combat.CombatReached import world.gregs.voidps.engine.entity.character.mode.combat.CombatStop import world.gregs.voidps.engine.entity.character.mode.interact.Interact import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.event.onCharacter import world.gregs.voidps.world.interact.entity.death.characterDeath diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatDebug.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatDebug.kts index ffe7344b5..4ba19375f 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatDebug.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatDebug.kts @@ -10,7 +10,6 @@ import world.gregs.voidps.engine.entity.character.npc.NPCLevels import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.equip.equipped import world.gregs.voidps.engine.entity.character.player.name -import world.gregs.voidps.engine.event.EventHandlerStore import world.gregs.voidps.engine.event.Priority import world.gregs.voidps.engine.event.onCharacter import world.gregs.voidps.engine.inject @@ -20,7 +19,6 @@ import world.gregs.voidps.world.interact.entity.combat.hit.Damage import world.gregs.voidps.world.interact.entity.combat.hit.Hit val npcDefinitions: NPCDefinitions by inject() -val eventHandler: EventHandlerStore by inject() modCommand("maxhit") { val debug = player["debug", false] @@ -37,8 +35,7 @@ modCommand("maxhit") { player.message("Hit Chance") val target = NPC(npcName).apply { def = npcDefinitions.get(npcName) - eventHandler.populate(this) - levels.link(events, NPCLevels(def)) + levels.link(this, NPCLevels(def)) levels.clear() } val rangeChance = Hit.chance(player, target, "range", weapon) diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/hit/Hit.kt b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/hit/Hit.kt index 8564dbe5f..e7f77af1c 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/hit/Hit.kt +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/combat/hit/Hit.kt @@ -7,7 +7,6 @@ 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.skill.Skill import world.gregs.voidps.engine.entity.item.Item -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.queue.strongQueue import world.gregs.voidps.engine.timer.TICKS import world.gregs.voidps.type.random diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathCharacter.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathCharacter.kts index d3179ba63..53a337671 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathCharacter.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathCharacter.kts @@ -2,7 +2,6 @@ package world.gregs.voidps.world.interact.entity.death import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.character.player.skill.level.characterLevelChange -import world.gregs.voidps.engine.event.emit characterLevelChange(Skill.Constitution) { character -> if (to <= 0 && !character.queue.contains("death")) { diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathNPC.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathNPC.kts index 611a4abaa..8242baabc 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathNPC.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/DeathNPC.kts @@ -20,7 +20,6 @@ import world.gregs.voidps.engine.entity.character.setAnimation import world.gregs.voidps.engine.entity.item.Item import world.gregs.voidps.engine.entity.item.drop.DropTables import world.gregs.voidps.engine.entity.item.floor.FloorItems -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.queue.strongQueue import world.gregs.voidps.type.Direction diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/GeneralStores.kt b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/GeneralStores.kt index 74df2dffb..8c8052e29 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/GeneralStores.kt +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/GeneralStores.kt @@ -39,12 +39,12 @@ object GeneralStores { } fun bind(player: Player, key: String): Inventory = get(key).apply { - this.transaction.changes.bind(player.events) + this.transaction.changes.bind(player) player.sendInventory(this, false) } fun unbind(player: Player, key: String): Inventory = get(key).apply { - this.transaction.changes.unbind(player.events) + this.transaction.changes.unbind(player) } } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/OpenShop.kt b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/OpenShop.kt index 068d3629d..62e9fd502 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/OpenShop.kt +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/npc/shop/OpenShop.kt @@ -2,7 +2,6 @@ package world.gregs.voidps.world.interact.entity.npc.shop import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.event.Event -import world.gregs.voidps.engine.event.emit data class OpenShop(val id: String): Event diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/Teleports.kt b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/Teleports.kt index f0e1b18e0..54c3c0a8d 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/Teleports.kt +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/Teleports.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.world.interact.entity.obj import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap import world.gregs.voidps.engine.entity.character.move.tele import world.gregs.voidps.engine.entity.obj.ObjectOption -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.getProperty import world.gregs.voidps.engine.suspend.delay diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/door/Doors.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/door/Doors.kts index ce538216f..e1116b9f1 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/door/Doors.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/obj/door/Doors.kts @@ -6,7 +6,6 @@ import world.gregs.voidps.engine.client.variable.remaining import world.gregs.voidps.engine.client.variable.start import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.obj.objectOperate -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.suspend.pause import world.gregs.voidps.engine.timer.epochSeconds import world.gregs.voidps.world.interact.entity.obj.door.Door.closeDoor diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/consume/Eating.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/consume/Eating.kts index 999c56812..06bc326e5 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/consume/Eating.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/consume/Eating.kts @@ -7,7 +7,6 @@ import world.gregs.voidps.engine.entity.character.player.chat.ChatType import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.character.setAnimation import world.gregs.voidps.engine.event.Priority -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.inventory import world.gregs.voidps.engine.inv.remove import world.gregs.voidps.engine.inv.replace diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/prayer/PrayerToggle.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/prayer/PrayerToggle.kts index 4fe79f97c..a91dd5f28 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/prayer/PrayerToggle.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/prayer/PrayerToggle.kts @@ -7,7 +7,6 @@ import world.gregs.voidps.engine.client.ui.closeInterfaces import world.gregs.voidps.engine.client.variable.variableAdded import world.gregs.voidps.engine.client.variable.variableRemoved import world.gregs.voidps.engine.client.variable.variableSet -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.world.interact.entity.player.combat.prayer.PrayerConfigs.ACTIVE_CURSES import world.gregs.voidps.world.interact.entity.player.combat.prayer.PrayerConfigs.ACTIVE_PRAYERS diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/EquipmentBonuses.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/EquipmentBonuses.kts index bb75bcd40..7815b8dce 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/EquipmentBonuses.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/EquipmentBonuses.kts @@ -12,7 +12,6 @@ import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.appearance import world.gregs.voidps.engine.entity.item.Item import world.gregs.voidps.engine.entity.playerSpawn -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.equipment import world.gregs.voidps.engine.inv.itemChange diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/Inventory.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/Inventory.kts index b340da43d..6a94224a5 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/Inventory.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/Inventory.kts @@ -7,7 +7,6 @@ import world.gregs.voidps.engine.client.ui.interfaceOption import world.gregs.voidps.engine.client.ui.interfaceSwap import world.gregs.voidps.engine.entity.character.mode.EmptyMode import world.gregs.voidps.engine.entity.character.mode.combat.CombatMovement -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.inventory import world.gregs.voidps.engine.inv.sendInventory import world.gregs.voidps.engine.inv.swap diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/WornEquipment.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/WornEquipment.kts index 3093845a7..858845ffe 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/WornEquipment.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/equip/WornEquipment.kts @@ -6,7 +6,6 @@ import world.gregs.voidps.engine.client.ui.closeInterfaces import world.gregs.voidps.engine.client.ui.event.interfaceRefresh import world.gregs.voidps.engine.client.ui.interfaceOption import world.gregs.voidps.engine.client.ui.open -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.sendInventory import world.gregs.voidps.network.visual.update.player.EquipSlot diff --git a/game/src/main/kotlin/world/gregs/voidps/world/map/varrock/Aubury.kts b/game/src/main/kotlin/world/gregs/voidps/world/map/varrock/Aubury.kts index c9cccbf05..de1972681 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/map/varrock/Aubury.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/map/varrock/Aubury.kts @@ -2,7 +2,6 @@ package world.gregs.voidps.world.map.varrock import world.gregs.voidps.engine.entity.character.CharacterContext import world.gregs.voidps.engine.entity.character.npc.npcOperate -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.inventory import world.gregs.voidps.engine.inv.remove diff --git a/game/src/test/kotlin/world/gregs/voidps/world/community/friend/PrivateChatStatusTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/community/friend/PrivateChatStatusTest.kt index bcdd124c4..d8208bfec 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/community/friend/PrivateChatStatusTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/community/friend/PrivateChatStatusTest.kt @@ -11,7 +11,6 @@ import world.gregs.voidps.engine.entity.Registered import world.gregs.voidps.engine.entity.World import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.chat.clan.ClanRank -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.network.client.Client import world.gregs.voidps.network.encode.Friend import world.gregs.voidps.network.encode.sendFriendsList diff --git a/game/src/test/kotlin/world/gregs/voidps/world/community/trade/LendTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/community/trade/LendTest.kt index afafa9517..15ec1fdd1 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/community/trade/LendTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/community/trade/LendTest.kt @@ -10,7 +10,6 @@ import world.gregs.voidps.engine.entity.Unregistered import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.item.Item -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.equipment import world.gregs.voidps.engine.inv.inventory diff --git a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatTest.kt index 806e14175..804d6cc95 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/combat/CombatTest.kt @@ -132,7 +132,7 @@ internal class CombatTest : WorldTest() { player.levels.set(Skill.Constitution, 990) player.levels.set(Skill.Prayer, 99) val npc = createNPC("rat", emptyTile.addY(1)) - npc.levels.link(npc.events, object : Levels.Level { + npc.levels.link(npc, object : Levels.Level { override fun getMaxLevel(skill: Skill): Int { return if (skill == Skill.Constitution) 10000 else 1 } diff --git a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MagicCombatFormulaTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MagicCombatFormulaTest.kt index 26d0a7254..bfc78be11 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MagicCombatFormulaTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MagicCombatFormulaTest.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.world.interact.entity.player.combat import org.junit.jupiter.api.Test import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.item.Item -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.equipment import world.gregs.voidps.engine.inv.inventory diff --git a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MeleeCombatFormulaTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MeleeCombatFormulaTest.kt index 5f29a3952..64939d9f5 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MeleeCombatFormulaTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/MeleeCombatFormulaTest.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.world.interact.entity.player.combat import org.junit.jupiter.api.Test import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.item.Item -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.equipment import world.gregs.voidps.engine.inv.inventory diff --git a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/RangedCombatFormulaTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/RangedCombatFormulaTest.kt index b6fd84991..ee1bcb0e0 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/RangedCombatFormulaTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/interact/entity/player/combat/RangedCombatFormulaTest.kt @@ -3,7 +3,6 @@ package world.gregs.voidps.world.interact.entity.player.combat import org.junit.jupiter.api.Test import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.item.Item -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.inv.add import world.gregs.voidps.engine.inv.equipment import world.gregs.voidps.engine.inv.inventory diff --git a/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt b/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt index 677265fec..f9009ae2b 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/script/InstructionCalls.kt @@ -16,7 +16,6 @@ import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.item.Item import world.gregs.voidps.engine.entity.item.floor.FloorItem import world.gregs.voidps.engine.entity.obj.GameObject -import world.gregs.voidps.engine.event.emit import world.gregs.voidps.engine.get import world.gregs.voidps.engine.inv.Inventory import world.gregs.voidps.engine.inv.inventory diff --git a/game/src/test/kotlin/world/gregs/voidps/world/script/WorldTest.kt b/game/src/test/kotlin/world/gregs/voidps/world/script/WorldTest.kt index 1a32e46af..75a5ab5a7 100644 --- a/game/src/test/kotlin/world/gregs/voidps/world/script/WorldTest.kt +++ b/game/src/test/kotlin/world/gregs/voidps/world/script/WorldTest.kt @@ -38,7 +38,7 @@ import world.gregs.voidps.engine.entity.item.floor.FloorItems import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.obj.GameObjects import world.gregs.voidps.engine.entity.obj.ObjectShape -import world.gregs.voidps.engine.event.EventHandlerStore +import world.gregs.voidps.engine.event.EventStore import world.gregs.voidps.engine.inv.Inventory import world.gregs.voidps.engine.map.collision.CollisionDecoder import world.gregs.voidps.engine.map.collision.Collisions @@ -63,7 +63,6 @@ abstract class WorldTest : KoinTest { private val logger = InlineLogger() private lateinit var engine: GameLoop - private lateinit var store: EventHandlerStore lateinit var players: Players private lateinit var gatekeeper: NetworkGatekeeper lateinit var npcs: NPCs @@ -169,7 +168,6 @@ abstract class WorldTest : KoinTest { MapDefinitions(CollisionDecoder(get()), get(), get(), cache).loadCache() saves = File(getProperty("savePath")) saves?.mkdirs() - store = get() val millis = measureTimeMillis { val handler = InterfaceHandler(get(), get(), get()) val tickStages = getTickStages(get(), @@ -188,7 +186,6 @@ abstract class WorldTest : KoinTest { handler, iterator = SequentialIterator()) engine = GameLoop(tickStages, mockk(relaxed = true)) - store.populate(World) World.start(true) } gatekeeper = get() @@ -224,7 +221,7 @@ abstract class WorldTest : KoinTest { @AfterAll fun afterAll() { saves?.deleteRecursively() - store.clear() + EventStore.events.clear() World.shutdown() stopKoin() } From c0f3a3e416edd62b144e10e5e0a6ef42b52bdc90 Mon Sep 17 00:00:00 2001 From: GregHib Date: Sat, 24 Feb 2024 23:46:01 +0000 Subject: [PATCH 05/15] Fix bot event handling --- .../kotlin/world/gregs/voidps/engine/event/EventStore.kt | 7 +++++++ .../src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt index 76595328c..a83815020 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt @@ -9,6 +9,7 @@ import kotlin.reflect.KClass class EventStore : CoroutineScope { override val coroutineContext: CoroutineContext = Dispatchers.Unconfined + errorHandler private val handlers: MutableMap, MutableMap, MutableList>> = Object2ObjectOpenHashMap() + val botListeners = mutableListOf<(Event) -> Unit>() fun add(dispatcher: KClass, event: KClass, handler: EventHandler) { handlers.getOrPut(dispatcher) { Object2ObjectOpenHashMap(2) }.getOrPut(event) { mutableListOf() }.add(handler) @@ -30,6 +31,9 @@ class EventStore : CoroutineScope { fun emit(dispatcher: EventDispatcher, event: E): Boolean { val handlers = handlers[dispatcher::class]?.get(event::class) ?: return false + for (listener in botListeners) { + listener.invoke(event) + } all?.invoke(event) var called = false for (handler in handlers) { @@ -51,6 +55,9 @@ class EventStore : CoroutineScope { if (handlers.none { it.condition(event, dispatcher) }) { return false } + for (listener in botListeners) { + listener.invoke(event) + } launch { for (handler in handlers) { if (event is CancellableEvent && event.cancelled) { diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts b/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts index 5192358a3..01865f577 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts @@ -16,6 +16,7 @@ import world.gregs.voidps.engine.entity.character.player.appearance import world.gregs.voidps.engine.entity.character.player.sex import world.gregs.voidps.engine.entity.worldSpawn import world.gregs.voidps.engine.event.Event +import world.gregs.voidps.engine.event.EventStore import world.gregs.voidps.engine.getIntProperty import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.add @@ -117,10 +118,10 @@ fun Player.initBot(): Bot { this["bot"] = bot val e = ConcurrentLinkedQueue() this["events"] = e -// events.all = { event -> -// e.add(event) -// handleSuspensions(bot.player, event) -// } + EventStore.events.botListeners.add { event -> + e.add(event) + handleSuspensions(bot.player, event) + } return bot } From 87d49433b65b96cd00e4f63f86e0d40defe19818 Mon Sep 17 00:00:00 2001 From: GregHib Date: Sat, 24 Feb 2024 23:46:13 +0000 Subject: [PATCH 06/15] Reuse event handler --- .../world/gregs/voidps/engine/event/EventHandlerStore.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt index d388318ab..553fcede2 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt @@ -20,9 +20,10 @@ inline fun addEvent(noinline co } fun add(dispatcher: KClass, event: KClass, condition: Event.(EventDispatcher) -> Boolean, priority: Priority, block: suspend Event.(EventDispatcher) -> Unit) { - EventStore.events.add(dispatcher, event, EventHandler(event, condition, priority, block)) + val handler = EventHandler(event, condition, priority, block) + EventStore.events.add(dispatcher, event, handler) for (parent in parents[dispatcher] ?: return) { - EventStore.events.add(parent, event, EventHandler(event, condition, priority, block)) + EventStore.events.add(parent, event, handler) } } From 4c7af5680b5f4d180781b5e3da5bafd774e3c25f Mon Sep 17 00:00:00 2001 From: GregHib Date: Sat, 24 Feb 2024 23:46:23 +0000 Subject: [PATCH 07/15] Fix InteractTest --- .../engine/entity/character/mode/interact/InteractTest.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/InteractTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/InteractTest.kt index 27b2a45ab..899339b6a 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/InteractTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/InteractTest.kt @@ -29,6 +29,7 @@ import world.gregs.voidps.engine.entity.character.npc.NPCOption import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.equip.BodyParts import world.gregs.voidps.engine.event.EventHandler +import world.gregs.voidps.engine.event.EventStore import world.gregs.voidps.engine.map.collision.Collisions import world.gregs.voidps.engine.script.KoinMock import world.gregs.voidps.engine.suspend.TickSuspension @@ -91,9 +92,9 @@ internal class InteractTest : KoinMock() { interaction = NPCOption(player, target, NPCDefinition.EMPTY, "interact") interact = Interact(player, target, interaction) player.mode = interact - val handlers = mutableListOf() + EventStore.events.clear() if (operate) { - handlers.add(EventHandler(NPCOption::class, { (this as NPCOption).operate }, block = { + EventStore.events.add(Player::class, NPCOption::class, EventHandler(NPCOption::class, { (this as NPCOption).operate }, block = { if (suspend) { this as NPCOption TickSuspension(2) @@ -102,7 +103,7 @@ internal class InteractTest : KoinMock() { })) } if (approach) { - handlers.add(EventHandler(NPCOption::class, { (this as NPCOption).approach }, block = { + EventStore.events.add(Player::class, NPCOption::class, EventHandler(NPCOption::class, { (this as NPCOption).approach }, block = { if (suspend) { this as NPCOption TickSuspension(2) @@ -110,7 +111,6 @@ internal class InteractTest : KoinMock() { approached = true })) } - player.events.set(mapOf(NPCOption::class to handlers)) } @ParameterizedTest From 5f6a1b63cd1bdec45e5e78d3659279ca358f4eb5 Mon Sep 17 00:00:00 2001 From: GregHib Date: Sat, 24 Feb 2024 23:46:30 +0000 Subject: [PATCH 08/15] Fix load message --- game/src/main/kotlin/world/gregs/voidps/Main.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/src/main/kotlin/world/gregs/voidps/Main.kt b/game/src/main/kotlin/world/gregs/voidps/Main.kt index 226c5b5eb..d7852faad 100644 --- a/game/src/main/kotlin/world/gregs/voidps/Main.kt +++ b/game/src/main/kotlin/world/gregs/voidps/Main.kt @@ -61,10 +61,10 @@ object Main { val engine = GameLoop(tickStages) World.start(properties) engine.start() + logger.info { "$name loaded in ${System.currentTimeMillis() - startTime}ms" } try { server.start(getIntProperty("port")) - logger.info { "$name loaded in ${System.currentTimeMillis() - startTime}ms" } } catch (e: BindException) { logger.error(e) { "Error starting server." } } finally { From 539ba2130af79b4ad04f688b65149b5a13767244 Mon Sep 17 00:00:00 2001 From: GregHib Date: Sat, 24 Feb 2024 23:52:32 +0000 Subject: [PATCH 09/15] Remove handler store --- .../voidps/engine/event/EventHandlerStore.kt | 43 ------------------- .../gregs/voidps/engine/event/EventStore.kt | 37 +++++++++++++++- 2 files changed, 36 insertions(+), 44 deletions(-) delete mode 100644 engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt deleted file mode 100644 index 553fcede2..000000000 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandlerStore.kt +++ /dev/null @@ -1,43 +0,0 @@ -package world.gregs.voidps.engine.event - -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap -import world.gregs.voidps.engine.entity.World -import world.gregs.voidps.engine.entity.character.Character -import world.gregs.voidps.engine.entity.character.npc.NPC -import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.entity.item.floor.FloorItem -import world.gregs.voidps.engine.get -import kotlin.reflect.KClass - -private val parents = Object2ObjectOpenHashMap(mapOf, List>>( - EventDispatcher::class to listOf(World::class, FloorItem::class, Character::class), - Character::class to listOf(Player::class, NPC::class) -)) - -@Suppress("UNCHECKED_CAST") -inline fun addEvent(noinline condition: E.(T) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(T) -> Unit) { - add(T::class, E::class, condition as Event.(EventDispatcher) -> Boolean, priority, block as suspend Event.(EventDispatcher) -> Unit) -} - -fun add(dispatcher: KClass, event: KClass, condition: Event.(EventDispatcher) -> Boolean, priority: Priority, block: suspend Event.(EventDispatcher) -> Unit) { - val handler = EventHandler(event, condition, priority, block) - EventStore.events.add(dispatcher, event, handler) - for (parent in parents[dispatcher] ?: return) { - EventStore.events.add(parent, event, handler) - } -} - -inline fun on(noinline condition: E.(Player) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(Player) -> Unit) = - addEvent(condition, priority, block) - -inline fun onNPC(noinline condition: E.(NPC) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(NPC) -> Unit) = - addEvent(condition, priority, block) - -inline fun onCharacter(noinline condition: E.(Character) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(Character) -> Unit) = - addEvent(condition, priority, block) - -inline fun onFloorItem(noinline condition: E.(FloorItem) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(FloorItem) -> Unit) = - addEvent(condition, priority, block) - -inline fun onWorld(noinline condition: E.(World) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(World) -> Unit) = - addEvent(condition, priority, block) \ No newline at end of file diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt index a83815020..d58425ad4 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt @@ -3,6 +3,11 @@ package world.gregs.voidps.engine.event import com.github.michaelbull.logging.InlineLogger import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import kotlinx.coroutines.* +import world.gregs.voidps.engine.entity.World +import world.gregs.voidps.engine.entity.character.Character +import world.gregs.voidps.engine.entity.character.npc.NPC +import world.gregs.voidps.engine.entity.character.player.Player +import world.gregs.voidps.engine.entity.item.floor.FloorItem import kotlin.coroutines.CoroutineContext import kotlin.reflect.KClass @@ -85,5 +90,35 @@ class EventStore : CoroutineScope { } var events = EventStore() private set + val parents = Object2ObjectOpenHashMap(mapOf, List>>( + EventDispatcher::class to listOf(World::class, FloorItem::class, Character::class), + Character::class to listOf(Player::class, NPC::class) + )) } -} \ No newline at end of file +} + +@Suppress("UNCHECKED_CAST") +inline fun addEvent(noinline condition: E.(T) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(T) -> Unit) { + val dispatcher = T::class + val event = E::class + val handler = EventHandler(event, condition as Event.(EventDispatcher) -> Boolean, priority, block as suspend Event.(EventDispatcher) -> Unit) + EventStore.events.add(dispatcher, event, handler) + for (parent in EventStore.parents[dispatcher] ?: return) { + EventStore.events.add(parent, event, handler) + } +} + +inline fun on(noinline condition: E.(Player) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(Player) -> Unit) = + addEvent(condition, priority, block) + +inline fun onNPC(noinline condition: E.(NPC) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(NPC) -> Unit) = + addEvent(condition, priority, block) + +inline fun onCharacter(noinline condition: E.(Character) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(Character) -> Unit) = + addEvent(condition, priority, block) + +inline fun onFloorItem(noinline condition: E.(FloorItem) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(FloorItem) -> Unit) = + addEvent(condition, priority, block) + +inline fun onWorld(noinline condition: E.(World) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(World) -> Unit) = + addEvent(condition, priority, block) \ No newline at end of file From c7c5ebc5b2219b9765a5b75a6669c9ca5b6313bc Mon Sep 17 00:00:00 2001 From: GregHib Date: Sat, 24 Feb 2024 23:59:44 +0000 Subject: [PATCH 10/15] Tweaks --- .../gregs/voidps/engine/event/EventStore.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt index d58425ad4..ad2113aee 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt @@ -13,18 +13,16 @@ import kotlin.reflect.KClass class EventStore : CoroutineScope { override val coroutineContext: CoroutineContext = Dispatchers.Unconfined + errorHandler - private val handlers: MutableMap, MutableMap, MutableList>> = Object2ObjectOpenHashMap() + private val handlers: MutableMap> = Object2ObjectOpenHashMap() val botListeners = mutableListOf<(Event) -> Unit>() fun add(dispatcher: KClass, event: KClass, handler: EventHandler) { - handlers.getOrPut(dispatcher) { Object2ObjectOpenHashMap(2) }.getOrPut(event) { mutableListOf() }.add(handler) + handlers.getOrPut("${dispatcher.simpleName}_${event.simpleName}") { mutableListOf() }.add(handler) } fun init() { - for ((_, map) in handlers) { - for ((_, list) in map) { - list.sort() - } + for ((_, list) in handlers) { + list.sort() } } @@ -35,7 +33,7 @@ class EventStore : CoroutineScope { var all: ((Event) -> Unit)? = null fun emit(dispatcher: EventDispatcher, event: E): Boolean { - val handlers = handlers[dispatcher::class]?.get(event::class) ?: return false + val handlers = handlers["${dispatcher::class.simpleName}_${event::class.simpleName}"] ?: return false for (listener in botListeners) { listener.invoke(event) } @@ -56,7 +54,7 @@ class EventStore : CoroutineScope { } fun emit(dispatcher: EventDispatcher, event: E): Boolean { - val handlers = handlers[dispatcher::class]?.get(event::class) ?: return false + val handlers = handlers["${dispatcher::class.simpleName}_${event::class.simpleName}"] ?: return false if (handlers.none { it.condition(event, dispatcher) }) { return false } @@ -77,7 +75,7 @@ class EventStore : CoroutineScope { } fun contains(dispatcher: EventDispatcher, event: E): Boolean { - val eventHandlers = handlers[dispatcher::class]?.get(event::class) + val eventHandlers = handlers["${dispatcher::class.simpleName}_${event::class.simpleName}"] return eventHandlers != null && eventHandlers.any { it.condition(event, dispatcher) } } From 54a09bb2983d3ab169b7864b82bdf207d7267bed Mon Sep 17 00:00:00 2001 From: GregHib Date: Sun, 25 Feb 2024 00:23:09 +0000 Subject: [PATCH 11/15] Add EventStore tests --- .../gregs/voidps/engine/event/EventHandler.kt | 3 - .../gregs/voidps/engine/event/EventStore.kt | 16 +-- .../character/mode/interact/InteractTest.kt | 4 +- .../voidps/engine/event/EventStoreTest.kt | 107 ++++++++++++++++++ 4 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 engine/src/test/kotlin/world/gregs/voidps/engine/event/EventStoreTest.kt diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandler.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandler.kt index 04a0a4635..9a81cc479 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandler.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventHandler.kt @@ -1,9 +1,6 @@ package world.gregs.voidps.engine.event -import kotlin.reflect.KClass - data class EventHandler( - val event: KClass, val condition: Event.(EventDispatcher) -> Boolean = { true }, val priority: Priority = Priority.MEDIUM, val block: suspend Event.(EventDispatcher) -> Unit = {} diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt index ad2113aee..8c904972d 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt @@ -18,6 +18,9 @@ class EventStore : CoroutineScope { fun add(dispatcher: KClass, event: KClass, handler: EventHandler) { handlers.getOrPut("${dispatcher.simpleName}_${event.simpleName}") { mutableListOf() }.add(handler) + for (parent in parents[dispatcher] ?: return) { + handlers.getOrPut("${parent}_${event.simpleName}") { mutableListOf() }.add(handler) + } } fun init() { @@ -30,14 +33,11 @@ class EventStore : CoroutineScope { handlers.clear() } - var all: ((Event) -> Unit)? = null - fun emit(dispatcher: EventDispatcher, event: E): Boolean { val handlers = handlers["${dispatcher::class.simpleName}_${event::class.simpleName}"] ?: return false for (listener in botListeners) { listener.invoke(event) } - all?.invoke(event) var called = false for (handler in handlers) { if (event is CancellableEvent && event.cancelled) { @@ -88,9 +88,8 @@ class EventStore : CoroutineScope { } var events = EventStore() private set - val parents = Object2ObjectOpenHashMap(mapOf, List>>( - EventDispatcher::class to listOf(World::class, FloorItem::class, Character::class), - Character::class to listOf(Player::class, NPC::class) + private val parents = Object2ObjectOpenHashMap(mapOf( + Character::class to listOf(Player::class.simpleName, NPC::class.simpleName) )) } } @@ -99,11 +98,8 @@ class EventStore : CoroutineScope { inline fun addEvent(noinline condition: E.(T) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(T) -> Unit) { val dispatcher = T::class val event = E::class - val handler = EventHandler(event, condition as Event.(EventDispatcher) -> Boolean, priority, block as suspend Event.(EventDispatcher) -> Unit) + val handler = EventHandler(condition as Event.(EventDispatcher) -> Boolean, priority, block as suspend Event.(EventDispatcher) -> Unit) EventStore.events.add(dispatcher, event, handler) - for (parent in EventStore.parents[dispatcher] ?: return) { - EventStore.events.add(parent, event, handler) - } } inline fun on(noinline condition: E.(Player) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(Player) -> Unit) = diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/InteractTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/InteractTest.kt index 899339b6a..2dcab38ce 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/InteractTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/entity/character/mode/interact/InteractTest.kt @@ -94,7 +94,7 @@ internal class InteractTest : KoinMock() { player.mode = interact EventStore.events.clear() if (operate) { - EventStore.events.add(Player::class, NPCOption::class, EventHandler(NPCOption::class, { (this as NPCOption).operate }, block = { + EventStore.events.add(Player::class, NPCOption::class, EventHandler({ (this as NPCOption).operate }, block = { if (suspend) { this as NPCOption TickSuspension(2) @@ -103,7 +103,7 @@ internal class InteractTest : KoinMock() { })) } if (approach) { - EventStore.events.add(Player::class, NPCOption::class, EventHandler(NPCOption::class, { (this as NPCOption).approach }, block = { + EventStore.events.add(Player::class, NPCOption::class, EventHandler({ (this as NPCOption).approach }, block = { if (suspend) { this as NPCOption TickSuspension(2) diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/event/EventStoreTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/event/EventStoreTest.kt new file mode 100644 index 000000000..a90ff24a9 --- /dev/null +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/event/EventStoreTest.kt @@ -0,0 +1,107 @@ +package world.gregs.voidps.engine.event + +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import world.gregs.voidps.engine.entity.World +import world.gregs.voidps.engine.entity.character.Character +import world.gregs.voidps.engine.entity.character.player.Player +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +internal class EventStoreTest { + + private lateinit var store: EventStore + + @BeforeEach + fun setup() { + store = EventStore() + } + + private class TestEvent : Event + private class TestSuspendableEvent : SuspendableEvent + + @Test + fun `Event is emitted to handler`() { + var called = false + val handler = EventHandler(block = { + called = true + }) + store.add(World::class, TestEvent::class, handler) + store.init() + + val emitted = store.emit(World, TestEvent()) + + assertTrue(emitted) + assertTrue(called) + } + + @Test + fun `Suspendable event is emitted to handler`() { + var called = false + val handler = EventHandler(block = { + called = true + }) + store.add(World::class, TestSuspendableEvent::class, handler) + store.init() + + val event = TestSuspendableEvent() + val emitted = store.emit(World, event) + + assertTrue(emitted) + assertTrue(called) + assertTrue(store.contains(World, event)) + } + + @Test + fun `Handlers with different priorities are sorted on init`() { + var called = 0 + store.add(World::class, TestEvent::class, EventHandler(priority = Priority.HIGH, block = { + assertEquals(0, called) + called++ + })) + store.add(World::class, TestEvent::class, EventHandler(priority = Priority.LOW, block = { + assertEquals(1, called) + called++ + })) + store.init() + + val emitted = store.emit(World, TestEvent()) + + assertTrue(emitted) + assertEquals(2, called) + } + + @Test + fun `Handler with parents are emitted to all`() { + var called = false + val handler = EventHandler(block = { + called = true + }) + store.add(Player::class, TestEvent::class, handler) + store.init() + + val character: Character = Player() + val emitted = store.emit(character, TestEvent()) + + assertTrue(emitted) + assertTrue(called) + } + + @Test + fun `Clear removes all handlers`() { + var called = false + val handler = EventHandler(block = { + called = true + }) + store.add(World::class, TestSuspendableEvent::class, handler) + store.clear() + + val event = TestSuspendableEvent() + val emitted = store.emit(World, event) + + assertFalse(emitted) + assertFalse(called) + assertFalse(store.contains(World, event)) + } +} \ No newline at end of file From dbb67a6d3dea4d4a65327d0d03ccafb328b5b494 Mon Sep 17 00:00:00 2001 From: GregHib Date: Sun, 25 Feb 2024 00:53:12 +0000 Subject: [PATCH 12/15] Fix other specs --- .../player/combat/melee/special/AbyssalWhip.kts | 3 --- .../entity/player/combat/range/ammo/Ammo.kts | 13 ++++++++++++- .../player/combat/range/special/MagicShortbow.kts | 8 +++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/AbyssalWhip.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/AbyssalWhip.kts index a4e409bb6..505d1186e 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/AbyssalWhip.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/melee/special/AbyssalWhip.kts @@ -5,14 +5,11 @@ 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.event.Priority -import world.gregs.voidps.world.interact.entity.combat.attackType import world.gregs.voidps.world.interact.entity.combat.hit.block import world.gregs.voidps.world.interact.entity.combat.hit.hit import world.gregs.voidps.world.interact.entity.combat.specialAttackSwing -import world.gregs.voidps.world.interact.entity.combat.weaponSwing import world.gregs.voidps.world.interact.entity.player.combat.special.MAX_SPECIAL_ATTACK import world.gregs.voidps.world.interact.entity.player.combat.special.drainSpecialEnergy -import world.gregs.voidps.world.interact.entity.player.combat.special.specialAttack import world.gregs.voidps.world.interact.entity.player.energy.runEnergy specialAttackSwing("abyssal_whip*", priority = Priority.LOW) { player -> diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/range/ammo/Ammo.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/range/ammo/Ammo.kts index 6447d00e4..29a991c62 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/range/ammo/Ammo.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/range/ammo/Ammo.kts @@ -2,12 +2,15 @@ package world.gregs.voidps.world.interact.entity.player.combat.range.ammo import world.gregs.voidps.engine.client.message import world.gregs.voidps.engine.data.definition.AmmoDefinitions +import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.equip.equipped import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.character.player.skill.level.Level.hasUseLevel import world.gregs.voidps.engine.event.Priority import world.gregs.voidps.engine.inject import world.gregs.voidps.network.visual.update.player.EquipSlot +import world.gregs.voidps.world.interact.entity.combat.CombatSwing +import world.gregs.voidps.world.interact.entity.combat.specialAttackSwing import world.gregs.voidps.world.interact.entity.combat.weapon import world.gregs.voidps.world.interact.entity.combat.weaponSwing import world.gregs.voidps.world.interact.entity.player.combat.range.Ammo @@ -17,12 +20,20 @@ import world.gregs.voidps.world.interact.entity.player.combat.special.specialAtt val ammoDefinitions: AmmoDefinitions by inject() weaponSwing(style = "range", priority = Priority.HIGHEST) { player -> + check(player) +} + +specialAttackSwing(style = "range", priority = Priority.HIGHEST) { player -> + check(player) +} + +fun CombatSwing.check(player: Player) { if (!player.hasUseLevel(Skill.Ranged, player.weapon, message = true)) { delay = -1 player.specialAttack = false player.message("You are not high enough level to use this weapon.") player.message("You need to have a Ranged level of ${player.weapon.def.get("secondary_use_level")}.") - return@weaponSwing + return } } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/range/special/MagicShortbow.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/range/special/MagicShortbow.kts index 7a68bd331..ac637f9e7 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/range/special/MagicShortbow.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/player/combat/range/special/MagicShortbow.kts @@ -1,6 +1,5 @@ package world.gregs.voidps.world.interact.entity.player.combat.range.special -import world.gregs.voidps.engine.client.ui.chat.toInt import world.gregs.voidps.engine.entity.character.setAnimation import world.gregs.voidps.engine.entity.character.setGraphic import world.gregs.voidps.engine.entity.distanceTo @@ -12,12 +11,15 @@ import world.gregs.voidps.world.interact.entity.combat.specialAttackSwing import world.gregs.voidps.world.interact.entity.combat.weapon import world.gregs.voidps.world.interact.entity.combat.weaponSwing import world.gregs.voidps.world.interact.entity.player.combat.special.drainSpecialEnergy -import world.gregs.voidps.world.interact.entity.player.combat.special.specialAttack import world.gregs.voidps.world.interact.entity.proj.shoot import world.gregs.voidps.world.interact.entity.sound.playSound weaponSwing("magic_shortbow*", style = "range", priority = Priority.HIGHER) { player -> - player["required_ammo"] = player.specialAttack.toInt() + 1 + player["required_ammo"] = 1 +} + +specialAttackSwing("magic_shortbow*", style = "range", priority = Priority.HIGHER) { player -> + player["required_ammo"] = 2 } specialAttackSwing("magic_shortbow*", style = "range", priority = Priority.MEDIUM) { player -> From c25704403e924e89513f06aa6b478684f8d509c3 Mon Sep 17 00:00:00 2001 From: GregHib Date: Sun, 25 Feb 2024 00:53:46 +0000 Subject: [PATCH 13/15] Remove bot event queue --- .../world/gregs/voidps/engine/event/EventStore.kt | 10 +++++----- .../main/kotlin/world/gregs/voidps/bot/BotSpawns.kts | 11 ++++------- .../kotlin/world/gregs/voidps/bot/DecisionMaking.kts | 7 ------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt index 8c904972d..030bcc58c 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/event/EventStore.kt @@ -14,7 +14,7 @@ import kotlin.reflect.KClass class EventStore : CoroutineScope { override val coroutineContext: CoroutineContext = Dispatchers.Unconfined + errorHandler private val handlers: MutableMap> = Object2ObjectOpenHashMap() - val botListeners = mutableListOf<(Event) -> Unit>() + var all: ((Player, Event) -> Unit)? = null fun add(dispatcher: KClass, event: KClass, handler: EventHandler) { handlers.getOrPut("${dispatcher.simpleName}_${event.simpleName}") { mutableListOf() }.add(handler) @@ -35,8 +35,8 @@ class EventStore : CoroutineScope { fun emit(dispatcher: EventDispatcher, event: E): Boolean { val handlers = handlers["${dispatcher::class.simpleName}_${event::class.simpleName}"] ?: return false - for (listener in botListeners) { - listener.invoke(event) + if (dispatcher is Player && dispatcher.contains("bot")) { + all?.invoke(dispatcher, event) } var called = false for (handler in handlers) { @@ -58,8 +58,8 @@ class EventStore : CoroutineScope { if (handlers.none { it.condition(event, dispatcher) }) { return false } - for (listener in botListeners) { - listener.invoke(event) + if (dispatcher is Player && dispatcher.contains("bot")) { + all?.invoke(dispatcher, event) } launch { for (handler in handlers) { diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts b/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts index 01865f577..c02befc4b 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts @@ -28,7 +28,6 @@ import world.gregs.voidps.network.client.DummyClient import world.gregs.voidps.network.visual.update.player.BodyColour import world.gregs.voidps.network.visual.update.player.BodyPart import world.gregs.voidps.type.random -import java.util.concurrent.ConcurrentLinkedQueue import java.util.concurrent.TimeUnit import kotlin.coroutines.resume import kotlin.reflect.KClass @@ -50,6 +49,9 @@ worldSpawn { if (botCount > 0) { World.timers.start("bot_spawn") } + EventStore.events.all = { player, event -> + handleSuspensions(player, event) + } } worldTimerStart("bot_spawn") { @@ -116,18 +118,13 @@ fun spawn() { fun Player.initBot(): Bot { val bot = Bot(this) this["bot"] = bot - val e = ConcurrentLinkedQueue() - this["events"] = e - EventStore.events.botListeners.add { event -> - e.add(event) - handleSuspensions(bot.player, event) - } return bot } fun handleSuspensions(player: Player, event: Event) { val suspensions: MutableMap, Pair Boolean, CancellableContinuation>> = player["bot_suspensions"] ?: return val pair = suspensions[event::class] ?: return + println("Suspensions $pair") val (condition, continuation) = pair if (condition(event, player)) { suspensions.remove(event::class) diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts b/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts index db92dc6bd..847b3b835 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts @@ -7,10 +7,8 @@ import world.gregs.voidps.bot.navigation.resume import world.gregs.voidps.engine.Contexts import world.gregs.voidps.engine.entity.AiTick import world.gregs.voidps.engine.entity.character.player.Players -import world.gregs.voidps.engine.event.Event import world.gregs.voidps.engine.event.onWorld import world.gregs.voidps.engine.inject -import java.util.concurrent.ConcurrentLinkedQueue val players: Players by inject() val tasks: TaskManager by inject() @@ -35,11 +33,6 @@ onWorld { if (!bot.contains("task")) { assign(bot, tasks.assign(bot)) } - val events: ConcurrentLinkedQueue = player["events"]!! - while (events.isNotEmpty()) { - val event = events.poll() - bot.emit(event) - } bot.resume("tick") } } From f0ec1459bfc482cc87de4ab0e13a1934aa82c1d1 Mon Sep 17 00:00:00 2001 From: GregHib Date: Sun, 25 Feb 2024 01:14:39 +0000 Subject: [PATCH 14/15] Remove onBot in favour of normal script helpers --- .../main/kotlin/world/gregs/voidps/bot/Bot.kt | 11 +----- .../world/gregs/voidps/bot/BotSpawns.kts | 1 - .../kotlin/world/gregs/voidps/bot/Bots.kt | 3 ++ .../world/gregs/voidps/bot/DecisionMaking.kts | 14 ++++--- .../kotlin/world/gregs/voidps/bot/Task.kt | 5 ++- .../world/gregs/voidps/bot/TaskManager.kt | 4 +- .../world/gregs/voidps/bot/WalkingBot.kts | 8 ++-- .../world/gregs/voidps/bot/bank/BankBot.kts | 11 ++++-- .../voidps/bot/navigation/Navigation.kts | 23 +++++++---- .../world/gregs/voidps/bot/shop/ShopBot.kts | 11 ++++-- .../world/gregs/voidps/bot/skill/SkillBot.kts | 7 ++-- .../voidps/bot/skill/combat/CombatBot.kts | 39 ++++++++++--------- .../voidps/bot/skill/combat/TrainingBot.kts | 8 ++-- .../voidps/bot/skill/cooking/CookingBot.kts | 18 +++++---- .../bot/skill/firemaking/FiremakingBot.kts | 25 ++++++------ .../voidps/bot/skill/fishing/FishingBot.kts | 16 ++++---- .../voidps/bot/skill/mining/MiningBot.kts | 16 ++++---- .../skill/runecrafting/RunecraftingBot.kts | 13 +++---- .../voidps/bot/skill/smithing/SmeltingBot.kts | 16 ++++---- .../voidps/bot/skill/smithing/SmithingBot.kts | 16 ++++---- .../bot/skill/woodcutting/WoodcuttingBot.kts | 16 ++++---- 21 files changed, 149 insertions(+), 132 deletions(-) diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/Bot.kt b/game/src/main/kotlin/world/gregs/voidps/bot/Bot.kt index 3d739058b..9f9f56b6d 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/Bot.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/Bot.kt @@ -2,17 +2,8 @@ package world.gregs.voidps.bot import world.gregs.voidps.engine.entity.character.Character import world.gregs.voidps.engine.entity.character.player.Player -import world.gregs.voidps.engine.event.Event -import world.gregs.voidps.engine.event.Priority -import world.gregs.voidps.engine.event.addEvent import world.gregs.voidps.network.Instruction data class Bot(val player: Player) : Character by player { - var step: Instruction? = null - -} - -@JvmName("onBot") -inline fun onBot(noinline condition: E.(Bot) -> Boolean = { true }, priority: Priority = Priority.MEDIUM, noinline block: suspend E.(Bot) -> Unit) = - addEvent(condition, priority, block) \ No newline at end of file +} \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts b/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts index c02befc4b..4d954a46c 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/BotSpawns.kts @@ -124,7 +124,6 @@ fun Player.initBot(): Bot { fun handleSuspensions(player: Player, event: Event) { val suspensions: MutableMap, Pair Boolean, CancellableContinuation>> = player["bot_suspensions"] ?: return val pair = suspensions[event::class] ?: return - println("Suspensions $pair") val (condition, continuation) = pair if (condition(event, player)) { suspensions.remove(event::class) diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/Bots.kt b/game/src/main/kotlin/world/gregs/voidps/bot/Bots.kt index a970365e3..99eeb9de9 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/Bots.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/Bots.kt @@ -29,6 +29,9 @@ import world.gregs.voidps.world.activity.bank.bank val Player.isBot: Boolean get() = contains("bot") +val Player.bot: Bot + get() = get("bot")!! + fun Bot.hasCoins(amount: Int, bank: Boolean = true): Boolean { if (player.inventory.contains("coins") && player.inventory.count("coins") >= amount) { return true diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts b/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts index 847b3b835..3df462610 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/DecisionMaking.kts @@ -6,7 +6,9 @@ import kotlinx.coroutines.launch import world.gregs.voidps.bot.navigation.resume import world.gregs.voidps.engine.Contexts import world.gregs.voidps.engine.entity.AiTick +import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.engine.entity.character.player.Players +import world.gregs.voidps.engine.event.on import world.gregs.voidps.engine.event.onWorld import world.gregs.voidps.engine.inject @@ -16,7 +18,7 @@ val tasks: TaskManager by inject() val scope = CoroutineScope(Contexts.Game) val logger = InlineLogger("Bot") -onBot({ it.contains("task") && !it.contains("task_started") }) { bot: Bot -> +on({ it.contains("task") && !it.contains("task_started") }) { bot -> val name: String = bot["task"]!! val task = tasks.get(name) if (task == null) { @@ -31,16 +33,16 @@ onWorld { if (player.isBot) { val bot: Bot = player["bot"]!! if (!bot.contains("task")) { - assign(bot, tasks.assign(bot)) + assign(player, tasks.assign(bot)) } - bot.resume("tick") + player.bot.resume("tick") } } } -fun assign(bot: Bot, task: Task) { +fun assign(bot: Player, task: Task) { if (bot["debug", false]) { - logger.debug { "Task assigned: ${bot.player.accountName} - ${task.name}" } + logger.debug { "Task assigned: ${bot.accountName} - ${task.name}" } } bot["task"] = task.name bot["task_started"] = true @@ -49,7 +51,7 @@ fun assign(bot: Bot, task: Task) { try { task.block.invoke(bot) } catch (t: Throwable) { - logger.warn(t) { "Task cancelled for ${bot.player}" } + logger.warn(t) { "Task cancelled for $bot" } } bot.clear("task") task.spaces++ diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/Task.kt b/game/src/main/kotlin/world/gregs/voidps/bot/Task.kt index e4185470b..97cbb6c62 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/Task.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/Task.kt @@ -1,14 +1,15 @@ package world.gregs.voidps.bot +import world.gregs.voidps.engine.entity.character.player.Player import world.gregs.voidps.type.Tile import world.gregs.voidps.type.Area data class Task( val name: String, - val block: suspend Bot.() -> Unit, + val block: suspend Player.() -> Unit, val area: Area? = null, var spaces: Int = 1, - val requirements: Collection Boolean> = emptySet() + val requirements: Collection Boolean> = emptySet() ) { fun full() = spaces <= 0 diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/TaskManager.kt b/game/src/main/kotlin/world/gregs/voidps/bot/TaskManager.kt index 8b7fb82d6..cc044981a 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/TaskManager.kt +++ b/game/src/main/kotlin/world/gregs/voidps/bot/TaskManager.kt @@ -20,7 +20,7 @@ class TaskManager { fun assign(bot: Bot): Task { return queue - .filter { !it.full() && it.requirements.all { req -> req(bot) } } + .filter { !it.full() && it.requirements.all { req -> req(bot.player) } } .minByOrNull { it.distanceTo(bot.tile) } ?: idle } @@ -29,7 +29,7 @@ class TaskManager { name = "do nothing", block = { repeat(random.nextInt(10, 100)) { - await("tick") + bot.await("tick") } }, spaces = Int.MAX_VALUE diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/WalkingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/WalkingBot.kts index d5ff5bae9..29275ee00 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/WalkingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/WalkingBot.kts @@ -12,10 +12,10 @@ worldSpawn { name = "walk randomly", block = { while (true) { - val tile = player.tile.toCuboid(10).random() -// clickInterface(271, 8, 0, itemSlot = 19) - player.instructions.emit(Walk(tile.x, tile.y)) - await("tick") + val tile = tile.toCuboid(10).random() +// bot.clickInterface(271, 8, 0, itemSlot = 19) + instructions.emit(Walk(tile.x, tile.y)) + bot.await("tick") } }, area = null, diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/bank/BankBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/bank/BankBot.kts index 57ce5e5d1..265d55317 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/bank/BankBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/bank/BankBot.kts @@ -1,9 +1,12 @@ package world.gregs.voidps.bot.bank +import world.gregs.voidps.bot.bot +import world.gregs.voidps.bot.isBot import world.gregs.voidps.bot.navigation.resume -import world.gregs.voidps.bot.onBot -import world.gregs.voidps.engine.client.ui.event.InterfaceOpened +import world.gregs.voidps.engine.client.ui.event.interfaceOpen -onBot({ id == "bank" }) { bot -> - bot.resume("bank") +interfaceOpen("bank") { player -> + if (player.isBot) { + player.bot.resume("bank") + } } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/navigation/Navigation.kts b/game/src/main/kotlin/world/gregs/voidps/bot/navigation/Navigation.kts index 984cb1817..6c6a70ef1 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/navigation/Navigation.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/navigation/Navigation.kts @@ -1,21 +1,28 @@ package world.gregs.voidps.bot.navigation -import world.gregs.voidps.bot.Bot -import world.gregs.voidps.bot.onBot +import world.gregs.voidps.bot.bot +import world.gregs.voidps.bot.isBot import world.gregs.voidps.engine.entity.character.mode.EmptyMode import world.gregs.voidps.engine.entity.character.mode.move.Moved import world.gregs.voidps.engine.entity.character.mode.move.Movement +import world.gregs.voidps.engine.event.on import world.gregs.voidps.world.interact.entity.obj.Teleport import world.gregs.voidps.world.interact.entity.obj.door.DoorOpened -onBot({ (it.player.mode is Movement && it.player.steps.size <= 1) || it.player.mode == EmptyMode }) { bot: Bot -> - bot.resume("move") +on({ (player.mode is Movement && player.steps.size <= 1) || player.mode == EmptyMode }) { player -> + if (player.isBot) { + player.bot.resume("move") + } } -onBot { bot -> - bot.resume("move") +on { player -> + if (player.isBot) { + player.bot.resume("move") + } } -onBot { bot -> - bot.resume("move") +on { player -> + if (player.isBot) { + player.bot.resume("move") + } } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/shop/ShopBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/shop/ShopBot.kts index 3a144818c..e599b28b5 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/shop/ShopBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/shop/ShopBot.kts @@ -1,9 +1,12 @@ package world.gregs.voidps.bot.shop +import world.gregs.voidps.bot.bot +import world.gregs.voidps.bot.isBot import world.gregs.voidps.bot.navigation.resume -import world.gregs.voidps.bot.onBot -import world.gregs.voidps.engine.client.ui.event.InterfaceOpened +import world.gregs.voidps.engine.client.ui.event.interfaceOpen -onBot({ id == "shop" }) { bot -> - bot.resume("shop") +interfaceOpen("shop") { player -> + if (player.isBot) { + player.bot.resume("shop") + } } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/SkillBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/SkillBot.kts index 1da256727..01bc666b4 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/SkillBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/SkillBot.kts @@ -1,9 +1,8 @@ package world.gregs.voidps.bot.skill -import world.gregs.voidps.bot.onBot -import world.gregs.voidps.engine.client.ui.event.InterfaceOpened +import world.gregs.voidps.engine.client.ui.event.interfaceOpen import world.gregs.voidps.network.instruct.InteractDialogue -onBot({ id == "dialogue_level_up" }) { bot -> - bot.player.instructions.tryEmit(InteractDialogue(interfaceId = 740, componentId = 3, option = -1)) +interfaceOpen("dialogue_level_up") { bot -> + bot.instructions.tryEmit(InteractDialogue(interfaceId = 740, componentId = 3, option = -1)) } \ No newline at end of file diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/CombatBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/CombatBot.kts index 8846f3885..fca5de1f2 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/CombatBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/CombatBot.kts @@ -4,13 +4,10 @@ import net.pearx.kasechange.toLowerSpaceCase import net.pearx.kasechange.toSnakeCase import world.gregs.voidps.bot.* import world.gregs.voidps.bot.item.pickup -import world.gregs.voidps.bot.navigation.await -import world.gregs.voidps.bot.navigation.cancel -import world.gregs.voidps.bot.navigation.goToArea -import world.gregs.voidps.bot.navigation.resume +import world.gregs.voidps.bot.navigation.* import world.gregs.voidps.engine.client.ui.chat.toIntRange import world.gregs.voidps.engine.client.update.view.Viewport -import world.gregs.voidps.engine.client.variable.VariableSet +import world.gregs.voidps.engine.client.variable.variableSet import world.gregs.voidps.engine.data.definition.AmmoDefinitions import world.gregs.voidps.engine.data.definition.AreaDefinition import world.gregs.voidps.engine.data.definition.AreaDefinitions @@ -25,6 +22,7 @@ import world.gregs.voidps.engine.entity.character.player.skill.level.Level.hasRe import world.gregs.voidps.engine.entity.distanceTo import world.gregs.voidps.engine.entity.item.floor.FloorItems import world.gregs.voidps.engine.entity.worldSpawn +import world.gregs.voidps.engine.event.on import world.gregs.voidps.engine.get import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.inventory @@ -32,8 +30,8 @@ import world.gregs.voidps.network.visual.update.player.EquipSlot import world.gregs.voidps.type.Tile import world.gregs.voidps.type.random import world.gregs.voidps.world.activity.skill.slayer.race -import world.gregs.voidps.world.interact.entity.combat.CombatSwing import world.gregs.voidps.world.interact.entity.combat.attackers +import world.gregs.voidps.world.interact.entity.combat.combatSwing import world.gregs.voidps.world.interact.entity.combat.underAttack import world.gregs.voidps.world.interact.entity.death.Death import world.gregs.voidps.world.interact.entity.death.weightedSample @@ -44,21 +42,24 @@ val areas: AreaDefinitions by inject() val tasks: TaskManager by inject() val floorItems: FloorItems by inject() -onBot({ key == "under_attack" && to == 0 }) { bot -> - bot.resume("combat") +variableSet("under_attack", 1) { player -> + if (player.isBot) { + player.bot.resume("combat") + } } -onBot { bot -> - val player = bot.player +combatSwing { player -> if (player.levels.getPercent(Skill.Constitution) < 50.0) { - val food = player.inventory.items.firstOrNull { it.def.contains("heals") } ?: return@onBot - bot.inventoryOption(food.id, "Eat") + val food = player.inventory.items.firstOrNull { it.def.contains("heals") } ?: return@combatSwing + player.bot.inventoryOption(food.id, "Eat") } } -onBot { bot -> - bot.clear("area") - bot.cancel() +on { player -> + if(player.isBot) { + player.clear("area") + player.bot.cancel() + } } worldSpawn { @@ -71,15 +72,15 @@ worldSpawn { val task = Task( name = "train ${skill.name} killing ${types.joinToString(", ")} at ${area.name}".toLowerSpaceCase(), block = { - while (player.levels.getMax(skill) < range.last + 1) { - fight(area, skill, types) + while (levels.getMax(skill) < range.last + 1) { + bot.fight(area, skill, types) } }, area = area.area, spaces = 1, requirements = listOf( - { player.levels.getMax(skill) in range }, - { hasExactGear(skill) || hasCoins(2000) } + { levels.getMax(skill) in range }, + { bot.hasExactGear(skill) || bot.hasCoins(2000) } ) ) tasks.register(task) diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/TrainingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/TrainingBot.kts index 4dc8a4306..bdaaedfa7 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/TrainingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/combat/TrainingBot.kts @@ -45,14 +45,14 @@ worldSpawn { val task = Task( name = "train ${if (melee) "melee" else skill.name} at ${area.name}".toLowerSpaceCase(), block = { - val actualSkill = if (melee) melees.filter { player.levels.getMax(it) in range }.random() else skill - train(area, actualSkill, range) + val actualSkill = if (melee) melees.filter { levels.getMax(it) in range }.random() else skill + bot.train(area, actualSkill, range) }, area = area.area, spaces = if (melee) 3 else 2, requirements = listOf( - { if (melee) melees.any { player.levels.getMax(it) in range } else player.levels.getMax(skill) in range }, - { canGetGearAndAmmo(skill) } + { if (melee) melees.any { levels.getMax(it) in range } else levels.getMax(skill) in range }, + { bot.canGetGearAndAmmo(skill) } ) ) tasks.register(task) diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/cooking/CookingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/cooking/CookingBot.kts index 21b566c6e..7dec0000f 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/cooking/CookingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/cooking/CookingBot.kts @@ -19,15 +19,17 @@ import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.worldSpawn import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.inventory -import world.gregs.voidps.engine.timer.TimerStop +import world.gregs.voidps.engine.timer.timerStop import world.gregs.voidps.network.instruct.InteractDialogue import world.gregs.voidps.network.instruct.InteractInterfaceObject val areas: AreaDefinitions by inject() val tasks: TaskManager by inject() -onBot({ timer == "cooking" }) { bot -> - bot.resume(timer) +timerStop("cooking") { player -> + if (player.isBot) { + player.bot.resume(timer) + } } worldSpawn { @@ -37,15 +39,15 @@ worldSpawn { val task = Task( name = "cook on ${type.plural(2)} at ${area.name}".toLowerSpaceCase(), block = { - val gear = getGear(Skill.Cooking) ?: return@Task - val item = getSuitableItem(gear.inventory.first()) - while (player.levels.getMax(Skill.Cooking) < gear.levels.last + 1) { - cook(area, item, gear) + val gear = bot.getGear(Skill.Cooking) ?: return@Task + val item = bot.getSuitableItem(gear.inventory.first()) + while (levels.getMax(Skill.Cooking) < gear.levels.last + 1) { + bot.cook(area, item, gear) } }, area = area.area, spaces = spaces, - requirements = listOf { hasExactGear(Skill.Cooking) } + requirements = listOf { bot.hasExactGear(Skill.Cooking) } ) tasks.register(task) } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/firemaking/FiremakingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/firemaking/FiremakingBot.kts index 5152a89f9..322e2bddd 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/firemaking/FiremakingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/firemaking/FiremakingBot.kts @@ -1,13 +1,10 @@ package world.gregs.voidps.bot.skill.firemaking import net.pearx.kasechange.toLowerSpaceCase -import world.gregs.voidps.bot.Bot -import world.gregs.voidps.bot.Task -import world.gregs.voidps.bot.TaskManager +import world.gregs.voidps.bot.* import world.gregs.voidps.bot.navigation.await import world.gregs.voidps.bot.navigation.goToArea import world.gregs.voidps.bot.navigation.resume -import world.gregs.voidps.bot.onBot import world.gregs.voidps.bot.skill.combat.getGear import world.gregs.voidps.bot.skill.combat.getSuitableItem import world.gregs.voidps.bot.skill.combat.hasExactGear @@ -22,15 +19,17 @@ import world.gregs.voidps.engine.entity.obj.ObjectLayer import world.gregs.voidps.engine.entity.worldSpawn import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.inventory -import world.gregs.voidps.engine.timer.TimerStop +import world.gregs.voidps.engine.timer.timerStop import world.gregs.voidps.network.instruct.InteractInterfaceItem val areas: AreaDefinitions by inject() val tasks: TaskManager by inject() val objects: GameObjects by inject() -onBot({ timer == "firemaking" }) { bot -> - bot.resume(timer) +timerStop("firemaking") { player -> + if (player.isBot) { + player.bot.resume(timer) + } } worldSpawn { @@ -39,16 +38,16 @@ worldSpawn { val task = Task( name = "make fires at ${area.name}".toLowerSpaceCase(), block = { - val gear = getGear(Skill.Firemaking) ?: return@Task - val lighter = getSuitableItem(gear.inventory.first()) - val logs = getSuitableItem(gear.inventory.last()) - while (player.levels.getMax(Skill.Firemaking) < gear.levels.last + 1) { - light(area, lighter, logs) + val gear = bot.getGear(Skill.Firemaking) ?: return@Task + val lighter = bot.getSuitableItem(gear.inventory.first()) + val logs = bot.getSuitableItem(gear.inventory.last()) + while (levels.getMax(Skill.Firemaking) < gear.levels.last + 1) { + bot.light(area, lighter, logs) } }, area = area.area, spaces = spaces, - requirements = listOf { hasExactGear(Skill.Firemaking) } + requirements = listOf { bot.hasExactGear(Skill.Firemaking) } ) tasks.register(task) } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/fishing/FishingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/fishing/FishingBot.kts index 85537de82..8dcc969b1 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/fishing/FishingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/fishing/FishingBot.kts @@ -26,7 +26,7 @@ import world.gregs.voidps.engine.get import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.holdsItem import world.gregs.voidps.engine.inv.inventory -import world.gregs.voidps.engine.timer.TimerStop +import world.gregs.voidps.engine.timer.timerStop import world.gregs.voidps.network.instruct.InteractNPC import world.gregs.voidps.world.interact.entity.death.weightedSample @@ -34,8 +34,10 @@ val areas: AreaDefinitions by inject() val tasks: TaskManager by inject() val gear: GearDefinitions by inject() -onBot({ timer == "fishing" }) { bot -> - bot.resume(timer) +timerStop("fishing") { player -> + if (player.isBot) { + player.bot.resume(timer) + } } worldSpawn { @@ -49,15 +51,15 @@ worldSpawn { val task = Task( name = "fish ${type.plural(2)} at ${area.name}".toLowerSpaceCase(), block = { - while (player.levels.getMax(Skill.Fishing) < set.levels.last + 1) { - fish(area, option, bait, set) + while (levels.getMax(Skill.Fishing) < set.levels.last + 1) { + bot.fish(area, option, bait, set) } }, area = area.area, spaces = spaces, requirements = listOf( - { player.levels.getMax(Skill.Fishing) in set.levels }, - { hasExactGear(set) || hasCoins(2000) } + { levels.getMax(Skill.Fishing) in set.levels }, + { bot.hasExactGear(set) || bot.hasCoins(2000) } ) ) tasks.register(task) diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/mining/MiningBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/mining/MiningBot.kts index 7fb5f8ff3..5924b67d5 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/mining/MiningBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/mining/MiningBot.kts @@ -19,15 +19,17 @@ import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.worldSpawn import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.inventory -import world.gregs.voidps.engine.timer.TimerStop +import world.gregs.voidps.engine.timer.timerStop import world.gregs.voidps.network.instruct.InteractObject import world.gregs.voidps.world.interact.entity.death.weightedSample val areas: AreaDefinitions by inject() val tasks: TaskManager by inject() -onBot({ timer == "mining" }) { bot -> - bot.resume(timer) +timerStop("mining") { player -> + if (player.isBot) { + player.bot.resume(timer) + } } worldSpawn { @@ -38,15 +40,15 @@ worldSpawn { val task = Task( name = "mine ${type.plural(2)} at ${area.name}".toLowerSpaceCase(), block = { - while (player.levels.getMax(Skill.Mining) < range.last + 1) { - mineRocks(area, type) + while (levels.getMax(Skill.Mining) < range.last + 1) { + bot.mineRocks(area, type) } }, area = area.area, spaces = spaces, requirements = listOf( - { player.levels.getMax(Skill.Mining) in range }, - { hasExactGear(Skill.Woodcutting) || hasCoins(1000) } + { levels.getMax(Skill.Mining) in range }, + { bot.hasExactGear(Skill.Woodcutting) || bot.hasCoins(1000) } ) ) tasks.register(task) diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/runecrafting/RunecraftingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/runecrafting/RunecraftingBot.kts index cfb4166c5..6f5dd6cfc 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/runecrafting/RunecraftingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/runecrafting/RunecraftingBot.kts @@ -1,9 +1,6 @@ package world.gregs.voidps.bot.skill.runecrafting -import world.gregs.voidps.bot.Bot -import world.gregs.voidps.bot.Task -import world.gregs.voidps.bot.TaskManager -import world.gregs.voidps.bot.getObjects +import world.gregs.voidps.bot.* import world.gregs.voidps.bot.navigation.await import world.gregs.voidps.bot.navigation.awaitInteract import world.gregs.voidps.bot.navigation.goToArea @@ -29,15 +26,15 @@ worldSpawn { val task = Task( name = "craft $type runes at ${area.name}", block = { - while (player.levels.getMax(Skill.Runecrafting) < range.last + 1) { - craftRunes(area) + while (levels.getMax(Skill.Runecrafting) < range.last + 1) { + bot.craftRunes(area) } }, area = area.area, spaces = spaces, requirements = listOf( - { player.levels.getMax(Skill.Runecrafting) in range }, - { hasExactGear(Skill.Runecrafting) } + { levels.getMax(Skill.Runecrafting) in range }, + { bot.hasExactGear(Skill.Runecrafting) } ) ) tasks.register(task) diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmeltingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmeltingBot.kts index 1755ea6f3..bd9993cc8 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmeltingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmeltingBot.kts @@ -18,7 +18,7 @@ import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.worldSpawn import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.inventory -import world.gregs.voidps.engine.timer.TimerStop +import world.gregs.voidps.engine.timer.timerStop import world.gregs.voidps.network.instruct.InteractDialogue import world.gregs.voidps.world.activity.skill.smithing.oreToBar @@ -26,8 +26,10 @@ val areas: AreaDefinitions by inject() val tasks: TaskManager by inject() val itemDefinitions: ItemDefinitions by inject() -onBot({ timer == "smelting" }) { bot -> - bot.resume(timer) +timerStop("smelting") { player -> + if (player.isBot) { + player.bot.resume(timer) + } } worldSpawn { @@ -36,14 +38,14 @@ worldSpawn { val task = Task( name = "smelt bars at ${area.name}".toLowerSpaceCase(), block = { - val gear = getGear("smelting", Skill.Smithing) ?: return@Task - while (player.levels.getMax(Skill.Smithing) < gear.levels.last + 1) { - smelt(area, gear) + val gear = bot.getGear("smelting", Skill.Smithing) ?: return@Task + while (levels.getMax(Skill.Smithing) < gear.levels.last + 1) { + bot.smelt(area, gear) } }, area = area.area, spaces = spaces, - requirements = listOf { hasExactGear("smelting", Skill.Smithing) } + requirements = listOf { bot.hasExactGear("smelting", Skill.Smithing) } ) tasks.register(task) } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmithingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmithingBot.kts index 3c43031f3..8aab057f0 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmithingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/smithing/SmithingBot.kts @@ -22,15 +22,17 @@ import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.worldSpawn import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.inventory -import world.gregs.voidps.engine.timer.TimerStop +import world.gregs.voidps.engine.timer.timerStop val interfaceDefinitions: InterfaceDefinitions by inject() val itemDefinitions: ItemDefinitions by inject() val areas: AreaDefinitions by inject() val tasks: TaskManager by inject() -onBot({ timer == "smithing" }) { bot -> - bot.resume(timer) +timerStop("smithing") { player -> + if (player.isBot) { + player.bot.resume(timer) + } } worldSpawn { @@ -39,15 +41,15 @@ worldSpawn { val task = Task( name = "smith on anvil at ${area.name}".toLowerSpaceCase(), block = { - val gear = getGear(Skill.Smithing) ?: return@Task + val gear = bot.getGear(Skill.Smithing) ?: return@Task val types: List = gear.getOrNull("types") ?: return@Task - while (player.levels.getMax(Skill.Smithing) < gear.levels.last + 1) { - smith(area, types, gear) + while (levels.getMax(Skill.Smithing) < gear.levels.last + 1) { + bot.smith(area, types, gear) } }, area = area.area, spaces = spaces, - requirements = listOf { hasExactGear(Skill.Smithing) } + requirements = listOf { bot.hasExactGear(Skill.Smithing) } ) tasks.register(task) } diff --git a/game/src/main/kotlin/world/gregs/voidps/bot/skill/woodcutting/WoodcuttingBot.kts b/game/src/main/kotlin/world/gregs/voidps/bot/skill/woodcutting/WoodcuttingBot.kts index aadacb404..619a9dc86 100644 --- a/game/src/main/kotlin/world/gregs/voidps/bot/skill/woodcutting/WoodcuttingBot.kts +++ b/game/src/main/kotlin/world/gregs/voidps/bot/skill/woodcutting/WoodcuttingBot.kts @@ -18,15 +18,17 @@ import world.gregs.voidps.engine.entity.obj.GameObject import world.gregs.voidps.engine.entity.worldSpawn import world.gregs.voidps.engine.inject import world.gregs.voidps.engine.inv.inventory -import world.gregs.voidps.engine.timer.TimerStop +import world.gregs.voidps.engine.timer.timerStop import world.gregs.voidps.network.instruct.InteractObject import world.gregs.voidps.world.interact.entity.death.weightedSample val areas: AreaDefinitions by inject() val tasks: TaskManager by inject() -onBot({ timer == "woodcutting" }) { bot -> - bot.resume(timer) +timerStop("woodcutting") { player -> + if (player.isBot) { + player.bot.resume(timer) + } } worldSpawn { @@ -37,15 +39,15 @@ worldSpawn { val task = Task( name = "cut ${(type ?: "tree").plural(2).lowercase()} at ${area.name}", block = { - while (player.levels.getMax(Skill.Woodcutting) < range.last + 1) { - cutTrees(area, type) + while (levels.getMax(Skill.Woodcutting) < range.last + 1) { + bot.cutTrees(area, type) } }, area = area.area, spaces = spaces, requirements = listOf( - { player.levels.getMax(Skill.Woodcutting) in range }, - { hasExactGear(Skill.Woodcutting) || hasCoins(1000) } + { levels.getMax(Skill.Woodcutting) in range }, + { bot.hasExactGear(Skill.Woodcutting) || bot.hasCoins(1000) } ) ) tasks.register(task) From 94758afe7c7ebf5da37325e9ac1bc6ef717f682d Mon Sep 17 00:00:00 2001 From: GregHib Date: Sun, 25 Feb 2024 01:20:01 +0000 Subject: [PATCH 15/15] Version 1.1.6 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 50a85979f..86853b347 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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