Cleanup/Housekeeping (#242)
This commit is contained in:
parent
90ede0659f
commit
741e8d8300
228 changed files with 6292 additions and 2690 deletions
|
|
@ -1,23 +1,3 @@
|
|||
/***************************************************************************
|
||||
* Region.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
|
|
@ -174,7 +154,9 @@ namespace Server
|
|||
: Array.Empty<Rectangle3D>();
|
||||
|
||||
if (Area.Length == 0)
|
||||
{
|
||||
Console.WriteLine("Empty area for region '{0}'", this);
|
||||
}
|
||||
|
||||
if (json.GetProperty("go", options, out Point3D go))
|
||||
{
|
||||
|
|
@ -232,13 +214,17 @@ namespace Server
|
|||
public int CompareTo(Region reg)
|
||||
{
|
||||
if (reg == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Dynamic regions go first
|
||||
if (Dynamic)
|
||||
{
|
||||
if (!reg.Dynamic)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (reg.Dynamic)
|
||||
{
|
||||
|
|
@ -249,7 +235,9 @@ namespace Server
|
|||
var regPriority = reg.Priority;
|
||||
|
||||
if (thisPriority != regPriority)
|
||||
{
|
||||
return regPriority - thisPriority;
|
||||
}
|
||||
|
||||
return reg.ChildLevel - ChildLevel;
|
||||
}
|
||||
|
|
@ -258,20 +246,28 @@ namespace Server
|
|||
public static Region Find(string name, Map map, bool insensitive = false)
|
||||
{
|
||||
if (insensitive)
|
||||
{
|
||||
name = name.ToLower();
|
||||
}
|
||||
|
||||
for (var i = 0; i < Regions.Count; i++)
|
||||
{
|
||||
var region = Regions[i];
|
||||
if (region.Map != map)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var rName = region.Name;
|
||||
if (insensitive)
|
||||
{
|
||||
rName = rName.ToLower();
|
||||
}
|
||||
|
||||
if (rName == name)
|
||||
{
|
||||
return region;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -280,7 +276,9 @@ namespace Server
|
|||
public static Region Find(Point3D p, Map map)
|
||||
{
|
||||
if (map == null)
|
||||
{
|
||||
return Map.Internal.DefaultRegion;
|
||||
}
|
||||
|
||||
var sector = map.GetSector(p);
|
||||
var list = sector.RegionRects;
|
||||
|
|
@ -290,7 +288,9 @@ namespace Server
|
|||
var regRect = list[i];
|
||||
|
||||
if (regRect.Contains(p))
|
||||
{
|
||||
return regRect.Region;
|
||||
}
|
||||
}
|
||||
|
||||
return map.DefaultRegion;
|
||||
|
|
@ -303,7 +303,10 @@ namespace Server
|
|||
{
|
||||
var ret = new Rectangle3D[rects.Length];
|
||||
|
||||
for (var i = 0; i < ret.Length; i++) ret[i] = ConvertTo3D(rects[i]);
|
||||
for (var i = 0; i < ret.Length; i++)
|
||||
{
|
||||
ret[i] = ConvertTo3D(rects[i]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -311,7 +314,9 @@ namespace Server
|
|||
public void Register()
|
||||
{
|
||||
if (Registered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OnRegister();
|
||||
|
||||
|
|
@ -340,6 +345,7 @@ namespace Server
|
|||
var endSector = Map.GetSector(end);
|
||||
|
||||
for (var x = startSector.X; x <= endSector.X; x++)
|
||||
{
|
||||
for (var y = startSector.Y; y <= endSector.Y; y++)
|
||||
{
|
||||
var sector = Map.GetRealSector(x, y);
|
||||
|
|
@ -347,8 +353,11 @@ namespace Server
|
|||
sector.OnEnter(this, rect);
|
||||
|
||||
if (!sectors.Contains(sector))
|
||||
{
|
||||
sectors.Add(sector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Sectors = sectors.ToArray();
|
||||
|
|
@ -357,14 +366,18 @@ namespace Server
|
|||
public void Unregister()
|
||||
{
|
||||
if (!Registered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OnUnregister();
|
||||
|
||||
Registered = false;
|
||||
|
||||
if (Children.Count > 0)
|
||||
{
|
||||
Console.WriteLine("Warning: Unregistering region '{0}' with children", this);
|
||||
}
|
||||
|
||||
if (Parent != null)
|
||||
{
|
||||
|
|
@ -377,8 +390,12 @@ namespace Server
|
|||
Map.UnregisterRegion(this);
|
||||
|
||||
if (Sectors != null)
|
||||
{
|
||||
for (var i = 0; i < Sectors.Length; i++)
|
||||
{
|
||||
Sectors[i].OnLeave(this);
|
||||
}
|
||||
}
|
||||
|
||||
Sectors = null;
|
||||
}
|
||||
|
|
@ -390,7 +407,9 @@ namespace Server
|
|||
var rect = Area[i];
|
||||
|
||||
if (rect.Contains(p))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -400,14 +419,18 @@ namespace Server
|
|||
public bool IsChildOf(Region region)
|
||||
{
|
||||
if (region == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var p = Parent;
|
||||
|
||||
while (p != null)
|
||||
{
|
||||
if (p == region)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
p = p.Parent;
|
||||
}
|
||||
|
|
@ -423,7 +446,9 @@ namespace Server
|
|||
do
|
||||
{
|
||||
if (r is T tr)
|
||||
{
|
||||
return tr;
|
||||
}
|
||||
|
||||
r = r.Parent;
|
||||
} while (r != null);
|
||||
|
|
@ -434,14 +459,18 @@ namespace Server
|
|||
public Region GetRegion(Type regionType)
|
||||
{
|
||||
if (regionType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var r = this;
|
||||
|
||||
do
|
||||
{
|
||||
if (regionType.IsInstanceOfType(r))
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
r = r.Parent;
|
||||
} while (r != null);
|
||||
|
|
@ -452,14 +481,18 @@ namespace Server
|
|||
public Region GetRegion(string regionName)
|
||||
{
|
||||
if (regionName == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var r = this;
|
||||
|
||||
do
|
||||
{
|
||||
if (r.Name == regionName)
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
r = r.Parent;
|
||||
} while (r != null);
|
||||
|
|
@ -485,8 +518,12 @@ namespace Server
|
|||
var sector = Sectors[i];
|
||||
|
||||
foreach (var player in sector.Players)
|
||||
{
|
||||
if (player.Region.IsPartOf(this))
|
||||
{
|
||||
list.Add(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
|
|
@ -501,8 +538,12 @@ namespace Server
|
|||
var sector = Sectors[i];
|
||||
|
||||
foreach (var player in sector.Players)
|
||||
{
|
||||
if (player.Region.IsPartOf(this))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
|
|
@ -517,8 +558,12 @@ namespace Server
|
|||
var sector = Sectors[i];
|
||||
|
||||
foreach (var mobile in sector.Mobiles)
|
||||
{
|
||||
if (mobile.Region.IsPartOf(this))
|
||||
{
|
||||
list.Add(mobile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
|
|
@ -533,8 +578,12 @@ namespace Server
|
|||
var sector = Sectors[i];
|
||||
|
||||
foreach (var mobile in sector.Mobiles)
|
||||
{
|
||||
if (mobile.Region.IsPartOf(this))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
|
|
@ -618,9 +667,13 @@ namespace Server
|
|||
public virtual void OnCriminalAction(Mobile m, bool message)
|
||||
{
|
||||
if (Parent != null)
|
||||
{
|
||||
Parent.OnCriminalAction(m, message);
|
||||
}
|
||||
else if (message)
|
||||
{
|
||||
m.SendLocalizedMessage(1005040); // You've committed a criminal act!!
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool AllowBeneficial(Mobile from, Mobile target) =>
|
||||
|
|
@ -683,7 +736,9 @@ namespace Server
|
|||
public virtual TimeSpan GetLogoutDelay(Mobile m)
|
||||
{
|
||||
if (Parent != null)
|
||||
{
|
||||
return Parent.GetLogoutDelay(m);
|
||||
}
|
||||
|
||||
return m.AccessLevel > AccessLevel.Player ? StaffLogoutDelay : DefaultLogoutDelay;
|
||||
}
|
||||
|
|
@ -696,10 +751,14 @@ namespace Server
|
|||
while (oldRegion != newRegion)
|
||||
{
|
||||
if (!newRegion.OnMoveInto(m, d, newLocation, oldLocation))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newRegion.Parent == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
newRegion = newRegion.Parent;
|
||||
}
|
||||
|
|
@ -713,7 +772,10 @@ namespace Server
|
|||
{
|
||||
m.CheckLightLevels(false);
|
||||
|
||||
if (oldRegion == null || oldRegion.Music != newRegion.Music) m.Send(PlayMusic.GetInstance(newRegion.Music));
|
||||
if (oldRegion == null || oldRegion.Music != newRegion.Music)
|
||||
{
|
||||
m.Send(PlayMusic.GetInstance(newRegion.Music));
|
||||
}
|
||||
}
|
||||
|
||||
var oldR = oldRegion;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: RegionLoader.cs *
|
||||
* *
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue