add Deleted property to IEntity

cleanup Map.GetObjectsInRange
additional hashtable -> dictionary conversions
generic timer impl for EffectController
This commit is contained in:
Mark Sturgill 2013-11-02 10:52:08 -07:00
parent 4fccb0c3d3
commit 436e8f054a
7 changed files with 84 additions and 76 deletions

View file

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Collections;
using Server;
namespace Server.Engines.BulkOrders
@ -127,22 +127,22 @@ namespace Server.Engines.BulkOrders
}
private static Hashtable m_Cache;
private static Dictionary<string,Dictionary<string,SmallBulkEntry[]>> m_Cache;
public static SmallBulkEntry[] GetEntries( string type, string name )
{
if ( m_Cache == null )
m_Cache = new Hashtable();
if (m_Cache == null)
m_Cache = new Dictionary<string, Dictionary<string, SmallBulkEntry[]>>();
Hashtable table = (Hashtable)m_Cache[type];
Dictionary<string, SmallBulkEntry[]> table = null;
if ( table == null )
m_Cache[type] = table = new Hashtable();
if (!m_Cache.TryGetValue(type, out table))
m_Cache[type] = table = new Dictionary<string, SmallBulkEntry[]>();
SmallBulkEntry[] entries = (SmallBulkEntry[])table[name];
SmallBulkEntry[] entries = null;
if ( entries == null )
table[name] = entries = SmallBulkEntry.LoadEntries( type, name );
if (!table.TryGetValue(name, out entries))
table[name] = entries = SmallBulkEntry.LoadEntries(type, name);
return entries;
}

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Server;
@ -43,22 +42,22 @@ namespace Server.Engines.BulkOrders
get{ return GetEntries( "Tailoring", "leather" ); }
}
private static Hashtable m_Cache;
private static Dictionary<string, Dictionary<string, SmallBulkEntry[]>> m_Cache;
public static SmallBulkEntry[] GetEntries( string type, string name )
{
if ( m_Cache == null )
m_Cache = new Hashtable();
m_Cache = new Dictionary<string, Dictionary<string, SmallBulkEntry[]>>();
Hashtable table = (Hashtable)m_Cache[type];
Dictionary<string, SmallBulkEntry[]> table = null;
if ( table == null )
m_Cache[type] = table = new Hashtable();
if (!m_Cache.TryGetValue(type, out table))
m_Cache[type] = table = new Dictionary<string, SmallBulkEntry[]>();
SmallBulkEntry[] entries = (SmallBulkEntry[])table[name];
SmallBulkEntry[] entries = null;
if ( entries == null )
table[name] = entries = LoadEntries( type, name );
if (!table.TryGetValue(name, out entries))
table[name] = entries = LoadEntries(type, name);
return entries;
}

View file

