From eb99d843248d4f2bf2cbb7e26c2a866d96b0adee Mon Sep 17 00:00:00 2001 From: Ziggy Date: Mon, 1 Jul 2024 21:15:29 +0200 Subject: [PATCH] Fixed infinite duration buffs expiring immediately --- .../services/gameplay/combat/buffs/BuffService.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/projectswg/holocore/services/gameplay/combat/buffs/BuffService.kt b/src/main/java/com/projectswg/holocore/services/gameplay/combat/buffs/BuffService.kt index 1a44f4782..1cf48059b 100644 --- a/src/main/java/com/projectswg/holocore/services/gameplay/combat/buffs/BuffService.kt +++ b/src/main/java/com/projectswg/holocore/services/gameplay/combat/buffs/BuffService.kt @@ -97,7 +97,7 @@ class BuffService : Service() { } private fun removeExpiredBuffs(creatureObject: CreatureObject) { - val crcsForExpiredBuffs = creatureObject.buffs.filter { isBuffExpired(creatureObject, it.value) }.map { it.key } + val crcsForExpiredBuffs = creatureObject.buffs.map { it.key }.filter { isBuffExpired(creatureObject, it) } crcsForExpiredBuffs.forEach { removeBuff(creatureObject, it) } } @@ -112,7 +112,12 @@ class BuffService : Service() { return ProjectSWG.galacticTime.toInt() } - private fun isBuffExpired(creature: CreatureObject, buff: Buff): Boolean { + private fun isBuffExpired(creature: CreatureObject, buffCrc: CRC): Boolean { + val buffData = buffs.getBuff(buffCrc) ?: return true + val buff = creature.buffs[buffCrc] ?: return true + + if (isBuffInfinite(buffData)) return false + return calculatePlayTime(creature) >= buff.endTime } @@ -196,8 +201,8 @@ class BuffService : Service() { private fun scheduleBuffExpirationCheck(receiver: CreatureObject, buffData: BuffInfo) { timerCheckThread.execute(1000L) { - val buff = receiver.buffs[buffData.crc] ?: return@execute - if (isBuffExpired(receiver, buff)) { + receiver.buffs[buffData.crc] ?: return@execute + if (isBuffExpired(receiver, buffData.crc)) { removeBuff(receiver, buffData.crc) } else { scheduleBuffExpirationCheck(receiver, buffData)