/// <summary> /// Sets race and class on a repop by looking up the race and class. /// </summary> public void Setup() { _race = Race.RaceList[Race.RaceLookup(_raceString)]; _class = CharClass.ClassList[(int)CharClass.ClassLookup(_classString)]; }
/// <summary> /// Creates and returns a new Area based on the filename. /// </summary> /// <param name="filename">The file to load from.</param> /// <returns>Area containing file data.</returns> public static Area Load(string filename) { if (String.IsNullOrEmpty(filename)) { return(null); } XmlTextReader xtr = null; try { XmlSerializer serializer = new XmlSerializer(typeof(Area)); xtr = new XmlTextReader(new StreamReader(filename)); Area newarea = (Area)serializer.Deserialize(xtr); xtr.Close(); // Add area flags if they don't exist. if (newarea.AreaFlags.Length == 0) { newarea.AreaFlags = new int[Limits.NUM_AREA_FLAGS]; } // Set each mob's class since we don't save the actual class data. // // Set and validate other values in the mob data. // // Associate each mob with this area. foreach (MobTemplate mob in newarea._mobs) { mob.Area = newarea; if (mob.AffectedBy.Length < Limits.NUM_AFFECT_VECTORS) { mob.ExtendAffects(); } if (!String.IsNullOrEmpty(mob.ClassName)) { mob.CharacterClass = CharClass.ClassList[(int)CharClass.ClassLookup(mob.ClassName)]; } //if( !String.IsNullOrEmpty( mob._chatterBotName ) ) //{ // foreach (ChatterBot bot in Database.ChatterBotList) // { // if( bot._name == mob._chatterBotName ) // { // mob._chatterBot = bot; // break; // } // } //} if (!String.IsNullOrEmpty(mob.SpecFunNames)) { mob.SpecFun = MobSpecial.SpecMobLookup(mob.SpecFunNames); } if (!String.IsNullOrEmpty(mob.DeathFunName)) { mob.DeathFun = MobSpecial.SpecMobLookup(mob.DeathFunName); } } // Associate each room with this area. foreach (RoomTemplate room in newarea._rooms) { room.Area = newarea; } // Associate each object with this area. foreach (ObjTemplate obj in newarea._objects) { obj.Area = newarea; obj.SetCost(); if (obj.AffectedBy.Length < Limits.NUM_AFFECT_VECTORS) { obj.ExtendAffects(); } } // Associate each shop with this area and bind it to its keeper. foreach (Shop shop in newarea._shops) { shop.Area = newarea; foreach (MobTemplate mob in newarea._mobs) { if (mob.IndexNumber == shop.Keeper) { mob.ShopData = shop; } } } // Add repops in this area to the global repop list. foreach (RepopulationPoint repop in newarea._repops) { repop.Setup(); RepopulationPoint.RepopList.Add(repop); } newarea._filename = filename; newarea.RebuildIndexes(); return(newarea); } catch (FileNotFoundException) { // Don't bother reporting file not found error, just return null. return(null); } catch (Exception ex) { Console.WriteLine("Exception loading area " + filename + ":" + ex); return(null); } }