public static bool TryGetObjectData(Vnum vnum, out ObjectDef retVal)
 {
     lock (objects)
     {
         retVal = objects.Find(md => md.Vnum == vnum);
         return(retVal == null);
     }
 }
示例#2
0
        public static void LoadFromArea(StringReader sr)
        {
            while (true)
            {
                var letter = sr.ReadLetter();

                if (letter == 'S')
                {
                    break;
                }
                if (letter == '*')
                {
                    sr.ReadToEOL();
                    continue;
                }

                var rd = new ResetData {
                    Command = letter
                };
                sr.ReadNumber(); // if_flag
                rd.Arg1 = sr.ReadNumber();
                rd.Arg2 = sr.ReadNumber();
                if (letter != 'G' && letter != 'R')
                {
                    rd.Arg3 = sr.ReadNumber();
                }
                sr.ReadToEOL();

                Vnum      lastObj  = Vnum.None;
                Vnum      lastRoom = Vnum.None;
                RoomDef   roomData;
                MobileDef mobData;
                ObjectDef objData;
                ExitData  exitData;

                switch (rd.Command)
                {
                case 'M':
                    if (MobileDef.TryGetMobileDef((Vnum)rd.Arg1, out mobData) && RoomDef.TryGetRoomDef((Vnum)rd.Arg3, out roomData))
                    {
                        roomData.AddReset(rd);
                        lastRoom = roomData.Vnum;
                    }
                    break;

                case 'O':
                    if (ObjectDef.TryGetObjectData((Vnum)rd.Arg1, out objData) && RoomDef.TryGetRoomDef((Vnum)rd.Arg3, out roomData))
                    {
                        roomData.AddReset(rd);
                        lastObj = roomData.Vnum;
                    }
                    break;

                case 'P':
                    if (ObjectDef.TryGetObjectData((Vnum)rd.Arg1, out objData) && RoomDef.TryGetRoomDef(lastObj, out roomData))
                    {
                        roomData.AddReset(rd);
                    }
                    break;

                case 'G':
                case 'E':
                    if (ObjectDef.TryGetObjectData((Vnum)rd.Arg1, out objData) && RoomDef.TryGetRoomDef(lastRoom, out roomData))
                    {
                        roomData.AddReset(rd);
                        lastObj = lastRoom;
                    }
                    break;

                case 'D':
                    if (rd.Arg2 < 0 ||
                        rd.Arg2 > 5 ||
                        !RoomDef.TryGetRoomDef((Vnum)rd.Arg1, out roomData) ||
                        !roomData.TryGetExit(rd.Arg2, out exitData) ||
                        !exitData.IsDoor)
                    {
                        throw new Exception($"Load_resets: 'D': exit {rd.Arg2} not door.");
                    }

                    switch (rd.Arg3)
                    {
                    case 0: break;

                    case 1:
                        exitData.RSFlags |= ExitFlags.Closed;
                        break;

                    case 2:
                        exitData.RSFlags |= ExitFlags.Closed | ExitFlags.Locked;
                        break;

                    default:
                        throw new Exception($"Load_resets: 'D': bad 'locks': {rd.Arg3}.");
                    }
                    break;

                case 'R':
                    if (rd.Arg2 < 0 || rd.Arg2 > 6)
                    {
                        throw new Exception($"Load_resets: 'R': bad exit {rd.Arg2}.");
                    }

                    if (RoomDef.TryGetRoomDef((Vnum)rd.Arg2, out roomData))
                    {
                        roomData.AddReset(rd);
                    }
                    break;

                default:
                    throw new Exception($"Load_resets: bad command '{rd.Command}'.");
                }
            }
        }
        public static void LoadFromArea(StringReader sr, AreaData area)
        {
            if (area == null)
            {
                throw new Exception("Load_objects: no #AREA seen yet.");
            }

            while (true)
            {
                var letter = sr.ReadLetter();
                if (letter != '#')
                {
                    throw new Exception("Load_objects: # not found.");
                }

                var vnum = sr.ReadVnum();
                if (vnum == Vnum.None)
                {
                    break;
                }

                ObjectDef existing;
                if (!TryGetObjectData(vnum, out existing))
                {
                    throw new Exception($"Load_objects: vnum % {vnum} duplicated.");
                }

                var od = new ObjectDef
                {
                    Vnum = vnum,
                    Area = area
                };

                od.Name = sr.ReadString();
                // TODO upper first char
                od.ShortDescription = sr.ReadString();
                // TODO upper first char
                od.Description = sr.ReadString();
                sr.ReadString(); // Action description

                od.ItemType   = (ItemType)sr.ReadShort();
                od.ExtraFlags = (ExtraFlags)sr.ReadNumber();
                od.WearFlags  = sr.ReadNumber();

                switch (od.ItemType)
                {
                case ItemType.Wand:
                case ItemType.Staff:
                    od.Value[0] = sr.ReadNumber();
                    od.Value[1] = sr.ReadNumber();
                    od.Value[2] = sr.ReadNumber();
                    od.Value[3] = SkillType.Lookup(sr.ReadWord());
                    break;

                case ItemType.Potion:
                case ItemType.Pill:
                case ItemType.Scroll:
                    od.Value[0] = sr.ReadNumber();
                    od.Value[1] = SkillType.Lookup(sr.ReadWord());
                    od.Value[2] = SkillType.Lookup(sr.ReadWord());
                    od.Value[3] = SkillType.Lookup(sr.ReadWord());
                    break;

                default:
                    od.Value[0] = sr.ReadNumber();
                    od.Value[1] = sr.ReadNumber();
                    od.Value[2] = sr.ReadNumber();
                    od.Value[3] = sr.ReadNumber();
                    break;
                }

                od.Weight = sr.ReadShort();
                od.Cost   = sr.ReadNumber();

                sr.ReadNumber(); // Cost per day

                //if (od.ItemType == ItemType.Potion)
                //{
                //    od.ExtraFlags |= ExtraFlags.NoDrop;
                //}

                while (true)
                {
                    bool done = false;
                    switch (sr.PeekLetter())
                    {
                    case 'A':
                        sr.ReadLetter();
                        var aff = new AffectData
                        {
                            Type     = -1,
                            Duration = -1
                        };
                        aff.Location = sr.ReadShort();
                        aff.Modifier = sr.ReadShort();
                        od.Affected.Add(aff);
                        // top_affect++;
                        break;

                    case 'E':
                        sr.ReadLetter();
                        var ed = new ExtraDescrData();
                        ed.Keyword     = sr.ReadString();
                        ed.Description = sr.ReadString();
                        od.ExtraDescr.Add(ed);
                        //top_ed++;
                        break;

                    case 'Q':
                        sr.ReadLetter();
                        od.CHPowerOn      = sr.ReadString();
                        od.CHPowerOff     = sr.ReadString();
                        od.CHPowerUse     = sr.ReadString();
                        od.VictimPowerOn  = sr.ReadString();
                        od.VictimPowerOff = sr.ReadString();
                        od.VictimPowerUse = sr.ReadString();
                        od.SpecType       = sr.ReadNumber();
                        od.SpecPower      = sr.ReadNumber();
                        break;

                    default:
                        done = true;
                        break;
                    }
                    if (done)
                    {
                        break;
                    }
                }

                // ?????
                switch (od.ItemType)
                {
                case ItemType.Pill:
                case ItemType.Potion:
                case ItemType.Scroll:
                case ItemType.Staff:
                case ItemType.Wand:
                    break;
                }

                switch (od.Vnum)
                {
                case (Vnum)3375:
                    // CHAOS = true;
                    break;

                case (Vnum)29515:
                    // VISOR = true;
                    break;

                case (Vnum)29512:
                    // DARKNESS = true;
                    break;

                case (Vnum)29505:
                    // SPEED = true;
                    break;

                case (Vnum)29518:
                    // BRACELET = true;
                    break;

                case (Vnum)29504:
                    // TORC = true;
                    break;

                case (Vnum)29514:
                    // ARMOUR = true;
                    break;

                case (Vnum)29516:
                    // CLAWS = true;
                    break;

                case (Vnum)29555:
                    // ITEMAFFMANTIS = true;
                    break;

                case (Vnum)2654:
                    // ITEMAFFENTROPY = true;
                    break;

                case (Vnum)29598:
                    // ITEMAFFENTROPY = true;
                    break;
                }


                // TODO ???????

                //iHash = vnum % MAX_KEY_HASH;
                //pObjIndex->next = obj_index_hash[iHash];
                //obj_index_hash[iHash] = pObjIndex;
                //top_obj_index++;
                //top_vnum_obj = top_vnum_obj < vnum ? vnum : top_vnum_obj;  /* OLC */
                //assign_area_vnum(vnum);                                  /* OLC */
            }
        }