Fixes code according to modern code style. Fixes a few expression bugs.

This commit is contained in:
Kamron Batman 2018-09-15 09:58:51 -07:00
parent 89eea25e5f
commit 970fd563b2
3324 changed files with 441118 additions and 433755 deletions

View file

@ -23,276 +23,295 @@ using System.Collections.Generic;
using Server.Items;
using Server.Network;
namespace Server {
public class RegionRect : IComparable {
private Rectangle3D m_Rect;
namespace Server
{
public class RegionRect : IComparable
{
private Rectangle3D m_Rect;
public Region Region { get; }
public RegionRect(Region region, Rectangle3D rect)
{
Region = region;
m_Rect = rect;
}
public Rectangle3D Rect => m_Rect;
public Region Region{ get; }
public RegionRect( Region region, Rectangle3D rect ) {
Region = region;
m_Rect = rect;
}
public Rectangle3D Rect => m_Rect;
public bool Contains( Point3D loc ) {
return m_Rect.Contains( loc );
}
int IComparable.CompareTo(object obj)
{
if (obj == null)
return 1;
int IComparable.CompareTo( object obj ) {
if ( obj == null )
return 1;
if (!(obj is RegionRect regRect))
throw new ArgumentException("obj is not a RegionRect", nameof(obj));
if ( !(obj is RegionRect regRect) )
throw new ArgumentException( "obj is not a RegionRect", nameof(obj) );
return ((IComparable)Region).CompareTo(regRect.Region);
}
return ( ( IComparable ) Region ).CompareTo( regRect.Region );
}
}
public bool Contains(Point3D loc)
{
return m_Rect.Contains(loc);
}
}
public class Sector {
private List<Mobile> m_Mobiles;
private List<Mobile> m_Players;
private List<Item> m_Items;
private List<NetState> m_Clients;
private List<BaseMulti> m_Multis;
private List<RegionRect> m_RegionRects;
private bool m_Active;
public class Sector
{
// TODO: Can we avoid this?
private static List<Mobile> m_DefaultMobileList = new List<Mobile>();
private static List<Item> m_DefaultItemList = new List<Item>();
private static List<NetState> m_DefaultClientList = new List<NetState>();
private static List<BaseMulti> m_DefaultMultiList = new List<BaseMulti>();
private static List<RegionRect> m_DefaultRectList = new List<RegionRect>();
private bool m_Active;
private List<NetState> m_Clients;
private List<Item> m_Items;
private List<Mobile> m_Mobiles;
private List<BaseMulti> m_Multis;
private List<Mobile> m_Players;
private List<RegionRect> m_RegionRects;
// TODO: Can we avoid this?
private static List<Mobile> m_DefaultMobileList = new List<Mobile>();
private static List<Item> m_DefaultItemList = new List<Item>();
private static List<NetState> m_DefaultClientList = new List<NetState>();
private static List<BaseMulti> m_DefaultMultiList = new List<BaseMulti>();
private static List<RegionRect> m_DefaultRectList = new List<RegionRect>();
public Sector(int x, int y, Map owner)
{
X = x;
Y = y;
Owner = owner;
m_Active = false;
}
public Sector( int x, int y, Map owner ) {
X = x;
Y = y;
Owner = owner;
m_Active = false;
}
public List<RegionRect> RegionRects
{
get
{
if (m_RegionRects == null)
return m_DefaultRectList;
private void Add<T>( ref List<T> list, T value ) {
if ( list == null ) {
list = new List<T>();
}
return m_RegionRects;
}
}
list.Add( value );
}
public List<BaseMulti> Multis
{
get
{
if (m_Multis == null)
return m_DefaultMultiList;
private void Remove<T>( ref List<T> list, T value ) {
if ( list != null ) {
list.Remove( value );
return m_Multis;
}
}
if ( list.Count == 0 ) {
list = null;
}
}
}
public List<Mobile> Mobiles
{
get
{
if (m_Mobiles == null)
return m_DefaultMobileList;
private void Replace<T>( ref List<T> list, T oldValue, T newValue ) {
if ( oldValue != null && newValue != null ) {
int index = list?.IndexOf( oldValue ) ?? -1;
return m_Mobiles;
}
}
if ( index >= 0 ) {
list[index] = newValue;
} else {
Add( ref list, newValue );
}
} else if ( oldValue != null ) {
Remove( ref list, oldValue );
} else if ( newValue != null ) {
Add( ref list, newValue );
}
}
public List<Item> Items
{
get
{
if (m_Items == null)
return m_DefaultItemList;
public void OnClientChange( NetState oldState, NetState newState ) {
Replace( ref m_Clients, oldState, newState );
}
return m_Items;
}
}
public void OnEnter( Item item ) {
Add( ref m_Items, item );
}
public List<NetState> Clients
{
get
{
if (m_Clients == null)
return m_DefaultClientList;
public void OnLeave( Item item ) {
Remove( ref m_Items, item );
}
return m_Clients;
}
}
public void OnEnter( Mobile mob ) {
Add( ref m_Mobiles, mob );
public List<Mobile> Players
{
get
{
if (m_Players == null)
return m_DefaultMobileList;
if ( mob.NetState != null ) {
Add( ref m_Clients, mob.NetState );
}
return m_Players;
}
}
if ( mob.Player ) {
if ( m_Players == null ) {
Owner.ActivateSectors( X, Y );
}
public bool Active => m_Active && Owner != Map.Internal;
Add( ref m_Players, mob );
}
}
public Map Owner{ get; }
public void OnLeave( Mobile mob ) {
Remove( ref m_Mobiles, mob );
public int X{ get; }
if ( mob.NetState != null ) {
Remove( ref m_Clients, mob.NetState );
}
public int Y{ get; }
if ( mob.Player && m_Players != null ) {
Remove( ref m_Players, mob );
private void Add<T>(ref List<T> list, T value)
{
if (list == null) list = new List<T>();
if ( m_Players == null ) {
Owner.DeactivateSectors( X, Y );
}
}
}
list.Add(value);
}
public void OnEnter( Region region, Rectangle3D rect ) {
Add( ref m_RegionRects, new RegionRect( region, rect ) );
private void Remove<T>(ref List<T> list, T value)
{
if (list != null)
{
list.Remove(value);
m_RegionRects.Sort();
if (list.Count == 0) list = null;
}
}
UpdateMobileRegions();
}
private void Replace<T>(ref List<T> list, T oldValue, T newValue)
{
if (oldValue != null && newValue != null)
{
int index = list?.IndexOf(oldValue) ?? -1;
public void OnLeave( Region region ) {
if ( m_RegionRects != null ) {
for ( int i = m_RegionRects.Count - 1; i >= 0; i-- ) {
RegionRect regRect = m_RegionRects[i];
if (index >= 0)
list[index] = newValue;
else
Add(ref list, newValue);
}
else if (oldValue != null)
{
Remove(ref list, oldValue);
}
else if (newValue != null)
{
Add(ref list, newValue);
}
}
if ( regRect.Region == region ) {
m_RegionRects.RemoveAt( i );
}
}
public void OnClientChange(NetState oldState, NetState newState)
{
Replace(ref m_Clients, oldState, newState);
}
if ( m_RegionRects.Count == 0 ) {
m_RegionRects = null;
}
}
public void OnEnter(Item item)
{
Add(ref m_Items, item);
}
UpdateMobileRegions();
}
public void OnLeave(Item item)
{
Remove(ref m_Items, item);
}
private void UpdateMobileRegions() {
if ( m_Mobiles != null ) {
List<Mobile> sandbox = new List<Mobile>( m_Mobiles );
public void OnEnter(Mobile mob)
{
Add(ref m_Mobiles, mob);
foreach ( Mobile mob in sandbox ) {
mob.UpdateRegion();
}
}
}
if (mob.NetState != null) Add(ref m_Clients, mob.NetState);
public void OnMultiEnter( BaseMulti multi ) {
Add( ref m_Multis, multi );
}
if (mob.Player)
{
if (m_Players == null) Owner.ActivateSectors(X, Y);
public void OnMultiLeave( BaseMulti multi ) {
Remove( ref m_Multis, multi );
}
Add(ref m_Players, mob);
}
}
public void Activate() {
if ( !Active && Owner != Map.Internal ) {
if ( m_Items != null ) {
foreach ( Item item in m_Items ) {
item.OnSectorActivate();
}
}
public void OnLeave(Mobile mob)
{
Remove(ref m_Mobiles, mob);
if ( m_Mobiles != null ) {
foreach ( Mobile mob in m_Mobiles ) {
mob.OnSectorActivate();
}
}
if (mob.NetState != null) Remove(ref m_Clients, mob.NetState);
m_Active = true;
}
}
if (mob.Player && m_Players != null)
{
Remove(ref m_Players, mob);
public void Deactivate() {
if ( Active ) {
if ( m_Items != null ) {
foreach ( Item item in m_Items ) {
item.OnSectorDeactivate();
}
}
if (m_Players == null) Owner.DeactivateSectors(X, Y);
}
}
if ( m_Mobiles != null ) {
foreach ( Mobile mob in m_Mobiles ) {
mob.OnSectorDeactivate();
}
}
public void OnEnter(Region region, Rectangle3D rect)
{
Add(ref m_RegionRects, new RegionRect(region, rect));
m_Active = false;
}
}
m_RegionRects.Sort();
public List<RegionRect> RegionRects {
get {
if ( m_RegionRects == null )
return m_DefaultRectList;
UpdateMobileRegions();
}
return m_RegionRects;
}
}
public void OnLeave(Region region)
{
if (m_RegionRects != null)
{
for (int i = m_RegionRects.Count - 1; i >= 0; i--)
{
RegionRect regRect = m_RegionRects[i];
public List<BaseMulti> Multis {
get {
if ( m_Multis == null )
return m_DefaultMultiList;
if (regRect.Region == region) m_RegionRects.RemoveAt(i);
}
return m_Multis;
}
}
if (m_RegionRects.Count == 0) m_RegionRects = null;
}
public List<Mobile> Mobiles {
get {
if ( m_Mobiles == null )
return m_DefaultMobileList;
UpdateMobileRegions();
}
return m_Mobiles;
}
}
private void UpdateMobileRegions()
{
if (m_Mobiles != null)
{
List<Mobile> sandbox = new List<Mobile>(m_Mobiles);
public List<Item> Items {
get {
if ( m_Items == null )
return m_DefaultItemList;
foreach (Mobile mob in sandbox) mob.UpdateRegion();
}
}
return m_Items;
}
}
public void OnMultiEnter(BaseMulti multi)
{
Add(ref m_Multis, multi);
}
public List<NetState> Clients {
get {
if ( m_Clients == null )
return m_DefaultClientList;
public void OnMultiLeave(BaseMulti multi)
{
Remove(ref m_Multis, multi);
}
return m_Clients;
}
}
public void Activate()
{
if (!Active && Owner != Map.Internal)
{
if (m_Items != null)
foreach (Item item in m_Items)
item.OnSectorActivate();
public List<Mobile> Players {
get {
if ( m_Players == null )
return m_DefaultMobileList;
if (m_Mobiles != null)
foreach (Mobile mob in m_Mobiles)
mob.OnSectorActivate();
return m_Players;
}
}
m_Active = true;
}
}
public bool Active => ( m_Active && Owner != Map.Internal );
public void Deactivate()
{
if (Active)
{
if (m_Items != null)
foreach (Item item in m_Items)
item.OnSectorDeactivate();
public Map Owner { get; }
if (m_Mobiles != null)
foreach (Mobile mob in m_Mobiles)
mob.OnSectorDeactivate();
public int X { get; }
public int Y { get; }
}
}
m_Active = false;
}
}
}
}