@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
namespace Server.Engines.Plants
@ -40,11 +40,11 @@ namespace Server.Engines.Plants
public class PlantHueInfo
{
private static Hashtable m_Table;
private static Dictionary<PlantHue, PlantHueInfo> m_Table;
static PlantHueInfo()
{
m_Table = new Hashtable();
m_Table = new Dictionary<PlantHue, PlantHueInfo>();
m_Table[PlantHue.Plain] = new PlantHueInfo( 0, 1060813, PlantHue.Plain, 0x835 );
m_Table[PlantHue.Red] = new PlantHueInfo( 0x66D, 1060814, PlantHue.Red, 0x24 );
@ -69,12 +69,12 @@ namespace Server.Engines.Plants
public static PlantHueInfo GetInfo( PlantHue plantHue )
{
PlantHueInfo info = m_Table[plantHue] as PlantHueInfo;
PlantHueInfo info = null;
if ( info != null )
if (m_Table.TryGetValue(plantHue, out info))
return info;
else
return (PlantHueInfo)m_Table[PlantHue.Plain];
return m_Table[PlantHue.Plain];
}
public static PlantHue RandomFirstGeneration()

View file

@ -264,75 +264,75 @@ namespace Server.Items
}
}
public void PlaySound( object trigger )
public void PlaySound(IEntity trigger)
{
IEntity ent = null;
if ( m_PlaySoundAtTrigger )
if (m_PlaySoundAtTrigger)
ent = trigger as IEntity;
if ( ent == null )
if (ent == null)
ent = this;
Effects.PlaySound( (ent is Item) ? ((Item)ent).GetWorldLocation() : ent.Location, ent.Map, m_SoundID );
Effects.PlaySound((ent is Item) ? ((Item)ent).GetWorldLocation() : ent.Location, ent.Map, m_SoundID);
}
public void DoEffect( object trigger )
public void DoEffect(IEntity trigger)
{
if ( Deleted || m_TriggerType == EffectTriggerType.None )
if (Deleted || m_TriggerType == EffectTriggerType.None)
return;
if( trigger is Mobile && ((Mobile)trigger).Hidden && ((Mobile)trigger).AccessLevel > AccessLevel.Player )
if (trigger is Mobile && ((Mobile)trigger).Hidden && ((Mobile)trigger).AccessLevel > AccessLevel.Player)
return;
if ( m_SoundID > 0 )
Timer.DelayCall( m_SoundDelay, new TimerStateCallback( PlaySound ), trigger );
if (m_SoundID > 0)
Timer.DelayCall<IEntity>(m_SoundDelay, new TimerStateCallback<IEntity>(PlaySound), trigger);
if ( m_Trigger != null )
Timer.DelayCall( m_TriggerDelay, new TimerStateCallback( m_Trigger.DoEffect ), trigger );
if (m_Trigger != null)
Timer.DelayCall<IEntity>(m_TriggerDelay, new TimerStateCallback<IEntity>(m_Trigger.DoEffect), trigger);
if ( m_EffectType != ECEffectType.None )
Timer.DelayCall( m_EffectDelay, new TimerStateCallback( InternalDoEffect ), trigger );
if (m_EffectType != ECEffectType.None)
Timer.DelayCall<IEntity>(m_EffectDelay, new TimerStateCallback<IEntity>(InternalDoEffect), trigger);
}
public void InternalDoEffect( object trigger )
public void InternalDoEffect(IEntity trigger)
{
IEntity from = m_Source, to = m_Target;
if ( from == null )
from = (IEntity)trigger;
if ( to == null )
to = (IEntity)trigger;
if (from == null)
from = trigger;
switch ( m_EffectType )
if (to == null)
to = trigger;
switch (m_EffectType)
{
case ECEffectType.Lightning:
{
Effects.SendBoltEffect( from, false, m_Hue );
break;
}
{
Effects.SendBoltEffect(from, false, m_Hue);
break;
}
case ECEffectType.Location:
{
Effects.SendLocationParticles( EffectItem.Create( from.Location, from.Map, EffectItem.DefaultDuration ), m_ItemID, m_Speed, m_Duration, m_Hue, m_RenderMode, m_ParticleEffect, m_Unknown );
break;
}
{
Effects.SendLocationParticles(EffectItem.Create(from.Location, from.Map, EffectItem.DefaultDuration), m_ItemID, m_Speed, m_Duration, m_Hue, m_RenderMode, m_ParticleEffect, m_Unknown);
break;
}
case ECEffectType.Moving:
{
if ( from == this )
from = EffectItem.Create( from.Location, from.Map, EffectItem.DefaultDuration );
{
if (from == this)
from = EffectItem.Create(from.Location, from.Map, EffectItem.DefaultDuration);
if ( to == this )
to = EffectItem.Create( to.Location, to.Map, EffectItem.DefaultDuration );
if (to == this)
to = EffectItem.Create(to.Location, to.Map, EffectItem.DefaultDuration);
Effects.SendMovingParticles( from, to, m_ItemID, m_Speed, m_Duration, m_FixedDirection, m_Explodes, m_Hue, m_RenderMode, m_ParticleEffect, m_ExplodeParticleEffect, m_ExplodeSound, m_EffectLayer, m_Unknown );
break;
}
Effects.SendMovingParticles(from, to, m_ItemID, m_Speed, m_Duration, m_FixedDirection, m_Explodes, m_Hue, m_RenderMode, m_ParticleEffect, m_ExplodeParticleEffect, m_ExplodeSound, m_EffectLayer, m_Unknown);
break;
}
case ECEffectType.Target:
{
Effects.SendTargetParticles( from, m_ItemID, m_Speed, m_Duration, m_Hue, m_RenderMode, m_ParticleEffect, m_EffectLayer, m_Unknown );
break;
}
{
Effects.SendTargetParticles(from, m_ItemID, m_Speed, m_Duration, m_Hue, m_RenderMode, m_ParticleEffect, m_EffectLayer, m_Unknown);
break;
}
}
}
}

View file

@ -87,12 +87,12 @@ namespace Server.Items
public virtual void ApplyDelayTo( Mobile from )
{
from.BeginAction( typeof( BaseWand ) );
Timer.DelayCall( GetUseDelay, new TimerStateCallback( ReleaseWandLock_Callback ), from );
Timer.DelayCall<Mobile>(GetUseDelay, new TimerStateCallback<Mobile>(ReleaseWandLock_Callback), from);
}
public virtual void ReleaseWandLock_Callback( object state )
public virtual void ReleaseWandLock_Callback(Mobile state)
{
((Mobile)state).EndAction( typeof( BaseWand ) );
state.EndAction(typeof(BaseWand));
}
public override void OnDoubleClick( Mobile from )

View file

@ -27,6 +27,7 @@ namespace Server
Serial Serial{ get; }
Point3D Location{ get; }
Map Map{ get; }
bool Deleted { get; }
void Delete();
void ProcessDelta();
@ -58,12 +59,14 @@ namespace Server
private Serial m_Serial;
private Point3D m_Location;
private Map m_Map;
private bool m_Deleted;
public Entity( Serial serial, Point3D loc, Map map )
{
m_Serial = serial;
m_Location = loc;
m_Map = map;
m_Deleted = false;
}
public Serial Serial {
@ -102,6 +105,12 @@ namespace Server
}
}
public bool Deleted {
get {
return m_Deleted;
}
}
public void Delete()
{
}

View file

@ -1382,19 +1382,19 @@ namespace Server
{
IEntity e = (IEntity)m_CurrentList[m_CurrentIndex];
if (e.Deleted)
continue;
if (e is Item)
{
Item item = (Item)e;
if (!item.Deleted && item.Parent == null && m_Bounds.Contains(e.Location))
return true;
}
else if (e is Mobile)
{
Mobile m = (Mobile)e;
if (!m.Deleted && m_Bounds.Contains(e.Location))
return true;
if (item.Parent != null)
continue;
}
if (m_Bounds.Contains(e.Location))
return true;
}
}
}