protected static void RemoveWrittenData(string type) { List <StoreItem> oldData = null; if (!Bookstore.mItemDictionary.TryGetValue(type, out oldData)) { return; } List <StoreItem> newData = new List <StoreItem>(); foreach (StoreItem item in oldData) { BookWrittenData data = item.CustomData as BookWrittenData; if (data != null) { continue; } newData.Add(item); } Bookstore.mItemDictionary.Remove(type); Bookstore.mItemDictionary.Add(type, newData); }
public static ObjectGuid CreateBookWrittenCallback(object customData, ref Simulator.ObjectInitParameters initData, Quality quality) { BookWrittenData data = customData as BookWrittenData; if (data == null) { return(ObjectGuid.InvalidObjectGuid); } try { Notify(data.Title); BookWritten book = GlobalFunctions.CreateObjectOutOfWorld("BookWritten") as BookWritten; if (book == null) { return(ObjectGuid.InvalidObjectGuid); } book.InitBookCommon(data); return(book.ObjectId); } catch (Exception e) { Common.Exception(data.ID, e); return(ObjectGuid.InvalidObjectGuid); } }
protected override bool PrivateUpdate(ScenarioFrame frame) { List <BookWritten> allBooks = new List <BookWritten>(Lot.GetObjects <BookWritten>()); Dictionary <BookWrittenData, int> books = new Dictionary <BookWrittenData, int>(); foreach (BookWritten book in allBooks) { BookWrittenData data = book.Data as BookWrittenData; if (data == null) { IncStat("Bad Removed"); book.FadeOut(false, true); } else { if (!books.ContainsKey(data)) { books.Add(data, 1); } else { books[data]++; } } } foreach (KeyValuePair <BookWrittenData, int> data in books) { if (data.Value <= 1) { continue; } List <BookWritten> bookList = new List <BookWritten>(); foreach (BookWritten book in allBooks) { if (book.Data == data.Key) { bookList.Add(book); } } if (bookList.Count > 1) { BookWritten save = RandomUtil.GetRandomObjectFromList(bookList); bookList.Remove(save); foreach (BookWritten book in bookList) { IncStat("Removed"); book.FadeOut(false, true); } } } return(false); }
public static ObjectGuid CreateWrittenBookCallback(object customData, ref Simulator.ObjectInitParameters initData, Quality quality) { BookWrittenData bookWrittenData = customData as BookWrittenData; if (bookWrittenData == null) { return(ObjectGuid.InvalidObjectGuid); } ObjectGuid result; try { BookWritten bookWritten = GlobalFunctions.CreateObjectOutOfWorld("BookWritten") as BookWritten; if (bookWritten == null) { result = ObjectGuid.InvalidObjectGuid; } else { bookWritten = BookWritten.CreateOutOfWorld(bookWrittenData); result = bookWritten.ObjectId; } } catch (Exception ex) { StyledNotification.Show(new StyledNotification.Format("CreateWrittenBookCallback: " + ex.Message, StyledNotification.NotificationStyle.kGameMessagePositive)); result = ObjectGuid.InvalidObjectGuid; } return(result); }
private static void OnAddBookBuff(Event e) { Sim actor = e.Actor as Sim; if (actor == null) { return; } BookWritten target = e.TargetObject as BookWritten; if (target == null) { return; } BookWrittenData data = target.Data as BookWrittenData; if (data == null) { return; } if (actor.SimDescription.ChildOrBelow) { return; } if (actor.SimDescription.Teen) { if (!Woohooer.Settings.AllowTeen(true)) { return; } } if (actor.BuffManager == null) { return; } switch (data.Genre) { case BookData.BookGenres.Romance: //case BookData.BookGenres.Poetry: case BookData.BookGenres.Trashy: actor.BuffManager.AddElement(BuffNames.InTheMood, sBookOrigin); break; } }
public static void ProcessWrittenBookCallback(object customData, IGameObject book) { BookWrittenData bookWrittenData = customData as BookWrittenData; if (bookWrittenData == null) { return; } try { BookWritten.ProcessCallback(bookWrittenData, book as BookWritten); } catch (Exception ex) { StyledNotification.Show(new StyledNotification.Format("ProcessWrittenBookCallback: " + ex.Message, StyledNotification.NotificationStyle.kGameMessagePositive)); } }
public Dictionary <string, List <StoreItem> > ItemDictionaryBooks() { Dictionary <string, List <StoreItem> > books = Bookstore.sItemDictionary; //Add written books into the shopping list List <Sim> sList = new List <Sim>(Sims3.Gameplay.Queries.GetObjects <Sim>()); BookWrittenData data3 = null; foreach (Sim s in sList) { if (s.SimDescription != null && s.SimDescription.ChildOrAbove && s.SkillManager != null) { Writing element = s.SkillManager.GetElement(SkillNames.Writing) as Writing; if ((element != null) && (element.WrittenBookDataList.Count > 0)) { BookGeneralStoreItem item = null; foreach (WrittenBookData data in element.WrittenBookDataList.Values) { //Check has the book already been added object o = books["General"].Find(delegate(StoreItem i) { return(i.Name.Equals(data.Title)); }); if (o == null) { data3 = new BookWrittenData(data, false); data3.Author = s.SimDescription.FullName; ThumbnailKey thumb = new ThumbnailKey(new ResourceKey((ulong)ResourceUtils.XorFoldHashString32("book_standard"), 0x1661233, 1), ThumbnailSize.Medium, ResourceUtils.HashString32("default"), ResourceUtils.HashString32(data.MaterialState)); item = new BookGeneralStoreItem(data.Title, (float)data.Value, data3, thumb, ("BookGeneral_" + data.Title.Replace(" ", string.Empty)), new CreateObjectCallback(CreateWrittenBookCallback), new ProcessObjectCallback(ProcessWrittenBookCallback), null, new List <WorldType> { WorldType.Undefined, WorldType.Base, WorldType.Downtown }, data3.Author, data.Title, data.NumPages, BookData.GetGenreLocalizedString(data.Genre)); if (books.ContainsKey("General")) { books["General"].Add(item); books["All"].Add(item); } } } } } } return(books); }
public static void ProcessBookWrittenCallback(object customData, IGameObject book) { BookWrittenData data = customData as BookWrittenData; if (data == null) { return; } try { BookWritten.ProcessCallback(data, book as BookWritten); } catch (Exception e) { Common.Exception(data.ID, e); } }
public void OnWorldLoadFinished() { Dictionary<BookWrittenData, bool> existing = new Dictionary<BookWrittenData, bool>(); foreach (BookWritten book in Sims3.Gameplay.Queries.GetObjects<BookWritten>()) { BookWrittenData bookData = book.Data as BookWrittenData; if (bookData == null) continue; existing[bookData] = true; } List<string> remove = new List<string>(); foreach (SimDescription sim in SimListing.GetResidents(true).Values) { if (sim.SkillManager == null) continue; Writing skill = sim.SkillManager.GetSkill<Writing>(SkillNames.Writing); if (skill == null) continue; if (skill.WrittenBookDataList == null) continue; foreach (WrittenBookData book in skill.WrittenBookDataList.Values) { book.Author = sim.FullName; string id = book.Title + book.Author; BookWrittenData bookData; if (!BookData.BookWrittenDataList.TryGetValue(id, out bookData)) { // Constructor auto-adds to dictionary bookData = new BookWrittenData(book, true); } existing[bookData] = true; } } RemoveWrittenData("General"); RemoveWrittenData("All"); List<StoreItem> general = null, all = null; Bookstore.mItemDictionary.TryGetValue("General", out general); Bookstore.mItemDictionary.TryGetValue("All", out all); List<WorldType> worldTypes = new List<WorldType>(); worldTypes.Add(GameUtils.GetCurrentWorldType()); Writing stateSkill = new Writing(); foreach (KeyValuePair<string,BookWrittenData> pair in BookData.BookWrittenDataList) { BookWrittenData data = pair.Value; if (!existing.ContainsKey(pair.Value)) { remove.Add(pair.Key); continue; } else if ((string.IsNullOrEmpty(data.Title)) || (string.IsNullOrEmpty(data.Author))) { remove.Add(pair.Key); continue; } string geoState, materialState; stateSkill.GetGeoAndMaterialStates(data.Genre, out geoState, out materialState); if (string.IsNullOrEmpty(data.GeometryState)) { data.GeometryState = geoState; } if (string.IsNullOrEmpty(data.MaterialState)) { data.MaterialState = materialState; } ThumbnailKey thumb = new ThumbnailKey(new ResourceKey((ulong)ResourceUtils.XorFoldHashString32("book_standard"), 0x1661233, 0x1), ThumbnailSize.Medium, ResourceUtils.HashString32(data.GeometryState), ResourceUtils.HashString32(data.MaterialState)); BookGeneralStoreItem item = new BookGeneralStoreItem(data.Title + " - " + data.Author, (float)data.Value, data, thumb, data.GenerateUIStoreItemID(), new CreateObjectCallback(CreateBookWrittenCallback), new ProcessObjectCallback(ProcessBookWrittenCallback), data.AllowedWorlds, worldTypes, data.Author, data.Title, data.Length, data.GenreString); general.Add(item); all.Add(item); } foreach (string id in remove) { BookData.BookWrittenDataList.Remove(id); BooterLogger.AddTrace("Removed: " + id); } }
public void OnWorldLoadFinished() { Dictionary <BookWrittenData, bool> existing = new Dictionary <BookWrittenData, bool>(); foreach (BookWritten book in Sims3.Gameplay.Queries.GetObjects <BookWritten>()) { BookWrittenData bookData = book.Data as BookWrittenData; if (bookData == null) { continue; } existing[bookData] = true; } List <string> remove = new List <string>(); foreach (SimDescription sim in SimListing.GetResidents(true).Values) { if (sim.SkillManager == null) { continue; } Writing skill = sim.SkillManager.GetSkill <Writing>(SkillNames.Writing); if (skill == null) { continue; } if (skill.WrittenBookDataList == null) { continue; } foreach (WrittenBookData book in skill.WrittenBookDataList.Values) { book.Author = sim.FullName; string id = book.Title + book.Author; BookWrittenData bookData; if (!BookData.BookWrittenDataList.TryGetValue(id, out bookData)) { // Constructor auto-adds to dictionary bookData = new BookWrittenData(book, true); } existing[bookData] = true; } } RemoveWrittenData("General"); RemoveWrittenData("All"); List <StoreItem> general = null, all = null; Bookstore.mItemDictionary.TryGetValue("General", out general); Bookstore.mItemDictionary.TryGetValue("All", out all); List <WorldType> worldTypes = new List <WorldType>(); worldTypes.Add(GameUtils.GetCurrentWorldType()); Writing stateSkill = new Writing(); foreach (KeyValuePair <string, BookWrittenData> pair in BookData.BookWrittenDataList) { BookWrittenData data = pair.Value; if (!existing.ContainsKey(pair.Value)) { remove.Add(pair.Key); continue; } else if ((string.IsNullOrEmpty(data.Title)) || (string.IsNullOrEmpty(data.Author))) { remove.Add(pair.Key); continue; } string geoState, materialState; stateSkill.GetGeoAndMaterialStates(data.Genre, out geoState, out materialState); if (string.IsNullOrEmpty(data.GeometryState)) { data.GeometryState = geoState; } if (string.IsNullOrEmpty(data.MaterialState)) { data.MaterialState = materialState; } ThumbnailKey thumb = new ThumbnailKey(new ResourceKey((ulong)ResourceUtils.XorFoldHashString32("book_standard"), 0x1661233, 0x1), ThumbnailSize.Medium, ResourceUtils.HashString32(data.GeometryState), ResourceUtils.HashString32(data.MaterialState)); BookGeneralStoreItem item = new BookGeneralStoreItem(data.Title + " - " + data.Author, (float)data.Value, data, thumb, data.GenerateUIStoreItemID(), new CreateObjectCallback(CreateBookWrittenCallback), new ProcessObjectCallback(ProcessBookWrittenCallback), data.AllowedWorlds, worldTypes, data.Author, data.Title, data.Length, data.GenreString); general.Add(item); all.Add(item); } foreach (string id in remove) { BookData.BookWrittenDataList.Remove(id); BooterLogger.AddTrace("Removed: " + id); } }