/// <summary> /// Adds a special function to this mobile type. /// </summary> /// <param name="fun"></param> public void AddSpecFun(MobSpecial fun) { // No duplicate specials allowed. foreach (MobSpecial existing in _specFun) { if (existing == fun) { return; } } _specFun.Add(fun); _specFunNames += fun.SpecName; return; }
/// <summary> /// Checks this mobile type for existence of a special function. /// </summary> /// <param name="name"></param> /// <returns></returns> public bool HasSpecFun(string name) { List <MobSpecial> specs = MobSpecial.SpecMobLookup(name); if (specs.Count < 1) { return(false); } foreach (MobSpecial specfun in _specFun) { if (specfun == specs[0]) { return(true); } } return(false); }
/// <summary> /// Adds a special function to this mobile type. /// </summary> /// <param name="name"></param> public void AddSpecFun(string name) { List <MobSpecial> fun = MobSpecial.SpecMobLookup(name); if (fun.Count < 1) { return; } // Prevent duplicate special functions. Each mob can have only one copy of a special function. foreach (MobSpecial spec in _specFun) { if (spec == fun[0]) { return; } } _specFun.Add(fun[0]); _specFunNames += fun[0].SpecName + " "; return; }
/// <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); } }