Пример #1
0
        public static bool Execute(MobileInstance ch, IManager dbManager)
        {
            var handler = Program.Kernel.Get <ISpecFunHandler>();

            ch.SummonIfHating();

            if (!ch.IsInCombatPosition())
            {
                return(false);
            }

            var victim =
                ch.CurrentRoom.Persons.Where(v => v != ch)
                .FirstOrDefault(vch => SmaugRandom.Bits(2) == 0 && vch.GetMyTarget() == ch);

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

            var skill = handler.PickSpell(SpellLevelLookupTable, ch.Level);

            if (skill?.SpellFunction == null)
            {
                return(false);
            }

            skill.SpellFunction.Value.DynamicInvoke(skill.ID, ch.Level, ch, victim);
            return(true);
        }
Пример #2
0
        private static ReturnTypes ConditionFull(CharacterInstance ch, int conditionValue)
        {
            ReturnTypes retcode = ReturnTypes.None;

            if (ch.Level < LevelConstants.AvatarLevel && ch.CurrentClass != ClassTypes.Vampire)
            {
                color.set_char_color(ATTypes.AT_HUNGRY, ch);
                DescriptorAttribute attrib = ConditionTypes.Full.GetAttribute <DescriptorAttribute>();

                color.send_to_char(attrib.Messages[conditionValue * 2], ch);
                if (conditionValue < 2)
                {
                    comm.act(ATTypes.AT_HUNGRY, attrib.Messages[(conditionValue * 2) + 1], ch, null, null, ToTypes.Room);
                    if (conditionValue == 0)
                    {
                        if (!ch.IsPKill() || SmaugRandom.Bits(1) == 0)
                        {
                            ch.WorsenMentalState(1);
                        }
                        retcode = ch.CauseDamageTo(ch, 2, (int)SkillNumberTypes.Undefined);
                    }
                    else
                    {
                        if (SmaugRandom.Bits(1) == 0)
                        {
                            ch.WorsenMentalState(1);
                        }
                    }
                }
            }

            return(retcode);
        }
Пример #3
0
        public static bool Execute(MobileInstance ch, string spellName, IManager dbManager)
        {
            if (!ch.IsInCombatPosition())
            {
                return(false);
            }

            var victim = ch.CurrentRoom.Persons.Where(v => v != ch)
                         .FirstOrDefault(vch => SmaugRandom.Bits(2) == 0 && vch.GetMyTarget() == ch);

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

            var databaseMgr = (IRepositoryManager)(dbManager ?? RepositoryManager.Instance);
            var skill       = databaseMgr.GetEntity <SkillData>(spellName);

            if (skill?.SpellFunction == null)
            {
                return(false);
            }

            skill.SpellFunction.Value.Invoke((int)skill.ID, ch.Level, ch, victim);
            return(true);
        }
Пример #4
0
 private static void DoFlee(CharacterInstance ch, CharacterInstance victim)
 {
     if ((victim.Act.IsSet((int)ActFlags.Wimpy) && SmaugRandom.Bits(1) == 0 &&
          victim.CurrentHealth < victim.MaximumHealth / 2) || (victim.IsAffected(AffectedByTypes.Charm) &&
                                                               victim.Master != null && victim.Master.CurrentRoom != victim.CurrentRoom))
     {
         var mob = (MobileInstance)victim;
         mob.StartFearing(ch);
         mob.StopHunting();
         Flee.do_flee(victim, string.Empty);
     }
 }
Пример #5
0
        public static bool Execute(MobileInstance ch, IManager dbManager)
        {
            if (!ch.IsInCombatPosition())
            {
                return(false);
            }

            var bits = SmaugRandom.Bits(3);

            return(bits == 2
                ? Dragon.Execute(ch, "lightning breath", dbManager)
                : Dragon.Execute(ch, BreathTable.ContainsKey(bits) ? BreathTable[bits] : "frost breath", dbManager));
        }
Пример #6
0
        private static int ModifyDamageForEquipment(CharacterInstance victim, int dam)
        {
            var wearLoc = GetRandomWearLocation();
            var obj     = victim.GetEquippedItem(wearLoc);

            if (obj != null && dam > obj.GetResistance() && SmaugRandom.Bits(1) == 0)
            {
                handler.set_cur_obj(obj);
                obj.CauseDamageTo();
                return(dam - 5);
            }

            return(dam + 5);
        }
Пример #7
0
        public SkillData PickSpell(Dictionary <int, SpecFunSpell> lookupTable, int characterLevel)
        {
            var minLevel  = 0;
            var spellName = string.Empty;

            while (minLevel < characterLevel)
            {
                SpecFunSpell value;
                lookupTable.TryGetValue(SmaugRandom.Bits(4), out value);

                minLevel  = value?.Level ?? lookupTable[-1].Level;
                spellName = value != null ? value.Spell : lookupTable[-1].Spell;
            }

            return(_dbManager.GetEntity <SkillData>(spellName));
        }
