* 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
288 lines
7.6 KiB
C#
288 lines
7.6 KiB
C#
/***************************************************************************
|
|
* Target.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 Server.Network;
|
|
|
|
namespace Server.Targeting
|
|
{
|
|
public abstract class Target
|
|
{
|
|
private static int _nextTargetId;
|
|
|
|
private Timer m_TimeoutTimer;
|
|
|
|
protected Target(int range, bool allowGround, TargetFlags flags)
|
|
{
|
|
TargetID = ++_nextTargetId;
|
|
Range = range;
|
|
AllowGround = allowGround;
|
|
Flags = flags;
|
|
|
|
CheckLOS = true;
|
|
}
|
|
|
|
public DateTime TimeoutTime{ get; private set; }
|
|
|
|
public bool CheckLOS{ get; set; }
|
|
|
|
public bool DisallowMultis{ get; set; }
|
|
|
|
public bool AllowNonlocal{ get; set; }
|
|
|
|
public int TargetID{ get; }
|
|
|
|
public int Range{ get; set; }
|
|
|
|
public bool AllowGround{ get; set; }
|
|
|
|
public TargetFlags Flags{ get; set; }
|
|
|
|
public static void Cancel(Mobile m)
|
|
{
|
|
Packets.SendCancelTarget(m.NetState);
|
|
m.Target?.OnTargetCancel(m, TargetCancelType.Canceled);
|
|
}
|
|
|
|
public void BeginTimeout(Mobile from, TimeSpan delay)
|
|
{
|
|
TimeoutTime = DateTime.UtcNow + delay;
|
|
|
|
m_TimeoutTimer?.Stop();
|
|
|
|
m_TimeoutTimer = new TimeoutTimer(this, from, delay);
|
|
m_TimeoutTimer.Start();
|
|
}
|
|
|
|
public void CancelTimeout()
|
|
{
|
|
m_TimeoutTimer?.Stop();
|
|
m_TimeoutTimer = null;
|
|
}
|
|
|
|
public void Timeout(Mobile from)
|
|
{
|
|
CancelTimeout();
|
|
from.ClearTarget();
|
|
|
|
Cancel(from);
|
|
|
|
OnTargetCancel(from, TargetCancelType.Timeout);
|
|
OnTargetFinish(from);
|
|
}
|
|
|
|
public virtual Packet GetPacketFor(NetState ns) => new TargetReq(this);
|
|
|
|
public void Cancel(Mobile from, TargetCancelType type)
|
|
{
|
|
CancelTimeout();
|
|
from.ClearTarget();
|
|
|
|
OnTargetCancel(from, type);
|
|
OnTargetFinish(from);
|
|
}
|
|
|
|
public void Invoke(Mobile from, object targeted)
|
|
{
|
|
CancelTimeout();
|
|
from.ClearTarget();
|
|
|
|
if (from.Deleted)
|
|
{
|
|
OnTargetCancel(from, TargetCancelType.Canceled);
|
|
OnTargetFinish(from);
|
|
return;
|
|
}
|
|
|
|
Point3D loc;
|
|
Map map;
|
|
|
|
Item item = targeted as Item;
|
|
Mobile mobile = targeted as Mobile;
|
|
|
|
if (targeted is LandTarget target)
|
|
{
|
|
loc = target.Location;
|
|
map = from.Map;
|
|
}
|
|
else if (targeted is StaticTarget staticTarget)
|
|
{
|
|
loc = staticTarget.Location;
|
|
map = from.Map;
|
|
}
|
|
else if (mobile != null)
|
|
{
|
|
if (mobile.Deleted)
|
|
{
|
|
OnTargetDeleted(from, mobile);
|
|
OnTargetFinish(from);
|
|
return;
|
|
}
|
|
|
|
if (!mobile.CanTarget)
|
|
{
|
|
OnTargetUntargetable(from, mobile);
|
|
OnTargetFinish(from);
|
|
return;
|
|
}
|
|
|
|
loc = mobile.Location;
|
|
map = mobile.Map;
|
|
}
|
|
else if (item != null)
|
|
{
|
|
if (item.Deleted)
|
|
{
|
|
OnTargetDeleted(from, item);
|
|
OnTargetFinish(from);
|
|
return;
|
|
}
|
|
|
|
if (!item.CanTarget)
|
|
{
|
|
OnTargetUntargetable(from, item);
|
|
OnTargetFinish(from);
|
|
return;
|
|
}
|
|
|
|
if (!AllowNonlocal && item.RootParent is Mobile && item.RootParent != from && from.AccessLevel == AccessLevel.Player)
|
|
{
|
|
OnNonlocalTarget(from, item);
|
|
OnTargetFinish(from);
|
|
return;
|
|
}
|
|
|
|
loc = item.GetWorldLocation();
|
|
map = item.Map;
|
|
}
|
|
else
|
|
{
|
|
OnTargetCancel(from, TargetCancelType.Canceled);
|
|
OnTargetFinish(from);
|
|
return;
|
|
}
|
|
|
|
if (map == null || map != from.Map || Range != -1 && !from.InRange(loc, Range))
|
|
{
|
|
OnTargetOutOfRange(from, targeted);
|
|
}
|
|
else
|
|
{
|
|
if (!from.CanSee(targeted))
|
|
OnCantSeeTarget(from, targeted);
|
|
else if (CheckLOS && !from.InLOS(targeted))
|
|
OnTargetOutOfLOS(from, targeted);
|
|
else if (item?.InSecureTrade == true)
|
|
OnTargetInSecureTrade(from, targeted);
|
|
else if (item?.IsAccessibleTo(from) == false)
|
|
OnTargetNotAccessible(from, targeted);
|
|
else if (item?.CheckTarget(from, this, targeted) == false)
|
|
OnTargetUntargetable(from, targeted);
|
|
else if (mobile?.CheckTarget(from, this, mobile) == false)
|
|
OnTargetUntargetable(from, mobile);
|
|
else if (from.Region.OnTarget(from, this, targeted))
|
|
OnTarget(from, targeted);
|
|
}
|
|
|
|
OnTargetFinish(from);
|
|
}
|
|
|
|
protected virtual void OnTarget(Mobile from, object targeted)
|
|
{
|
|
}
|
|
|
|
protected virtual void OnTargetNotAccessible(Mobile from, object targeted)
|
|
{
|
|
from.SendLocalizedMessage(500447); // That is not accessible.
|
|
}
|
|
|
|
protected virtual void OnTargetInSecureTrade(Mobile from, object targeted)
|
|
{
|
|
from.SendLocalizedMessage(500447); // That is not accessible.
|
|
}
|
|
|
|
protected virtual void OnNonlocalTarget(Mobile from, object targeted)
|
|
{
|
|
from.SendLocalizedMessage(500447); // That is not accessible.
|
|
}
|
|
|
|
protected virtual void OnCantSeeTarget(Mobile from, object targeted)
|
|
{
|
|
from.SendLocalizedMessage(500237); // Target can not be seen.
|
|
}
|
|
|
|
protected virtual void OnTargetOutOfLOS(Mobile from, object targeted)
|
|
{
|
|
from.SendLocalizedMessage(500237); // Target can not be seen.
|
|
}
|
|
|
|
protected virtual void OnTargetOutOfRange(Mobile from, object targeted)
|
|
{
|
|
from.SendLocalizedMessage(500446); // That is too far away.
|
|
}
|
|
|
|
protected virtual void OnTargetDeleted(Mobile from, object targeted)
|
|
{
|
|
}
|
|
|
|
protected virtual void OnTargetUntargetable(Mobile from, object targeted)
|
|
{
|
|
from.SendLocalizedMessage(500447); // That is not accessible.
|
|
}
|
|
|
|
protected virtual void OnTargetCancel(Mobile from, TargetCancelType cancelType)
|
|
{
|
|
}
|
|
|
|
protected virtual void OnTargetFinish(Mobile from)
|
|
{
|
|
}
|
|
|
|
private class TimeoutTimer : Timer
|
|
{
|
|
private static TimeSpan ThirtySeconds = TimeSpan.FromSeconds(30.0);
|
|
private static TimeSpan TenSeconds = TimeSpan.FromSeconds(10.0);
|
|
private static TimeSpan OneSecond = TimeSpan.FromSeconds(1.0);
|
|
private Mobile m_Mobile;
|
|
private Target m_Target;
|
|
|
|
public TimeoutTimer(Target target, Mobile m, TimeSpan delay) : base(delay)
|
|
{
|
|
m_Target = target;
|
|
m_Mobile = m;
|
|
|
|
if (delay >= ThirtySeconds)
|
|
Priority = TimerPriority.FiveSeconds;
|
|
else if (delay >= TenSeconds)
|
|
Priority = TimerPriority.OneSecond;
|
|
else if (delay >= OneSecond)
|
|
Priority = TimerPriority.TwoFiftyMS;
|
|
else
|
|
Priority = TimerPriority.TwentyFiveMS;
|
|
}
|
|
|
|
protected override void OnTick()
|
|
{
|
|
if (m_Mobile.Target == m_Target)
|
|
m_Target.Timeout(m_Mobile);
|
|
}
|
|
}
|
|
}
|
|
}
|