public PandaResearchable(IPandaResearch pandaResearch, int currentLevel) { Conditions = new List <IResearchableCondition>(); RecipeUnlocks = new List <RecipeUnlock>(); Dependencies = new List <string>(); try { List <IResearchableCondition> researchableConditions; if (pandaResearch.Conditions != null && (pandaResearch.Conditions.TryGetValue(currentLevel, out researchableConditions) || pandaResearch.Conditions.TryGetValue(0, out researchableConditions))) { Conditions.AddRange(researchableConditions); } List <string> dependancies = null; if (pandaResearch.Dependancies != null && !pandaResearch.Dependancies.TryGetValue(currentLevel, out dependancies)) { pandaResearch.Dependancies.TryGetValue(0, out dependancies); } Initialize(currentLevel, pandaResearch.name, pandaResearch.BaseValue, pandaResearch.IconDirectory, dependancies, pandaResearch.BaseIterationCount, pandaResearch.AddLevelToName); List <InventoryItem> inventoryItems; if (pandaResearch.RequiredItems != null && (pandaResearch.RequiredItems.TryGetValue(currentLevel, out inventoryItems) || pandaResearch.RequiredItems.TryGetValue(0, out inventoryItems))) { AddCraftingCondition(inventoryItems, currentLevel); } List <RecipeUnlock> listUnlocks; if (pandaResearch.Unlocks != null && (pandaResearch.Unlocks.TryGetValue(currentLevel, out listUnlocks) || pandaResearch.Unlocks.TryGetValue(0, out listUnlocks))) { RecipeUnlocks.AddRange(listUnlocks); } Register(currentLevel, pandaResearch.name); } catch (NullReferenceException nullRef) { APILogger.LogToFile(nullRef.StackTrace); APILogger.LogToFile(nullRef.Message); APILogger.LogError(nullRef); } catch (Exception ex) { APILogger.LogError(ex); } }
public PandaResearchable(IPandaResearch pandaResearch, int currentLevel) { Conditions = new List <IResearchableCondition>(); RecipeUnlocks = new List <RecipeUnlock>(); Dependencies = new List <string>(); AdditionalClientUnlocks = new List <RecipeUnlockClient>(); try { List <IResearchableCondition> researchableConditions; if (pandaResearch.Conditions != null && (pandaResearch.Conditions.TryGetValue(currentLevel, out researchableConditions) || pandaResearch.Conditions.TryGetValue(0, out researchableConditions))) { foreach (var condition in researchableConditions) { if (condition is HappinessCondition happinessCondition) { if (ServerManager.WorldSettingsReadOnly.EnableHappiness) { Conditions.Add(condition); } } else { Conditions.Add(condition); } } } List <string> dependancies = null; if (pandaResearch.Dependancies != null && !pandaResearch.Dependancies.TryGetValue(currentLevel, out dependancies)) { pandaResearch.Dependancies.TryGetValue(0, out dependancies); } Initialize(currentLevel, pandaResearch.name, pandaResearch.BaseValue, pandaResearch.IconDirectory, dependancies, pandaResearch.BaseIterationCount, pandaResearch.AddLevelToName); List <InventoryItem> inventoryItems; if (pandaResearch.RequiredItems != null && (pandaResearch.RequiredItems.TryGetValue(currentLevel, out inventoryItems) || pandaResearch.RequiredItems.TryGetValue(0, out inventoryItems))) { AddCraftingCondition(inventoryItems, currentLevel); } List <RecipeUnlock> listUnlocks; if (pandaResearch.Unlocks != null && (pandaResearch.Unlocks.TryGetValue(currentLevel, out listUnlocks) || pandaResearch.Unlocks.TryGetValue(0, out listUnlocks))) { RecipeUnlocks.AddRange(listUnlocks); } List <(string, RecipeUnlockClient.EType)> additionalUnlocks; if (pandaResearch.AdditionalUnlocks != null && (pandaResearch.AdditionalUnlocks.TryGetValue(currentLevel, out additionalUnlocks) || pandaResearch.AdditionalUnlocks.TryGetValue(0, out additionalUnlocks))) { AdditionalClientUnlocks.AddRange(additionalUnlocks.Select(tuple => { if (tuple.Item2 == RecipeUnlockClient.EType.Recipe) { return(new RecipeUnlockClient { Payload = new Recipes.RecipeKey(tuple.Item1).Index, UnlockType = tuple.Item2 }); } else if (tuple.Item2 == RecipeUnlockClient.EType.NPCType) { return(new RecipeUnlockClient { Payload = NPC.NPCType.GetByKeyNameOrDefault(tuple.Item1).Type, UnlockType = tuple.Item2 }); } else { throw new ArgumentOutOfRangeException("type", tuple.Item2, "unexpected recipe unlock type"); } })); } APILogger.LogToFile($"PandaResearch Added: {pandaResearch.name} Level {currentLevel}"); } catch (NullReferenceException nullRef) { APILogger.LogToFile(nullRef.StackTrace); APILogger.LogToFile(nullRef.Message); APILogger.LogError(nullRef); } catch (Exception ex) { APILogger.LogError(ex); } }