Пример #8
0
        public static void do_flee(CharacterInstance ch, string argument)
        {
            if (ch.GetMyTarget() == null)
            {
                if (ch.IsInCombatPosition())
                {
                    ch.CurrentPosition = ch.CurrentMount != null ? PositionTypes.Mounted : PositionTypes.Standing;
                }
                ch.SendTo("You aren't fighting anyone.");
                return;
            }

            if (CheckFunctions.CheckIfTrue(ch, ch.IsAffected(AffectedByTypes.Berserk),
                                           "Flee while berserking? You aren't thinking very clearly..."))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, ch.CurrentMovement <= 0, "You're too exhausted to flee from combat!"))
            {
                return;
            }
            if (CheckFunctions.CheckIfTrue(ch, !ch.IsNpc() && (int)ch.CurrentPosition < (int)PositionTypes.Fighting,
                                           "You can't flee in an aggressive stance..."))
            {
                return;
            }
            if (ch.IsNpc() && (int)ch.CurrentPosition <= (int)PositionTypes.Sleeping)
            {
                return;
            }

            var wasIn = ch.CurrentRoom;

            comm.act(ATTypes.AT_FLEE, "You attempt to flee from combat, but can't escape!", ch, null, null, ToTypes.Character);

            if (AttemptToFlee(ch, wasIn))
            {
                return;
            }

            if (!ch.IsNpc() && ch.Level < LevelConstants.AvatarLevel && SmaugRandom.Bits(3) == 1)
            {
                LoseExperience((PlayerInstance)ch);
            }
        }
Пример #9
0
        public static bool Execute(MobileInstance ch, IManager dbManager)
        {
            if (ch.CurrentPosition != PositionTypes.Standing)
            {
                return(false);
            }
            if (SmaugRandom.Bits(2) != 0)
            {
                return(false);
            }

            foreach (var victim in ch.CurrentRoom.Persons.Where(victim => victim != ch)
                     .Where(victim => !victim.IsNpc())
                     .Where(victim => victim.Level < LevelConstants.ImmortalLevel)
                     .Where(ch.CanSee))
            {
                if (victim.IsAwake() && SmaugRandom.Between(0, ch.Level) == 0)
                {
                    comm.act(ATTypes.AT_ACTION, "You discover $n's hands in your sack of gold!", ch, null, victim,
                             ToTypes.Victim);
                    comm.act(ATTypes.AT_ACTION, "$N discovers $n's hands in $S sack of gold!", ch, null, victim,
                             ToTypes.NotVictim);
                    return(true);
                }

                var maxgold = ch.Level * ch.Level * 1000;
                var gold    = victim.CurrentCoin *
                              SmaugRandom.Between(1, 2.GetNumberThatIsBetween(ch.Level / 4, 10)) / 100;

                ch.CurrentCoin     += 9 * gold / 10;
                victim.CurrentCoin -= gold;
                if (ch.CurrentCoin <= maxgold)
                {
                    return(true);
                }

                ch.CurrentRoom.Area.BoostEconomy(ch.CurrentCoin - maxgold / 2);
                ch.CurrentCoin = maxgold / 2;
                return(true);
            }
            return(false);
        }
Пример #10
0
 private static void DamageAndDefault(CharacterInstance victim, int dam)
 {
     if (dam > victim.MaximumHealth / 4)
     {
         comm.act(ATTypes.AT_HURT, "That really did HURT!", victim, null, null, ToTypes.Character);
         if (SmaugRandom.Bits(3) == 0)
         {
             ((PlayerInstance)victim).WorsenMentalState(1);
         }
     }
     if (victim.CurrentHealth < victim.MaximumHealth / 4)
     {
         comm.act(ATTypes.AT_HURT, "You wish that your wounds would stop BLEEDING so much!", victim, null, null,
                  ToTypes.Character);
         if (SmaugRandom.Bits(2) == 0)
         {
             ((PlayerInstance)victim).WorsenMentalState(1);
         }
     }
 }
Пример #11
0
        public static ReturnTypes spell_acid_breath(int sn, int level, CharacterInstance ch, object vo)
        {
            var victim = (CharacterInstance)vo;

            int chance;

            checked
            {
                chance = 2 * level;
            }

            if (ch.Chance(chance) && !victim.SavingThrows.CheckSaveVsBreath(level, victim))
            {
                foreach (var obj in victim.Carrying.Where(obj => SmaugRandom.Bits(2) == 0))
                {
                    switch (obj.ItemType)
                    {
                    case ItemTypes.Armor:
                        CheckDamageArmor(obj, victim);
                        break;

                    case ItemTypes.Container:
                        CheckDamageContainer(obj, victim);
                        break;
                    }
                }
            }

            var hpChange = 10.GetHighestOfTwoNumbers(ch.CurrentHealth);
            var damage   = SmaugRandom.Between(hpChange / 16 + 1, hpChange / 8);

            if (victim.SavingThrows.CheckSaveVsBreath(level, victim))
            {
                damage /= 2;
            }
            return(ch.CauseDamageTo(victim, damage, sn));
        }
Пример #12
0
        private static ReturnTypes ConditionFull(PlayerInstance ch, int conditionValue)
        {
            var retcode = ReturnTypes.None;

            if (ch.Level >= LevelConstants.AvatarLevel || ch.CurrentClass == ClassTypes.Vampire)
            {
                return(retcode);
            }

            ch.SetColor(ATTypes.AT_HUNGRY);
            var attrib = ConditionTypes.Full.GetAttribute <DescriptorAttribute>();

            ch.SendTo(attrib.Messages.ToList()[conditionValue * 2]);
            if (conditionValue >= 2)
            {
                return(retcode);
            }

            comm.act(ATTypes.AT_HUNGRY, attrib.Messages.ToList()[conditionValue * 2 + 1], ch, null, null, ToTypes.Room);
            if (conditionValue == 0)
            {
                if (!ch.IsPKill() || SmaugRandom.Bits(1) == 0)
                {
                    ch.WorsenMentalState(1);
                }
                retcode = ch.CauseDamageTo(ch, 2, (int)SkillNumberTypes.Undefined);
            }
            else
            {
                if (SmaugRandom.Bits(1) == 0)
                {
                    ch.WorsenMentalState(1);
                }
            }

            return(retcode);
        }
