diff --git a/Projects/Server/Targeting/Target.cs b/Projects/Server/Targeting/Target.cs index e60231322..90d08d3db 100644 --- a/Projects/Server/Targeting/Target.cs +++ b/Projects/Server/Targeting/Target.cs @@ -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); } diff --git a/Projects/UOContent/Items/Addons/AddonComponent.cs b/Projects/UOContent/Items/Addons/AddonComponent.cs index f32576ff7..90d74dbc0 100644 --- a/Projects/UOContent/Items/Addons/AddonComponent.cs +++ b/Projects/UOContent/Items/Addons/AddonComponent.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; -using Server.ContextMenus; using Server.Engines.Craft; namespace Server.Items diff --git a/Projects/UOContent/Items/Deeds/VendorRentalContract.cs b/Projects/UOContent/Items/Deeds/VendorRentalContract.cs index 37969839b..437d4d0f4 100644 --- a/Projects/UOContent/Items/Deeds/VendorRentalContract.cs +++ b/Projects/UOContent/Items/Deeds/VendorRentalContract.cs @@ -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 { diff --git a/Projects/UOContent/Items/Weapons/Abilities/Bladeweave.cs b/Projects/UOContent/Items/Weapons/Abilities/Bladeweave.cs index 48e69f012..3ac67b7e2 100644 --- a/Projects/UOContent/Items/Weapons/Abilities/Bladeweave.cs +++ b/Projects/UOContent/Items/Weapons/Abilities/Bladeweave.cs @@ -1,4 +1,3 @@ -using Server.Mobiles; using System; using System.Collections.Generic; diff --git a/Projects/UOContent/Items/Weapons/Abilities/DoubleShot.cs b/Projects/UOContent/Items/Weapons/Abilities/DoubleShot.cs index 8f01dea14..c32132fac 100644 --- a/Projects/UOContent/Items/Weapons/Abilities/DoubleShot.cs +++ b/Projects/UOContent/Items/Weapons/Abilities/DoubleShot.cs @@ -1,5 +1,3 @@ -using System; - namespace Server.Items { /// diff --git a/Projects/UOContent/Misc/ClientVerification.cs b/Projects/UOContent/Misc/ClientVerification.cs index 046455d2e..7b264eec8 100644 --- a/Projects/UOContent/Misc/ClientVerification.cs +++ b/Projects/UOContent/Misc/ClientVerification.cs @@ -6,7 +6,6 @@ using Server.Gumps; using Server.Logging; using Server.Mobiles; using Server.Network; -using Server.Text; namespace Server.Misc { diff --git a/Projects/UOContent/Misc/Guild.cs b/Projects/UOContent/Misc/Guild.cs index 2893071ce..bccad8bb9 100644 --- a/Projects/UOContent/Misc/Guild.cs +++ b/Projects/UOContent/Misc/Guild.cs @@ -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 } } diff --git a/Projects/UOContent/Misc/ServerList.cs b/Projects/UOContent/Misc/ServerList.cs index 7d3a95194..d457a102a 100644 --- a/Projects/UOContent/Misc/ServerList.cs +++ b/Projects/UOContent/Misc/ServerList.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Net; using System.Net.Http; using System.Net.NetworkInformation; diff --git a/Projects/UOContent/Skills/Inscribe.cs b/Projects/UOContent/Skills/Inscribe.cs index 3c97e95ee..dbcca17e8 100644 --- a/Projects/UOContent/Skills/Inscribe.cs +++ b/Projects/UOContent/Skills/Inscribe.cs @@ -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); } } diff --git a/Projects/UOContent/Spells/Fifth/DispelField.cs b/Projects/UOContent/Spells/Fifth/DispelField.cs index ff0241410..ac0bfe41e 100644 --- a/Projects/UOContent/Spells/Fifth/DispelField.cs +++ b/Projects/UOContent/Spells/Fifth/DispelField.cs @@ -1,6 +1,5 @@ using Server.Items; using Server.Misc; -using Server.Targeting; namespace Server.Spells.Fifth { diff --git a/Projects/UOContent/Spells/Fifth/PoisonField.cs b/Projects/UOContent/Spells/Fifth/PoisonField.cs index bbc26fb85..8a55f0d0b 100644 --- a/Projects/UOContent/Spells/Fifth/PoisonField.cs +++ b/Projects/UOContent/Spells/Fifth/PoisonField.cs @@ -3,7 +3,6 @@ using Server.Collections; using Server.Items; using Server.Misc; using Server.Mobiles; -using Server.Targeting; namespace Server.Spells.Fifth { diff --git a/Projects/UOContent/Spells/Fourth/ArchCure.cs b/Projects/UOContent/Spells/Fourth/ArchCure.cs index f7be3f3e9..3d7158499 100644 --- a/Projects/UOContent/Spells/Fourth/ArchCure.cs +++ b/Projects/UOContent/Spells/Fourth/ArchCure.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; using Server.Mobiles; -using Server.Targeting; namespace Server.Spells.Fourth { diff --git a/Projects/UOContent/Spells/Fourth/ArchProtection.cs b/Projects/UOContent/Spells/Fourth/ArchProtection.cs index a798ad83b..d924d4c82 100644 --- a/Projects/UOContent/Spells/Fourth/ArchProtection.cs +++ b/Projects/UOContent/Spells/Fourth/ArchProtection.cs @@ -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 { diff --git a/Projects/UOContent/Spells/Fourth/FireField.cs b/Projects/UOContent/Spells/Fourth/FireField.cs index e685fd6c0..c3979af90 100644 --- a/Projects/UOContent/Spells/Fourth/FireField.cs +++ b/Projects/UOContent/Spells/Fourth/FireField.cs @@ -3,7 +3,6 @@ using Server.Collections; using Server.Items; using Server.Misc; using Server.Mobiles; -using Server.Targeting; namespace Server.Spells.Fourth { diff --git a/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs b/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs index 47448544b..f67cdeb78 100644 --- a/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs +++ b/Projects/UOContent/Spells/Necromancy/AnimateDeadSpell.cs @@ -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 diff --git a/Projects/UOContent/Spells/Second/MagicTrap.cs b/Projects/UOContent/Spells/Second/MagicTrap.cs index 13200240f..baf6e346f 100644 --- a/Projects/UOContent/Spells/Second/MagicTrap.cs +++ b/Projects/UOContent/Spells/Second/MagicTrap.cs @@ -1,5 +1,4 @@ using Server.Items; -using Server.Targeting; namespace Server.Spells.Second { diff --git a/Projects/UOContent/Spells/Second/RemoveTrap.cs b/Projects/UOContent/Spells/Second/RemoveTrap.cs index 3850205c0..cb800ddf2 100644 --- a/Projects/UOContent/Spells/Second/RemoveTrap.cs +++ b/Projects/UOContent/Spells/Second/RemoveTrap.cs @@ -1,5 +1,4 @@ using Server.Items; -using Server.Targeting; namespace Server.Spells.Second { diff --git a/Projects/UOContent/Spells/Seventh/ChainLightning.cs b/Projects/UOContent/Spells/Seventh/ChainLightning.cs index 0286729fe..6f3ec9923 100644 --- a/Projects/UOContent/Spells/Seventh/ChainLightning.cs +++ b/Projects/UOContent/Spells/Seventh/ChainLightning.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Server.Targeting; namespace Server.Spells.Seventh { diff --git a/Projects/UOContent/Spells/Seventh/EnergyField.cs b/Projects/UOContent/Spells/Seventh/EnergyField.cs index 98177d63f..d802cd5e8 100644 --- a/Projects/UOContent/Spells/Seventh/EnergyField.cs +++ b/Projects/UOContent/Spells/Seventh/EnergyField.cs @@ -2,7 +2,6 @@ using System; using Server.Items; using Server.Misc; using Server.Mobiles; -using Server.Targeting; namespace Server.Spells.Seventh { diff --git a/Projects/UOContent/Spells/Seventh/MassDispel.cs b/Projects/UOContent/Spells/Seventh/MassDispel.cs index 9e40a0930..1b355af71 100644 --- a/Projects/UOContent/Spells/Seventh/MassDispel.cs +++ b/Projects/UOContent/Spells/Seventh/MassDispel.cs @@ -1,7 +1,6 @@ using Server.Collections; using Server.Items; using Server.Mobiles; -using Server.Targeting; namespace Server.Spells.Seventh { diff --git a/Projects/UOContent/Spells/Seventh/MeteorSwarm.cs b/Projects/UOContent/Spells/Seventh/MeteorSwarm.cs index 1d6e56825..19899f7b0 100644 --- a/Projects/UOContent/Spells/Seventh/MeteorSwarm.cs +++ b/Projects/UOContent/Spells/Seventh/MeteorSwarm.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Server.Targeting; namespace Server.Spells.Seventh { diff --git a/Projects/UOContent/Spells/Sixth/Mark.cs b/Projects/UOContent/Spells/Sixth/Mark.cs index 0f8d7d6a1..d656ea5bd 100644 --- a/Projects/UOContent/Spells/Sixth/Mark.cs +++ b/Projects/UOContent/Spells/Sixth/Mark.cs @@ -1,6 +1,5 @@ using Server.Items; using Server.Network; -using Server.Targeting; namespace Server.Spells.Sixth { diff --git a/Projects/UOContent/Spells/Sixth/MassCurse.cs b/Projects/UOContent/Spells/Sixth/MassCurse.cs index bbd7e183e..069805a0f 100644 --- a/Projects/UOContent/Spells/Sixth/MassCurse.cs +++ b/Projects/UOContent/Spells/Sixth/MassCurse.cs @@ -1,5 +1,3 @@ -using Server.Targeting; - namespace Server.Spells.Sixth { public class MassCurseSpell : MagerySpell, ISpellTargetingPoint3D diff --git a/Projects/UOContent/Spells/Sixth/ParalyzeField.cs b/Projects/UOContent/Spells/Sixth/ParalyzeField.cs index 475bc4406..8a018caba 100644 --- a/Projects/UOContent/Spells/Sixth/ParalyzeField.cs +++ b/Projects/UOContent/Spells/Sixth/ParalyzeField.cs @@ -2,7 +2,6 @@ using System; using Server.Items; using Server.Misc; using Server.Mobiles; -using Server.Targeting; namespace Server.Spells.Sixth { diff --git a/Projects/UOContent/Spells/Sixth/Reveal.cs b/Projects/UOContent/Spells/Sixth/Reveal.cs index 653594d25..edaf005a3 100644 --- a/Projects/UOContent/Spells/Sixth/Reveal.cs +++ b/Projects/UOContent/Spells/Sixth/Reveal.cs @@ -1,5 +1,4 @@ using Server.Mobiles; -using Server.Targeting; namespace Server.Spells.Sixth { diff --git a/Projects/UOContent/Spells/Targeting/SpellTargetItem.cs b/Projects/UOContent/Spells/Targeting/SpellTargetItem.cs index 0bab04b1d..3d29a33a5 100644 --- a/Projects/UOContent/Spells/Targeting/SpellTargetItem.cs +++ b/Projects/UOContent/Spells/Targeting/SpellTargetItem.cs @@ -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) diff --git a/Projects/UOContent/Spells/Targeting/SpellTargetMobile.cs b/Projects/UOContent/Spells/Targeting/SpellTargetMobile.cs index b8e245cf7..c97511dcd 100644 --- a/Projects/UOContent/Spells/Targeting/SpellTargetMobile.cs +++ b/Projects/UOContent/Spells/Targeting/SpellTargetMobile.cs @@ -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); diff --git a/Projects/UOContent/Spells/Targeting/SpellTargetPoint3D.cs b/Projects/UOContent/Spells/Targeting/SpellTargetPoint3D.cs index 40da7d383..ba6b4838b 100644 --- a/Projects/UOContent/Spells/Targeting/SpellTargetPoint3D.cs +++ b/Projects/UOContent/Spells/Targeting/SpellTargetPoint3D.cs @@ -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) diff --git a/Projects/UOContent/Spells/Third/MagicLock.cs b/Projects/UOContent/Spells/Third/MagicLock.cs index 55da042cc..76b0ef7a6 100644 --- a/Projects/UOContent/Spells/Third/MagicLock.cs +++ b/Projects/UOContent/Spells/Third/MagicLock.cs @@ -1,7 +1,6 @@ using Server.Items; using Server.Multis; using Server.Network; -using Server.Targeting; namespace Server.Spells.Third { diff --git a/Projects/UOContent/Spells/Third/Telekinesis.cs b/Projects/UOContent/Spells/Third/Telekinesis.cs index f41be5a7f..aeb3a24be 100644 --- a/Projects/UOContent/Spells/Third/Telekinesis.cs +++ b/Projects/UOContent/Spells/Third/Telekinesis.cs @@ -1,5 +1,4 @@ using Server.Items; -using Server.Targeting; namespace Server.Spells.Third { diff --git a/Projects/UOContent/Spells/Third/Teleport.cs b/Projects/UOContent/Spells/Third/Teleport.cs index c2797f9f4..9e2b2236a 100644 --- a/Projects/UOContent/Spells/Third/Teleport.cs +++ b/Projects/UOContent/Spells/Third/Teleport.cs @@ -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 { diff --git a/Projects/UOContent/Spells/Third/Unlock.cs b/Projects/UOContent/Spells/Third/Unlock.cs index 6476bd0c7..715cf1e82 100644 --- a/Projects/UOContent/Spells/Third/Unlock.cs +++ b/Projects/UOContent/Spells/Third/Unlock.cs @@ -1,7 +1,6 @@ using Server.Items; using Server.Multis; using Server.Network; -using Server.Targeting; namespace Server.Spells.Third { diff --git a/Projects/UOContent/Spells/Third/WallOfStone.cs b/Projects/UOContent/Spells/Third/WallOfStone.cs index fd4bd0b2d..0be6b4b9c 100644 --- a/Projects/UOContent/Spells/Third/WallOfStone.cs +++ b/Projects/UOContent/Spells/Third/WallOfStone.cs @@ -1,7 +1,6 @@ using System; using Server.Misc; using Server.Mobiles; -using Server.Targeting; namespace Server.Spells.Third {