public override void OnSpeech( SpeechEventArgs e ) { Mobile from = e.Mobile; if ( !e.Handled && from.InRange( this, 10 ) && e.Speech.ToLower() == this.Word ) { BaseShip ship = BaseShip.FindShipAt( from, from.Map ); if ( ship == null ) return; if ( !this.Active ) { if ( ship.TillerMan != null ) ship.TillerMan.Say( 502507 ); // Ar, Legend has it that these pillars are inactive! No man knows how it might be undone! return; } if (T2AAccess.IsT2A(m_Destination.Start, from.Map)) { if (ship.Map != null && ship.Map != Map.Internal) { MultiComponentList mcl = ship.Components; IPooledEnumerable eable = ship.Map.GetClientsInBounds(new Rectangle2D(ship.X + mcl.Min.X, ship.Y + mcl.Min.Y, mcl.Width, mcl.Height)); foreach (NetState ns in eable) if (ns != null && ns.Mobile != null && ship.Contains((Mobile)ns.Mobile) && !T2AAccess.HasAccess(ns.Mobile)) { eable.Free(); from.SendMessage("One or more players on board does not have access to T2A at this time."); return; } eable.Free(); } } Map map = from.Map; for ( int i = 0; i < 5; i++ ) // Try 5 times { int x = Utility.Random( Destination.X, Destination.Width ); int y = Utility.Random( Destination.Y, Destination.Height ); int z = map.GetAverageZ( x, y ); Point3D dest = new Point3D( x, y, z ); if ( ship.CanFit( dest, map, ship.ItemID ) ) { int xOffset = x - ship.X; int yOffset = y - ship.Y; int zOffset = z - ship.Z; ship.Teleport( xOffset, yOffset, zOffset ); return; } } if ( ship.TillerMan != null ) ship.TillerMan.Say( 502508 ); // Ar, I refuse to take that matey through here! } }
protected override void OnTick() { if (!m_ShipSpawner.Activated) { return; } DateTime nextSpawnTime = m_ShipSpawner.m_LastActivity + m_ShipSpawner.m_NextActivity; if (nextSpawnTime < DateTime.UtcNow) { if (m_ShipSpawner.m_Ships.Count < m_ShipSpawner.ShipCount) { int shipsNeeded = m_ShipSpawner.ShipCount - m_ShipSpawner.m_Ships.Count; int shipsSpawned = 0; if (!m_ShipSpawner.SpawnAllAvailable) { shipsNeeded = 1; } m_ShipSpawner.m_LastActivity = DateTime.UtcNow; m_ShipSpawner.m_NextActivity = TimeSpan.FromMinutes(Utility.RandomMinMax(m_ShipSpawner.m_MinSpawnTime, m_ShipSpawner.m_MaxSpawnTime)); //Ships Needed for (int a = 0; a < shipsNeeded; a++) { BaseShip ship = GetRandomShipType(m_ShipSpawner.m_ShipTypes); if (ship == null) { continue; } bool shipSpawned = false; //Make 50 Attempts to Find Randomized Location for Ship Spawn Point Before Aborting for (int b = 0; b < 50; b++) { if (shipSpawned) { break; } Point3D newLocation = new Point3D(); int x = m_ShipSpawner.X; int xOffset = Utility.RandomMinMax(0, m_ShipSpawner.SpawnRange); if (Utility.RandomDouble() >= .5) { xOffset *= -1; } x += xOffset; int y = m_ShipSpawner.Y; int yOffset = Utility.RandomMinMax(0, m_ShipSpawner.SpawnRange); if (Utility.RandomDouble() >= .5) { yOffset *= -1; } y += yOffset; newLocation.X = x; newLocation.Y = y; newLocation.Z = m_ShipSpawner.Z; Direction newDirection = Direction.North; int shipFacingItemID = -1; //Try Preferred Direction first switch (m_ShipSpawner.PreferredDirection) { case Direction.North: newDirection = Direction.North; shipFacingItemID = ship.NorthID; break; case Direction.Up: newDirection = Direction.North; shipFacingItemID = ship.NorthID; break; case Direction.East: newDirection = Direction.East; shipFacingItemID = ship.EastID; break; case Direction.Right: newDirection = Direction.East; shipFacingItemID = ship.EastID; break; case Direction.South: newDirection = Direction.South; shipFacingItemID = ship.SouthID; break; case Direction.Down: newDirection = Direction.South; shipFacingItemID = ship.SouthID; break; case Direction.West: newDirection = Direction.West; shipFacingItemID = ship.WestID; break; case Direction.Left: newDirection = Direction.West; shipFacingItemID = ship.WestID; break; default: newDirection = Direction.North; shipFacingItemID = ship.NorthID; break; } if (ship.CanFit(newLocation, m_ShipSpawner.Map, shipFacingItemID)) { m_ShipSpawner.m_LastActivity = DateTime.UtcNow; ship.MoveToWorld(newLocation, m_ShipSpawner.Map); m_ShipSpawner.m_Ships.Add(ship); ship.m_ShipSpawner = m_ShipSpawner; Timer.DelayCall(TimeSpan.FromSeconds(.200), delegate { if (ship != null) { if (!ship.Deleted && ship.CanFit(newLocation, m_ShipSpawner.Map, shipFacingItemID)) { ship.SetFacing(newDirection); } } }); shipSpawned = true; } //Try Random Direction else { int randomDirection = Utility.RandomList(1, 2, 3, 4); switch (randomDirection) { case 1: newDirection = Direction.North; shipFacingItemID = ship.NorthID; break; case 2: newDirection = Direction.East; shipFacingItemID = ship.EastID; break; case 3: newDirection = Direction.South; shipFacingItemID = ship.SouthID; break; case 4: newDirection = Direction.West; shipFacingItemID = ship.WestID; break; } if (ship.CanFit(newLocation, m_ShipSpawner.Map, shipFacingItemID)) { m_ShipSpawner.m_LastActivity = DateTime.UtcNow; ship.MoveToWorld(newLocation, m_ShipSpawner.Map); m_ShipSpawner.m_Ships.Add(ship); ship.m_ShipSpawner = m_ShipSpawner; Timer.DelayCall(TimeSpan.FromSeconds(.200), delegate { ship.SetFacing(newDirection); }); shipSpawned = true; } } } if (!shipSpawned) { ship.Delete(); } } } } }
public void OnPlacement(PlayerMobile player, Point3D location) { if (player == null) { return; } if (!player.Alive) { return; } if (Deleted) { return; } else if (!IsChildOf(player.Backpack)) { player.SendLocalizedMessage(1042001); // That must be in your pack for you to use it. LaunchGump(player); } else { Map map = player.Map; if (map == null) { return; } if (player.AccessLevel < AccessLevel.GameMaster && map != Map.Felucca) { player.SendLocalizedMessage(1043284); // A ship can not be created here. LaunchGump(player); return; } if (player.Region.IsPartOf(typeof(HouseRegion)) || BaseShip.FindShipAt(player, player.Map) != null) { player.SendLocalizedMessage(1010568, null, 0x25); // You may not place a ship while on another ship or inside a house. LaunchGump(player); return; } Region region = Region.Find(location, map); if (region.IsPartOf(typeof(DungeonRegion))) { player.SendLocalizedMessage(502488); // You can not place a ship inside a dungeon. LaunchGump(player); return; } if (region.IsPartOf(typeof(HouseRegion))) { player.SendLocalizedMessage(1042549); // A ship may not be placed in this area. LaunchGump(player); return; } if (player.GetDistanceToSqrt(location) > 10) { player.SendMessage("You cannot place a ship that far away from land."); LaunchGump(player); return; } foreach (BaseShip shipInstance in BaseShip.m_Instances) { if (shipInstance.Owner == player) { player.SendMessage("You already have a ship at sea."); LaunchGump(player); return; } } BaseShip ship = (BaseShip)Activator.CreateInstance(ShipType); if (ship == null) { LaunchGump(player); return; } location = new Point3D(location.X - m_Offset.X, location.Y - m_Offset.Y, location.Z - m_Offset.Z); Direction newDirection = Direction.North; int shipFacingItemID = -1; switch (player.Direction) { case Direction.North: newDirection = Direction.North; shipFacingItemID = ship.NorthID; break; case Direction.Up: newDirection = Direction.North; shipFacingItemID = ship.NorthID; break; case Direction.East: newDirection = Direction.East; shipFacingItemID = ship.EastID; break; case Direction.Right: newDirection = Direction.East; shipFacingItemID = ship.EastID; break; case Direction.South: newDirection = Direction.South; shipFacingItemID = ship.SouthID; break; case Direction.Down: newDirection = Direction.South; shipFacingItemID = ship.SouthID; break; case Direction.West: newDirection = Direction.West; shipFacingItemID = ship.WestID; break; case Direction.Left: newDirection = Direction.West; shipFacingItemID = ship.WestID; break; default: newDirection = Direction.North; shipFacingItemID = ship.NorthID; break; } if (BaseShip.IsValidLocation(location, map) && ship.CanFit(location, map, shipFacingItemID)) { ship.Owner = player; BaseShip.PushDeedStoredPropertiesToShip(this, ship); ship.DecayTime = DateTime.UtcNow + ship.ShipDecayDelay; ship.Anchored = true; ship.SetFacing(newDirection); ship.MoveToWorld(location, map); Delete(); ShipRune shipRune = new ShipRune(ship, player); ship.m_ShipRune = shipRune; ShipRune shipBankRune = new ShipRune(ship, player); ship.m_ShipBankRune = shipBankRune; bool addedToPack = false; bool addedToBank = false; if (player.AddToBackpack(shipRune)) { addedToPack = true; } BankBox bankBox = player.FindBankNoCreate(); if (bankBox != null) { if (bankBox.Items.Count < bankBox.MaxItems) { bankBox.AddItem(shipBankRune); addedToBank = true; } } string message = "You place the ship at sea. A ship rune has been placed both in your bankbox and your backpack."; if (!addedToPack && !addedToBank) { message = "You place the ship at sea. However, there was no room in neither your bankbox nor your backpack to place ship runes."; } else if (!addedToPack) { message = "You place the ship at sea. A ship rune was placed in your bankbox, however, there was no room in your backpack to place a ship rune."; } else if (!addedToBank) { message = "You place the ship at sea. A ship rune was placed in your backpack, however, there was no room in your bankbox to place a ship rune."; } player.SendMessage(message); ShipGumpObject shipGumpObject = new ShipGumpObject(player, ship, null); player.CloseGump(typeof(ShipGump)); player.SendGump(new ShipGump(player, shipGumpObject)); } else { ship.Delete(); player.SendMessage("A ship cannot be placed there. You may change your facing to change the direction of the ship placement."); LaunchGump(player); } } }