public void ShootCannons(Mobile focus, bool shootAtBoat) { List <Item> cannons = new List <Item>(m_Galleon.Cannons); foreach (Item item in cannons) { if (item != null && item is BaseCannon && !item.Deleted) { BaseCannon cannon = item as BaseCannon; if (m_ShootTable.ContainsKey(cannon) && m_ShootTable[cannon] > DateTime.UtcNow) { continue; } Direction facing = cannon.GetFacing(); if (shootAtBoat && HasTarget(focus, cannon, true)) { cannon.AmmoType = AmmoType.Cannonball; cannon.LoadedAmmo = cannon.LoadTypes[0]; } else if (!shootAtBoat && HasTarget(focus, cannon, false)) { cannon.AmmoType = AmmoType.Grapeshot; cannon.LoadedAmmo = cannon.LoadTypes[1]; } else { continue; } cannon.Shoot(this); m_ShootTable[cannon] = DateTime.UtcNow + ShootFrequency + TimeSpan.FromSeconds(Utility.RandomMinMax(0, 3)); } } }
private bool HasTarget(Mobile focus, BaseCannon cannon, bool shootatboat) { if (cannon == null || cannon.Deleted || cannon.Map == null || cannon.Map == Map.Internal || m_Galleon == null || m_Galleon.Deleted) { return(false); } Direction d = cannon.GetFacing(); int xOffset = 0; int yOffset = 0; int cannonrange = cannon.Range; int currentRange = 0; Point3D pnt = cannon.Location; switch (d) { case Direction.North: xOffset = 0; yOffset = -1; break; case Direction.South: xOffset = 0; yOffset = 1; break; case Direction.West: xOffset = -1; yOffset = 0; break; case Direction.East: xOffset = 1; yOffset = 0; break; } int xo = xOffset; int yo = yOffset; while (currentRange++ <= cannonrange) { xOffset = xo; yOffset = yo; for (int i = -1; i <= 1; i++) { Point3D newPoint; if (xOffset == 0) { newPoint = new Point3D(pnt.X + (xOffset + i), pnt.Y + (yOffset * currentRange), pnt.Z); } else { newPoint = new Point3D(pnt.X + (xOffset * currentRange), pnt.Y + (yOffset + i), pnt.Z); } if (shootatboat) { BaseGalleon g = BaseGalleon.FindGalleonAt(newPoint, this.Map); if (g != null && g == m_TargetBoat && g != Galleon) { return(true); } } else { if (focus == null) { return(false); } if (newPoint.X == focus.X && newPoint.Y == focus.Y) { Console.WriteLine("Shooting: {0} at {1} / {2}", focus.Name, newPoint.X, newPoint.Y); return(true); } } } } return(false); }