Same spell but 2 different delays depending on region?

Discussion in 'Script Support' started by maybeshewill, Nov 16, 2017.

  1. maybeshewill

    maybeshewill Sorceror

    Joined:
    Nov 6, 2010
    Messages:
    409
    Likes Received:
    67
    Its possible to make a spell that have 2 different cast delay depending on what region the player is?


    Thanks
     
  2. Arvoreen

    Arvoreen Sorceror

    Joined:
    May 4, 2005
    Messages:
    2,620
    Likes Received:
    69
    I would hazard a guess and say yes it's possible. Basically dig into code for the spell(s) you want to modify, find where the delay is, and then make it check the casters region before deciding the delay.
     
    maybeshewill likes this.
  3. Enroq

    Enroq Sorceror

    Joined:
    Jan 28, 2011
    Messages:
    1,940
    Likes Received:
    230
    I've added the lines needed to give you an idea of where and/or how to do it. This is in Spell.cs

    Code:
                if (m_Caster != null && m_Caster.AccessLevel == AccessLevel.Player && m_Caster.Region.IsPartOf(typeof(Regions.GuardedRegion)))
                {
                    TimeSpan regionDelayMod = TimeSpan.FromSeconds(0.5f);
                    delay += regionDelayMod;
                }
    
    Code:
            public virtual TimeSpan GetCastDelay()
            {
                if ( m_Scroll is BaseWand )
                    return Core.ML ? CastDelayBase : TimeSpan.Zero; // TODO: Should FC apply to wands?
    
                // Faster casting cap of 2 (if not using the protection spell)
                // Faster casting cap of 0 (if using the protection spell)
                // Paladin spells are subject to a faster casting cap of 4
                // Paladins with magery of 70.0 or above are subject to a faster casting cap of 2
                int fcMax = 4;
    
                if ( CastSkill == SkillName.Magery || CastSkill == SkillName.Necromancy || ( CastSkill == SkillName.Chivalry && m_Caster.Skills[SkillName.Magery].Value >= 70.0 ) )
                    fcMax = 2;
    
                int fc = AosAttributes.GetValue( m_Caster, AosAttribute.CastSpeed );
    
                if ( fc > fcMax )
                    fc = fcMax;
    
                if ( ProtectionSpell.Registry.Contains( m_Caster ) )
                    fc -= 2;
    
                if( EssenceOfWindSpell.IsDebuffed( m_Caster ) )
                    fc -= EssenceOfWindSpell.GetFCMalus( m_Caster );
    
                TimeSpan baseDelay = CastDelayBase;
    
                TimeSpan fcDelay = TimeSpan.FromSeconds( -(CastDelayFastScalar * fc * CastDelaySecondsPerTick) );
    
                //int delay = CastDelayBase + circleDelay + fcDelay;
                TimeSpan delay = baseDelay + fcDelay;
    
                if ( delay < CastDelayMinimum )
                    delay = CastDelayMinimum;
    
                if (m_Caster != null && m_Caster.AccessLevel == AccessLevel.Player && m_Caster.Region.IsPartOf(typeof(Regions.GuardedRegion)))
                {
                    TimeSpan regionDelayMod = TimeSpan.FromSeconds(0.5f);
                    delay += regionDelayMod;
                }
    
                //return TimeSpan.FromSeconds( (double)delay / CastDelayPerSecond );
                return delay;
            }
     
    maybeshewill likes this.
  4. maybeshewill

    maybeshewill Sorceror

    Joined:
    Nov 6, 2010
    Messages:
    409
    Likes Received:
    67
    Thanks im going to try that
     
  5. Enroq

    Enroq Sorceror

    Joined:
    Jan 28, 2011
    Messages:
    1,940
    Likes Received:
    230
    No problem. Targeting a specific region will be a little different. That's only going to work for region types that are registered. But I wasn't exactly sure what you're going for.
     
  6. maybeshewill

    maybeshewill Sorceror

    Joined:
    Nov 6, 2010
    Messages:
    409
    Likes Received:
    67
    So i can add that to any spell? because im trying... and doesnt seem to work get errrors and all that so this is what i added to my Greater Heal Spell:


    thhe next code dont throw any errors but the delay is always 12 sec

    Code:
      public override TimeSpan GetCastDelay()
            {
               
                 PlayerMobile mobile = (PlayerMobile)Caster;
               
                 if ( Caster != null && Caster.Region.IsPartOf( "Felucca" ) || Caster.Region.IsPartOf( "Trammel" ) || Caster.Region.IsPartOf( "Ilshenar" ) || Caster.Region.IsPartOf( "Tokuno" ) )
            {
               
                   return TimeSpan.FromSeconds(3.1);
               
                }
               
                   if (Caster != null && Caster.Region.Name == "12secondscastregion");
                {
                   
                   return TimeSpan.FromSeconds(12.1);
             
                }
    
    return TimeSpan.FromSeconds(3.1);
    
    Im using custom regions in a box, however doesnt matter where the player is when casting the spell, its always 12.1 seconds cast.

    sometimes i have issues trying to check whats the caster region is
     
    #6 maybeshewill, Jan 9, 2018
    Last edited: Jan 9, 2018
  7. Enroq

    Enroq Sorceror

    Joined:
    Jan 28, 2011
    Messages:
    1,940
    Likes Received:
    230
    So, if I remember correctly.. Tthe way IsPartOf works is kind of counter-intuitive. You'd think if your map is one of those, they'd return true.

    Thing is, I believe they only return true if you're in a region defines in the data files found here:

    https://github.com/runuo/runuo/tree/master/Data/Locations

    So, the first thing is.. When you get this working, by checking all the map facets - you'll never get to your '12secondcastregion.'

    So in regards to that, you should be checking for the region first or adding another bool check to the if statement like.. && != 12secondcastregion or something of the nature.

    As for making the first part work, I think you would be better served by checking their map instead of if their region 'IsParOf'.

    So like.. If Caster.Map == Map.Felucca.
     
    maybeshewill likes this.
  8. maybeshewill

    maybeshewill Sorceror

    Joined:
    Nov 6, 2010
    Messages:
    409
    Likes Received:
    67
    Couldnt make it working by adding that delaymod thing server just froze whenever i cast the spell so i added this and it worked:


    Code:
       public override TimeSpan GetCastDelay()
            {
             
     
                  PlayerMobile mobile = (PlayerMobile)Caster;
                  if ( Caster.Region.Name == "12secondscastregion")
                  {
            Console.WriteLine("Debug mode; delay should be increased");
              if (Caster != null)
              {
                 return TimeSpan.FromSeconds(16.5);
               
                }
              
               
    
               
                     return TimeSpan.FromSeconds(3.1);
                  }
    if player is inside that region the spell is 16.5 seconds cast, anywhere else 3.1

    now i need to figure out how ot consume more mana in these regions :p it should be on Spell.cs
    inside
    public virtual void DoFizzle() right?
     
    #8 maybeshewill, Jan 10, 2018
    Last edited: Jan 10, 2018
  9. Enroq

    Enroq Sorceror

    Joined:
    Jan 28, 2011
    Messages:
    1,940
    Likes Received:
    230
    I have no idea how that works :eek:

    As for mana.. you'll notice this line in the check sequence of Spell.cs

    Code:
                else if ( m_Caster.Mana < mana )
                {
                    m_Caster.LocalOverheadMessage( MessageType.Regular, 0x22, 502625 ); // Insufficient mana for this spell.
                }
    
    'mana' comes from..

    Code:
                int mana = ScaleMana( GetMana() );
    
    So, what you then might notice is that GetMana() is an abstract method that doesn't actually provide any functionality in Spell.cs

    This is because it's used by its inheriting classes like MagerySpell.cs

    Code:
            public override int GetMana()
            {
                if( Scroll is BaseWand )
                    return 0;
                return m_ManaTable[(int)Circle];
            }
    
    So I'd say the easiest options on the table are modifying your ScaleMana method to scale what GetMana returns which would be effect all of the spell classes or you could modify each individual GetMana() method for each of the spell type classes.
     
  10. Enroq

    Enroq Sorceror

    Joined:
    Jan 28, 2011
    Messages:
    1,940
    Likes Received:
    230
    I should probably also mention, that your GetCastDelay() really confuses me :p

    It should always be returning 16.5 if caster isn't null.. I really have no idea.

    Is that exactly how the code you're running looks? Because it shouldn't even be returning a value if not in that '12secondregion'..? Unless the code posted is just missing a bracket that closes the if statement checking the region name?

    What I can tell you is that you're never using this cast:

    Code:
                 PlayerMobile mobile = (PlayerMobile)Caster;
    
    So you could either switch Caster to mobile in that context or ditch the cast all together.
     
  11. maybeshewill

    maybeshewill Sorceror

    Joined:
    Nov 6, 2010
    Messages:
    409
    Likes Received:
    67
    Yes i was missing a bracket this is the full code


    Code:
        public override TimeSpan GetCastDelay()
            {
              
        #region castingchanged
               
                
                  if ( Caster.Region.Name == "12secondsregion" || Caster.Region.Name == "customregion3" || Caster.Region.Name == "customregion9" || Caster.Region.Name == "customregion33")
                  {
      
              if (Caster != null)
                     {
                 return TimeSpan.FromSeconds(16.5);
                
                     }
                  }
      #endregion
    
                
                     return TimeSpan.FromSeconds(3.1);
                  }
    it will always return 3.1 unless player is inside one of those regions.

    As for the mana thing thank you so much i will try that out ;)

    silly question what the

    #region castingchanged

    #endregion
    does actually? lol
     
  12. Enroq

    Enroq Sorceror

    Joined:
    Jan 28, 2011
    Messages:
    1,940
    Likes Received:
    230
    When you're using an IDE it allows you to collapse an area of code. There's no actual effect to your code. However, they're not really necessary for a few lines of code, or inside a method because method and classes can already be collapsed without the use of regions.
     
    maybeshewill likes this.

Share This Page