Inheritance: IPoint3D
		public static void TargetResponse( NetState state, PacketReader pvSrc )
		{
			int type = pvSrc.ReadByte();
			int targetID = pvSrc.ReadInt32();
			/*int flags = */pvSrc.ReadByte();
			Serial serial = pvSrc.ReadInt32();
			int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
			int graphic = pvSrc.ReadInt16();

			if ( targetID == unchecked( (int) 0xDEADBEEF ) )
				return;

			Mobile from = state.Mobile;

			Target t = from.Target;

			if ( t != null )
			{
				if ( x == -1 && y == -1 && !serial.IsValid )
				{
					// User pressed escape
					t.Cancel( from, TargetCancelType.Canceled );
				}
				else
				{
					object toTarget;

					if ( type == 1 )
					{
						if ( graphic == 0 )
						{
							toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
						}
						else
						{
							Map map = from.Map;

							if ( map == null || map == Map.Internal )
							{
								t.Cancel( from, TargetCancelType.Canceled );
								return;
							}
							else
							{
								Tile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );

								bool valid = false;

								for ( int i = 0; !valid && i < tiles.Length; ++i )
								{
									if ( tiles[i].Z == z && (tiles[i].ID & 0x3FFF) == (graphic & 0x3FFF) )
										valid = true;
								}

								if ( !valid )
								{
									t.Cancel( from, TargetCancelType.Canceled );
									return;
								}
								else
								{
									toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
								}
							}
						}
					}
					else if ( serial.IsMobile )
					{
						toTarget = World.FindMobile( serial );
					}
					else if ( serial.IsItem )
					{
						toTarget = World.FindItem( serial );
					}
					else
					{
						t.Cancel( from, TargetCancelType.Canceled );
						return;
					}

					try {
						t.Invoke( from, toTarget );
					} catch (Exception e) {
						log.Fatal(String.Format("Exception disarmed in target {0} > {1} > {2}",
												from, t, toTarget), e);
					}
				}
			}
		}
Exemple #2
0
        public override bool DoActionGuard()
        {
            if (m_LastTarget != null && m_LastTarget.Hidden)
            {
                Map map = m_Mobile.Map;

                if (map == null || !m_Mobile.InRange(m_LastTargetLoc, Core.ML ? 10 : 12))
                {
                    m_LastTarget = null;
                }
                else if (m_Mobile.Spell == null && DateTime.Now > m_NextCastTime)
                {
                    m_Mobile.DebugSay("I am going to reveal my last target");

                    m_RevealTarget = new LandTarget(m_LastTargetLoc, map);
                    Spell spell = new RevealSpell(m_Mobile, null);

                    if (spell.Cast())
                        m_LastTarget = null; // only do it once

                    m_NextCastTime = DateTime.Now + GetDelay(spell);
                }
            }

            if (AcquireFocusMob(m_Mobile.RangePerception, m_Mobile.FightMode, false, false, true))
            {
                m_Mobile.DebugSay("I am going to attack {0}", m_Mobile.FocusMob.Name);

                m_Mobile.Combatant = m_Mobile.FocusMob;
                Action = ActionType.Combat;
            }
            else
            {
                if (!m_Mobile.Controlled)
                {
                    ProcessTarget();

                    Spell spell = CheckCastHealingSpell();

                    if (spell != null)
                        spell.Cast();
                }

                base.DoActionGuard();
            }

            return true;
        }
