[refused] Charge/SpeedofRealm Stack fix

A place to submit .patch fixes for the DOL SVN

Moderator: Developer Team

[refused] Charge/SpeedofRealm Stack fix

Postby bryon » Mon Jun 07, 2010 9:07 pm

realmabilitys/effects/ChargeEffect.CS

Code: Select all



using System;
using System.Collections;
using System.Collections.Generic;

using DOL.AI.Brain;
using DOL.GS.PacketHandler;

namespace DOL.GS.Effects
{

   public class ChargeEffect : StaticEffect, IGameEffect
   {
      protected const String delveString = "Grants unbreakable speed 3 for 15 second duration. Grants immunity to roots, stun, snare and mesmerize spells. Target will still take damage from snare/root spells that do damage.";
      GameLiving m_living;
      protected long m_startTick;
      protected RegionTimer m_expireTimer;

      public override void Start(GameLiving living)
      {
         m_living = living;
         //Send messages
         if (m_living is GamePlayer)
         {
            ((GamePlayer)m_living).Out.SendMessage("You begin to charge wildly!", eChatType.CT_Spell, eChatLoc.CL_SystemWindow);
         }
         else if (m_living is GameNPC)
         {
            IControlledBrain icb = ((GameNPC)m_living).Brain as IControlledBrain;
            if (icb != null && icb.Body != null)
            {
               GamePlayer playerowner = icb.GetPlayerOwner();

               if (playerowner != null)
               {
                  playerowner.Out.SendMessage("The " + icb.Body.Name + " charges its prey!", eChatType.CT_Say, eChatLoc.CL_SystemWindow);
               }
            }
         }
         else
            return;
         
         m_startTick = living.CurrentRegion.Time;
         foreach (GamePlayer t_player in living.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE))
         {
            t_player.Out.SendSpellEffectAnimation(living, living, 7035, 0, false, 1);
         }

         //sets player into combat mode
            living.LastAttackTickPvP = living.CurrentRegion.Time;
         ArrayList speedSpells = new ArrayList();
         lock(living.EffectList)
         {
            foreach (IGameEffect effect in living.EffectList)
            {
               if (effect is GameSpellEffect == false) continue;
               if ((effect as GameSpellEffect).Spell.SpellType == "SpeedEnhancement")
                  speedSpells.Add(effect);
                    if ((effect as GameSpellEffect).Spell.SpellType == "SpeedOfTheRealm")
                        speedSpells.Add(effect);
            }
         }
         foreach (GameSpellEffect spell in speedSpells)
            spell.Cancel(false);



         m_living.BuffBonusMultCategory1.Set((int)eProperty.MaxSpeed, this, PropertyCalc.MaxSpeedCalculator.SPEED3);
         m_living.TempProperties.setProperty("Charging", true);
         if (m_living is GamePlayer)
            ((GamePlayer)m_living).Out.SendUpdateMaxSpeed();
         StartTimers();
         m_living.EffectList.Add(this);

      }

