fix: Removes players from sectors (#682)

This commit is contained in:
Kamron Batman 2021-08-13 21:25:24 -07:00 committed by GitHub
parent f795ab4698
commit 84cbd52a2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 29 deletions

View file

@ -792,7 +792,7 @@ namespace Server
for (var y = sect.Y - range; y <= sect.Y + range; ++y) for (var y = sect.Y - range; y <= sect.Y + range; ++y)
{ {
var check = GetRealSector(x, y); var check = GetRealSector(x, y);
if (check != InvalidSector && check.Players.Count > 0) if (check != InvalidSector && check.Clients.Count > 0)
{ {
return true; return true;
} }

View file

@ -509,11 +509,12 @@ namespace Server
{ {
var sector = Sectors[i]; var sector = Sectors[i];
foreach (var player in sector.Players) foreach (var ns in sector.Clients)
{ {
if (player.Region.IsPartOf(this)) var player = ns.Mobile;
if (player?.Deleted == false && player.Region.IsPartOf(this))
{ {
list.Add(player); list.Add(ns.Mobile);
} }
} }
} }
@ -529,9 +530,10 @@ namespace Server
{ {
var sector = Sectors[i]; var sector = Sectors[i];
foreach (var player in sector.Players) foreach (var ns in sector.Clients)
{ {
if (player.Region.IsPartOf(this)) var player = ns.Mobile;
if (player?.Deleted == false && player.Region.IsPartOf(this))
{ {
count++; count++;
} }

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Server.Items; using Server.Items;
using Server.Network; using Server.Network;
@ -37,7 +38,6 @@ namespace Server
private List<Item> m_Items; private List<Item> m_Items;
private List<Mobile> m_Mobiles; private List<Mobile> m_Mobiles;
private List<BaseMulti> m_Multis; private List<BaseMulti> m_Multis;
private List<Mobile> m_Players;
private List<RegionRect> m_RegionRects; private List<RegionRect> m_RegionRects;
public Sector(int x, int y, Map owner) public Sector(int x, int y, Map owner)
@ -58,8 +58,6 @@ namespace Server
public List<NetState> Clients => m_Clients ?? m_DefaultClientList; public List<NetState> Clients => m_Clients ?? m_DefaultClientList;
public List<Mobile> Players => m_Players ?? m_DefaultMobileList;
public bool Active => m_Active && Owner != Map.Internal; public bool Active => m_Active && Owner != Map.Internal;
public Map Owner { get; } public Map Owner { get; }
@ -68,6 +66,7 @@ namespace Server
public int Y { get; } public int Y { get; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Add<T>(ref List<T> list, T value) private static void Add<T>(ref List<T> list, T value)
{ {
list ??= new List<T>(); list ??= new List<T>();
@ -75,7 +74,8 @@ namespace Server
list.Add(value); list.Add(value);
} }
private void Remove<T>(ref List<T> list, T value) [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Remove<T>(ref List<T> list, T value)
{ {
if (list != null) if (list != null)
{ {
@ -88,7 +88,8 @@ namespace Server
} }
} }
private void Replace<T>(ref List<T> list, T oldValue, T newValue) [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Replace<T>(ref List<T> list, T oldValue, T newValue)
{ {
if (oldValue != null && newValue != null) if (oldValue != null && newValue != null)
{ {
@ -135,16 +136,8 @@ namespace Server
if (mob.NetState != null) if (mob.NetState != null)
{ {
Add(ref m_Clients, mob.NetState); Add(ref m_Clients, mob.NetState);
}
if (mob.Player) Owner.ActivateSectors(X, Y);
{
if (m_Players == null)
{
Owner.ActivateSectors(X, Y);
}
Add(ref m_Players, mob);
} }
} }
@ -155,16 +148,8 @@ namespace Server
if (mob.NetState != null) if (mob.NetState != null)
{ {
Remove(ref m_Clients, mob.NetState); Remove(ref m_Clients, mob.NetState);
}
if (mob.Player && m_Players != null) Owner.DeactivateSectors(X, Y);
{
Remove(ref m_Players, mob);
if (m_Players == null)
{
Owner.DeactivateSectors(X, Y);
}
} }
} }