Exemple #1
0
        /// <summary>
        /// Shows a character's attribute screen.
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="str"></param>
        public static void Attributes(CharData ch, string[] str)
        {
            if( ch == null ) return;

            string buf1 = String.Empty;

            if (ch.IsNPC())
            {
                ch.SendText("&nYour attributes are as would be expected for an NPC.\r\n");
                return;
            }

            if (ch.IsImmortal() && str.Length != 0)
            {
                CharData worldChar = ch.GetCharWorld(str[0]);
                if (!worldChar)
                {
                    ch.SendText("No such person.\r\n");
                    return;
                }
                if (worldChar.IsNPC())
                {
                    ch.SendText("NPCs don't have skills!\r\n");
                    return;
                }
            }

            string buf = String.Format(
                "&+WName: &+G{0}&n    &+WLevel: {1}&n\r\n",
                MUDString.PadStr(ch.Name, 17),
                ch.Level);
            buf1 += buf;

            buf = String.Format(
                      "&+WRace:&n {0}          &+WClass:&n {1}     &n&+WSex:&n {2}\r\n",
                      MUDString.PadStr(Race.RaceList[ch.GetRace()].ColorName, 16),
                      MUDString.PadStr(ch.CharacterClass.WholistName, 16),
                      System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(ch.GetSexString()));
            buf1 += buf;

            // Break a player's size into strings when we get around to it
            // -- Xangis
            if (!ch.IsNPC())
            {
                buf = String.Format(
                          "&+WHeight:&n {0} inches         &+WWeight:&n {1} pounds    &+WSize:&n {2}\r\n",
                          MUDString.PadInt(((PC)ch).Height, 3),
                          MUDString.PadInt(((PC)ch).Weight, 5),
                          Race.SizeString(ch.CurrentSize));
            }
            else
            {
                buf = String.Format("&+WSize:&n  {0}\r\n", ch.CurrentSize);
            }
            buf1 += buf;

            TimeSpan time = TimeSpan.FromTicks(ch.TimePlayed.Ticks) + (DateTime.Now - ch.LogonTime);
            int days = (int)time.TotalHours / 24;
            time = (time - TimeSpan.FromDays(days));
            int hours = (int)time.TotalHours;
            time = (time - TimeSpan.FromHours(hours));
            int minutes = (int)time.TotalMinutes;

            // Age is a hack until we get it coded - Xangis
            buf = String.Format(
                      "\r\n&+BAge:&n {0} years.             &+BPlaying Time:&n {1} days {2} hours {3} minutes.\r\n",
                      MUDString.PadInt(ch.GetAge(), 3), days, hours, minutes);
            buf1 += buf;

            // Need to create a function to display character status strings
            buf = String.Format("&+BStatus:&n  {0}", System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Position.PositionString(ch.CurrentPosition)));
            if (!ch.IsNPC() && ch.IsAffected(Affect.AFFECT_BERZERK))
            {
                buf += ", &+Rberzerk&n";
            }
            if (!ch.IsNPC() && ch.HasActionBit(PC.PLAYER_MEMORIZING))
            {
                buf += ", Memorizing";
            }
            if (ch.IsAffected(Affect.AFFECT_CASTING))
            {
                buf += ", Casting";
            }
            if (ch.IsAffected(Affect.AFFECT_SINGING))
            {
                buf += ", Singing";
            }
            if (!ch.IsNPC() && ch.HasActionBit(PC.PLAYER_MEDITATING))
            {
                buf += ", Meditating";
            }
            if (!ch.IsNPC() && ch.HasActionBit(PC.PLAYER_CAMPING))
            { /* This is ugly and should be moved to its own function */
                buf += ", Camping";
            }
            buf += ".\r\n\r\n";
            buf1 += buf;

            // We want players to see the same stats for levels 1-50.

            // Should create string converters so that we have no decimals displayed
            // below this point.
            buf = String.Format("     &+cSTR:&n  {0}      &+cArmor Class:&n {1}.\r\n",
                      MUDString.PadStr(StringConversion.AbilityScoreString(ch.GetCurrStr()), 15), ch.GetAC());
            buf1 += buf;
            buf = String.Format("     &+cAGI:&n  {0}      &+cHitroll:&n     {1}\r\n",
                      MUDString.PadStr(StringConversion.AbilityScoreString(ch.GetCurrAgi()), 15), StringConversion.BonusString(ch.GetHitroll(ObjTemplate.WearLocation.hand_one)));
            buf1 += buf;
            buf = String.Format("     &+cDEX:&n  {0}      &+cDamroll:&n     {1}\r\n",
                      MUDString.PadStr(StringConversion.AbilityScoreString(ch.GetCurrDex()), 15), StringConversion.BonusString(ch.GetDamroll(ObjTemplate.WearLocation.hand_one)));
            buf1 += buf;
            buf = String.Format("     &+cCON:&n  {0}      &+cAlignment:&n   {1}\r\n",
                      MUDString.PadStr(StringConversion.AbilityScoreString(ch.GetCurrCon()), 15), StringConversion.AlignmentString(ch));
            buf1 += buf;
            buf = String.Format("     &n&+cINT:&n  {0}\r\n", MUDString.PadStr(StringConversion.AbilityScoreString(ch.GetCurrInt()), 15));
            buf1 += buf;
            buf = String.Format("     &+cWIS:&n  {0}      &+BSaving Throws&n\r\n",
                      MUDString.PadStr(StringConversion.AbilityScoreString(ch.GetCurrWis()), 15));
            buf1 += buf;
            buf = String.Format("     &+cPOW:&n  {0}      &+cParalysis:&n {1}\r\n",
                      MUDString.PadStr(StringConversion.AbilityScoreString(ch.GetCurrPow()), 15), StringConversion.BonusString(-ch.SavingThrows[0]));
            buf1 += buf;
            buf = String.Format("     &+cCHA:&n  {0}      &+cRod:&n       {1}\r\n",
                      MUDString.PadStr(StringConversion.AbilityScoreString(ch.GetCurrCha()), 15), StringConversion.BonusString(-ch.SavingThrows[1]));
            buf1 += buf;
            buf = String.Format("     &+cLUK:&n  {0}      &+cPetrify:&n   {1}\r\n",
                      MUDString.PadStr(StringConversion.AbilityScoreString(ch.GetCurrLuck()), 15), StringConversion.BonusString(-ch.SavingThrows[2]));
            buf1 += buf;

            buf = String.Format("                                &+cBreath:&n    {0}\r\n",
                      StringConversion.BonusString(-ch.SavingThrows[3]));
            buf1 += buf;

            buf = String.Format("&+BWimpy:        &n{0}               &+cSpell:&n     {1}\r\n",
                      MUDString.PadInt(ch.Wimpy, 4), StringConversion.BonusString(-ch.SavingThrows[4]));
            buf1 += buf;

            buf = String.Format("&+BLoad Carried: &n{0} pounds ({1})\r\n",
                      MUDString.PadInt(ch.CarryWeight, 3), StringConversion.WeightString(ch));
            buf1 += buf;

            ch.SendText(buf1);
            return;
        }