Exemple #3
0
        protected virtual bool ProcessTarget()
        {
            Target targ = m_Mobile.Target;

            if (targ == null)
                return false;

            bool isDispel = (targ is DispelSpell.InternalTarget || targ is MassDispelSpell.InternalTarget);
            bool isParalyze = (targ is ParalyzeSpell.InternalTarget);
            bool isTeleport = (targ is TeleportSpell.InternalTarget);
            bool isSummon = (targ is EnergyVortexSpell.InternalTarget || targ is BladeSpiritsSpell.InternalTarget || targ is NatureFurySpell.InternalTarget);
            bool isField = (targ is FireFieldSpell.InternalTarget || targ is PoisonFieldSpell.InternalTarget || targ is ParalyzeFieldSpell.InternalTarget);
            bool isAnimate = (targ is AnimateDeadSpell.InternalTarget);
            bool isDispelField = (targ is DispelFieldSpell.InternalTarget);
            bool teleportAway = false;
            bool harmful = (targ.Flags & TargetFlags.Harmful) != 0 || targ is HailStormSpell.InternalTarget || targ is WildfireSpell.InternalTarget;
            bool beneficial = (targ.Flags & TargetFlags.Beneficial) != 0 || targ is ArchCureSpell.InternalTarget;

            if (isTeleport && m_Mobile.CanSwim)
                targ.Cancel(m_Mobile, TargetCancelType.Canceled);

            IDamageable toTarget = null;

            if (isDispel)
            {
                toTarget = FindDispelTarget(false);

                if (toTarget != null)
                    RunTo(toTarget);
            }
            else if (isDispelField)
            {
                Item field = GetHarmfulFieldItem();

                if (field != null)
                    targ.Invoke(m_Mobile, field);
                else
                    targ.Cancel(m_Mobile, TargetCancelType.Canceled);
            }
            else if (SmartAI && (isParalyze || isTeleport))
            {
                toTarget = FindDispelTarget(true);

                if (toTarget == null)
                {
                    toTarget = m_Mobile.Combatant as Mobile;

                    if (toTarget != null)
                        RunTo(toTarget);
                }
                else if (m_Mobile.InRange(toTarget, 10))
                {
                    RunFrom(toTarget);
                    teleportAway = true;
                }
                else
                {
                    teleportAway = true;
                }
            }
            else if (isAnimate)
            {
                Item corpse = FindCorpseToAnimate();

                if (corpse != null)
                    targ.Invoke(m_Mobile, corpse);
            }
            else
            {
                toTarget = m_Mobile.Combatant;

                if (toTarget != null)
                    RunTo(toTarget);
            }

            if (isSummon && toTarget != null)
            {
                int failSafe = 0;
                Map map = toTarget.Map;

                while (failSafe <= 25)
                {
                    int x = Utility.RandomMinMax(toTarget.X - 2, toTarget.X + 2);
                    int y = Utility.RandomMinMax(toTarget.Y - 2, toTarget.Y + 2);
                    int z = toTarget.Z;

                    LandTarget lt = new LandTarget(new Point3D(x, y, z), map);

                    if (map.CanSpawnMobile(x, y, z))
                    {
                        targ.Invoke(m_Mobile, lt);
                        break;
                    }

                    failSafe++;
                }
            }
            else if (isField && toTarget != null)
            {
                Map map = toTarget.Map;

                int x = m_Mobile.X;
                int y = m_Mobile.Y;
                int z = m_Mobile.Z;

                if (toTarget == null || m_Mobile.InRange(toTarget.Location, 3))
                {
                    targ.Invoke(m_Mobile, toTarget);
                    return true;
                }

                Direction d = Utility.GetDirection(m_Mobile, toTarget);
                int dist = (int)m_Mobile.GetDistanceToSqrt(toTarget.Location) / 2;
                Point3D p = m_Mobile.Location;

                switch ((int)d)
                {
                    case (int)Direction.Running:
                    case (int)Direction.North:
                        y = p.Y - dist;
                        break;
                    case 129:
                    case (int)Direction.Right:
                        x = p.X + dist;
                        y = p.Y - dist;
                        break;
                    case 130:
                    case (int)Direction.East:
                        x = p.X + dist;
                        break;
                    case 131:
                    case (int)Direction.Down:
                        x = p.X + dist;
                        y = p.Y + dist;
                        break;
                    case 132:
                    case (int)Direction.South:
                        y = p.Y + dist;
                        break;
                    case 133:
                    case (int)Direction.Left:
                        x = p.X - dist;
                        y = p.Y + dist;
                        break;
                    case 134:
                    case (int)Direction.West:
                        x = p.X - dist;
                        break;
                    case (int)Direction.ValueMask:
                    case (int)Direction.Up:
                        x = p.X - dist;
                        y = p.Y - dist;
                        break;
                }

                LandTarget lt = new LandTarget(new Point3D(x, y, z), map);
                targ.Invoke(m_Mobile, lt);
            }

            if (harmful && toTarget != null)
            {
                if ((targ.Range == -1 || m_Mobile.InRange(toTarget, targ.Range)) && m_Mobile.CanSee(toTarget) && m_Mobile.InLOS(toTarget))
                {
                    targ.Invoke(m_Mobile, toTarget);
                }
                else if (isDispel)
                {
                    targ.Cancel(m_Mobile, TargetCancelType.Canceled);
                }
            }
            else if (beneficial)
            {
                targ.Invoke(m_Mobile, m_Mobile);
            }
            else if (isTeleport && toTarget != null)
            {
                Map map = m_Mobile.Map;

                if (map == null)
                {
                    targ.Cancel(m_Mobile, TargetCancelType.Canceled);
                    return true;
                }

                int px, py;

                if (teleportAway)
                {
                    int rx = m_Mobile.X - toTarget.X;
                    int ry = m_Mobile.Y - toTarget.Y;

                    double d = m_Mobile.GetDistanceToSqrt(toTarget);

                    px = toTarget.X + (int)(rx * (10 / d));
                    py = toTarget.Y + (int)(ry * (10 / d));
                }
                else
                {
                    px = toTarget.X;
                    py = toTarget.Y;
                }

                for (int i = 0; i < m_Offsets.Length; i += 2)
                {
                    int x = m_Offsets[i], y = m_Offsets[i + 1];

                    Point3D p = new Point3D(px + x, py + y, 0);

                    LandTarget lt = new LandTarget(p, map);

                    if ((targ.Range == -1 || m_Mobile.InRange(p, targ.Range)) && m_Mobile.InLOS(lt) && map.CanSpawnMobile(px + x, py + y, lt.Z) && !SpellHelper.CheckMulti(p, map))
                    {
                        targ.Invoke(m_Mobile, lt);
                        return true;
                    }
                }

                int teleRange = targ.Range;

                if (teleRange < 0)
                    teleRange = Core.ML ? 11 : 12;

                for (int i = 0; i < 10; ++i)
                {
                    Point3D randomPoint = new Point3D(m_Mobile.X - teleRange + Utility.Random(teleRange * 2 + 1), m_Mobile.Y - teleRange + Utility.Random(teleRange * 2 + 1), 0);

                    LandTarget lt = new LandTarget(randomPoint, map);

                    if (m_Mobile.InLOS(lt) && map.CanSpawnMobile(lt.X, lt.Y, lt.Z) && !SpellHelper.CheckMulti(randomPoint, map))
                    {
                        targ.Invoke(m_Mobile, new LandTarget(randomPoint, map));
                        return true;
                    }
                }

                targ.Cancel(m_Mobile, TargetCancelType.Canceled);
            }
            else
            {
                targ.Cancel(m_Mobile, TargetCancelType.Canceled);
            }

            return true;
        }
		public virtual void Teleport()
		{				
			if ( Combatant == null )
				return;
						
			// 20 tries to teleport
			for ( int tries = 0; tries < 20; tries ++ )
			{
				int x = Utility.RandomMinMax( 5, 7 ); 
				int y = Utility.RandomMinMax( 5, 7 );
				
				if ( Utility.RandomBool() )
					x *= -1;
					
				if ( Utility.RandomBool() )
					y *= -1;
				
				Point3D p = new Point3D( X + x, Y + y, 0 );
				IPoint3D po = new LandTarget( p, Map ) as IPoint3D;
				
				if ( po == null )
					continue;
					
				SpellHelper.GetSurfaceTop( ref po );

				if ( InRange( p, 12 ) && InLOS( p ) && Map.CanSpawnMobile( po.X, po.Y, po.Z ) )
				{					
					
					Point3D from = Location;
					Point3D to = new Point3D( po );
	
					Location = to;
					ProcessDelta();
					
					FixedParticles( 0x376A, 9, 32, 0x13AF, EffectLayer.Waist );
					PlaySound( 0x1FE );
										
					return;					
				}
			}		
			
			RevealingAction();
		}
