Example #1
0
 public static ExitData GetReverse(this ExitData exit)
 {
     if (exit.Reverse == 0)
     {
         return(null);
     }
     return(exit.GetDestination() == null ? null : exit.GetDestination().GetExit((int)exit.Reverse));
 }
Example #2
0
        private static void CloseExit(CharacterInstance ch, ObjectInstance obj, ExitData exit, string txt)
        {
            exit.Flags = exit.Flags.SetBit(ExitFlags.Closed);

            var room = RepositoryManager.Instance.ROOMS.Get(obj.Value.ToList()[1]);

            if (room == null)
            {
                throw new InvalidDataException($"Room {obj.Value.ToList()[1]} was null");
            }

            foreach (var rch in room.Persons)
            {
                comm.act(ATTypes.AT_ACTION, "The $d closes.", rch, null, exit.Keywords, ToTypes.Character);
            }

            var reverseExit = exit.GetReverse();

            if (reverseExit != null && reverseExit.Destination == exit.Destination)
            {
                reverseExit.Flags = reverseExit.Flags.SetBit(ExitFlags.Closed);

                var destRoom = exit.GetDestination(RepositoryManager.Instance);
                foreach (var rch in destRoom.Persons)
                {
                    comm.act(ATTypes.AT_ACTION, "The $d closes.", rch, null, reverseExit.Keywords, ToTypes.Character);
                }
            }

            // TODO Check room for traps
        }
Example #3
0
        public static bool valid_edge(ExitData exit)
        {
            return(exit.Destination != null
#if !TRACK_THROUGH_DOORS
                   && !exit.Flags.IsSet((int)ExitFlags.Closed)
#endif
                   && !IS_MARKED(exit.GetDestination()));
        }
Example #4
0
        private static void OpenDoor(CharacterInstance ch, ExitData exit, string arg)
        {
            if (exit.Flags.IsSet(ExitFlags.Secret) && !exit.Keywords.IsAnyEqual(arg))
            {
                ch.Printf("You see no %s here.", arg);
                return;
            }

            if (CheckFunctions.CheckIfTrue(ch, !exit.Flags.IsSet(ExitFlags.IsDoor) ||
                                           exit.Flags.IsSet(ExitFlags.Dig), "You can't do that."))
            {
                return;
            }

            if (CheckFunctions.CheckIfNotSet(ch, exit.Flags, ExitFlags.Closed, "It's already open."))
            {
                return;
            }

            if (CheckFunctions.CheckIfTrue(ch, exit.Flags.IsSet(ExitFlags.Locked) &&
                                           exit.Flags.IsSet(ExitFlags.Bolted), "The bolt is locked."))
            {
                return;
            }

            if (CheckFunctions.CheckIfSet(ch, exit.Flags, ExitFlags.Bolted, "It's bolted."))
            {
                return;
            }
            if (CheckFunctions.CheckIfSet(ch, exit.Flags, ExitFlags.Locked, "It's locked."))
            {
                return;
            }

            if (!exit.Flags.IsSet(ExitFlags.Secret) || exit.Keywords.IsAnyEqual(arg))
            {
                comm.act(ATTypes.AT_ACTION, "$n opens the $d.", ch, null, exit.Keywords, ToTypes.Room);
                comm.act(ATTypes.AT_ACTION, "You open the $d.", ch, null, exit.Keywords, ToTypes.Character);

                var reverseExit = exit.GetReverse();
                if (reverseExit != null)
                {
                    var room = exit.GetDestination(RepositoryManager.Instance);
                    foreach (var vch in room.Persons)
                    {
                        comm.act(ATTypes.AT_ACTION, "The $d opens.", vch, null, reverseExit.Keywords, ToTypes.Character);
                    }
                }

                exit.RemoveFlagFromSelfAndReverseExit(ExitFlags.Closed);

                // TODO Check for traps
            }
        }
Example #5
0
        private static void BashSomething(CharacterInstance actor, ExitData exit, SkillData skill, string arg)
        {
            if (CheckFunctions.CheckIfSet(actor, exit.Flags, ExitFlags.Closed, "Calm down. It is already open."))
            {
                return;
            }

            Macros.WAIT_STATE(actor, skill.Rounds);

            var keyword = exit.Flags.IsSet(ExitFlags.Secret) ? "wall" : exit.Keywords;

            var chance = !actor.IsNpc()
                ? Macros.LEARNED(actor, (int)skill.ID) / 2
                : 90;

            if (exit.Flags.IsSet(ExitFlags.Locked))
            {
                chance /= 3;
            }

            if (exit.Flags.IsSet(ExitFlags.BashProof) ||
                actor.CurrentMovement < 15 ||
                SmaugRandom.D100() >= chance + 4 * (actor.GetCurrentStrength() - 19))
            {
                Bash(actor, skill, arg);
                return;
            }

            BashExit(exit);

            comm.act(ATTypes.AT_SKILL, "Crash! You bashed open the $d!", actor, null, keyword, ToTypes.Character);
            comm.act(ATTypes.AT_SKILL, "$n bashes open the $d!", actor, null, keyword, ToTypes.Room);
            skill.LearnFromSuccess(actor);

            var reverseExit = exit.GetReverse();

            BashExit(reverseExit);

            var destination = exit.GetDestination(RepositoryManager.Instance);

            foreach (var ch in destination.Persons)
            {
                comm.act(ATTypes.AT_SKILL, "The $d crashes open!", ch, null, reverseExit.Keywords, ToTypes.Character);
            }

            actor.CauseDamageTo(actor, actor.CurrentHealth / 20, (int)skill.ID);
        }
Example #6
0
        private static void ThrowScrapAtDirection(CharacterInstance ch, ObjectInstance trash, ExitData exit)
        {
            trash.Split();
            comm.act(ATTypes.AT_ACTION, "$n growls and throws $p $T.", ch, trash, exit.Direction.GetName(),
                     ToTypes.Room);
            trash.RemoveFrom();

            var oldRoom = ch.CurrentRoom;
            var room    = exit.GetDestination(RepositoryManager.Instance);

            room.AddTo(trash);
            ch.CurrentRoom.RemoveFrom(ch);
            room.AddTo(ch);
            comm.act(ATTypes.AT_CYAN, "$p thrown by $n lands in the room.", ch, trash, ch, ToTypes.Room);
            ch.CurrentRoom.RemoveFrom(ch);
            oldRoom.AddTo(ch);
        }
Example #7
0
        private static void CloseDoor(CharacterInstance ch, ExitData exit, string firstArg)
        {
            if (exit.Flags.IsSet(ExitFlags.Secret) &&
                !exit.Keywords.IsAnyEqual(firstArg))
            {
                ch.Printf("You see no %s here.", firstArg);
                return;
            }

            if (CheckFunctions.CheckIfNotSet(ch, exit.Flags, ExitFlags.IsDoor, "You can't do that."))
            {
                return;
            }
            if (CheckFunctions.CheckIfNotSet(ch, exit.Flags, ExitFlags.Closed, "It's already closed."))
            {
                return;
            }

            comm.act(ATTypes.AT_ACTION, "$n closes the $d.", ch, null, exit.Keywords, ToTypes.Room);
            comm.act(ATTypes.AT_ACTION, "You close the $d.", ch, null, exit.Keywords, ToTypes.Character);

            var reverseExit = exit.GetReverse();

            if (reverseExit != null)
            {
                reverseExit.Flags.SetBit(ExitFlags.Closed);
                foreach (var vch in exit.GetDestination(RepositoryManager.Instance).Persons)
                {
                    comm.act(ATTypes.AT_ACTION, "The $d closes.", vch, null, reverseExit.Keywords, ToTypes.Character);
                }
            }

            exit.SetFlagOnSelfAndReverseExit(ExitFlags.Closed);

            // TODO Check room for traps
        }