Exemple #2
0
        /// <summary>
        /// Search the local area for food.
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="str"></param>
        public static void Forage(CharData ch, string[] str)
        {
            if( ch == null ) return;

            int indexNumber;
            Object obj = null;
            int[] flist = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 25 };

            if (!ch.InRoom)
            {
                ch.SendText("There's no foraging to be done here.\r\n");
                return;
            }

            if (ch.FlightLevel != 0)
            {
                ch.SendText("Right, you're going to find something way up here.\r\n");
                return;
            }
            int chance = 10 + (ch.GetCurrLuck() / 20);
            if (ch.IsClass(CharClass.Names.ranger) || ch.IsClass(CharClass.Names.hunter) || ch.IsImmortal())
                chance = 75;
            if (chance < MUDMath.NumberPercent())
            {
                ch.SendText("You don't find anything at all.\r\n");
                ch.Wait += 10;
                return;
            }
            ch.Wait += 15;
            TerrainType sector = ch.InRoom.TerrainType;
            // TODO: FIXME: Don't use hard-coded item numbers!
            switch (sector)
            {
                default:
                    ch.SendText("Nothing edible could be growing here.\r\n");
                    return;
                case TerrainType.field:
                    flist[0] = 80;
                    flist[1] = 84;
                    flist[2] = 86;
                    flist[6] = 91;
                    flist[7] = 80;
                    break;
                case TerrainType.hills:
                    flist[0] = 82748;
                    flist[1] = 86;
                    flist[2] = 92;
                    flist[6] = 94;
                    break;
                case TerrainType.underground_wild:
                    flist[0] = 3352;
                    flist[5] = 3352;
                    flist[6] = 7711;
                    flist[1] = 85;
                    flist[2] = 88;
                    flist[7] = 82;
                    flist[8] = 83;
                    break;
                case TerrainType.swamp:
                    flist[0] = 3352;
                    flist[1] = 88;
                    flist[5] = 94;
                    flist[6] = 83;
                    flist[7] = 89;
                    break;
                case TerrainType.forest:
                    flist[0] = 2057;
                    flist[1] = 81651;
                    flist[2] = 90;
                    flist[3] = 93;
                    flist[4] = 92;
                    flist[5] = 90;
                    flist[6] = 87;
                    flist[7] = 84;
                    break;
            } //end switch
            if (ch.IsClass(CharClass.Names.ranger) || ch.IsClass(CharClass.Names.hunter))
                indexNumber = flist[MUDMath.NumberRange(0, 9)];
            else
                indexNumber = flist[MUDMath.NumberRange(0, 4)];
            if (indexNumber == 0)
            {
                ch.SendText("You find nothing edible.\r\n");
                return;
            }
            string buf = String.Format("Forage: {0} found index number {1} in room {2}.", ch.Name, indexNumber, ch.InRoom.IndexNumber);
            ImmortalChat.SendImmortalChat(null, ImmortalChat.IMMTALK_SPAM, 0, buf);
            /*
            if (fvnum == StaticObjects.OBJECT_NUMBER_SPRING) {
            //don't allow endless springs
            for ( obj = ch.in_room.contents; obj; obj = obj.next_content ) {
            if (obj.pIndexData.vnum == fvnum) {
            Descriptor._actFlags("You notice the $p&n.", ch, obj, null, Descriptor.MessageTarget.character);
            return;
            }
            }
            }
            */
            ObjTemplate objTemplate = Database.GetObjTemplate(indexNumber);
            // Foraging found an object that doesn't exist -- log an error and fail gracefully.
            if (objTemplate == null)
            {
                Log.Error("Forage: invalid object index number " + indexNumber + " in terrain type " + sector + ".");
                ch.SendText("The area appears to have been picked clean.\r\n");
                return;
            }
            obj = Database.CreateObject(objTemplate, 1);
            obj.AddToRoom(ch.InRoom);
            obj.FlyLevel = 0;
            if (indexNumber == StaticObjects.OBJECT_NUMBER_SPRING) // give spring a timer;
            {
                obj.Timer = 10 + MUDMath.NumberRange(1, 20);
            }
            SocketConnection.Act("You find $p&n.", ch, obj, null, SocketConnection.MessageTarget.character);
            SocketConnection.Act("$n&n forages around and finds $p&n.", ch, obj, null, SocketConnection.MessageTarget.room);
            return;
        }
Exemple #3
0
        /// <summary>
        /// Steal an object or some coins from a victim.
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="str"></param>
        public static void Steal(CharData ch, string[] str)
        {
            if( ch == null ) return;

            Object obj = null;
            CharData victim;
            bool sleeping = false;
            string arg1 = String.Empty;
            string arg2 = String.Empty;
            string arg = String.Empty;
            int percent;

            if (!ch.HasSkill("steal") && !ch.IsAffected(Affect.AFFECT_CHARM))
            {
                ch.SendText("Who are you trying to kid?  You couldn't steal shoes from a &n&+mbl&+Mo&n&+ma&+Mte&n&+md&n corpse.\r\n");
                return;
            }

            if (ch.Riding != null)
            {
                ch.SendText("You can't do that while mounted.\r\n");
                return;
            }

            if (String.IsNullOrEmpty(arg1) || String.IsNullOrEmpty(arg2))
            {
                ch.SendText("Steal what from whom?\r\n");
                return;
            }

            if ((victim = ch.GetCharRoom(arg2)) == null)
            {
                ch.SendText("They aren't here.\r\n");
                return;
            }

            if (victim == ch)
            {
                ch.SendText("That's pointless.\r\n");
                return;
            }

            if (Combat.IsSafe(ch, victim))
                return;

            if (!ch.IsImmortal())
            {
                ch.WaitState(Skill.SkillList["steal"].Delay);
            }

            // Justice stuff
            Crime.CheckThief(ch, victim);

            if (ch.IsNPC())
            {
                percent = ch.Level * 2;
            }
            else
            {
                percent = ((PC)ch).SkillAptitude["steal"];
            }

            percent += ch.GetCurrLuck() / 20; /* Luck */

            percent -= victim.Level; /* Character level vs victim's */

            if (ch.GetRace() == Race.RACE_HALFLING)
            {
                // Halflings get a racial bonus
                percent += 10;
            }

            if (victim.IsAffected(Affect.AFFECT_CURSE))
                percent += 15;

            if (ch.IsAffected(Affect.AFFECT_CURSE))
                percent -= 15;

            if (!victim.IsAwake())
                percent += 25; /* Sleeping characters are easier */

            if (ch.CheckSneak())
                percent += 10; /* Quiet characters steal better */

            if (!CharData.CanSee(ch, victim))
                percent += 10; /* Unseen characters steal better */

            if (!MUDString.IsPrefixOf(arg1, "coins"))
            {
                percent = (int)(percent * 1.2); /* Cash is fairly easy to steal */
            }
            else
            {
                int number = MUDString.NumberArgument(arg1, ref arg);
                int count = 0;
                foreach (Object iobj in victim.Carrying)
                {
                    if (CharData.CanSeeObj(ch, iobj) && MUDString.NameContainedIn(arg, iobj.Name))
                    {
                        if (++count == number)
                        {
                            obj = iobj;
                            break;
                        }
                    }
                }

                if (!obj)
                {
                    ch.SendText("You can't find it.\r\n");
                    return;
                }

                if (ch.Level < victim.Level)
                {
                    // stealing from higher level is possible, but harder
                    percent -= 5 * (victim.Level - ch.Level);
                }
                else
                {
                    // slight bonus for mobs lower level
                    percent += (ch.Level - victim.Level);
                }
                if (obj.WearLocation == ObjTemplate.WearLocation.none)
                    /* Items worn are harder */
                    percent = (int)(percent * .8);
                else
                    percent = (int)(percent * .4);
            }

            ch.PracticeSkill("steal");

            if (percent > 85)
                percent = 85;

            if (percent < 2)
                percent = 2;
            if (percent < MUDMath.NumberPercent())
            {
                /*
                * Failure.
                */
                //strip sneak
                ch.RemoveAffect(Affect.AFFECT_SNEAK);
                // chance of removing invis
                if (ch.IsAffected(Affect.AFFECT_INVISIBLE) && MUDMath.NumberPercent() > percent)
                {
                    ch.SendText("You really bungled that attempt.\r\n");
                    ch.RemoveAffect(Affect.AFFECT_INVISIBLE);
                }
                else
                {
                    ch.SendText("Oops.\r\n");
                }
                SocketConnection.Act("$n&n tried to steal from $N&n.", ch, null, victim, SocketConnection.MessageTarget.everyone_but_victim);
                if (victim.IsAwake())
                {
                    SocketConnection.Act("$n&n tried to steal from you!", ch, null, victim, SocketConnection.MessageTarget.victim);
                }
                else
                {
                    sleeping = true;
                }
                // Thief flag for justice.
                // Added so blind mobs dont hit who ever failed steal from em.
                if (victim.IsNPC())
                {
                    if (!sleeping && !victim.IsBlind())
                    {
                        CommandType.Interpret(victim, "kill " + ch.Name);
                    }
                }
                else
                {
                    if (!victim.IsBlind() && !sleeping && victim.IsAffected(Affect.AFFECT_BERZERK))
                    {
                        victim.SendText("In your &+Rblood rage&n, you lash out in anger!\r\n");
                        CommandType.Interpret(victim, "kill " + ch.Name);
                    }
                }
                /*
                if ( !Macros.IS_SET( ch.actflags, PC.PLAYER_THIEF ) )
                {
                Macros.SET_BIT( ref ch.actflags, PC.PLAYER_THIEF );
                buf = String.Format(  "{0} became a THIEF by stealing from {1}",
                ch._name, victim._name );
                Immtalk.Immtalk( ch, Immtalk.IMMTALK_CRIME, ch.GetTrust(), buf );
                CharData.SavePlayer( ch );
                }
                */
                //    }
                if (sleeping)
                {
                    if (MUDMath.NumberPercent() < victim.GetCurrLuck())
                    {
                        CommandType.Interpret(victim, "wake");
                    }
                }
                return;
            } //end failure

            if (!MUDString.IsPrefixOf(arg1, "coins"))
            {
                int amount = victim.GetGold() * MUDMath.NumberRange(1, 20) / 100;
                int amount2 = victim.GetSilver() * MUDMath.NumberRange(1, 20) / 100;
                int amount3 = victim.GetCopper() * MUDMath.NumberRange(1, 20) / 100;
                int amount4 = victim.GetPlatinum() * MUDMath.NumberRange(1, 20) / 100;

                if ((amount + amount2 + amount3 + amount4) <= 0)
                {
                    ch.SendText("You couldn't get any &n&+wcoins&n.\r\n");
                    return;
                }

                ch.ReceiveGold(amount);
                ch.ReceiveSilver(amount2);
                ch.ReceiveCopper(amount3);
                ch.ReceivePlatinum(amount4);

                victim.SpendGold(amount);
                victim.SpendSilver(amount2);
                victim.SpendCopper(amount3);
                victim.SpendPlatinum(amount4);

                string text = String.Format("Success!  You got {0} &+Wplatinum&n, {1} &+Ygold&n, {2} silver, and {3} &+ycopper&n.\r\n",
                                            amount2, amount3, amount, amount4);
                ch.SendText(text);
                return;
            }

            if (!ch.CanDropObject(obj) || obj.HasFlag(ObjTemplate.ITEM_INVENTORY))
            {
                ch.SendText("You can't pry it away.\r\n");
                return;
            }

            if (ch.CarryNumber + 1 > Limits.MAX_CARRY)
            {
                ch.SendText("You have your hands full.\r\n");
                return;
            }

            if (ch.CarryWeight + obj.GetWeight() > ch.MaxCarryWeight())
            {
                ch.SendText("You cannot carry that much weight.\r\n");
                return;
            }

            if (obj.WearLocation != ObjTemplate.WearLocation.none)
            {
                ch.SendText("Very daring, and you got it!\r\n");
                victim.UnequipObject(obj);
            }

            obj.RemoveFromChar();
            obj.ObjToChar(ch);
            ch.SendText("Nice work.\r\n");
            if (obj.Trap != null && obj.Trap.CheckTrigger( Trap.TriggerType.steal))
            {
                ch.SetOffTrap(obj);
                if (ch.CurrentPosition == Position.dead)
                {
                    return;
                }
            }
            return;
        }