Exemple #5
0
        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;

            if (isDispel)
            {
                toTarget = this.FindDispelTarget(false);

                if (toTarget != null && this.m_Mobile.InRange(toTarget, 10))
                    this.RunFrom(toTarget);
            }
            else if (isParalyze || isTeleport)
            {
                toTarget = this.FindDispelTarget(true);

                if (toTarget == null)
                {
                    toTarget = this.m_Mobile.Combatant;

                    if (toTarget != null)
                        this.RunTo(toTarget);
                }
                else if (this.m_Mobile.InRange(toTarget, 10))
                {
                    this.RunFrom(toTarget);
                    teleportAway = true;
                }
                else
                {
                    teleportAway = true;
                }
            }
            else if (isAnimate)
            {
                Item corpse = this.FindCorpseToAnimate();				

                if (corpse != null)
                    targ.Invoke(this.m_Mobile, corpse);

                toTarget = null;
            }
            else
            {
                toTarget = this.m_Mobile.Combatant;

                if (toTarget != null)
                    this.RunTo(toTarget);
            }

            if ((targ.Flags & TargetFlags.Harmful) != 0 && toTarget != null)
            {
                if ((targ.Range == -1 || this.m_Mobile.InRange(toTarget, targ.Range)) && this.m_Mobile.CanSee(toTarget) && this.m_Mobile.InLOS(toTarget))
                {
                    targ.Invoke(this.m_Mobile, toTarget);
                }
                else if (isDispel)
                {
                    targ.Cancel(this.m_Mobile, TargetCancelType.Canceled);
                }
            }
            else if ((targ.Flags & TargetFlags.Beneficial) != 0)
            {
                targ.Invoke(this.m_Mobile, this.m_Mobile);
            }
            else if (isTeleport && toTarget != null)
            {
                Map map = this.m_Mobile.Map;

                if (map == null)
                {
                    targ.Cancel(this.m_Mobile, TargetCancelType.Canceled);
                    return;
                }

                int px, py;

                if (teleportAway)
                {
                    int rx = this.m_Mobile.X - toTarget.X;
                    int ry = this.m_Mobile.Y - toTarget.Y;

                    double d = this.m_Mobile.GetDistanceToSqrt(toTarget);

                    px = toTarget.X + (int)(rx * (10 / d));
                    py = toTarget.Y + (int)(ry * (10 / d));
                }
                else
                {
                    px = toTarget.X;
                    py = toTarget.Y;
                }

                for (int i = 0; i < m_Offsets.Length; i += 2)
                {
                    int x = m_Offsets[i], y = m_Offsets[i + 1];

                    Point3D p = new Point3D(px + x, py + y, 0);

                    LandTarget lt = new LandTarget(p, map);

                    if ((targ.Range == -1 || this.m_Mobile.InRange(p, targ.Range)) && this.m_Mobile.InLOS(lt) && map.CanSpawnMobile(px + x, py + y, lt.Z) && !SpellHelper.CheckMulti(p, map))
                    {
                        targ.Invoke(this.m_Mobile, lt);
                        return;
                    }
                }

                int teleRange = targ.Range;

                if (teleRange < 0)
                    teleRange = 12;

                for (int i = 0; i < 10; ++i)
                {
                    Point3D randomPoint = new Point3D(this.m_Mobile.X - teleRange + Utility.Random(teleRange * 2 + 1), this.m_Mobile.Y - teleRange + Utility.Random(teleRange * 2 + 1), 0);

                    LandTarget lt = new LandTarget(randomPoint, map);

                    if (this.m_Mobile.InLOS(lt) && map.CanSpawnMobile(lt.X, lt.Y, lt.Z) && !SpellHelper.CheckMulti(randomPoint, map))
                    {
                        targ.Invoke(this.m_Mobile, new LandTarget(randomPoint, map));
                        return;
                    }
                }

                targ.Cancel(this.m_Mobile, TargetCancelType.Canceled);
            }
            else
            {
                targ.Cancel(this.m_Mobile, TargetCancelType.Canceled);
            }
        }
		public static GreenThornsEffect Create( Mobile from, LandTarget land )
		{
			if ( !from.Map.CanSpawnMobile( land.Location ) )
				return null;

			int tileID = land.TileID;

			foreach ( TilesAndEffect taep in m_Table )
			{
				bool contains = false;

				for ( int i = 0; !contains && i < taep.Tiles.Length; i += 2 )
					contains = ( tileID >= taep.Tiles[i] && tileID <= taep.Tiles[i + 1] );

				if ( contains )
				{
					GreenThornsEffect effect = (GreenThornsEffect)Activator.CreateInstance( taep.Effect, new object[] { land.Location, from.Map, from } );
					return effect;
				}
			}

			return null;
		}
		private void TryToTeleport()
		{
			Mobile m = FindNearestAggressor();

			if ( m == null || m.Map == null || m_Mobile.Map == null )
			{
				return;
			}

			if ( m_Mobile.GetDistanceToSqrt( m ) > m_Mobile.RangePerception + 1 )
			{
				return;
			}

			int px = m_Mobile.X;
			int py = m_Mobile.Y;

			int dx = m_Mobile.X - m.X;
			int dy = m_Mobile.Y - m.Y;

			// get vector's length

			double l = Math.Sqrt( (double) (dx*dx + dy*dy) );

			if ( l == 0 )
			{
				int rand = Utility.Random( 8 ) + 1;
				rand *= 2;
				dx = m_Offsets[ rand ];
				dy = m_Offsets[ rand + 1 ];
				l = Math.Sqrt( (double) (dx*dx + dy*dy) );
			}

			// normalize vector
			double dpx = ((double) dx)/l;
			double dpy = ((double) dy)/l;
			// move 
			px += (int) (dpx*(4 + Utility.Random( 3 )));
			py += (int) (dpy*(4 + Utility.Random( 3 )));

			for ( int i = 0; i < m_Offsets.Length; i += 2 )
			{
				int x = m_Offsets[ i ], y = m_Offsets[ i + 1 ];

				Point3D p = new Point3D( px + x, py + y, 0 );

				LandTarget lt = new LandTarget( p, m_Mobile.Map );

				if ( m_Mobile.InLOS( lt ) && m_Mobile.Map.CanSpawnMobile( px + x, py + y, lt.Z ) && !SpellHelper.CheckMulti( p, m_Mobile.Map ) )
				{
					m_Mobile.FixedParticles( 0x376A, 9, 32, 0x13AF, EffectLayer.Waist );
					m_Mobile.PlaySound( 0x1FE );

					m_Mobile.Location = new Point3D( lt.X, lt.Y, lt.Z );
					m_Mobile.ProcessDelta();

					return;
				}
			}

			return;
		}
		public override void ProcessTarget(Target targ)
		{
			bool isDispel = (targ is DispelSpell.InternalTarget);
			bool isParalyze = (targ is ParalyzeSpell.InternalTarget);
			bool isTeleport = (targ is TeleportSpell.InternalTarget);
			bool isCrossHeal = (targ is GreaterHealSpell.InternalTarget);
			bool isTrap = (targ is MagicTrapSpell.InternalTarget);
			bool teleportAway = false;
			bool isReveal = (targ is RevealSpell.InternalTarget || targ is DetectHidden.InternalTarget);

			Mobile toTarget = null;
			Mobile toHeal = null;

			if (isReveal)
			{
				targ.Invoke(m_Mobile, m_Mobile);
			}

			if (isTrap)
			{
				Pouch p = FindPouch(m_Mobile);
				if (p != null)
				{
					targ.Invoke(m_Mobile, p);
				}
				else
					targ.Cancel(m_Mobile, TargetCancelType.Canceled);
			}

			if (isDispel)
			{
				toTarget = FindDispelTarget(false);

				if (toTarget != null && m_Mobile.InRange(toTarget, 10) && !toTarget.Paralyzed)
					RunFrom(toTarget);
			}

			if (CrossHeals && isCrossHeal)
			{
				toHeal = FindHealTarget(true);

				if (toHeal != null && !m_Mobile.InRange(toHeal, 8))
				{

					RunTo(toHeal, CanRun);
				}
			}

			else if (isParalyze || isTeleport)
			{
				toTarget = FindDispelTarget(true);

				if (toTarget == null)
				{
					toTarget = m_Mobile.Combatant;

					if (toTarget != null && !m_Mobile.InRange(toTarget, 8))
						RunTo(toTarget, CanRun);
				}
				else if (m_Mobile.InRange(toTarget, 10))
				{
					RunFrom(toTarget);
					teleportAway = true;
				}
				else
				{
					teleportAway = true;
				}
			}

			else
			{
				if (m_Mobile.ControlOrder == OrderType.Come && isTeleport)
				{
					toTarget = m_Mobile.ControlMaster;
				}
				else
				{
					toTarget = m_Mobile.Combatant;
				}

				if (toTarget != null)
				{

					RunTo(toTarget, CanRun);
				}
			}

			if ((targ.Flags & TargetFlags.Harmful) != 0 && toTarget != null)
			{
				if ((m_Mobile.InRange(toTarget, 10)) && m_Mobile.CanSee(toTarget) && m_Mobile.InLOS(toTarget))
				{
					targ.Invoke(m_Mobile, toTarget);
				}
				else if (isDispel)
				{
					targ.Cancel(m_Mobile, TargetCancelType.Canceled);
				}

			}

			else if ((targ.Flags & TargetFlags.Beneficial) != 0 && toHeal != null)
			{
				if ((m_Mobile.InRange(toHeal, 10)) && m_Mobile.CanSee(toHeal) && m_Mobile.InLOS(toHeal) && NeedGHeal(toHeal))
				{

					targ.Invoke(m_Mobile, toHeal);
				}
				else
				{
					Targeting.Target.Cancel(m_Mobile);
				}
			}

			else if ((targ.Flags & TargetFlags.Beneficial) != 0)
			{
				if (!isCrossHeal)
				{
					targ.Invoke(m_Mobile, m_Mobile);
				}
				if ((isCrossHeal) && (NeedGHeal(m_Mobile)))
				{
					targ.Invoke(m_Mobile, m_Mobile);
				}
				else
				{
					targ.Cancel(m_Mobile, TargetCancelType.Canceled);
				}



			}
			else if (isTeleport && toTarget != null)
			{
				Map map = m_Mobile.Map;

				if (map == null)
				{
					targ.Cancel(m_Mobile, TargetCancelType.Canceled);
					return;
				}

				int px, py;

				if (teleportAway)
				{
					int rx = m_Mobile.X - toTarget.X;
					int ry = m_Mobile.Y - toTarget.Y;

					double d = m_Mobile.GetDistanceToSqrt(toTarget);

					px = toTarget.X + (int)(rx * (10 / d));
					py = toTarget.Y + (int)(ry * (10 / d));
				}
				else
				{
					px = toTarget.X;
					py = toTarget.Y;
				}

				for (int i = 0; i < m_Offsets.Length; i += 2)
				{
					int x = m_Offsets[i], y = m_Offsets[i + 1];

					Point3D p = new Point3D(px + x, py + y, 0);

					LandTarget lt = new LandTarget(p, map);

					if ((targ.Range == -1 || m_Mobile.InRange(p, targ.Range)) && m_Mobile.InLOS(lt) && map.CanSpawnMobile(px + x, py + y, lt.Z) && !SpellHelper.CheckMulti(p, map))
					{
						targ.Invoke(m_Mobile, lt);
						return;
					}
				}

				int teleRange = targ.Range;

				if (teleRange < 0)
					teleRange = 12;

				for (int i = 0; i < 10; ++i)
				{
					Point3D randomPoint = new Point3D(m_Mobile.X - teleRange + Utility.Random(teleRange * 2 + 1), m_Mobile.Y - teleRange + Utility.Random(teleRange * 2 + 1), 0);

					LandTarget lt = new LandTarget(randomPoint, map);

					if (m_Mobile.InLOS(lt) && map.CanSpawnMobile(lt.X, lt.Y, lt.Z) && !SpellHelper.CheckMulti(randomPoint, map))
					{
						targ.Invoke(m_Mobile, new LandTarget(randomPoint, map));
						return;
					}
				}

				targ.Cancel(m_Mobile, TargetCancelType.Canceled);
			}
			else
			{
				targ.Cancel(m_Mobile, TargetCancelType.Canceled);
			}
		}
        public void Target(LandTarget p)
        {
            if (!Caster.CanSee(p))
            {
                Caster.SendLocalizedMessage(500237); // Target can not be seen.
            }
            else if (!CheckLineOfSight(p))
            {
                this.DoFizzle();
                Caster.SendAsciiMessage("Target is not in line of sight");
            }
            else
            {
                if (CheckSequence())
                {
                    try
                    {
                        BaseCreature creature = (BaseCreature)Activator.CreateInstance(m_Types[Utility.Random(m_Types.Length)]);

                        creature.ControlSlots = 2;

                        TimeSpan duration;

                        if (Core.AOS)
                            duration = TimeSpan.FromSeconds((2 * Caster.Skills.Magery.Fixed) / 5);
                        else
                            duration = TimeSpan.FromSeconds(4.0 * Caster.Skills[SkillName.Magery].Value);

                        SpellHelper.Summon(creature, Caster, 0x215, duration, false, false);

                        creature.MoveToWorld(new Point3D(p), Caster.Map );
                    }
                    catch
                    {
                    }
                }

                FinishSequence();
            }
        }
		private bool ProcessTarget()
		{
			Target targ = m_Mobile.Target;

			if ( targ == null )
				return false;

			Mobile toTarget;

			toTarget = m_Mobile.Combatant;

			//if ( toTarget != null )
				//RunTo( toTarget );

			if ( targ is DispelSpell.InternalTarget && !(m_Mobile.AutoDispel) )
			{
				List<Mobile> targets = new List<Mobile>();

				foreach ( Mobile m in m_Mobile.GetMobilesInRange( 12 ) )
				{
					if ( m is BaseCreature )
					{
						if ( ((BaseCreature)m).IsDispellable && CanTarget( m_Mobile, m ) )
							targets.Add( m );
					}
				}

				if ( targets.Count >= 0 )
				{
					int whichone = Utility.RandomMinMax( 0, targets.Count );

					if ( targets[whichone] != null )
						targ.Invoke( m_Mobile, targets[whichone] );
				}
			}
			else if ( targ is TeleportSpell.InternalTarget || targ is Shadowjump.InternalTarget )
			{
				if ( targ is Shadowjump.InternalTarget && !m_Mobile.Hidden )
					return false;

				Map map = m_Mobile.Map;

				if ( map == null )
				{
					targ.Cancel( m_Mobile, TargetCancelType.Canceled );
					return true;
				}

				int px, py;
				bool teleportAway = ( m_Mobile.Hits < (m_Mobile.Hits / 10) );

				if ( teleportAway )
				{
					int rx = m_Mobile.X - toTarget.X;
					int ry = m_Mobile.Y - toTarget.Y;
					double d = m_Mobile.GetDistanceToSqrt( toTarget );

					px = toTarget.X + (int)(rx * (10 / d));
					py = toTarget.Y + (int)(ry * (10 / d));
				}
				else
				{
					px = toTarget.X;
					py = toTarget.Y;
				}

				for ( int i = 0; i < m_RandomLocations.Length; i += 2 )
				{
					int x = m_RandomLocations[i], y = m_RandomLocations[i + 1];

					Point3D p = new Point3D( px + x, py + y, 0 );

					LandTarget lt = new LandTarget( p, map );

					if ( (targ.Range == -1 || m_Mobile.InRange( p, targ.Range )) && m_Mobile.InLOS( lt ) && map.CanSpawnMobile( px + x, py + y, lt.Z ) && !SpellHelper.CheckMulti( p, map ) )
					{
						targ.Invoke( m_Mobile, lt );
						return true;
					}
				}

				int teleRange = targ.Range;

				if ( teleRange < 0 )
					teleRange = 12;

				for ( int i = 0; i < 10; ++i )
				{
					Point3D randomPoint = new Point3D( m_Mobile.X - teleRange + Utility.Random( teleRange * 2 + 1 ), m_Mobile.Y - teleRange + Utility.Random( teleRange * 2 + 1 ), 0 );

					LandTarget lt = new LandTarget( randomPoint, map );

					if ( m_Mobile.InLOS( lt ) && map.CanSpawnMobile( lt.X, lt.Y, lt.Z ) && !SpellHelper.CheckMulti( randomPoint, map ) )
					{
						targ.Invoke( m_Mobile, new LandTarget( randomPoint, map ) );
						return true;
					}
				}
			}
			else if ( targ is AnimateDeadSpell.InternalTarget )
			{
				Type type = null;

				List<Item> itemtargets = new List<Item>();

				foreach ( Item itemstofind in m_Mobile.GetItemsInRange( 5 ) )
				{
					if ( itemstofind is Corpse )
					{
						itemtargets.Add( itemstofind );
					}
				}

				for ( int i = 0; i < itemtargets.Count; ++i )
				{
					Corpse items = (Corpse)itemtargets[i];

					if ( items.Owner != null )
						type = items.Owner.GetType();

					if ( items.ItemID != 0x2006 || items.Channeled || type == typeof( PlayerMobile ) || type == null || (items.Owner != null && items.Owner.Fame < 100) || ((items.Owner != null) && (items.Owner is BaseCreature) && (((BaseCreature)items.Owner).Summoned || ((BaseCreature)items.Owner).IsBonded)) )
						continue;
					else
					{
						targ.Invoke( m_Mobile, items );
						break;
					}
				}

				if ( targ != null )
					targ.Cancel( m_Mobile, TargetCancelType.Canceled );

			}
			else if ( (targ.Flags & TargetFlags.Harmful) != 0 && toTarget != null )
			{
				if ( (targ.Range == -1 || m_Mobile.InRange( toTarget, targ.Range )) && m_Mobile.CanSee( toTarget ) && m_Mobile.InLOS( toTarget ) )
				{
					targ.Invoke( m_Mobile, toTarget );
				}
			}
			else if ( (targ.Flags & TargetFlags.Beneficial) != 0 )
			{
				targ.Invoke( m_Mobile, m_Mobile );
			}
			else
			{
				targ.Cancel( m_Mobile, TargetCancelType.Canceled );
			}

			return true;
		}
        // Shadowjump
        private bool PerformShadowjump( Mobile toTarget )
        {
            if ( m_Mobile.Skills[ SkillName.Ninjitsu ].Value < 50.0 )
            {
                return false;
            }

            if ( toTarget != null )
            {
                Map map = m_Mobile.Map;

                if ( map == null )
                {
                    return false;
                }

                int px, py, ioffset = 0;

                px = toTarget.X;
                py = toTarget.Y;

                if ( Action == ActionType.Flee )
                {
                    double outerradius = m_Mobile.Skills[ SkillName.Ninjitsu ].Value/10.0;
                    double radiusoffset = 2.0;
                    // random point for direction vector
                    int rpx = Utility.Random( 40 ) - 20 + toTarget.X;
                    int rpy = Utility.Random( 40 ) - 20 + toTarget.Y;
                    // get vector
                    int dx = rpx - toTarget.X;
                    int dy = rpy - toTarget.Y;
                    // get vector's length
                    double l = Math.Sqrt( (double) (dx*dx + dy*dy) );

                    if ( l == 0 )
                    {
                        return false;
                    }
                    // normalize vector
                    double dpx = ((double) dx)/l;
                    double dpy = ((double) dy)/l;
                    // move
                    px += (int) (dpx*(outerradius - radiusoffset) + Math.Sign( dpx )*(radiusoffset + 0.5));
                    py += (int) (dpy*(outerradius - radiusoffset) + Math.Sign( dpy )*(radiusoffset + 0.5));
                }
                else
                {
                    ioffset = 2;
                }

                for ( int i = ioffset; i < m_Offsets.Length; i += 2 )
                {
                    int x = m_Offsets[ i ], y = m_Offsets[ i + 1 ];

                    Point3D p = new Point3D( px + x, py + y, 0 );

                    LandTarget lt = new LandTarget( p, map );

                    if ( m_Mobile.InLOS( lt ) && map.CanSpawnMobile( px + x, py + y, lt.Z ) && !SpellHelper.CheckMulti( p, map ) )
                    {
                        m_Mobile.Location = new Point3D( lt.X, lt.Y, lt.Z );
                        m_Mobile.ProcessDelta();

                        return true;
                    }
                }
            }

            return false;
        }
