Server.Misc.Titles.AwardKarma C# (CSharp) Méthode

AwardKarma() public static méthode

public static AwardKarma ( Mobile m, int offset, bool message ) : void
m Mobile
offset int
message bool
Résultat void
		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.
			}
		}

Usage Example

        public static void PayAssassin(Mobile m, Mobile leader)
        {
            string victim = CharacterDatabase.GetQuestInfo(m, "AssassinQuest");

            if (CharacterDatabase.GetQuestState(m, "AssassinQuest"))
            {
                string sAssassinTarget   = "";
                string sAssassinTitle    = "";
                string sAssassinName     = "";
                string sAssassinRegion   = "";
                int    nAssassinDone     = 0;
                int    nAssassinFee      = 0;
                string sAssassinWorld    = "";
                string sAssassinCategory = "";
                string sAssassinStory    = "";

                string[] victims = victim.Split('#');
                int      nEntry  = 1;
                foreach (string victimz in victims)
                {
                    if (nEntry == 1)
                    {
                        sAssassinTarget = victimz;
                    }
                    else if (nEntry == 2)
                    {
                        sAssassinTitle = victimz;
                    }
                    else if (nEntry == 3)
                    {
                        sAssassinName = victimz;
                    }
                    else if (nEntry == 4)
                    {
                        sAssassinRegion = victimz;
                    }
                    else if (nEntry == 5)
                    {
                        nAssassinDone = Convert.ToInt32(victimz);
                    }
                    else if (nEntry == 6)
                    {
                        nAssassinFee = Convert.ToInt32(victimz);
                    }
                    else if (nEntry == 7)
                    {
                        sAssassinWorld = victimz;
                    }
                    else if (nEntry == 8)
                    {
                        sAssassinCategory = victimz;
                    }
                    else if (nEntry == 9)
                    {
                        sAssassinStory = victimz;
                    }

                    nEntry++;
                }

                if (nAssassinDone > 0 && nAssassinFee > 0)
                {
                    m.SendSound(0x3D);
                    m.AddToBackpack(new Gold(nAssassinFee));
                    string sMessage = "";
                    switch (Utility.RandomMinMax(0, 9))
                    {
                    case 0: sMessage = "I assume the death was quick. Here is " + nAssassinFee.ToString() + " gold for you.";               break;

                    case 1: sMessage = "I bet they never seen you coming. Here is " + nAssassinFee.ToString() + " gold for you.";           break;

                    case 2: sMessage = "Was the death swift? Here is " + nAssassinFee.ToString() + " gold for you.";                break;

                    case 3: sMessage = "Were there any witnesses? Here is " + nAssassinFee.ToString() + " gold for you.";           break;

                    case 4: sMessage = "I am impressed. Here is " + nAssassinFee.ToString() + " gold for you.";             break;

                    case 5: sMessage = "Word of your deed already reached my ears. Here is " + nAssassinFee.ToString() + " gold for you.";          break;

                    case 6: sMessage = "How you did that one, I'll never know. Here is " + nAssassinFee.ToString() + " gold for you.";              break;

                    case 7: sMessage = "You are one of my best. Here is " + nAssassinFee.ToString() + " gold for you.";             break;

                    case 8: sMessage = "Did you leave the body behind? Here is " + nAssassinFee.ToString() + " gold for you.";              break;

                    case 9: sMessage = "Next time, strike from the shadows. Here is " + nAssassinFee.ToString() + " gold for you.";         break;
                    }
                    leader.Say(sMessage);

                    int totalKarma = nAssassinFee;
                    if (sAssassinCategory == "Innocent")
                    {
                        totalKarma = nAssassinFee * 2;
                    }                                                                                                    // MORE KARMA LOSS FOR CITIZENS

                    Titles.AwardFame(m, ((int)(totalKarma / 100)), true);
                    Titles.AwardKarma(m, -((int)(totalKarma / 100)), true);

                    AssassinFunctions.QuestTimeAllowed(m);

                    m.Criminal = false;
                    if (sAssassinCategory == "Innocent" && m.Kills > 0)
                    {
                        m.Kills = m.Kills - 1;
                    }                                                                                                   // REMOVE THE KILL FOR THIS CIVILIAN
                }
            }
        }
All Usage Examples Of Server.Misc.Titles::AwardKarma