void IndexEffectRecipes(BaseEntityEffect effect) { // Must have at least one recipe int recipeCount = GetEffectPotionRecipeCount(effect); if (recipeCount == 0) { return; } Debug.LogFormat("Effect '{0}' has {1} potion recipes:", effect.Key, recipeCount); // Index all recipes for this effect for (int i = 0; i < recipeCount; i++) { // Get recipe variant PotionRecipe recipe = GetEffectPotionRecipe(effect, i); if (recipe != null) { // Add potion effect or log error if collision int recipeKey = recipe.GetHashCode(); if (!potionEffectTemplates.ContainsKey(recipeKey)) { potionEffectTemplates.Add(recipeKey, effect); Debug.LogFormat("'{0}' recipe {1} [key={2}] ingredients: {3}", effect.Key, i, recipeKey, recipe.ToString()); } else { Debug.LogErrorFormat("EnityEffectBroker: Already contains potion recipe key {0} for ingredients: {1}", recipeKey, recipe.ToString()); } } } }
void Start() { // Enumerate classes implementing an effect and create an instance to use as factory // TODO: Provide an external method for mods to register custom effects without reflections magicEffectTemplates.Clear(); IEnumerable <BaseEntityEffect> effectTemplates = ReflectiveEnumerator.GetEnumerableOfType <BaseEntityEffect>(); foreach (BaseEntityEffect effect in effectTemplates) { magicEffectTemplates.Add(effect.Key, effect); // Link effect to potion recipe lookup if supported PotionRecipe recipe = GetEffectPotionRecipe(effect); if (recipe != null) { // Add potion effect or log error if collision int recipeKey = recipe.GetHashCode(); if (!potionEffectTemplates.ContainsKey(recipeKey)) { potionEffectTemplates.Add(recipeKey, effect); // TEMP: Output something just to show potion recipe was registered Debug.LogFormat("EnityEffectBroker: Registered effect '{0}' with recipe key '{1}'. Potion ingredients are: {2}", effect.Key, recipeKey, recipe.ToString()); } else { Debug.LogErrorFormat("EnityEffectBroker: Already contains potion recipe key {0} for ingredients: {1}", recipeKey, recipe.ToString()); } } } }
/// <summary> /// Gets IEntityEffect from PotionRecipe. /// </summary> /// <param name="recipe">Input recipe.</param> /// <returns>IEntityEffect if this recipe is linked to an effect, otherwise null.</returns> public IEntityEffect GetPotionRecipeEffect(PotionRecipe recipe) { if (recipe != null) { int recipeKey = recipe.GetHashCode(); if (potionEffectTemplates.ContainsKey(recipeKey)) { return(potionEffectTemplates[recipeKey]); } } return(null); }