Damage - noonmaru/psychics GitHub Wiki

개요

개체에게 EsperAttribute의 수치를 이용해 피해를 입히는 방법을 제공합니다.

LivingEntity의 확장함수로 마인크래프트 방어력과 상호작용하여 피해를 입힐 수 있습니다.

예제

LivingEntity.psychicDamage (com.github.noonmaru.psychics.DamageSupport.kt에 정의되어있는 확장함수)

직접 Esper로부터 EsperStatistics를 이용해 능력치를 가져온 수치만큼 피해를 입히는 코드입니다.

class MyAbility : ActiveAbility<AbilityConcept>() {
    init {
        targeter = {
            val eyeLocation = esper.player.eyeLocation
            val direction = eyeLocation.direction

            eyeLocation.world.rayTraceEntities(
                    eyeLocation,
                    direction, 64.0,
                    1.0
            )
        }
    }

    override fun onCast(target: Any?) {
        // target = targetEntity
        val targetEntity = target as LivingEntity
        val stats = EsperStatistic.of(EsperAttribute.ATTACK_DAMAGE to 1.0)

        val damageType = DamageType.RANGED
        val damageAmount = esper.getStatistic(stats)

        targetEntity.psychicDamage(
                this, // 공격자의 Ability
                damageType, // 데미지 타입
                damageAmount, // 데미지량
                esper.player, // 공격자 플레이어
                esper.player.location, // 넉백 기준 좌표
                1.0) // 넉백 강도
    }
}

LivingEntity.psychicDamage (com.github.noonmaru.psychics.Ability에 정의되어있는 내부 확장함수)

위 확장함수를 com.github.noonmaru.damage.Damage 클래스를 이용해 조금 더 마법적인 방법으로 호출합니다.

Ability내에 선언되어있는 확장함수이므로 내부 속성을 이용해 능력 사용자의 능력치를 가져와 피해량을 적용합니다.

class MyAbility : ActiveAbility<AbilityConcept>() {
    init {
        targeter = {
            val eyeLocation = esper.player.eyeLocation
            val direction = eyeLocation.direction

            eyeLocation.world.rayTraceEntities(
                    eyeLocation,
                    direction, 64.0,
                    1.0
            )
        }
    }

    override fun onCast(target: Any?) {
        // target = targetEntity
        val targetEntity = target as LivingEntity
        val damage = Damage(DamageType.RANGED, EsperStatistic.of(EsperAttribute.ATTACK_DAMAGE to 1.0))

        targetEntity.psychicDamage(damage, esper.player.eyeLocation, 1.0)
    }
}

AbilityConcept에는 damage속성이 정의되어있습니다.

damage속성이 null이 아닐경우 이를 이용해 아래처럼 간단하게 적용할 수 있습니다.

class MyAbility : ActiveAbility<AbilityConcept>() {
    init {
        targeter = {
            val eyeLocation = esper.player.eyeLocation
            val direction = eyeLocation.direction

            eyeLocation.world.rayTraceEntities(
                    eyeLocation,
                    direction, 64.0,
                    1.0
            )
        }
    }

    override fun onCast(target: Any?) {
        // target = targetEntity
        val targetEntity = target as LivingEntity

        concept.damage?.let { targetEntity.psychicDamage(it) }
    }
}