Example #1
0
        public void DockBoat(BaseBoat boat, BaseHouse house)
        {
            List <ISpawnable> list = boat.GetMovingEntities();

            foreach (ISpawnable o in list)
            {
                if (!(o is Item) || o == this || boat.IsComponentItem(o) || o is EffectItem || o == boat.TillerMan)
                {
                    continue;
                }

                Item item = o as Item;

                if (!item.Deleted && boat.Contains(item))
                {
                    if (item is AddonComponent || item is BaseAddon)
                    {
                        BaseAddon addon = item is AddonComponent ? ((AddonComponent)item).Addon : (BaseAddon)item;
                        Item      deed  = addon.Deed;

                        bool retainDeedHue = false;
                        int  hue           = 0;

                        if (addon != null && addon.RetainDeedHue)
                        {
                            retainDeedHue = true;

                            for (int j = 0; hue == 0 && j < addon.Components.Count; ++j)
                            {
                                AddonComponent c = addon.Components[j];

                                if (c.Hue != 0)
                                {
                                    hue = c.Hue;
                                }
                            }
                        }

                        if (deed != null)
                        {
                            if (retainDeedHue)
                            {
                                deed.Hue = hue;
                            }

                            house.DropToMovingCrate(deed);
                        }
                    }
                    else
                    {
                        item.Delete();
                    }
                }

                Container cont;

                if (boat is BaseGalleon)
                {
                    cont = ((BaseGalleon)boat).GalleonHold;
                }
                else
                {
                    cont = boat.Hold;
                }

                if (cont != null)
                {
                    cont.Items.ForEach(i =>
                    {
                        if (i is BaseWeapon)
                        {
                            house.DropToMovingCrate(i);
                        }
                        else
                        {
                            i.Delete();
                        }
                    });
                }
            }

            BaseDockedBoat model = boat.BoatItem;

            if (model == null || model.Deleted)
            {
                model = boat.DockedBoat;
            }

            if (model == null)
            {
                return;
            }

            model.BoatItem = boat;

            if (boat.IsClassicBoat && boat.Owner != null)
            {
                boat.RemoveKeys(boat.Owner);
            }

            house.DropToMovingCrate(model);

            boat.OnDryDock();

            boat.Refresh();
            boat.Internalize();

            list.Clear();
            list.TrimExcess();
        }
Example #2
0
        public void DockBoat(BaseBoat boat, BaseHouse house)
        {
            foreach (IEntity entity in boat.GetEntitiesOnBoard())
            {
                if (!(entity is Item) || entity == this || boat.IsComponentItem(entity) || entity is EffectItem || entity == boat.TillerMan)
                {
                    continue;
                }

                Item item = entity as Item;

                if (!item.Deleted && boat.Contains(item))
                {
                    if (item is AddonComponent || item is BaseAddon)
                    {
                        BaseAddon addon = item is AddonComponent component ? component.Addon : (BaseAddon)item;
                        Item      deed  = addon.Deed;

                        bool retainDeedHue = false;
                        int  hue           = 0;

                        if (addon.RetainDeedHue)
                        {
                            retainDeedHue = true;

                            for (int j = 0; hue == 0 && j < addon.Components.Count; ++j)
                            {
                                AddonComponent c = addon.Components[j];

                                if (c.Hue != 0)
                                {
                                    hue = c.Hue;
                                }
                            }
                        }

                        if (deed != null)
                        {
                            if (retainDeedHue)
                            {
                                deed.Hue = hue;
                            }

                            house.DropToMovingCrate(deed);
                        }
                    }
                    else
                    {
                        item.Delete();
                    }
                }

                Container cont;

                if (boat is BaseGalleon galleon)
                {
                    cont = galleon.GalleonHold;
                }
                else
                {
                    cont = boat.Hold;
                }

                if (cont != null)
                {
                    for (var index = 0; index < cont.Items.Count; index++)
                    {
                        var i = cont.Items[index];

                        if (i is BaseWeapon)
                        {
                            house.DropToMovingCrate(i);
                        }
                        else
                        {
                            i.Delete();
                        }
                    }
                }
            }

            BaseDockedBoat model = boat.BoatItem;

            if (model == null || model.Deleted)
            {
                model = boat.DockedBoat;
            }

            if (model == null)
            {
                return;
            }

            model.BoatItem = boat;

            if (boat.IsClassicBoat && boat.Owner != null)
            {
                boat.RemoveKeys(boat.Owner);
            }

            house.DropToMovingCrate(model);

            boat.OnDryDock(null);

            boat.Refresh();
            boat.Internalize();
        }
