Here's the PRC function. I tried to optimize it a bit but it's still far from being perfect. It checks for item metamagic and it's also used for sudden metamagic, divine metamagic and some class feats. Some of them stack

int PRCGetMetaMagicFeat(object oCaster = OBJECT_SELF, int bClearFeatFlags = TRUE)
{[list]
int nOverride = GetLocalInt(oCaster, PRC_METAMAGIC_OVERRIDE);
if(nOverride)
{[list]
if (DEBUG) DoDebug("PRCGetMetaMagicFeat: found override metamagic = "+IntToString(nOverride)+", original = "+IntToString(GetMetaMagicFeat()));
return nOverride;
[/list]}
object oItem = PRCGetSpellCastItem(oCaster);
// we assume that we are casting from an item, if the item is valid and the item belongs to oCaster
// however, we cannot be sure because of Bioware's inadequate implementation of GetSpellCastItem
if(GetIsObjectValid(oItem) && GetItemPossessor(oItem) == oCaster)
{[list]
int nFeat;
//check item for metamagic
itemproperty ipTest = GetFirstItemProperty(oItem);
while(GetIsItemPropertyValid(ipTest))
{[list]
if(GetItemPropertyType(ipTest) == ITEM_PROPERTY_CAST_SPELL_METAMAGIC)
{[list]
int nSubType = GetItemPropertySubType(ipTest);
nSubType = StringToInt(Get2DACache("iprp_spells", "SpellIndex", nSubType));
if(nSubType == PRCGetSpellId(oCaster))
{[list]
int nCostValue = GetItemPropertyCostTableValue(ipTest);
if(nCostValue == -1 && DEBUG)
DoDebug("Problem examining itemproperty");
switch(nCostValue)
{[list]
//bitwise "addition" equivalent to nFeat = (nFeat | nSSFeat)
case 1: nFeat |= METAMAGIC_QUICKEN; break;
case 2: nFeat |= METAMAGIC_EMPOWER; break;
case 3: nFeat |= METAMAGIC_EXTEND; break;
case 4: nFeat |= METAMAGIC_MAXIMIZE; break;
case 5: nFeat |= METAMAGIC_SILENT; break;
case 6: nFeat |= METAMAGIC_STILL; break;
[/list]}
[/list]}
[/list]}
ipTest = GetNextItemProperty(oItem);
[/list]}
if (DEBUG) DoDebug("PRCGetMetaMagicFeat: item casting with item = "+GetName(oItem)+", found metamagic = "+IntToString(nFeat));
//Hellfire Infusion - doesn't work on scrolls and potions
int nType = GetBaseItemType(oItem);
if(nType != BASE_ITEM_POTIONS && nType != BASE_ITEM_ENCHANTED_POTION
&& nType != BASE_ITEM_SCROLL && nType != BASE_ITEM_ENCHANTED_SCROLL)
{[list]
nFeat |= GetLocalInt(oCaster, "PRC_HF_Infusion");
if(bClearFeatFlags) DeleteLocalInt(oCaster, "PRC_HF_Infusion");
[/list]}
//apply metamagic adjustment (chanell spell)
nFeat |= GetLocalInt(oCaster, PRC_METAMAGIC_ADJUSTMENT);
return nFeat;
[/list]}
if(GetLocalInt(oCaster, "PRC_SPELL_EVENT"))
{[list]
if (DEBUG) DoDebug("PRCGetMetaMagicFeat: found spell event metamagic = "+IntToString(GetLocalInt(oCaster, "PRC_SPELL_METAMAGIC"))+", original = "+IntToString(GetMetaMagicFeat()));
return GetLocalInt(oCaster, "PRC_SPELL_METAMAGIC");
[/list]}
int nFeat = GetMetaMagicFeat();
if(nFeat == METAMAGIC_ANY)
// work around for spontaneous casters (bard or sorcerer) having all metamagic turned on when using ActionCastSpell*
nFeat = METAMAGIC_NONE;
nFeat |= GetLocalInt(oCaster, PRC_METAMAGIC_ADJUSTMENT);
int nclass = PRCGetLastSpellCastclass(oCaster);
// Suel Archanamach's Extend spells they cast on themselves.
// Only works for Suel Spells, and not any other caster type they might have
// Since this is a spellscript, it assumes OBJECT_SELF is the caster
if(nclass == class_TYPE_SUEL_ARCHANAMACH
&& GetLevelByclass(class_TYPE_SUEL_ARCHANAMACH) >= 3)
{[list]
// Check that they cast on themselves
// if (oCaster == PRCGetSpellTargetObject())
if(oCaster == PRCGetSpellTargetObject(oCaster))
{[list]
// Add extend to the metamagic feat using bitwise math
nFeat |= METAMAGIC_EXTEND;
[/list]}
[/list]}
// Magical Contraction, Truenaming Utterance
if(GetHasSpellEffect(UTTER_MAGICAL_CONTRACTION_R, oCaster))
//(GetLocalInt(oCaster, "TrueMagicalContraction"))
{[list]
nFeat |= METAMAGIC_EMPOWER;
[/list]}
// Sudden Metamagic
int nSuddenMeta = GetLocalInt(oCaster, "SuddenMeta");
if(nSuddenMeta)
{[list]
nFeat |= nSuddenMeta;
if(bClearFeatFlags)
DeleteLocalInt(oCaster, "SuddenMeta");
[/list]}
int nDivMeta = GetLocalInt(oCaster, "DivineMeta");
if(nDivMeta)
{[list]
if(GetIsDivineclass(nclass, oCaster))
{[list]
nFeat |= nDivMeta;
if(bClearFeatFlags)
DeleteLocalInt(oCaster, "DivineMeta");
[/list]}
[/list]}
// if (DEBUG) DoDebug("PRCGetMetaMagicFeat: returning " +IntToString(nFeat));
return nFeat;
[/list]}
Modifié par Alex Warren, 09 juin 2012 - 06:37 .