Exemple #4
0
        /// <summary>
        /// Try to find hidden things.
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="str"></param>
        public static void Search(CharData ch, string[] str)
        {
            if( ch == null ) return;

            Room toRoom;
            Exit reverseExit;
            Exit exit = null;
            Object obj;
            bool isArg;
            Exit.Direction door;

            if (ch.InRoom == null)
            {
                ch.SendText("There's no searching to be done here.\r\n");
                return;
            }

            /* Calculate the probability that ch finds something. */
            int chance = ch.GetCurrInt() * 35 / 100;
            chance += ch.GetCurrWis() * 35 / 100;
            chance += ch.GetCurrLuck() * 10 / 100;

            // Dwarves, being natural architects, can search better - Xangis
            if (ch.GetRace() == Race.RACE_DWARF)
                chance += 25;

            if (chance > 95)
                chance = 95;
            if (chance < 10)
                chance = 10;

            /* Searching with arguments. */
            if (str.Length != 0)
            {
                isArg = true;
                obj = ch.GetObjHere(str[0]);
                if (obj == null)
                {
                    ch.SendText("You don't see that object here.\r\n");
                    return;
                }
                switch (obj.ItemType)
                {
                    case ObjTemplate.ObjectType.quiver:
                    case ObjTemplate.ObjectType.container:
                    case ObjTemplate.ObjectType.npc_corpse:
                    case ObjTemplate.ObjectType.pc_corpse:
                        if (Macros.IsSet(obj.Values[1], ObjTemplate.CONTAINER_CLOSED.Vector))
                        {
                            SocketConnection.Act("$p&n is closed.", ch, obj, null, SocketConnection.MessageTarget.character);
                            return;
                        }
                        break;
                    default:
                        ch.SendText("That is not a container!\r\n");
                        return;
                }
            }
            else
            {
                isArg = false;
                obj = null;
            }

            /* Lag ch from searching. */
            if (ch.Level < Limits.LEVEL_AVATAR)
            {
                ch.WaitState(MUDMath.FuzzyNumber(18));
            }

            List<Object> list;
            if (obj != null)
            {
                list = obj.Contains;
            }
            else
            {
                list = ch.InRoom.Contents;
            }
            foreach (Object obj2 in list)
            {
                if (obj2.HasFlag(ObjTemplate.ITEM_SECRET) && chance > MUDMath.NumberPercent()
                        && obj2.FlyLevel == ch.FlightLevel)
                {
                    obj2.RemoveFlag(ObjTemplate.ITEM_SECRET);
                    SocketConnection.Act("You find $p&n.", ch, obj2, null, SocketConnection.MessageTarget.character);
                    SocketConnection.Act("$n&n points out $p&n!", ch, obj, null, SocketConnection.MessageTarget.room);
                    return;
                }
            }

            /* Look for a hidden exit. */
            door = Exit.Direction.invalid;
            for (int doornum = 0; doornum <= Limits.MAX_DIRECTION; doornum++)
            {
                /* If there's a secret exit that leads to a room. */
                exit = ch.InRoom.GetExit((Exit.Direction)doornum);
                if (exit && exit.HasFlag(Exit.ExitFlag.secret) && exit.TargetRoom)
                {
                    door = (Exit.Direction)doornum;
                    break;
                }
            }

            if (isArg)
            {
                door = Exit.Direction.invalid;
            }
            if (door != Exit.Direction.invalid)
            {
                if (exit == null)
                {
                    Log.Error("Command.Search: null exit found", 0);
                    return;
                }
                if (exit.TargetRoom == null)
                {
                    Log.Error("Command.Search: exit to null room found", 0);
                    return;
                }
                if (MUDMath.NumberPercent() < chance)
                {
                    if (ch.FlightLevel > 0)
                    {
                        ch.SendText("You're too high to be sure of what you saw.\r\n");
                        return;
                    }
                    ch.SendText("You found a hidden exit!\r\n");
                    SocketConnection.Act("$n&n points out a secret exit!", ch, null, null, SocketConnection.MessageTarget.room);

                    /* Search out one side. */
                    exit.RemoveFlag(Exit.ExitFlag.secret);
                    /* And the other side, if it exists. */
                    toRoom = Room.GetRoom(exit.IndexNumber);
                    if (toRoom && (reverseExit = toRoom.GetExit(Exit.ReverseDirection(door))) && (reverseExit.TargetRoom == ch.InRoom))
                    {
                        reverseExit.RemoveFlag(Exit.ExitFlag.secret);
                    }
                    return;
                }
            }

            if (!isArg)
            {
                // Chance of finding people hiding in the room
                foreach (CharData roomChar in ch.InRoom.People)
                {
                    if (!roomChar.IsAffected(Affect.AFFECT_HIDE) || roomChar.FlightLevel != ch.FlightLevel)
                        continue;
                    if (MUDMath.NumberPercent() < chance)
                    {
                        roomChar.RemoveAffect(Affect.AFFECT_HIDE);
                        /* People without DI can't search out invis hiding pplz. */
                        if (CharData.CanSee(ch, roomChar))
                        {
                            SocketConnection.Act("$n&n points out $N&n lurking here!", ch, null, roomChar, SocketConnection.MessageTarget.room);
                            SocketConnection.Act("You point out $N&n lurking here!", ch, null, roomChar, SocketConnection.MessageTarget.character);
                            SocketConnection.Act("$n&n reveals your hiding spot!", ch, null, roomChar, SocketConnection.MessageTarget.victim);
                            return;
                        }
                        roomChar.SetAffectBit(Affect.AFFECT_HIDE);
                    }
                }
            }

            ch.SendText("You find nothing new.\r\n");
            return;
        }
