コード例 #1
0
 internal static bool AddRecipeToList_Pre(Player player, Recipe recipe, ItemDrop.ItemData item, ref bool canCraft)
 {
     if (!player.NoCostCheat() && SkillRequirement.skillRequirements.ContainsKey(recipe.name))
     {
         canCraft = SkillRequirement.GoodEnough(player, recipe);
     }
     return(true);
 }
コード例 #2
0
 internal static bool AddKnownRecipe_Pre(ref Player __instance, Recipe recipe)
 {
     if (!SkillRequirement.skillRequirements.ContainsKey(recipe.name) || SkillRequirement.GoodEnough(__instance, recipe))
     {
         return(true);
     }
     return(false);
 }
コード例 #3
0
 internal static void OnSkillLevelup_Post(ref Player __instance, Skills.SkillType skill, float level)
 {
     foreach (var recipe in SkillRequirement.GetRecipesToLearnForSkillAndLevel(skill, level))
     {
         if (DoesPlayerKnowsAllMaterials(__instance, recipe) && !__instance.IsRecipeKnown(recipe.name))
         {
             __instance.AddKnownRecipe(recipe);
         }
     }
 }
コード例 #4
0
        internal static bool GoodEnough(Player player, Recipe recipe)
        {
            if (!skillRequirements.ContainsKey(recipe.name))
            {
                return(true);
            }
            SkillRequirement skillRecipe = skillRequirements[recipe.name];
            Skills           skills      = player.GetSkills();
            Dictionary <Skills.SkillType, Skills.Skill> m_skillData = AccessTools.Field(typeof(Skills), "m_skillData").GetValue(skills) as Dictionary <Skills.SkillType, Skills.Skill>;

            if (m_skillData.ContainsKey(skillRecipe.m_skill))
            {
                Skills.Skill requiredSkill = m_skillData[skillRecipe.m_skill];
                return(requiredSkill.m_level >= skillRecipe.m_requiredLevel);
            }
            return(false);
        }
コード例 #5
0
 public void Awake()
 {
     SkilledCraftingConfig.Init(Config);
     if (SkilledCraftingConfig.modEnabled.Value)
     {
         SkillRequirement.InitAll();
         Harmony.CreateAndPatchAll(typeof(PatchInventoryGui), null);
         Harmony.CreateAndPatchAll(typeof(PatchSkillsDialog), null);
         if (SkilledCraftingConfig.overrideRecipeDiscovery.Value)
         {
             Harmony.CreateAndPatchAll(typeof(PatchPlayerRecipeDiscovery), null);
         }
         if (SkilledCraftingConfig.restrictItemUsage.Value)
         {
             Harmony.CreateAndPatchAll(typeof(PatchPlayerItemUsageRestriction), null);
         }
     }
 }
コード例 #6
0
        internal static void UpdateRecipe_Post(ref InventoryGui __instance, Player player)
        {
            Recipe selectedRecipe = ((KeyValuePair <Recipe, ItemDrop.ItemData>)AccessTools.Field(typeof(InventoryGui), "m_selectedRecipe").GetValue(__instance)).Key;

            if (selectedRecipe && SkillRequirement.skillRequirements.ContainsKey(selectedRecipe.name))
            {
                SkillRequirement skillRecipe = SkillRequirement.skillRequirements[selectedRecipe.name];
                Dictionary <Skills.SkillType, Skills.Skill> m_skillData = AccessTools.Field(typeof(Skills), "m_skillData").GetValue(player.GetSkills()) as Dictionary <Skills.SkillType, Skills.Skill>;
                if (m_skillData.ContainsKey(skillRecipe.m_skill))
                {
                    string message = $"Requires Lvl {skillRecipe.m_requiredLevel} in {SkillRequirement.GetSkillName(skillRecipe.m_skill)}";
                    __instance.m_recipeDecription.text += Localization.instance.Localize($"\n\n{message}\n");
                    if (__instance.m_craftButton.interactable && !SkillRequirement.GoodEnough(player, selectedRecipe))
                    {
                        __instance.m_craftButton.GetComponent <UITooltip>().m_text = message;
                        __instance.m_craftButton.interactable = false;
                    }
                }
            }
        }
コード例 #7
0
 internal static bool PlayerAttackInput_Pre(ref Player __instance, float dt)
 {
     if (__instance)
     {
         ItemDrop.ItemData currentWeapon = __instance.GetCurrentWeapon();
         if (currentWeapon != null)
         {
             if (ObjectDB.instance)
             {
                 List <Recipe> recipes = ObjectDB.instance.m_recipes;
                 if (recipes != null)
                 {
                     Recipe recipe = recipes
                                     .Where(r => r.m_item != null &&
                                            r.m_item.m_itemData != null &&
                                            r.m_item.m_itemData.m_shared != null &&
                                            r.m_item.m_itemData.m_shared.m_name.Equals(currentWeapon.m_shared.m_name))
                                     .FirstOrDefault();
                     if (recipe && !SkillRequirement.GoodEnough(__instance, recipe))
                     {
                         SkillRequirement skillRequirement = SkillRequirement.skillRequirements[recipe.name];
                         string           message          = $"Need level {skillRequirement.m_requiredLevel} in {SkillRequirement.GetSkillName(skillRequirement.m_skill)} to use {currentWeapon.m_shared.m_name}";
                         MessageHud.instance.ShowMessage(MessageHud.MessageType.TopLeft, message);
                         if (!lastCurrentWeapon.Equals(currentWeapon.m_shared.m_name))
                         {
                             MessageHud.instance.ShowMessage(MessageHud.MessageType.Center, message);
                             lastCurrentWeapon = currentWeapon.m_shared.m_name;
                         }
                         return(false);
                     }
                 }
             }
             lastCurrentWeapon = currentWeapon.m_shared.m_name;
         }
     }
     return(true);
 }
コード例 #8
0
        internal static void Setup_Post(ref SkillsDialog __instance, Player player)
        {
            List <GameObject> elements = AccessTools.Field(typeof(SkillsDialog), "m_elements").GetValue(__instance) as List <GameObject>;

            foreach (GameObject gameObject in elements)
            {
                Dictionary <Skills.SkillType, Skills.Skill> skillData = AccessTools.Field(typeof(Skills), "m_skillData").GetValue(player.GetSkills()) as Dictionary <Skills.SkillType, Skills.Skill>;
                Skills.Skill skill = skillData
                                     .Where(sd => Utils.FindChild(gameObject.transform, "name").GetComponent <Text>().text.ToLower().Contains(SkillRequirement.GetSkillName(sd.Key).ToLower()))
                                     .Select(sd => sd.Value).FirstOrDefault();
                if (skill != null)
                {
                    string message = GetMessage(__instance, player, skill, gameObject);
                    var    tooltip = gameObject.GetComponentInChildren <UITooltip>();
                    tooltip.m_text += $"\n{message}";
                    Image img = tooltip.m_tooltipPrefab.GetComponentInChildren <Image>(true);
                    if (img && !string.IsNullOrEmpty(message))
                    {
                        img.gameObject.transform.localScale     = new Vector3(1f, 2.1f, 1f);
                        img.gameObject.transform.localPosition += new Vector3(0f, 15f);
                        Text text = tooltip.m_tooltipPrefab.GetComponentInChildren <Text>(true);
                        if (text)
                        {
                            text.gameObject.transform.localPosition += new Vector3(0f, 15f);
                        }
                    }
                }
            }
            AccessTools.Field(typeof(SkillsDialog), "m_elements").SetValue(__instance, elements);
        }