      public override void Cancel(bool playerCancel)
      {
         m_living.TempProperties.removeProperty("Charging");
         m_living.EffectList.Remove(this);
         m_living.BuffBonusMultCategory1.Remove((int)eProperty.MaxSpeed, this);
         //Send messages
         if (m_living is GamePlayer)
         {
            GamePlayer player = m_living as GamePlayer;
            player.Out.SendUpdateMaxSpeed();
            player.Out.SendMessage("You no longer seem so crazy!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
         }
         else if (m_living is GameNPC)
         {
            IControlledBrain icb = ((GameNPC)m_living).Brain as IControlledBrain;
            if (icb != null && icb.Body != null)
            {
               GamePlayer playerowner = icb.GetPlayerOwner();

               if (playerowner != null)
               {
                  playerowner.Out.SendMessage("The " + icb.Body.Name + " ceases its charge!", eChatType.CT_Say, eChatLoc.CL_SystemWindow);
               }
            }
         }
         StopTimers();
      }

      protected virtual void StartTimers()
      {
         StopTimers();
         m_expireTimer = new RegionTimer(m_living, new RegionTimerCallback(ExpiredCallback), RealmAbilities.ChargeAbility.DURATION * 1000);
      }


      // Stops the timers for this effect
      protected virtual void StopTimers()
      {
         if (m_expireTimer != null)
         {
            m_expireTimer.Stop();
            m_expireTimer = null;
         }
      }


      // The callback method when the effect expires
      protected virtual int ExpiredCallback(RegionTimer timer)
      {
         Cancel(false);
         return 0;
      }


      // Name of the effect
      public override string Name { get { return "Charge"; } }


      /// <summary>
      /// Remaining time of the effect in milliseconds
      /// </summary>
      public override Int32 RemainingTime
      {
         get
         {
            RegionTimer timer = m_expireTimer;
            if (timer == null || !timer.IsAlive)
               return 0;
            return timer.TimeUntilElapsed;
         }
      }


      // Icon to show on players, can be id
      public override ushort Icon
      {
         get
         {
            if (m_living is GameNPC) return 411;
            else return 3034;
         }
      }

      // Delve Info
      public override IList<string> DelveInfo
      {
         get
         {
            var delveInfoList = new List<string>(4);
            delveInfoList.Add(delveString);

            int seconds = (int)(RemainingTime / 1000);
            if (seconds > 0)
            {
               delveInfoList.Add(" "); //empty line
               if (seconds > 60)
                  delveInfoList.Add("- " + seconds / 60 + ":" + (seconds % 60).ToString("00") + " minutes remaining.");
               else
                  delveInfoList.Add("- " + seconds + " seconds remaining.");
            }

            return delveInfoList;
         }
      }
   }
}





ADDED:

Code: Select all

if ((effect as GameSpellEffect).Spell.SpellType == "SpeedOfTheRealm")
                        speedSpells.Add(effect);



May not be the correct fix. But it does the job.

I fixed it for thid international. shared for everyone.
Project Silodaira -
Ports and Jump points √
Ladder √
Dungeons √
Zone Population ~
User avatar
bryon
DOL Expert
 
Posts: 601
Joined: Tue May 01, 2007 6:42 am
Location: Albion, Dark age of Camelot

Re: Charge/SpeedofRealm Stack fix

Postby Tinantiol » Mon Jun 07, 2010 9:20 pm

I don't think they should stack.... on charge activation speed of realm should be removed if i remember well
Drydruid Druid 10l4 (Deira off)
Driwyth Shadowblade 9l6 (Deira Off)
Dryinfiwyth Infiltrator 5l6 (Deira off)

Drywyth Cleric 11l7 (Eden)
Dryywyth Druid 11l7 (Eden)
Dryywyyth Bard 11l7 (Eden)
Dryywyith Shaman 11l7 (Eden)
http://genesis-daoc.forums-free.com/
Tinantiol
DOL Devotee
 
Posts: 380
Joined: Sat May 09, 2009 10:33 am
Website: http://genesis-daoc.forums-free.com/
Location: Gaeta, Italy

Re: Charge/SpeedofRealm Stack fix

Postby bryon » Mon Jun 07, 2010 9:25 pm

well it doesnt on the latest source.. lol so this is what i came up with to fix it lol
Project Silodaira -
Ports and Jump points √
Ladder √
Dungeons √
Zone Population ~
User avatar
bryon
DOL Expert
 
Posts: 601
Joined: Tue May 01, 2007 6:42 am
Location: Albion, Dark age of Camelot

Re: Charge/SpeedofRealm Stack fix

Postby Tinantiol » Mon Jun 07, 2010 9:45 pm

bryon wrote:well it doesnt on the latest source.. lol so this is what i came up with to fix it lol

you ADDED the speed of realm, not removed....
Drydruid Druid 10l4 (Deira off)
Driwyth Shadowblade 9l6 (Deira Off)
Dryinfiwyth Infiltrator 5l6 (Deira off)