Пример #13
0
        public static bool Execute(MobileInstance ch, IManager dbManager)
        {
            if (!ch.IsAwake() || ch.CurrentFighting != null)
            {
                return(false);
            }

            var victim = ch.CurrentRoom.Persons.Where(vch => vch != ch)
                         .Where(ch.CanSee)
                         .FirstOrDefault(vch => SmaugRandom.Bits(1) != 0);

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

            var bits           = SmaugRandom.Bits(3);
            var actLookupValue = ActLookupTable[bits];

            comm.act(ATTypes.AT_MAGIC,
                     $"$n utters the word '{actLookupValue.Item1}'.",
                     ch, null, null, ToTypes.Room);
            return(CastSpell(ch, victim, bits, actLookupValue.Item2, dbManager));
        }
Пример #14
0
        private static void CheckNpc(MobileInstance ch, IRepositoryManager dbManager)
        {
            if ((_charCounter & 1) > 0)
            {
                return;
            }

            if (ch.Act.IsSet((int)ActFlags.Running))
            {
                if (!ch.Act.IsSet((int)ActFlags.Sentinel) &&
                    ch.CurrentPosition == PositionTypes.Standing &&
                    !ch.Act.IsSet((int)ActFlags.Mounted) &&
                    ch.CurrentFighting == null &&
                    ch.CurrentHunting != null)
                {
                    Macros.WAIT_STATE(ch, 2 * GameConstants.GetSystemValue <int>("PulseViolence"));
                    track.hunt_victim(ch);
                    return;
                }

                if (ch.SpecialFunction != null)
                {
                    if (ch.SpecialFunction.Value.Invoke(ch, dbManager))
                    {
                        return;
                    }
                    if (ch.CharDied())
                    {
                        return;
                    }
                }

                if (!ch.Act.IsSet((int)ActFlags.Sentinel) &&
                    ch.CurrentPosition == PositionTypes.Standing &&
                    !ch.Act.IsSet((int)ActFlags.Mounted) &&
                    !ch.Act.IsSet((int)ActFlags.Prototype))
                {
                    var door = SmaugRandom.Bits(4);
                    if (door >= 9)
                    {
                        return;
                    }

                    var exit = ch.CurrentRoom.GetExit(door);
                    if (exit == null)
                    {
                        return;
                    }

                    if (exit.Flags.IsSet(ExitFlags.Closed))
                    {
                        return;
                    }

                    var room = exit.GetDestination();
                    if (room == null)
                    {
                        return;
                    }

                    if (room.Flags.IsSet(RoomFlags.NoMob) || room.Flags.IsSet(RoomFlags.Death))
                    {
                        return;
                    }

                    if (ch.Act.IsSet((int)ActFlags.StayArea) && ch.CurrentRoom.Area != room.Area)
                    {
                        return;
                    }

                    Move.move_char(ch, exit, 0);
                }
            }
        }