Exemple #12
0
        public static void TargetResponse( NetState state, PacketReader pvSrc )
        {
            int type = pvSrc.ReadByte();
            int targetID = pvSrc.ReadInt32();
            int flags = pvSrc.ReadByte();
            Serial serial = pvSrc.ReadInt32();
            int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
            int graphic = pvSrc.ReadInt16();

            Mobile from = state.Mobile;

            Target t = from.Target;

            if ( t != null )
            {
                TargetProfile prof = TargetProfile.Acquire( t.GetType() );

                if ( prof != null ) {
                    prof.Start();
                }

                try {
                    if (( x == -1 && y == -1 && !serial.IsValid ) || ( targetID == unchecked( (int) 0xDEADBEEF ) ))
                    {
                        // User pressed escape
                        t.Cancel( from, TargetCancelType.Canceled );
                    }
                    else
                    {
                        object toTarget;

                        if ( type == 1 )
                        {
                            if ( graphic == 0 )
                            {
                                toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
                            }
                            else
                            {
                                Map map = from.Map;

                                if ( map == null || map == Map.Internal )
                                {
                                    t.Cancel( from, TargetCancelType.Canceled );
                                    return;
                                }
                                else
                                {
                                    Tile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );

                                    bool valid = false;

                                    for ( int i = 0; !valid && i < tiles.Length; ++i )
                                    {
                                        if ( tiles[i].Z == z && (tiles[i].ID & 0x3FFF) == (graphic & 0x3FFF) )
                                            valid = true;
                                    }

                                    if ( !valid )
                                    {
                                        t.Cancel( from, TargetCancelType.Canceled );
                                        return;
                                    }
                                    else
                                    {
                                        toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
                                    }
                                }
                            }
                        }
                        else if ( serial.IsMobile )
                        {
                            toTarget = World.FindMobile( serial );
                        }
                        else if ( serial.IsItem )
                        {
                            toTarget = World.FindItem( serial );
                        }
                        else
                        {
                            t.Cancel( from, TargetCancelType.Canceled );
                            return;
                        }

                        t.Invoke( from, toTarget );
                    }
                } finally {
                    if ( prof != null ) {
                        prof.Finish();
                    }
                }
            }
        }
