Go Back   RunUO - Ultima Online Emulation > RunUO > Server Support on Windows

Server Support on Windows Get (and give) support on general questions related to the RunUO server itself.

Reply
 
Thread Tools Display Modes
Old 09-07-2007, 08:51 AM   #1 (permalink)
Newbie
 
Join Date: May 2005
Age: 29
Posts: 32
Send a message via ICQ to Admin_Delphi
Default Rental Vendor Crashing Server

Just wondering if anyone could help me. Every time I open the paper doll on a rental vendor it crashes my server. Can any one help with this? Here is the crash log.

Quote:
Server Crash Report
===================

RunUO Version 2.0, Build 2797.34178
Operating System: Microsoft Windows NT 5.1.2600 Service Pack 2
.NET Framework: 2.0.50727.832
Time: 9/7/2007 7:43:49 AM
Mobiles: 938
Items: 96152
Exception:
System.InvalidCastException: Unable to cast object of type 'Server.Mobiles.PlayerVendor' to type 'Server.Mobiles.PlayerMobile'.
at Server.Misc.Titles.ComputeTitle(Mobile beholder, Mobile beheld)
at Server.Misc.Paperdoll.EventSink_PaperdollRequest(P aperdollRequestEventArgs e)
at Server.EventSink.InvokePaperdollRequest(PaperdollR equestEventArgs e) in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\RunUO1\RunUO1\EventSink.cs:line 920
at Server.Mobile.DisplayPaperdollTo(Mobile to) in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\RunUO1\RunUO1\Mobile.cs:line 10421
at Server.Mobiles.PlayerVendor.DisplayPaperdollTo(Mob ile m)
at Server.ContextMenus.PaperdollEntry.OnClick() in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\RunUO1\RunUO1\ContextMenus\Paperdoll Entry.cs:line 37
at Server.Network.PacketHandlers.ContextMenuResponse( NetState state, PacketReader pvSrc) in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\RunUO1\RunUO1\Network\PacketHandlers .cs:line 1746
at Server.Network.PacketHandlers.ExtendedCommand(NetS tate state, PacketReader pvSrc) in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\RunUO1\RunUO1\Network\PacketHandlers .cs:line 1527
at Server.Network.MessagePump.HandleReceive(NetState ns) in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\RunUO1\RunUO1\Network\MessagePump.cs :line 242
at Server.Network.MessagePump.Slice() in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\RunUO1\RunUO1\Network\MessagePump.cs :line 109
at Server.Core.Main(String[] args) in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\RunUO1\RunUO1\Main.cs:line 472

Clients:
- Count: 1
Admin_Delphi is offline   Reply With Quote
Old 09-07-2007, 11:57 AM   #2 (permalink)
Forum Novice
 
brixey2451's Avatar
 
Join Date: Apr 2006
Location: Oregon
Age: 22
Posts: 134
Default

can you post your rental vendor script
brixey2451 is offline   Reply With Quote
Old 09-07-2007, 05:49 PM   #3 (permalink)
Forum Administrator
 
Join Date: Jan 2003
Location: Northern Virginia
Posts: 1,548
Default

Looks like you have an error in Misc\Titles.cs

Look how RunUO distribution does Champion titles:
Code:
if( beheld is PlayerMobile && ((PlayerMobile)beheld).DisplayChampionTitle )
You need to ensure you are dealing with a PlayerMobile before you attempt to cast to one.
Mark is offline   Reply With Quote
Old 09-07-2007, 09:55 PM   #4 (permalink)
Newbie
 
Join Date: May 2005
Age: 29
Posts: 32
Send a message via ICQ to Admin_Delphi
Default Rented Vendor Script

Now Keep in mind the server starts just fine and compiles the scripts properly. It only crashes when I open the paperdoll of a rental vendor. Players or shop keeper paper dolls work fine.


Code:
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Gumps;
using Server.Multis;
using Server.ContextMenus;
using Server.Prompts;

