/// <summary> /// Modify a Chest object based on the data in a ModifiedChestEntry object. /// </summary> private void ModifyChest(Chest chest, ModifiedChestEntry modifiedChestEntry) { // check the parameters if ((chest == null) || (modifiedChestEntry == null)) { return; } // set the new gold amount chest.Gold = modifiedChestEntry.Gold; // remove all contents not found in the modified version chest.Entries.RemoveAll(delegate(ContentEntry<Gear> contentEntry) { return !modifiedChestEntry.ChestEntries.Exists( delegate(ContentEntry<Gear> modifiedTestEntry) { return (contentEntry.ContentName == modifiedTestEntry.ContentName); }); }); // set the new counts on the remaining content items foreach (ContentEntry<Gear> contentEntry in chest.Entries) { ContentEntry<Gear> modifiedGearEntry = modifiedChestEntry.ChestEntries.Find( delegate(ContentEntry<Gear> modifiedTestEntry) { return (contentEntry.ContentName == modifiedTestEntry.ContentName); }); if (modifiedGearEntry != null) { contentEntry.Count = modifiedGearEntry.Count; } } }
/// <summary> /// Stores the entry for a chest on the current map or quest that has been /// modified but not emptied. /// </summary> public static void StoreModifiedChest(MapEntry<Chest> mapEntry) { // check the parameter if ((mapEntry == null) || (mapEntry.Content == null)) { throw new ArgumentNullException("mapEntry"); } Predicate<ModifiedChestEntry> checkModifiedChests = delegate(ModifiedChestEntry entry) { return (TileEngine.Map.AssetName.EndsWith( entry.WorldEntry.MapContentName) && (entry.WorldEntry.ContentName == mapEntry.ContentName) && (entry.WorldEntry.MapPosition == mapEntry.MapPosition)); }; // check the map for the item first if ((TileEngine.Map != null) && TileEngine.Map.ChestEntries.Exists( delegate(MapEntry<Chest> entry) { return ((entry.ContentName == mapEntry.ContentName) && (entry.MapPosition == mapEntry.MapPosition)); })) { singleton.modifiedMapChests.RemoveAll(checkModifiedChests); ModifiedChestEntry modifiedChestEntry = new ModifiedChestEntry(); modifiedChestEntry.WorldEntry.Content = mapEntry.Content; modifiedChestEntry.WorldEntry.ContentName = mapEntry.ContentName; modifiedChestEntry.WorldEntry.Count = mapEntry.Count; modifiedChestEntry.WorldEntry.Direction = mapEntry.Direction; modifiedChestEntry.WorldEntry.MapContentName = TileEngine.Map.AssetName; modifiedChestEntry.WorldEntry.MapPosition = mapEntry.MapPosition; Chest chest = mapEntry.Content; modifiedChestEntry.ChestEntries.AddRange(chest.Entries); modifiedChestEntry.Gold = chest.Gold; singleton.modifiedMapChests.Add(modifiedChestEntry); return; } // look for the map entry within the quest if ((singleton.quest != null) && singleton.quest.ChestEntries.Exists( delegate(WorldEntry<Chest> entry) { return ((entry.ContentName == mapEntry.ContentName) && (entry.MapPosition == mapEntry.MapPosition) && TileEngine.Map.AssetName.EndsWith(entry.MapContentName)); })) { singleton.modifiedQuestChests.RemoveAll(checkModifiedChests); ModifiedChestEntry modifiedChestEntry = new ModifiedChestEntry(); modifiedChestEntry.WorldEntry.Content = mapEntry.Content; modifiedChestEntry.WorldEntry.ContentName = mapEntry.ContentName; modifiedChestEntry.WorldEntry.Count = mapEntry.Count; modifiedChestEntry.WorldEntry.Direction = mapEntry.Direction; modifiedChestEntry.WorldEntry.MapContentName = TileEngine.Map.AssetName; modifiedChestEntry.WorldEntry.MapPosition = mapEntry.MapPosition; Chest chest = mapEntry.Content; modifiedChestEntry.ChestEntries.AddRange(chest.Entries); modifiedChestEntry.Gold = chest.Gold; singleton.modifiedQuestChests.Add(modifiedChestEntry); return; } }