Exemple #13
0
        public void Invoke(Mobile from, object targeted)
        {
            CancelTimeout();
            from.ClearTarget();

            if (from.Deleted)
            {
                OnTargetCancel(from, TargetCancelType.Canceled);
                OnTargetFinish(from);
                return;
            }

            Point3D loc               = default;
            Map     map               = null;
            Item    item              = null;
            Mobile  mobile            = null;
            bool    isValidTargetType = true;

            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 (!valid)
            {
                if (!isValidTargetType)
                {
                    OnTargetCancel(from, TargetCancelType.Canceled);
                }

                OnTargetFinish(from);
            }

            if (map == null || map != from.Map || Range >= 0 && !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);
        }
Exemple #14
0
        private bool ProcessTarget()
        {
            Target targ = m_Mobile.Target;

            if (targ == null)
                return false;

            bool isReveal = (targ is RevealSpell.InternalTarget);
            bool isDispel = (targ is DispelSpell.InternalTarget);
            bool isParalyze = (targ is ParalyzeSpell.InternalTarget);
            bool isTeleport = (targ is TeleportSpell.InternalTarget);
            bool isInvisible = (targ is InvisibilitySpell.InternalTarget);
            bool teleportAway = false;

            Mobile toTarget;

            if (isInvisible)
            {
                toTarget = m_Mobile;
            }
            else if (isDispel)
            {
                toTarget = FindDispelTarget(false);

                if (!SmartAI && toTarget != null)
                    RunTo(toTarget);
                else if (toTarget != null && m_Mobile.InRange(toTarget, 10))
                    RunFrom(toTarget);
            }
            else if (SmartAI && (isParalyze || isTeleport))
            {
                toTarget = FindDispelTarget(true);

                if (toTarget == null)
                {
                    toTarget = m_Mobile.Combatant;

                    if (toTarget != null)
                        RunTo(toTarget);
                }
                else if (m_Mobile.InRange(toTarget, 10))
                {
                    RunFrom(toTarget);
                    teleportAway = true;
                }
                else
                {
                    teleportAway = true;
                }
            }
            else
            {
                toTarget = m_Mobile.Combatant;

                if (toTarget != null)
                    RunTo(toTarget);
            }

            if ((targ.Flags & TargetFlags.Harmful) != 0 && toTarget != null)
            {
                if ((targ.Range == -1 || m_Mobile.InRange(toTarget, targ.Range)) && m_Mobile.CanSee(toTarget) && m_Mobile.InLOS(toTarget))
                {
                    targ.Invoke(m_Mobile, toTarget);
                }
                else if (isDispel)
                {
                    targ.Cancel(m_Mobile, TargetCancelType.Canceled);
                }
            }
            else if ((targ.Flags & TargetFlags.Beneficial) != 0)
            {
                targ.Invoke(m_Mobile, m_Mobile);
            }
            else if (isReveal && m_RevealTarget != null)
            {
                targ.Invoke(m_Mobile, m_RevealTarget);
            }
            else if (isTeleport && toTarget != null)
            {
                Map map = m_Mobile.Map;

                if (map == null)
                {
                    targ.Cancel(m_Mobile, TargetCancelType.Canceled);
                    return true;
                }

                int px, py;

                if (teleportAway)
                {
                    int rx = m_Mobile.X - toTarget.X;
                    int ry = m_Mobile.Y - toTarget.Y;

                    double d = m_Mobile.GetDistanceToSqrt(toTarget);

                    px = toTarget.X + (int)(rx * (10 / d));
                    py = toTarget.Y + (int)(ry * (10 / d));
                }
                else
                {
                    px = toTarget.X;
                    py = toTarget.Y;
                }

                for (int i = 0; i < m_Offsets.Length; i += 2)
                {
                    int x = m_Offsets[i], y = m_Offsets[i + 1];

                    Point3D p = new Point3D(px + x, py + y, 0);

                    LandTarget lt = new LandTarget(p, map);

                    if ((targ.Range == -1 || m_Mobile.InRange(p, targ.Range)) && m_Mobile.InLOS(lt) && map.CanSpawnMobile(px + x, py + y, lt.Z) && !SpellHelper.CheckMulti(p, map))
                    {
                        targ.Invoke(m_Mobile, lt);
                        return true;
                    }
                }

                int teleRange = targ.Range;

                if (teleRange < 0)
                    teleRange = Core.ML ? 11 : 12;

                for (int i = 0; i < 10; ++i)
                {
                    Point3D randomPoint = new Point3D(m_Mobile.X - teleRange + Utility.Random(teleRange * 2 + 1), m_Mobile.Y - teleRange + Utility.Random(teleRange * 2 + 1), 0);

                    LandTarget lt = new LandTarget(randomPoint, map);

                    if (m_Mobile.InLOS(lt) && map.CanSpawnMobile(lt.X, lt.Y, lt.Z) && !SpellHelper.CheckMulti(randomPoint, map))
                    {
                        targ.Invoke(m_Mobile, new LandTarget(randomPoint, map));
                        return true;
                    }
                }

                targ.Cancel(m_Mobile, TargetCancelType.Canceled);
            }
            else
            {
                targ.Cancel(m_Mobile, TargetCancelType.Canceled);
            }

            return true;
        }
