rendered paste body#include "nw_i0_spells"
#include "x2_i0_spells"
#include "x2_inc_spellhook"
void main()
{
if (!X2PreSpellCastCode()) //for spellhooking
return;
int bLv10cap = TRUE;
//set to TRUE for the better system with 1 additional damage every level until level 10
//set to FALSE for the old system with 1 additional damage every 2 levels until level 20
int nDamType = IP_CONST_DAMAGETYPE_FIRE;
int nItemEffect = ITEM_VISUAL_FIRE;
int nVisEffect2 = VFX_IMP_PULSE_FIRE;
int nVisEffect1 = VFX_IMP_FLAME_M;
effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
int nCasterLvl = GetCasterLevel(OBJECT_SELF);
int nDuration = 2 * nCasterLvl;
int nMetaMagic = GetMetaMagicFeat();
object oTarget = GetSpellTargetObject();
if (nMetaMagic == METAMAGIC_EXTEND)
nDuration = nDuration * 2; //Duration is +100%
float fDuration = TurnsToSeconds(nDuration);
if (bLv10cap == FALSE)
{
if(nCasterLvl > 20) //cap at lv 20, old system
nCasterLvl = 20;
nCasterLvl = FloatToInt(nCasterLvl / 2.0);
}
else if (nCasterLvl > 10) //cap at lv 10, was intended so from beginning on
nCasterLvl = 10;
int nDamConst = 3 + nCasterLvl; //3 for "variable" damage (1d6), lv for add damage
if (GetLastSpellCastClass() != CLASS_TYPE_CLERIC) //if sorc/wiz -> flameweapon
nDamConst -= 1; //if wiz/sorc (1d4) -> 2 (1 less than cleric (1d6))
//see iprp_damagecost.2da (because of bad table setup)
//const 1-5 = 1-5 damage, const 16-30 = 6-20 damage, const 6-15 variable damage
if (nDamConst > 5)
nDamConst += 10;
object oMyWeapon; //replaced original for my little improved check
if (IPGetIsMeleeWeapon(oTarget)) //is weapon
oMyWeapon = oTarget;
else if (GetCreatureSize(oTarget) != CREATURE_SIZE_INVALID) //is creature
{
object oRightWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oTarget);
if (IPGetIsMeleeWeapon(oRightWeapon)) //has melee weapon in hand
oMyWeapon = oRightWeapon;
else //sometimes players unequip weapon just before spell is cast at, this is a fix
{
oMyWeapon = GetLastWeaponUsed(oTarget);
if (!IPGetIsMeleeWeapon(oMyWeapon)) //last weapon is no melee weapon (blind caster?)
oMyWeapon = OBJECT_INVALID;
}
}
else //is no creature or player
oMyWeapon = OBJECT_INVALID;
if(GetIsObjectValid(oMyWeapon) )
{
itemproperty ipLoop=GetFirstItemProperty(oMyWeapon);
while (GetIsItemPropertyValid(ipLoop)) //because same damage types don`t stack
{
if (GetItemPropertyType(ipLoop) == ITEM_PROPERTY_DAMAGE_BONUS)
{
if (GetItemPropertyDurationType(ipLoop) == DURATION_TYPE_PERMANENT)
{
int nSubType = GetItemPropertySubType(ipLoop);
if (nSubType == nDamType) //apply different damage if weapon already has the same
{
nDamType = IP_CONST_DAMAGETYPE_ELECTRICAL;
nItemEffect = ITEM_VISUAL_ELECTRICAL;
nVisEffect2 = VFX_IMP_PULSE_WIND;
nVisEffect1 = VFX_IMP_LIGHTNING_S;
}//if subtype
}//if permanent
}//if bonus
ipLoop=GetNextItemProperty(oMyWeapon);
}//while
effect eVis1 = EffectVisualEffect(nVisEffect1);
effect eVis2 = EffectVisualEffect(nVisEffect2);
effect eVis = EffectLinkEffects(eVis1 ,eVis2);
SignalEvent(GetItemPossessor(oMyWeapon), EventSpellCastAt(OBJECT_SELF, GetSpellId(), FALSE));
if (nDuration>0)
{
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, GetItemPossessor(oMyWeapon));
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eDur, GetItemPossessor(oMyWeapon), fDuration);
itemproperty ipElemDam = ItemPropertyDamageBonus(nDamType, nDamConst);
IPSafeAddItemProperty(oMyWeapon, ipElemDam, fDuration, X2_IP_ADDPROP_POLICY_REPLACE_EXISTING);
itemproperty ipElemVis = ItemPropertyVisualEffect(nItemEffect);
IPSafeAddItemProperty(oMyWeapon, ipElemVis, fDuration, X2_IP_ADDPROP_POLICY_REPLACE_EXISTING,FALSE,TRUE);
}//if duration
}//if valid
else
FloatingTextStrRefOnCreature(83615, OBJECT_SELF);
}//by Master Lexx