Example #8
0
        public static ReturnTypes pullcheck(CharacterInstance ch, int pulse)
        {
            if (ch.CurrentRoom == null)
            {
                LogManager.Instance.Bug("{0} not in a room?!?", ch.Name);
                return(ReturnTypes.None);
            }

            ExitData xit = null;

            foreach (var exit in ch.CurrentRoom.Exits)
            {
                if (exit.Pull > 0 && exit.Destination != null &&
                    (xit == null || Math.Abs(exit.Pull) > Math.Abs(xit.Pull)))
                {
                    xit = exit;
                }
            }

            if (xit == null)
            {
                return(ReturnTypes.None);
            }

            var pull     = xit.Pull;
            var pullfact = (20 - Math.Abs(pull) / 5).GetNumberThatIsBetween(1, 20);

            if (pulse % pullfact != 0)
            {
                foreach (var exit in ch.CurrentRoom.Exits
                         .Where(exit => exit.Pull > 0 && exit.Destination != null))
                {
                    pull     = exit.Pull;
                    pullfact = (20 - Math.Abs(pull) / 5).GetNumberThatIsBetween(1, 20);
                    if (pulse % pullfact == 0)
                    {
                        break;
                    }
                }
            }

            if (xit.Flags.IsSet(ExitFlags.Closed))
            {
                return(ReturnTypes.None);
            }

            if (xit.GetDestination().Tunnel > 0)
            {
                var count = ch.CurrentMount != null ? 1 : 0;

                if (xit.GetDestination().Persons.Any(ctmp => ++ count >= xit.GetDestination().Tunnel))
                {
                    return(ReturnTypes.None);
                }
            }

            if (pull < 0)
            {
                xit = ch.CurrentRoom.GetExit(LookupConstants.rev_dir[(int)xit.Direction]);
                if (xit == null)
                {
                    return(ReturnTypes.None);
                }
            }

            var dtxt = rev_exit(xit.Direction);

            // First determine if the player should be moved or not Check various flags, spells,
            // the players position and strength vs. the pull, etc... any kind of checks you like.
            var move = false;

            switch (xit.PullType)
            {
            case DirectionPullTypes.Current:
            case DirectionPullTypes.Whirlpool:
                if (xit.PullType == DirectionPullTypes.Current)
                {
                    break;
                }

                switch (ch.CurrentRoom.SectorType)
                {
                // allow whirlpool to be in any sector type
                case SectorTypes.ShallowWater:
                case SectorTypes.DeepWater:
                    if ((ch.CurrentMount != null &&
                         !ch.CurrentMount.IsFloating()) ||
                        (ch.CurrentMount == null &&
                         !ch.IsFloating()))
                    {
                        move = true;
                    }
                    break;

                case SectorTypes.Underwater:
                case SectorTypes.OceanFloor:
                    move = true;
                    break;
                }
                break;

            case DirectionPullTypes.Geyser:
            case DirectionPullTypes.Wave:
                move = true;
                break;

            case DirectionPullTypes.Wind:
            case DirectionPullTypes.Storm:
                // if not flying, check weight, position and strength
                move = true;
                break;

            case DirectionPullTypes.ColdWind:
                // if not flying, check weight, position and strength
                // also check for damage due to bitter cold
                move = true;
                break;

            case DirectionPullTypes.HotAir:
                // if not flying, check weight, position and strength
                // also check for damage due to heat
                move = true;
                break;

            case DirectionPullTypes.Breeze:
                move = false;
                break;

            case DirectionPullTypes.Earthquake:
            case DirectionPullTypes.Sinkhole:
            case DirectionPullTypes.Quicksand:
            case DirectionPullTypes.Landslide:
            case DirectionPullTypes.Slip:
            case DirectionPullTypes.Lava:
                if ((ch.CurrentMount != null && !ch.CurrentMount.IsFloating()) ||
                    (ch.CurrentMount == null && !ch.IsFloating()))
                {
                    move = true;
                }
                break;

            case DirectionPullTypes.Undefined:
                // as if player moved in that direction him/herself
                return(Move.move_char(ch, xit, 0));

            default:
                move = true;
                break;
            }

            var showroom = xit.PullType == DirectionPullTypes.Mysterious;
            var msg      = GetPullcheckMessages(pull, xit.PullType);

            if (move)
            {
                if (!string.IsNullOrEmpty(msg.ToChar))
                {
                    comm.act(ATTypes.AT_PLAIN, msg.ToChar, ch, null,
                             LookupManager.Instance.GetLookup("DirectionNames", (int)xit.Direction), ToTypes.Character);
                    ch.SendTo("\r\n");
                }
                if (!string.IsNullOrEmpty(msg.ToRoom))
                {
                    comm.act(ATTypes.AT_PLAIN, msg.ToRoom, ch, null,
                             LookupManager.Instance.GetLookup("DirectionNames", (int)xit.Direction), ToTypes.Room);
                }

                if (!string.IsNullOrEmpty(msg.DestRoom) &&
                    xit.GetDestination().Persons.Any())
                {
                    comm.act(ATTypes.AT_PLAIN, msg.DestRoom, xit.GetDestination().Persons.First(), null, dtxt, ToTypes.Character);
                    comm.act(ATTypes.AT_PLAIN, msg.DestRoom, xit.GetDestination().Persons.First(), null, dtxt, ToTypes.Room);
                }

                if (xit.PullType == DirectionPullTypes.Slip)
                {
                    return(Move.move_char(ch, xit, 1));
                }

                ch.CurrentRoom.RemoveFrom(ch);
                xit.GetDestination().AddTo(ch);

                if (showroom)
                {
                    Look.do_look(ch, "auto");
                }

                if (ch.CurrentMount != null)
                {
                    ch.CurrentMount.CurrentRoom.RemoveFrom(ch.CurrentMount);
                    xit.GetDestination().AddTo(ch.CurrentMount);
                    if (showroom)
                    {
                        Look.do_look(ch.CurrentMount, "auto");
                    }
                }
            }

            foreach (var obj in ch.CurrentRoom.Contents)
            {
                if (obj.ExtraFlags.IsSet((int)ItemExtraFlags.Buried) ||
                    !obj.WearFlags.IsSet(ItemWearFlags.Take))
                {
                    continue;
                }

                var resistance = obj.GetWeight();
                if (obj.ExtraFlags.IsSet((int)ItemExtraFlags.Metallic))
                {
                    resistance = resistance * 6 / 5;
                }

                switch (obj.ItemType)
                {
                case ItemTypes.Scroll:
                case ItemTypes.Note:
                case ItemTypes.Trash:
                    resistance >>= 2;
                    break;

                case ItemTypes.Scraps:
                case ItemTypes.Container:
                    resistance >>= 1;
                    break;

                case ItemTypes.Pen:
                case ItemTypes.Wand:
                    resistance = resistance * 5 / 6;
                    break;

                case ItemTypes.PlayerCorpse:
                case ItemTypes.NpcCorpse:
                case ItemTypes.Fountain:
                    resistance <<= 2;
                    break;
                }

                if (Math.Abs(pull) * 10 > resistance)
                {
                    if (!string.IsNullOrEmpty(msg.ObjMsg) &&
                        ch.CurrentRoom.Persons.Any())
                    {
                        comm.act(ATTypes.AT_PLAIN, msg.ObjMsg, ch.CurrentRoom.Persons.First(), obj,
                                 LookupManager.Instance.GetLookup("DirectionNames", (int)xit.Direction),
                                 ToTypes.Character);
                        comm.act(ATTypes.AT_PLAIN, msg.ObjMsg, ch.CurrentRoom.Persons.First(), obj,
                                 LookupManager.Instance.GetLookup("DirectionNames", (int)xit.Direction), ToTypes.Room);
                    }

                    if (!string.IsNullOrEmpty(msg.DestObj) && ch.CurrentRoom.Persons.Any())
                    {
                        comm.act(ATTypes.AT_PLAIN, msg.DestObj, xit.GetDestination().Persons.First(), obj, dtxt, ToTypes.Character);
                        comm.act(ATTypes.AT_PLAIN, msg.DestObj, xit.GetDestination().Persons.First(), obj, dtxt, ToTypes.Room);
                    }

                    obj.InRoom.RemoveFrom(obj);
                    xit.GetDestination().AddTo(obj);
                }
            }

            return(ReturnTypes.None);
        }
