using System.Collections.Generic; using System.Linq; namespace Harmony.GUIWindowManagerPatches { [HarmonyPatch(typeof(GUIWindowManager))] [HarmonyPatch("CloseAllOpenWindows")] [HarmonyPatch(new Type[] { typeof(GUIWindow), typeof(bool) })] public class CloseAllOpenWindowsPatch { public static bool Prefix(GUIWindowManager __instance, ref bool __result, GUIWindow _exceptThis, bool _fromEsc, List ___windows ) { bool result = false; for (int i = 0; i < ___windows.Count; i++) { GUIWindow guiwindow = ___windows[i]; if (guiwindow.Id == "InformationPreview" || guiwindow.Id == "SelectClass") { return false; } if (guiwindow.isModal && (_exceptThis == null || _exceptThis != guiwindow)) { __instance.Close(guiwindow, _fromEsc); __result = true; } } __result = result; return false; } } [HarmonyPatch(typeof(GUIWindowManager))] [HarmonyPatch("Open")] [HarmonyPatch(new Type[] { typeof(GUIWindow), typeof(bool), typeof(bool), typeof(bool) })] public class OpenPatch { public static bool Prefix(GUIWindowManager __instance, GUIWindow _w, bool _bModal, bool _bIsNotEscClosable, bool _bCloseAllOpenWindows, Dictionary ___nameToWindowMap ) { if (__instance.IsWindowOpen("InformationPreview") || __instance.IsWindowOpen("SelectClass") ) { return false; } //Log.Out("GUIWindowManagerPatches-Open START"); /*foreach (string key in ___nameToWindowMap.Keys) { Log.Out("GUIWindowManagerPatches-Open window: " + key); }*/ if (___nameToWindowMap.ContainsKey("backpack") && _w == ___nameToWindowMap["backpack"]) { EntityPlayerLocal ___entityPlayerLocal = GameManager.Instance.World.GetPrimaryPlayer(); bool isValid = false; if (___entityPlayerLocal.inventory.holdingItem != null) { bool bRanged = ___entityPlayerLocal.inventory.holdingItem.ItemTags.ToString().ToLower().Contains("ranged"); bool bMelee = ___entityPlayerLocal.inventory.holdingItem.ItemTags.ToString().ToLower().Contains("melee"); bool bAmmo = ___entityPlayerLocal.inventory.holdingItem.ItemTags.ToString().ToLower().Contains("ammo"); bool bDrone = ___entityPlayerLocal.inventory.holdingItem.ItemTags.ToString().ToLower().Contains("drone"); if ((bRanged || bMelee) && !bAmmo && !bDrone) { List tagNames = ___entityPlayerLocal.inventory.holdingItem.ItemTags.GetTagNames(); float activeClassID = ___entityPlayerLocal.Buffs.GetCustomVar("$ActiveClass_FR"); //Log.Out("GUIWindowManagerPatches-Open item: " + ___entityPlayerLocal.inventory.holdingItem.GetItemName()); //Log.Out("GUIWindowManagerPatches-Open bMelee: " + bMelee); //Log.Out("GUIWindowManagerPatches-Open bRanged: " + bRanged); if (bRanged) { bMelee = false; } RebirthUtilities.SetAuraChance(ItemClass.GetItem(___entityPlayerLocal.inventory.holdingItem.GetItemName(), false), ___entityPlayerLocal.inventory.holdingItem.GetItemName(), ___entityPlayerLocal.entityId, activeClassID, -1, false, bMelee); isValid = true; } } //Log.Out("GUIWindowManagerPatches-Open isValid: " + isValid); if (!isValid) { for (int i = 0; i < RebirthVariables.localAuraChances.Count; i++) { string auraKey = RebirthVariables.localAuraChances.ElementAt(i).Key; float baseChance = 0; int auraProgressionLevel = 0; bool isOwner = false; foreach (BuffValue buffValue in ___entityPlayerLocal.Buffs.ActiveBuffs) { if (buffValue != null && buffValue.BuffClass != null) { BuffClass buffClass = buffValue.BuffClass; if (buffClass.Name.ToLower().Contains(("FuriousRamsayBuff" + auraKey + "Aura").ToLower())) { if (buffClass.Name.ToLower() == ("FuriousRamsayBuff" + auraKey + "Aura").ToLower()) { string progression = RebirthVariables.localAuras[auraKey].progressionName; ProgressionValue auraProgressionValue = ___entityPlayerLocal.Progression.GetProgressionValue(progression); auraProgressionLevel = auraProgressionValue.Level; isOwner = true; } else { auraProgressionLevel = int.Parse(buffClass.Name.ToLower().Replace(("FuriousRamsayBuff" + auraKey + "Aura").ToLower(), "")); } break; } } } float chance = 10; if (!isOwner) { chance *= 0.5f; } baseChance = auraProgressionLevel * RebirthVariables.localAuras[auraKey].baseChancePerLevel; if (RebirthVariables.localAuras[auraKey].overrideChance) { baseChance = chance * RebirthVariables.localAuras[auraKey].baseChancePerLevel; } RebirthVariables.localConstants["$varFuriousRamsay" + auraKey + "Aura_Cst"] = 0f; RebirthVariables.localConstants["$varFuriousRamsay" + auraKey + "AuraBase_Cst"] = baseChance; RebirthVariables.localConstants["$varFuriousRamsay" + auraKey + "AuraBase2_Cst"] = baseChance * 2; //Log.Out("GUIWindowManagerPatches-Open baseChance: " + baseChance); } } } return true; } } }