I have rather strange idea to get mobile from target ;] Is this even possible ?

For example:

We have some bandit that is BaseCreature, that is Mobile and he is attacking some Mobile defender.

BaseCreature bandit = new Bandit();
[.......]

Target t = bandit.Target;

Is there any way to get Mobile defender from our Target t ? Any conversion/parse or something ?
 
Not sure what you are trying to do. Can you be more specific? Where is this snippet of code coming from? Are you making a targeting device, using a skill, or is the mobile itself going to do its own targeting?

Those questions aside...conversion in targeting is done by trial and error. For example, the Target has a built in overridable function called OnTarget, which takes as a parameter, and object called "targeted". What we do is test the conditions, like this:

if (targeted is Mobile)
Mobile m = (Mobile)targeted;
 
It was out of context question but if you want more specific than for example -> NecroMageAI.cs from line 892+
I just want to know if i can get Mobile from Target. Is there any way to do that ? I'm not trying to do anything yet - just learning about ServUO and its structure. ;]

private void ProcessTarget(Target targ) {
bool isDispel = (targ is DispelSpell.InternalTarget);
bool isParalyze = (targ is ParalyzeSpell.InternalTarget);
bool isTeleport = (targ is TeleportSpell.InternalTarget);
bool isAnimate = (targ is AnimateDeadSpell.InternalTarget);
bool teleportAway = false;

Mobile toTarget;
//HERE I want to get Mobile from Target targ before any ifs ect. and lets assume that I have only Target targ to work with - is it possible to achieve? toTarget = ???? targ.xxx ???
[...]
 
Last edited:
No. The "Target targ" in this case comes from when the creature thinks, and if they have something to target, then this will run, but we don't know what it is they found, nor what type of Target was even called yet. That is why the rest of that method tries to figure out what targeting process triggered the method, and by that it tries to determine the most likely candidate for the effects based on what Mobiles are either Combatant to the creature or what Mobiles are nearby, etc. "Target targ" by itself does not give us any specific Mobile to act on, nor is there even any way to extract the original "targeted" object of the Target from this call, since that is a protected internal process. Hence the rest of the method attempts to infer the Mobile "toTarget" from the bits of information it gets.
 
Back