Fixes dictionary uses (#7)
This commit is contained in:
parent
d4a52344f2
commit
916d404c51
161 changed files with 1211 additions and 1722 deletions
|
|
@ -107,7 +107,7 @@ namespace Server.Misc
|
|||
m.Send(new BeginHandshake());
|
||||
|
||||
if (m_Dictionary.TryGetValue(m, out Timer t))
|
||||
t?.Stop();
|
||||
t.Stop();
|
||||
|
||||
m_Dictionary[m] = t = Timer.DelayCall(Settings.HandshakeTimeout, OnHandshakeTimeout, m);
|
||||
t.Start();
|
||||
|
|
@ -124,7 +124,7 @@ namespace Server.Misc
|
|||
Mobile m = state.Mobile;
|
||||
if (m_Dictionary.TryGetValue(m, out Timer t))
|
||||
{
|
||||
t?.Stop();
|
||||
t.Stop();
|
||||
|
||||
m_Dictionary.Remove(m);
|
||||
}
|
||||
|
|
@ -159,7 +159,7 @@ namespace Server.Misc
|
|||
{
|
||||
if (m == null)
|
||||
return;
|
||||
|
||||
|
||||
if (m.NetState != null && m.NetState.Running)
|
||||
m.NetState.Dispose();
|
||||
|
||||
|
|
@ -179,4 +179,4 @@ namespace Server.Misc
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,14 +114,14 @@ namespace Server
|
|||
if (!m_Temps.TryGetValue( localType, out Queue<LocalBuilder> list ))
|
||||
m_Temps[localType] = list = new Queue<LocalBuilder>();
|
||||
|
||||
if ( list.Count > 0 )
|
||||
return list.Dequeue();
|
||||
|
||||
return CreateLocal( localType );
|
||||
return list.Count > 0 ? list.Dequeue() : CreateLocal( localType );
|
||||
}
|
||||
|
||||
public void ReleaseTemp( LocalBuilder local )
|
||||
{
|
||||
if (local.LocalType == null)
|
||||
return;
|
||||
|
||||
if (!m_Temps.TryGetValue( local.LocalType, out Queue<LocalBuilder> list ))
|
||||
m_Temps[local.LocalType] = list = new Queue<LocalBuilder>();
|
||||
|
||||
|
|
|
|||
|
|
@ -242,18 +242,11 @@ namespace Server.Guilds
|
|||
for (int i = 0; i < m_Members.Count; i++)
|
||||
m_Members[i].Alliance = null;
|
||||
|
||||
Alliances.TryGetValue(Name.ToLower(), out AllianceInfo aInfo);
|
||||
|
||||
if (aInfo == this)
|
||||
if (Alliances.TryGetValue(Name.ToLower(), out AllianceInfo aInfo) && aInfo == this)
|
||||
Alliances.Remove(Name.ToLower());
|
||||
}
|
||||
|
||||
public void InvalidateMemberProperties()
|
||||
{
|
||||
InvalidateMemberProperties(false);
|
||||
}
|
||||
|
||||
public void InvalidateMemberProperties(bool onlyOPL)
|
||||
public void InvalidateMemberProperties(bool onlyOPL = false)
|
||||
{
|
||||
for (int i = 0; i < m_Members.Count; i++)
|
||||
{
|
||||
|
|
@ -1449,11 +1442,7 @@ namespace Server.Guilds
|
|||
if (m == null)
|
||||
continue;
|
||||
|
||||
if (!votes.TryGetValue(m, out int v))
|
||||
votes[m] = 1;
|
||||
else
|
||||
votes[m] = v + 1;
|
||||
|
||||
votes[m] = 1 + (votes.TryGetValue(m, out int v) ? v : 0);
|
||||
votingMembers++;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -405,9 +405,7 @@ namespace Server.Misc
|
|||
|
||||
for ( int i = 0; i < split.Length; ++i )
|
||||
{
|
||||
m_KeywordHash.TryGetValue( split[i], out string keyword );
|
||||
|
||||
if ( keyword != null )
|
||||
if (m_KeywordHash.TryGetValue( split[i], out string keyword ))
|
||||
keywordsFound.Add( keyword );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,15 +8,15 @@ namespace Server.Misc
|
|||
/**
|
||||
* This file requires to be saved in a Unicode
|
||||
* compatible format.
|
||||
*
|
||||
*
|
||||
* Warning: if you change String.Format methods,
|
||||
* please note that the following character
|
||||
* is suggested before any left-to-right text
|
||||
* in order to prevent undesired formatting
|
||||
* resulting from mixing LR and RL text:
|
||||
*
|
||||
*
|
||||
* Use this one if you need to force RL:
|
||||
*
|
||||
*
|
||||
* If you do not see the above chars, please
|
||||
* enable showing of unicode control chars
|
||||
**/
|
||||
|
|
@ -199,17 +199,17 @@ namespace Server.Misc
|
|||
|
||||
string lang = mob?.Language;
|
||||
|
||||
if (lang != null)
|
||||
{
|
||||
lang = lang.ToUpper();
|
||||
if (lang == null)
|
||||
continue;
|
||||
|
||||
if (!ht.ContainsKey(lang))
|
||||
ht[lang] = new InternationalCodeCounter(lang);
|
||||
else
|
||||
ht[lang].Increase();
|
||||
lang = lang.ToUpper();
|
||||
|
||||
break;
|
||||
}
|
||||
if (ht.TryGetValue(lang, out InternationalCodeCounter codes))
|
||||
codes.Increase();
|
||||
else
|
||||
ht[lang] = new InternationalCodeCounter(lang);
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
foreach (Mobile mob in World.Mobiles.Values)
|
||||
|
|
@ -217,15 +217,15 @@ namespace Server.Misc
|
|||
{
|
||||
string lang = mob.Language;
|
||||
|
||||
if (lang != null)
|
||||
{
|
||||
lang = lang.ToUpper();
|
||||
if (lang == null)
|
||||
continue;
|
||||
|
||||
if (!ht.ContainsKey(lang))
|
||||
ht[lang] = new InternationalCodeCounter(lang);
|
||||
else
|
||||
ht[lang].Increase();
|
||||
}
|
||||
lang = lang.ToUpper();
|
||||
|
||||
if (ht.TryGetValue(lang, out InternationalCodeCounter codes))
|
||||
codes.Increase();
|
||||
else
|
||||
ht[lang] = new InternationalCodeCounter(lang);
|
||||
}
|
||||
|
||||
writer.WriteLine(
|
||||
|
|
@ -350,4 +350,4 @@ namespace Server.Misc
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,12 +45,7 @@ namespace Server
|
|||
|
||||
public static string RandomName( string type )
|
||||
{
|
||||
NameList list = GetNameList( type );
|
||||
|
||||
if ( list != null )
|
||||
return list.GetRandomName();
|
||||
|
||||
return "";
|
||||
return GetNameList( type )?.GetRandomName() ?? "";
|
||||
}
|
||||
|
||||
private static Dictionary<string, NameList> m_Table;
|
||||
|
|
|
|||
|
|
@ -488,10 +488,7 @@ namespace Server.Items
|
|||
if ( m_TypeTable == null )
|
||||
return CraftResource.None;
|
||||
|
||||
if (!m_TypeTable.TryGetValue(resourceType, out CraftResource res))
|
||||
return CraftResource.None;
|
||||
|
||||
return res;
|
||||
return m_TypeTable.TryGetValue(resourceType, out CraftResource res) ? res : CraftResource.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -392,9 +392,10 @@ namespace Server
|
|||
if (flags != ShopFlags.None)
|
||||
{
|
||||
Point2D p = new Point2D(x, y);
|
||||
ShopInfo si = m_ShopTable[p];
|
||||
|
||||
if (si == null)
|
||||
if (m_ShopTable.TryGetValue(p, out ShopInfo si))
|
||||
si.m_Flags |= flags;
|
||||
else
|
||||
{
|
||||
List<Point2D> floor = new List<Point2D>();
|
||||
|
||||
|
|
@ -409,10 +410,6 @@ namespace Server
|
|||
for (int i = 0; i < floor.Count; ++i)
|
||||
m_ShopTable[floor[i]] = si;
|
||||
}
|
||||
else
|
||||
{
|
||||
si.m_Flags |= flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,9 +45,7 @@ namespace Server.Misc
|
|||
if ( facet == null )
|
||||
return null;
|
||||
|
||||
m_WeatherByFacet.TryGetValue( facet, out List<Weather> list );
|
||||
|
||||
if ( list == null )
|
||||
if (!m_WeatherByFacet.TryGetValue( facet, out List<Weather> list ))
|
||||
m_WeatherByFacet[facet] = list = new List<Weather>();
|
||||
|
||||
return list;
|
||||
|
|
@ -74,10 +72,8 @@ namespace Server.Misc
|
|||
if ( !isValid )
|
||||
continue;
|
||||
|
||||
Weather w = new Weather( m_Facets[i], new[]{ area }, temperature, chanceOfPercipitation, chanceOfExtremeTemperature, TimeSpan.FromSeconds( 30.0 ) );
|
||||
|
||||
w.Bounds = bounds;
|
||||
w.MoveSpeed = moveSpeed;
|
||||
new Weather(m_Facets[i], new[] { area }, temperature, chanceOfPercipitation, chanceOfExtremeTemperature,
|
||||
TimeSpan.FromSeconds(30.0)) { Bounds = bounds, MoveSpeed = moveSpeed };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,36 +123,13 @@ namespace Server.Misc
|
|||
|
||||
public static bool CheckIntersection( Rectangle2D r1, Rectangle2D r2 )
|
||||
{
|
||||
if ( r1.X >= (r2.X + r2.Width) )
|
||||
return false;
|
||||
|
||||
if ( r2.X >= (r1.X + r1.Width) )
|
||||
return false;
|
||||
|
||||
if ( r1.Y >= (r2.Y + r2.Height) )
|
||||
return false;
|
||||
|
||||
if ( r2.Y >= (r1.Y + r1.Height) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return r1.X < r2.X + r2.Width && r2.X < r1.X + r1.Width && r1.Y < r2.Y + r2.Height && r2.Y < r1.Y + r1.Height;
|
||||
}
|
||||
|
||||
public static bool CheckContains( Rectangle2D big, Rectangle2D small )
|
||||
{
|
||||
if ( small.X < big.X )
|
||||
return false;
|
||||
|
||||
if ( small.Y < big.Y )
|
||||
return false;
|
||||
|
||||
if ( (small.X + small.Width) > (big.X + big.Width) )
|
||||
return false;
|
||||
|
||||
if ( (small.Y + small.Height) > (big.Y + big.Height) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return small.X >= big.X && small.Y >= big.Y && small.X + small.Width <= big.X + big.Width
|
||||
&& small.Y + small.Height <= big.Y + big.Height;
|
||||
}
|
||||
|
||||
public virtual bool IntersectsWith( Rectangle2D area )
|
||||
|
|
@ -182,7 +155,7 @@ namespace Server.Misc
|
|||
|
||||
list?.Add( this );
|
||||
|
||||
Timer.DelayCall( TimeSpan.FromSeconds( (0.2+(Utility.RandomDouble()*0.8)) * interval.TotalSeconds ), interval, OnTick );
|
||||
Timer.DelayCall( TimeSpan.FromSeconds( (0.2+Utility.RandomDouble()*0.8) * interval.TotalSeconds ), interval, OnTick );
|
||||
}
|
||||
|
||||
public virtual void Reposition()
|
||||
|
|
@ -231,8 +204,8 @@ namespace Server.Misc
|
|||
|
||||
for ( int i = 0; i < 5; ++i ) // try 5 times to find a valid spot
|
||||
{
|
||||
int xOffset = (MoveSpeed * MoveAngleX) / 100;
|
||||
int yOffset = (MoveSpeed * MoveAngleY) / 100;
|
||||
int xOffset = MoveSpeed * MoveAngleX / 100;
|
||||
int yOffset = MoveSpeed * MoveAngleY / 100;
|
||||
|
||||
Rectangle2D oldArea = Area[0];
|
||||
Rectangle2D newArea = new Rectangle2D( oldArea.X + xOffset, oldArea.Y + yOffset, oldArea.Width, oldArea.Height );
|
||||
|
|
@ -255,8 +228,8 @@ namespace Server.Misc
|
|||
{
|
||||
if ( m_Stage == 0 )
|
||||
{
|
||||
m_Active = ( ChanceOfPercipitation > Utility.Random( 100 ) );
|
||||
m_ExtremeTemperature = ( ChanceOfExtremeTemperature > Utility.Random( 100 ) );
|
||||
m_Active = ChanceOfPercipitation > Utility.Random( 100 );
|
||||
m_ExtremeTemperature = ChanceOfExtremeTemperature > Utility.Random( 100 );
|
||||
|
||||
if ( MoveSpeed > 0 )
|
||||
{
|
||||
|
|
@ -270,9 +243,8 @@ namespace Server.Misc
|
|||
if ( m_Stage > 0 && MoveSpeed > 0 )
|
||||
MoveForward();
|
||||
|
||||
int type, density, temperature;
|
||||
|
||||
temperature = Temperature;
|
||||
int type, density;
|
||||
int temperature = Temperature;
|
||||
|
||||
if ( m_ExtremeTemperature )
|
||||
temperature *= -1;
|
||||
|
|
@ -283,7 +255,7 @@ namespace Server.Misc
|
|||
}
|
||||
else
|
||||
{
|
||||
density = 150 - (m_Stage * 5);
|
||||
density = 150 - m_Stage * 5;
|
||||
|
||||
if ( density < 10 )
|
||||
density = 10;
|
||||
|
|
@ -310,7 +282,7 @@ namespace Server.Misc
|
|||
if ( mob == null || mob.Map != Facet )
|
||||
continue;
|
||||
|
||||
bool contains = ( Area.Length == 0 );
|
||||
bool contains = Area.Length == 0;
|
||||
|
||||
for ( int j = 0; !contains && j < Area.Length; ++j )
|
||||
contains = Area[j].Contains( mob.Location );
|
||||
|
|
@ -358,7 +330,7 @@ namespace Server.Misc
|
|||
Weather w = list[i];
|
||||
|
||||
for ( int j = 0; j < w.Area.Length; ++j )
|
||||
AddWorldPin( w.Area[j].X + (w.Area[j].Width/2), w.Area[j].Y + (w.Area[j].Height/2) );
|
||||
AddWorldPin( w.Area[j].X + w.Area[j].Width/2, w.Area[j].Y + w.Area[j].Height/2 );
|
||||
}
|
||||
|
||||
base.OnDoubleClick( from );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue