Example #1
0
        private void ParseSpecials()
        {
            Log.Default.WriteLine(LogLevels.Trace, "Specials section");

            while (true)
            {
                char letter = ReadLetter();

                if (letter == 'S') // done
                {
                    break;
                }
                else if (letter == '*')
                {
                    ; // nop
                }
                else if (letter == 'M')
                {
                    int        vnum       = (int)ReadNumber();
                    string     special    = ReadWord();
                    MobileData mobileData = _mobiles.FirstOrDefault(x => x.VNum == vnum);
                    if (mobileData != null)
                    {
                        mobileData.Special = special;
                    }
                    else
                    {
                        Warn("ParseSpecials: 'M' unknown mobile vnum {0}", vnum);
                    }
                    Log.Default.WriteLine(LogLevels.Trace, "Specials [{0}] parsed", vnum);
                }
                else
                {
                    RaiseParseException("ParseSpecials: letter {0} not *MS", letter);
                }
                ReadToEol();
            }
        }
Example #2
0
        private void ParseShops()
        {
            Log.Default.WriteLine(LogLevels.Trace, "Shops section");

            while (true)
            {
                int keeper = (int)ReadNumber();
                if (keeper == 0)
                {
                    break; // done
                }
                MobileData mobileData = _mobiles.FirstOrDefault(x => x.VNum == keeper);
                if (mobileData == null)
                {
                    RaiseParseException("ParseShops: unknown mobile vnum {0}", keeper);
                }
                else
                {
                    ShopData shopData = new ShopData
                    {
                        Keeper = keeper
                    };
                    for (int i = 0; i < ShopData.MaxTrades; i++)
                    {
                        shopData.BuyType[i] = (int)ReadNumber();
                    }
                    shopData.ProfitBuy  = (int)ReadNumber();
                    shopData.ProfitSell = (int)ReadNumber();
                    shopData.OpenHour   = (int)ReadNumber();
                    shopData.CloseHour  = (int)ReadNumber();
                    mobileData.Shop     = shopData;

                    Log.Default.WriteLine(LogLevels.Trace, "Shop [{0}] parsed", keeper);
                }
                ReadToEol();
            }
        }
Example #3
0
        private void ParseResets()
        {
            Log.Default.WriteLine(LogLevels.Trace, "Resets section");

            int iLastObj  = 0; // TODO: replace with RoomData
            int iLastRoom = 0; // TODO: replace with RoomData

            while (true)
            {
                char letter = ReadLetter();

                if (letter == 'S') // done
                {
                    break;
                }
                else if (letter == '*')
                {
                    ReadToEol();
                    continue;
                }

                ReadNumber(); // unused
                int arg1 = (int)ReadNumber();
                int arg2 = (int)ReadNumber();
                int arg3 = (letter == 'G' || letter == 'R') ? 0 : (int)ReadNumber();
                int arg4 = (letter == 'P' || letter == 'M' || letter == 'Z') ? (int)ReadNumber() : 0;
                ReadToEol();

                ResetData resetData = new ResetData
                {
                    Command = letter,
                    Arg1    = arg1,
                    Arg2    = arg2,
                    Arg3    = arg3,
                    Arg4    = arg4
                };

                if (letter == 'M')
                {
                    if (arg2 == 0 || arg4 == 0)
                    {
                        Warn("ParseResets: 'M' has arg2 or arg4 equal to 0 (room: {0})", arg3);
                    }
                    MobileData mobileData = _mobiles.FirstOrDefault(x => x.VNum == arg1);
                    if (mobileData == null)
                    {
                        Warn("ParseResets: 'M' unknown mobile vnum {0}", arg1);
                    }
                    RoomData roomData = _rooms.FirstOrDefault(x => x.VNum == arg3);
                    if (roomData == null)
                    {
                        Warn("ParseResets: 'M' unknown room vnum {0}", arg3);
                    }
                    else
                    {
                        roomData.Resets.Add(resetData);
                        iLastRoom = arg3;
                    }
                }
                else if (letter == 'O')
                {
                    ObjectData objectData = _objects.FirstOrDefault(x => x.VNum == arg1);
                    if (objectData == null)
                    {
                        Warn("ParseResets: 'O' unknown object vnum {0}", arg1);
                    }
                    RoomData roomData = _rooms.FirstOrDefault(x => x.VNum == arg3);
                    if (roomData == null)
                    {
                        Warn("ParseResets: 'O' unknown room vnum {0}", arg3);
                    }
                    else
                    {
                        roomData.Resets.Add(resetData);
                        iLastObj = arg3;
                    }
                }
                else if (letter == 'P')
                {
                    if (arg2 == 0 || arg4 == 0)
                    {
                        Warn("ParseResets: 'P' has arg2 or arg4 equal to 0 (room: {0})", iLastObj);
                    }
                    ObjectData objectData = _objects.FirstOrDefault(x => x.VNum == arg1);
                    if (objectData == null)
                    {
                        Warn("ParseResets: 'P' unknown object vnum {0}", arg1);
                    }
                    RoomData roomData = _rooms.FirstOrDefault(x => x.VNum == iLastObj);
                    if (roomData == null)
                    {
                        Warn("ParseResets: 'P' unknown room vnum {0}", iLastObj);
                    }
                    else
                    {
                        roomData.Resets.Add(resetData);
                    }
                }
                else if (letter == 'G' || letter == 'E')
                {
                    ObjectData objectData = _objects.FirstOrDefault(x => x.VNum == arg1);
                    if (objectData == null)
                    {
                        Warn("ParseResets: '{0}' unknown object vnum {1}", letter, arg1);
                    }
                    RoomData roomData = _rooms.FirstOrDefault(x => x.VNum == iLastRoom);
                    if (roomData == null)
                    {
                        Warn("ParseResets: '{0}' unknown room vnum {1}", letter, iLastRoom);
                    }
                    else
                    {
                        roomData.Resets.Add(resetData);
                        iLastObj = iLastRoom;
                    }
                }
                else if (letter == 'D')
                {
                    RoomData roomData = _rooms.FirstOrDefault(x => x.VNum == arg1);
                    if (roomData == null)
                    {
                        Warn("ParseResets: 'D' unknown room vnum {0}", arg1);
                    }
                    else
                    {
                        if (arg2 < 0 || arg2 >= RoomData.MaxExits || roomData.Exits[arg2] == null)
                        {
                            RaiseParseException("ParseResets: 'D': exit {0} not door", arg2);
                        }
                        else
                        {
                            if (arg3 == 0)
                            {
                                ; // NOP
                            }
                            else if (arg3 == 1)
                            {
                                roomData.Exits[arg2].ExitInfo |= 0x2; // closed
                            }
                            else if (arg3 == 2)
                            {
                                roomData.Exits[arg2].ExitInfo |= 0x2 | 0x4; // closed + locked
                            }
                            else
                            {
                                Warn("ParseResets: 'D': bad 'locks': {0}", arg3);
                            }
                        }
                        // ResetData is not stored
                    }
                }
                else if (letter == 'R')
                {
                    if (arg2 < 0 || arg2 >= RoomData.MaxExits)
                    {
                        RaiseParseException("ParseResets: 'R': exit {0} not door", arg2);
                    }
                    RoomData roomData = _rooms.FirstOrDefault(x => x.VNum == arg3);
                    if (roomData == null)
                    {
                        Warn("ParseResets: 'D' unknown room vnum {0}", arg3);
                    }
                    else
                    {
                        roomData.Resets.Add(resetData);
                    }
                }
                else if (letter == 'Z')
                {
                    if (arg1 < 2 || arg2 < 2 || arg1 * arg2 > 100)
                    {
                        RaiseParseException("ParseResets: 'Z': bad width, height (room {0})", arg3);
                    }
                    if (arg4 > 0)
                    {
                        ObjectData map = _objects.FirstOrDefault(x => x.VNum == arg4);
                        if (map == null)
                        {
                            RaiseParseException("ParseResets: 'Z': bad map vnum: {0}", arg4);
                        }
                    }
                    RoomData roomData = _rooms.FirstOrDefault(x => x.VNum == arg1);
                    if (roomData == null)
                    {
                        Warn("ParseResets: 'Z' unknown room vnum {0}", arg1);
                    }
                    else
                    {
                        roomData.Resets.Add(resetData);
                    }
                }
                else
                {
                    RaiseParseException("ParseResets: bad command '{0}'", letter);
                }
            }
        }
Example #4
0
        private void ParseMobiles()
        {
            Log.Default.WriteLine(LogLevels.Trace, "Mobiles section");

            while (true)
            {
                char letter = ReadLetter();
                if (letter != '#')
                {
                    RaiseParseException("ParseMobiles: # not found");
                }

                int vnum = (int)ReadNumber();
                if (vnum == 0)
                {
                    break; // parsed
                }
                if (_mobiles.Any(x => x.VNum == vnum))
                {
                    RaiseParseException("ParseMobiles: vnum {0} duplicated", vnum);
                }

                MobileData mobileData = new MobileData
                {
                    VNum        = vnum,
                    Name        = ReadString(),
                    ShortDescr  = ReadString(),
                    LongDescr   = UpperCaseFirst(ReadString()),
                    Description = UpperCaseFirst(ReadString()),
                    Race        = ReadString(),
                    Classes     = ReadFlags(),
                    Act         = ReadFlags(),
                    AffectedBy  = ReadFlags(),
                    AffectedBy2 = ReadFlags(),
                    Etho        = (int)ReadNumber(),
                    Alignment   = (int)ReadNumber(),
                    Group       = (int)ReadNumber(),
                    Level       = (int)ReadNumber(),
                    HitRoll     = (int)ReadNumber()
                };
                ReadDice(mobileData.Hit);
                ReadDice(mobileData.Mana);
                ReadDice(mobileData.Psp);
                ReadDice(mobileData.Damage);
                mobileData.DamageType = ReadWord();
                mobileData.Armor[0]   = (int)ReadNumber() * 10;
                mobileData.Armor[1]   = (int)ReadNumber() * 10;
                mobileData.Armor[2]   = (int)ReadNumber() * 10;
                mobileData.Armor[3]   = (int)ReadNumber() * 10;
                mobileData.OffFlags   = ReadFlags();
                mobileData.ImmFlags   = ReadFlags();
                mobileData.ResFlags   = ReadFlags();
                mobileData.VulnFlags  = ReadFlags();
                mobileData.StartPos   = ReadWord();
                mobileData.DefaultPos = ReadWord();
                mobileData.Sex        = ReadWord();
                mobileData.Wealth     = ReadNumber();
                mobileData.Form       = ReadFlags();
                mobileData.Parts      = ReadFlags();
                mobileData.Size       = ReadWord();
                mobileData.Material   = ReadWord();

                while (true)
                {
                    letter = ReadLetter();

                    if (letter == 'F')
                    {
                        string category = ReadWord();
                        long   vector   = ReadFlags();
                        if (category.StartsWith("act"))
                        {
                            mobileData.Act &= ~vector;
                        }
                        else if (category.StartsWith("aff"))
                        {
                            mobileData.AffectedBy &= ~vector;
                        }
                        else if (category.StartsWith("aff2"))
                        {
                            mobileData.AffectedBy2 &= ~vector;
                        }
                        else if (category.StartsWith("off"))
                        {
                            mobileData.OffFlags &= ~vector;
                        }
                        else if (category.StartsWith("imm"))
                        {
                            mobileData.ImmFlags &= ~vector;
                        }
                        else if (category.StartsWith("res"))
                        {
                            mobileData.ResFlags &= ~vector;
                        }
                        else if (category.StartsWith("vul"))
                        {
                            mobileData.VulnFlags &= ~vector;
                        }
                        else if (category.StartsWith("for"))
                        {
                            mobileData.Form &= ~vector;
                        }
                        else if (category.StartsWith("par"))
                        {
                            mobileData.Parts &= ~vector;
                        }
                    }
                    else if (letter == 'D')
                    {
                        long dummy = ReadFlags(); // not used
                    }
                    else if (letter == 'M')
                    {
                        mobileData.Program = ReadWord();
                    }
                    else if (letter == 'Y')
                    {
                        // TODO: affects (see db2.C:419)
                        string where = ReadWord();
                        string location = ReadWord();
                        long   value1   = ReadNumber();
                        long   value2   = ReadNumber();
                    }
                    else
                    {
                        UngetChar(letter);
                        break;
                    }
                }

                // TODO: convert act flags (see db.C:626)
                // TODO: fix parts (see db.C:520)

                Log.Default.WriteLine(LogLevels.Trace, "Mobile [{0}] parsed", vnum);

                // Save mobile data
                _mobiles.Add(mobileData);
            }
        }