public EntityRelationshipHandler() { this.ValueExtractor = new JSONValueExtractor(); this.m_Relationships = new NonUniqueDictionary <long, IRelationship>(); this.m_RelationshipTypes = this.Load().ToDictionary(relationship => relationship.Name, relationship => relationship); }
public void AddTest() { NonUniqueDictionary <string, string> collection = new NonUniqueDictionary <string, string>(); collection.Add("1", "2"); Assert.IsTrue(collection["1"].Contains("2")); }
public void CountTest() { NonUniqueDictionary <string, string> collection = new NonUniqueDictionary <string, string>(); collection.Add("1", "2"); Assert.AreEqual(1, collection.Count); }
public IRecipe InferRecipeFromIngredients() { NonUniqueDictionary <IItemMaterial, int> materials = this.GetMaterialsFromSlots(); IEnumerable <BaseItemType> components = this.FilledSlots.Select(slot => slot.Item.ItemType); IEnumerable <IRecipe> recipes = this.PossibleRecipes.Where(recipe => recipe.CanCraft(materials, components) && recipe.OutputMaterialsMatch(materials)); return(recipes.FirstOrDefault()); }
public void IndexTest() { NonUniqueDictionary <string, string> collection = new NonUniqueDictionary <string, string>(); HashSet <string> set = new HashSet <string> { "1" }; collection.Add(new KeyValuePair <string, HashSet <string> >("0", set)); Assert.AreEqual(set, collection["0"]); }
public CraftingRecipe( NonUniqueDictionary <string, int> requiredMaterials, IEnumerable <BaseItemType> components, IEnumerable <BaseItemType> craftingResults, IEnumerable <BaseItemType> returnResults = null) { this.RequiredMaterials = requiredMaterials; this.RequiredComponents = new List <BaseItemType>(components); this.CraftingResults = craftingResults; this.ReturnResults = returnResults ?? new List <BaseItemType>(); this.Guid = GlobalConstants.GameManager.GUIDManager.AssignGUID(); }
public void Dispose() { List <Guid> recipesKeys = new List <Guid>(this.Recipes.Keys); foreach (Guid key in recipesKeys) { this.Recipes.RemoveAll(key); } this.Recipes = null; this.ValueExtractor = null; }
protected NonUniqueDictionary <IItemMaterial, int> GetMaterialsFromSlots() { NonUniqueDictionary <IItemMaterial, int> returnMaterials = new NonUniqueDictionary <IItemMaterial, int>(); foreach (JoyItemSlot temp in this.FilledSlots) { if (temp is JoyCraftingSlot slot) { returnMaterials.AddRange(slot.Item.ItemType.Materials); } } return(returnMaterials); }
public void Load(Dictionary data) { this.LiveItems = new System.Collections.Generic.Dictionary <Guid, IItemInstance>(); this.QuestRewards = new NonUniqueDictionary <Guid, Guid>(); var items = this.ValueExtractor.GetArrayValuesCollectionFromDictionary <Dictionary>(data, "Items"); foreach (Dictionary itemDict in items) { IItemInstance item = new ItemInstance(); item.Load(itemDict); this.Add(item); } }
public bool OutputMaterialsMatch(NonUniqueDictionary <IItemMaterial, int> materials) { IEnumerable <string> materialNames = materials.Keys.Select(material => material.Name).Distinct(); foreach (var result in this.CraftingResults) { var intersect = result.MaterialNames.Intersect(materialNames).Count(); if (intersect < result.MaterialNames.Count()) { return(false); } } return(true); }
public void Dispose() { this.m_RelationshipTypes = null; this.m_Relationships = null; this.ValueExtractor = null; }
public void InitTest() { NonUniqueDictionary <string, string> collection = new NonUniqueDictionary <string, string>(); Assert.IsNotNull(collection); }
public CraftingRecipeHandler() { this.ValueExtractor = new JSONValueExtractor(); this.Recipes = new NonUniqueDictionary <Guid, IRecipe>(); }
public bool CanCraft(NonUniqueDictionary <IItemMaterial, int> materials, IEnumerable <BaseItemType> components) { bool result = true; foreach (Tuple <string, int> tuple in this.RequiredMaterials) { var recipeMaterials = this.RequiredMaterials .Where(t => t.Item1.Equals( tuple.Item1, StringComparison.OrdinalIgnoreCase)) .ToList(); var resultsList = materials .Where(t => t.Item1.Name.Equals( tuple.Item1, StringComparison.OrdinalIgnoreCase) || t.Item1.HasTag(tuple.Item1)) .ToList(); resultsList = resultsList .OrderByDescending(i => i.Item2) .ToList(); if (resultsList.Count < recipeMaterials.Count) { result = false; break; } int resultsSum = resultsList.Select(t => t.Item2).Sum(); int recipeSum = recipeMaterials.Select(t => t.Item2).Sum(); if (resultsSum < recipeSum) { result = false; break; } } if (!result) { return(result); } var copyComponents = new List <BaseItemType>(components); int leftToFill = this.RequiredComponents.Count; foreach (BaseItemType component in this.RequiredComponents) { if (copyComponents.Any(c => c.Equals(component))) { copyComponents.Remove(component); leftToFill--; } } if (leftToFill != 0) { result = false; } return(result); }
protected IEnumerable <BaseItemType> GetTypesFromJson(IEnumerable <string> files) { List <BaseItemType> items = new List <BaseItemType>(); foreach (string file in files) { JSONParseResult result = JSON.Parse(File.ReadAllText(file)); if (result.Error != Error.Ok) { this.ValueExtractor.PrintFileParsingError(result, file); continue; } if (!(result.Result is Dictionary dictionary)) { GlobalConstants.ActionLog.Log("Failed to parse JSON from " + file + " into a Dictionary.", LogLevel.Warning); continue; } Dictionary itemData = this.ValueExtractor.GetValueFromDictionary <Dictionary>(dictionary, "Items"); List <IdentifiedItem> identifiedItems = new List <IdentifiedItem>(); ICollection <Dictionary> identifiedItemsDicts = this.ValueExtractor.GetArrayValuesCollectionFromDictionary <Dictionary>(itemData, "IdentifiedItems"); foreach (Dictionary identifiedToken in identifiedItemsDicts) { string name = this.ValueExtractor.GetValueFromDictionary <string>(identifiedToken, "Name"); string description = identifiedToken.Contains("Description") ? this.ValueExtractor.GetValueFromDictionary <string>(identifiedToken, "Description") : ""; int value = this.ValueExtractor.GetValueFromDictionary <int>(identifiedToken, "Value"); IEnumerable <Dictionary> materialsDict = this.ValueExtractor.GetArrayValuesCollectionFromDictionary <Dictionary>( identifiedToken, "Materials"); IDictionary <string, int> materials = new System.Collections.Generic.Dictionary <string, int>(); foreach (Dictionary material in materialsDict) { materials.Add( this.ValueExtractor.GetValueFromDictionary <string>(material, "Name"), this.ValueExtractor.GetValueFromDictionary <int>(material, "Value")); } IEnumerable <string> componentNames = this.ValueExtractor.GetArrayValuesCollectionFromDictionary <string>( identifiedToken, "Components"); IEnumerable <IEnumerable <BaseItemType> > components = componentNames.Select(this.GetAllForName); int size = this.ValueExtractor.GetValueFromDictionary <int>(identifiedToken, "Size"); int lightLevel = identifiedToken.Contains("LightLevel") ? this.ValueExtractor.GetValueFromDictionary <int>(identifiedToken, "LightLevel") : 0; int spawnWeight = identifiedToken.Contains("SpawnWeight") ? this.ValueExtractor.GetValueFromDictionary <int>(identifiedToken, "SpawnWeight") : 0; int range = identifiedToken.Contains("Range") ? this.ValueExtractor.GetValueFromDictionary <int>(identifiedToken, "Range") : 1; IEnumerable <string> tags = this.ValueExtractor.GetArrayValuesCollectionFromDictionary <string>(identifiedToken, "Tags"); string tileSet = this.ValueExtractor.GetValueFromDictionary <string>(identifiedToken, "TileSet"); IEnumerable <string> abilityNames = identifiedToken.Contains("Effects") ? this.ValueExtractor.GetArrayValuesCollectionFromDictionary <string>(identifiedToken, "Effects") : new List <string>(); IEnumerable <IAbility> abilities = abilityNames.Select(abilityName => this.AbilityHandler.Get(abilityName)); IEnumerable <string> slots = identifiedToken.Contains("Slots") ? this.ValueExtractor.GetArrayValuesCollectionFromDictionary <string>(identifiedToken, "Slots") : new List <string>(); IEnumerable <string> skills = identifiedToken.Contains("Skill") ? this.ValueExtractor.GetArrayValuesCollectionFromDictionary <string>(identifiedToken, "Skill") : new[] { "none" }; identifiedItems.Add(new IdentifiedItem( name, tags.ToArray(), description, value, abilities.ToArray(), spawnWeight, skills, materials, size, slots.ToArray(), tileSet, range, components, lightLevel)); } List <UnidentifiedItem> unidentifiedItems = new List <UnidentifiedItem>(); if (itemData.Contains("UnidentifiedItems")) { ICollection <Dictionary> unidentifiedItemDicts = this.ValueExtractor.GetArrayValuesCollectionFromDictionary <Dictionary>( itemData, "UnidentifiedItems"); foreach (Dictionary unidentifiedToken in unidentifiedItemDicts) { string name = this.ValueExtractor.GetValueFromDictionary <string>(unidentifiedToken, "Name"); string description = unidentifiedToken.Contains("Description") ? this.ValueExtractor.GetValueFromDictionary <string>(unidentifiedToken, "Description") : ""; string identifiedName = this.ValueExtractor.GetValueFromDictionary <string>(unidentifiedToken, "IdentifiedName"); unidentifiedItems.Add(new UnidentifiedItem(name, description, identifiedName)); } } string actionWord = itemData.Contains("ActionWord") ? this.ValueExtractor.GetValueFromDictionary <string>(itemData, "ActionWord") : "strikes"; this.ObjectIcons.AddSpriteDataFromJson(itemData); foreach (IdentifiedItem identifiedItem in identifiedItems) { var materialCombinations = this.GetMaterialPermutations(identifiedItem.materials); var componentCombinations = identifiedItem.components.CartesianProduct(); NonUniqueDictionary <string, int> craftingMaterials = new NonUniqueDictionary <string, int>( identifiedItem.materials.Select(pair => new Tuple <string, int>(pair.Key, pair.Value))); Guid itemGuid = GlobalConstants.GameManager.GUIDManager.AssignGUID(); foreach (var materials in materialCombinations) { foreach (var components in componentCombinations) { UnidentifiedItem[] possibilities = unidentifiedItems .Where(unidentifiedItem => unidentifiedItem.identifiedName.Equals( identifiedItem.name, StringComparison.OrdinalIgnoreCase)) .ToArray(); UnidentifiedItem selectedItem; if (possibilities.IsNullOrEmpty()) { selectedItem = new UnidentifiedItem( identifiedItem.name, identifiedItem.description, identifiedItem.name); } else { selectedItem = possibilities.GetRandom(); } var materialDict = new NonUniqueDictionary <IItemMaterial, int>(materials); var createdItem = new BaseItemType( itemGuid, identifiedItem.tags, identifiedItem.description, selectedItem.description, selectedItem.name, identifiedItem.name, identifiedItem.slots, identifiedItem.size, materialDict, identifiedItem.skills, actionWord, identifiedItem.weighting, identifiedItem.spriteSheet, range: identifiedItem.range, lightLevel: identifiedItem.lightLevel, components, abilities: identifiedItem.abilities); items.Add(createdItem); this.CraftingRecipeHandler.Add( new CraftingRecipe( craftingMaterials, components, new[] { createdItem })); } } } } return(items); }