diff --git a/project/common/src/main/kotlin/ink/ptms/um/skill/SkillMechanic.kt b/project/common/src/main/kotlin/ink/ptms/um/skill/SkillMechanic.kt index ea3ed52..374e123 100644 --- a/project/common/src/main/kotlin/ink/ptms/um/skill/SkillMechanic.kt +++ b/project/common/src/main/kotlin/ink/ptms/um/skill/SkillMechanic.kt @@ -7,6 +7,4 @@ package ink.ptms.um.skill * @author 坏黑 * @since 2023/6/6 16:03 */ -interface SkillMechanic { - -} \ No newline at end of file +interface SkillMechanic \ No newline at end of file diff --git a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/BaseCondition.kt b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/BaseCondition.kt index 90f6154..59b7992 100644 --- a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/BaseCondition.kt +++ b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/BaseCondition.kt @@ -15,6 +15,7 @@ interface BaseCondition { is LocationCondition -> true is SkillMetadataCondition -> true is EntityComparisonCondition -> true + is SkillMetaComparisonCondition->true is EntityLocationDistanceCondition -> true else -> false } diff --git a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/CasterCondition.kt b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/CasterCondition.kt index 4c29d11..cb442a0 100644 --- a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/CasterCondition.kt +++ b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/CasterCondition.kt @@ -8,5 +8,5 @@ import ink.ptms.um.skill.SkillCaster * author 劫 */ interface CasterCondition:BaseCondition { - fun check(skillCaster: SkillCaster):Boolean + fun check(skillCaster: SkillCaster?):Boolean } \ No newline at end of file diff --git a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/EntityCondition.kt b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/EntityCondition.kt index 8101afc..07ef537 100644 --- a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/EntityCondition.kt +++ b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/EntityCondition.kt @@ -8,5 +8,5 @@ import org.bukkit.entity.Entity * author 劫 */ interface EntityCondition:BaseCondition { - fun check(entity: Entity):Boolean + fun check(entity: Entity?):Boolean } \ No newline at end of file diff --git a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/EntityLocationDistanceCondition.kt b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/EntityLocationDistanceCondition.kt index 80e5c4b..240049d 100644 --- a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/EntityLocationDistanceCondition.kt +++ b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/EntityLocationDistanceCondition.kt @@ -9,5 +9,5 @@ import org.bukkit.entity.Entity * author 劫 */ interface EntityLocationDistanceCondition : BaseCondition { - fun check(entity: Entity?, location: Location): Boolean + fun check(entity: Entity?, location: Location?): Boolean } \ No newline at end of file diff --git a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/LocationCondition.kt b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/LocationCondition.kt index 6de7af4..e23a90c 100644 --- a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/LocationCondition.kt +++ b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/LocationCondition.kt @@ -8,5 +8,5 @@ import org.bukkit.Location * author 劫 */ interface LocationCondition:BaseCondition { - fun check(location: Location):Boolean + fun check(location: Location?):Boolean } \ No newline at end of file diff --git a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/SkillMetaComparisonCondition.kt b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/SkillMetaComparisonCondition.kt new file mode 100644 index 0000000..6a18b98 --- /dev/null +++ b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/SkillMetaComparisonCondition.kt @@ -0,0 +1,13 @@ +package ink.ptms.um.skill.condition + +import ink.ptms.um.skill.SkillMeta +import org.bukkit.entity.Entity + +/** project name universal-mythic + * package ink.ptms.um.skill.condition + * time 2024/7/8 + * author 劫 + */ +interface SkillMetaComparisonCondition:BaseCondition { + fun check(skillMeta: SkillMeta?, entity: Entity?):Boolean +} \ No newline at end of file diff --git a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/SkillMetadataCondition.kt b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/SkillMetadataCondition.kt index 2bfee61..6a444f9 100644 --- a/project/common/src/main/kotlin/ink/ptms/um/skill/condition/SkillMetadataCondition.kt +++ b/project/common/src/main/kotlin/ink/ptms/um/skill/condition/SkillMetadataCondition.kt @@ -8,5 +8,5 @@ import ink.ptms.um.skill.SkillMeta * author 劫 */ interface SkillMetadataCondition :BaseCondition{ - fun check(skill:SkillMeta):Boolean + fun check(skill: SkillMeta?):Boolean } \ No newline at end of file diff --git a/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/MobListener.kt b/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/MobListener.kt index 133ff7c..6bb5823 100644 --- a/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/MobListener.kt +++ b/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/MobListener.kt @@ -38,6 +38,7 @@ internal object MobListener { val e = MobSpawnEvent(mob4, mob4.type, runCatching { event.mobLevel }.getOrElse { 0.0 }).fire() // 更新等级 runCatching { event.mobLevel = e.level } + if (e.isCancelled) event.setCancelled() } @Ghost diff --git a/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/MobListenerCondition.kt b/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/MobListenerCondition.kt index 55033e2..86846c8 100644 --- a/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/MobListenerCondition.kt +++ b/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/MobListenerCondition.kt @@ -23,53 +23,58 @@ internal object MobListenerCondition { @Ghost @SubscribeEvent fun onSkillConditionEvent(event: MythicConditionLoadEvent) { - val e = MobConditionLoadEvent(event.config.key, event.config.toUniversal()).fire() + val config = event.config + val e = MobConditionLoadEvent(config.key, config.toUniversal()).fire() val registerCondition = e.skillCondition ?: return if (!BaseCondition.isSubclass(registerCondition)) { error("Unsupported skill: $registerCondition") } - event.register(ProxyCondition(registerCondition, event.config)) + when (registerCondition) { + is EntityCondition -> event.register(Entity(registerCondition, config)) + is CasterCondition -> event.register(Caster(registerCondition, config)) + is LocationCondition -> event.register(Location(registerCondition, config)) + is SkillMetadataCondition -> event.register(SkillMeta(registerCondition, config)) + is EntityComparisonCondition -> event.register(EntityComparison(registerCondition, config)) + is EntityLocationDistanceCondition -> event.register(EntityLocation(registerCondition, config)) + is SkillMetaComparisonCondition -> throw NullPointerException("当前MM版本不支持这个条件") + } } - class ProxyCondition(private val skillCondition: BaseCondition, config: MythicLineConfig) : SkillCondition(config.line), ICasterCondition, - IEntityComparisonCondition, IEntityCondition, IEntityLocationComparisonCondition, ILocationCondition, ISkillMetaCondition { - + class Caster(val condition: CasterCondition, config: MythicLineConfig) : SkillCondition(config.line), ICasterCondition { override fun check(p0: SkillCaster?): Boolean { - return if (skillCondition is CasterCondition) { - p0?.toUniversal()?.let { skillCondition.check(it) } ?: false - } else false + return condition.check(p0?.toUniversal()) } + } + class EntityComparison(val condition: EntityComparisonCondition, config: MythicLineConfig) : SkillCondition(config.line), + IEntityComparisonCondition { override fun check(p0: AbstractEntity?, p1: AbstractEntity?): Boolean { - return if (skillCondition is EntityComparisonCondition) { - skillCondition.check(p0?.bukkitEntity, p1?.bukkitEntity) - } else false - } - - override fun check(p0: AbstractEntity?): Boolean { - return if (skillCondition is EntityCondition) { - p0?.let { skillCondition.check(it.bukkitEntity) } ?: false - } else false + return condition.check(p0?.bukkitEntity, p1?.bukkitEntity) } + } + class EntityLocation(val condition: EntityLocationDistanceCondition, config: MythicLineConfig) : SkillCondition(config.line), + IEntityLocationComparisonCondition { override fun check(p0: AbstractEntity?, p1: AbstractLocation?): Boolean { - return if (skillCondition is EntityLocationDistanceCondition) { - p1?.let { skillCondition.check(p0?.bukkitEntity, it.toBukkit()) } ?: false - } else false + return condition.check(p0?.bukkitEntity, p1?.toBukkit()) } + } - override fun check(p0: AbstractLocation?): Boolean { - return if (skillCondition is LocationCondition) { - p0?.toBukkit()?.let { skillCondition.check(it) } ?: false - } else false + class Entity(val condition: EntityCondition, config: MythicLineConfig) : SkillCondition(config.line), IEntityCondition { + override fun check(p0: AbstractEntity?): Boolean { + return condition.check(p0?.bukkitEntity) } + } + class SkillMeta(val condition: SkillMetadataCondition, config: MythicLineConfig) : SkillCondition(config.line), ISkillMetaCondition { override fun check(p0: SkillMetadata?): Boolean { - return if (skillCondition is SkillMetadataCondition) { - p0?.toUniversal()?.let { skillCondition.check(it) } ?: false - } else false + return condition.check(p0?.toUniversal()) } + } - + class Location(val condition: LocationCondition, config: MythicLineConfig) : SkillCondition(config.line), ILocationCondition { + override fun check(p0: AbstractLocation?): Boolean { + return condition.check(p0?.toBukkit()) + } } } \ No newline at end of file diff --git a/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/MobListener.kt b/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/MobListener.kt index 41e85e6..3e92486 100644 --- a/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/MobListener.kt +++ b/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/MobListener.kt @@ -20,7 +20,9 @@ internal object MobListener { @Ghost @SubscribeEvent fun onMobSpawnEvent(event: MythicMobSpawnEvent) { - event.mobLevel = MobSpawnEvent(Mob(event.mob), MobType(event.mob.type), event.mobLevel).fire().level + val e = MobSpawnEvent(Mob(event.mob), MobType(event.mob.type), event.mobLevel).fire() + event.mobLevel = e.level + event.isCancelled = e.isCancelled } @Ghost diff --git a/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/MobListenerCondition.kt b/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/MobListenerCondition.kt index b4a4f0e..a15dbe5 100644 --- a/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/MobListenerCondition.kt +++ b/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/MobListenerCondition.kt @@ -22,55 +22,68 @@ internal object MobListenerCondition { @Ghost @SubscribeEvent fun onMythicConditionLoad(event: MythicConditionLoadEvent) { - val e = MobConditionLoadEvent(event.conditionName, event.config.toUniversal()).fire() + val config = event.config + val e = MobConditionLoadEvent(config.key, config.toUniversal()).fire() val registerCondition = e.skillCondition ?: return // 如果注册的条件,不在这些类型中,那么就是无效的技能类型 if (!BaseCondition.isSubclass(registerCondition)) { error("Unsupported skill: $registerCondition") } - event.register(ProxyCondition(registerCondition, event.config)) + when (registerCondition) { + is EntityCondition -> event.register(Entity(registerCondition, config)) + is CasterCondition -> event.register(Caster(registerCondition, config)) + is LocationCondition -> event.register(Location(registerCondition, config)) + is SkillMetadataCondition -> event.register(SkillMeta(registerCondition, config)) + is EntityComparisonCondition -> event.register(EntityComparison(registerCondition, config)) + is EntityLocationDistanceCondition -> event.register(EntityLocation(registerCondition, config)) + is SkillMetaComparisonCondition -> event.register(SkillMetaComparison(registerCondition, config)) + } } - class ProxyCondition(private val skillCondition: BaseCondition, config: MythicLineConfig) : SkillCondition(config.line), - ICasterCondition, IEntityComparisonCondition, IEntityCondition, IEntityLocationComparisonCondition, - ILocationCondition, ISkillMetaCondition { - override fun check(p0: SkillCaster?): Boolean { - return if (skillCondition is CasterCondition) { - p0?.toUniversal()?.let { skillCondition.check(it) } ?: false - } else false + + class SkillMetaComparison(val condition: SkillMetaComparisonCondition, config: MythicLineConfig) : SkillCondition(config.line), + ISkillMetaComparisonCondition { + override fun check(p0: SkillMetadata?, p1: AbstractEntity?): Boolean { + return condition.check(p0?.toUniversal(), p1?.bukkitEntity) } + } - override fun check(p0: AbstractEntity?, p1: AbstractEntity?): Boolean { - return if (skillCondition is EntityComparisonCondition) { - skillCondition.check(p0?.bukkitEntity, p1?.bukkitEntity) - } else false + class Caster(val condition: CasterCondition, config: MythicLineConfig) : SkillCondition(config.line), ICasterCondition { + override fun check(p0: SkillCaster?): Boolean { + return condition.check(p0?.toUniversal()) } + } - override fun check(p0: AbstractEntity?): Boolean { - return if (skillCondition is EntityCondition) { - p0?.let { skillCondition.check(it.bukkitEntity) } ?: false - } else false + class EntityComparison(val condition: EntityComparisonCondition, config: MythicLineConfig) : SkillCondition(config.line), + IEntityComparisonCondition { + override fun check(p0: AbstractEntity?, p1: AbstractEntity?): Boolean { + return condition.check(p0?.bukkitEntity, p1?.bukkitEntity) } + } + class EntityLocation(val condition: EntityLocationDistanceCondition, config: MythicLineConfig) : SkillCondition(config.line), + IEntityLocationComparisonCondition { override fun check(p0: AbstractEntity?, p1: AbstractLocation?): Boolean { - return if (skillCondition is EntityLocationDistanceCondition) { - p1?.let { skillCondition.check(p0?.bukkitEntity, it.toBukkit()) } ?: false - } else false + return condition.check(p0?.bukkitEntity, p1?.toBukkit()) } + } - override fun check(p0: AbstractLocation?): Boolean { - return if (skillCondition is LocationCondition) { - p0?.toBukkit()?.let { skillCondition.check(it) } ?: false - } else false + class Entity(val condition: EntityCondition, config: MythicLineConfig) : SkillCondition(config.line), IEntityCondition { + override fun check(p0: AbstractEntity?): Boolean { + return condition.check(p0?.bukkitEntity) } + } + class SkillMeta(val condition: SkillMetadataCondition, config: MythicLineConfig) : SkillCondition(config.line), ISkillMetaCondition { override fun check(p0: SkillMetadata?): Boolean { - return if (skillCondition is SkillMetadataCondition) { - p0?.toUniversal()?.let { skillCondition.check(it) } ?: false - } else false + return condition.check(p0?.toUniversal()) } + } - + class Location(val condition: LocationCondition, config: MythicLineConfig) : SkillCondition(config.line), ILocationCondition { + override fun check(p0: AbstractLocation?): Boolean { + return condition.check(p0?.toBukkit()) + } } } \ No newline at end of file