namespace Server.Mobiles
{
    public class VendorRentalDuration
    {
        public static readonly VendorRentalDuration[] Instances = new VendorRentalDuration[]
            {
                new VendorRentalDuration( TimeSpan.FromDays(  7.0 ), 1062361 ),    // 1 Week
                new VendorRentalDuration( TimeSpan.FromDays( 14.0 ), 1062362 ),    // 2 Weeks
                new VendorRentalDuration( TimeSpan.FromDays( 21.0 ), 1062363 ),    // 3 Weeks
                new VendorRentalDuration( TimeSpan.FromDays( 28.0 ), 1062364 )    // 1 Month
            };

        private TimeSpan m_Duration;
        private int m_Name;

        public TimeSpan Duration{ get{ return m_Duration; } }
        public int Name{ get{ return m_Name; } }

        public int ID
        {
            get
            {
                for ( int i = 0; i < Instances.Length; i++ )
                {
                    if ( Instances[i] == this )
                        return i;
                }

                return 0;
            }
        }

        private VendorRentalDuration( TimeSpan duration, int name )
        {
            m_Duration = duration;
            m_Name = name;
        }
    }

    public class RentedVendor : PlayerVendor
    {
        private VendorRentalDuration m_RentalDuration;
        private int m_RentalPrice;
        private bool m_LandlordRenew;
        private bool m_RenterRenew;
        private int m_RenewalPrice;

        private int m_RentalGold;

        private DateTime m_RentalExpireTime;
        private Timer m_RentalExpireTimer;

        public RentedVendor( Mobile owner, BaseHouse house, VendorRentalDuration duration, int rentalPrice, bool landlordRenew, int rentalGold ) : base( owner, house )
        {
            m_RentalDuration = duration;
            m_RentalPrice = m_RenewalPrice = rentalPrice;
            m_LandlordRenew = landlordRenew;
            m_RenterRenew = false;

            m_RentalGold = rentalGold;

            m_RentalExpireTime = DateTime.Now + duration.Duration;
            m_RentalExpireTimer = new RentalExpireTimer( this, duration.Duration );
            m_RentalExpireTimer.Start();
        }

        public RentedVendor( Serial serial ) : base( serial )
        {
        }

