Created
June 30, 2023 11:43
-
-
Save klg71/89adffc2a90352639ed338ee7a84542a to your computer and use it in GitHub Desktop.
Spells as Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface AbilityCompanion : ScaledAbility { | |
fun id(): UUID | |
fun name(): String | |
fun aggroModifier(): Long = 1 | |
//Used for bosses where the ability changes from one difficulty to another | |
fun descriptionOverride(difficulty: Difficulty): String? = null | |
// Locks rotation while casting (only in client) | |
fun lockRotation(): Boolean = false | |
fun referencedBuffs(): List<BuffAbilityCompanion> = emptyList() | |
fun referencedAoes(): List<AreaOfEffectAbilityCompanion> = emptyList() | |
fun referencedPets(): List<ReferencedPet> = emptyList() | |
fun referencedNpcs(): List<NpcCompanion> = emptyList() | |
fun referencedAbilities(): List<AbilityCompanion> = emptyList() | |
} | |
interface Ability { | |
fun static(): AbilityCompanion | |
fun range(): Long = 0 | |
fun possibleTargets(source: Target): PossibleTargets = PossibleTargets.ALL | |
/** | |
* Simple effect implementation. | |
* This will only be executed if multiEffect returns null, here you can specify the effect only for the target. | |
*/ | |
fun effect(source: Target, target: Target): AbilityEffect = AbilityEffect() | |
/** | |
* More sophisticated effect implementation | |
* You are expected to return a Map with TargetId to the related AbilityEffect | |
*/ | |
fun multiEffect(gameState: GameState, | |
source: Target, | |
initialTargetIds: List<UUID>, | |
targets: List<Target>, | |
initialPositions: List<Point>, | |
targetZones: List<TargetZone>): List<EffectOnTarget> = targets.map { | |
EffectOnTarget(it.id(), effect(source, it)) | |
} | |
fun canHit(source: Target, target: Target): Boolean = true | |
fun canCast(source: Target): Boolean = true | |
fun cooldown(source: Target?): Long = 0 | |
fun resourceType(): ResourceType? = null | |
fun resourceAmount(source: Target?): Long = 0 | |
fun targetCount(): TargetCount = TargetCount() | |
fun castTime(source: Target?): Long = 0 | |
fun isInterruptible(): Boolean = true | |
fun buildTargetZone(sourcePosition: Point, position: Point): TargetZone? = null | |
/** | |
* If this ability is a channel ability, this has multiple implications: | |
* - castTime becomes channelTime | |
* - multiEffect is not called | |
*/ | |
fun channelConfig(): ChannelConfig? = null | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class AbilityEffect( | |
val resourceChange: List<ResourceChange> = emptyList(), | |
val newBuffs: List<NewBuff> = emptyList(), | |
// This contains an array of the actual id field of buff | |
val removeBuffs: List<RemoveBuff> = emptyList(), | |
val abilitiesEffects: List<AbilityEffectType> = emptyList(), | |
val newPetSummons: List<NewPetSummon> = emptyList(), | |
val newNpcSummons: List<NewNpcSummon> = emptyList(), | |
// This contains an array of the actual id field of pet | |
val removeSummons: List<UUID> = emptyList(), | |
val displacements: List<DisplacementEffect> = emptyList(), | |
val aggroEffect: AggroEffectType? = null, | |
val newAreas: List<NewAreaOfEffect> = emptyList(), | |
val newTeleporter: List<NewTeleporterEffect> = emptyList(), | |
val newProjectile: List<NewProjectile> = emptyList(), | |
val removeAreas: List<RemoveAreaOfEffect> = emptyList(), | |
// Reset the cooldown of this ability | |
val resetCds: List<CdReset> = emptyList(), | |
// Extends the lifespan of the chosen pet | |
val petLifeSpanExtends: List<PetLifeSpanExtend> = emptyList(), | |
//Revives the target | |
val revive: ReviveEffect? = null | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface BuffAbilityCompanion : ScaledAbility { | |
fun id(): UUID | |
fun name(): String | |
fun buffType(): BuffType = BuffType.BUFF | |
/** | |
* A Buff with initialTime 0 is called an aura and lives until it is removed otherwise | |
*/ | |
fun initialTime(): Long? | |
fun stackBehaviour(): StackBehaviour = StackBehaviour(1, BuffAllowedPerTarget.SINGLE_BUFF_FOR_SOURCE_ID) | |
fun displayBehaviour(): BuffDisplayBehaviour? = null | |
fun referencedBuffs(): List<BuffAbilityCompanion> = emptyList() | |
fun aggroModifier(): Long? = null | |
fun transmitEvents(): List<CastAbilityState> = CastAbilityState.values().toList() | |
} | |
interface BuffAbility { | |
fun static(): BuffAbilityCompanion | |
fun tickDelay(): Long? = null | |
fun tickDelay(source: Target): Long? = tickDelay() | |
fun initialTime(source: Target): Long? = static().initialTime() | |
fun isCleansable(): Boolean = false | |
/** | |
* Called when buff is applied, ticking and removed | |
*/ | |
fun effect(effectType: BuffEffectType, | |
buffHolderId: UUID, | |
buff: Buff, | |
gameState: GameState): List<BuffEffectOnTarget> = | |
emptyList() | |
/** | |
* Called when a resource changes on the buffholder | |
*/ | |
fun onResourceChangeOnSelf(resource: ResourceType, | |
amount: Long, | |
buffHolderId: UUID, | |
sourceId: UUID, | |
buff: Buff, | |
gameState: GameState, | |
damageType: DamageType): List<BuffEffectOnTarget> = emptyList() | |
/** | |
* Called when a resource changes from an action of the buffholder | |
*/ | |
fun onResourceChangedBySelf( | |
change: ActualResourceChange, | |
buffHolderId: UUID, | |
targetId: UUID, | |
buff: Buff, | |
gameState: GameState): List<BuffEffectOnTarget> = emptyList() | |
/** | |
* Called when the buffholder has another position | |
*/ | |
fun onPositionChange( | |
distance: Long, | |
buffHolder: UUID, | |
buff: Buff, | |
gameState: GameState): List<BuffEffectOnTarget> = emptyList() | |
/** | |
* Called when another buff is applied on this target | |
*/ | |
fun onBuffApply( | |
buffHolder: UUID, | |
buff: Buff, | |
gameState: GameState, appliedBuff: Buff): List<BuffEffectOnTarget> = emptyList() | |
/** | |
* Called when the buffholder has casted an ability | |
*/ | |
fun onAbilityCasted( | |
buffHolderId: UUID, | |
buff: Buff, | |
gameState: GameState, ability: CastingAbilityEvent): List<BuffEffectOnTarget> = emptyList() | |
/** | |
* Called when another buff is removed on this target | |
*/ | |
fun onBuffRemoved( | |
buffHolder: UUID, | |
buff: Buff, | |
gameState: GameState, removedBuff: Buff): List<BuffEffectOnTarget> = emptyList() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIT License | |
Copyright (c) [year] [fullname] | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment