public static bool LuaIsPassage(RoomTemplate room, int direction)
        {
            if (room == null)
            {
                throw new LuaException("Room cannot be null");
            }

            return(room.GetExit(direction) != null);
        }
        public static bool LuaIsExitLocked(RoomTemplate room, int direction)
        {
            if (room == null)
            {
                throw new LuaException("Room cannot be null");
            }

            var exit = room.GetExit(direction);

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

            return(!exit.Flags.IsSet(ExitFlags.Locked));
        }
Пример #3
0
        private static bool CheckAndFireDoor(CharacterInstance ch, ObjectInstance obj)
        {
            if (obj.Values.Flags.IsSet(TriggerFlags.Door))
            {
                RoomTemplate room = RepositoryManager.Instance.ROOMS.Get(obj.Values.Val1) ?? obj.InRoom;
                if (room == null)
                {
                    throw new InvalidDataException(string.Format("Room {0} was null", obj.Values.Val1));
                }

                var exitDir = GetExitDirectionAndText(obj);

                var exit = room.GetExit(exitDir.Item1);
                if (exit == null)
                {
                    CreateNewPassage(ch, obj, exitDir.Item1);
                    return(true);
                }

                if (obj.Values.Flags.IsSet(TriggerFlags.Unlock) && exit.Flags.IsSet(ExitFlags.Locked))
                {
                    UnlockExit(ch, exit, exitDir.Item2);
                    return(true);
                }

                if (obj.Values.Flags.IsSet(TriggerFlags.Lock) && !exit.Flags.IsSet(ExitFlags.Locked))
                {
                    LockExit(ch, exit, exitDir.Item2);
                    return(true);
                }

                if (obj.Values.Flags.IsSet(TriggerFlags.Open) && exit.Flags.IsSet(ExitFlags.Closed))
                {
                    OpenExit(ch, obj, exit, exitDir.Item2);
                    return(true);
                }

                if (obj.Values.Flags.IsSet(TriggerFlags.Close) && !exit.Flags.IsSet(ExitFlags.Closed))
                {
                    CloseExit(ch, obj, exit, exitDir.Item2);
                    return(true);
                }
            }
            return(false);
        }
Пример #4
0
        private static bool MakeFleeAttempt(CharacterInstance ch, RoomTemplate wasIn)
        {
            var door = db.number_door();
            var exit = wasIn.GetExit(door);

            if (exit?.GetDestination() == null || exit.Flags.IsSet(ExitFlags.NoFlee) || exit.Flags.IsSet(ExitFlags.Closed) || !ch.IsAffected(AffectedByTypes.PassDoor) || (ch.IsNpc() && exit.GetDestination().Flags.IsSet(RoomFlags.NoMob)))
            {
                return(false);
            }

            var sneak = RepositoryManager.Instance.GetEntity <SkillData>("sneak");

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

            ch.StripAffects((int)sneak.ID);
            ch.AffectedBy.RemoveBit((int)AffectedByTypes.Sneak);

            if (ch.CurrentMount?.CurrentFighting != null)
            {
                ch.CurrentMount.StopFighting(true);
            }
            Move.move_char(ch, exit, 0);

            var nowIn = ch.CurrentRoom;

            if (nowIn == wasIn)
            {
                return(false);
            }

            ch.CurrentRoom = wasIn;
            comm.act(ATTypes.AT_FLEE, "$n flees head over heels!", ch, null, null, ToTypes.Room);

            ch.CurrentRoom = nowIn;
            comm.act(ATTypes.AT_FLEE, "$n glances around for signs of pursuit.", ch, null, null, ToTypes.Room);

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

                comm.act(ATTypes.AT_FLEE, "You flee head over heels from combat!", pch, null, null, ToTypes.Character);

                if (pch.Level < LevelConstants.AvatarLevel)
                {
                    LoseExperience(pch);
                }

                if (wf != null)
                {
                    if (pch.PlayerData.CurrentDeity != null)
                    {
                        var ratio = 1.GetNumberThatIsBetween(wf.Level / pch.Level, LevelConstants.MaxLevel);
                        if (wf.CurrentRace == pch.PlayerData.CurrentDeity.NPCRace)
                        {
                            pch.AdjustFavor(DeityFieldTypes.FleeNPCRace, ratio);
                        }
                        else if (wf.CurrentRace == pch.PlayerData.CurrentDeity.NPCFoe)
                        {
                            pch.AdjustFavor(DeityFieldTypes.FleeNPCFoe, ratio);
                        }
                        else
                        {
                            pch.AdjustFavor(DeityFieldTypes.Flee, ratio);
                        }
                    }
                }
            }

            ch.StopFighting(true);
            return(true);
        }