Example #9
0
        public static RoomTemplate generate_exit(RoomTemplate room, ExitData exit)
        {
            long         serial;
            long         roomnum;
            long         brvnum;
            long         distance = -1;
            RoomTemplate backroom;
            var          vdir = (int)exit.Direction;

            if (room.ID > 32767)
            {
                serial  = room.ID;
                roomnum = room.TeleportToVnum;
                if ((serial & 65535) == exit.vnum)
                {
                    brvnum = serial >> 16;
                    --roomnum;
                    distance = roomnum;
                }
                else
                {
                    brvnum = serial & 65535;
                    ++roomnum;
                    distance = exit.Distance - 1;
                }
                backroom = RepositoryManager.Instance.ROOMS.CastAs <Repository <long, RoomTemplate> >().Get(brvnum);
            }
            else
            {
                var r1 = room.ID;
                var r2 = exit.vnum;

                brvnum   = r1;
                backroom = room;
                serial   = (r1.GetHighestOfTwoNumbers(r2) << 16) | r1.GetLowestOfTwoNumbers(r2);
                distance = exit.Distance - 1;
                roomnum  = r1 < r2 ? 1 : distance;
            }

            var found = false;

            var foundRoom =
                RepositoryManager.Instance.ROOMS.CastAs <Repository <long, RoomTemplate> >().Values.FirstOrDefault(
                    x => x.ID == serial && x.TeleportToVnum == roomnum);

            if (foundRoom != null)
            {
                found = true;
            }

            // Create room in direction
            RoomTemplate newRoom = null;

            if (!found)
            {
                newRoom = new RoomTemplate(serial, "New room")
                {
                    Area           = room.Area,
                    TeleportToVnum = roomnum,
                    SectorType     = room.SectorType,
                    Flags          = room.Flags
                };
                decorate_room(newRoom);
                RepositoryManager.Instance.ROOMS.CastAs <Repository <long, RoomTemplate> >().Add(newRoom.ID, newRoom);
            }

            var xit = newRoom.GetExit(vdir);

            if (!found || xit == null)
            {
                xit          = db.make_exit(newRoom, exit.GetDestination(), vdir);
                xit.Key      = -1;
                xit.Distance = (int)distance;
            }

            if (!found)
            {
                ExitData bxit = db.make_exit(newRoom, backroom, LookupConstants.rev_dir[vdir]);
                bxit.Key = -1;
                if ((serial & 65536) != exit.vnum)
                {
                    bxit.Distance = (int)roomnum;
                }
                else
                {
                    var tmp = backroom.GetExit(vdir);
                    bxit.Distance = tmp.Distance - (int)distance;
                }
            }

            return(newRoom);
        }
