# lib_immunity function library

Dependencies: alter_effect, ds, lib_2da, lib_anon, lib_array, lib_fn, lib_ini, lib_sfo, lib_struct, lib_sugar, lib_tools, lib_ui

## Description

Functions here streamline applying immunity effects (to damage types, opcodes, etc) to spells, items and creatures, while managing the required secondary immunities to graphics, strings, icons and the like.

## Public functions

immunity_effect(permanent:i=1, arguments:s, struct:s)=(struct:a) dimorphic

(This is a struct function).

Patches the spell/item/creature to offer immunity to a list of effects. If run in permanent mode (the default) it adds the effect outright with timing=9 (2 for items). On a spell, this is added to all abilities; on an item or cre, to the base item/cre. If run in non-permanent mode, everything is applied as a clone of the controlling immune-to-this opcode (if any).

The list of effects is: charm, stun, fear, hold, sleep, poison, diseased, energy_drain, blinded, insects

immunity_effects_load action_macro

Defines the arrays for the immunity_effect function

immunity_find_strings()=(immunity_string_array:a) action

This function gets all the immunity strings - loading them from a premade file if it exists, creating that file otherwise. The file is created with COPY + and so persists even when the component is uninstalled.

The 'create file' version only works in English. It shouldn't be run in distributed code. Make sure it's run ahead of time (on each of BG2, SoD, IWD) to make the files.

Currently EE-only, though wouldn't be difficult to adapt.

immunity_spell(struct:s, arguments:s)=(struct:a) dimorphic

Given a list of spell resrefs, grants (for an item or creature) while-equipped or permanent immunity. On a spell, adds permanent (not just until-death) immunity to target=2 as an ability effect.

## Internal functions

These should not be called from outside the library itself.

immunity_spell_helper()=() patch