public static BaseMulti GETCANNONTARGET(TriggerObject trigObject, ShipCannon cannon, int range)
			{
				if (cannon == null || cannon.Deleted)
				{
					return null;
				}

				Point2D testLocation = new Point2D(cannon.Location.X, cannon.Location.Y);
				Point2D dir = cannon.CannonDirectionVector;

				for (int i = 0; i < range; i++)
				{
					testLocation.X += dir.X;
					testLocation.Y += dir.Y;

					BaseMulti boatTarget = BaseMulti.FindMultiAt(testLocation, cannon.Map);

					if (boatTarget == null || boatTarget == cannon.Boat || !(boatTarget is BaseBoat) || ((BaseBoat)boatTarget).Sunk)
					{
						continue;
					}

					return boatTarget;
				}

				return null;
			}
Example #2
0
            protected override void OnTarget(Mobile from, object targeted)
            {
                IPoint3D p   = targeted as IPoint3D;
                Map      map = from.Map;

                if (p == null || map == null || m_Deed.Deleted)
                {
                    return;
                }

                if (m_Deed.IsChildOf(from.Backpack))
                {
                    if (targeted is BoatComponent)
                    {
                        BoatComponent spot = (BoatComponent)targeted;
                        if (spot.Boat == null || spot.Boat.Deleted || spot.Deleted || spot.ComponentType != BoatComponentType.CannonSpot || !spot.Boat.Contains(from))
                        {
                            from.SendLocalizedMessage(500269); // You cannot build that there.
                            return;
                        }

                        ShipCannonDirection cannonDir = ShipCannonDirection.Fore;
                        int baseItemID = spot.DirectionalItemIDs[0, 0];
                        foreach (int cannonID in BoatComponent.ForeCannonItemIDs)
                        {
                            if (baseItemID == cannonID)
                            {
                                cannonDir = ShipCannonDirection.Fore;
                            }
                        }
                        foreach (int cannonID in BoatComponent.PortCannonItemIDs)
                        {
                            if (baseItemID == cannonID)
                            {
                                cannonDir = ShipCannonDirection.Port;
                            }
                        }
                        foreach (int cannonID in BoatComponent.StarboardCannonItemIDs)
                        {
                            if (baseItemID == cannonID)
                            {
                                cannonDir = ShipCannonDirection.Starboard;
                            }
                        }
                        foreach (int cannonID in BoatComponent.AftCannonItemIDs)
                        {
                            if (baseItemID == cannonID)
                            {
                                cannonDir = ShipCannonDirection.Aft;
                            }
                        }

                        Point3D offset = spot.Offset;
                        offset.Z += spot.Boat.MarkOffset.Z;           // offset from the ground up
                        ShipCannon addon = m_Deed.Cannon(spot.Boat, offset, cannonDir);
                        addon.MoveToWorld(Point3D.Zero, Map.Felucca); // get it out of the way (it blocks itself ironically)
                        Server.Spells.SpellHelper.GetSurfaceTop(ref p);

                        if (!map.CanFit(p.X, p.Y, p.Z, addon.ItemData.Height, false, true, (addon.Z == 0)))
                        {
                            from.SendLocalizedMessage(500269); // You cannot build that there.
                            addon.Delete();
                        }
                        else
                        {
                            addon.MoveToWorld(new Point3D(p), map);

                            m_Deed.Delete();
                            from.SendMessage("You place the cannon.");
                        }
                    }
                    else
                    {
                        from.SendMessage(38, "You can only place cannons at appropriate cannon locations on a boat.");
                    }
                }
                else
                {
                    from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
                }
            }