Beispiel #1
0
 /// <summary>
 /// Loads a player file and returns a PC object populated with the data.
 /// </summary>
 /// <param name="filename"></param>
 /// <returns></returns>
 new public static PC LoadFile(string filename)
 {
     try
     {
         XmlSerializer serializer = new XmlSerializer(typeof(PC));
         Stream        stream     = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);
         PC            data       = (PC)serializer.Deserialize(stream);
         stream.Close();
         // Fix up any data references that can't be saved.
         for (int i = data.Carrying.Count - 1; i >= 0; i--)
         {
             if ((data.Carrying[i].ObjIndexData = Database.GetObjTemplate(data.Carrying[i].ObjIndexNumber)) == null)
             {
                 // If the object can't be found, the player loses it. Items can be removed from the game by removing
                 // a zone.
                 Log.Error("Object index data not found for object " + data.Carrying[i].ObjIndexNumber + " (" +
                           data.Carrying[i].ShortDescription + ") on player " + filename + ". Removing from player.");
                 data.Carrying.RemoveAt(i);
                 continue;
             }
             data.Carrying[i].CarriedBy = data;
         }
         data.RemoveActionBit(PLAYER_CAMPING);
         if (data.Level >= Limits.LEVEL_AVATAR && data.ImmortalData == null)
         {
             data.ImmortalData = new ImmortalData();
         }
         // Extend affect vectors if the number has been increased.
         if (data.AffectedBy.Length < Limits.NUM_AFFECT_VECTORS)
         {
             data.ExtendAffectData();
         }
         return(data);
     }
     catch (FileNotFoundException)
     {
         Log.Trace("Player file not found.");
         return(null);
     }
     catch (Exception ex)
     {
         Log.Trace("Unable to load player file: " + filename + ".  This may be a new player.  Exception is:" + ex);
         return(null);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Resets a room, reloading according to resets.
        /// </summary>
        /// <param name="notInitial"></param>
        /// <returns></returns>
        public bool ResetRoom(int notInitial)
        {
            Exit     exit = null;
            CharData mobile;
            CharData lastMob = null;
            int      level   = 0;
            bool     last    = true;
            // Added for debugging.
            string text = String.Empty;

            foreach (Reset reset in Area.Resets)
            {
                if (!reset.IsRoomReset(this))
                {
                    continue;
                }
                Object      obj;
                Object      lastObj;
                MobTemplate mobIndex;
                ObjTemplate objTemplate;
                Room        room;

                switch (reset.Command)
                {
                default:
                    Log.Error("RoomIndex.Reset(): bad command %c.", reset.Command);
                    break;

                case 'M':
                    mobIndex = Database.GetMobTemplate(reset.Arg1);
                    if (!mobIndex)
                    {
                        Log.Error("RoomIndex.Reset(): 'M': bad mob index number {0} for arg1.", reset.Arg1);
                        continue;
                    }

                    room = GetRoom(reset.Arg3);
                    if (!room)
                    {
                        Log.Error("RoomIndex.Reset(): 'R': bad room index number {0} for arg3.", reset.Arg3);
                        continue;
                    }

                    if ((mobIndex.HasSpecFun("spec_cast_ghost")) &&
                        (Database.SystemData.WeatherData.Sunlight > SunType.night) &&
                        (Database.SystemData.WeatherData.Sunlight < SunType.moonrise))
                    {
                        last = false;
                        continue;
                    }

                    level = Macros.Range(0, mobIndex.Level - 2, Limits.LEVEL_HERO);

                    if (mobIndex.NumActive >= reset.Arg2)
                    {
                        last = false;
                        break;
                    }
                    mobile = Database.CreateMobile(mobIndex);

                    // Check for pet shop.
                    Room prevRoom = GetRoom(room.IndexNumber - 1);
                    if (prevRoom && prevRoom.HasFlag(ROOM_PET_SHOP))
                    {
                        mobile.SetActionBit(MobTemplate.ACT_PET);
                    }

                    if (room.IsDark())
                    {
                        mobile.SetAffectBit(Affect.AFFECT_INFRAVISION);
                    }

                    mobile.AddToRoom(room);
                    mobile.LoadRoomIndexNumber = room.IndexNumber;

                    // This code makes mounts make their mounters mount them.
                    if (reset.Arg0 == -1 && lastMob)
                    {
                        // If set to be mounted.
                        String[] keywords = mobile.Name.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        Command.Mount(lastMob, keywords);
                    }

                    lastMob = mobile;

                    level = Macros.Range(0, mobile.Level - 2, Limits.LEVEL_HERO);
                    last  = true;
                    break;

                case 'F':
                    mobIndex = Database.GetMobTemplate(reset.Arg1);
                    if (!mobIndex)
                    {
                        Log.Error("RoomIndex.Reset(): 'F': bad mob index number {0} for arg1.", reset.Arg1);
                        continue;
                    }

                    room = GetRoom(reset.Arg3);
                    if (!room)
                    {
                        Log.Error("RoomIndex.Reset(): 'F': bad room index number {0} for arg3.", reset.Arg3);
                        continue;
                    }

                    if (mobIndex.HasSpecFun("spec_cast_ghost") && (Database.SystemData.WeatherData.Sunlight > SunType.night) &&
                        (Database.SystemData.WeatherData.Sunlight < SunType.moonrise))
                    {
                        last = false;
                        continue;
                    }

                    level = Macros.Range(0, mobIndex.Level - 2, Limits.LEVEL_HERO);

                    if (mobIndex.NumActive >= reset.Arg2)
                    {
                        last = false;
                        break;
                    }
                    mobile = Database.CreateMobile(mobIndex);

                    Room prev = GetRoom(room.IndexNumber - 1);
                    if (prev && prev.HasFlag(ROOM_PET_SHOP))
                    {
                        mobile.SetActionBit(MobTemplate.ACT_PET);
                    }

                    if (room.IsDark())
                    {
                        mobile.SetAffectBit(Affect.AFFECT_INFRAVISION);
                    }

                    // Set following bit. Can't have a message sent because
                    // there is no valid room number (causes a segmentation fault)
                    CharData.AddFollowerWithoutMessage(mobile, lastMob);

                    lastMob = mobile;
                    mobile.AddToRoom(room);
                    mobile.LoadRoomIndexNumber = room.IndexNumber;
                    level = Macros.Range(0, mobile.Level - 2, Limits.LEVEL_HERO);
                    last  = true;
                    break;

                case 'O':
                    if (notInitial != 0)
                    {
                        last = false;
                        continue;
                    }
                    objTemplate = Database.GetObjTemplate(reset.Arg1);
                    if (!objTemplate)
                    {
                        Log.Error("RoomIndex.Reset(): 'O': bad obj index number {0} for arg1.", reset.Arg1);
                        continue;
                    }

                    room = GetRoom(reset.Arg3);
                    if (!room)
                    {
                        Log.Error("RoomIndex.Reset(): 'O': bad room index number {0} for arg3.", reset.Arg3);
                        continue;
                    }

                    if (Area.NumPlayers > 0 || room._contents.Count != 0 && (Object.CountObjectInList(objTemplate, room._contents) > 0))
                    {
                        last = false;
                        break;
                    }
                    // check if is unique/arti
                    if (Database.IsArtifact(objTemplate.IndexNumber))
                    {
                        text += "RoomIndex.Reset(): Artifact found: " + objTemplate.Name + " (" + objTemplate.IndexNumber + ")";
                        Log.Trace(text);
                    }     //end if artiact

                    obj = Database.CreateObject(objTemplate, MUDMath.FuzzyNumber(level));
                    if (obj != null)
                    {
                        obj.Cost = 0;
                        obj.AddToRoom(this);
                        last = true;
                    }
                    else
                    {
                        Log.Error("RoomIndex.Reset(): Unable to Database.CreateObject {0}", reset.Arg3);
                    }
                    break;

                case 'P':
                    if (notInitial != 0)
                    {
                        last = false;
                        continue;
                    }
                    objTemplate = Database.GetObjTemplate(reset.Arg1);
                    if (!objTemplate)
                    {
                        Log.Error("RoomIndex.Reset(): 'P': bad obj index number {0} for arg3.", reset.Arg1);
                        continue;
                    }

                    ObjTemplate targetObjTemplate = Database.GetObjTemplate(reset.Arg3);
                    if (!targetObjTemplate)
                    {
                        Log.Error("RoomIndex.Reset(): 'P': bad obj index number {0} for arg3.", reset.Arg3);
                        continue;
                    }

                    if (Area.NumPlayers > 0 || !(lastObj = Object.GetFirstObjectOfTemplateType(targetObjTemplate)) ||
                        lastObj.Contains.Count != 0 && (Object.CountObjectInList(objTemplate, lastObj.Contains) > 0))
                    {
                        last = false;
                        break;
                    }
                    // check if is unique/arti
                    if (Database.IsArtifact(objTemplate.IndexNumber))
                    {
                        text += "RoomIndex.Reset(): Artifact found: " + objTemplate.Name + " (" + objTemplate.IndexNumber + ")";
                        Log.Trace(text);
                    }     //end if artifact

                    obj = Database.CreateObject(objTemplate, MUDMath.FuzzyNumber(lastObj.Level));
                    lastObj.AddToObject(obj);
                    last = true;

                    // Ensure that the container gets Reset.
                    if ((lastObj.ItemType == ObjTemplate.ObjectType.container) || (lastObj.ItemType == ObjTemplate.ObjectType.drink_container))
                    {
                        lastObj.Values[1] = lastObj.ObjIndexData.Values[1];
                    }
                    break;

                case 'G':
                case 'E':
                    if (notInitial != 0)
                    {
                        last = false;
                        continue;
                    }
                    objTemplate = Database.GetObjTemplate(reset.Arg1);
                    if (!objTemplate)
                    {
                        Log.Error("RoomIndex.Reset(): 'E' or 'G': bad obj index number {0} for arg1.", reset.Arg1);
                        continue;
                    }

                    if (!last)
                    {
                        break;
                    }

                    if (!lastMob)
                    {
                        Log.Error("RoomIndex.Reset(): 'E' or 'G': null mob for index number {0} for arg1.", reset.Arg1);
                        last = false;
                        break;
                    }
                    // check if is unique/arti
                    if (Database.IsArtifact(objTemplate.IndexNumber))
                    {
                        text += "RoomIndex.Reset(): Artifact found: " + objTemplate.Name + " (" + objTemplate.IndexNumber + ")";
                        Log.Trace(text);
                    }                                    //end if artifact

                    if (lastMob.MobileTemplate.ShopData) /* Shop-keeper? */
                    {
                        int olevel;

                        switch (objTemplate.ItemType)
                        {
                        default:
                            olevel = 0;
                            break;

                        case ObjTemplate.ObjectType.pill:
                            olevel = MUDMath.NumberRange(0, 10);
                            break;

                        case ObjTemplate.ObjectType.potion:
                            olevel = MUDMath.NumberRange(0, 10);
                            break;

                        case ObjTemplate.ObjectType.scroll:
                            olevel = MUDMath.NumberRange(5, 15);
                            break;

                        case ObjTemplate.ObjectType.wand:
                            olevel = MUDMath.NumberRange(10, 20);
                            break;

                        case ObjTemplate.ObjectType.staff:
                            olevel = MUDMath.NumberRange(15, 25);
                            break;

                        case ObjTemplate.ObjectType.armor:
                            olevel = MUDMath.NumberRange(5, 15);
                            break;

                        case ObjTemplate.ObjectType.other:
                            olevel = MUDMath.NumberRange(5, 15);
                            break;

                        case ObjTemplate.ObjectType.clothing:
                            olevel = MUDMath.NumberRange(5, 15);
                            break;

                        case ObjTemplate.ObjectType.weapon:
                            if (reset.Command == 'G')
                            {
                                olevel = MUDMath.NumberRange(5, 15);
                            }
                            else
                            {
                                olevel = MUDMath.FuzzyNumber(level);
                            }
                            break;
                        }

                        obj = Database.CreateObject(objTemplate, olevel);
                        if (reset.Command == 'G')
                        {
                            obj.AddFlag(ObjTemplate.ITEM_INVENTORY);
                        }
                    }
                    else
                    {
                        obj = Database.CreateObject(objTemplate, MUDMath.FuzzyNumber(level));
                    }
                    obj.ObjToChar(lastMob);
                    if (reset.Command == 'E')
                    {
                        lastMob.EquipObject(ref obj, (ObjTemplate.WearLocation)reset.Arg3);
                    }
                    last = true;
                    break;

                case 'D':
                    if (reset.Arg2 < 0 || reset.Arg2 >= Limits.MAX_DIRECTION || !(exit = ExitData[reset.Arg2]) ||
                        !exit.HasFlag(Exit.ExitFlag.is_door))
                    {
                        Log.Error("RoomIndex.Reset(): 'D': exit {0} not door for arg2.", reset.Arg2);
                    }

                    switch (reset.Arg3)
                    {
                    default:
                        Log.Error("RoomIndex.Reset(): 'D': bad 'locks': {0} for arg3.", reset.Arg3);
                        break;

                    case 0:
                        break;

                    case 1:
                        exit.AddFlag(Exit.ExitFlag.closed);
                        break;

                    case 2:
                        exit.AddFlag(Exit.ExitFlag.closed | Exit.ExitFlag.locked);
                        break;

                    case 4:
                        exit.AddFlag(Exit.ExitFlag.secret);
                        break;

                    case 5:
                        exit.AddFlag(Exit.ExitFlag.secret | Exit.ExitFlag.closed);
                        break;

                    case 6:
                        exit.AddFlag(Exit.ExitFlag.secret | Exit.ExitFlag.closed | Exit.ExitFlag.locked);
                        break;

                    case 8:
                        exit.AddFlag(Exit.ExitFlag.blocked);
                        break;

                    case 9:
                        exit.AddFlag(Exit.ExitFlag.blocked | Exit.ExitFlag.closed);
                        break;

                    case 10:
                        exit.AddFlag(Exit.ExitFlag.blocked | Exit.ExitFlag.closed | Exit.ExitFlag.locked);
                        break;

                    case 12:
                        exit.AddFlag(Exit.ExitFlag.blocked | Exit.ExitFlag.secret);
                        break;

                    case 13:
                        exit.AddFlag(Exit.ExitFlag.blocked | Exit.ExitFlag.secret | Exit.ExitFlag.closed);
                        break;

                    case 14:
                        exit.AddFlag(Exit.ExitFlag.blocked | Exit.ExitFlag.secret | Exit.ExitFlag.closed | Exit.ExitFlag.locked);
                        break;
                    }
                    break;

                case 'R':
                    Log.Trace("Unsupported randomize room exits call.  Please implement this.");
                    break;
                }
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Creating a portal.
        /// </summary>
        /// <param name="ch"></param>
        /// <param name="spell"></param>
        /// <param name="level"></param>
        /// <param name="target"></param>
        /// <param name="indexNumber"></param>
        public static void MakePortal(CharData ch, Spell spell, int level, Target target, int indexNumber)
        {
            Room     location;
            CharData victim   = (CharData)target;
            Room     original = ch.InRoom;

            if (ch.IsNPC())
            {
                return;
            }
            if (!victim)
            {
                ch.SendText("Who exactly is your target?\r\n");
                return;
            }
            if (victim.IsNPC() && !ch.IsImmortal())
            {
                return;
            }

            if (!Magic.HasSpellConsent(ch, victim))
            {
                return;
            }

            if (victim == ch || ch.InRoom == victim.InRoom)
            {
                ch.SendText("Seems like a waste of time.\r\n");
                return;
            }

            if (!(location = victim.InRoom) ||
                victim.InRoom.HasFlag(RoomTemplate.ROOM_SAFE) ||
                victim.InRoom.HasFlag(RoomTemplate.ROOM_PRIVATE) ||
                victim.InRoom.HasFlag(RoomTemplate.ROOM_SOLITARY))
            {
                ch.SendText("You can't seem to get a fix their location.\r\n");
                return;
            }
            if (!victim.IsNPC() && (ch.IsRacewar(victim)) && !ch.IsImmortal())
            {
                ch.SendText("Don't you wish it was that easy!\r\n");
                return;
            }

            Object portal = Database.CreateObject(Database.GetObjTemplate(indexNumber), 0);

            if (victim.InRoom.HasFlag(RoomTemplate.ROOM_NO_GATE) ||
                ch.InRoom.HasFlag(RoomTemplate.ROOM_NO_GATE))
            {
                SocketConnection.Act("$p opens for a brief instant and then collapses.&n", ch, portal, null, SocketConnection.MessageTarget.character);
                SocketConnection.Act("$p opens for a brief instant and then collapses.&n", ch, portal, null, SocketConnection.MessageTarget.room);
                SocketConnection.Act("$p opens for a brief instant and then collapses.&n", victim, portal, null, SocketConnection.MessageTarget.character);
                SocketConnection.Act("$p opens for a brief instant and then collapses.&n", victim, portal, null, SocketConnection.MessageTarget.room);
                portal.RemoveFromWorld();
                return;
            }

            portal.Timer     = level / 15;
            portal.Values[2] = level / 7;
            portal.Values[0] = location.IndexNumber;

            portal.AddToRoom(original);

            portal           = Database.CreateObject(Database.GetObjTemplate(indexNumber), 0);
            portal.Timer     = level / 15;
            portal.Values[2] = level / 7;
            portal.Values[0] = original.IndexNumber;

            portal.AddToRoom(location);

            switch (indexNumber)
            {
            case StaticObjects.OBJECT_NUMBER_PORTAL:
                SocketConnection.Act("$p&+Y rises up from the ground.&n", ch, portal, null, SocketConnection.MessageTarget.room);
                SocketConnection.Act("$p&+Y rises up before you.&n", ch, portal, null, SocketConnection.MessageTarget.character);

                if (location.People.Count > 0)
                {
                    SocketConnection.Act("$p&+Y rises up from the ground.&n", location.People[0], portal, null,
                                         SocketConnection.MessageTarget.room);
                    SocketConnection.Act("$p&+Y rises up from the ground.&n", location.People[0], portal, null,
                                         SocketConnection.MessageTarget.character);
                }
                break;

            case StaticObjects.OBJECT_NUMBER_MOONWELL:
                SocketConnection.Act("&+WSilver mists swirl and form into a $p.&n", ch, portal, null, SocketConnection.MessageTarget.room);
                SocketConnection.Act("&+WSilver mists swirl and form into a $p.&n", ch, portal, null, SocketConnection.MessageTarget.character);

                if (location.People.Count > 0)
                {
                    SocketConnection.Act("&+WSilver mists swirl and form into a $p.&n", location.People[0], portal, null,
                                         SocketConnection.MessageTarget.room);
                    SocketConnection.Act("&+WSilver mists swirl and form into a $p.&n", location.People[0], portal, null,
                                         SocketConnection.MessageTarget.character);
                }
                break;

            case StaticObjects.OBJECT_NUMBER_WORMHOLE:
                SocketConnection.Act("$p&+L appears from a warping of space and time.&n", ch, portal, null, SocketConnection.MessageTarget.room);
                SocketConnection.Act("$p&+L appears from a warping of space and time.&n", ch, portal, null, SocketConnection.MessageTarget.character);

                if (location.People.Count > 0)
                {
                    SocketConnection.Act("$p&+L appears from a warping of space and time.&n", location.People[0], portal, null,
                                         SocketConnection.MessageTarget.room);
                    SocketConnection.Act("$p&+L appears from a warping of space and time.&n", location.People[0], portal, null,
                                         SocketConnection.MessageTarget.character);
                }
                break;
            }

            ch.WaitState(8);

            return;
        }