From 12eaa1e05a4368a33119ae0ec6080f18f0138e78 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Fri, 1 Sep 2023 12:29:12 +0000 Subject: [PATCH] Fixed antipoison not working in some scenarios Added new ::timers admin command --- .../data/consumables/effects/AddTimerEffect.kt | 2 ++ Server/src/main/core/api/ContentAPI.kt | 3 +++ .../game/system/command/sets/DevelopmentCommandSet.kt | 11 +++++++++++ Server/src/main/core/game/system/timer/impl/Poison.kt | 4 ---- .../content/familiar/special/BloodDrainTests.kt | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Server/src/main/content/data/consumables/effects/AddTimerEffect.kt b/Server/src/main/content/data/consumables/effects/AddTimerEffect.kt index 29167ee1e..d21985101 100644 --- a/Server/src/main/content/data/consumables/effects/AddTimerEffect.kt +++ b/Server/src/main/content/data/consumables/effects/AddTimerEffect.kt @@ -1,12 +1,14 @@ package content.data.consumables.effects import core.api.registerTimer +import core.api.removeTimer import core.api.spawnTimer import core.game.consumable.ConsumableEffect import core.game.node.entity.player.Player class AddTimerEffect (val identifier: String, vararg val args: Any) : ConsumableEffect() { override fun activate (p: Player) { + removeTimer (p, identifier) val timer = spawnTimer (identifier, *args) ?: return registerTimer (p, timer) } diff --git a/Server/src/main/core/api/ContentAPI.kt b/Server/src/main/core/api/ContentAPI.kt index 032b7647b..012eb21b6 100644 --- a/Server/src/main/core/api/ContentAPI.kt +++ b/Server/src/main/core/api/ContentAPI.kt @@ -2831,6 +2831,9 @@ fun isStunned(entity: Entity) : Boolean { * @see To those whe ask "why severity instead of plain damage?" to which the answer is: severity is how it works authentically, and allows for scenarios where, e.g. a poison should hit 6 once, and then drop to 5 immediately. **/ fun applyPoison (entity: Entity, source: Entity, severity: Int) { + if(hasTimerActive(entity)) { + return + } val existingTimer = getTimer(entity) if (existingTimer != null) { diff --git a/Server/src/main/core/game/system/command/sets/DevelopmentCommandSet.kt b/Server/src/main/core/game/system/command/sets/DevelopmentCommandSet.kt index f32d5945f..0730bfca9 100644 --- a/Server/src/main/core/game/system/command/sets/DevelopmentCommandSet.kt +++ b/Server/src/main/core/game/system/command/sets/DevelopmentCommandSet.kt @@ -279,5 +279,16 @@ class DevelopmentCommandSet : CommandSet(Privilege.ADMIN) { val id = args[1].toIntOrNull() ?: 9804 player.dialogueInterpreter.sendDialogues(player, id, "Expression ID: $id") } + + define("timers", Privilege.ADMIN, "::timers", "Print out timers") { player, args -> + player.sendMessage("Active timers:") + for(timer in player.timers.activeTimers) { + player.sendMessage(" ${timer.identifier} ${timer.nextExecution}") + } + player.sendMessage("New timers:") + for(timer in player.timers.newTimers) { + player.sendMessage(" ${timer.identifier}") + } + } } } diff --git a/Server/src/main/core/game/system/timer/impl/Poison.kt b/Server/src/main/core/game/system/timer/impl/Poison.kt index 882b5d776..2f4c58cf9 100644 --- a/Server/src/main/core/game/system/timer/impl/Poison.kt +++ b/Server/src/main/core/game/system/timer/impl/Poison.kt @@ -40,10 +40,6 @@ class Poison : PersistTimer (30, "poison", flags = arrayOf(TimerFlag.ClearOnDeat } override fun onRegister (entity: Entity) { - if (hasTimerActive(entity)) { - removeTimer(entity) - return - } if (entity is Player) { sendMessage(entity, "You have been poisoned.") entity.debug ("[Poison] -> Received for $severity severity.") diff --git a/Server/src/test/kotlin/content/familiar/special/BloodDrainTests.kt b/Server/src/test/kotlin/content/familiar/special/BloodDrainTests.kt index 93d585e3f..9bdc4584c 100644 --- a/Server/src/test/kotlin/content/familiar/special/BloodDrainTests.kt +++ b/Server/src/test/kotlin/content/familiar/special/BloodDrainTests.kt @@ -114,4 +114,4 @@ class BloodDrainTests { Assertions.assertEquals(false, hasTimerActive(p)) } } -} \ No newline at end of file +}