Resource icon

PoolOfAcid.cs [fix]

PoolOfAcid.cs had logic problems that caused the List<Mobile> in onDamage to never be used and OnMoveOver() had no logic at all, which was targeting dead mobiles. Created a seperate method to handle validity of creature that moves over the acid. These fixes should also be used in AcidSlime.cs. Still learning to program so if I left anything out please let me know!

Code:
using System;
using Server;
using Server.Mobiles;
using Server.Spells;
using System.Collections;
using System.Collections.Generic;

namespace Server.Items
{
   public class PoolOfAcid : Item
   {
   
     private TimeSpan m_Duration;
     private int m_MinDamage;
     private int m_MaxDamage;
  private DateTime m_Created;
     private bool m_Drying;
     private Timer m_Timer;
   

     [Constructable]
     public PoolOfAcid() : this( TimeSpan.FromSeconds( 10.0 ), 2, 5 )
     {
     }

     public override string DefaultName { get { return "a pool of acid"; } }

     [Constructable]
     public PoolOfAcid( TimeSpan duration, int minDamage, int maxDamage )
       : base( 0x122A )
     {
       Hue = 0x3F;
       Movable = false;

       m_MinDamage = minDamage;
       m_MaxDamage = maxDamage;
  m_Duration = duration;
  m_Created = DateTime.UtcNow;
  m_Drying = false;

       m_Timer = Timer.DelayCall( TimeSpan.Zero, TimeSpan.FromSeconds( 1 ), new TimerCallback( OnTick ) );
     }

     public override void OnAfterDelete()
     {

       if( m_Timer != null )
         m_Timer.Stop();
     }

     private void OnTick()
     {
   
  DateTime now = DateTime.UtcNow;
  TimeSpan age = now - m_Created;

  if ( age > m_Duration)
  {   
         Delete();   
  }
  else
  {

         if( !m_Drying && age > (m_Duration - age))
         {
           m_Drying = true;
           ItemID = 0x122B;
         }

         List<Mobile> toDamage = new List<Mobile>();

  for (int i = 0; i < toDamage.Count; i++)
  {
  Console.WriteLine("List Before Adding = #{0} Mobile = {1} ",i, toDamage[i]);
  }

         foreach( Mobile m in GetMobilesInRange( 0 ) )
         {
  if (IsValidTarget(m))
  {
  Damage(m);
  }
         }

         for ( int i = 0; i < toDamage.Count; i++ )
  {   
  Damage(toDamage[i]);   
  }
  for (int i = 0; i < toDamage.Count; i++)
  {
  Console.WriteLine("Mobile[{0}] = {1}",i,toDamage[i]);
  }
   
       }
     }

  private bool IsValidTarget(Mobile m)
  {
  BaseCreature bc = m as BaseCreature;

  if (m.Alive && m.AccessLevel == AccessLevel.Player &&
  m is PlayerMobile)
  {
  return true;
  }
  else if (bc != null && !bc.IsDeadBondedPet
  && (bc.Controlled || bc.Summoned))
  {
  return true;
  }

  return false;
  }
   
  public override bool OnMoveOver(Mobile m)
  {

  if (IsValidTarget(m))
  {
  Damage(m);   
  }
   
  return true;
  }

     public void Damage ( Mobile m )
     {
  int damage = Utility.RandomMinMax(m_MinDamage, m_MaxDamage);
  if (Core.AOS)
  AOS.Damage(m, damage, 0, 0, 0, 100, 0);
  else
  m.Damage(damage);       
     }

     public PoolOfAcid( Serial serial ) : base( serial )
     {
     }

     public override void Serialize( GenericWriter writer )
     {
       //Don't serialize these
     }

     public override void Deserialize( GenericReader reader )
     {
     }
   }
}
Author
Sorthious
Views
229
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from Sorthious