* Fixes a bug with the main loop. Removes unnecessary optimizations for RDRand. * WIP - Rewriting packets. * Cleanup and updates README * Converts more packets * Fixes header * Converts Effects packets. * Forgot the send command * Adds the start of containers packets. * Adds message packets with caching * Extends the send methods * Starts to add Acquire methods * Converted the packets * Cleanup * Cleanup * Adds more packets * Adds more packets * Fixes clearing arrays from pool. Adds Mobile Incoming * Converts more packets. * Moves more packets * Moves more packets * Test compression * Merges * Migrating to an idiomatic syntax that also supports compression, and proxying. * Optimize the stack alloc. Changes attributes * Converted container packets * Visual Studio doesn't auto save files. I am still getting used to subpar IDEs. * Adds static packet caching. Will profile later. Converts more packets * Fixes packets and changes how compression is configured * WIP - Adds basics for Gumps. Not finished though. * Fix file * Fixes formatting * Changed SpanWriter to be more idiomatic. * Fixes Span vs RawSpan and missing stackallocs * Converts over some more gumps * WIP - Deletes 32bit support. * Drops RDRand32 support. * Fixes gump compilation * Converting gump components * Removes old huffman compression function * Revert signature for backwards compatibility * WIP - Converting more gump components * Creates ArraySet for the strings. Updates AppendTo to reference that. * Converts the maining gump components * Cleans up gump components * Cleans up directives * Cleans up ArraySet and moves it. Adds null-coalescing-assignment * Cleanup, Target Packets, and C# 8 changes. * Removed OPL Packet * World packets * Fixing packet uses * Cleans up code. Fixes packet uses in various places. * More cleanup for packets * Code cleanup * Converts more packet uses and cleans up more code * More code cleanup * Finishes fixing the packets in Item * Updates secure trade packets * Updates core and gets it to compile. * Moved packets to scripts. Fixed account handler use of packets * Code cleanup * Updates chat packets * Code cleanuo * Adds party packets, but need to implement them. * Party packets WIP * Finishes party packets * Rearrange movement namespaces and classes * Finishes plant packets * Code Formatting * Fixes moving effects * Code cleanup, eliminates equipinfo * Adds more packets. Fixes bugs with various packets. * Finishes mahjon packets * Fixes mahjong packet * Code cleanup * Finishes mahjong packets * Adds Map packets * Add multifacet maps and charts * Cleans up some packets with UTF8 * Optimizes packets * Cleans up more packets. Moves the MessageHelper * Removes assistant support. Removes extended protocol. Incorporates MapUO packets as normal packets. * Updates protocol extensions packet receiver * Fixes a few bugs. Fixes a few more packets. * Code cleanup and fixing more packets * Fixes packet effects * Cleaned up more code * Buff Icon cleanup * Removed unused constructors * Code Cleanup. Adds BoatHS Packets * Moves house files. Updates house foundation packets. * Deployment cleanup * Fixes: * Code cleanup * More code cleanup * More code cleanup * Cleaned up BaseHouse * Enforces styling * Converts foreach to linq where possible. * Dont need that * Goals/Readme updates * Removes 32bit support at the highest level. Turns on HRT by default. * Code cleanup. Fixes extended features packet. * Fixes various bugs * Code cleanup * Code cleanup * Code cleanup. Fixes gump X/Y assignment. * Code cleanup using |= operator * More code cleanup * Cleanup * Fixes spacing issues. Thanks Visual Studio. You suck. * Compiler error * Fixes NPE from RunUO 2.7 * Renames ScriptCompiler to AssemblyHandler. Fixes packets. Updates README * Fixes more packets. Stupid trailing nulls. * Fixes various bugs. * Fixes for gumps * Fixes more gump stuff. Going to split it out later since it is getting insane * Recoded the gump writing * WIP * *Added output path of scripts project to dev branch *Activated debugging in code
250 lines
6.2 KiB
C#
250 lines
6.2 KiB
C#
/***************************************************************************
|
|
* Sector.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 Server.Items;
|
|
using Server.Network;
|
|
|
|
namespace Server
|
|
{
|
|
public class RegionRect : IComparable<RegionRect>
|
|
{
|
|
private Rectangle3D m_Rect;
|
|
|
|
public RegionRect(Region region, Rectangle3D rect)
|
|
{
|
|
Region = region;
|
|
m_Rect = rect;
|
|
}
|
|
|
|
public Region Region{ get; }
|
|
|
|
public Rectangle3D Rect => m_Rect;
|
|
|
|
public int CompareTo(RegionRect regRect) => regRect == null ? 1 : Region.CompareTo(regRect.Region);
|
|
|
|
public bool Contains(Point3D loc) => m_Rect.Contains(loc);
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
public Sector(int x, int y, Map owner)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
Owner = owner;
|
|
m_Active = false;
|
|
}
|
|
|
|
public List<RegionRect> RegionRects => m_RegionRects ?? m_DefaultRectList;
|
|
|
|
public List<BaseMulti> Multis => m_Multis ?? m_DefaultMultiList;
|
|
|
|
public List<Mobile> Mobiles => m_Mobiles ?? m_DefaultMobileList;
|
|
|
|
public List<Item> Items => m_Items ?? m_DefaultItemList;
|
|
|
|
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 Map Owner{ get; }
|
|
|
|
public int X{ get; }
|
|
|
|
public int Y{ get; }
|
|
|
|
private void Add<T>(ref List<T> list, T value)
|
|
{
|
|
list ??= new List<T>();
|
|
list.Add(value);
|
|
}
|
|
|
|
private void Remove<T>(ref List<T> list, T value)
|
|
{
|
|
if (list != null)
|
|
{
|
|
list.Remove(value);
|
|
|
|
if (list.Count == 0) list = null;
|
|
}
|
|
}
|
|
|
|
private void Replace<T>(ref List<T> list, T oldValue, T newValue)
|
|
{
|
|
if (oldValue != null && newValue != null)
|
|
{
|
|
int index = list?.IndexOf(oldValue) ?? -1;
|
|
|
|
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 void OnClientChange(NetState oldState, NetState newState)
|
|
{
|
|
Replace(ref m_Clients, oldState, newState);
|
|
}
|
|
|
|
public void OnEnter(Item item)
|
|
{
|
|
Add(ref m_Items, item);
|
|
}
|
|
|
|
public void OnLeave(Item item)
|
|
{
|
|
Remove(ref m_Items, item);
|
|
}
|
|
|
|
public void OnEnter(Mobile mob)
|
|
{
|
|
Add(ref m_Mobiles, mob);
|
|
|
|
if (mob.NetState != null) Add(ref m_Clients, mob.NetState);
|
|
|
|
if (mob.Player)
|
|
{
|
|
if (m_Players == null) Owner.ActivateSectors(X, Y);
|
|
|
|
Add(ref m_Players, mob);
|
|
}
|
|
}
|
|
|
|
public void OnLeave(Mobile mob)
|
|
{
|
|
Remove(ref m_Mobiles, mob);
|
|
|
|
if (mob.NetState != null) Remove(ref m_Clients, mob.NetState);
|
|
|
|
if (mob.Player && m_Players != null)
|
|
{
|
|
Remove(ref m_Players, mob);
|
|
|
|
if (m_Players == null) Owner.DeactivateSectors(X, Y);
|
|
}
|
|
}
|
|
|
|
public void OnEnter(Region region, Rectangle3D rect)
|
|
{
|
|
Add(ref m_RegionRects, new RegionRect(region, rect));
|
|
|
|
m_RegionRects.Sort();
|
|
|
|
UpdateMobileRegions();
|
|
}
|
|
|
|
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 (regRect.Region == region) m_RegionRects.RemoveAt(i);
|
|
}
|
|
|
|
if (m_RegionRects.Count == 0) m_RegionRects = null;
|
|
}
|
|
|
|
UpdateMobileRegions();
|
|
}
|
|
|
|
private void UpdateMobileRegions()
|
|
{
|
|
if (m_Mobiles != null)
|
|
{
|
|
List<Mobile> sandbox = new List<Mobile>(m_Mobiles);
|
|
|
|
foreach (Mobile mob in sandbox) mob.UpdateRegion();
|
|
}
|
|
}
|
|
|
|
public void OnMultiEnter(BaseMulti multi)
|
|
{
|
|
Add(ref m_Multis, multi);
|
|
}
|
|
|
|
public void OnMultiLeave(BaseMulti multi)
|
|
{
|
|
Remove(ref m_Multis, multi);
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
if (!Active && Owner != Map.Internal)
|
|
{
|
|
if (m_Items != null)
|
|
foreach (Item item in m_Items)
|
|
item.OnSectorActivate();
|
|
|
|
if (m_Mobiles != null)
|
|
foreach (Mobile mob in m_Mobiles)
|
|
mob.OnSectorActivate();
|
|
|
|
m_Active = true;
|
|
}
|
|
}
|
|
|
|
public void Deactivate()
|
|
{
|
|
if (Active)
|
|
{
|
|
if (m_Items != null)
|
|
foreach (Item item in m_Items)
|
|
item.OnSectorDeactivate();
|
|
|
|
if (m_Mobiles != null)
|
|
foreach (Mobile mob in m_Mobiles)
|
|
mob.OnSectorDeactivate();
|
|
|
|
m_Active = false;
|
|
}
|
|
}
|
|
}
|
|
}
|