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,286 +1,287 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Network;
|
||||
using Server.Targeting;
|
||||
using Server.Spells;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Items
|
||||
{
|
||||
public abstract class BaseExplosionPotion : BasePotion
|
||||
{
|
||||
public abstract int MinDamage { get; }
|
||||
public abstract int MaxDamage { get; }
|
||||
public abstract class BaseExplosionPotion : BasePotion
|
||||
{
|
||||
private const int ExplosionRange = 2; // How long is the blast radius?
|
||||
|
||||
public override bool RequireFreeHand => false;
|
||||
private static bool LeveledExplosion = false; // Should explosion potions explode other nearby potions?
|
||||
private static bool InstantExplosion = false; // Should explosion potions explode on impact?
|
||||
private static bool RelativeLocation = false; // Is the explosion target location relative for mobiles?
|
||||
|
||||
private static bool LeveledExplosion = false; // Should explosion potions explode other nearby potions?
|
||||
private static bool InstantExplosion = false; // Should explosion potions explode on impact?
|
||||
private static bool RelativeLocation = false; // Is the explosion target location relative for mobiles?
|
||||
private const int ExplosionRange = 2; // How long is the blast radius?
|
||||
private Timer m_Timer;
|
||||
|
||||
public BaseExplosionPotion( PotionEffect effect ) : base( 0xF0D, effect )
|
||||
{
|
||||
}
|
||||
public BaseExplosionPotion(PotionEffect effect) : base(0xF0D, effect)
|
||||
{
|
||||
}
|
||||
|
||||
public BaseExplosionPotion( Serial serial ) : base( serial )
|
||||
{
|
||||
}
|
||||
public BaseExplosionPotion(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Serialize( GenericWriter writer )
|
||||
{
|
||||
base.Serialize( writer );
|
||||
public abstract int MinDamage{ get; }
|
||||
public abstract int MaxDamage{ get; }
|
||||
|
||||
writer.Write( (int) 0 ); // version
|
||||
}
|
||||
public override bool RequireFreeHand => false;
|
||||
|
||||
public override void Deserialize( GenericReader reader )
|
||||
{
|
||||
base.Deserialize( reader );
|
||||
|
||||
int version = reader.ReadInt();
|
||||
}
|
||||
|
||||
public virtual object FindParent( Mobile from )
|
||||
{
|
||||
Mobile m = HeldBy;
|
||||
|
||||
if ( m != null && m.Holding == this )
|
||||
return m;
|
||||
|
||||
object obj = RootParent;
|
||||
|
||||
if ( obj != null )
|
||||
return obj;
|
||||
|
||||
if ( Map == Map.Internal )
|
||||
return from;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private Timer m_Timer;
|
||||
|
||||
public List<Mobile> Users { get; private set; }
|
||||
|
||||
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 a purple potion while paralyzed.
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowTarget targ = from.Target as ThrowTarget;
|
||||
Stackable = false; // Scavenged explosion potions won't stack with those ones in backpack, and still will explode.
|
||||
|
||||
if ( targ != null && targ.Potion == this )
|
||||
return;
|
||||
|
||||
from.RevealingAction();
|
||||
|
||||
if ( Users == null )
|
||||
Users = new List<Mobile>();
|
||||
|
||||
if ( !Users.Contains( from ) )
|
||||
Users.Add( from );
|
||||
public List<Mobile> Users{ get; private set; }
|
||||
|
||||
from.Target = new ThrowTarget( this );
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
if ( m_Timer == null )
|
||||
{
|
||||
from.SendLocalizedMessage( 500236 ); // You should throw it now!
|
||||
writer.Write(0); // version
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
int version = reader.ReadInt();
|
||||
}
|
||||
|
||||
if ( Core.ML )
|
||||
m_Timer = Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), TimeSpan.FromSeconds( 1.25 ), 5, new TimerStateCallback( Detonate_OnTick ), new object[]{ from, 3 } ); // 3.6 seconds explosion delay
|
||||
else
|
||||
m_Timer = Timer.DelayCall( TimeSpan.FromSeconds( 0.75 ), TimeSpan.FromSeconds( 1.0 ), 4, new TimerStateCallback( Detonate_OnTick ), new object[]{ from, 3 } ); // 2.6 seconds explosion delay
|
||||
}
|
||||
}
|
||||
public virtual object FindParent(Mobile from)
|
||||
{
|
||||
Mobile m = HeldBy;
|
||||
|
||||
if (m != null && m.Holding == this)
|
||||
return m;
|
||||
|
||||
object obj = RootParent;
|
||||
|
||||
if (obj != null)
|
||||
return obj;
|
||||
|
||||
private void Detonate_OnTick( object state )
|
||||
{
|
||||
if ( Deleted )
|
||||
return;
|
||||
|
||||
object[] states = (object[])state;
|
||||
Mobile from = (Mobile)states[0];
|
||||
int timer = (int)states[1];
|
||||
|
||||
object parent = FindParent( from );
|
||||
if (Map == Map.Internal)
|
||||
return from;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
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 a purple potion while paralyzed.
|
||||
return;
|
||||
}
|
||||
|
||||
ThrowTarget targ = from.Target as ThrowTarget;
|
||||
Stackable = false; // Scavenged explosion potions won't stack with those ones in backpack, and still will explode.
|
||||
|
||||
if (targ != null && targ.Potion == this)
|
||||
return;
|
||||
|
||||
from.RevealingAction();
|
||||
|
||||
if (Users == null)
|
||||
Users = new List<Mobile>();
|
||||
|
||||
if (!Users.Contains(from))
|
||||
Users.Add(from);
|
||||
|
||||
if ( timer == 0 )
|
||||
{
|
||||
Point3D loc;
|
||||
Map map;
|
||||
from.Target = new ThrowTarget(this);
|
||||
|
||||
if ( parent is Item item )
|
||||
{
|
||||
loc = item.GetWorldLocation();
|
||||
map = item.Map;
|
||||
}
|
||||
else if ( parent is Mobile m )
|
||||
{
|
||||
loc = m.Location;
|
||||
map = m.Map;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (m_Timer == null)
|
||||
{
|
||||
from.SendLocalizedMessage(500236); // You should throw it now!
|
||||
|
||||
Explode( from, true, loc, map );
|
||||
m_Timer = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( parent is Item item )
|
||||
item.PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() );
|
||||
else if ( parent is Mobile mobile )
|
||||
mobile.PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() );
|
||||
if (Core.ML)
|
||||
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.25), 5,
|
||||
new TimerStateCallback(Detonate_OnTick), new object[] { from, 3 }); // 3.6 seconds explosion delay
|
||||
else
|
||||
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(0.75), TimeSpan.FromSeconds(1.0), 4,
|
||||
new TimerStateCallback(Detonate_OnTick), new object[] { from, 3 }); // 2.6 seconds explosion delay
|
||||
}
|
||||
}
|
||||
|
||||
states[1] = timer - 1;
|
||||
}
|
||||
}
|
||||
private void Detonate_OnTick(object state)
|
||||
{
|
||||
if (Deleted)
|
||||
return;
|
||||
|
||||
object[] states = (object[])state;
|
||||
Mobile from = (Mobile)states[0];
|
||||
int timer = (int)states[1];
|
||||
|
||||
private void Reposition_OnTick( object state )
|
||||
{
|
||||
if ( Deleted )
|
||||
return;
|
||||
object parent = FindParent(from);
|
||||
|
||||
if (timer == 0)
|
||||
{
|
||||
Point3D loc;
|
||||
Map map;
|
||||
|
||||
object[] states = (object[])state;
|
||||
Mobile from = (Mobile)states[0];
|
||||
IPoint3D p = (IPoint3D)states[1];
|
||||
Map map = (Map)states[2];
|
||||
|
||||
Point3D loc = new Point3D( p );
|
||||
|
||||
if ( InstantExplosion )
|
||||
Explode( from, true, loc, map );
|
||||
else
|
||||
MoveToWorld( loc, map );
|
||||
}
|
||||
|
||||
private class ThrowTarget : Target
|
||||
{
|
||||
public BaseExplosionPotion Potion { get; }
|
||||
|
||||
public ThrowTarget( BaseExplosionPotion potion ) : base( 12, true, TargetFlags.None )
|
||||
{
|
||||
Potion = potion;
|
||||
}
|
||||
if (parent is Item item)
|
||||
{
|
||||
loc = item.GetWorldLocation();
|
||||
map = item.Map;
|
||||
}
|
||||
else if (parent is Mobile m)
|
||||
{
|
||||
loc = m.Location;
|
||||
map = m.Map;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Explode(from, true, loc, map);
|
||||
m_Timer = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parent is Item item)
|
||||
item.PublicOverheadMessage(MessageType.Regular, 0x22, false, timer.ToString());
|
||||
else if (parent is Mobile mobile)
|
||||
mobile.PublicOverheadMessage(MessageType.Regular, 0x22, false, timer.ToString());
|
||||
|
||||
states[1] = timer - 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void Reposition_OnTick(object state)
|
||||
{
|
||||
if (Deleted)
|
||||
return;
|
||||
|
||||
object[] states = (object[])state;
|
||||
Mobile from = (Mobile)states[0];
|
||||
IPoint3D p = (IPoint3D)states[1];
|
||||
Map map = (Map)states[2];
|
||||
|
||||
Point3D loc = new Point3D(p);
|
||||
|
||||
if (InstantExplosion)
|
||||
Explode(from, true, loc, map);
|
||||
else
|
||||
MoveToWorld(loc, map);
|
||||
}
|
||||
|
||||
public void Explode(Mobile from, bool direct, Point3D loc, Map map)
|
||||
{
|
||||
if (Deleted)
|
||||
return;
|
||||
|
||||
Consume();
|
||||
|
||||
for (int i = 0; Users != null && i < Users.Count; ++i)
|
||||
{
|
||||
Mobile m = Users[i];
|
||||
|
||||
if (m.Target is ThrowTarget targ && targ.Potion == this)
|
||||
Target.Cancel(m);
|
||||
}
|
||||
|
||||
if (map == null)
|
||||
return;
|
||||
|
||||
Effects.PlaySound(loc, map, 0x307);
|
||||
|
||||
Effects.SendLocationEffect(loc, map, 0x36B0, 9, 10, 0, 0);
|
||||
int alchemyBonus = 0;
|
||||
|
||||
if (direct)
|
||||
alchemyBonus = (int)(from.Skills.Alchemy.Value / (Core.AOS ? 5 : 10));
|
||||
|
||||
IPooledEnumerable<IEntity> eable = map.GetObjectsInRange(loc, ExplosionRange, LeveledExplosion, true);
|
||||
List<IEntity> toExplode = new List<IEntity>();
|
||||
|
||||
int toDamage = 0;
|
||||
|
||||
foreach (IEntity o in eable)
|
||||
if (o is Mobile mobile && (from == null ||
|
||||
SpellHelper.ValidIndirectTarget(from, mobile) &&
|
||||
from.CanBeHarmful(mobile, false)))
|
||||
{
|
||||
toExplode.Add(mobile);
|
||||
++toDamage;
|
||||
}
|
||||
else if (o is BaseExplosionPotion && o != this)
|
||||
{
|
||||
toExplode.Add(o);
|
||||
}
|
||||
|
||||
eable.Free();
|
||||
|
||||
int min = Scale(from, MinDamage);
|
||||
int max = Scale(from, MaxDamage);
|
||||
|
||||
for (int i = 0; i < toExplode.Count; ++i)
|
||||
{
|
||||
object o = toExplode[i];
|
||||
|
||||
if (o is Mobile m)
|
||||
{
|
||||
from?.DoHarmful(m);
|
||||
|
||||
int damage = Utility.RandomMinMax(min, max);
|
||||
|
||||
damage += alchemyBonus;
|
||||
|
||||
if (!Core.AOS && damage > 40)
|
||||
damage = 40;
|
||||
else if (Core.AOS && toDamage > 2)
|
||||
damage /= toDamage - 1;
|
||||
|
||||
AOS.Damage(m, from, damage, 0, 100, 0, 0, 0);
|
||||
}
|
||||
else if (o is BaseExplosionPotion pot)
|
||||
{
|
||||
pot.Explode(from, false, pot.GetWorldLocation(), pot.Map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnTarget( Mobile from, object targeted )
|
||||
{
|
||||
if ( Potion.Deleted || Potion.Map == Map.Internal )
|
||||
return;
|
||||
|
||||
if ( !(targeted is IPoint3D p) )
|
||||
return;
|
||||
|
||||
Map map = from.Map;
|
||||
|
||||
if ( map == null )
|
||||
return;
|
||||
|
||||
SpellHelper.GetSurfaceTop( ref p );
|
||||
|
||||
from.RevealingAction();
|
||||
|
||||
IEntity to = new Entity( Serial.Zero, new Point3D( p ), map );
|
||||
|
||||
if ( p is Mobile m )
|
||||
{
|
||||
if ( !RelativeLocation ) // explosion location = current mob location.
|
||||
p = m.Location;
|
||||
else
|
||||
to = m;
|
||||
}
|
||||
|
||||
Effects.SendMovingEffect( from, to, Potion.ItemID, 7, 0, false, false, Potion.Hue, 0 );
|
||||
|
||||
if ( Potion.Amount > 1 )
|
||||
{
|
||||
Mobile.LiftItemDupe( Potion, 1 );
|
||||
}
|
||||
|
||||
Potion.Internalize();
|
||||
Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerStateCallback( Potion.Reposition_OnTick ), new object[]{ from, p, map } );
|
||||
}
|
||||
}
|
||||
|
||||
public void Explode( Mobile from, bool direct, Point3D loc, Map map )
|
||||
{
|
||||
if ( Deleted )
|
||||
return;
|
||||
|
||||
Consume();
|
||||
|
||||
for ( int i = 0; Users != null && i < Users.Count; ++i )
|
||||
{
|
||||
Mobile m = Users[i];
|
||||
|
||||
if ( m.Target is ThrowTarget targ && targ.Potion == this )
|
||||
Target.Cancel( m );
|
||||
}
|
||||
|
||||
if ( map == null )
|
||||
return;
|
||||
|
||||
Effects.PlaySound(loc, map, 0x307);
|
||||
|
||||
Effects.SendLocationEffect(loc, map, 0x36B0, 9, 10, 0, 0);
|
||||
int alchemyBonus = 0;
|
||||
|
||||
if ( direct )
|
||||
alchemyBonus = (int)(from.Skills.Alchemy.Value / (Core.AOS ? 5 : 10));
|
||||
private class ThrowTarget : Target
|
||||
{
|
||||
public ThrowTarget(BaseExplosionPotion potion) : base(12, true, TargetFlags.None)
|
||||
{
|
||||
Potion = potion;
|
||||
}
|
||||
|
||||
IPooledEnumerable<IEntity> eable = map.GetObjectsInRange(loc, ExplosionRange, LeveledExplosion, true);
|
||||
List<IEntity> toExplode = new List<IEntity>();
|
||||
public BaseExplosionPotion Potion{ get; }
|
||||
|
||||
int toDamage = 0;
|
||||
protected override void OnTarget(Mobile from, object targeted)
|
||||
{
|
||||
if (Potion.Deleted || Potion.Map == Map.Internal)
|
||||
return;
|
||||
|
||||
foreach ( IEntity o in eable )
|
||||
{
|
||||
if ( o is Mobile mobile && (from == null || (SpellHelper.ValidIndirectTarget( from, mobile ) && from.CanBeHarmful( mobile, false ))))
|
||||
{
|
||||
toExplode.Add( mobile );
|
||||
++toDamage;
|
||||
}
|
||||
else if ( o is BaseExplosionPotion && o != this )
|
||||
{
|
||||
toExplode.Add( o );
|
||||
}
|
||||
}
|
||||
if (!(targeted is IPoint3D p))
|
||||
return;
|
||||
|
||||
eable.Free();
|
||||
Map map = from.Map;
|
||||
|
||||
int min = Scale( from, MinDamage );
|
||||
int max = Scale( from, MaxDamage );
|
||||
if (map == null)
|
||||
return;
|
||||
|
||||
for ( int i = 0; i < toExplode.Count; ++i )
|
||||
{
|
||||
object o = toExplode[i];
|
||||
SpellHelper.GetSurfaceTop(ref p);
|
||||
|
||||
if ( o is Mobile m )
|
||||
{
|
||||
from?.DoHarmful( m );
|
||||
from.RevealingAction();
|
||||
|
||||
int damage = Utility.RandomMinMax( min, max );
|
||||
IEntity to = new Entity(Serial.Zero, new Point3D(p), map);
|
||||
|
||||
damage += alchemyBonus;
|
||||
if (p is Mobile m)
|
||||
{
|
||||
if (!RelativeLocation) // explosion location = current mob location.
|
||||
p = m.Location;
|
||||
else
|
||||
to = m;
|
||||
}
|
||||
|
||||
if ( !Core.AOS && damage > 40 )
|
||||
damage = 40;
|
||||
else if ( Core.AOS && toDamage > 2 )
|
||||
damage /= toDamage - 1;
|
||||
Effects.SendMovingEffect(from, to, Potion.ItemID, 7, 0, false, false, Potion.Hue, 0);
|
||||
|
||||
AOS.Damage( m, from, damage, 0, 100, 0, 0, 0 );
|
||||
}
|
||||
else if ( o is BaseExplosionPotion pot )
|
||||
{
|
||||
pot.Explode( from, false, pot.GetWorldLocation(), pot.Map );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Potion.Amount > 1) Mobile.LiftItemDupe(Potion, 1);
|
||||
|
||||
Potion.Internalize();
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(1.0), new TimerStateCallback(Potion.Reposition_OnTick),
|
||||
new object[] { from, p, map });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue