Skip to content

Commit

Permalink
add Deleted property to IEntity
Browse files Browse the repository at this point in the history
cleanup Map.GetObjectsInRange
additional hashtable -> dictionary conversions
generic timer impl for EffectController
  • Loading branch information
msturgill committed Nov 2, 2013
1 parent 4fccb0c commit 436e8f0
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 76 deletions.
20 changes: 10 additions & 10 deletions Scripts/Engines/BulkOrders/LargeBulkEntry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Collections;
using Server;

namespace Server.Engines.BulkOrders
Expand Down Expand Up @@ -127,22 +127,22 @@ public static SmallBulkEntry[] Wizard
}


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;
}
Expand Down
17 changes: 8 additions & 9 deletions Scripts/Engines/BulkOrders/SmallBulkEntry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Server;
Expand Down Expand Up @@ -43,22 +42,22 @@ public static SmallBulkEntry[] TailorLeather
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;
}
Expand Down
12 changes: 6 additions & 6 deletions Scripts/Engines/Plants/PlantHue.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server;

namespace Server.Engines.Plants
Expand Down Expand Up @@ -40,11 +40,11 @@ public enum PlantHue

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 );
Expand All @@ -69,12 +69,12 @@ static PlantHueInfo()

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()
Expand Down
80 changes: 40 additions & 40 deletions Scripts/Items/Misc/EffectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,75 +264,75 @@ public override void Deserialize( GenericReader reader )
}
}

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;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Scripts/Items/Wands/BaseWand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public BaseWand( Serial serial ) : base( serial )
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 )
Expand Down
9 changes: 9 additions & 0 deletions Server/IEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public interface IEntity : IPoint3D, IComparable, IComparable<IEntity>
Serial Serial{ get; }
Point3D Location{ get; }
Map Map{ get; }
bool Deleted { get; }

void Delete();
void ProcessDelta();
Expand Down Expand Up @@ -58,12 +59,14 @@ public int CompareTo( object other )
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 {
Expand Down Expand Up @@ -102,6 +105,12 @@ public Map Map {
}
}

public bool Deleted {
get {
return m_Deleted;
}
}

public void Delete()
{
}
Expand Down
16 changes: 8 additions & 8 deletions Server/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,19 +1382,19 @@ public bool MoveNext()
{
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;
}
}
}
Expand Down

0 comments on commit 436e8f0

Please sign in to comment.