Example #10
0
        public static CharacterInstance scan_for_victim(CharacterInstance ch, ExitData pexit, string name)
        {
            if (ch.IsAffected(AffectedByTypes.Blind) || pexit == null)
            {
                return(null);
            }

            var was_in_room  = ch.CurrentRoom;
            var max_distance = 8;

            if (ch.IsVampire() && GameManager.Instance.GameTime.Hour < 21 && GameManager.Instance.GameTime.Hour > 5)
            {
                max_distance = 1;
            }

            if (ch.Level < 50)
            {
                --max_distance;
            }
            if (ch.Level < 40)
            {
                --max_distance;
            }
            if (ch.Level < 30)
            {
                --max_distance;
            }

            for (int dist = 1; dist <= max_distance; dist++)
            {
                if (pexit.Flags.IsSet(ExitFlags.Closed))
                {
                    break;
                }

                if (pexit.GetDestination().IsPrivate() &&
                    ch.Level < LevelConstants.GetLevel(ImmortalTypes.Greater))
                {
                    break;
                }

                ch.CurrentRoom.RemoveFrom(ch);
                pexit.GetDestination().AddTo(ch);

                var victim = ch.GetCharacterInRoom(name);
                if (victim != null)
                {
                    ch.CurrentRoom.RemoveFrom(ch);
                    was_in_room.AddTo(ch);
                    return(victim);
                }

                switch (ch.CurrentRoom.SectorType)
                {
                default:
                    dist++;
                    break;

                case SectorTypes.Air:
                    if (SmaugRandom.D100() < 80)
                    {
                        dist++;
                    }
                    break;

                case SectorTypes.Forest:
                case SectorTypes.City:
                case SectorTypes.Desert:
                case SectorTypes.Hills:
                    dist += 2;
                    break;

                case SectorTypes.ShallowWater:
                case SectorTypes.DeepWater:
                    dist += 3;
                    break;

                case SectorTypes.Mountain:
                case SectorTypes.Underwater:
                case SectorTypes.OceanFloor:
                    dist += 4;
                    break;
                }

                if (dist >= max_distance)
                {
                    break;
                }

                var dir  = pexit.Direction;
                var exit = ch.CurrentRoom.GetExit(dir);
                if (exit == null)
                {
                    break;
                }
            }

            ch.CurrentRoom.RemoveFrom(ch);
            was_in_room.AddTo(ch);

            return(null);
        }