Exemple #15
0
        public void Teleport()
        { 
            // 20 tries to teleport
            for (int tries = 0; tries < 20; tries ++)
            {
                int x = Utility.RandomMinMax(5, 7); 
                int y = Utility.RandomMinMax(5, 7);
				
                if (Utility.RandomBool())
                    x *= -1;
					
                if (Utility.RandomBool())
                    y *= -1;
				
                Point3D p = new Point3D(this.X + x, this.Y + y, 0);
                IPoint3D po = new LandTarget(p, this.Map)as IPoint3D;
				
                if (po == null)
                    continue;
					
                SpellHelper.GetSurfaceTop(ref po);

                if (this.InRange(p, 12) && this.InLOS(p) && this.Map.CanSpawnMobile(po.X, po.Y, po.Z))
                { 
                    Point3D from = this.Location;
                    Point3D to = new Point3D(po);
	
                    this.Location = to;
                    this.ProcessDelta();
					
                    this.FixedParticles(0x376A, 9, 32, 0x13AF, EffectLayer.Waist);
                    this.PlaySound(0x1FE);
										
                    break;					
                }
            }
			
            this.RevealingAction();
        }
		public static void TargetResponse( NetState state, PacketReader pvSrc )
		{
			int type = pvSrc.ReadByte();
			int targetID = pvSrc.ReadInt32();
			int flags = pvSrc.ReadByte();
			Serial serial = pvSrc.ReadInt32();
			int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
			int graphic = pvSrc.ReadUInt16();

			if ( targetID == unchecked( (int) 0xDEADBEEF ) )
				return;

			Mobile from = state.Mobile;

			Target t = from.Target;

			if ( t != null )
			{
				TargetProfile prof = TargetProfile.Acquire( t.GetType() );

				if ( prof != null ) {
					prof.Start();
				}

				try {
					if ( x == -1 && y == -1 && !serial.IsValid )
					{
						// User pressed escape
						t.Cancel( from, TargetCancelType.Canceled );
					}
					else if ( Target.TargetIDValidation && t.TargetID != targetID )
					{
						// Sanity, prevent fake target
						return;
					}
					else
					{
						object toTarget;

						if ( type == 1 )
						{
							if ( graphic == 0 )
							{
								toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
							}
							else
							{
								Map map = from.Map;

								if ( map == null || map == Map.Internal )
								{
									t.Cancel( from, TargetCancelType.Canceled );
									return;
								}
								else
								{
									StaticTile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );

									bool valid = false;

									if ( state.HighSeas ) {
										ItemData id = TileData.ItemTable[graphic&TileData.MaxItemValue];
										if ( id.Surface ) {
											z -= id.Height;
										}
									}

									for ( int i = 0; !valid && i < tiles.Length; ++i )
									{
										if ( tiles[i].Z == z && tiles[i].ID == graphic )
											valid = true;
									}

									if ( !valid )
									{
										t.Cancel( from, TargetCancelType.Canceled );
										return;
									}
									else
									{
										toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
									}
								}
							}
						}
						else if ( serial.IsMobile )
						{
							toTarget = World.FindMobile( serial );
						}
						else if ( serial.IsItem )
						{
							toTarget = World.FindItem( serial );
						}
						else
						{
							t.Cancel( from, TargetCancelType.Canceled );
							return;
						}

						t.Invoke( from, toTarget );
					}
				} finally {
					if ( prof != null ) {
						prof.Finish();
					}
				}
			}
		}
