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;
                    }
                }
            }
        }
Example #2
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);
 }
Example #3
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);
        }