FunkySwerve

ac_aoeper_inc

Mar 17th, 2014
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.95 KB | None | 0 0
  1. #include "hg_inc"
  2. #include "ac_spell_inc"
  3.  
  4. int GetIsHeraldAoE(object oAoE) {
  5.     string sTag = GetTag(oAoE);
  6.     if (sTag == "VFX_PER_FOGFREEZE"     ||
  7.         sTag == "VFX_AOE_CONSECRATE_20" ||
  8.         sTag == "VFX_PER_FOGACID"       ||
  9.         sTag == "VFX_PER_FOGKILL"       ||
  10.         sTag == "VFX_PER_FOGMIND"       ||
  11.         sTag == "VFX_PER_FOGSTINK")
  12.         return TRUE;
  13.  
  14.     return FALSE;
  15. }
  16.  
  17. struct SpellInfo GetPersistentAoESpellInfo ();
  18. #pragma default_function(GetPersistentAoESpellInfo)
  19. int GetPersistentAoELimit (struct SpellInfo si);
  20. #pragma default_function(GetPersistentAoELimit)
  21. int GetPersistentAoEEffect (struct SpellInfo si);
  22. #pragma default_function(GetPersistentAoEEffect)
  23. string GetPersistentAoETag (struct SpellInfo si);
  24. #pragma default_function(GetPersistentAoETag)
  25. string GetPersistentAoEName (struct SpellInfo si);
  26. #pragma default_function(GetPersistentAoEName)
  27. int GetPersistentAoETargetMask (struct SpellInfo si);
  28. #pragma default_function(GetPersistentAoETargetMask)
  29. int GetPersistentAoETargetType (struct SpellInfo si);
  30. #pragma default_function(GetPersistentAoETargetType)
  31. object GetPersistentAoEPlaceable (struct SpellInfo si);
  32. #pragma default_function(GetPersistentAoEPlaceable)
  33.  
  34. float GetPersistentAoEDuration (struct SpellInfo si);
  35. #pragma default_function(GetPersistentAoEDuration)
  36.  
  37. effect GetPersistentAoEImpactEffect (struct SpellInfo si);
  38. #pragma default_function(GetPersistentAoEImpactEffect)
  39. effect GetPersistentAoEDurationEffect (struct SpellInfo si);
  40. #pragma default_function(GetPersistentAoEDurationEffect)
  41. effect GetPersistentAoEVisualEffect (struct SpellInfo si);
  42. #pragma default_function(GetPersistentAoEVisualEffect)
  43.  
  44.  
  45. void ApplyAoEEffect (struct SpellInfo si, object oAoE, object oTarget, effect eEff, effect eDur, effect eVis);
  46. #pragma default_function(ApplyAoEEffect)
  47.  
  48. float GetPersistentAoERemaining (object oAoE) {
  49.     int nRemaining = GetLocalInt(oAoE, "AoEExpires") - GetLocalInt(GetModule(), "uptime");
  50.  
  51.     return IntToFloat(nRemaining < 1 ? 1 : nRemaining);
  52. }
  53.  
  54.  
  55. void DoAoEHeartbeat (struct SpellInfo si, object oAoE, effect eEff, effect eDur, effect eVis, object oPlace) {
  56.     int bDestroy = FALSE, bAllPCs = FALSE;
  57.  
  58.     if (!GetIsObjectValid(oAoE)) {
  59.         SetPlotFlag(oPlace, FALSE);
  60.         DestroyObject(oPlace);
  61.         return;
  62.     }
  63.  
  64.  
  65.     /* Storm of Vengeance doesn't destroy properly sometimes */
  66.     if (GetPersistentAoEEffect(si) == AOE_PER_STORM) {
  67.         if (si.id == SPELL_STORM_OF_VENGEANCE && GetLocalInt(GetArea(oAoE), "Area_Underwater"))
  68.             bAllPCs = TRUE;
  69.  
  70.         if (GetLocalInt(GetModule(), "uptime") > GetLocalInt(oAoE, "AoEExpires"))
  71.             bDestroy = TRUE;
  72.     }
  73.  
  74.     if (bDestroy                     ||
  75.         !GetIsObjectValid(si.caster) ||
  76.         GetIsDead(si.caster)         ||
  77.         GetArea(si.caster) != si.area) {
  78.  
  79.         SetPlotFlag(oAoE, FALSE);
  80.         SetPlotFlag(oPlace, FALSE);
  81.         DestroyObject(oAoE);
  82.         DestroyObject(oPlace);
  83.         return;
  84.     }
  85.  
  86.     DelayCommand(6.0, DoAoEHeartbeat(si, oAoE, eEff, eDur, eVis, oPlace));
  87.     AddLocalInt(oAoE, "AoERounds", 1);
  88.  
  89.     if (!LineOfSightObject(oAoE, si.caster))
  90.         return;
  91.  
  92.  
  93.     si.target = oAoE;
  94.     int nMask = GetPersistentAoETargetMask(si);
  95.     int nType = GetPersistentAoETargetType(si);
  96.  
  97.     for (si.target = GetFirstInPersistentObject(oAoE, nMask);
  98.          GetIsObjectValid(si.target);
  99.          si.target = GetNextInPersistentObject(oAoE, nMask)) {
  100.  
  101.         if (GetIsSpellTarget(si, si.target, nType) || (bAllPCs && GetIsPC(si.target))) {
  102.             if (nType == TARGET_TYPE_ALLY)
  103.                 SignalEvent(si.target, EventSpellCastAt(si.caster, si.id, FALSE));
  104.             else
  105.                 SignalEvent(si.target, EventSpellCastAt(si.caster, si.id));
  106.  
  107.             AssignCommand(si.caster, DelayCommand(GetRandomDelay(0.5, 4.5), ApplyAoEEffect(si, oAoE, si.target, eEff, eDur, eVis)));
  108.         }
  109.     }
  110. }
  111.  
  112. void StartAoEHeartbeat (struct SpellInfo si, string sTag, effect eEff, effect eDur, effect eVis, object oPlace, int nUntil, int nLimit) {
  113.     int nCount = 1;
  114.     object oLoc, oAoE;
  115.  
  116.     do {
  117.         oLoc = GetNearestObjectToLocation(OBJECT_TYPE_ALL, si.loc, nCount++);
  118.     } while (GetTag(oLoc) == sTag);
  119.  
  120.     nCount = 1;
  121.     oAoE = GetNearestObjectByTag(sTag, oLoc);
  122.  
  123.     while (GetIsObjectValid(oAoE)) {
  124.         if (GetAreaOfEffectCreator(oAoE) == si.caster && !GetLocalInt(oAoE, "AoEHeartbeat")) {
  125.  
  126.             SetLocalInt(oAoE, "AoEHeartbeat", 1);
  127.             SetLocalInt(oAoE, "AoEExpires", nUntil);
  128.             SetLocalInt(oAoE, "AoESpellId", si.id);
  129.             SetLocalInt(oAoE, "AoESP", si.sp);
  130.  
  131.             if ((si.id >= HGSPELL_FONT_OF_VISION        &&
  132.                  si.id <= HGSPELL_FONT_OF_PURIFICATION) ||
  133.                  si.id == HGSPELL_FONT_OF_THAUMATURGY)
  134.                 SetLocalInt(oAoE, "NoGust", 1);
  135.  
  136.             if (nLimit == -2)
  137.                 SetLocalInt(oAoE, "AoEDispelResistance", 25);
  138.  
  139.             DelayCommand(0.0, DoAoEHeartbeat(si, oAoE, eEff, eDur, eVis, oPlace));
  140.             return;
  141.         }
  142.  
  143.         oAoE = GetNearestObjectByTag(sTag, oLoc, ++nCount);
  144.     }
  145. }
  146.  
  147. void main () {
  148.     struct SpellInfo si = GetPersistentAoESpellInfo();
  149.     if (si.id < 0)
  150.         return;
  151.  
  152.     float fDur  = GetPersistentAoEDuration(si);
  153.     string sTag = GetPersistentAoETag(si);
  154.     effect eAoE = EffectAreaOfEffect(GetPersistentAoEEffect(si),
  155.         (si.id == SPELL_GREASE ? "nw_s0_greasea" : "****"), "****", "****");
  156.  
  157.  
  158.     int nLimit = GetPersistentAoELimit(si);
  159.  
  160.     if (nLimit > 0) {
  161.         int nFound = 0, nCount = 1;
  162.         object oOther, oCreator, oArea = GetArea(si.caster);
  163.  
  164.         while (GetIsObjectValid(oOther = GetNearestObjectByTag(sTag, si.caster, nCount++))) {
  165.             oCreator = GetAreaOfEffectCreator(oOther);
  166.             if (oCreator == oArea || GetLocalInt(oOther, "NoAoEDispel"))
  167.                 continue;
  168.  
  169.             if (GetIsPC(si.caster) && GetIsPC(oCreator)) {
  170.                 if (GetIsHeraldAoE(oOther)) {
  171.                     if (!GetIsQuasiclass(QUASICLASS_HERALD_OF_STORMS, oCreator))
  172.                         nFound++;
  173.                 } else
  174.                     nFound++;
  175.             } else if (GetFactionEqual(si.caster, oCreator)) {
  176.                 nFound++;
  177.             }
  178.  
  179.             if (nFound >= nLimit) {
  180.                 object oPlace = GetLocalObject(oOther, "AoEPlaceable");
  181.  
  182.                 SetPlotFlag(oOther, FALSE);
  183.                 SetPlotFlag(oPlace, FALSE);
  184.                 DestroyObject(oOther);
  185.                 DestroyObject(oPlace);
  186.  
  187.                 if (nFound == nLimit)
  188.                     FloatingTextStringOnCreature("To prevent lag, only " +
  189.                         IntToString(nLimit) + " " + GetPersistentAoEName(si) +
  190.                         " spell" + (nLimit == 1 ? "" : "s") + " may exist in an area at the same time.", si.caster);
  191.             }
  192.         }
  193.     } else if (nLimit == -1) {
  194.         object oOther, oCreator, oArea = GetArea(si.caster);
  195.         string sAoETag;
  196.         for (oOther = GetFirstObjectInArea(oArea); GetIsObjectValid(oOther); oOther = GetNextObjectInArea(oArea)) {
  197.  
  198.             oCreator = GetAreaOfEffectCreator(oOther);
  199.             if (GetObjectType(oOther) != OBJECT_TYPE_AREA_OF_EFFECT ||
  200.                 oCreator != si.caster)
  201.                 continue;
  202.  
  203.             if (GetIsQuasiclass(QUASICLASS_HERALD_OF_STORMS, oCreator) && //heralds ignore herald spells in this check - that limit handled in -2
  204.                 GetIsHeraldAoE(oOther))
  205.                 continue;
  206.  
  207.             sAoETag = GetTag(oOther);
  208.             if (GetLocalInt(si.caster, "DebugSpells"))
  209.                 FloatingTextStringOnCreature("AoE Tag: " + sAoETag, si.caster, FALSE);
  210.  
  211.             if (FindSubString(" VFX_PER_FOGACID VFX_PER_FOGFIRE VFX_PER_FOGFREEZE VFX_PER_STORM VFX_PER_RAINFIRE VFX_PER_RAINFREEZE VFX_AOE_CONSECRATE_20 VFX_MOB_MENACE ",
  212.                               " " + sAoETag + " ") >= 0) {
  213.                 object oPlace = GetLocalObject(oOther, "AoEPlaceable");
  214.  
  215.                 SetPlotFlag(oOther, FALSE);
  216.                 SetPlotFlag(oPlace, FALSE);
  217.                 DestroyObject(oOther);
  218.                 DestroyObject(oPlace);
  219.  
  220.                 FloatingTextStringOnCreature("Only one area of effect damage field may exist per caster in an area at the same time.", si.caster);
  221.             }
  222.         }
  223.     } else if (nLimit == -2) {
  224.         object oOther, oArea = GetArea(si.caster);
  225.         int nFound;
  226.  
  227.         for (oOther = GetFirstObjectInArea(oArea); GetIsObjectValid(oOther); oOther = GetNextObjectInArea(oArea)) {
  228.             if (GetObjectType(oOther) != OBJECT_TYPE_AREA_OF_EFFECT ||
  229.                 !GetIsQuasiclass(QUASICLASS_HERALD_OF_STORMS, GetAreaOfEffectCreator(oOther)))
  230.                 continue;
  231.  
  232.             if (FindSubString(" VFX_PER_FOGACID VFX_PER_FOGSTINK VFX_PER_FOGKILL VFX_AOE_CONSECRATE_20 VFX_PER_FOGFREEZE VFX_PER_FOGMIND ",
  233.                               " " + GetTag(oOther) + " ") >= 0) {
  234.                 nFound++;
  235.                 if (nFound >= 2) {
  236.                     object oPlace = GetLocalObject(oOther, "AoEPlaceable");
  237.  
  238.                     SetPlotFlag(oOther, FALSE);
  239.                     SetPlotFlag(oPlace, FALSE);
  240.                     DestroyObject(oOther);
  241.                     DestroyObject(oPlace);
  242.  
  243.                     if (nFound == 2)
  244.                         FloatingTextStringOnCreature("Only two herald of storms clouds may exist in an area at the same time.", si.caster);
  245.                 }
  246.             }
  247.         }
  248.     }
  249.  
  250.  
  251.     effect eEff = GetPersistentAoEImpactEffect(si);
  252.     effect eDur = GetPersistentAoEDurationEffect(si);
  253.     effect eVis = GetPersistentAoEVisualEffect(si);
  254.     object oPlace = GetPersistentAoEPlaceable(si);
  255.  
  256.     AssignCommand(si.area, DelayCommand(2.0, StartAoEHeartbeat(si, sTag, eEff, eDur, eVis, oPlace,
  257.         GetLocalInt(GetModule(), "uptime") + FloatToInt(fDur), nLimit)));
  258.  
  259.     ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eAoE, si.loc, fDur);
  260. }
Advertisement
Add Comment
Please, Sign In to add comment