Drywyth Cleric 11l7 (Eden)
Dryywyth Druid 11l7 (Eden)
Dryywyyth Bard 11l7 (Eden)
Dryywyith Shaman 11l7 (Eden)
http://genesis-daoc.forums-free.com/
Tinantiol
DOL Devotee
 
Posts: 380
Joined: Sat May 09, 2009 10:33 am
Website: http://genesis-daoc.forums-free.com/
Location: Gaeta, Italy

Re: Charge/SpeedofRealm Stack fix

Postby bryon » Mon Jun 07, 2010 9:54 pm

well it removes it in game lol
Project Silodaira -
Ports and Jump points √
Ladder √
Dungeons √
Zone Population ~
User avatar
bryon
DOL Expert
 
Posts: 601
Joined: Tue May 01, 2007 6:42 am
Location: Albion, Dark age of Camelot

Re: Charge/SpeedofRealm Stack fix

Postby bryon » Mon Jun 07, 2010 10:04 pm

well i dunno lol i didnt write this script originally so i dont know.. when its set to remove it doesnt remove it.. when its set to add it removes it with no errors.. so maybe it has to be added to be removed correctly lol. but when its not there it doesnt add it so i dont see the problem haha
Project Silodaira -
Ports and Jump points √
Ladder √
Dungeons √
Zone Population ~
User avatar
bryon
DOL Expert
 
Posts: 601
Joined: Tue May 01, 2007 6:42 am
Location: Albion, Dark age of Camelot

Re: Charge/SpeedofRealm Stack fix

Postby geshi » Tue Jun 08, 2010 10:47 am

You have

ArrayList speedSpells = new ArrayList();

You then add "speedSpells.Add(effect);"

So you're adding an effect to an ArrayList then you are going through that ArrayList and cancelling the spell.

You could just do

Code: Select all
         lock(living.EffectList)
         {
            foreach (IGameEffect effect in living.EffectList)
            {
               if (effect is GameSpellEffect == false) continue;
               if ((effect as GameSpellEffect).Spell.SpellType == "SpeedEnhancement")
                  effect.Cancel(false);
                    if ((effect as GameSpellEffect).Spell.SpellType == "SpeedOfTheRealm")
                        effect.Cancel(false);
            }
         }


Without the ArrayList stuff, I think..
geshi
Contributor
 
Posts: 1826
Joined: Tue Oct 21, 2008 9:16 pm

Re: Charge/SpeedofRealm Stack fix

Postby Graveen » Tue Jun 08, 2010 12:23 pm

what is sure is i can't include this in the SVN. I don't even know what is the trouble you are fixing, and even if it works, it is rather an hack than a fix - this is why it is taggued as 'refused'

Anyway, thank you for this contribution :)
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12660
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

Re: Charge/SpeedofRealm Stack fix

Postby tobz » Wed Jun 09, 2010 3:35 am

geshi wrote:You have

ArrayList speedSpells = new ArrayList();

You then add "speedSpells.Add(effect);"

So you're adding an effect to an ArrayList then you are going through that ArrayList and cancelling the spell.

You could just do

Code: Select all
         lock(living.EffectList)
         {
            foreach (IGameEffect effect in living.EffectList)
            {
               if (effect is GameSpellEffect == false) continue;
               if ((effect as GameSpellEffect).Spell.SpellType == "SpeedEnhancement")
                  effect.Cancel(false);
                    if ((effect as GameSpellEffect).Spell.SpellType == "SpeedOfTheRealm")
                        effect.Cancel(false);
            }
         }


Without the ArrayList stuff, I think..


That would actually throw an enumeration exception: you can't modify collections while enumerating them. The classic pattern is the tag-and-delete - pick out the objects you need to remove, then remove them in a separate loop.
tobz
DOL Devotee
 
Posts: 363
Joined: Mon Jul 27, 2009 6:24 pm


Return to “%s” DOL Code Contributions

Who is online

Users browsing this forum: No registered users and 1 guest