Fixes code according to modern code style. Fixes a few expression bugs.
This commit is contained in:
parent
89eea25e5f
commit
970fd563b2
3324 changed files with 441118 additions and 433755 deletions
|
|
@ -1,325 +1,330 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Server.Targeting;
|
||||
using Server.Spells;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Items
|
||||
{
|
||||
public abstract class BaseConflagrationPotion : BasePotion
|
||||
{
|
||||
public abstract int MinDamage{ get; }
|
||||
public abstract int MaxDamage{ get; }
|
||||
public abstract class BaseConflagrationPotion : BasePotion
|
||||
{
|
||||
private List<Mobile> m_Users = new List<Mobile>();
|
||||
|
||||
public override bool RequireFreeHand => false;
|
||||
public BaseConflagrationPotion(PotionEffect effect) : base(0xF06, effect)
|
||||
{
|
||||
Hue = 0x489;
|
||||
}
|
||||
|
||||
public BaseConflagrationPotion( PotionEffect effect ) : base( 0xF06, effect )
|
||||
{
|
||||
Hue = 0x489;
|
||||
}
|
||||
public BaseConflagrationPotion(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public BaseConflagrationPotion( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
public abstract int MinDamage{ get; }
|
||||
public abstract int MaxDamage{ get; }
|
||||
|
||||
public override void Drink( Mobile from )
|
||||
{
|
||||
if ( Core.AOS && (from.Paralyzed || from.Frozen || (from.Spell != null && from.Spell.IsCasting)) )
|
||||
{
|
||||
from.SendLocalizedMessage( 1062725 ); // You can not use that potion while paralyzed.
|
||||
return;
|
||||
}
|
||||
|
||||
int delay = GetDelay( from );
|
||||
|
||||
if ( delay > 0 )
|
||||
{
|
||||
from.SendLocalizedMessage( 1072529, $"{delay}\t{(delay > 1 ? "seconds." : "second.")}"); // You cannot use that for another ~1_NUM~ ~2_TIMEUNITS~
|
||||
return;
|
||||
}
|
||||
|
||||
if ( from.Target is ThrowTarget targ && targ.Potion == this )
|
||||
return;
|
||||
|
||||
from.RevealingAction();
|
||||
|
||||
if ( !m_Users.Contains( from ) )
|
||||
m_Users.Add( from );
|
||||
|
||||
from.Target = new ThrowTarget( this );
|
||||
}
|
||||
|
||||
public override void Serialize( GenericWriter writer )
|
||||
{
|
||||
base.Serialize( writer );
|
||||
|
||||
writer.Write( (int) 0 ); // version
|
||||
}
|
||||
|
||||
public override void Deserialize( GenericReader reader )
|
||||
{
|
||||
base.Deserialize( reader );
|
||||
public override bool RequireFreeHand => false;
|
||||
|
||||
int version = reader.ReadInt();
|
||||
}
|
||||
public override void Drink(Mobile from)
|
||||
{
|
||||
if (Core.AOS && (from.Paralyzed || from.Frozen || from.Spell != null && from.Spell.IsCasting))
|
||||
{
|
||||
from.SendLocalizedMessage(1062725); // You can not use that potion while paralyzed.
|
||||
return;
|
||||
}
|
||||
|
||||
private List<Mobile> m_Users = new List<Mobile>();
|
||||
int delay = GetDelay(from);
|
||||
|
||||
public void Explode_Callback( object state )
|
||||
{
|
||||
object[] states = (object[]) state;
|
||||
if (delay > 0)
|
||||
{
|
||||
from.SendLocalizedMessage(1072529,
|
||||
$"{delay}\t{(delay > 1 ? "seconds." : "second.")}"); // You cannot use that for another ~1_NUM~ ~2_TIMEUNITS~
|
||||
return;
|
||||
}
|
||||
|
||||
Explode( (Mobile) states[ 0 ], (Point3D) states[ 1 ], (Map) states[ 2 ] );
|
||||
}
|
||||
if (from.Target is ThrowTarget targ && targ.Potion == this)
|
||||
return;
|
||||
|
||||
public virtual void Explode( Mobile from, Point3D loc, Map map )
|
||||
{
|
||||
if ( Deleted || map == null )
|
||||
return;
|
||||
|
||||
Consume();
|
||||
|
||||
// Check if any other players are using this potion
|
||||
for ( int i = 0; i < m_Users.Count; i ++ )
|
||||
{
|
||||
if ( m_Users[ i ].Target is ThrowTarget targ && targ.Potion == this )
|
||||
Target.Cancel( from );
|
||||
}
|
||||
|
||||
// Effects
|
||||
Effects.PlaySound( loc, map, 0x20C );
|
||||
from.RevealingAction();
|
||||
|
||||
for ( int i = -2; i <= 2; i ++ )
|
||||
{
|
||||
for ( int j = -2; j <= 2; j ++ )
|
||||
{
|
||||
Point3D p = new Point3D( loc.X + i, loc.Y + j, loc.Z );
|
||||
if (!m_Users.Contains(from))
|
||||
m_Users.Add(from);
|
||||
|
||||
if ( map.CanFit( p, 12, true, false ) && from.InLOS( p ) )
|
||||
new InternalItem( from, p, map, MinDamage, MaxDamage );
|
||||
}
|
||||
}
|
||||
}
|
||||
from.Target = new ThrowTarget(this);
|
||||
}
|
||||
|
||||
#region Delay
|
||||
private static Hashtable m_Delay = new Hashtable();
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
public static void AddDelay( Mobile m )
|
||||
{
|
||||
if ( m_Delay[ m ] is Timer timer )
|
||||
timer.Stop();
|
||||
writer.Write(0); // version
|
||||
}
|
||||
|
||||
m_Delay[ m ] = Timer.DelayCall( TimeSpan.FromSeconds( 30 ), new TimerStateCallback( EndDelay_Callback ), m );
|
||||
}
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
public static int GetDelay( Mobile m )
|
||||
{
|
||||
if ( m_Delay[ m ] is Timer timer && timer.Next > DateTime.UtcNow )
|
||||
return (int) (timer.Next - DateTime.UtcNow).TotalSeconds;
|
||||
int version = reader.ReadInt();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
public void Explode_Callback(object state)
|
||||
{
|
||||
object[] states = (object[])state;
|
||||
|
||||
private static void EndDelay_Callback( object obj )
|
||||
{
|
||||
if ( obj is Mobile mobile )
|
||||
EndDelay( mobile );
|
||||
}
|
||||
Explode((Mobile)states[0], (Point3D)states[1], (Map)states[2]);
|
||||
}
|
||||
|
||||
public static void EndDelay( Mobile m )
|
||||
{
|
||||
if ( m_Delay[ m ] is Timer timer )
|
||||
{
|
||||
timer.Stop();
|
||||
m_Delay.Remove( m );
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
public virtual void Explode(Mobile from, Point3D loc, Map map)
|
||||
{
|
||||
if (Deleted || map == null)
|
||||
return;
|
||||
|
||||
private class ThrowTarget : Target
|
||||
{
|
||||
public BaseConflagrationPotion Potion { get; }
|
||||
Consume();
|
||||
|
||||
public ThrowTarget( BaseConflagrationPotion potion ) : base( 12, true, TargetFlags.None )
|
||||
{
|
||||
Potion = potion;
|
||||
}
|
||||
// Check if any other players are using this potion
|
||||
for (int i = 0; i < m_Users.Count; i++)
|
||||
if (m_Users[i].Target is ThrowTarget targ && targ.Potion == this)
|
||||
Target.Cancel(from);
|
||||
|
||||
protected override void OnTarget( Mobile from, object targeted )
|
||||
{
|
||||
if ( Potion.Deleted || Potion.Map == Map.Internal )
|
||||
return;
|
||||
// Effects
|
||||
Effects.PlaySound(loc, map, 0x20C);
|
||||
|
||||
if ( !(targeted is IPoint3D p) || from.Map == null )
|
||||
return;
|
||||
for (int i = -2; i <= 2; i++)
|
||||
for (int j = -2; j <= 2; j++)
|
||||
{
|
||||
Point3D p = new Point3D(loc.X + i, loc.Y + j, loc.Z);
|
||||
|
||||
// Add delay
|
||||
AddDelay( from );
|
||||
if (map.CanFit(p, 12, true, false) && from.InLOS(p))
|
||||
new InternalItem(from, p, map, MinDamage, MaxDamage);
|
||||
}
|
||||
}
|
||||
|
||||
SpellHelper.GetSurfaceTop( ref p );
|
||||
private class ThrowTarget : Target
|
||||
{
|
||||
public ThrowTarget(BaseConflagrationPotion potion) : base(12, true, TargetFlags.None)
|
||||
{
|
||||
Potion = potion;
|
||||
}
|
||||
|
||||
from.RevealingAction();
|
||||
public BaseConflagrationPotion Potion{ get; }
|
||||
|
||||
IEntity to;
|
||||
protected override void OnTarget(Mobile from, object targeted)
|
||||
{
|
||||
if (Potion.Deleted || Potion.Map == Map.Internal)
|
||||
return;
|
||||
|
||||
if ( p is Mobile mobile )
|
||||
to = mobile;
|
||||
else
|
||||
to = new Entity( Serial.Zero, new Point3D( p ), from.Map );
|
||||
if (!(targeted is IPoint3D p) || from.Map == null)
|
||||
return;
|
||||
|
||||
Effects.SendMovingEffect( from, to, 0xF0D, 7, 0, false, false, Potion.Hue, 0 );
|
||||
Timer.DelayCall( TimeSpan.FromSeconds( 1.5 ), new TimerStateCallback( Potion.Explode_Callback ), new object[] { from, new Point3D( p ), from.Map } );
|
||||
}
|
||||
}
|
||||
// Add delay
|
||||
AddDelay(from);
|
||||
|
||||
public class InternalItem : Item
|
||||
{
|
||||
private int m_MinDamage;
|
||||
private int m_MaxDamage;
|
||||
private DateTime m_End;
|
||||
private Timer m_Timer;
|
||||
SpellHelper.GetSurfaceTop(ref p);
|
||||
|
||||
public Mobile From { get; private set; }
|
||||
from.RevealingAction();
|
||||
|
||||
public override bool BlocksFit => true;
|
||||
IEntity to;
|
||||
|
||||
public InternalItem( Mobile from, Point3D loc, Map map, int min, int max ) : base( 0x398C )
|
||||
{
|
||||
Movable = false;
|
||||
Light = LightType.Circle300;
|
||||
if (p is Mobile mobile)
|
||||
to = mobile;
|
||||
else
|
||||
to = new Entity(Serial.Zero, new Point3D(p), from.Map);
|
||||
|
||||
MoveToWorld( loc, map );
|
||||
Effects.SendMovingEffect(from, to, 0xF0D, 7, 0, false, false, Potion.Hue, 0);
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(1.5), new TimerStateCallback(Potion.Explode_Callback),
|
||||
new object[] { from, new Point3D(p), from.Map });
|
||||
}
|
||||
}
|
||||
|
||||
From = from;
|
||||
m_End = DateTime.UtcNow + TimeSpan.FromSeconds( 10 );
|
||||
public class InternalItem : Item
|
||||
{
|
||||
private DateTime m_End;
|
||||
private int m_MaxDamage;
|
||||
private int m_MinDamage;
|
||||
private Timer m_Timer;
|
||||
|
||||
SetDamage( min, max );
|
||||
public InternalItem(Mobile from, Point3D loc, Map map, int min, int max) : base(0x398C)
|
||||
{
|
||||
Movable = false;
|
||||
Light = LightType.Circle300;
|
||||
|
||||
m_Timer = new InternalTimer( this, m_End );
|
||||
m_Timer.Start();
|
||||
}
|
||||
MoveToWorld(loc, map);
|
||||
|
||||
public override void OnAfterDelete()
|
||||
{
|
||||
base.OnAfterDelete();
|
||||
From = from;
|
||||
m_End = DateTime.UtcNow + TimeSpan.FromSeconds(10);
|
||||
|
||||
m_Timer?.Stop();
|
||||
}
|
||||
SetDamage(min, max);
|
||||
|
||||
public InternalItem( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
m_Timer = new InternalTimer(this, m_End);
|
||||
m_Timer.Start();
|
||||
}
|
||||
|
||||
public int GetDamage(){ return Utility.RandomMinMax( m_MinDamage, m_MaxDamage ); }
|
||||
public InternalItem(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
private void SetDamage( int min, int max )
|
||||
{
|
||||
/* new way to apply alchemy bonus according to Stratics' calculator.
|
||||
this gives a mean to values 25, 50, 75 and 100. Stratics' calculator is outdated.
|
||||
Those goals will give 2 to alchemy bonus. It's not really OSI-like but it's an approximation. */
|
||||
public Mobile From{ get; private set; }
|
||||
|
||||
m_MinDamage = min;
|
||||
m_MaxDamage = max;
|
||||
public override bool BlocksFit => true;
|
||||
|
||||
if ( From == null )
|
||||
return;
|
||||
public override void OnAfterDelete()
|
||||
{
|
||||
base.OnAfterDelete();
|
||||
|
||||
int alchemySkill = From.Skills.Alchemy.Fixed;
|
||||
int alchemyBonus = alchemySkill / 125 + alchemySkill / 250 ;
|
||||
m_Timer?.Stop();
|
||||
}
|
||||
|
||||
m_MinDamage = Scale( From, m_MinDamage + alchemyBonus );
|
||||
m_MaxDamage = Scale( From, m_MaxDamage + alchemyBonus );
|
||||
}
|
||||
public int GetDamage()
|
||||
{
|
||||
return Utility.RandomMinMax(m_MinDamage, m_MaxDamage);
|
||||
}
|
||||
|
||||
public override void Serialize( GenericWriter writer )
|
||||
{
|
||||
base.Serialize( writer );
|
||||
private void SetDamage(int min, int max)
|
||||
{
|
||||
/* new way to apply alchemy bonus according to Stratics' calculator.
|
||||
this gives a mean to values 25, 50, 75 and 100. Stratics' calculator is outdated.
|
||||
Those goals will give 2 to alchemy bonus. It's not really OSI-like but it's an approximation. */
|
||||
|
||||
writer.Write( (int) 0 ); // version
|
||||
m_MinDamage = min;
|
||||
m_MaxDamage = max;
|
||||
|
||||
writer.Write( (Mobile) From );
|
||||
writer.Write( (DateTime) m_End );
|
||||
writer.Write( (int) m_MinDamage );
|
||||
writer.Write( (int) m_MaxDamage );
|
||||
}
|
||||
if (From == null)
|
||||
return;
|
||||
|
||||
public override void Deserialize( GenericReader reader )
|
||||
{
|
||||
base.Deserialize( reader );
|
||||
int alchemySkill = From.Skills.Alchemy.Fixed;
|
||||
int alchemyBonus = alchemySkill / 125 + alchemySkill / 250;
|
||||
|
||||
int version = reader.ReadInt();
|
||||
m_MinDamage = Scale(From, m_MinDamage + alchemyBonus);
|
||||
m_MaxDamage = Scale(From, m_MaxDamage + alchemyBonus);
|
||||
}
|
||||
|
||||
From = reader.ReadMobile();
|
||||
m_End = reader.ReadDateTime();
|
||||
m_MinDamage = reader.ReadInt();
|
||||
m_MaxDamage = reader.ReadInt();
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
m_Timer = new InternalTimer( this, m_End );
|
||||
m_Timer.Start();
|
||||
}
|
||||
writer.Write(0); // version
|
||||
|
||||
public override bool OnMoveOver( Mobile m )
|
||||
{
|
||||
if ( Visible && From != null && (!Core.AOS || m != From) && SpellHelper.ValidIndirectTarget( From, m ) && From.CanBeHarmful( m, false ) )
|
||||
{
|
||||
From.DoHarmful( m );
|
||||
writer.Write(From);
|
||||
writer.Write(m_End);
|
||||
writer.Write(m_MinDamage);
|
||||
writer.Write(m_MaxDamage);
|
||||
}
|
||||
|
||||
AOS.Damage( m, From, GetDamage(), 0, 100, 0, 0, 0 );
|
||||
m.PlaySound( 0x208 );
|
||||
}
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
return true;
|
||||
}
|
||||
int version = reader.ReadInt();
|
||||
|
||||
private class InternalTimer : Timer
|
||||
{
|
||||
private InternalItem m_Item;
|
||||
private DateTime m_End;
|
||||
From = reader.ReadMobile();
|
||||
m_End = reader.ReadDateTime();
|
||||
m_MinDamage = reader.ReadInt();
|
||||
m_MaxDamage = reader.ReadInt();
|
||||
|
||||
public InternalTimer( InternalItem item, DateTime end ) : base( TimeSpan.Zero, TimeSpan.FromSeconds( 1.0 ) )
|
||||
{
|
||||
m_Item = item;
|
||||
m_End = end;
|
||||
m_Timer = new InternalTimer(this, m_End);
|
||||
m_Timer.Start();
|
||||
}
|
||||
|
||||
public override bool OnMoveOver(Mobile m)
|
||||
{
|
||||
if (Visible && From != null && (!Core.AOS || m != From) && SpellHelper.ValidIndirectTarget(From, m) &&
|
||||
From.CanBeHarmful(m, false))
|
||||
{
|
||||
From.DoHarmful(m);
|
||||
|
||||
AOS.Damage(m, From, GetDamage(), 0, 100, 0, 0, 0);
|
||||
m.PlaySound(0x208);
|
||||
}
|
||||
|
||||
Priority = TimerPriority.FiftyMS;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
if ( m_Item.Deleted )
|
||||
return;
|
||||
private class InternalTimer : Timer
|
||||
{
|
||||
private DateTime m_End;
|
||||
private InternalItem m_Item;
|
||||
|
||||
if ( DateTime.UtcNow > m_End )
|
||||
{
|
||||
m_Item.Delete();
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
Mobile from = m_Item.From;
|
||||
public InternalTimer(InternalItem item, DateTime end) : base(TimeSpan.Zero, TimeSpan.FromSeconds(1.0))
|
||||
{
|
||||
m_Item = item;
|
||||
m_End = end;
|
||||
|
||||
if ( m_Item.Map == null || from == null )
|
||||
return;
|
||||
Priority = TimerPriority.FiftyMS;
|
||||
}
|
||||
|
||||
List<Mobile> mobiles = new List<Mobile>();
|
||||
|
||||
foreach( Mobile mobile in m_Item.GetMobilesInRange( 0 ) )
|
||||
mobiles.Add( mobile );
|
||||
|
||||
for( int i = 0; i < mobiles.Count; i++ )
|
||||
{
|
||||
Mobile m = mobiles[i];
|
||||
|
||||
if ( (m.Z + 16) > m_Item.Z && (m_Item.Z + 12) > m.Z && (!Core.AOS || m != from) && SpellHelper.ValidIndirectTarget( from, m ) && from.CanBeHarmful( m, false ) )
|
||||
{
|
||||
from?.DoHarmful( m );
|
||||
|
||||
AOS.Damage( m, from, m_Item.GetDamage(), 0, 100, 0, 0, 0 );
|
||||
m.PlaySound( 0x208 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void OnTick()
|
||||
{
|
||||
if (m_Item.Deleted)
|
||||
return;
|
||||
|
||||
if (DateTime.UtcNow > m_End)
|
||||
{
|
||||
m_Item.Delete();
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
Mobile from = m_Item.From;
|
||||
|
||||
if (m_Item.Map == null || from == null)
|
||||
return;
|
||||
|
||||
List<Mobile> mobiles = new List<Mobile>();
|
||||
|
||||
foreach (Mobile mobile in m_Item.GetMobilesInRange(0))
|
||||
mobiles.Add(mobile);
|
||||
|
||||
for (int i = 0; i < mobiles.Count; i++)
|
||||
{
|
||||
Mobile m = mobiles[i];
|
||||
|
||||
if (m.Z + 16 > m_Item.Z && m_Item.Z + 12 > m.Z && (!Core.AOS || m != from) &&
|
||||
SpellHelper.ValidIndirectTarget(from, m) && from.CanBeHarmful(m, false))
|
||||
{
|
||||
from?.DoHarmful(m);
|
||||
|
||||
AOS.Damage(m, from, m_Item.GetDamage(), 0, 100, 0, 0, 0);
|
||||
m.PlaySound(0x208);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Delay
|
||||
|
||||
private static Hashtable m_Delay = new Hashtable();
|
||||
|
||||
public static void AddDelay(Mobile m)
|
||||
{
|
||||
if (m_Delay[m] is Timer timer)
|
||||
timer.Stop();
|
||||
|
||||
m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), new TimerStateCallback(EndDelay_Callback), m);
|
||||
}
|
||||
|
||||
public static int GetDelay(Mobile m)
|
||||
{
|
||||
if (m_Delay[m] is Timer timer && timer.Next > DateTime.UtcNow)
|
||||
return (int)(timer.Next - DateTime.UtcNow).TotalSeconds;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void EndDelay_Callback(object obj)
|
||||
{
|
||||
if (obj is Mobile mobile)
|
||||
EndDelay(mobile);
|
||||
}
|
||||
|
||||
public static void EndDelay(Mobile m)
|
||||
{
|
||||
if (m_Delay[m] is Timer timer)
|
||||
{
|
||||
timer.Stop();
|
||||
m_Delay.Remove(m);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue