fix: Fixes targeting checks (#869)

* Adds CanTarget for more granular overrides of specific targeting restrictions
* Updates spell targeting
* Fixes targeting checks
This commit is contained in:
Kamron Batman 2021-12-01 08:15:16 -08:00 committed by GitHub
parent 09a3bc9754
commit bea20f36a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 104 additions and 116 deletions

View file

@ -79,6 +79,72 @@ namespace Server.Targeting
OnTargetFinish(from);
}
protected virtual bool CanTarget(Mobile from, LandTarget landTarget, ref Point3D loc, ref Map map)
{
if (!AllowGround)
{
// We should actually never get here. If we do, it's probably a misbehaving client/macro.
OnTargetCancel(from, TargetCancelType.Canceled);
return false;
}
loc = landTarget.Location;
map = from.Map;
return true;
}
protected virtual bool CanTarget(Mobile from, StaticTarget staticTarget, ref Point3D loc, ref Map map)
{
loc = staticTarget.Location;
map = from.Map;
return true;
}
protected virtual bool CanTarget(Mobile from, Item item, ref Point3D loc, ref Map map)
{
if (item.Deleted)
{
OnTargetDeleted(from, item);
return false;
}
if (!item.CanTarget)
{
OnTargetUntargetable(from, item);
return false;
}
if (!AllowNonlocal && item.RootParent is Mobile && item.RootParent != from &&
from.AccessLevel == AccessLevel.Player)
{
OnNonlocalTarget(from, item);
return false;
}
loc = item.GetWorldLocation();
map = item.Map;
return true;
}
protected virtual bool CanTarget(Mobile from, Mobile mobile, ref Point3D loc, ref Map map)
{
if (mobile.Deleted)
{
OnTargetDeleted(from, mobile);
return false;
}
if (!mobile.CanTarget)
{
OnTargetUntargetable(from, mobile);
return false;
}
loc = mobile.Location;
map = mobile.Map;
return true;
}
public void Invoke(Mobile from, object targeted)
{
CancelTimeout();
@ -91,76 +157,32 @@ namespace Server.Targeting
return;
}
Point3D loc;
Map map;
Point3D loc = default;
Map map = null;
Item item = null;
Mobile mobile = null;
bool isValidTargetType = true;
var item = targeted as Item;
var mobile = targeted as Mobile;
bool valid = targeted switch
{
LandTarget landTarget => CanTarget(from, landTarget, ref loc, ref map),
StaticTarget staticTarget => CanTarget(from, staticTarget, ref loc, ref map),
Item i => CanTarget(from, item = i, ref loc, ref map),
Mobile m => CanTarget(from, mobile = m, ref loc, ref map),
_ => isValidTargetType = false
};
if (targeted is LandTarget target)
if (!valid)
{
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)
if (!isValidTargetType)
{
OnTargetDeleted(from, mobile);
OnTargetFinish(from);
return;
OnTargetCancel(from, TargetCancelType.Canceled);
}
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))
if (map == null || map != from.Map || Range < 0 && !from.InRange(loc, Range))
{
OnTargetOutOfRange(from, targeted);
}

View file

@ -1,5 +1,3 @@
using System.Collections.Generic;
using Server.ContextMenus;
using Server.Engines.Craft;
namespace Server.Items

View file

@ -290,9 +290,8 @@ namespace Server.Items
}
else if (BaseHouse.FindHouseAt(from) != house)
{
from.SendLocalizedMessage(
1062339
); // You must be located inside of the house in which you are trying to place the contract.
// You must be located inside of the house in which you are trying to place the contract.
from.SendLocalizedMessage(1062339);
}
else if (!house.IsAosRules)
{
@ -320,15 +319,13 @@ namespace Server.Items
if (vendor)
{
from.SendLocalizedMessage(
1062342
); // You may not place a rental contract at this location while other beings occupy it.
// You may not place a rental contract at this location while other beings occupy it.
from.SendLocalizedMessage(1062342);
}
else if (contract)
{
from.SendLocalizedMessage(
1062341
); // That location is cluttered. Please clear out any objects there and try again.
// That location is cluttered. Please clear out any objects there and try again.
from.SendLocalizedMessage(1062341);
}
else
{

View file

@ -1,4 +1,3 @@
using Server.Mobiles;
using System;
using System.Collections.Generic;

View file

@ -1,5 +1,3 @@
using System;
namespace Server.Items
{
/// <summary>

View file

@ -6,7 +6,6 @@ using Server.Gumps;
using Server.Logging;
using Server.Mobiles;
using Server.Network;
using Server.Text;
namespace Server.Misc
{

View file

@ -1351,10 +1351,10 @@ namespace Server.Guilds
alliance = Alliance; // CheckLeader could possibly change the value of this.Alliance
if (alliance?.IsMember(this) == false && !alliance.IsPendingMember(this)
) // This block is there to fix a bug in the code in an older version.
// This block is there to fix a bug in the code in an older version.
if (alliance?.IsMember(this) == false && !alliance.IsPendingMember(this))
{
Alliance = null; // Will call Alliance.RemoveGuild which will set it null & perform all the pertient checks as far as alliacne disbanding
Alliance = null; // Will call Alliance.RemoveGuild which will set it null & perform all the pertinent checks as far as alliance disbanding
}
}

View file

@ -1,5 +1,4 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;

View file

@ -112,9 +112,8 @@ namespace Server.SkillHandlers
{
if (cancelType == TargetCancelType.Timeout)
{
from.SendLocalizedMessage(
501619
); // You have waited too long to make your inscribe selection, your inscription attempt has timed out.
// You have waited too long to make your inscribe selection, your inscription attempt has timed out.
from.SendLocalizedMessage(501619);
}
}
}
@ -172,9 +171,8 @@ namespace Server.SkillHandlers
{
if (cancelType == TargetCancelType.Timeout)
{
from.SendLocalizedMessage(
501619
); // You have waited too long to make your inscribe selection, your inscription attempt has timed out.
// You have waited too long to make your inscribe selection, your inscription attempt has timed out.
from.SendLocalizedMessage(501619);
}
}

View file

@ -1,6 +1,5 @@
using Server.Items;
using Server.Misc;
using Server.Targeting;
namespace Server.Spells.Fifth
{

View file

@ -3,7 +3,6 @@ using Server.Collections;
using Server.Items;
using Server.Misc;
using Server.Mobiles;
using Server.Targeting;
namespace Server.Spells.Fifth
{

View file

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Server.Mobiles;
using Server.Targeting;
namespace Server.Spells.Fourth
{

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using Server.Collections;
using Server.Engines.PartySystem;
using Server.Spells.Second;
using Server.Targeting;
namespace Server.Spells.Fourth
{

View file

@ -3,7 +3,6 @@ using Server.Collections;
using Server.Items;
using Server.Misc;
using Server.Mobiles;
using Server.Targeting;
namespace Server.Spells.Fourth
{

View file

@ -4,7 +4,6 @@ using Server.Engines.Quests;
using Server.Engines.Quests.Necro;
using Server.Items;
using Server.Mobiles;
using Server.Targeting;
using Server.Utilities;
namespace Server.Spells.Necromancy

View file

@ -1,5 +1,4 @@
using Server.Items;
using Server.Targeting;
namespace Server.Spells.Second
{

View file

@ -1,5 +1,4 @@
using Server.Items;
using Server.Targeting;
namespace Server.Spells.Second
{

View file

@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Server.Targeting;
namespace Server.Spells.Seventh
{

View file

@ -2,7 +2,6 @@ using System;
using Server.Items;
using Server.Misc;
using Server.Mobiles;
using Server.Targeting;
namespace Server.Spells.Seventh
{

View file

@ -1,7 +1,6 @@
using Server.Collections;
using Server.Items;
using Server.Mobiles;
using Server.Targeting;
namespace Server.Spells.Seventh
{

View file

@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Server.Targeting;
namespace Server.Spells.Seventh
{

View file

@ -1,6 +1,5 @@
using Server.Items;
using Server.Network;
using Server.Targeting;
namespace Server.Spells.Sixth
{

View file

@ -1,5 +1,3 @@
using Server.Targeting;
namespace Server.Spells.Sixth
{
public class MassCurseSpell : MagerySpell, ISpellTargetingPoint3D

View file

@ -2,7 +2,6 @@ using System;
using Server.Items;
using Server.Misc;
using Server.Mobiles;
using Server.Targeting;
namespace Server.Spells.Sixth
{

View file

@ -1,5 +1,4 @@
using Server.Mobiles;
using Server.Targeting;
namespace Server.Spells.Sixth
{

View file

@ -16,12 +16,12 @@ namespace Server.Spells
public ISpell Spell => _spell;
protected override bool CanTarget(Mobile from, StaticTarget staticTarget, ref Point3D loc, ref Map map) => false;
protected override bool CanTarget(Mobile from, Mobile mobile, ref Point3D loc, ref Map map) => false;
protected override void OnTarget(Mobile from, object o)
{
if (o is Item item)
{
_spell.Target(item);
}
_spell.Target(o as Item);
}
protected override void OnTargetFinish(Mobile from)

View file

@ -16,6 +16,9 @@ namespace Server.Spells
public ISpell Spell => _spell;
protected override bool CanTarget(Mobile from, StaticTarget staticTarget, ref Point3D loc, ref Map map) => false;
protected override bool CanTarget(Mobile from, Item item, ref Point3D loc, ref Map map) => false;
protected override void OnTarget(Mobile from, object o)
{
_spell.Target(o as Mobile);

View file

@ -24,10 +24,7 @@ namespace Server.Spells
protected override void OnTarget(Mobile from, object o)
{
if (o is IPoint3D p)
{
_spell.Target(p);
}
_spell.Target(o as IPoint3D);
}
protected override void OnTargetOutOfLOS(Mobile from, object o)

View file

@ -1,7 +1,6 @@
using Server.Items;
using Server.Multis;
using Server.Network;
using Server.Targeting;
namespace Server.Spells.Third
{

View file

@ -1,5 +1,4 @@
using Server.Items;
using Server.Targeting;
namespace Server.Spells.Third
{

View file

@ -5,7 +5,6 @@ using Server.Regions;
using Server.Spells.Fifth;
using Server.Spells.Fourth;
using Server.Spells.Sixth;
using Server.Targeting;
namespace Server.Spells.Third
{

View file

@ -1,7 +1,6 @@
using Server.Items;
using Server.Multis;
using Server.Network;
using Server.Targeting;
namespace Server.Spells.Third
{

View file

@ -1,7 +1,6 @@
using System;
using Server.Misc;
using Server.Mobiles;
using Server.Targeting;
namespace Server.Spells.Third
{