        public VendorRentalDuration RentalDuration
        {
            get{ return m_RentalDuration; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public int RentalPrice
        {
            get{ return m_RentalPrice; }
            set{ m_RentalPrice = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public bool LandlordRenew
        {
            get{ return m_LandlordRenew; }
            set{ m_LandlordRenew = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public bool RenterRenew
        {
            get{ return m_RenterRenew; }
            set{ m_RenterRenew = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public bool Renew
        {
            get{ return LandlordRenew && RenterRenew && House != null && House.DecayType != DecayType.Condemned; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public int RenewalPrice
        {
            get{ return m_RenewalPrice; }
            set{ m_RenewalPrice = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public int RentalGold
        {
            get{ return m_RentalGold; }
            set{ m_RentalGold = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public DateTime RentalExpireTime
        {
            get{ return m_RentalExpireTime; }
        }

        public override bool IsOwner( Mobile m )
        {
            return m == Owner || m.AccessLevel >= AccessLevel.GameMaster;
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public Mobile Landlord
        {
            get
            {
                if ( House != null )
                    return House.Owner;

                return null;
            }
        }

        public bool IsLandlord( Mobile m )
        {
            return House != null && House.IsOwner( m );
        }

        public void ComputeRentalExpireDelay( out int days, out int hours )
        {
            TimeSpan delay = RentalExpireTime - DateTime.Now;

            if ( delay <= TimeSpan.Zero )
            {
                days = 0;
                hours = 0;
            }
            else
            {
                days = delay.Days;
                hours = delay.Hours;
            }
        }

        public void SendRentalExpireMessage( Mobile to )
        {
            int days, hours;
            ComputeRentalExpireDelay( out days, out hours );

            to.SendLocalizedMessage( 1062464, days.ToString() + "\t" + hours.ToString() ); // The rental contract on this vendor will expire in ~1_DAY~ day(s) and ~2_HOUR~ hour(s).
        }

        public override void OnAfterDelete()
        {
            base.OnAfterDelete();

            m_RentalExpireTimer.Stop();
        }

        public override void Destroy( bool toBackpack )
        {
            if ( RentalGold > 0 && House != null && House.IsAosRules )
            {
                if ( House.MovingCrate == null )
                    House.MovingCrate = new MovingCrate( House );

                Banker.Deposit( House.MovingCrate, RentalGold );
                RentalGold = 0;
            }

            base.Destroy( toBackpack );
        }

        public override void GetContextMenuEntries( Mobile from, List<ContextMenuEntry> list )
        {
            if ( from.Alive )
            {
                if ( IsOwner( from ) )
                {
                    list.Add( new ContractOptionsEntry( this ) );
                }
                else if ( IsLandlord( from ) )
                {
                    if ( RentalGold > 0 )
                        list.Add( new CollectRentEntry( this ) );

                    list.Add( new TerminateContractEntry( this ) );
                    list.Add( new ContractOptionsEntry( this ) );
                }
            }

            base.GetContextMenuEntries( from, list );
        }

        private class ContractOptionsEntry : ContextMenuEntry
        {
            private RentedVendor m_Vendor;

            public ContractOptionsEntry( RentedVendor vendor ) : base( 6209 )
            {
                m_Vendor = vendor;
            }

            public override void OnClick()
            {
                Mobile from = Owner.From;

                if ( m_Vendor.Deleted || !from.CheckAlive() )
                    return;

                if ( m_Vendor.IsOwner( from ) )
                {
                    from.CloseGump( typeof( RenterVendorRentalGump ) );
                    from.SendGump( new RenterVendorRentalGump( m_Vendor ) );

                    m_Vendor.SendRentalExpireMessage( from );
                }
                else if ( m_Vendor.IsLandlord( from ) )
                {
                    from.CloseGump( typeof( LandlordVendorRentalGump ) );
                    from.SendGump( new LandlordVendorRentalGump( m_Vendor ) );

                    m_Vendor.SendRentalExpireMessage( from );
                }
            }
        }

        private class CollectRentEntry : ContextMenuEntry
        {
            private RentedVendor m_Vendor;

            public CollectRentEntry( RentedVendor vendor ) : base( 6212 )
            {
                m_Vendor = vendor;
            }

            public override void OnClick()
            {
                Mobile from = Owner.From;

                if ( m_Vendor.Deleted || !from.CheckAlive() || !m_Vendor.IsLandlord( from ) )
                    return;

                if ( m_Vendor.RentalGold > 0 )
                {
                    int depositedGold = Banker.DepositUpTo( from, m_Vendor.RentalGold );
                    m_Vendor.RentalGold -= depositedGold;

                    if ( depositedGold > 0 )
                        from.SendLocalizedMessage( 1060397, depositedGold.ToString() ); // ~1_AMOUNT~ gold has been deposited into your bank box.

                    if ( m_Vendor.RentalGold > 0 )
                        from.SendLocalizedMessage( 500390 ); // Your bank box is full.
                }
            }
        }

        private class TerminateContractEntry : ContextMenuEntry
        {
            private RentedVendor m_Vendor;

            public TerminateContractEntry( RentedVendor vendor ) : base( 6218 )
            {
                m_Vendor = vendor;
            }

            public override void OnClick()
            {
                Mobile from = Owner.From;

                if ( m_Vendor.Deleted || !from.CheckAlive() || !m_Vendor.IsLandlord( from ) )
                    return;

                from.SendLocalizedMessage( 1062503 ); // Enter the amount of gold you wish to offer the renter in exchange for immediate termination of this contract?
                from.Prompt = new RefundOfferPrompt( m_Vendor );
            }
        }

        private class RefundOfferPrompt : Prompt
        {
            private RentedVendor m_Vendor;

            public RefundOfferPrompt( RentedVendor vendor )
            {
                m_Vendor = vendor;
            }

            public override void OnResponse( Mobile from, string text )
            {
                if ( !m_Vendor.CanInteractWith( from, false ) || !m_Vendor.IsLandlord( from ) )
                    return;

                text = text.Trim();

                int amount;
                try
                {
                    amount = Convert.ToInt32( text );
                }
                catch
                {
                    amount = -1;
                }

                Mobile owner = m_Vendor.Owner;
                if ( owner == null )
                    return;

                if ( amount < 0 )
                {
                    from.SendLocalizedMessage( 1062506 ); // You did not enter a valid amount.  Offer canceled.
                }
                else if ( Banker.GetBalance( from ) < amount )
                {
                    from.SendLocalizedMessage( 1062507 ); // You do not have that much money in your bank account.
                }
                else if ( owner.Map != m_Vendor.Map || !owner.InRange( m_Vendor, 5 ) )
                {
                    from.SendLocalizedMessage( 1062505 ); // The renter must be closer to the vendor in order for you to make this offer.
                }
                else
                {
                    from.SendLocalizedMessage( 1062504 ); // Please wait while the renter considers your offer.

                    owner.CloseGump( typeof( VendorRentalRefundGump ) );
                    owner.SendGump( new VendorRentalRefundGump( m_Vendor, from, amount ) );
                }
            }
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );

            writer.WriteEncodedInt( 0 ); // version

            writer.WriteEncodedInt( m_RentalDuration.ID );

            writer.Write( (int) m_RentalPrice );
            writer.Write( (bool) m_LandlordRenew );
            writer.Write( (bool) m_RenterRenew );
            writer.Write( (int) m_RenewalPrice );

            writer.Write( (int) m_RentalGold );

            writer.WriteDeltaTime( (DateTime) m_RentalExpireTime );
        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadEncodedInt();

            int durationID = reader.ReadEncodedInt();
            if ( durationID < VendorRentalDuration.Instances.Length )
                m_RentalDuration = VendorRentalDuration.Instances[durationID];
            else
                m_RentalDuration = VendorRentalDuration.Instances[0];

            m_RentalPrice = reader.ReadInt();
            m_LandlordRenew = reader.ReadBool();
            m_RenterRenew = reader.ReadBool();
            m_RenewalPrice = reader.ReadInt();

            m_RentalGold = reader.ReadInt();

            m_RentalExpireTime = reader.ReadDeltaTime();

            TimeSpan delay = m_RentalExpireTime - DateTime.Now;
            m_RentalExpireTimer = new RentalExpireTimer( this, delay > TimeSpan.Zero ? delay : TimeSpan.Zero );
            m_RentalExpireTimer.Start();
        }

        private class RentalExpireTimer : Timer
        {
            private RentedVendor m_Vendor;

            public RentalExpireTimer( RentedVendor vendor, TimeSpan delay ) : base( delay, vendor.RentalDuration.Duration )
            {
                m_Vendor = vendor;

                Priority = TimerPriority.OneMinute;
            }

            protected override void OnTick()
            {
                int renewalPrice = m_Vendor.RenewalPrice;

                if ( m_Vendor.Renew && m_Vendor.HoldGold >= renewalPrice )
                {
                    m_Vendor.HoldGold -= renewalPrice;
                    m_Vendor.RentalGold += renewalPrice;

                    m_Vendor.RentalPrice = renewalPrice;

                    m_Vendor.m_RentalExpireTime = DateTime.Now + m_Vendor.RentalDuration.Duration;
                }
                else
                {
                    m_Vendor.Destroy( false );
                }
            }
        }
    }
}

Last edited by Admin_Delphi; 09-07-2007 at 09:59 PM.
Admin_Delphi is offline   Reply With Quote
Old 09-07-2007, 10:27 PM   #5 (permalink)
Forum Administrator
 
Join Date: Jan 2003
Location: Northern Virginia
Posts: 1,548
Default

Has nothing to do with the RentalVendors specifically. The problem is in Titles.cs
Mark is offline   Reply With Quote
Old 09-07-2007, 10:40 PM   #6 (permalink)
Newbie
 
Join Date: May 2005
Age: 29
Posts: 32
Send a message via ICQ to Admin_Delphi
Default

Here is my titles.cs.

Code:
using System;
using System.Text;
using Server;
using Server.Mobiles;
using Server.Engines.CannedEvil;

namespace Server.Misc
{
    public class Titles
    {
        public const int MinFame = 0;
        public const int MaxFame = 15000;

        public static void AwardFame( Mobile m, int offset, bool message )
        {
            if ( offset > 0 )
            {
                if ( m.Fame >= MaxFame )
                    return;

                offset -= m.Fame / 100;

                if ( offset < 0 )
                    offset = 0;
            }
            else if ( offset < 0 )
            {
                if ( m.Fame <= MinFame )
                    return;

                offset -= m.Fame / 100;

                if ( offset > 0 )
                    offset = 0;
            }

            if ( (m.Fame + offset) > MaxFame )
                offset = MaxFame - m.Fame;
            else if ( (m.Fame + offset) < MinFame )
                offset = MinFame - m.Fame;

            m.Fame += offset;

            if ( message )
            {
                if ( offset > 40 )
                    m.SendLocalizedMessage( 1019054 ); // You have gained a lot of fame.
                else if ( offset > 20 )
                    m.SendLocalizedMessage( 1019053 ); // You have gained a good amount of fame.
                else if ( offset > 10 )
                    m.SendLocalizedMessage( 1019052 ); // You have gained some fame.
                else if ( offset > 0 )
                    m.SendLocalizedMessage( 1019051 ); // You have gained a little fame.
                else if ( offset < -40 )
                    m.SendLocalizedMessage( 1019058 ); // You have lost a lot of fame.
                else if ( offset < -20 )
                    m.SendLocalizedMessage( 1019057 ); // You have lost a good amount of fame.
                else if ( offset < -10 )
                    m.SendLocalizedMessage( 1019056 ); // You have lost some fame.
                else if ( offset < 0 )
                    m.SendLocalizedMessage( 1019055 ); // You have lost a little fame.
            }
        }

        public const int MinKarma = -15000;
        public const int MaxKarma =  15000;

        public static void AwardKarma( Mobile m, int offset, bool message )
        {
            if ( offset > 0 )
            {
                if ( m is PlayerMobile && ((PlayerMobile)m).KarmaLocked )
                    return;

                if ( m.Karma >= MaxKarma )
                    return;

                offset -= m.Karma / 100;

                if ( offset < 0 )
                    offset = 0;
            }
            else if ( offset < 0 )
            {
                if ( m.Karma <= MinKarma )
                    return;

                offset -= m.Karma / 100;

                if ( offset > 0 )
                    offset = 0;
            }

            if ( (m.Karma + offset) > MaxKarma )
                offset = MaxKarma - m.Karma;
            else if ( (m.Karma + offset) < MinKarma )
                offset = MinKarma - m.Karma;

            bool wasPositiveKarma = ( m.Karma >= 0 );

            m.Karma += offset;

            if ( message )
            {
                if ( offset > 40 )
                    m.SendLocalizedMessage( 1019062 ); // You have gained a lot of karma.
                else if ( offset > 20 )
                    m.SendLocalizedMessage( 1019061 ); // You have gained a good amount of karma.
                else if ( offset > 10 )
                    m.SendLocalizedMessage( 1019060 ); // You have gained some karma.
                else if ( offset > 0 )
                    m.SendLocalizedMessage( 1019059 ); // You have gained a little karma.
                else if ( offset < -40 )
                    m.SendLocalizedMessage( 1019066 ); // You have lost a lot of karma.
                else if ( offset < -20 )
                    m.SendLocalizedMessage( 1019065 ); // You have lost a good amount of karma.
                else if ( offset < -10 )
                    m.SendLocalizedMessage( 1019064 ); // You have lost some karma.
                else if ( offset < 0 )
                    m.SendLocalizedMessage( 1019063 ); // You have lost a little karma.
            }

            if ( wasPositiveKarma && m.Karma < 0 && m is PlayerMobile && !((PlayerMobile)m).KarmaLocked )
            {
                ((PlayerMobile)m).KarmaLocked = true;
                m.SendLocalizedMessage( 1042511, "", 0x22 ); // Karma is locked.  A mantra spoken at a shrine will unlock it again.
            }
        }

        public static string[] HarrowerTitles = new string[] { "Spite", "Opponent", "Hunter", "Venom", "Executioner", "Annihilator", "Champion" };

        public static string ComputeTitle( Mobile beholder, Mobile beheld )
        {
            StringBuilder title = new StringBuilder();

            int fame = beheld.Fame;
            int karma = beheld.Karma;

            bool showSkillTitle = beheld.ShowFameTitle && ( (beholder == beheld) || (fame >= 5000) );

            /*if ( beheld.Kills >= 5 )
            {
                title.AppendFormat( beheld.Fame >= 10000 ? "The Murderer {1} {0}" : "The Murderer {0}", beheld.Name, beheld.Female ? "Lady" : "Lord" );
            }
            else*/if ( beheld.ShowFameTitle || (beholder == beheld) )
            {
                for ( int i = 0; i < m_FameEntries.Length; ++i )
                {
                    FameEntry fe = m_FameEntries[i];

                    if ( fame <= fe.m_Fame || i == (m_FameEntries.Length - 1) )
                    {
                        KarmaEntry[] karmaEntries = fe.m_Karma;

                        for ( int j = 0; j < karmaEntries.Length; ++j )
                        {
                            KarmaEntry ke = karmaEntries[j];

                            if ( karma <= ke.m_Karma || j == (karmaEntries.Length - 1) )
                            {
                                title.AppendFormat( ke.m_Title, beheld.Name, beheld.Female ? "Lady" : "Lord" );
                                break;
                            }
                        }

                        break;
                    }
                }
            }
            else
            {
                title.Append( beheld.Name );
            }

            if( beheld is PlayerMobile && ((PlayerMobile)beheld).DisplayChampionTitle )
            {
                PlayerMobile.ChampionTitleInfo info = ((PlayerMobile)beheld).ChampionTitles;

                if( info.Harrower > 0 )
                    title.AppendFormat( ": {0} of Evil", HarrowerTitles[Math.Min( HarrowerTitles.Length, info.Harrower )-1] );
                else
                {
                    int highestValue = 0, highestType = 0;
                    for( int i = 0; i < ChampionSpawnInfo.Table.Length; i++ )
                    {
                        int v = info.GetValue( i );

                        if( v > highestValue )
                        {
                            highestValue = v;
                            highestType = i;
                        }
                    }

                    int offset = 0;
                    if( highestValue > 800 )
                        offset = 3;
                    else if( highestValue > 300 )
                        offset = (int)(highestValue/300);

                    if( offset > 0 )
                    {
                        ChampionSpawnInfo champInfo = ChampionSpawnInfo.GetInfo( (ChampionSpawnType)highestType );
                        title.AppendFormat( ": {0} of the {1}", champInfo.LevelNames[Math.Min( offset, champInfo.LevelNames.Length ) -1], champInfo.Name );
                    }
                }
            }

            string customTitle = beheld.Title;

            if (customTitle != null && (customTitle = customTitle.Trim()).Length > 0)
            {
                title.AppendFormat(" {0}", customTitle);
            }
            else if (SkillTitles.Enabled)
            {
                PlayerMobile pm = (PlayerMobile)beheld;

                if (pm != null)
                {
                    Skill skill = pm.Skills[pm.Settings.SkillTitle];

                    if (skill != null && skill.BaseFixedPoint < 300)
                    {
                        skill = GetHighestSkill(beheld);
                    }

                    if (skill != null && skill.BaseFixedPoint >= 300)
                    {
                        string skillLevel = GetSkillLevel(skill);
                        string skillTitle = skill.Info.Title;

                        if (beheld.Female && skillTitle.EndsWith("man"))
                            skillTitle = skillTitle.Substring(0, skillTitle.Length - 3) + "woman";

                        title.AppendFormat(", {0} {1}", skillLevel, skillTitle);
                    }
                }
            }
            else if (showSkillTitle && beheld.Player)
            {
                Skill highest = GetHighestSkill(beheld);// beheld.Skills.Highest;

                if (highest != null && highest.BaseFixedPoint >= 300)
                {
                    string skillLevel = GetSkillLevel(highest);
                    string skillTitle = highest.Info.Title;

                    if (beheld.Female && skillTitle.EndsWith("man"))
                        skillTitle = skillTitle.Substring(0, skillTitle.Length - 3) + "woman";

                    title.AppendFormat(", {0} {1}", skillLevel, skillTitle);
                }
            }
            else if ( showSkillTitle && beheld.Player )
            {
                string skillTitle = GetSkillTitle( beheld );

                if ( skillTitle != null ) {
                    title.Append( ", " ).Append( skillTitle );
                }
            }

            return title.ToString();
        }

        public static string GetSkillTitle( Mobile mob ) {
            Skill highest = GetHighestSkill( mob );// beheld.Skills.Highest;

            if ( highest != null && highest.BaseFixedPoint >= 300 )
            {
                string skillLevel = GetSkillLevel( highest );
                string skillTitle = highest.Info.Title;

                if ( mob.Female && skillTitle.EndsWith( "man" ) )
                    skillTitle = skillTitle.Substring( 0, skillTitle.Length - 3 ) + "woman";

                return String.Concat( skillLevel, " ", skillTitle );
            }

            return null;
        }

        private static Skill GetHighestSkill( Mobile m )
        {
            Skills skills = m.Skills;

            if ( !Core.AOS )
                return skills.Highest;

            Skill highest = null;

            for ( int i = 0; i < m.Skills.Length; ++i )
            {
                Skill check = m.Skills[i];

                if ( highest == null || check.BaseFixedPoint > highest.BaseFixedPoint )
                    highest = check;
                else if ( highest != null && highest.Lock != SkillLock.Up && check.Lock == SkillLock.Up && check.BaseFixedPoint == highest.BaseFixedPoint )
                    highest = check;
            }

            return highest;
        }

        private static string[,] m_Levels = new string[,]
            {
                { "Neophyte",        "Neophyte",        "Neophyte"        },
                { "Novice",            "Novice",        "Novice"        },
                { "Apprentice",        "Apprentice",    "Apprentice"    },
                { "Journeyman",        "Journeyman",    "Journeyman"    },
                { "Expert",            "Expert",        "Expert"        },
                { "Adept",            "Adept",        "Adept"            },
                { "Master",            "Master",        "Master"        },
                { "Grandmaster",    "Grandmaster",    "Grandmaster"    },
                { "Elder",            "Tatsujin",        "Shinobi"        },
                { "Legendary",        "Kengo",        "Ka-ge"            }
            };

        public static string GetSkillLevel(Skill skill)
        {
            return m_Levels[GetTableIndex(skill), GetTableType(skill)];
        }

        private static int GetTableType( Skill skill )
        {
            switch ( skill.SkillName )
            {
                default: return 0;
                case SkillName.Bushido: return 1;
                case SkillName.Ninjitsu: return 2;
            }
        }

        private static int GetTableIndex( Skill skill )
        {
            int fp = Math.Min( skill.BaseFixedPoint, 1200 );

            return (fp - 300) / 100;
        }

        private static FameEntry[] m_FameEntries = new FameEntry[]
            {
                new FameEntry( 1249, new KarmaEntry[]
                {
                    new KarmaEntry( -10000, "The Outcast {0}" ),
                    new KarmaEntry( -5000, "The Despicable {0}" ),
                    new KarmaEntry( -2500, "The Scoundrel {0}" ),
                    new KarmaEntry( -1250, "The Unsavory {0}" ),
                    new KarmaEntry( -625, "The Rude {0}" ),
                    new KarmaEntry( 624, "{0}" ),
                    new KarmaEntry( 1249, "The Fair {0}" ),
                    new KarmaEntry( 2499, "The Kind {0}" ),
                    new KarmaEntry( 4999, "The Good {0}" ),
                    new KarmaEntry( 9999, "The Honest {0}" ),
                    new KarmaEntry( 10000, "The Trustworthy {0}" )
                } ),
                new FameEntry( 2499, new KarmaEntry[]
                {
                    new KarmaEntry( -10000, "The Wretched {0}" ),
                    new KarmaEntry( -5000, "The Dastardly {0}" ),
                    new KarmaEntry( -2500, "The Malicious {0}" ),
                    new KarmaEntry( -1250, "The Dishonorable {0}" ),
                    new KarmaEntry( -625, "The Disreputable {0}" ),
                    new KarmaEntry( 624, "The Notable {0}" ),
                    new KarmaEntry( 1249, "The Upstanding {0}" ),
                    new KarmaEntry( 2499, "The Respectable {0}" ),
                    new KarmaEntry( 4999, "The Honorable {0}" ),
                    new KarmaEntry( 9999, "The Commendable {0}" ),
                    new KarmaEntry( 10000, "The Estimable {0}" )
                } ),
                new FameEntry( 4999, new KarmaEntry[]
                {
                    new KarmaEntry( -10000, "The Nefarious {0}" ),
                    new KarmaEntry( -5000, "The Wicked {0}" ),
                    new KarmaEntry( -2500, "The Vile {0}" ),
                    new KarmaEntry( -1250, "The Ignoble {0}" ),
                    new KarmaEntry( -625, "The Notorious {0}" ),
                    new KarmaEntry( 624, "The Prominent {0}" ),
                    new KarmaEntry( 1249, "The Reputable {0}" ),
                    new KarmaEntry( 2499, "The Proper {0}" ),
                    new KarmaEntry( 4999, "The Admirable {0}" ),
                    new KarmaEntry( 9999, "The Famed {0}" ),
                    new KarmaEntry( 10000, "The Great {0}" )
                } ),
                new FameEntry( 9999, new KarmaEntry[]
                {
                    new KarmaEntry( -10000, "The Dread {0}" ),
                    new KarmaEntry( -5000, "The Evil {0}" ),
                    new KarmaEntry( -2500, "The Villainous {0}" ),
                    new KarmaEntry( -1250, "The Sinister {0}" ),
                    new KarmaEntry( -625, "The Infamous {0}" ),
                    new KarmaEntry( 624, "The Renowned {0}" ),
                    new KarmaEntry( 1249, "The Distinguished {0}" ),
                    new KarmaEntry( 2499, "The Eminent {0}" ),
                    new KarmaEntry( 4999, "The Noble {0}" ),
                    new KarmaEntry( 9999, "The Illustrious {0}" ),
                    new KarmaEntry( 10000, "The Glorious {0}" )
                } ),
                new FameEntry( 10000, new KarmaEntry[]
                {
                    new KarmaEntry( -10000, "The Dread {1} {0}" ),
                    new KarmaEntry( -5000, "The Evil {1} {0}" ),
                    new KarmaEntry( -2500, "The Dark {1} {0}" ),
                    new KarmaEntry( -1250, "The Sinister {1} {0}" ),
                    new KarmaEntry( -625, "The Dishonored {1} {0}" ),
                    new KarmaEntry( 624, "{1} {0}" ),
                    new KarmaEntry( 1249, "The Distinguished {1} {0}" ),
                    new KarmaEntry( 2499, "The Eminent {1} {0}" ),
                    new KarmaEntry( 4999, "The Noble {1} {0}" ),
                    new KarmaEntry( 9999, "The Illustrious {1} {0}" ),
                    new KarmaEntry( 10000, "The Glorious {1} {0}" )
                } )
            };
    }

    public class FameEntry
    {
        public int m_Fame;
        public KarmaEntry[] m_Karma;

        public FameEntry( int fame, KarmaEntry[] karma )
        {
            m_Fame = fame;
            m_Karma = karma;
        }
    }

    public class KarmaEntry
    {
        public int m_Karma;
        public string m_Title;

        public KarmaEntry( int karma, string title )
        {
            m_Karma = karma;
            m_Title = title;
        }
    }
}

Last edited by Admin_Delphi; 09-07-2007 at 10:53 PM.
Admin_Delphi is offline   Reply With Quote
Old 09-07-2007, 11:28 PM   #7 (permalink)
Forum Administrator
 
Join Date: Jan 2003
Location: Northern Virginia
Posts: 1,548
Default

Here is where the problem is:

Code:
            else if (SkillTitles.Enabled)
            {
                PlayerMobile pm = (PlayerMobile)beheld;
You do not test if beheld is a PlayerMobile before casting.

There are 2 solutions:

1. Change "else if ( SkillTitles.Enabled )" to "else if ( SkillTitles.Enabled && beheld is PlayerMobile )"

2. Change "PlayerMobile pm = (PlayerMobile)beheld;" to "PlayerMobile pm = beheld as PlayerMobile;"

I recommend using method two, as it will set pm to null if beheld is not a PlayerMobile and you already have a null check right after the cast. If you write new code though, I would use the first method as it is easier to read and flows better.
Mark is offline   Reply With Quote
Old 09-08-2007, 12:08 AM   #8 (permalink)
Newbie
 
Join Date: May 2005
Age: 29
Posts: 32
Send a message via ICQ to Admin_Delphi
Default

Thanks very much your were 100% on the money! It works great now.
Admin_Delphi is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5