Пример #15
0
        public static ReturnTypes move_char(CharacterInstance ch, ExitData pexit, int fall)
        {
            var    drunk    = false;
            var    nuisance = false;
            string txt;

            if (!ch.IsNpc())
            {
                var pch = (PlayerInstance)ch;

                if (ch.IsDrunk(2) && ch.CurrentPosition != PositionTypes.Shove &&
                    ch.CurrentPosition != PositionTypes.Drag)
                {
                    drunk = true;
                }

                if (pch.PlayerData.Nuisance != null && pch.PlayerData.Nuisance.Flags > 8 &&
                    ch.CurrentPosition != PositionTypes.Shove &&
                    ch.CurrentPosition != PositionTypes.Drag &&
                    SmaugRandom.D100() > pch.PlayerData.Nuisance.Flags * pch.PlayerData.Nuisance.Power)
                {
                    nuisance = true;
                }
            }

            int      door;
            ExitData exit = null;

            // Nuisance flag, makes them walk in random directions 50% of the time
            if ((nuisance || drunk) && fall == 0)
            {
                door = db.number_door();
                exit = ch.CurrentRoom.GetExit(door);
            }

#if DEBUG
            if (exit != null)
            {
                LogManager.Instance.Info("{0} to door {1}", ch.Name, pexit.Direction);
            }
#endif

            if (ch.IsNpc() && ch.Act.IsSet((int)ActFlags.Mounted))
            {
                return(ReturnTypes.None);
            }

            var          inRoom   = ch.CurrentRoom;
            var          fromRoom = inRoom;
            RoomTemplate toRoom   = null;

            if (exit?.Destination == null)
            {
                if (drunk && ch.CurrentPosition != PositionTypes.Mounted &&
                    ch.CurrentRoom.SectorType != SectorTypes.ShallowWater &&
                    ch.CurrentRoom.SectorType != SectorTypes.DeepWater &&
                    ch.CurrentRoom.SectorType != SectorTypes.Underwater &&
                    ch.CurrentRoom.SectorType != SectorTypes.OceanFloor)
                {
                    switch (SmaugRandom.Bits(4))
                    {
                    default:
                        comm.act(ATTypes.AT_ACTION, "You drunkenly stumble into some obstacle.", ch, null, null, ToTypes.Character);
                        comm.act(ATTypes.AT_ACTION, "$n drunkenly stumbles into a nearby obstacle.", ch, null, null, ToTypes.Room);
                        break;

                    case 3:
                        comm.act(ATTypes.AT_ACTION, "In your drunken stupor you trip over your own feet and tumble to the ground.", ch, null, null, ToTypes.Character);
                        comm.act(ATTypes.AT_ACTION, "$n stumbles drunkenly, trips and tumbles to the ground.", ch, null, null, ToTypes.Room);
                        ch.CurrentPosition = PositionTypes.Resting;
                        break;

                    case 4:
                        comm.act(ATTypes.AT_SOCIAL, "You utter a string of slurred obscenities.", ch, null, null, ToTypes.Character);
                        comm.act(ATTypes.AT_ACTION, "Something blurry and immovable has intercepted you as you stagger along.", ch, null, null, ToTypes.Character);
                        comm.act(ATTypes.AT_HURT, "Oh geez... THAT really hurt.  Everything slowly goes dark and numb...", ch, null, null, ToTypes.Character);
                        comm.act(ATTypes.AT_ACTION, "$n drunkenly staggers into something.", ch, null, null, ToTypes.Room);
                        comm.act(ATTypes.AT_SOCIAL, "$n utters a string of slurred obscenities: @*&^%@*&!", ch, null, null, ToTypes.Room);
                        comm.act(ATTypes.AT_ACTION, "$n topples to the ground with a thud.", ch, null, null, ToTypes.Room);
                        ch.CurrentPosition = PositionTypes.Incapacitated;
                        break;
                    }
                }
                else if (nuisance)
                {
                    comm.act(ATTypes.AT_ACTION, "You stare around trying to remember where you where going.", ch, null, null, ToTypes.Character);
                }
                else if (drunk)
                {
                    comm.act(ATTypes.AT_ACTION, "You stare around trying to make sense of things through your drunken stupor.", ch, null, null, ToTypes.Character);
                }
                else
                {
                    ch.SendTo("Alas, you cannot go that way.\r\n");
                }
                return(ReturnTypes.None);
            }

            door = (int)exit.Direction;
            var distance = exit.Distance;

            // Exit is only a "window", there is no way to travel in that direction unless it's a door with a window in it
            if (CheckFunctions.CheckIfTrue(ch, exit.Flags.IsSet(ExitFlags.Window) && !exit.Flags.IsSet(ExitFlags.IsDoor),
                                           "Alas, you cannot go that way."))
            {
                return(ReturnTypes.None);
            }

            if (ch.IsNpc())
            {
                if (exit.Flags.IsSet(ExitFlags.Portal))
                {
                    comm.act(ATTypes.AT_PLAIN, "Mobs can't use portals.", ch, null, null, ToTypes.Character);
                    return(ReturnTypes.None);
                }

                if (exit.Flags.IsSet(ExitFlags.NoMob) || toRoom.Flags.IsSet(RoomFlags.NoMob))
                {
                    comm.act(ATTypes.AT_PLAIN, "Mobs can't enter there.", ch, null, null, ToTypes.Character);
                    return(ReturnTypes.None);
                }
            }

            if (exit.Flags.IsSet(ExitFlags.Closed) && (!ch.IsAffected(AffectedByTypes.PassDoor) || exit.Flags.IsSet(ExitFlags.NoPassDoor)))
            {
                if (!exit.Flags.IsSet(ExitFlags.Secret) && !exit.Flags.IsSet(ExitFlags.Dig))
                {
                    if (drunk)
                    {
                        comm.act(ATTypes.AT_PLAIN, "$n runs into the $d in $s drunken state.", ch, null, null,
                                 ToTypes.Room);
                        comm.act(ATTypes.AT_PLAIN, "You run into the $d in your drunken state.", ch, null, null,
                                 ToTypes.Character);
                    }
                    else
                    {
                        comm.act(ATTypes.AT_PLAIN, "The $d is closed.", ch, null, exit.Keywords,
                                 ToTypes.Character);
                    }
                }
                else
                {
                    ch.SendTo(drunk
                        ? "You stagger around in your drunken state.\r\n"
                        : "Alas, you cannot go that way.\r\n");
                }

                return(ReturnTypes.None);
            }

            // Crazy virtual room idea, created upon demand.
            if (distance > 1)
            {
                toRoom = act_move.generate_exit(inRoom, exit);
                if (toRoom == null)
                {
                    ch.SendTo("Alas, you cannot go that way.");
                }
            }

            if (CheckFunctions.CheckIfTrue(ch, fall == 0 && ch.IsAffected(AffectedByTypes.Charm) &&
                                           ch.Master != null && inRoom == ch.Master.CurrentRoom, "What?  And leave your beloved master?"))
            {
                return(ReturnTypes.None);
            }

            if (CheckFunctions.CheckIfTrue(ch, toRoom.IsPrivate(), "That room is private right now."))
            {
                return(ReturnTypes.None);
            }

            if (CheckFunctions.CheckIfNotNullObject(ch, toRoom.IsDoNotDisturb(ch),
                                                    "That room is \"do not disturb\" right now."))
            {
                return(ReturnTypes.None);
            }

            if (!ch.IsImmortal() && !ch.IsNpc() &&
                ch.CurrentRoom.Area != toRoom.Area)
            {
                if (ch.Level < toRoom.Area.LowHardRange)
                {
                    ch.SetColor(ATTypes.AT_TELL);
                    switch (toRoom.Area.LowHardRange - ch.Level)
                    {
                    case 1:
                        ch.SendTo("A voice in your mind says, 'You are nearly ready to go that way...'");
                        break;

                    case 2:
                        ch.SendTo("A voice in your mind says, 'Soon you shall be ready to travel down this path... soon.'");
                        break;

                    case 3:
                        ch.SendTo("A voice in your mind says, 'You are not ready to go down that path... yet.'");
                        break;

                    default:
                        ch.SendTo("A voice in your mind says, 'You are not ready to go down that path.'");
                        break;
                    }

                    return(ReturnTypes.None);
                }
                if (ch.Level > toRoom.Area.HighHardRange)
                {
                    ch.SetColor(ATTypes.AT_TELL);
                    ch.SendTo("A voice in your mind says, 'There is nothing more for you down that path.'");
                    return(ReturnTypes.None);
                }
            }

            if (fall == 0 && !ch.IsNpc())
            {
                int move;

                // Prevent deadlies from entering a nopkill-flagged area from a non-flagged area,
                // but allow them to move around if already inside a nopkill area.
                if (toRoom.Area.Flags.IsSet(AreaFlags.NoPlayerVsPlayer) && !ch.CurrentRoom.Area.Flags.IsSet(AreaFlags.NoPlayerVsPlayer) &&
                    ch.IsPKill() && !ch.IsImmortal())
                {
                    ch.SetColor(ATTypes.AT_MAGIC);
                    ch.SendTo("\r\nA godly force forbids deadly characters from entering that area...");
                    return(ReturnTypes.None);
                }

                if (inRoom.SectorType == SectorTypes.Air ||
                    toRoom.SectorType == SectorTypes.Air ||
                    exit.Flags.IsSet(ExitFlags.Fly))
                {
                    if (CheckFunctions.CheckIfTrue(ch,
                                                   ch.CurrentMount != null && !ch.CurrentMount.IsAffected(AffectedByTypes.Flying),
                                                   "Your mount can't fly."))
                    {
                        return(ReturnTypes.None);
                    }
                    if (CheckFunctions.CheckIfTrue(ch, ch.CurrentMount == null && !ch.IsAffected(AffectedByTypes.Flying),
                                                   "You'd need to fly to go there."))
                    {
                        return(ReturnTypes.None);
                    }
                }

                if (inRoom.SectorType == SectorTypes.DeepWater || toRoom.SectorType == SectorTypes.DeepWater)
                {
                    if ((ch.CurrentMount != null && !ch.CurrentMount.IsFloating()) || !ch.IsFloating())
                    {
                        // Look for a boat. We can use the boat obj for a more detailed description.
                        var boat = ch.GetObjectOfType(ItemTypes.Boat);
                        if (CheckFunctions.CheckIfNullObject(ch, boat,
                                                             ch.CurrentMount != null ? "Your mount would drown!" : "You'd need a boat to go there."))
                        {
                            return(ReturnTypes.None);
                        }

                        txt = drunk ? "paddles unevenly" : "paddles";
                    }
                }

                if (exit.Flags.IsSet(ExitFlags.Climb))
                {
                    var found = false;
                    if (ch.CurrentMount != null && ch.CurrentMount.IsAffected(AffectedByTypes.Flying))
                    {
                        found = true;
                    }
                    else if (ch.IsAffected(AffectedByTypes.Flying))
                    {
                        found = true;
                    }

                    if (!found && ch.CurrentMount == null)
                    {
                        // TODO Climbing
                    }

                    if (CheckFunctions.CheckIfTrue(ch, !found, "You can't climb."))
                    {
                        return(ReturnTypes.None);
                    }
                }

                if (ch.CurrentMount != null)
                {
                    if (PositionMoveMessage.ContainsKey(ch.CurrentMount.CurrentPosition))
                    {
                        ch.SendTo(PositionMoveMessage[ch.CurrentMount.CurrentPosition]);
                        return(ReturnTypes.None);
                    }

                    if (!ch.CurrentMount.IsFloating())
                    {
                    }    // TODO
                }
            }

            return(ReturnTypes.None);
        }
