private void ParseRooms() { Log.Default.WriteLine(LogLevels.Trace, "Rooms section"); while (true) { char letter = ReadLetter(); if (letter != '#') { RaiseParseException("ParseRooms: # not found"); } int vnum = (int)ReadNumber(); if (vnum == 0) { break; // parsed } if (_rooms.Any(x => x.VNum == vnum)) { RaiseParseException("ParseRooms: vnum {0} duplicated", vnum); } RoomData roomData = new RoomData { AreaVnum = _lastAreaVnum, VNum = vnum, Name = ReadString(), Description = ReadString() }; ReadNumber(); // area number not used roomData.Flags = ReadFlags(); // convert_room_flags (see db.C:601) roomData.Sector = (int)ReadNumber(); while (true) { letter = ReadLetter(); if (letter == 'S') { break; } else if (letter == 'H') { roomData.HealRate = (int)ReadNumber(); } else if (letter == 'M') { roomData.ManaRate = (int)ReadNumber(); } else if (letter == 'C') { roomData.Clan = ReadString(); } else if (letter == 'D') { int door = (int)ReadNumber(); if (door < 0 || door >= RoomData.MaxExits) { RaiseParseException("ParseRooms: vnum {0} has bad door number", vnum); } ExitData exitData = new ExitData { Description = ReadString(), Keyword = ReadString(), ExitInfo = ReadFlags(), Key = (int)ReadNumber(), DestinationVNum = (int)ReadNumber() }; roomData.Exits[door] = exitData; } else if (letter == 'E') { string keyword = ReadString(); string description = ReadString(); if (roomData.ExtraDescr.ContainsKey(keyword)) { Warn("ParseRooms: duplicate description in vnum {0}", vnum); } else { roomData.ExtraDescr.Add(keyword, description); } } else if (letter == 'O') { if (!string.IsNullOrWhiteSpace(roomData.Owner)) { RaiseParseException("ParseRooms: vnum {0} has duplicate owner", vnum); } roomData.Owner = ReadString(); } else if (letter == 'G') { roomData.Guilds = ReadFlags(); } else if (letter == 'Z') { roomData.Program = ReadWord(); } else if (letter == 'R') { roomData.TimeBetweenRepop = (int)ReadNumber(); roomData.TimeBetweenRepopPeople = (int)ReadNumber(); } else if (letter == 'Y') { // TODO: affects (see db.C:3502) string where = ReadWord(); string location = ReadWord(); long value1 = ReadNumber(); long value2 = ReadNumber(); } else { RaiseParseException("ParseRooms: vnum {0} has unknown flag", vnum); } } Log.Default.WriteLine(LogLevels.Trace, "Room [{0}] parsed", vnum); Debug.WriteLine("Room [{0}] parsed", vnum); // Save room data _rooms.Add(roomData); } }
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); } } }