Skip to content

Commit

Permalink
feat(modules): update effects module
Browse files Browse the repository at this point in the history
add experimental function which checks if the effect is available for
the selected creature
  • Loading branch information
rudnovd committed Feb 24, 2022
1 parent eaa88d6 commit b3e1b8e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/modules/effects.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,55 @@
import type { DamageCalculatorBattleSide } from '@/models/Battle'
import type { CreatureInstance } from '@/models/Creature'
import { Creatures, Spells } from '@/models/enums'
import { Spell } from '@/models/Spell'

export const Effects = {
functions: {
canAccess: (effect: Spell, target: CreatureInstance) => {
if (!target) return false

// if target has Anti Magic effect
if (target.effects.find((effect) => effect.id === Spells.AntiMagic)) return false

// if target has immunity to effect
if (target.special?.immunity?.find((spell) => spell.id === effect.id)) return false

const undeadImmunitySpells = [
Spells.Bless,
Spells.Curse,
Spells.DeathRipple,
Spells.Resurrection,
Spells.Sacrifice,
]
const mindSpells = [
Spells.Berserk,
Spells.Blind,
Spells.Forgetfulness,
Spells.Frenzy,
Spells.Hypnotize,
Spells.Mirth,
Spells.Sorrow,
]

// Check undead creatures immunities
if (target.special?.undead) {
if (undeadImmunitySpells.indexOf(effect.id) > -1) return false
if (mindSpells.indexOf(effect.id) > -1) return false
}

// Check non living creatures immunities
if (
target.special?.nonLiving &&
target.id !== Creatures.StoneGargoyle &&
target.id !== Creatures.ObsidianGargoyle
) {
if (mindSpells.indexOf(effect.id) > -1) return false
}

return true
},
},

/**
* Calculate creature minDamage, maxDamage and damageBonus with bless spell
* @param initiator DamageCalculatorBattleSide who casts effect
Expand Down

0 comments on commit b3e1b8e

Please sign in to comment.