Example #3
0
        private void OnTarget(Mobile from, object targeted)
        {
            BaseBoat ship = null;

            if (targeted is BaseBoat)
            {
                ship = (BaseBoat)targeted;
            }
            else if (targeted is TillerMan)
            {
                ship = ((TillerMan)targeted).Boat;
            }
            else if (targeted is Plank)
            {
                ship = ((Plank)targeted).Boat;
            }
            else if (targeted is Hold)
            {
                ship = ((Hold)targeted).Boat;
            }

            if (ship == null)
            {
                SayTo(from, true, "That is not a ship!");
                return;
            }
            else if (!InRange(ship.Location, 50))
            {
                SayTo(from, true, "That is too far away!");
                return;
            }

            BaseBoat.DryDockResult res = ship.CheckDryDock(from);
            switch (res)
            {
            case BaseBoat.DryDockResult.Dead:
                SayTo(from, true, "Thou art dead and cannot do that.");
                break;

            case BaseBoat.DryDockResult.Decaying:
                SayTo(from, true, "I will not dock a boat that is sinking!");
                break;

            case BaseBoat.DryDockResult.Hold:
                SayTo(from, true, "You must clear the ship's hold before you can dock it.");
                break;

            case BaseBoat.DryDockResult.Items:
                SayTo(from, true, "You must clear the ship's deck of items before docking it.");
                break;

            case BaseBoat.DryDockResult.Mobiles:
                SayTo(from, true, "You cannot dock a ship with beings on board!");
                break;

            case BaseBoat.DryDockResult.NoKey:
                SayTo(from, true, "That ship does not belong to you.");
                break;

            case BaseBoat.DryDockResult.NotAnchored:
                SayTo(from, true, "The ship is not anchored.");
                break;

            case BaseBoat.DryDockResult.Valid:
            {
                if (!from.BankBox.ConsumeTotal(typeof(Gold), 25))
                {
                    SayTo(from, true, "You do not have 25 gold in your bank account to pay for the docking of this ship.");
                    break;
                }

                BaseDockedBoat claim = ship.DockedBoat;
                if (claim == null)
                {
                    break;
                }

                StringBuilder sb = new StringBuilder("a ship claim ticket");
                if (this.Region.Name != "")
                {
                    sb.AppendFormat(" from {0}", this.Region.Name);
                }
                if (claim.ShipName != null && claim.ShipName != "")
                {
                    sb.AppendFormat(" for the {0}", claim.ShipName);
                }
                claim.Name         = sb.ToString();
                claim.DockLocation = this.Home != Point3D.Zero ? this.Home : ship.Location;

                ship.RemoveKeys(from);
                ship.Delete();

                from.AddToBackpack(claim);

                SayTo(from, true, "Here is your claim ticket.  I suggest you store it in a safe place.");
                break;
            }
            }
        }
        public static void SailBoat(Mobile from, BaseBoat boat)
        {
            bool newsail = true;

            if (m_SailTime.ContainsKey(from))
            {
                if (m_SailTime[from] >= DateTime.Now)
                {
                    newsail = false;
                }
                else
                {
                    m_SailTime.Remove(from);
                }
            }

            if (newsail)
            {
                int MinLevel = 10;
                int MaxLevel = 100;
                //if (Core.Debug) from.SendMessage("TEST: SAILING IN A BOAT");

                Mobile sailor = from;

                LokaiSkills skils = LokaiSkillUtilities.XMLGetSkills(sailor);

                List <Mobile> crew = GetMobilesOn(boat);

                SuccessRating rating = SuccessRating.LokaiSkillNotEnabled;

                foreach (Mobile seaman in crew)
                {
                    skils = LokaiSkillUtilities.XMLGetSkills(sailor);

                    LokaiSkills seamanAbs = LokaiSkillUtilities.XMLGetSkills(seaman);
                    if (seamanAbs.Sailing.Value > skils.Sailing.Value)
                    {
                        sailor = seaman;
                    }
                    MinLevel--;
                    MaxLevel--;
                    if ((MinLevel == 5 && (boat is SmallBoat || boat is SmallDragonBoat)) ||
                        (MinLevel == 0 && (boat is MediumBoat || boat is MediumDragonBoat)) ||
                        (MinLevel == -5 && (boat is LargeBoat || boat is LargeDragonBoat)))
                    {
                        break;
                    }
                }

                int count = 0;
                foreach (Mobile seaman in crew)
                {
                    if ((count == 5 && (boat is SmallBoat || boat is SmallDragonBoat)) ||
                        (count == 10 && (boat is MediumBoat || boat is MediumDragonBoat)) ||
                        (count == 15 && (boat is LargeBoat || boat is LargeDragonBoat)))
                    {
                        break;
                    }
                    else
                    {
                        count++;
                        skils = LokaiSkillUtilities.XMLGetSkills(seaman);
                        if (seaman != sailor)
                        {
                            rating = LokaiSkillUtilities.CheckLokaiSkill(seaman, skils.Sailing, MinLevel, MaxLevel);
                            if (rating >= SuccessRating.PartialSuccess)
                            {
                                seaman.SendMessage("You did your part.");
                            }
                            else
                            {
                                seaman.SendMessage("You could have been more helpful.");
                            }
                        }
                    }
                }

                skils = LokaiSkillUtilities.XMLGetSkills(sailor);

                rating = LokaiSkillUtilities.CheckLokaiSkill(sailor, skils.Sailing, MinLevel, MaxLevel);
                if (rating <= SuccessRating.Failure)
                {
                    int severity = 25;
                    if (rating == SuccessRating.HazzardousFailure)
                    {
                        severity += 4;
                    }
                    else if (rating == SuccessRating.CriticalFailure)
                    {
                        severity += 8;
                    }

                    bool crash = false;

                    foreach (Mobile seaman in crew)
                    {
                        if (!m_SailTime.ContainsKey(seaman))
                        {
                            m_SailTime.Add(seaman, DateTime.Now.AddSeconds(FAILSECONDS));
                        }
                    }

                    switch (Utility.Random(severity))
                    {
                    case 0:
                    case 1:
                    case 2: boat.StartMove(Direction.Down, true); goto case 24;

                    case 3:
                    case 4:
                    case 5: boat.StartMove(Direction.East, true); goto case 24;

                    case 6:
                    case 7:
                    case 8: boat.StartMove(Direction.Left, true); goto case 24;

                    case 9:
                    case 10:
                    case 11: boat.StartMove(Direction.North, true); goto case 24;

                    case 12:
                    case 13:
                    case 14: boat.StartMove(Direction.Right, true); goto case 24;

                    case 15:
                    case 16:
                    case 17: boat.StartMove(Direction.South, true); goto case 24;

                    case 18:
                    case 19:
                    case 20: boat.StartMove(Direction.Up, true); goto case 24;

                    case 21:
                    case 22:
                    case 23: boat.StartMove(Direction.West, true); goto case 24;

                    case 24: boat.StartTurn(Utility.RandomList(2, -2, -4), false); goto case 99;

                    case 99:
                    {
                        foreach (Mobile mobile in crew)
                        {
                            MightGetSick(mobile);
                        }
                        break;
                    }

                    default: crash = true; break;
                    }

                    if (crash)
                    {
                        boat.LowerAnchor(false);
                        List <Item> items = CheckForItems(boat);

                        BaseDockedBoat dboat = boat.DockedBoat;

                        foreach (Mobile seaman in crew)
                        {
                            seaman.SendMessage("The boat runs aground at some nearby land.");
                            boat.RemoveKeys(seaman);
                            if (seaman == boat.Owner)
                            {
                                if (dboat != null)
                                {
                                    seaman.AddToBackpack(dboat);
                                }
                            }
                        }

                        boat.Delete();

                        foreach (Mobile seaman in crew)
                        {
                            Strand(seaman);
                        }
                        if (items.Count > 0)
                        {
                            for (int v = 0; v < items.Count; v++)
                            {
                                int x = from.X + Utility.Random(7) - 3;
                                int y = from.Y + Utility.Random(7) - 3;
                                items[v].MoveToWorld(new Point3D(x, y, from.Z));
                            }
                        }
                    }
                    else
                    {
                        foreach (Mobile seaman in crew)
                        {
                            seaman.SendMessage("You go off course slightly.");
                        }
                    }
                }
                else
                {
                    //if (Core.Debug) from.SendMessage("TEST: SAILING SUCCESSFUL.");

                    foreach (Mobile seaman in crew)
                    {
                        seaman.SendMessage("You feel the gentle breeze of the open sea.");
                        if (!m_SailTime.ContainsKey(seaman))
                        {
                            m_SailTime.Add(seaman, DateTime.Now.AddSeconds(SAILSECONDS));
                        }
                    }
                }
            }
        }