Server.Items.HousePlacementEntry.OnPlacement C# (CSharp) Method

OnPlacement() public method

public OnPlacement ( Mobile from, Point3D p ) : bool
from Mobile
p Point3D
return bool
        public bool OnPlacement( Mobile from, Point3D p )
        {
            if ( !from.CheckAlive() || from.Backpack == null || from.Backpack.FindItemByType( typeof( HousePlacementTool ) ) == null  )
                return false;

            ArrayList toMove;
            Point3D center = new Point3D( p.X - m_Offset.X, p.Y - m_Offset.Y, p.Z - m_Offset.Z );
            HousePlacementResult res = HousePlacement.Check( from, m_MultiID, center, out toMove );

            switch ( res )
            {
                case HousePlacementResult.Valid:
                {
                    if ( from.AccessLevel < AccessLevel.GameMaster && BaseHouse.HasAccountHouse( from ) )
                    {
                        from.SendLocalizedMessage( 501271 ); // You already own a house, you may not place another!
                    }
                    else
                    {
                        from.SendLocalizedMessage( 1011576 ); // This is a valid location.

                        PreviewHouse prev = new PreviewHouse( m_MultiID );

                        MultiComponentList mcl = prev.Components;

                        Point3D banLoc = new Point3D( center.X + mcl.Min.X, center.Y + mcl.Max.Y + 1, center.Z );

                        for ( int i = 0; i < mcl.List.Length; ++i )
                        {
                            MultiTileEntry entry = mcl.List[i];

                            int itemID = entry.m_ItemID;

                            if ( itemID >= 0xBA3 && itemID <= 0xC0E )
                            {
                                banLoc = new Point3D( center.X + entry.m_OffsetX, center.Y + entry.m_OffsetY, center.Z );
                                break;
                            }
                        }

                        for ( int i = 0; i < toMove.Count; ++i )
                        {
                            object o = toMove[i];

                            if ( o is Mobile )
                                ((Mobile)o).Location = banLoc;
                            else if ( o is Item )
                                ((Item)o).Location = banLoc;
                        }

                        prev.MoveToWorld( center, from.Map );

                        /* You are about to place a new house.
                         * Placing this house will condemn any and all of your other houses that you may have.
                         * All of your houses on all shards will be affected.
                         *
                         * In addition, you will not be able to place another house or have one transferred to you for one (1) real-life week.
                         *
                         * Once you accept these terms, these effects cannot be reversed.
                         * Re-deeding or transferring your new house will not uncondemn your other house(s) nor will the one week timer be removed.
                         *
                         * If you are absolutely certain you wish to proceed, click the button next to OKAY below.
                         * If you do not wish to trade for this house, click CANCEL.
                         */
                        from.SendGump( new WarningGump( 1060635, 30720, 1049583, 32512, 420, 280, new WarningGumpCallback( PlacementWarning_Callback ), prev ) );

                        return true;
                    }

                    break;
                }
                case HousePlacementResult.BadItem:
                case HousePlacementResult.BadLand:
                case HousePlacementResult.BadStatic:
                case HousePlacementResult.BadRegionHidden:
                case HousePlacementResult.NoSurface:
                {
                    from.SendLocalizedMessage( 1043287 ); // The house could not be created here.  Either something is blocking the house, or the house would not be on valid terrain.
                    break;
                }
                case HousePlacementResult.BadRegion:
                {
                    from.SendLocalizedMessage( 501265 ); // Housing cannot be created in this area.
                    break;
                }
                case HousePlacementResult.BadRegionTemp:
                {
                    from.SendLocalizedMessage( 501270 ); //Lord British has decreed a 'no build' period, thus you cannot build this house at this time.
                    break;
                }
                case HousePlacementResult.BadRegionRaffle:
                {
                    from.SendLocalizedMessage( 1150493 ); // You must have a deed for this plot of land in order to build here.
                    break;
                }
                case HousePlacementResult.InvalidCastleKeep:
                {
                    from.SendLocalizedMessage( 1061122 ); // Castles and keeps cannot be created here.
                    break;
                }
            }

            return false;
        }

Usage Example

        protected override void OnTarget(Mobile from, object o)
        {
            if (!from.CheckAlive())
            {
                return;
            }

            IPoint3D ip = o as IPoint3D;

            if (ip != null)
            {
                if (ip is Item)
                {
                    ip = ((Item)ip).GetWorldTop();
                }

                Point3D p = new Point3D(ip);

                Region reg = Region.Find(new Point3D(p), from.Map);

                if (from.AccessLevel >= AccessLevel.GameMaster || reg.AllowHousing(from, p))
                {
                    m_Placed = m_Entry.OnPlacement(from, p);
                }
                else if (reg is TreasureRegion)
                {
                    from.SendLocalizedMessage(1043287);                       // The house could not be created here.  Either something is blocking the house, or the house would not be on valid terrain.
                }
                else
                {
                    from.SendLocalizedMessage(501265);                       // Housing can not be created in this area.
                }
            }
        }
All Usage Examples Of Server.Items.HousePlacementEntry::OnPlacement