Exemple #5
0
        /// <summary>
        /// Processes a blur-type attack.  Returns true if the victim died.
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="victim"></param>
        /// <returns></returns>
        public static bool BlurAttack( CharData ch, CharData victim )
        {
            if (ch == null) return false;

            int numAttacks;
            int count;

            if( ch.IsAffected( Affect.AFFECT_CASTING ) )
            {
                return false;
            }

            if( ch.IsAffected( Affect.AFFECT_BLUR ) && MUDMath.NumberPercent() < 25 )
            {
                SocketConnection.Act( "$n&n moves with a BLUR of speed!", ch, null, null, SocketConnection.MessageTarget.room );
                SocketConnection.Act( "You move with a BLUR of speed!", ch, null, null, SocketConnection.MessageTarget.character );
                for( count = 0, numAttacks = 4; count < numAttacks && victim.CurrentPosition > Position.dead; ++count )
                {
                    SingleAttack( ch, victim, String.Empty, ObjTemplate.WearLocation.hand_one );
                }
            }
            else
            {
                Object wield;

                if( MUDMath.NumberPercent() > 10 )
                    return false;
                if( ch.IsClass(CharClass.Names.hunter) || ch.IsClass(CharClass.Names.ranger ))
                    numAttacks = 2;
                else if( ch.GetRace() == Race.RACE_OGRE || ch.GetRace() == Race.RACE_CENTAUR )
                    numAttacks = 4;
                else
                    numAttacks = 9;
                if( MUDMath.NumberPercent() < ch.GetCurrLuck() )
                    numAttacks++;
                if( MUDMath.NumberPercent() < victim.GetCurrLuck() )
                    numAttacks--;

                /* 9716 is the index number for the dagger of the wind. */
                // HORRIBLE HORRIBLE TODO: FIXME: BUG: Never hard-code item index numbers.
                if( ( wield = Object.GetEquipmentOnCharacter( ch, ObjTemplate.WearLocation.hand_one ) ) && wield.ObjIndexData.IndexNumber == 9716 )
                {
                    SocketConnection.Act( "&+c$n&+c's $p&n &+cbegins to move with the &+Wspeed&+c of a &+lstorm&+c!&n", ch, wield, null, SocketConnection.MessageTarget.room );
                    SocketConnection.Act( "Your $p&n &+cbegins to move with the &+Wspeed&+c of a &+lstorm&+c!&n", ch, wield, null, SocketConnection.MessageTarget.character );
                    for( count = 0; count < numAttacks && victim.CurrentPosition > Position.dead; ++count )
                    {
                        SingleAttack(ch, victim, String.Empty, ObjTemplate.WearLocation.hand_one);
                    }
                    return ( victim.CurrentPosition > Position.dead );
                }
                if( ( wield = Object.GetEquipmentOnCharacter( ch, ObjTemplate.WearLocation.hand_two ) ) && wield.ObjIndexData.IndexNumber == 9716 )
                {
                    SocketConnection.Act( "&+c$n&+c's $p&n &+cbegins to move with the &+Wspeed&+c of a &+lstorm&+c!&n", ch, wield, null, SocketConnection.MessageTarget.room );
                    SocketConnection.Act( "Your $p&n &+cbegins to move with the &+Wspeed&+c of a &+lstorm&+c!&n", ch, wield, null, SocketConnection.MessageTarget.character );
                    for( count = 0; count < numAttacks && victim.CurrentPosition > Position.dead; ++count )
                    {
                        SingleAttack(ch, victim, String.Empty, ObjTemplate.WearLocation.hand_two);
                    }
                    return ( victim.CurrentPosition > Position.dead );
                }
                if( ( wield = Object.GetEquipmentOnCharacter( ch, ObjTemplate.WearLocation.hand_three ) ) && wield.ObjIndexData.IndexNumber == 9716 )
                {
                    SocketConnection.Act( "&+c$n&+c's $p&n &+cbegins to move with the &+Wspeed&+c of a &+lstorm&+c!&n", ch, wield, null, SocketConnection.MessageTarget.room );
                    SocketConnection.Act( "Your $p&n &+cbegins to move with the &+Wspeed&+c of a &+lstorm&+c!&n", ch, wield, null, SocketConnection.MessageTarget.character );
                    for( count = 0; count < numAttacks && victim.CurrentPosition > Position.dead; ++count )
                    {
                        SingleAttack(ch, victim, String.Empty, ObjTemplate.WearLocation.hand_three);
                    }
                    return ( victim.CurrentPosition > Position.dead );
                }
                if( ( wield = Object.GetEquipmentOnCharacter( ch, ObjTemplate.WearLocation.hand_four ) ) && wield.ObjIndexData.IndexNumber == 9716 )
                {
                    SocketConnection.Act( "&+c$n&+c's $p&n &+cbegins to move with the &+Wspeed&+c of a &+lstorm&+c!&n", ch, wield, null, SocketConnection.MessageTarget.room );
                    SocketConnection.Act( "Your $p&n &+cbegins to move with the &+Wspeed&+c of a &+lstorm&+c!&n", ch, wield, null, SocketConnection.MessageTarget.character );
                    for( count = 0; count < numAttacks && victim.CurrentPosition > Position.dead; ++count )
                    {
                        SingleAttack(ch, victim, String.Empty, ObjTemplate.WearLocation.hand_four);
                    }
                    return ( victim.CurrentPosition > Position.dead );
                }
            }
            return false;
        }
