* 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
341 lines
9.4 KiB
C#
341 lines
9.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Xml;
|
|
using Server.Mobiles;
|
|
|
|
namespace Server.Regions
|
|
{
|
|
public class GuardedRegion : BaseRegion
|
|
{
|
|
private static object[] m_GuardParams = new object[1];
|
|
|
|
private Dictionary<Mobile, GuardTimer> m_GuardCandidates = new Dictionary<Mobile, GuardTimer>();
|
|
private Type m_GuardType;
|
|
|
|
public GuardedRegion(string name, Map map, int priority, params Rectangle3D[] area) : base(name, map, priority, area) => m_GuardType = DefaultGuardType;
|
|
|
|
public GuardedRegion(string name, Map map, int priority, params Rectangle2D[] area)
|
|
: base(name, map, priority, area) =>
|
|
m_GuardType = DefaultGuardType;
|
|
|
|
public GuardedRegion(XmlElement xml, Map map, Region parent) : base(xml, map, parent)
|
|
{
|
|
XmlElement el = xml["guards"];
|
|
|
|
if (ReadType(el, "type", ref m_GuardType, false))
|
|
{
|
|
if (!typeof(Mobile).IsAssignableFrom(m_GuardType))
|
|
{
|
|
Console.WriteLine("Invalid guard type for region '{0}'", this);
|
|
m_GuardType = DefaultGuardType;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_GuardType = DefaultGuardType;
|
|
}
|
|
|
|
bool disabled = false;
|
|
if (ReadBoolean(el, "disabled", ref disabled, false))
|
|
Disabled = disabled;
|
|
}
|
|
|
|
public bool Disabled{ get; set; }
|
|
|
|
public virtual bool AllowReds => Core.AOS;
|
|
|
|
public virtual Type DefaultGuardType
|
|
{
|
|
get
|
|
{
|
|
if (Map == Map.Ilshenar || Map == Map.Malas)
|
|
return typeof(ArcherGuard);
|
|
return typeof(WarriorGuard);
|
|
}
|
|
}
|
|
|
|
public virtual bool IsDisabled() => Disabled;
|
|
|
|
public static void Initialize()
|
|
{
|
|
CommandSystem.Register("CheckGuarded", AccessLevel.GameMaster, CheckGuarded_OnCommand);
|
|
CommandSystem.Register("SetGuarded", AccessLevel.Administrator, SetGuarded_OnCommand);
|
|
CommandSystem.Register("ToggleGuarded", AccessLevel.Administrator, ToggleGuarded_OnCommand);
|
|
}
|
|
|
|
[Usage("CheckGuarded")]
|
|
[Description("Returns a value indicating if the current region is guarded or not.")]
|
|
private static void CheckGuarded_OnCommand(CommandEventArgs e)
|
|
{
|
|
Mobile from = e.Mobile;
|
|
GuardedRegion reg = from.Region.GetRegion<GuardedRegion>();
|
|
|
|
if (reg == null)
|
|
from.SendMessage("You are not in a guardable region.");
|
|
else if (reg.Disabled)
|
|
from.SendMessage("The guards in this region have been disabled.");
|
|
else
|
|
from.SendMessage("This region is actively guarded.");
|
|
}
|
|
|
|
[Usage("SetGuarded <true|false>")]
|
|
[Description("Enables or disables guards for the current region.")]
|
|
private static void SetGuarded_OnCommand(CommandEventArgs e)
|
|
{
|
|
Mobile from = e.Mobile;
|
|
|
|
if (e.Length == 1)
|
|
{
|
|
GuardedRegion reg = from.Region.GetRegion<GuardedRegion>();
|
|
|
|
if (reg == null)
|
|
from.SendMessage("You are not in a guardable region.");
|
|
else
|
|
{
|
|
reg.Disabled = !e.GetBoolean(0);
|
|
|
|
from.SendMessage(reg.Disabled
|
|
? "The guards in this region have been disabled."
|
|
: "The guards in this region have been enabled.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
from.SendMessage("Format: SetGuarded <true|false>");
|
|
}
|
|
}
|
|
|
|
[Usage("ToggleGuarded")]
|
|
[Description("Toggles the state of guards for the current region.")]
|
|
private static void ToggleGuarded_OnCommand(CommandEventArgs e)
|
|
{
|
|
Mobile from = e.Mobile;
|
|
GuardedRegion reg = from.Region.GetRegion<GuardedRegion>();
|
|
|
|
if (reg == null)
|
|
{
|
|
from.SendMessage("You are not in a guardable region.");
|
|
}
|
|
else
|
|
{
|
|
reg.Disabled = !reg.Disabled;
|
|
|
|
if (reg.Disabled)
|
|
from.SendMessage("The guards in this region have been disabled.");
|
|
else
|
|
from.SendMessage("The guards in this region have been enabled.");
|
|
}
|
|
}
|
|
|
|
public static GuardedRegion Disable(GuardedRegion reg)
|
|
{
|
|
reg.Disabled = true;
|
|
return reg;
|
|
}
|
|
|
|
public virtual bool CheckVendorAccess(BaseVendor vendor, Mobile from)
|
|
{
|
|
if (from.AccessLevel >= AccessLevel.GameMaster || IsDisabled())
|
|
return true;
|
|
|
|
return from.Kills < 5;
|
|
}
|
|
|
|
public override bool OnBeginSpellCast(Mobile m, ISpell s)
|
|
{
|
|
if (!IsDisabled() && !s.OnCastInTown(this))
|
|
{
|
|
m.SendLocalizedMessage(500946); // You cannot cast this in town!
|
|
return false;
|
|
}
|
|
|
|
return base.OnBeginSpellCast(m, s);
|
|
}
|
|
|
|
public override bool AllowHousing(Mobile from, Point3D p) => false;
|
|
|
|
public override void MakeGuard(Mobile focus)
|
|
{
|
|
IPooledEnumerable<BaseGuard> eable = focus.GetMobilesInRange<BaseGuard>(8);
|
|
BaseGuard useGuard = eable.FirstOrDefault(m => m.Focus == null);
|
|
|
|
eable.Free();
|
|
|
|
if (useGuard == null)
|
|
{
|
|
m_GuardParams[0] = focus;
|
|
|
|
try
|
|
{
|
|
Activator.CreateInstance(m_GuardType, m_GuardParams);
|
|
}
|
|
catch
|
|
{
|
|
// ignored
|
|
}
|
|
}
|
|
else
|
|
{
|
|
useGuard.Focus = focus;
|
|
}
|
|
}
|
|
|
|
public override void OnEnter(Mobile m)
|
|
{
|
|
if (IsDisabled())
|
|
return;
|
|
|
|
if (!AllowReds && m.Kills >= 5)
|
|
CheckGuardCandidate(m);
|
|
}
|
|
|
|
public override void OnSpeech(SpeechEventArgs args)
|
|
{
|
|
base.OnSpeech(args);
|
|
|
|
if (IsDisabled())
|
|
return;
|
|
|
|
if (args.Mobile.Alive && args.HasKeyword(0x0007)) // *guards*
|
|
CallGuards(args.Mobile.Location);
|
|
}
|
|
|
|
public override void OnAggressed(Mobile aggressor, Mobile aggressed, bool criminal)
|
|
{
|
|
base.OnAggressed(aggressor, aggressed, criminal);
|
|
|
|
if (!IsDisabled() && aggressor != aggressed && criminal)
|
|
CheckGuardCandidate(aggressor);
|
|
}
|
|
|
|
public override void OnGotBeneficialAction(Mobile helper, Mobile helped)
|
|
{
|
|
base.OnGotBeneficialAction(helper, helped);
|
|
|
|
if (IsDisabled())
|
|
return;
|
|
|
|
int noto = Notoriety.Compute(helper, helped);
|
|
|
|
if (helper != helped && (noto == Notoriety.Criminal || noto == Notoriety.Murderer))
|
|
CheckGuardCandidate(helper);
|
|
}
|
|
|
|
public override void OnCriminalAction(Mobile m, bool message)
|
|
{
|
|
base.OnCriminalAction(m, message);
|
|
|
|
if (!IsDisabled())
|
|
CheckGuardCandidate(m);
|
|
}
|
|
|
|
public void CheckGuardCandidate(Mobile m)
|
|
{
|
|
if (IsDisabled() || !IsGuardCandidate(m))
|
|
return;
|
|
|
|
if (!m_GuardCandidates.TryGetValue(m, out GuardTimer timer))
|
|
{
|
|
timer = new GuardTimer(m, m_GuardCandidates);
|
|
timer.Start();
|
|
|
|
m_GuardCandidates[m] = timer;
|
|
m.SendLocalizedMessage(502275); // Guards can now be called on you!
|
|
|
|
Map map = m.Map;
|
|
|
|
if (map == null)
|
|
return;
|
|
|
|
Mobile fakeCall = null;
|
|
double prio = 0.0;
|
|
|
|
foreach (Mobile v in m.GetMobilesInRange(8))
|
|
if (!v.Player && v != m && !IsGuardCandidate(v) &&
|
|
((v as BaseCreature)?.IsHumanInTown() ?? v.Body.IsHuman && v.Region.IsPartOf(this)))
|
|
{
|
|
double dist = m.GetDistanceToSqrt(v);
|
|
|
|
if (fakeCall == null || dist < prio)
|
|
{
|
|
fakeCall = v;
|
|
prio = dist;
|
|
}
|
|
}
|
|
|
|
if (fakeCall != null)
|
|
{
|
|
fakeCall.Say(Utility.RandomList(1007037, 501603, 1013037, 1013038, 1013039, 1013041, 1013042,
|
|
1013043, 1013052));
|
|
MakeGuard(m);
|
|
timer.Stop();
|
|
m_GuardCandidates.Remove(m);
|
|
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
|
}
|
|
}
|
|
else
|
|
{
|
|
timer.Stop();
|
|
timer.Start();
|
|
}
|
|
}
|
|
|
|
public void CallGuards(Point3D p)
|
|
{
|
|
if (IsDisabled())
|
|
return;
|
|
|
|
IPooledEnumerable<Mobile> eable = Map.GetMobilesInRange(p, 14);
|
|
|
|
foreach (Mobile m in eable)
|
|
if (IsGuardCandidate(m) &&
|
|
(!AllowReds && m.Kills >= 5 && m.Region.IsPartOf(this) || m_GuardCandidates.ContainsKey(m)))
|
|
{
|
|
if (m_GuardCandidates.TryGetValue(m, out GuardTimer timer))
|
|
{
|
|
timer.Stop();
|
|
m_GuardCandidates.Remove(m);
|
|
}
|
|
|
|
MakeGuard(m);
|
|
m.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
|
break;
|
|
}
|
|
|
|
eable.Free();
|
|
}
|
|
|
|
public bool IsGuardCandidate(Mobile m)
|
|
{
|
|
if (m is BaseGuard || !m.Alive || m.AccessLevel > AccessLevel.Player || m.Blessed ||
|
|
m is BaseCreature creature && creature.IsInvulnerable || IsDisabled())
|
|
return false;
|
|
|
|
return !AllowReds && m.Kills >= 5 || m.Criminal;
|
|
}
|
|
|
|
private class GuardTimer : Timer
|
|
{
|
|
private Mobile m_Mobile;
|
|
private Dictionary<Mobile, GuardTimer> m_Table;
|
|
|
|
public GuardTimer(Mobile m, Dictionary<Mobile, GuardTimer> table) : base(TimeSpan.FromSeconds(15.0))
|
|
{
|
|
Priority = TimerPriority.TwoFiftyMS;
|
|
|
|
m_Mobile = m;
|
|
m_Table = table;
|
|
}
|
|
|
|
protected override void OnTick()
|
|
{
|
|
if (m_Table.ContainsKey(m_Mobile))
|
|
{
|
|
m_Table.Remove(m_Mobile);
|
|
m_Mobile.SendLocalizedMessage(502276); // Guards can no longer be called on you.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|