Пример #16
0
        public static void ProcessUpdate(this MobileInstance ch, IRepositoryManager dbManager)
        {
            handler.set_cur_char(ch);

            if (ch.CurrentRoom == null || ch.IsAffected(AffectedByTypes.Charm) ||
                ch.IsAffected(AffectedByTypes.Paralysis))
            {
                return;
            }

            if (ch.MobIndex.ID == VnumConstants.MOB_VNUM_ANIMATED_CORPSE &&
                !ch.IsAffected(AffectedByTypes.Charm))
            {
                if (ch.CurrentRoom.Persons.Any())
                {
                    comm.act(ATTypes.AT_MAGIC, "$n returns to the dust from whence $e came.", ch, null, null,
                             ToTypes.Room);
                }

                if (ch.IsNpc())
                {
                    ch.Extract(true);
                }
                return;
            }

            if (!ch.Act.IsSet((int)ActFlags.Running) && !ch.Act.IsSet((int)ActFlags.Sentinel) && ch.CurrentFighting == null &&
                ch.CurrentHunting == null)
            {
                Macros.WAIT_STATE(ch, 2 * GameConstants.GetSystemValue <int>("PulseViolence"));
                track.hunt_victim(ch);
                return;
            }

            if (!ch.Act.IsSet((int)ActFlags.Running) && ch.SpecialFunction != null)
            {
                if (ch.SpecialFunction.Value.Invoke(ch, dbManager))
                {
                    return;
                }
                if (ch.CharDied())
                {
                    return;
                }
            }

            if (ch.MobIndex.HasProg(MudProgTypes.Script))
            {
                MudProgHandler.ExecuteMobileProg(MudProgTypes.Script, ch);
                return;
            }

            if (ch != handler.CurrentCharacter)
            {
                // TODO BUG: ch does not equal CurrentCharacter after spec_fun");
                return;
            }

            if (ch.CurrentPosition != PositionTypes.Standing)
            {
                return;
            }

            if (ch.Act.IsSet((int)ActFlags.Mounted))
            {
                if (ch.Act.IsSet((int)ActFlags.Aggressive) || ch.Act.IsSet((int)ActFlags.MetaAggr))
                {
                    Emote.do_emote(ch, "snarls and growls.");
                }
                return;
            }

            if (ch.CurrentRoom.Flags.IsSet(RoomFlags.Safe) &&
                (ch.Act.IsSet((int)ActFlags.Aggressive) || ch.Act.IsSet((int)ActFlags.MetaAggr)))
            {
                Emote.do_emote(ch, "glares around and snarls.");
            }

            if (ch.CurrentRoom.Area.NumberOfPlayers > 0)
            {
                MudProgHandler.ExecuteMobileProg(MudProgTypes.Random, ch);
                if (ch.CharDied())
                {
                    return;
                }
                if ((int)ch.CurrentPosition < (int)PositionTypes.Standing)
                {
                    return;
                }
            }

            MudProgHandler.ExecuteMobileProg(MudProgTypes.Hour, ch);
            if (ch.CharDied())
            {
                return;
            }

            MudProgHandler.ExecuteRoomProg(MudProgTypes.Hour, ch);
            if (ch.CharDied())
            {
                return;
            }

            if ((int)ch.CurrentPosition < (int)PositionTypes.Standing)
            {
                return;
            }

            if (ch.Act.IsSet((int)ActFlags.Scavenger) && ch.CurrentRoom.Contents.Any() && SmaugRandom.Bits(2) == 0)
            {
                Scavenge(ch);
            }

            if (!ch.Act.IsSet((int)ActFlags.Running) &&
                !ch.Act.IsSet((int)ActFlags.Sentinel) &&
                !ch.Act.IsSet((int)ActFlags.Prototype) &&
                !ch.Act.IsSet((int)ActFlags.StayArea))
            {
                var door = SmaugRandom.Bits(5);
                if (door > 9)
                {
                    return;
                }

                var exit = ch.CurrentRoom.GetExit(door);
                if (exit == null)
                {
                    return;
                }

                if (exit.Flags.IsSet(ExitFlags.Window) || exit.Flags.IsSet(ExitFlags.Closed))
                {
                    return;
                }

                var room = exit.GetDestination();
                if (room == null)
                {
                    return;
                }

                if (room.Flags.IsSet(RoomFlags.NoMob) || room.Flags.IsSet(RoomFlags.Death))
                {
                    return;
                }

                if (room.Area != ch.CurrentRoom.Area)
                {
                    return;
                }

                var retcode = Move.move_char(ch, exit, 0);
                if (ch.CharDied())
                {
                    return;
                }
                if (retcode != ReturnTypes.None || ch.Act.IsSet((int)ActFlags.Sentinel) ||
                    (int)ch.CurrentPosition < (int)PositionTypes.Standing)
                {
                    return;
                }
            }

            if (ch.CurrentHealth < ch.MaximumHealth / 2)
            {
                var door = SmaugRandom.Bits(4);
                if (door > 9)
                {
                    return;
                }

                var exit = ch.CurrentRoom.GetExit(door);
                if (exit == null)
                {
                    return;
                }

                if (exit.Flags.IsSet(ExitFlags.Window) || exit.Flags.IsSet(ExitFlags.Closed))
                {
                    return;
                }

                var room = exit.GetDestination();
                if (room == null)
                {
                    return;
                }

                if (room.Flags.IsSet(RoomFlags.NoMob) || room.Flags.IsSet(RoomFlags.Death))
                {
                    return;
                }

                var found = false;
                foreach (var rch in ch.CurrentRoom.Persons)
                {
                    if (ch.IsFearing(rch))
                    {
                        var buf = string.Empty;
                        switch (SmaugRandom.Bits(2))
                        {
                        case 0:
                            buf = $"Get away from me, {rch.Name}!";
                            break;

                        case 1:
                            buf = $"Leave me be, {rch.Name}!";
                            break;

                        case 2:
                            buf = $"{rch.Name} is trying to kill me!  Help!";
                            break;

                        case 3:
                            buf = $"Someone save me from {rch.Name}!";
                            break;
                        }

                        Yell.do_yell(ch, buf);
                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    Move.move_char(ch, exit, 0);
                }
            }
        }
Пример #17
0
        public static ReturnTypes ObjectCastSpell(this CharacterInstance ch, int sn, int level,
                                                  CharacterInstance victim = null, ObjectInstance obj = null)
        {
            var skill = RepositoryManager.Instance.GetEntity <SkillData>(sn);

            if (skill?.SpellFunction == null)
            {
                return(ReturnTypes.Error);
            }

            if (ch.CurrentRoom.Flags.IsSet(RoomFlags.NoMagic) ||
                (ch.CurrentRoom.Flags.IsSet(RoomFlags.Safe) &&
                 skill.Target == TargetTypes.OffensiveCharacter))
            {
                ch.SetColor(ATTypes.AT_MAGIC);
                ch.SendTo("Nothing seems to happen...");
                return(ReturnTypes.None);
            }

            // Reduces the number of level 5 players using level 40 scrolls in battle
            var levelDiff = ch.Level - level;

            if ((skill.Target == TargetTypes.OffensiveCharacter || SmaugRandom.Bits(7) == 1) &&
                skill.Type != SkillTypes.Herb &&
                ch.Chance(95 + levelDiff))
            {
                switch (SmaugRandom.Bits(2))
                {
                case 0:
                case 2:
                    ch.FailedCast(skill, victim);
                    break;

                case 1:
                case 3:
                    comm.act(ATTypes.AT_MAGIC, "The $t spell backfires!", ch, skill.Name, victim, ToTypes.Character);
                    if (victim != null)
                    {
                        comm.act(ATTypes.AT_MAGIC, "$n's $t spell backfires!", ch, skill.Name, victim,
                                 ToTypes.Victim);
                    }
                    comm.act(ATTypes.AT_MAGIC, "$n's $t spell backfires!", ch, skill.Name, victim, ToTypes.Room);
                    return(ch.CauseDamageTo(ch, SmaugRandom.Between(1, level), Program.TYPE_UNDEFINED));
                }

                return(ReturnTypes.None);
            }

            object vo;

            switch (skill.Target)
            {
            default:
                LogManager.Instance.Bug("Bad target for sn {0}", sn);
                return(ReturnTypes.Error);

            case TargetTypes.Ignore:
                vo = null;
                if (victim != null)
                {
                    Cast.TargetName = victim.Name;
                }
                else if (obj != null)
                {
                    Cast.TargetName = obj.Name;
                }
                break;

            case TargetTypes.OffensiveCharacter:
                if (victim != ch)
                {
                    if (victim == null)
                    {
                        victim = ch.GetMyTarget();
                    }
                    if (CheckFunctions.CheckIfTrue(ch, victim == null || (!victim.IsNpc() && !victim.IsInArena()),
                                                   "You can't do that."))
                    {
                        return(ReturnTypes.None);
                    }
                }
                if (ch != victim && fight.is_safe(ch, victim, true))
                {
                    return(ReturnTypes.None);
                }
                vo = victim;
                break;

            case TargetTypes.DefensiveCharacter:
                if (victim == null)
                {
                    victim = ch;
                }
                vo = victim;
                if (CheckFunctions.CheckIfTrueCasting(
                        skill.Type != SkillTypes.Herb && victim.Immunity.IsSet(ResistanceTypes.Magic),
                        skill, ch, CastingFunctionType.Immune, victim))
                {
                    return(ReturnTypes.None);
                }
                break;

            case TargetTypes.Self:
                vo = ch;
                if (CheckFunctions.CheckIfTrueCasting(
                        skill.Type != SkillTypes.Herb && ch.Immunity.IsSet(ResistanceTypes.Magic),
                        skill, ch, CastingFunctionType.Immune, victim))
                {
                    return(ReturnTypes.None);
                }
                break;

            case TargetTypes.InventoryObject:
                if (CheckFunctions.CheckIfNullObject(ch, obj, "You can't do that!"))
                {
                    return(ReturnTypes.None);
                }

                vo = obj;
                break;
            }

            var start   = DateTime.Now;
            var retcode = skill.SpellFunction.Value.Invoke(sn, level, ch, vo);

            skill.UseHistory.Use(ch, DateTime.Now.Subtract(start));

            if (retcode == ReturnTypes.SpellFailed)
            {
                retcode = ReturnTypes.None;
            }

            if (retcode == ReturnTypes.CharacterDied || retcode == ReturnTypes.Error)
            {
                return(retcode);
            }

            if (ch.CharDied())
            {
                return(ReturnTypes.CharacterDied);
            }

            if (skill.Target == TargetTypes.OffensiveCharacter &&
                victim != ch &&
                !victim.CharDied())
            {
                foreach (
                    var vch in
                    ch.CurrentRoom.Persons.Where(
                        vch => victim == vch && vch.CurrentFighting == null && vch.Master != ch))
                {
                    retcode = fight.multi_hit(vch, ch, Program.TYPE_UNDEFINED);
                    break;
                }
            }

            return(retcode);
        }
Пример #18
0
        public static void CheckDisarm(CharacterInstance ch, CharacterInstance victim, IRepositoryManager dbManager = null)
        {
            var obj = victim.GetEquippedItem(WearLocations.Wield);

            if (CheckFunctions.CheckIfNullObject(ch, obj))
            {
                return;
            }

            var tempObj = victim.GetEquippedItem(WearLocations.DualWield);

            if (tempObj != null && SmaugRandom.Bits(1) == 0)
            {
                obj = tempObj;
            }

            var skill = (dbManager ?? RepositoryManager.Instance).GetEntity <SkillData>("disarm");

            if (skill == null)
            {
                throw new ObjectNotFoundException("Skill 'disarm' not found");
            }

            if (!ch.IsNpc() && ch.GetEquippedItem(WearLocations.Wield) == null && SmaugRandom.Bits(1) == 0)
            {
                skill.LearnFromFailure(ch);
                return;
            }

            if (!ch.IsNpc() && !ch.CanSee(obj) && SmaugRandom.Bits(1) == 0)
            {
                skill.LearnFromFailure(ch);
                return;
            }

            if (Grip.CheckGrip(ch, victim) && !ch.IsNpc())
            {
                skill.LearnFromFailure(ch);
                return;
            }

            comm.act(ATTypes.AT_SKILL, "$n DISARMS you!", ch, null, victim, ToTypes.Victim);
            comm.act(ATTypes.AT_SKILL, "You disarm $N!", ch, null, victim, ToTypes.Character);
            comm.act(ATTypes.AT_SKILL, "$n disarms $N!", ch, null, victim, ToTypes.Room);

            skill.LearnFromFailure(ch);

            obj.RemoveFrom();

            if (!victim.IsNpc() && victim.CanPKill() && !obj.ExtraFlags.IsSet((int)ItemExtraFlags.Loyal))
            {
                obj.MagicFlags.SetBit(ItemMagicFlags.PKDisarmed);
                obj.Value.ToList()[5] = victim.Level;
            }

            if (victim.IsNpc() || (obj.ExtraFlags.IsSet((int)ItemExtraFlags.Loyal) && victim.IsPKill() && !ch.IsNpc()))
            {
                obj.AddTo(victim);
            }
            else
            {
                victim.CurrentRoom.AddTo(obj);
            }
        }
Пример #19
0
        public static void show_list_to_char(List <ObjectInstance> list, PlayerInstance ch, bool fShort, bool fShowNothing)
        {
            if (ch.Descriptor == null)
            {
                return;
            }

            if (list == null)
            {
                if (fShowNothing)
                {
                    if (ch.Act.IsSet((int)PlayerFlags.Combine))
                    {
                        ch.SendTo("     ");
                    }
                    ch.SetColor(ATTypes.AT_OBJECT);
                    ch.SendTo("Nothing.");
                }
                return;
            }

            var count = list.Count;

            var ms = (ch.MentalState > 0 ? ch.MentalState : 1) *
                     (ch.PlayerData.GetConditionValue(ConditionTypes.Drunk) > 0
                         ? ch.PlayerData.GetConditionValue(ConditionTypes.Drunk) / 12
                         : 1);

            int offcount;

            if (Math.Abs(ms) > 40)
            {
                offcount = (count * ms / 100).GetNumberThatIsBetween(-count, count * 2);
                if (offcount < 0)
                {
                    offcount += SmaugRandom.Between(0, Math.Abs(offcount));
                }
                else if (offcount > 0)
                {
                    offcount -= SmaugRandom.Between(0, offcount);
                }
            }
            else
            {
                offcount = 0;
            }

            if (count + offcount <= 0)
            {
                if (fShowNothing)
                {
                    if (ch.Act.IsSet((int)PlayerFlags.Combine))
                    {
                        ch.SendTo("     ");
                    }
                    ch.SetColor(ATTypes.AT_OBJECT);
                    ch.SendTo("Nothing.");
                }
                return;
            }

            var tmp = offcount > 0 ? offcount : 0;
            var cnt = 0;

            var size        = count + (offcount > 0 ? offcount : 0);
            var prgpstrShow = new string[size];
            var prgnShow    = new int[size];
            var pitShow     = new int[size];
            var nShow       = 0;

            foreach (var obj in list)
            {
                if (offcount < 0 && ++cnt > count + offcount)
                {
                    break;
                }

                if (tmp > 0 && SmaugRandom.Bits(1) == 0)
                {
                    prgpstrShow[nShow] = hallucinated_object(ms, fShort);
                    prgnShow[nShow]    = 1;
                    pitShow[nShow]     = SmaugRandom.Between((int)ItemTypes.Light, (int)ItemTypes.Book);
                    nShow++;
                    --tmp;
                }

                if (obj.WearLocation == WearLocations.None &&
                    ch.CanSee(obj) &&
                    (obj.ItemType != ItemTypes.Trap ||
                     ch.IsAffected(AffectedByTypes.DetectInvisibility)))
                {
                    string pstrShow = obj.GetFormattedDescription(ch, fShort);
                    bool   fCombine = false;

                    if (ch.Act.IsSet((int)PlayerFlags.Combine))
                    {
                        for (var i = nShow - 1; i >= 0; i--)
                        {
                            if (prgpstrShow[i] == pstrShow)
                            {
                                prgnShow[i] += obj.Count;
                                fCombine     = true;
                                break;
                            }
                        }
                    }

                    pitShow[nShow] = (int)obj.ItemType;

                    if (!fCombine)
                    {
                        prgpstrShow[nShow] = pstrShow;
                        prgnShow[nShow]    = obj.Count;
                        nShow++;
                    }
                }
            }

            if (tmp > 0)
            {
                for (var i = 0; i < tmp; i++)
                {
                    prgpstrShow[nShow] = hallucinated_object(ms, fShort);
                    prgnShow[nShow]    = 1;
                    pitShow[nShow]     = SmaugRandom.Between((int)ItemTypes.Light, (int)ItemTypes.Book);
                    nShow++;
                }
            }

            for (var i = 0; i < nShow; i++)
            {
                SetCharacterColorByItemType(ch, pitShow, i);

                if (fShowNothing)
                {
                    ch.SendTo("     ");
                }
                ch.SendTo(prgpstrShow[i]);

                if (prgnShow[i] != 1)
                {
                    ch.Printf(" (%d)", prgnShow[i]);
                }

                ch.SendTo("\r\n");
            }

            if (fShowNothing && nShow == 0)
            {
                if (ch.Act.IsSet((int)PlayerFlags.Combine))
                {
                    ch.SendTo("     ");
                }
                ch.SetColor(ATTypes.AT_OBJECT);
                ch.SendTo("Nothing.");
            }
        }