public static void Read(SerializationReader Reader, acegiak_Romancable romancable) { string classname = Reader.ReadString(); Type type = Type.GetType(classname); acegiak_RomancePreference preference = (acegiak_RomancePreference)Activator.CreateInstance(type, romancable); preference.setRomancable(romancable); preference.Load(Reader); romancable.preferences.Add(preference); }
public void havePreference() { if (ParentObject.IsPlayer()) { this.preferences = new List <acegiak_RomancePreference>(); this.boons = new List <acegiak_RomanceBoon>(); return; } bool loading = false; if (this.preferences == null || this.boons == null) { Loading.SetLoadingStatus("Compiling preferences..."); loading = true; } if (this.preferences == null) { //IPart.AddPlayerMessage("Populating Preference for "+ParentObject.DisplayNameOnly); this.preferences = new List <acegiak_RomancePreference>(); List <acegiak_RomancePreference> possible = new List <acegiak_RomancePreference>(); if (GameObjectFactory.Factory == null || GameObjectFactory.Factory.BlueprintList == null) { return; } GameObjectBlueprint[] blueprints = GameObjectFactory.Factory.BlueprintList.ToArray(); for (int i = blueprints.Length - 1; i >= 0; i--) { GameObjectBlueprint blueprint = blueprints[i]; if (!blueprint.IsBaseBlueprint() && blueprint.DescendsFrom("RomancePreference")) { //IPart.AddPlayerMessage("possible preference type:"+blueprint.Name); GameObject sample = GameObjectFactory.Factory.CreateSampleObject(blueprint.Name); if (sample.HasTag("classname") && sample.GetTag("classname") != null && sample.GetTag("classname") != "") { try{ acegiak_RomancePreference preference = Activator.CreateInstance(Type.GetType(sample.GetTag("classname")), this) as acegiak_RomancePreference; possible.Add(preference); }catch (Exception e) { LogWarning(e.ToString()); } } } } //IPart.AddPlayerMessage("possible prefs checked."); int count = Stat.Rnd2.Next(3) + 3; //IPart.AddPlayerMessage("choosing "+count.ToString()+" out of "+possible.Count().ToString()+" prefs"); for (int i = 0; i < count; i++) { int w = Stat.Rnd2.Next(possible.Count()); preferences.Add(possible[w]); } } if (this.boons == null) { // IPart.AddPlayerMessage("Populating Preference"); this.boons = new List <acegiak_RomanceBoon>(); List <acegiak_RomanceBoon> possible = new List <acegiak_RomanceBoon>(); if (GameObjectFactory.Factory == null || GameObjectFactory.Factory.BlueprintList == null) { return; } foreach (GameObjectBlueprint blueprint in GameObjectFactory.Factory.BlueprintList) { if (!blueprint.IsBaseBlueprint() && blueprint.DescendsFrom("RomanceBoon")) { //IPart.AddPlayerMessage(blueprint.Name); GameObject sample = GameObjectFactory.Factory.CreateSampleObject(blueprint.Name); if (sample.HasTag("classname") && sample.GetTag("classname") != null && sample.GetTag("classname") != "") { acegiak_RomanceBoon preference = Activator.CreateInstance(Type.GetType(sample.GetTag("classname")), this) as acegiak_RomanceBoon; possible.Add(preference); } } } int count = Stat.Rnd2.Next(2); for (int i = 0; i < count; i++) { int w = Stat.Rnd2.Next(possible.Count()); boons.Add(possible[w]); } // IPart.AddPlayerMessage(this.preferences.ToString()); } if (loading) { Loading.SetLoadingStatus(null); } touch(); }