Skip to content

Commit

Permalink
Merge pull request #5 from XiaoJie-150/master
Browse files Browse the repository at this point in the history
我的问题,他这判断真奇特,顺便改进实体生成可取消,增加mm5的一个技能meta判断条件,将参数原生转过去
  • Loading branch information
FxRayHughes authored Jul 8, 2024
2 parents 8ccc0d8 + 7a9d4ea commit 94e7788
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ package ink.ptms.um.skill
* @author 坏黑
* @since 2023/6/6 16:03
*/
interface SkillMechanic {

}
interface SkillMechanic
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface BaseCondition {
is LocationCondition -> true
is SkillMetadataCondition -> true
is EntityComparisonCondition -> true
is SkillMetaComparisonCondition->true
is EntityLocationDistanceCondition -> true
else -> false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import ink.ptms.um.skill.SkillCaster
* author 劫
*/
interface CasterCondition:BaseCondition {
fun check(skillCaster: SkillCaster):Boolean
fun check(skillCaster: SkillCaster?):Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import org.bukkit.entity.Entity
* author 劫
*/
interface EntityCondition:BaseCondition {
fun check(entity: Entity):Boolean
fun check(entity: Entity?):Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import org.bukkit.Location
* author 劫
*/
interface LocationCondition:BaseCondition {
fun check(location: Location):Boolean
fun check(location: Location?):Boolean
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import ink.ptms.um.skill.SkillMeta
* author 劫
*/
interface SkillMetadataCondition :BaseCondition{
fun check(skill:SkillMeta):Boolean
fun check(skill: SkillMeta?):Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}

0 comments on commit 94e7788

Please sign in to comment.