Exemple #6
0
        /// <summary>
        /// Hit one guy once.
        ///
        /// Hitroll is now done on a 200-sided die rather than a 20-sided die
        /// This allows for more dynamic modifiers to hitroll.
        /// i.e. a couple extra points of strength and whatnot _may_ make the
        /// difference between a hit and a miss rather than incrementing something
        /// every 10-20 points of an ability we can modify it every 1-2 points.
        /// </summary>
        /// <param name="ch">attacker</param>
        /// <param name="victim">person being attacked</param>
        /// <param name="skill">damage type being used (skill)</param>
        /// <param name="weapon">wear location of weapon (usually primary or secondary hand)</param>
        /// <returns>true if victim is killed, otherwise false</returns>
        public static bool SingleAttack(CharData ch, CharData victim, string skill, ObjTemplate.WearLocation weapon)
        {
            string text;
            int dam;
            int chance;

            /*
            * Can't beat a dead char!
            * Guard against weird room-leavings.
            */
            if( victim.CurrentPosition == Position.dead || victim.Hitpoints < -10 )
            {
                text = String.Format("SingleAttack: ch {0} fighting dead victim {1}.", ch.Name, victim.Name );
                Log.Error( text, 0 );
                ch.Fighting = null;
                if( ch.CurrentPosition == Position.fighting )
                    ch.CurrentPosition = Position.standing;
                return true;
            }
            if( ch.InRoom != victim.InRoom )
            {
                text = String.Format("SingleAttack: ch {0} not with victim {1}.", ch.Name, victim.Name );
                Log.Error( text, 0 );
                ch.Fighting = null;
                if( ch.CurrentPosition == Position.fighting )
                    ch.CurrentPosition = Position.standing;
                return false;
            }

            /* No casting/being para'd and hitting at the same time. */
            if ((ch.IsAffected(Affect.AFFECT_CASTING)) || ch.IsAffected(Affect.AFFECT_MINOR_PARA)
                    || ch.IsAffected(Affect.AFFECT_HOLD))
            {
                return false;
            }

            // Inertial barrier will prevent some attacks.  At the following levels a person
            // affected by inertial barrier will be able to avoid this percentage of attacks:
            // 1 = 7%  5 = 10%  10 = 13%  20 = 20%  30 = 27%  40 = 33%  50 = 39%  51 = 40%
            if (victim.IsAffected(Affect.AFFECT_INERTIAL_BARRIER) && MUDMath.NumberPercent() > (victim.Level * 2 / 3 + 7))
                return false;

            // Keep in mind that CheckRiposte returns a boolean.
            if (skill != "kick" && skill != "backstab" && skill != "circle" && CheckRiposte( ch, victim ) )
            {
                SingleAttack( victim, ch, String.Empty, ObjTemplate.WearLocation.hand_one );
                return false;
            }
            if (CheckParry(ch, victim) && skill != "backstab" && skill != "circle")
                return false;
            if (CheckShieldBlock(ch, victim) && skill != "backstab" && skill != "circle")
                return false;
            if (CheckDodge(ch, victim) && skill != "backstab" && skill != "circle")
                return false;

            /*
            * Figure out the type of damage message if we don't have an associated attack skill.
            */
            Object wield = Object.GetEquipmentOnCharacter( ch, weapon );
            if (String.IsNullOrEmpty(skill))
            {
                skill = "barehanded fighting";
                if( wield && wield.ItemType == ObjTemplate.ObjectType.weapon )
                    skill = AttackType.Table[wield.Values[3]].SkillName;
            }

            /*
            * Weapon proficiencies.
            */
            string weaponGsn = "barehanded fighting";
            AttackType.DamageType damType = AttackType.DamageType.bludgeon;
            if( wield && wield.ItemType == ObjTemplate.ObjectType.weapon )
            {
                if( wield.Values[ 3 ] >= 0 && wield.Values[ 3 ] < AttackType.Table.Length )
                {
                    weaponGsn = (AttackType.Table[wield.Values[3]].SkillName);
                    damType = AttackType.Table[ wield.Values[ 3 ] ].DamageInflicted;
                }
                else
                {
                    text = String.Format( "SingleAttack: bad weapon damage type {0} caused by {1} ({2}).",
                              skill, wield.Name, wield.ObjIndexData ?
                              wield.ObjIndexData.IndexNumber : -1 );
                    Log.Error( text, 0 );
                    wield.Values[ 3 ] = 0;
                }
            }

            /*
            * Calculate to-hit-armor-class-0 versus armor.
            */
            int hitroll00 = ch.CharacterClass.HitrollLevel0;
            int hitroll40 = ch.CharacterClass.HitrollLevel40;

            /* Weapon-specific hitroll and damroll */

            int hitroll = MUDMath.Interpolate( ch.Level, hitroll00, hitroll40 )
                          - ( ch.GetHitroll( weapon ) * 3 );
            int victimAC = Math.Max( -100, victim.GetAC() );

            // Added blindfighting skill - Xangis
            if( !CharData.CanSee( ch, victim ) )
            {
                if( ch.CheckSkill( "blindfighting" ) )
                {
                    victimAC -= 5;
                }
                else
                {
                    victimAC -= 40;
                }
            }

            /* Weapon proficiencies *
            *
            * The twohanded version of a weapon proficiency *MUST* follow the onehanded
            * version in the definitions.  This is stupid.
            */
            if( wield && wield.ItemType == ObjTemplate.ObjectType.weapon )
            {
                if( !wield.HasFlag( ObjTemplate.ITEM_TWOHANDED ) )
                {
                    if( ch.CheckSkill( weaponGsn ))
                    {
                        victimAC += 20;
                        ch.PracticeSkill( weaponGsn );
                    }
                }
                else
                {
                    // This is not going to work.
                    if (ch.CheckSkill(weaponGsn+1))
                    {
                        victimAC += 20;
                        ch.PracticeSkill(weaponGsn);
                    }
                }
            }
            else if( ch.CheckSkill("barehanded fighting"))
            {
                victimAC += 20;
            }

            /*
            * The moment of excitement!
            */
            int diceroll = MUDMath.NumberRange( 0, 199 );

            // Give them a small bonus if they can make a successful luck check.
            if( MUDMath.NumberPercent() <= ch.GetCurrLuck() )
                diceroll += 5;

            /* Made really lucky chars get saved by the godz. */
            if( diceroll == 0 || ( diceroll <= 196 && diceroll < hitroll - victimAC )
                     || ( MUDMath.NumberPercent() < victim.GetCurrLuck() / 40 ) )
            {
                /* Miss. */
                return InflictDamage(ch, victim, 0, skill, weapon, damType);
            }

            /*
            * Hit.
            * Calc damage.
            *
            * NPCs are more badass barehanded than players.  If they weren't
            * the game would be too damned easy since mobs almost never have
            * weapons.
            *
            * Increased mob damage by about 1/6
            * It was previously level/2 to level*3/2 (25-75 at 50, average 50)
            * It is now level*3/5 to level*10/6      (30-87 at 50, average 59)
            *
            * Added the + ch.level - 1 'cause mobs still not hittin' hard enough
            */
            if( ch.IsNPC() )
            {
                dam = MUDMath.NumberRange( ( ch.Level * 3 / 5 ), ( ch.Level * 14 / 8 ) )
                      + ( ch.Level - 1 );
                if (wield)
                {
                    dam += MUDMath.Dice(wield.Values[1], wield.Values[2]);
                }
                else if (ch.CheckSkill("unarmed damage"))
                {
                    dam += MUDMath.NumberRange(1, (ch.GetSkillChance("unarmed damage") / 12));
                }
            }
            else
            {
                if (wield)
                {
                    dam = MUDMath.Dice(wield.Values[1], wield.Values[2]);
                }
                else
                {
                    if (!ch.IsClass(CharClass.Names.monk))
                    {
                        dam = MUDMath.NumberRange(1, (2 + (int)ch.CurrentSize / 3));
                        if (ch.CheckSkill("unarmed damage"))
                        {
                            dam += MUDMath.NumberRange(1, (ch.GetSkillChance("unarmed damage") / 12));
                        }
                    }
                    else
                    {
                        int min;
                        // monk barehanded damage - Xangis
                        ch.PracticeSkill("unarmed damage");
                        chance = ch.GetSkillChance("unarmed damage");
                        if (chance < 13)
                        {
                            min = 1;
                        }
                        else
                        {
                            min = chance / 13;
                        }
                        // at max skill for barehanded and unarmed, a monk will get
                        // a damage of 7-38, an average of 22.5 damage per hit before
                        // modifiers.  This is slightly better than a 6d6 weapon (average of 21 dmg)
                        // this is slightly worse than a 6d7 weapon (average of 24 dmg)
                        dam = MUDMath.NumberRange(min, ((chance / 3) + min));
                    }
                }
                if( ( wield && dam > 1000 ) && ch.Level < Limits.LEVEL_AVATAR )
                {
                    text = String.Format( "SingleAttack damage range > 1000 from {0} to {1}",
                              wield.Values[ 1 ], wield.Values[ 2 ] );
                    Log.Error( text, 0 );
                }
            }

            /*
            * Played a character with an armor class of 126 (awful agility).
            * Wasn't getting pounded much at all.  Added a damage bonus applied
            * when the target's ac is worse than 100.
            *
            * This also means that someone who makes their weapon proficiency
            * check against someone with an ac of 81 or higher will also get a
            * damage bonus of 1% per ac point.
            *
            * This applies to mobs too, so if a mob has a terrible AC it will
            * get whacked harder.  I call this the "soft as a pudding" code.
            *
            * This would also make AC debuffs stronger if they can make ac worse
            * than 100.
            */
            if( victimAC > 100 )
            {
                dam += ( (victimAC - 100) * dam) / 100;
            }

            /*
            * Bonuses.
            */
            dam += ch.GetDamroll( weapon );

            /* Weapon proficiencies, players only */
            /* Up to 50% increase based on weapon skill */
            if (wield && !ch.IsNPC())
            {
                dam += dam * ch.GetSkillChance(weaponGsn) / 180;
            }

            /* Up to 33% for offense skill */
            /* This means someone that has mastered a weapon and offense
            automatically does double damage in combat */
            chance = ch.GetSkillChance("offense");
            dam += dam * chance / 270;

            /* Bad idea to get caught napping in a fight */
            if( !victim.IsAwake() )
                dam *= 2;

            /* Backstab: 2 + one per 9 levels, 7x damage at 50 */
            if (skill == "backstab")
            {
                // Cap was previously too low.  It has been raised because a merc that was previously
                // stabbing for 180 now stabs for 64.  Assassins will still be able to stab for
                // 175 and mercs for 116 with this revised cap.  Keep in mind that a sorc can easily
                // fist for 250.
                int cap = 100 + 12 * ch.Level;
                if( ch.IsClass(CharClass.Names.mercenary) || ch.IsClass(CharClass.Names.bard ))
                    cap = cap * 2 / 3;
                dam *= ( 2 + ( ch.Level / 9 ) );
                /* damage cap applied here */
                dam = Math.Min( dam, cap );
            }
            else if (skill == "circle")              /* 150% to 200% at lev. 50 */
                dam += dam / 2 + ( dam * ch.Level ) / 100;

            if( dam <= 0 )
                dam = 1;

            return InflictDamage(ch, victim, dam, skill, weapon, damType);
        }
