Advertisement
Terrah

dispel

Jan 26th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.07 KB | None | 0 0
  1. //oCaster makes a dispel check vs oTargets spells
  2. void DoDispelCheck(object oCaster, object oTarget, int nCasterLevel, int nMaxSpells);
  3.  
  4. //Used to determine the casterlevel nSpell should have when cast by oTarget
  5. int GetCasterLevelForSpell(object oTarget, int nSpell);
  6.  
  7. int GetCasterLevelForSpell(object oTarget, int nSpell){
  8.  
  9.     return GetCasterLevel(oTarget);
  10. }
  11.  
  12. void DoFeedback(object oCaster, object oTarget, int nRoll, int nCL, int nVs, int nSpell){
  13.  
  14.     if(!GetIsPC(oCaster) && !GetIsPC(oTarget)){
  15.         return;
  16.     }
  17.  
  18.     string sSpellName = GetStringByStrRef(StringToInt(Get2DAString("spells", "name", nSpell)));
  19.    
  20.     string sMessage = "<color=aqua>["+sSpellName+"]</color><color=white> D20 "+IntToString(nRoll)+" + " +IntToString(nCL) + " = "+IntToString(nRoll+nCL)+" vs: " + IntToString(nVs)+ "</color> ";
  21.    
  22.     if(nRoll + nCL > nVs){
  23.         sMessage += "<color=green>Dispelled</color>";
  24.     }
  25.     else{
  26.         sMessage += "<color=red>Not Dispelled</color>";
  27.     }
  28.    
  29.     if(GetIsPC(oCaster))
  30.         SendMessageToPC(oCaster, sMessage);
  31.        
  32.     if(GetIsPC(oTarget) && oCaster != oTarget)
  33.         SendMessageToPC(oTarget, sMessage);
  34. }
  35.  
  36. int Contains(object oObj, int nCnt, int nSpell, object oOwn){
  37.  
  38.     int n;
  39.     for(n=0;n<nCnt;n++){
  40.         if(GetLocalInt(oObj, "disp_spell_"+IntToString(n)) == nSpell &&
  41.         GetLocalObject(oObj, "disp_owner_"+IntToString(n)) == oOwn){
  42.             return TRUE;
  43.         }
  44.     }
  45.    
  46.     return FALSE;
  47. }
  48.  
  49. void DoDispelCheck(object oCaster, object oTarget, int nCasterLevel, int nMaxSpells){
  50.  
  51.     int nLast=-1;
  52.     object oLast=OBJECT_INVALID;
  53.     int nCnt = 0;
  54.     effect eEffect = GetFirstEffect(oTarget);
  55.     while(GetIsEffectValid(eEffect)){
  56.    
  57.         if(GetEffectSubType(eEffect) == SUBTYPE_MAGICAL && !Contains(oCaster, nCnt, GetEffectSpellId(eEffect), GetEffectCreator(eEffect)) ){
  58.            
  59.             nLast = GetEffectSpellId(eEffect);
  60.             oLast = GetEffectCreator(eEffect);
  61.            
  62.             SetLocalInt(oCaster, "disp_spell_"+IntToString(nCnt), nLast);
  63.             SetLocalObject(oCaster, "disp_owner_"+IntToString(nCnt), oLast);
  64.  
  65.             nCnt++;
  66.         }
  67.    
  68.         eEffect = GetNextEffect(oTarget);
  69.     }
  70.    
  71.     int n, nRoll, nEffectCL;
  72.     int nSuccesses=0;
  73.     for(n=0;n<nCnt;n++){
  74.    
  75.         nLast = GetLocalInt(oCaster, "disp_spell_"+IntToString(n));
  76.         oLast = GetLocalObject(oCaster, "disp_owner_"+IntToString(n));
  77.        
  78.         DeleteLocalInt(oCaster, "disp_spell_"+IntToString(n));
  79.         DeleteLocalObject(oCaster, "disp_owner_"+IntToString(n));
  80.  
  81.         //Only dispel spells as long as we got allowed spells and said spell is a spell, otherwise only do cleanup
  82.         if(nLast > -1 && (nMaxSpells <= 0 || nSuccesses < nMaxSpells)){
  83.        
  84.             nRoll = d20();
  85.             nEffectCL = GetCasterLevelForSpell(oLast, nLast);
  86.            
  87.             DoFeedback(oCaster, oTarget, nRoll, nCasterLevel, 11 + nEffectCL, nLast);
  88.            
  89.             if(nRoll + nCasterLevel > 11 + nEffectCL){
  90.            
  91.                 nSuccesses++;
  92.            
  93.                 eEffect = GetFirstEffect(oTarget);
  94.                 while(GetIsEffectValid(eEffect)){
  95.        
  96.                     if(GetEffectSubType(eEffect) == SUBTYPE_MAGICAL && GetEffectSpellId(eEffect) == nLast && GetEffectCreator(eEffect) == oLast){
  97.                        
  98.                         RemoveEffect(oTarget, eEffect);
  99.                     }
  100.                
  101.                     eEffect = GetNextEffect(oTarget);
  102.                 }
  103.             }
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement