Rune_PRC8/_module/nss/j_inc_seteffects.nss
Jaysyn904 d1c309ae63 Initial commit
Initial commit
2024-09-13 09:10:39 -04:00

445 lines
21 KiB
Plaintext

/************************ [Set Effects Include] ********************************
Filename:
************************* [Set Effects] ****************************************
This can be executed on a PC or NPC, and sets what thier current effects
are - the hostile ones.
It is executed on a PC every 6 seconds in combat, delayed by a timer,
by other NPCs who want to target them.
It is meant to be more efficient then doing countless checks against other
NPCs and PCs for what effects they already have on them.
************************* [History] ********************************************
1.3 - Added
************************* [Workings] *******************************************
ExecuteScript - might not work faster. If so, it is easy to add into the
generic AI and have oTarget to set to.
It searches the code and sets 3 custom integers, but only once (so not
during the loop)
************************* [Arguments] ******************************************
Arguments: N/A
************************* [Set Effects] ***************************************/
#include "J_INC_CONSTANTS"
// List (use Global to not conflict with the nwscript.nss!)
const int GlobalEffectUncommandable = 0x00000001;// Stun. Sleep. Fear. Turning.
const int GlobalEffectSilenced = 0x00000002;// Eeek!
const int GlobalEffectSlowed = 0x00000004;// Stop with haste.
const int GlobalEffectUltravision = 0x00000008;
const int GlobalEffectSeeInvisible = 0x00000010; // NOT Inc. Trueseeing
const int GlobalEffectTrueSeeing = 0x00000020;
const int GlobalEffectTimestop = 0x00000040;
const int GlobalEffectInvisible = 0x00000080;
const int GlobalEffectDeaf = 0x00000100;// Ack!
const int GlobalEffectHaste = 0x00000200;
const int GlobalEffectPolymorph = 0x00000400;// Only attack
const int GlobalEffectBlindness = 0x00000800;// Oh no!
const int GlobalEffectDisease = 0x00001000;
const int GlobalEffectPoison = 0x00002000;
const int GlobalEffectCurse = 0x00004000;
const int GlobalEffectNegativeLevel = 0x00008000;
const int GlobalEffectEntangle = 0x00010000;
const int GlobalEffectMovementSpeedDecrease = 0x00020000;
const int GlobalEffectDarkness = 0x00040000;// Noo! Need ultravision!
const int GlobalEffectDazed = 0x00080000;// Special: 1.30 patch, we can move!
const int GlobalEffectEthereal = 0x00100000;
const int GlobalEffectPetrify = 0x00200000;
const int GlobalEffectParalyze = 0x00400000;// Divided from Uncommandable for healing of
//const int GlobalEffectAbilityDecrease = 0x00080000;// Ohh! Tingly!
const int GlobalEffectSpellFailure = 0x00800000;// Makes sure spells are not cast under high failure.
const int GlobalEffectDamageShield = 0x01000000;// All damage shields
//int GlobalEffectAbilityDecrease = 0; // In combat include
// These are Globals for spell effects, to not csat them on us again, and to
// speed things up...
const int GlobalHasStoneSkinProtections = 0x00000001;
const int GlobalHasElementalProtections = 0x00000002;
const int GlobalHasVisageProtections = 0x00000004;
const int GlobalHasMantalProtections = 0x00000008;
const int GlobalHasGlobeProtections = 0x00000010;
const int GlobalHasMindResistanceProtections = 0x00000020;
const int GlobalHasAidingSpell = 0x00000040;
const int GlobalHasRangedConsealment = 0x00000080;
const int GlobalHasRageSpells = 0x00000100;
const int GlobalHasBullsStrengthSpell = 0x00000200;
const int GlobalHasCatsGraceSpell = 0x00000400;
const int GlobalHasClairaudienceSpell = 0x00000800;
const int GlobalHasDeathWardSpell = 0x00001000;
const int GlobalHasDivinePowerSpell = 0x00002000;
const int GlobalHasEaglesSpledorSpell = 0x00004000;
const int GlobalHasEnduranceSpell = 0x00008000;
const int GlobalHasFoxesCunningSpell = 0x00010000;
const int GlobalHasProtectionEvilSpell = 0x00020000;
const int GlobalHasProtectionGoodSpell = 0x00040000;
const int GlobalHasLightSpell = 0x00080000;
const int GlobalHasConsealmentSpells = 0x00100000;// Displacement
const int GlobalHasProtectionSpellsSpell = 0x00200000;
const int GlobalHasRegenerateSpell = 0x00400000;
const int GlobalHasOwlsWisdomSpell = 0x00800000;
const int GlobalHasSpellResistanceSpell = 0x01000000;
const int GlobalHasSpellWarCrySpell = 0x02000000;
//const int GlobalHasElementalShieldSpell = 0x04000000;
const int GlobalHasDomainSpells = 0x08000000;
const int GlobalHasDeflectionACSpell = 0x10000000;
const int GlobalHasNaturalACSpell = 0x20000000;
const int GlobalHasOtherACSpell = 0x40000000;
const int GlobalHasWeaponHelpSpell = 0x80000000;
// Other, AOE ones
//const int GlobalHasAreaEffectDamaging = 0x04000000;
//const int GlobalHasAreaEffectImpeding = 0x08000000;
int TempEffectHex, TempSpellHex;
// Sets up an effects thing to that
void AI_SetWeHaveEffect(int iEffectHex);
// Sets we have spell iSpellHex's effects.
void AI_SetWeHaveSpellsEffect(int iSpellHex);
// Sets up effects on oTarget
void AI_SetEffectsOnTarget(object oTarget = OBJECT_SELF);
// Simple return TRUE if it matches hex.
// - Effects tested on oTarget
int AI_GetAIHaveEffect(int iEffectHex, object oTarget = OBJECT_SELF);
// Simple return TRUE if it matches hex.
// - Uses oTarget
int AI_GetAIHaveSpellsEffect(int iSpellHex, object oTarget = OBJECT_SELF);
// Sets up an effects thing to that
void AI_SetWeHaveEffect(int iEffectHex)
{
TempEffectHex = TempEffectHex | iEffectHex;
}
// Sets we have spell iSpellHex's effects.
void AI_SetWeHaveSpellsEffect(int iSpellHex)
{
TempSpellHex = TempSpellHex | iSpellHex;
}
// Simple return TRUE if it matches hex.
// - Effects tested on oTarget
int AI_GetAIHaveEffect(int iEffectHex, object oTarget = OBJECT_SELF)
{
return (GetLocalInt(oTarget, AI_EFFECT_HEX) & iEffectHex);
}
// Simple return TRUE if it matches hex.
// - Uses oTarget
int AI_GetAIHaveSpellsEffect(int iSpellHex, object oTarget = OBJECT_SELF)
{
return (GetLocalInt(oTarget, AI_SPELL_HEX) & iSpellHex);
}
void AI_SetEffectsOnTarget(object oTarget = OBJECT_SELF)
{
TempEffectHex = FALSE;
TempSpellHex = FALSE;
// Checks our effects once.
effect eCheck = GetFirstEffect(oTarget);
int iEffect, iEffectAbilityDecrease, iSpellID;
// EFFECTS:
// For ALL targets (that we will use), we set up effects on a system of Hexes.
// like spawn in things. Replaces GetHasSpellEffect, except genralising -
// IE we will NOT cast more than one of the stoneskin type things at once.
while(GetIsEffectValid(eCheck))
{
iEffect = GetEffectType(eCheck);
switch(iEffect)
{
case EFFECT_TYPE_INVALIDEFFECT:
case EFFECT_TYPE_VISUALEFFECT:
// Don't check these for spell values.
break;
case EFFECT_TYPE_PARALYZE:
AI_SetWeHaveEffect(GlobalEffectParalyze);
break;
case EFFECT_TYPE_STUNNED:
case EFFECT_TYPE_FRIGHTENED:
case EFFECT_TYPE_SLEEP:
case EFFECT_TYPE_TURNED:
case EFFECT_TYPE_DISAPPEARAPPEAR:// Added for dragon flying
AI_SetWeHaveEffect(GlobalEffectUncommandable);
break;
case EFFECT_TYPE_DAZED:
AI_SetWeHaveEffect(GlobalEffectDazed);
break;
case EFFECT_TYPE_SILENCE:
AI_SetWeHaveEffect(GlobalEffectSilenced);
break;
case EFFECT_TYPE_SLOW:
AI_SetWeHaveEffect(GlobalEffectSlowed);
break;
case EFFECT_TYPE_ULTRAVISION:
AI_SetWeHaveEffect(GlobalEffectUltravision);
break;
case EFFECT_TYPE_SEEINVISIBLE:
AI_SetWeHaveEffect(GlobalEffectSeeInvisible);
break;
// Caused by Beholder things mainly, but this stops any spell being
// cast, not just, for example, arcane spells cast in armor.
case EFFECT_TYPE_SPELL_FAILURE:
AI_SetWeHaveEffect(GlobalEffectSpellFailure);
break;
// Penetrates darkness.
case EFFECT_TYPE_TRUESEEING:
AI_SetWeHaveEffect(GlobalEffectTrueSeeing);
break;
// Timestop - IE don't cast same spell twice.
case EFFECT_TYPE_TIMESTOP:
AI_SetWeHaveEffect(GlobalEffectTimestop);
break;
// Invisibility/Improved (although improved only uses normal in the spell)
// Sneak attack/whatever :-)
// - include the spell EFFECT_TYPE_ETHEREAL.
case EFFECT_TYPE_INVISIBILITY:
case EFFECT_TYPE_IMPROVEDINVISIBILITY:
AI_SetWeHaveEffect(GlobalEffectInvisible);
break;
// Deaf - spell failing of 20%, but still cast.
case EFFECT_TYPE_DEAF:
AI_SetWeHaveEffect(GlobalEffectDeaf);
break;
// Special invis.
case EFFECT_TYPE_ETHEREAL:
AI_SetWeHaveEffect(GlobalEffectEthereal);
break;
// Haste - so don't cast haste again and whatever.
case EFFECT_TYPE_HASTE:
AI_SetWeHaveEffect(GlobalEffectHaste);
break;
// Haste - so don't cast haste again and whatever.
case EFFECT_TYPE_POLYMORPH:
AI_SetWeHaveEffect(GlobalEffectPolymorph);
break;
// Blindness - oh no, can't see, only hear!
case EFFECT_TYPE_BLINDNESS:
AI_SetWeHaveEffect(GlobalEffectBlindness);
break;
// Damage shield = Elemental shield, wounding whispers, Death armor, mestals
// sheth and so on.
case EFFECT_TYPE_ELEMENTALSHIELD:
AI_SetWeHaveEffect(GlobalEffectDamageShield);
break;
// Things we may want to remove VIA cirtain spells, we set here - may as well.
// Same setting as any other.
// IF we can remove it (not confusion ETC of course) then we set it.
case EFFECT_TYPE_DISEASE:
AI_SetWeHaveEffect(GlobalEffectDisease);
break;
case EFFECT_TYPE_POISON:
AI_SetWeHaveEffect(GlobalEffectPoison);
break;
// SoU Petrify
case EFFECT_TYPE_PETRIFY:
AI_SetWeHaveEffect(GlobalEffectPetrify);
break;
case EFFECT_TYPE_CURSE:
AI_SetWeHaveEffect(GlobalEffectCurse);
break;
case EFFECT_TYPE_NEGATIVELEVEL:
AI_SetWeHaveEffect(GlobalEffectNegativeLevel);
break;
case EFFECT_TYPE_ABILITY_DECREASE:
case EFFECT_TYPE_AC_DECREASE:
case EFFECT_TYPE_ATTACK_DECREASE:
case EFFECT_TYPE_DAMAGE_DECREASE:
case EFFECT_TYPE_DAMAGE_IMMUNITY_DECREASE:
case EFFECT_TYPE_SAVING_THROW_DECREASE:
case EFFECT_TYPE_SPELL_RESISTANCE_DECREASE:
case EFFECT_TYPE_SKILL_DECREASE:
// Special - we add one to this, to determine when to use restoration
iEffectAbilityDecrease++;
break;
case EFFECT_TYPE_ENTANGLE:
AI_SetWeHaveEffect(GlobalEffectEntangle);
break;
case EFFECT_TYPE_MOVEMENT_SPEED_DECREASE:
AI_SetWeHaveEffect(GlobalEffectMovementSpeedDecrease);
break;
case EFFECT_TYPE_DARKNESS:
AI_SetWeHaveEffect(GlobalEffectDarkness);
break;
default:
{
// Check spells we have on...so we don't cast over them!
iSpellID = GetEffectSpellId(eCheck);
if(iSpellID != iM1)
{
switch(iSpellID)
{
// All weapon things are on one variable. We cast the best.
case SPELL_MAGIC_WEAPON:
case SPELL_BLESS_WEAPON:
case SPELL_FLAME_WEAPON:
case SPELL_GREATER_MAGIC_WEAPON:
case SPELL_BLACKSTAFF:
case SPELL_BLADE_THIRST:
AI_SetWeHaveSpellsEffect(GlobalHasWeaponHelpSpell);
break;
case SPELL_ENDURE_ELEMENTS:
case SPELL_ENERGY_BUFFER:
case SPELL_RESIST_ELEMENTS:
case SPELL_PROTECTION_FROM_ELEMENTS:
AI_SetWeHaveSpellsEffect(GlobalHasElementalProtections);
break;
case SPELL_BARKSKIN:
case SPELL_STONE_BONES: // +3 to undead
AI_SetWeHaveSpellsEffect(GlobalHasNaturalACSpell);
break;
case SPELL_SHIELD:
case SPELL_DIVINE_SHIELD:
AI_SetWeHaveSpellsEffect(GlobalHasDeflectionACSpell);
break;
case SPELL_EPIC_MAGE_ARMOR:// Epic spell +20 to AC.
case SPELL_MAGE_ARMOR:
AI_SetWeHaveSpellsEffect(GlobalHasOtherACSpell);
break;
case SPELL_ENTROPIC_SHIELD:
AI_SetWeHaveSpellsEffect(GlobalHasRangedConsealment);
break;
case AI_SPELL_EPIC_WARDING:
case SPELL_STONESKIN:
case SPELL_GREATER_STONESKIN:
case SPELL_PREMONITION:
case SPELL_SHADES_STONESKIN: // Stoneskin one: 342
AI_SetWeHaveSpellsEffect(GlobalHasStoneSkinProtections);
break;
case SPELL_GHOSTLY_VISAGE:
case SPELL_SHADOW_SHIELD:
case SPELL_ETHEREAL_VISAGE:
case SPELL_GREATER_SHADOW_CONJURATION_MIRROR_IMAGE: // one: 351 is gostly visage. Speeds up not using number
case SPELL_SHADOW_EVADE: // Shadow dancer
case SPELLABILITY_AS_GHOSTLY_VISAGE: // Assassin
AI_SetWeHaveSpellsEffect(GlobalHasVisageProtections);
break;
case SPELL_GREATER_SPELL_MANTLE:
case SPELL_SPELL_MANTLE:
case SPELL_LESSER_SPELL_MANTLE:
AI_SetWeHaveSpellsEffect(GlobalHasMantalProtections);
break;
case SPELL_MINOR_GLOBE_OF_INVULNERABILITY:
case SPELL_GLOBE_OF_INVULNERABILITY:
case SPELL_GREATER_SHADOW_CONJURATION_MINOR_GLOBE:
AI_SetWeHaveSpellsEffect(GlobalHasGlobeProtections);
break;
case SPELL_AID:
case SPELL_PRAYER:
case SPELL_BLESS:
AI_SetWeHaveSpellsEffect(GlobalHasAidingSpell);
break;
case SPELL_BULLS_STRENGTH:
case SPELL_GREATER_BULLS_STRENGTH:
case SPELLABILITY_BG_BULLS_STRENGTH: // Blackguard
AI_SetWeHaveSpellsEffect(GlobalHasBullsStrengthSpell);
break;
case SPELL_CATS_GRACE:
case SPELL_GREATER_CATS_GRACE:
case AI_SPELL_HARPER_CATS_GRACE: // Harper
AI_SetWeHaveSpellsEffect(GlobalHasCatsGraceSpell);
break;
case SPELL_CLAIRAUDIENCE_AND_CLAIRVOYANCE:
AI_SetWeHaveSpellsEffect(GlobalHasClairaudienceSpell);
break;
case SPELL_CLARITY:
case SPELL_LESSER_MIND_BLANK:
case SPELL_MIND_BLANK:
AI_SetWeHaveSpellsEffect(GlobalHasMindResistanceProtections);
break;
case SPELL_DEATH_WARD:
case SPELL_UNDEATHS_ETERNAL_FOE:// Similar to death ward. Got more things.
AI_SetWeHaveSpellsEffect(GlobalHasDeathWardSpell);
break;
case SPELL_DISPLACEMENT:// 50% consealment
AI_SetWeHaveSpellsEffect(GlobalHasConsealmentSpells);
break;
case SPELL_DIVINE_POWER:
AI_SetWeHaveSpellsEffect(GlobalHasDivinePowerSpell);
break;
case SPELL_EAGLE_SPLEDOR:
case SPELL_GREATER_EAGLE_SPLENDOR:
case AI_SPELL_HARPER_EAGLE_SPLEDOR: // Harper
AI_SetWeHaveSpellsEffect(GlobalHasEaglesSpledorSpell);
break;
case SPELL_ENDURANCE:
case SPELL_GREATER_ENDURANCE:
AI_SetWeHaveSpellsEffect(GlobalHasEnduranceSpell);
break;
case SPELL_FOXS_CUNNING:
case SPELL_GREATER_FOXS_CUNNING:
AI_SetWeHaveSpellsEffect(GlobalHasFoxesCunningSpell);
break;
case SPELL_HOLY_AURA:
case SPELL_MAGIC_CIRCLE_AGAINST_EVIL:
case SPELL_PROTECTION_FROM_EVIL:
AI_SetWeHaveSpellsEffect(GlobalHasProtectionEvilSpell);
break;
case SPELL_UNHOLY_AURA:
case SPELL_MAGIC_CIRCLE_AGAINST_GOOD:
case SPELL_PROTECTION_FROM_GOOD:
AI_SetWeHaveSpellsEffect(GlobalHasProtectionGoodSpell);
break;
case SPELL_LIGHT:
case SPELL_CONTINUAL_FLAME:
AI_SetWeHaveSpellsEffect(GlobalHasLightSpell);
break;
case SPELL_OWLS_WISDOM:
case SPELL_GREATER_OWLS_WISDOM:
case AI_SPELL_OWLS_INSIGHT:// Missed spell
AI_SetWeHaveSpellsEffect(GlobalHasOwlsWisdomSpell);
break;
case SPELL_PROTECTION_FROM_SPELLS:
AI_SetWeHaveSpellsEffect(GlobalHasProtectionSpellsSpell);
break;
case SPELL_REGENERATE:
AI_SetWeHaveSpellsEffect(GlobalHasRegenerateSpell);
break;
case SPELL_SPELL_RESISTANCE:
AI_SetWeHaveSpellsEffect(GlobalHasSpellResistanceSpell);
break;
case SPELL_WAR_CRY:
AI_SetWeHaveSpellsEffect(GlobalHasSpellWarCrySpell);
break;
case SPELLABILITY_DIVINE_PROTECTION:
case SPELLABILITY_DIVINE_STRENGTH:
case SPELLABILITY_DIVINE_TRICKERY:
case SPELLABILITY_BATTLE_MASTERY:
AI_SetWeHaveSpellsEffect(GlobalHasDomainSpells);
break;
case SPELLABILITY_RAGE_3:
case SPELLABILITY_RAGE_4:
case SPELLABILITY_RAGE_5:
case SPELLABILITY_BARBARIAN_RAGE:
case SPELLABILITY_INTENSITY_1:
case SPELLABILITY_INTENSITY_2:
case SPELLABILITY_INTENSITY_3:
case SPELLABILITY_FEROCITY_1:
case SPELLABILITY_FEROCITY_2:
case SPELLABILITY_FEROCITY_3:
case SPELL_BLOOD_FRENZY:
AI_SetWeHaveSpellsEffect(GlobalHasRageSpells);
break;
}
}
}
break;
}
eCheck = GetNextEffect(oTarget);
}
// If undead, set some immunities by default
if(GetRacialType(oTarget) == RACIAL_TYPE_UNDEAD)
{
AI_SetWeHaveSpellsEffect(GlobalHasDeathWardSpell);
}
DeleteLocalInt(oTarget, AI_ABILITY_DECREASE);
DeleteLocalInt(oTarget, AI_EFFECT_HEX);
DeleteLocalInt(oTarget, AI_SPELL_HEX);
// Set final ones from temp integers
SetLocalInt(oTarget, AI_ABILITY_DECREASE, iEffectAbilityDecrease);
SetLocalInt(oTarget, AI_EFFECT_HEX, TempEffectHex);
SetLocalInt(oTarget, AI_SPELL_HEX, TempSpellHex);
}