Exemple #7
0
        /// <summary>
        /// Inflict damage from a single hit.  This could use some cleanup since it's way too unwieldy at more than 600 lines.
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="victim"></param>
        /// <param name="dam"></param>
        /// <param name="skill"></param>
        /// <param name="weapon"></param>
        /// <param name="damType"></param>
        /// <returns></returns>
        public static bool InflictDamage(CharData ch, CharData victim, int dam, string skill, ObjTemplate.WearLocation weapon, AttackType.DamageType damType)
        {
            if (ch == null || victim == null)
            {
                return false;
            }

            Object obj;
            bool critical = false;

            if( victim.CurrentPosition == Position.dead || victim.Hitpoints < -10 )
            {
                return true;
            }

            /*
            * Stop up any residual loopholes.
            */
            if( ( dam > 1276 ) && ch.Level < Limits.LEVEL_AVATAR )
            {
                string text;

                if (ch.IsNPC() && ch.Socket)
                {
                    text = String.Format("Damage: {0} from {1} by {2}: > 1276 points with {3} damage type!",
                              dam, ch.Name, ch.Socket.Original.Name, skill);
                }
                else
                {
                    text = String.Format("Damage: {0} from {1}: > 1276 points with {2} damage type!",
                              dam, ch.IsNPC() ? ch.ShortDescription : ch.Name, skill);
                }
                Log.Error( text, 0 );
                dam = 1276;
            }

            // Remove memorization and meditation bits - Xangis
            victim.BreakMeditate();
            victim.BreakMemorization();
            if (victim.IsAffected( Affect.AFFECT_MINOR_PARA))
            {
                SocketConnection.Act( "$n&n disrupts the magic preventing $N&n from moving.", ch, null, victim, SocketConnection.MessageTarget.room_vict );
                SocketConnection.Act( "You disrupt the magic preventing $N&n from moving.", ch, null, victim, SocketConnection.MessageTarget.character );
                SocketConnection.Act( "&+YYou can move again.&n", ch, null, victim, SocketConnection.MessageTarget.victim );
                victim.RemoveAffect( Affect.AFFECT_MINOR_PARA );
            }

            bool immune = false;
            if( victim != ch )
            {
                /*
                * Certain attacks are forbidden.
                * Most other attacks are returned.
                */
                victim = CheckGuarding( ch, victim );
                if( IsSafe( ch, victim ) )
                    return false;
                // is_safe could wipe out victim, as it calls procs if a boss
                // check and see that victim is still valid
                if( victim == null )
                    return true;
                Crime.CheckAttemptedMurder( ch, victim );
                if( victim.CurrentPosition > Position.stunned )
                {
                    if( !victim.Fighting )
                        SetFighting( victim, ch );
                    // Can't have prone people automatically stand
                    if( victim.CurrentPosition == Position.standing )
                        victim.CurrentPosition = Position.fighting;

                    if( !ch.Fighting )
                        SetFighting( ch, victim );

                    /*
                    * If NPC victim is following, ch might attack victim's master.
                    * No charm check here because charm would be dispelled from
                    * tanking mobile when combat ensues thus ensuring PC charmer is
                    * not harmed.
                    * Check for IsSameGroup wont work as following mobile is not
                    * always grouped with PC charmer
                    *
                    * Added a check for whether ch has switch skill.  If not,
                    * much lower chancing of retargetting
                    */
                    if( ch.IsNPC()
                            && victim.IsNPC()
                            && victim.Master
                            && victim.Master.InRoom == ch.InRoom
                            && MUDMath.NumberBits( 2 ) == 0 )
                    {
                        StartGrudge( ch, victim.Master, false );
                    }
                }

                /*
                * More charm stuff.
                */
                if( victim.Master == ch )
                {
                    StopFighting( victim, true );
                }

                ch.BreakInvisibility();

                /*
                * Hunting stuff...
                */
                if( dam != 0 && victim.IsNPC() )
                {
                    /* StartGrudge is combined StartHating and StartHunting */
                    StartGrudge( victim, ch, false );
                }

                /*
                * Damage modifiers.
                */

                // Critical hits for double damage
                // Average of 5% for those that have average luck
                // Gnomes could concievably have 10%
                if( MUDMath.NumberPercent() < ( 2 + ( ch.GetCurrLuck() / 18 ) ) && dam > 0 )
                {
                    ch.SendText( "&+WYou score a CRITICAL HIT!&n\r\n" );
                    dam *= 2;
                    critical = true;
                }

                if( victim.IsAffected( Affect.AFFECT_SANCTUARY ) )
                    dam /= 2;

                if( victim.IsAffected( Affect.AFFECT_PROTECT_EVIL ) && ch.IsEvil() )
                    dam -= dam / 8;
                else if( victim.IsAffected( Affect.AFFECT_PROTECT_GOOD ) && ch.IsGood() )
                    dam -= dam / 8;

                // Check stoneskin.  People not affected by a stoneskin affect
                // cannot lose their stoneskin for any reason.  This should mean
                // that mobs will keep their stoneskin and players should always
                // have a chance to lose it, since no player should ever be
                // setbit stoneskin.
                //
                // The bool value of found is used so that we can have them
                // take full damage when their stoneskin shatters, but get the
                // damage reduction if they are either a mob or their stoneskin
                // wears off that round.
                //
                /* Yeah, yeah.. so maybe backstabs shouldn't be aff'd. */
                // Actually they should be affected, but they should have a much
                // higher chance of getting through (say 30-70%).
                //
                // Critical hits will now go through stoneskin
                // automatically
                if (!critical && victim.IsAffected( Affect.AFFECT_STONESKIN) &&
                        ( skill != "backstab" || MUDMath.NumberPercent() < ( 25 + ch.Level ) ) )
                {
                    bool found = false;
                    for (int i = (victim.Affected.Count - 1); i >= 0; i--)
                    {
                        if( victim.Affected[i].HasBitvector( Affect.AFFECT_STONESKIN ) )
                        {
                            // Small chance of shattering the stoneskin on a good hit.
                            // Reduced chance by about 20%
                            if( dam >= 25 && MUDMath.NumberPercent() <= ( dam / 12 ) )
                            {
                                victim.SendText( "&+LYour stoneskin is shattered by the massive blow!&n\r\n" );
                                SocketConnection.Act( "$n&n's massive blow shatters $N&n's stoneskin!", ch, null, victim, SocketConnection.MessageTarget.everyone_but_victim );
                                SocketConnection.Act( "Your massive blow shatters $N&n's stoneskin!", ch, null, victim, SocketConnection.MessageTarget.character );
                                victim.RemoveAffect(victim.Affected[i]);
                                found = true;
                            }
                            else if( dam > 0 ) // Added check for actual damage
                            {
                                for( int j = 0; j < victim.Affected[i].Modifiers.Count; j++ )
                                {
                                    victim.Affected[i].Modifiers[j].Amount--;
                                    if (victim.Affected[i].Modifiers[j].Amount < 1)
                                    {
                                        victim.RemoveAffect(victim.Affected[i]);
                                        victim.SendText("&+LYou feel your skin soften and return to normal.&n\r\n");
                                    }
                                    dam /= 15;
                                    found = true;
                                }
                            }
                        }
                    }
                    // This means they're Affect.AFFECT_STONESKIN as an innate/permenant.
                    // We will still allow it to shatter, but it will refresh itself
                    // upon a mob update.  Because of this, we make it easier to shatter.
                    // No damage reduction when it shatters.
                    if( !found )
                    {
                        if( dam >= 8 && MUDMath.NumberPercent() <= ( dam / 8 ) )
                        {
                            victim.SendText( "&+LYour stoneskin is shattered by the massive blow!&n\r\n" );
                            SocketConnection.Act( "$n&n's massive blow shatters $N&n's stoneskin!", ch, null, victim, SocketConnection.MessageTarget.everyone_but_victim );
                            SocketConnection.Act( "Your massive blow shatters $N&n's stoneskin!", ch, null, victim, SocketConnection.MessageTarget.character );
                            victim.RemoveAffect( Affect.AFFECT_STONESKIN );
                        }
                        else
                        {
                            dam = dam / 15 != 0 ? dam / 15 : 1;
                        }
                    }

                }

                if( dam < 0 )
                    dam = 0;

                /*
                * Check for disarm, trip, parry, dodge and shield block.
                */
                if (skill != "barehanded fighting" || skill == "kick")
                {
                    // Trip and disarm removed because those should be handled
                    // by each individual mob's special function.
                    if( ch.IsNPC()
                            && ch.HasInnate( Race.RACE_WEAPON_WIELD )
                            && MUDMath.NumberPercent() < Math.Min( 25, Math.Max( 10, ch.Level ) )
                            && !victim.IsNPC() )
                        UseMagicalItem( ch );
                }
            }

            switch( victim.CheckRIS( damType ) )
            {
                case Race.ResistanceType.resistant:
                    dam -= dam / 3;
                    break;
                case Race.ResistanceType.immune:
                    immune = true;
                    dam = 0;
                    break;
                case Race.ResistanceType.susceptible:
                    dam += dam / 2;
                    break;
                case Race.ResistanceType.vulnerable:
                    dam *= 2;
                    break;
                default:
                    break;
            }

            if( ( damType == AttackType.DamageType.wind || damType == AttackType.DamageType.gas || damType == AttackType.DamageType.asphyxiation )
                    && victim.IsAffected(Affect.AFFECT_DENY_AIR))
            {
                if( MUDMath.NumberPercent() < 50 )
                {
                    ch.SendText( "&+CYou deny the damage.&n\r\n" );
                    immune = true;
                    dam = 0;
                }
                else
                    dam -= dam / 5;
            }
            if (damType == AttackType.DamageType.fire && victim.IsAffected( Affect.AFFECT_DENY_FIRE))
            {
                if( MUDMath.NumberPercent() < 50 )
                {
                    ch.SendText( "&+rYou deny the damage.&n\r\n" );
                    immune = true;
                    dam = 0;
                }
                else
                    dam -= dam / 5;
            }
            if( ( damType == AttackType.DamageType.earth || damType == AttackType.DamageType.crushing )
                    && victim.IsAffected( Affect.AFFECT_DENY_EARTH))
            {
                if( MUDMath.NumberPercent() < 50 )
                {
                    ch.SendText( "&+yYou deny the damage.&n\r\n" );
                    immune = true;
                    dam = 0;
                }
                else
                    dam -= dam / 5;
            }
            if( ( damType == AttackType.DamageType.water || damType == AttackType.DamageType.acid || damType == AttackType.DamageType.drowning )
                    && victim.IsAffected( Affect.AFFECT_DENY_WATER))
            {
                if( MUDMath.NumberPercent() < 50 )
                {
                    ch.SendText( "&+bYou deny the damage.&n\r\n" );
                    immune = true;
                    dam = 0;
                }
                else
                    dam -= dam / 5;
            }

            // Check for protection spells that give 25% damage reduction - Xangis
            if (damType == AttackType.DamageType.fire && victim.IsAffected( Affect.AFFECT_PROTECT_FIRE))
                dam = ( dam * 3 ) / 4;
            else if (damType == AttackType.DamageType.cold && victim.IsAffected( Affect.AFFECT_PROTECT_COLD))
                dam = ( dam * 3 ) / 4;
            else if (damType == AttackType.DamageType.acid && victim.IsAffected( Affect.AFFECT_PROTECT_ACID))
                dam = ( dam * 3 ) / 4;
            else if (damType == AttackType.DamageType.gas && victim.IsAffected( Affect.AFFECT_PROTECT_GAS))
                dam = ( dam * 3 ) / 4;
            else if (damType == AttackType.DamageType.electricity && victim.IsAffected( Affect.AFFECT_PROTECT_LIGHTNING))
                dam = ( dam * 3 ) / 4;

            // Barkskin protects from 8% of slash and 12% of pierce damage.
            if (victim.IsAffected( Affect.AFFECT_BARKSKIN))
            {
                if (skill == "1h slashing" || skill == "2h slashing")
                    dam = dam * 11 / 12;
                else if (skill == "1h piercing" || skill == "2h piercing")
                    dam = dam * 7 / 8;
            }

            // Check for vampiric touch for anti-paladins and vampires
            if( weapon == ObjTemplate.WearLocation.hand_one || weapon == ObjTemplate.WearLocation.hand_two || weapon == ObjTemplate.WearLocation.hand_three || weapon == ObjTemplate.WearLocation.hand_four )
            {
                if( ( ( ch.IsClass(CharClass.Names.antipaladin) || ch.GetRace() == Race.RACE_VAMPIRE )
                        && skill == "barehanded fighting" && !Object.GetEquipmentOnCharacter(ch, weapon)) || (ch.IsAffected( Affect.AFFECT_VAMP_TOUCH)
                             && ( !( obj = Object.GetEquipmentOnCharacter( ch, weapon ) ) || obj.HasAffect( Affect.AFFECT_VAMP_TOUCH ) ) ) )
                {
                    ch.Hitpoints += dam / 3;
                    if( ch.Hitpoints > ( ch.GetMaxHit() + 50 + ch.Level * 5 ) )
                    {
                        ch.Hitpoints = ch.GetMaxHit() + 50 + ch.Level * 5;
                    }
                }
            }

            /* PC to PC damage quartered.
            *  NPC to PC damage divided by 3.
            */
            if( dam > 0 && !victim.IsNPC() && victim != ch )
            {
                if( !ch.IsNPC() )
                    dam /= 4;
                else
                    dam /= 3;
            }

            /*
            * Just a check for anything that is excessive damage
            * Send a log message, keeping the imms on their toes
            * Changed this from 300 to 250 'cause hitters get more than one
            *  attack/round and w/haste that's 1000 possible in the time one fist
            *  goes off.  That's more than the fist might do and it has to be
            *  memmed.
            */
            if (dam > 250 && skill != "backstab" )
            {
                string buf4;
                if (!string.IsNullOrEmpty(skill))
                {
                    buf4 = String.Format("Excessive damage: {0} attacking {1} for {2}, skill = {3}({4}).",
                              ch.Name, victim.Name, dam, Skill.SkillList[skill].DamageText, skill);
                }
                else
                {
                    buf4 = String.Format("Excessive damage: {0} attacking {1} for {2}, unknown damage type.",
                              ch.Name, victim.Name, dam);
                }
                Log.Trace( buf4 );
            }

            /*
            * We moved DamageMessage out of the victim != ch if above
            * so self damage would show.  Other valid type_undefined
            * damage is ok to avoid like mortally wounded damage
            */
            if (!String.IsNullOrEmpty(skill))
            {
                SendDamageMessage(ch, victim, dam, skill, weapon, immune);
            }

            victim.Hitpoints -= dam;

            /* Check for HOLY_SACRFICE and BATTLE_ECSTASY */
            if( dam > 0 && victim != ch )
            {
                CharData groupChar;
                if (victim.IsAffected( Affect.AFFECT_HOLY_SACRIFICE) && victim.GroupLeader)
                {
                    for( groupChar = victim.GroupLeader; groupChar; groupChar = groupChar.NextInGroup )
                    {
                        if( groupChar == victim || groupChar.InRoom != ch.InRoom )
                            continue;
                        groupChar.Hitpoints += dam / 5;
                        if (groupChar.Hitpoints > groupChar.GetMaxHit() + 50 + groupChar.Level * 5)
                        {
                            groupChar.Hitpoints = groupChar.GetMaxHit() + 50 + groupChar.Level * 5;
                        }
                    } //end for loop
                } //end if holy sac
                if( ch.GroupLeader != null )
                {
                    for( groupChar = ch.GroupLeader; groupChar != null; groupChar = groupChar.NextInGroup )
                    {
                        if( groupChar == victim || groupChar.InRoom != ch.InRoom )
                            continue;
                        if( groupChar.IsAffected( Affect.AFFECT_BATTLE_ECSTASY ) )
                        {
                            groupChar.Hitpoints += dam / 20;
                            if( groupChar.Hitpoints > groupChar.GetMaxHit() + 50 + groupChar.Level * 5 )
                                groupChar.Hitpoints = groupChar.GetMaxHit() + 50 + groupChar.Level * 5;
                        } // end if battle ecstasy
                    } //end for loop
                } //end if grouped
            } //end if

            // Make sure if they got an instant kill roll that the victim dies.
            if (skill == "instant kill")
            {
                if( victim.GetRace() != Race.RACE_DEVIL
                        && victim.GetRace() != Race.RACE_DEMON
                        && victim.GetRace() != Race.RACE_GOD )
                    victim.Hitpoints = -20;
            }

            /* Added damage exp! */
            // chance added because people level faster and faster as they get higher level...
            // to be worked out when exp is redone.
            // you can now only get damage exp on mobs that con easy or better
            // and there's only a 25% chance per hit of you evern being eligible for damage exp.
            if( MUDMath.NumberPercent() < 25 && victim.Level >= ( ch.Level - 3 ) )
                ch.GainExperience( Math.Max( 1, dam / 20 ) );

            if( !victim.IsNPC()
                    && victim.Level >= Limits.LEVEL_AVATAR
                    && victim.Hitpoints < 1 )
                victim.Hitpoints = 1;

            /*
            * Magic shields that retaliate
            *
            * Apparently two people with the same sort of shield do not
            * take damage from each other
            */
            if( ( dam > 1 ) && victim != ch )
            {
                if( victim.IsAffected( Affect.AFFECT_FIRESHIELD )
                        && !ch.IsAffected( Affect.AFFECT_FIRESHIELD ) )
                    InflictSpellDamage( victim, ch, dam / 2, "fireshield", AttackType.DamageType.fire );

                if (victim.IsAffected( Affect.AFFECT_COLDSHIELD)
                        && !ch.IsAffected(Affect.AFFECT_COLDSHIELD))
                    InflictSpellDamage( victim, ch, dam / 2, "coldshield", AttackType.DamageType.cold );

                if (victim.IsAffected(Affect.AFFECT_SHOCK_SHIELD)
                        && !ch.IsAffected(Affect.AFFECT_SHOCK_SHIELD))
                    InflictSpellDamage( victim, ch, dam / 2, "shockshield", AttackType.DamageType.electricity );

                /* Soulshield is a complex one.  If the attacker and victim are of
                * opposite alignment, the shield retaliates with 1/2 damage just like
                * any other shield.  If the victim is neutral and the attacker is
                * not, the shield retaliates with 1/4 damage.  If the victim is good
                * or evil and the attacker is neutral, the shield retaliates with
                * 1/8 damage.  If the attacker and victim are of same alignment,
                * the shield does nothing.
                */
                if (victim.IsAffected(Affect.AFFECT_SOULSHIELD)
                        && !ch.IsAffected(Affect.AFFECT_SOULSHIELD))
                {
                    if( victim.IsEvil() && ch.IsGood() )
                        InflictSpellDamage(victim, ch, dam / 2, "soulshield", AttackType.DamageType.harm);
                    else if( victim.IsGood() && ch.IsEvil() )
                        InflictSpellDamage(victim, ch, dam / 2, "soulshield", AttackType.DamageType.harm);
                    else if( victim.IsNeutral() && ( ch.IsEvil() || ch.IsGood() ) )
                        InflictSpellDamage(victim, ch, dam / 4, "soulshield", AttackType.DamageType.harm);
                    else if( victim.IsGood() && ch.IsNeutral() )
                        InflictSpellDamage(victim, ch, dam / 8, "soulshield", AttackType.DamageType.harm);
                    else if( victim.IsEvil() && ch.IsNeutral() )
                        InflictSpellDamage(victim, ch, dam / 8, "soulshield", AttackType.DamageType.harm);
                }
            }

            if (victim.IsAffected( Affect.AFFECT_BERZERK ) && victim.CurrentPosition <= Position.stunned )
                victim.RemoveAffect(Affect.AFFECT_BERZERK);

            if (dam > 0 && skill != "barehanded fighting"
                    && IsWieldingPoisoned( ch, weapon )
                    && !Magic.SpellSavingThrow( ch.Level, victim, AttackType.DamageType.poison ) )
            {
                InflictPoison( "poison_weapon", ch.Level, IsWieldingPoisoned( ch, weapon ), ch, victim );
                SocketConnection.Act( "$n&n suffers from the &+Gpoison&n inflicted upon $m.", victim, null, null, SocketConnection.MessageTarget.room, true );
                Object.StripAffect( Object.GetEquipmentOnCharacter( ch, weapon ), Affect.AffectType.skill, "poison weapon" );
            }

            victim.UpdatePosition();

            switch( victim.CurrentPosition )
            {
                case Position.mortally_wounded:
                    victim.SendText(
                        "&+LYou are &+Rmo&n&+rr&+Rt&n&+ral&+Rl&n&+ry&+L wounded, and will die soon, if not aided.&n\r\n" );
                    SocketConnection.Act( "$n&+L is &+Rmo&n&+rr&+Rt&n&+ral&+Rl&n&+ry&+L wounded, and will die soon, if not aided.&n",
                         victim, null, null, SocketConnection.MessageTarget.room, true );
                    StopNotVicious( victim );
                    break;

                case Position.incapacitated:
                    victim.SendText(
                        "&+LYou are incapacitated and will &n&+rbl&+Re&n&+re&+Rd&+L to death, if not aided.&n\r\n" );
                    SocketConnection.Act( "$n&+L is incapacitated and will slowly &n&+rbl&+Re&n&+re&+Rd&+L to death, if not aided.&n",
                         victim, null, null, SocketConnection.MessageTarget.room, true );
                    StopNotVicious( victim );
                    break;

                case Position.stunned:
                    victim.SendText( "&+LYou are stunned, but will probably recover.&n\r\n" );
                    SocketConnection.Act( "$n&+L is stunned, but will probably recover.&n",
                         victim, null, null, SocketConnection.MessageTarget.room, true );
                    break;

                case Position.dead:
                    if( victim == ch )
                    {
                        victim.SendText( "&+LYou have been &+Rsl&n&+ra&+Ri&n&+rn&+L!&n\r\n\r\n" );
                    }
                    else
                    {
                        string buf = String.Format( "&+LYou have been &+Rsl&n&+ra&+Ri&n&+rn&+L by&n {0}&+L!&n\r\n\r\n",
                                                    ch.ShowNameTo( victim, false ) );
                        victim.SendText( buf );
                    }
                    /* Added this to stop a bug. */
                    Combat.StopFighting( victim, true );
                    SocketConnection.Act( "$n&+L is &n&+rdead&+L!&n", victim, null, null, SocketConnection.MessageTarget.room, true );
                    break;

                default:
                    if( dam > victim.GetMaxHit() / 5 )
                        victim.SendText( "That really did &+RHURT&n!\r\n" );
                    if( victim.Hitpoints < victim.GetMaxHit() / 10 )
                        victim.SendText( "You sure are &n&+rBL&+RE&n&+rE&+RDI&n&+rN&+RG&n!\r\n" );
                    break;
            }

            // Check for weapon procs
            if( ( obj = Object.GetEquipmentOnCharacter( ch, weapon ) ) && Position.dead != victim.CurrentPosition )
            {
                if( obj.SpecFun.Count > 0 )
                    obj.CheckSpecialFunction(true);
            }

            /*
            * Sleep spells and extremely wounded folks.
            */
            if( !victim.IsAwake() )      /* lets make NPC's not slaughter PC's */
            {
                if( victim.Fighting
                        && victim.Fighting.Hunting
                        && victim.Fighting.Hunting.Who == victim )
                    StopHunting( victim.Fighting );
                if( victim.Fighting
                        && !victim.IsNPC()
                        && ch.IsNPC() )
                    StopFighting( victim, true );
                else
                    StopFighting( victim, false );
            }

            /*
            * Payoff for killing things.
            */
            if( victim.CurrentPosition == Position.dead )
            {
                // Done in attempt to squelch the combat continuation bug
                StopFighting( victim, true );

                if( !victim.HasActionBit(MobTemplate.ACT_NOEXP ) || !victim.IsNPC() )
                    GroupExperienceGain( ch, victim );

                if( ch.IsNPC() )
                {
                    if( ch.Hunting )
                    {
                        if( ch.Hunting.Who == victim )
                            StopHunting( ch );
                    }
                    if( ch.IsHating(victim) )
                    {
                        ch.StopHating( victim );
                    }
                }

                if( !victim.IsNPC() )
                {
                    if( ch.IsNPC() )
                    {
                        ( (PC)victim ).MobDeaths++;
                        if( victim.IsGuild() )
                        {
                            ( (PC)victim ).GuildMembership.MonsterDeaths++;
                            ( (PC)victim ).GuildMembership.Score += CalculateDeathScore( ch, victim );
                        }
                        ( (PC)victim ).Score += CalculateDeathScore( ch, victim );

                    }
                    else
                    {
                        ( (PC)ch ).PlayerKills++;
                        ( (PC)victim ).PlayerDeaths++;

                        ( (PC)victim ).Score += CalculateDeathScore( ch, victim );
                        ( (PC)ch ).Score += CalculateKillScore( ch, victim );

                        if( ch.IsGuild()
                                && victim.IsGuild()
                                && ( (PC)ch ).GuildMembership != ( (PC)victim ).GuildMembership )
                        {
                            ( (PC)ch ).GuildMembership.PlayerKills++;
                            ( (PC)victim ).GuildMembership.PlayerDeaths++;
                            ( (PC)ch ).GuildMembership.Score += CalculateKillScore( ch, victim );
                            ( (PC)victim ).GuildMembership.Score += CalculateDeathScore( ch, victim );
                        }
                    }

                    string logBuf = String.Format( "{0}&n killed by {1}&n at {2}",
                              victim.Name, ( ch.IsNPC() ? ch.ShortDescription : ch.Name ),
                              victim.InRoom.IndexNumber );
                    Log.Trace( logBuf );
                    ImmortalChat.SendImmortalChat( ch, ImmortalChat.IMMTALK_DEATHS, Limits.LEVEL_AVATAR, logBuf );

                    /*
                    * Dying penalty:
                    *
                    * At level 1 you lose 12.5% of a level.
                    * At level 50 you lose 25% of a level.
                    */
                    // Made it so people level 5 and under lose no exp from death.
                    if( ch.Level > 5 )
                        victim.GainExperience( ( 0 - ( ( ( 50 + victim.Level ) * ExperienceTable.Table[ victim.Level ].LevelExperience ) / 400 ) ) );
                    if( victim.Level < 2 && victim.ExperiencePoints < 1 )
                        victim.ExperiencePoints = 1;

                }
                else
                {
                    if( !ch.IsNPC() )
                    {
                        ( (PC)ch ).MobKills++;
                        if( ch.IsGuild() )
                        {
                            ( (PC)ch ).GuildMembership.MonsterKills++;
                            ( (PC)ch ).GuildMembership.Score += CalculateKillScore( ch, victim );
                        }
                        ( (PC)ch ).Score += CalculateKillScore( ch, victim );
                    }
                }
                KillingBlow( ch, victim );

                return true;
            }

            if( victim == ch )
            {
                return false;
            }

            /*
            * Wimp out?
            */
            if( victim.IsNPC() && dam > 0 )
            {
                if( ( victim.HasActionBit(MobTemplate.ACT_WIMPY ) && MUDMath.NumberBits( 1 ) == 0
                        && victim.Hitpoints < victim.GetMaxHit() / 5 )
                        || (victim.IsAffected( Affect.AFFECT_CHARM) && victim.Master
                             && victim.Master.InRoom != victim.InRoom ) )
                {
                    StartFearing( victim, ch );
                    StopHunting( victim );
                    CommandType.Interpret(victim, "flee");
                }
            }

            if( !victim.IsNPC() && victim.Hitpoints > 0 && victim.Hitpoints <= victim.Wimpy )
            {
                CommandType.Interpret(victim, "flee");
            }

            return false;
        }