Exemple #17
0
        public void TargetResponse( GameClient state, PacketReader pvSrc )
        {
            int type = pvSrc.ReadByte();
            /*int targetID = */
            pvSrc.ReadInt32();
            /*int flags = */
            pvSrc.ReadByte();
            Serial serial = pvSrc.ReadInt32();
            int x = pvSrc.ReadInt16(), y = pvSrc.ReadInt16(), z = pvSrc.ReadInt16();
            int graphic = pvSrc.ReadInt16();

            Mobile from = state.Mobile;

            Target t = from.Target;

            if ( t == null )
            {
                state.NullTargets++;

                if ( state.NullTargets > GameClient.MaxNullTargets )
                {
                    state.Dispose();
                    return;
                }
            }
            else
            {
                state.NullTargets = 0;

                if ( x == -1 && y == -1 && !serial.IsValid )
                {
                    // User pressed escape
                    t.Cancel( from, TargetCancelType.Canceled );
                }
                else
                {
                    object toTarget;

                    if ( type == 1 )
                    {
                        if ( graphic == 0 )
                        {
                            toTarget = new LandTarget( new Point3D( x, y, z ), from.Map );
                        }
                        else
                        {
                            Map map = from.Map;

                            if ( map == null || map == Map.Internal )
                            {
                                t.Cancel( from, TargetCancelType.Canceled );
                                return;
                            }
                            else
                            {
                                Tile[] tiles = map.Tiles.GetStaticTiles( x, y, !t.DisallowMultis );

                                bool valid = false;

                                for ( int i = 0; !valid && i < tiles.Length; ++i )
                                {
                                    bool surface = ( TileData.ItemTable[tiles[i].ID & TileData.MaxItemValue].Flags & TileFlag.Surface ) != 0;
                                    int zOffset = surface ? tiles[i].Height : 0;

                                    if ( ( tiles[i].Z + zOffset ) == z && ( tiles[i].ID & TileData.MaxItemValue ) == ( graphic & TileData.MaxItemValue ) )
                                    {
                                        valid = true;
                                        z -= zOffset;
                                    }
                                }

                                if ( !valid )
                                {
                                    t.Cancel( from, TargetCancelType.Canceled );
                                    return;
                                }
                                else
                                {
                                    toTarget = new StaticTarget( new Point3D( x, y, z ), graphic );
                                }
                            }
                        }
                    }
                    else if ( serial.IsMobile )
                    {
                        toTarget = World.Instance.FindMobile( serial );
                    }
                    else if ( serial.IsItem )
                    {
                        toTarget = World.Instance.FindItem( serial );
                    }
                    else
                    {
                        t.Cancel( from, TargetCancelType.Canceled );
                        return;
                    }

                    try
                    {
                        t.Invoke( from, toTarget );
                    }
                    catch ( Exception e )
                    {
                        Logger.Error( "Exception disarmed in target {0} > {1} > {2}: {3}", from, t, toTarget, e );
                    }
                }
            }
        }