Example #1
0
        public static void InvItem_SetupDetails(InvItem __instance)
        {
            bool debug  = RogueFramework.IsDebugEnabled(DebugFlags.Items);
            bool debug2 = RogueFramework.IsDebugEnabled(DebugFlags.Abilities);

            foreach (IHookFactory <InvItem> factory in RogueFramework.ItemFactories)
            {
                if (factory.TryCreate(__instance, out IHook <InvItem> hook))
                {
                    if (debug2 && hook is CustomAbility)
                    {
                        RogueFramework.LogDebug($"Initializing custom ability {hook} ({__instance.invItemName}).");
                    }
                    else if (debug)
                    {
                        if (hook is CustomItem)
                        {
                            RogueFramework.LogDebug($"Initializing custom item {hook} ({__instance.invItemName}).");
                        }
                        else
                        {
                            RogueFramework.LogDebug($"Initializing item hook {hook} for \"{__instance.invItemName}\".");
                        }
                    }
                    __instance.AddHook(hook);
                }
            }
        }
        public static bool CharacterCreation_PushedButton(CharacterCreation __instance, ButtonHelper myButton)
        {
            bool debug = RogueFramework.IsDebugEnabled(DebugFlags.UnlockMenus);

            if (__instance.selectedSpace == "Load")
            {
                if (debug)
                {
                    RogueFramework.LogDebug("Redirecting the button push to the original method.");
                }
                return(true);
            }

            if (debug)
            {
                RogueFramework.LogDebug($"Pressing \"{myButton.myText.text}\" ({myButton.scrollingButtonNum}, {myButton.scrollingButtonType}) button.");
            }

            string            type        = myButton.scrollingButtonUnlock.unlockType;
            List <ButtonData> buttonsData = type == UnlockTypes.Item ? __instance.buttonsDataItems
                                : type == UnlockTypes.Trait ? __instance.buttonsDataTraits
                                : type == UnlockTypes.Ability ? __instance.buttonsDataAbilities
                                : type == UnlockTypes.BigQuest ? __instance.buttonsDataBigQuests : null;

            ButtonData      buttonData = buttonsData[myButton.scrollingButtonNum];
            DisplayedUnlock du         = (DisplayedUnlock)buttonData.__RogueLibsCustom;

            try { du.OnPushedButton(); }
            catch (Exception e) { RogueFramework.LogError(e, "DisplayedUnlock.OnPushedButton", du, du.Menu); }
            __instance.curSelectedButton    = myButton;
            __instance.curSelectedButtonNum = myButton.scrollingButtonNum;
            return(false);
        }
Example #3
0
        public static void StatusEffects_GiveSpecialAbility(StatusEffects __instance)
        {
            if (GameController.gameController.levelType == "HomeBase" &&
                !__instance.agent.isDummy && __instance.agent.agentName != VanillaAgents.MechEmpty)
            {
                return;
            }
            CustomAbility custom = __instance.agent.GetAbility();

            if (custom is null)
            {
                return;
            }

            if (RogueFramework.IsDebugEnabled(DebugFlags.Abilities))
            {
                RogueFramework.LogDebug($"Giving ability {custom} ({__instance.agent.specialAbility}, {__instance.agent.agentName}).");
            }

            try { custom.OnAdded(); }
            catch (Exception e) { RogueFramework.LogError(e, "CustomAbility.OnAdded", custom, __instance.agent); }

            if (custom is IAbilityTargetable)
            {
                __instance.SpecialAbilityInterfaceCheck();
            }
            if (custom is IAbilityRechargeable)
            {
                __instance.RechargeSpecialAbility(custom.ItemInfo.Name);
            }
        }
Example #4
0
        public static void SetupEffectHook(StatusEffect effect, StatusEffects parent)
        {
            bool debug = RogueFramework.IsDebugEnabled(DebugFlags.Effects);

            effect.__RogueLibsContainer = parent;
            foreach (IHookFactory <StatusEffect> factory in RogueFramework.EffectFactories)
            {
                if (factory.TryCreate(effect, out IHook <StatusEffect> hook))
                {
                    if (debug)
                    {
                        if (hook is CustomEffect)
                        {
                            RogueFramework.LogDebug($"Initializing custom effect {hook} ({effect.statusEffectName}, {parent.agent.agentName}).");
                        }
                        else
                        {
                            RogueFramework.LogDebug($"Initializing effect hook {hook} ({effect.statusEffectName}, {parent.agent.agentName}).");
                        }
                    }
                    effect.AddHook(hook);
                    // CustomEffect does not call OnAdded when initialized,
                    // because of the GetStatusEffectTime/Hate patches
                    if (hook is CustomEffect custom)
                    {
                        custom.OnAdded();
                    }
                }
            }
        }
        public static bool ScrollingMenu_PushedButton(ScrollingMenu __instance, ButtonHelper myButton)
        {
            bool debug = RogueFramework.IsDebugEnabled(DebugFlags.UnlockMenus);

            if (__instance.menuType.EndsWith("Configs"))
            {
                if (debug)
                {
                    RogueFramework.LogDebug("Redirecting the button push to the original method.");
                }
                return(true);
            }

            if (debug)
            {
                RogueFramework.LogDebug($"Pressing \"{myButton.myText.text}\" ({myButton.scrollingButtonNum}, {myButton.scrollingButtonType}) button.");
            }

            ButtonData      buttonData = __instance.buttonsData[myButton.scrollingButtonNum];
            DisplayedUnlock du         = (DisplayedUnlock)buttonData.__RogueLibsCustom;

            try { du.OnPushedButton(); }
            catch (Exception e) { RogueFramework.LogError(e, "DisplayedUnlock.OnPushedButton", du, du.Menu); }
            return(false);
        }
Example #6
0
        public static void SetupTraitHook(Trait trait, StatusEffects parent)
        {
            bool debug      = RogueFramework.IsDebugEnabled(DebugFlags.Traits);
            bool updateable = false;

            trait.__RogueLibsContainer = parent;
            foreach (IHookFactory <Trait> factory in RogueFramework.TraitFactories)
            {
                if (factory.TryCreate(trait, out IHook <Trait> hook))
                {
                    if (debug)
                    {
                        if (hook is CustomTrait)
                        {
                            RogueFramework.LogDebug($"Initializing custom trait {hook} ({trait.traitName}, {parent.agent.agentName}).");
                        }
                        else
                        {
                            RogueFramework.LogDebug($"Initializing trait hook {hook} ({trait.traitName}, {parent.agent.agentName}).");
                        }
                    }
                    trait.AddHook(hook);
                    if (hook is CustomTrait && hook is ITraitUpdateable)
                    {
                        updateable = true;
                    }
                }
            }

            if (updateable && parent.agent.name != "DummyAgent" && !parent.agent.name.Contains("Backup"))
            {
                parent.StartCoroutine(parent.UpdateTrait(trait));
                trait.requiresUpdates = true;
            }
        }
Example #7
0
        public static void StatusEffects_PressedSpecialAbility(StatusEffects __instance)
        {
            CustomAbility custom = __instance.agent.GetAbility();

            if (custom is null)
            {
                return;
            }
            if (custom.Item.invItemName != __instance.agent.specialAbility)
            {
                return;
            }

            if (RogueFramework.IsDebugEnabled(DebugFlags.Abilities))
            {
                RogueFramework.LogDebug($"Pressing ability ability {custom} ({__instance.agent.specialAbility}, {__instance.agent.agentName}).");
            }

            try { custom.OnPressed(); }
            catch (Exception e) { RogueFramework.LogError(e, "CustomAbility.OnPressed", custom, __instance.agent); }
            if (custom.Count > 0)
            {
                __instance.agent.inventory.buffDisplay.specialAbilitySlot.MakeNotUsable();
            }
        }
        public static bool ScrollingMenu_SortUnlocks(ScrollingMenu __instance, List <Unlock> myUnlockList, List <Unlock> ___listUnlocks)
        {
            List <DisplayedUnlock> displayedList = myUnlockList.ConvertAll(u => (DisplayedUnlock)u.__RogueLibsCustom);

            if (__instance.menuType == "FreeItems")
            {
                displayedList.RemoveAll(u => u is ItemUnlock itemUnlock && !itemUnlock.IsAvailableInItemTeleporter);
            }

            displayedList.Sort();
            CustomScrollingMenu menu = new CustomScrollingMenu(__instance, displayedList);

            if (RogueFramework.IsDebugEnabled(DebugFlags.UnlockMenus))
            {
                RogueFramework.LogDebug($"Setting up \"{menu.Type}\" menu.");
            }

            ___listUnlocks.Clear();
            ___listUnlocks.AddRange(menu.Unlocks.Select(du => du.Unlock));

            foreach (DisplayedUnlock du in menu.Unlocks)
            {
                du.Menu = menu;
            }

            if (menu.Type == UnlocksMenuType.Loadouts)
            {
                reRollLoadouts.Menu = menu;
                ___listUnlocks.Insert(0, reRollLoadouts.Unlock);
                if (RogueFramework.IsDebugEnabled(DebugFlags.EnableTools))
                {
                    RogueFramework.LogDebug("Adding \"GiveNuggets\" debug tool to the menu.");
                    giveNuggets.Menu = menu;
                    ___listUnlocks.Insert(0, giveNuggets.Unlock);
                }
            }
            if (menu.Type == UnlocksMenuType.MutatorMenu)
            {
                __instance.nuggetSlot.gameObject.SetActive(true);
                clearAllMutators.Menu = menu;
                ___listUnlocks.Insert(0, clearAllMutators.Unlock);
            }
            else if (menu.Type == UnlocksMenuType.RewardsMenu)
            {
                __instance.nuggetSlot.gameObject.SetActive(true);
                // clearAllItems.Menu = menu;
                // ___listUnlocks.Insert(0, clearAllItems.Unlock);
            }
            else if (menu.Type == UnlocksMenuType.TraitsMenu)
            {
                __instance.nuggetSlot.gameObject.SetActive(true);
                // clearAllTraits.Menu = menu;
                // ___listUnlocks.Insert(0, clearAllTraits.Unlock);
            }

            __instance.numButtons = ___listUnlocks.Count;
            return(false);
        }
 public override void OnPushedButton()
 {
     if (RogueFramework.IsDebugEnabled(DebugFlags.UnlockMenus))
     {
         RogueFramework.LogDebug("Added 10 nuggets with the debug tool.");
     }
     gc.unlocks.AddNuggets(10);
     PlaySound(VanillaAudio.BuyItem);
     UpdateMenu();
 }
Example #10
0
        public static void StatusEffects_RemoveStatusEffect(StatusEffect __state)
        {
            CustomEffect effect = __state?.GetHook <CustomEffect>();

            if (__state != null && RogueFramework.IsDebugEnabled(DebugFlags.Effects))
            {
                RogueFramework.LogDebug($"Removing effect {effect} ({__state.statusEffectName}, {__state.GetStatusEffects().agent.agentName}).");
            }
            effect?.OnRemoved();
        }
Example #11
0
        public static void StatusEffects_RemoveTrait(Trait __state)
        {
            CustomTrait trait = __state?.GetHook <CustomTrait>();

            if (__state != null && RogueFramework.IsDebugEnabled(DebugFlags.Traits))
            {
                RogueFramework.LogDebug($"Removing trait {trait} ({__state.traitName}, {__state.GetStatusEffects().agent.agentName}).");
            }
            trait?.OnRemoved();
        }
        public static void ScrollingMenu_OpenScrollingMenu_Prefix(ScrollingMenu __instance, out float __state)
        {
            float x = 1f - __instance.scrollBar.value;

            __state = x * (__instance.numButtons - __instance.numButtonsOnScreen + 1f);
            if (RogueFramework.IsDebugEnabled(DebugFlags.UnlockMenus))
            {
                RogueFramework.LogDebug($"Stored menu's scrolling value of {__state} units.");
            }
        }
Example #13
0
 /// <summary>
 ///   <para>Prevents ghost agents from using items.</para>
 /// </summary>
 /// <param name="e">The item usage event args.</param>
 public static void GhostCheck(OnItemUsingArgs e)
 {
     if (e.User.ghost)
     {
         if (RogueFramework.IsDebugEnabled(DebugFlags.Items))
         {
             RogueFramework.LogDebug("---- Triggered \"Ghost\" inventory check.");
         }
         e.User.gc.audioHandler.Play(e.User, "CantDo");
         e.Cancel = e.Handled = true;
     }
 }
Example #14
0
 public static void Unlocks_LoadInitialUnlocks_Helper(bool dontClear)
 {
     if (dontClear)
     {
         return;
     }
     if (RogueFramework.IsDebugEnabled(DebugFlags.Unlocks))
     {
         RogueFramework.LogDebug("Reloading unlocks.");
     }
     RogueFramework.Unlocks.Clear();
 }
Example #15
0
        /// <summary>
        ///   <para>Adds the specified <typeparamref name="TTrait"/> type to the factory.</para>
        /// </summary>
        /// <typeparam name="TTrait">The <see cref="CustomTrait"/> type to add.</typeparam>
        /// <returns>The added trait's metadata.</returns>
        public TraitInfo AddTrait <TTrait>() where TTrait : CustomTrait, new()
        {
            TraitInfo info = TraitInfo.Get <TTrait>();

            if (RogueFramework.IsDebugEnabled(DebugFlags.Traits))
            {
                RogueFramework.LogDebug($"Created custom trait {typeof(TTrait)} ({info.Name}).");
            }
            traitsDict.Add(info.Name, new TraitEntry {
                Initializer = () => new TTrait(), TraitInfo = info
            });
            return(info);
        }
Example #16
0
 /// <summary>
 ///   <para>Prevents "Electronic" agents from using medicine.</para>
 /// </summary>
 /// <param name="e">The item usage event args.</param>
 public static void OnlyChargeMedicineCheck(OnItemUsingArgs e)
 {
     if (e.User.electronic && e.Item.itemType == ItemTypes.Consumable && e.Item.Categories.Contains("Health"))
     {
         if (RogueFramework.IsDebugEnabled(DebugFlags.Items))
         {
             RogueFramework.LogDebug("---- Triggered \"OnlyChargeMedicine\" inventory check.");
         }
         e.User.SayDialogue("OnlyChargeGivesHealth");
         e.User.gc.audioHandler.Play(e.User, "CantDo");
         e.Cancel = e.Handled = true;
     }
 }
Example #17
0
 /// <summary>
 ///   <para>Prevents agents with full health from consuming healing items.</para>
 /// </summary>
 /// <param name="e">The item usage event args.</param>
 public static void FullHealthCheck(OnItemUsingArgs e)
 {
     if (e.Item.healthChange > 0 && e.User.health == e.User.healthMax)
     {
         if (RogueFramework.IsDebugEnabled(DebugFlags.Items))
         {
             RogueFramework.LogDebug("---- Triggered \"FullHealth\" inventory check.");
         }
         e.User.SayDialogue("HealthFullCantUseItem");
         e.User.gc.audioHandler.Play(e.User, "CantDo");
         e.Cancel = e.Handled = true;
     }
 }
Example #18
0
 /// <summary>
 ///   <para>Prevents "Pea-Brained" agents from using non-Food items.</para>
 /// </summary>
 /// <param name="e">The item usage event args.</param>
 public static void PeaBrainedCheck(OnItemUsingArgs e)
 {
     if (e.Item.itemType != ItemTypes.Food && e.User.HasTrait("CantInteract"))
     {
         if (RogueFramework.IsDebugEnabled(DebugFlags.Items))
         {
             RogueFramework.LogDebug("---- Triggered \"PeaBrained\" inventory check.");
         }
         e.User.SayDialogue("CantInteract");
         e.User.gc.audioHandler.Play(e.User, "CantDo");
         e.Cancel = e.Handled = true;
     }
 }
Example #19
0
 /// <summary>
 ///   <para>Prevents "Oil-Reliant" agents from consuming food.</para>
 /// </summary>
 /// <param name="e">The item usage event args.</param>
 public static void OnlyOilCheck(OnItemUsingArgs e)
 {
     if (e.Item.itemType == ItemTypes.Food && (e.Item.Categories.Contains("Food") || e.Item.Categories.Contains("Alcohol")) &&
         e.User.HasTrait("OilRestoresHealth"))
     {
         if (RogueFramework.IsDebugEnabled(DebugFlags.Items))
         {
             RogueFramework.LogDebug("---- Triggered \"OnlyOil\" inventory check.");
         }
         e.User.SayDialogue("OnlyOilGivesHealth");
         e.User.gc.audioHandler.Play(e.User, "CantDo");
         e.Cancel = e.Handled = true;
     }
 }
Example #20
0
        public static void NameDB_RealAwake(NameDB __instance)
        {
            if (!LanguageService.Languages.TryGetValue(__instance.language, out LanguageCode code))
            {
                code = LanguageCode.English;
            }
            if (RogueFramework.IsDebugEnabled(DebugFlags.Names))
            {
                RogueFramework.LogDebug($"Current language: {LanguageService.GetLanguageName(code)} ({(int)code})");
            }

            LanguageService.NameDB  = __instance;
            LanguageService.Current = code;
        }
Example #21
0
        /// <summary>
        ///   <para>Forcefully unlocks an unlock with the specified <paramref name="unlockName"/> and <paramref name="unlockType"/>.</para>
        /// </summary>
        /// <param name="unlocks">The current unlocks.</param>
        /// <param name="unlockName">The name of the unlock to unlock.</param>
        /// <param name="unlockType">The type of the unlock to unlock.</param>
        /// <exception cref="ArgumentNullException"><paramref name="unlocks"/> is <see langword="null"/>.</exception>
        public static void DoUnlockForced(this Unlocks unlocks, string unlockName, string unlockType)
        {
            if (unlocks is null)
            {
                throw new ArgumentNullException(nameof(unlocks));
            }
            if (RogueFramework.IsDebugEnabled(DebugFlags.Unlocks))
            {
                RogueFramework.LogDebug($"Force-unlocking \"{unlockName}\" ({unlockType})");
            }

            bool prev = AllowUnlocksAnyway;

            AllowUnlocksAnyway = true;
            unlocks.DoUnlock(unlockName, unlockType);
            AllowUnlocksAnyway = prev;
        }
Example #22
0
        public static void RefreshEffect(StatusEffect effect, int newTime)
        {
            CustomEffect custom  = effect.GetHook <CustomEffect>();
            float        oldTime = effect.curTime;

            if (custom is null)
            {
                effect.curTime = newTime;
            }
            else
            {
                custom.OnRefreshed();
            }
            if (RogueFramework.IsDebugEnabled(DebugFlags.Effects))
            {
                RogueFramework.LogDebug($"Refreshed {custom} ({effect.statusEffectName}, {effect.GetStatusEffects().agent.agentName}): {oldTime} > {effect.curTime}.");
            }
        }
Example #23
0
#pragma warning restore CS0618 // Type or member is obsolete
        public static void AddUnlockFull(UnlockWrapper wrapper, bool alreadyLoaded = false)
        {
            try
            {
                // integrating custom unlocks
                Unlock result = alreadyLoaded ? wrapper.Unlock : GameController.gameController.unlocks.AddUnlock(wrapper.Unlock);
                if (wrapper.Unlock != result)
                {
                    if (RogueFramework.IsDebugEnabled(DebugFlags.Unlocks))
                    {
                        RogueFramework.LogDebug($"Loaded state for \"{wrapper.Name}\" ({wrapper.Type}): unlocked - {result.unlocked}, enabled - {!result.notActive}");
                    }

                    List <Unlock> list = GameController.gameController.sessionDataBig.unlocks;
                    list.Remove(result);
                    list.Add(wrapper.Unlock);

                    wrapper.IsUnlocked = result.unlocked;
                    if (!(wrapper is MutatorUnlock))
                    {
                        wrapper.IsEnabled = !result.notActive;
                    }
                }
                wrapper.IsAvailable = wrapper.IsAvailable;
                if (wrapper is IUnlockInCC inCC)
                {
                    inCC.IsAvailableInCC = inCC.IsAvailableInCC;
                }
                if (wrapper is ItemUnlock item)
                {
                    item.IsAvailableInItemTeleporter = item.IsAvailableInItemTeleporter;
                }
                // make sure that the Unlocks are in their appropriate lists
                wrapper.SetupUnlock();
            }
            catch (Exception e)
            {
                RogueFramework.Logger.LogError($"Error setting up {wrapper.Unlock?.unlockName} ({wrapper.Unlock?.unlockType}) unlock.");
                RogueFramework.Logger.LogError(e);
            }
        }
Example #24
0
        private EffectInfo(Type type)
        {
            if (!typeof(CustomEffect).IsAssignableFrom(type))
            {
                throw new ArgumentException($"The specified {nameof(type)} is not a {nameof(CustomEffect)}.", nameof(type));
            }

            EffectNameAttribute attr = type.GetCustomAttributes <EffectNameAttribute>().FirstOrDefault();

            Name = attr?.Name ?? type.Name;

            EffectParametersAttribute parsAttr = type.GetCustomAttributes <EffectParametersAttribute>().FirstOrDefault();

            if (parsAttr is null)
            {
                RogueFramework.LogWarning($"Type {type} does not have a {nameof(EffectParametersAttribute)}!");
            }

            Limitations       = parsAttr?.Limitations ?? EffectLimitations.RemoveOnDeath;
            RemoveOnDeath     = (Limitations & EffectLimitations.RemoveOnDeath) != 0;
            RemoveOnKnockOut  = (Limitations & EffectLimitations.RemoveOnKnockOut) != 0;
            RemoveOnNextLevel = (Limitations & EffectLimitations.RemoveOnNextLevel) != 0;
        }
        public static void ScrollingMenu_RefreshLoadouts(List <Unlock> ___loadoutList)
        {
            bool debug = RogueFramework.IsDebugEnabled(DebugFlags.UnlockMenus);

            if (debug)
            {
                RogueFramework.LogDebug("Refreshing the loadouts.");
            }
            ___loadoutList.RemoveAt(0);
            for (int i = 0; i < ___loadoutList.Count; i++)
            {
                Unlock unlock = ___loadoutList[i];
                if (unlock.__RogueLibsCustom is null)
                {
                    if (debug)
                    {
                        RogueFramework.LogDebug("Hooking up an unhooked unlock.");
                    }
                    Unlock normalized = GameController.gameController.sessionDataBig.unlocks
                                        .Find(u => u.unlockName == unlock.unlockName && u.unlockType == unlock.unlockType);
                    unlock.__RogueLibsCustom = normalized.__RogueLibsCustom;
                }
            }
        }
        public static bool CharacterCreation_SortUnlocks(CharacterCreation __instance, List <Unlock> myUnlockList, string unlockType)
        {
            if (unlockType == UnlockTypes.BigQuest)
            {
                myUnlockList = __instance.gc.sessionDataBig.bigQuestUnlocks;
            }

            List <DisplayedUnlock> displayedList = myUnlockList.Select(u => u.__RogueLibsCustom).OfType <DisplayedUnlock>().ToList();

            if (unlockType == UnlockTypes.Ability || unlockType == UnlockTypes.BigQuest)
            {
                displayedList.RemoveAll(u => u is IUnlockInCC inCC && !inCC.IsAvailableInCC);
            }

            displayedList.Sort();
            CustomCharacterCreation menu = new CustomCharacterCreation(__instance, displayedList);

            if (RogueFramework.IsDebugEnabled(DebugFlags.UnlockMenus))
            {
                RogueFramework.LogDebug($"Setting up \"{menu.Type}\" menu.");
            }

            List <Unlock> listUnlocks = unlockType == UnlockTypes.Item ? __instance.listUnlocksItems
                                : unlockType == UnlockTypes.Trait ? __instance.listUnlocksTraits
                                : unlockType == UnlockTypes.Ability ? __instance.listUnlocksAbilities
                                : unlockType == UnlockTypes.BigQuest ? __instance.listUnlocksBigQuests : null;

            listUnlocks.Clear();
            listUnlocks.AddRange(menu.Unlocks.Select(du => du.Unlock));

            foreach (DisplayedUnlock du in menu.Unlocks)
            {
                du.Menu = menu;
            }

            if (unlockType == UnlockTypes.Item)
            {
                clearAllItems.Menu = menu;
                listUnlocks.Insert(0, clearAllItems.Unlock);
            }
            else if (unlockType == UnlockTypes.Trait)
            {
                clearAllTraits.Menu = menu;
                listUnlocks.Insert(0, clearAllTraits.Unlock);
            }

            if (unlockType == UnlockTypes.Item)
            {
                __instance.numButtonsItems = listUnlocks.Count - 1;
            }
            else if (unlockType == UnlockTypes.Trait)
            {
                __instance.numButtonsTraits = listUnlocks.Count - 1;
            }
            else if (unlockType == UnlockTypes.Ability)
            {
                __instance.numButtonsAbilities = listUnlocks.Count;
            }
            else if (unlockType == UnlockTypes.BigQuest)
            {
                __instance.numButtonsBigQuests = listUnlocks.Count;
            }
            return(false);
        }
Example #27
0
        public static bool InvItem_TargetObject(InvItem __instance, PlayfieldObject otherObject, string combineType, ref bool __result)
        {
            bool       debug           = RogueFramework.IsDebugEnabled(DebugFlags.Items);
            bool       actualCombining = combineType == "Combine";
            CustomItem custom          = __instance.GetHook <CustomItem>();

            if (debug && actualCombining)
            {
                RogueFramework.LogDebug($"Targeting {custom} ({__instance.invItemName}) on {otherObject.objectName}:");
            }

            if (Vector2.Distance(__instance.agent.curPosition, otherObject.curPosition) > 15f &&
                InventoryChecks.IsCheckAllowed(custom, "Distance"))
            {
                if (debug && actualCombining)
                {
                    RogueFramework.LogDebug("---- Triggered \"Distance\" inventory check.");
                    RogueFramework.LogDebug("---- Targeting was prevented by an inventory check.");
                }
                __result = false;
                return(false);
            }
            if ((otherObject as Agent)?.butlerBot == true && InventoryChecks.IsCheckAllowed(custom, "ButlerBot"))
            {
                if (debug && actualCombining)
                {
                    RogueFramework.LogDebug("---- Triggered \"ButlerBot\" inventory check.");
                    RogueFramework.LogDebug("---- Targeting was prevented by an inventory check.");
                }
                __result = false;
                return(false);
            }
            if ((otherObject as Agent)?.mechEmpty == true && InventoryChecks.IsCheckAllowed(custom, "EmptyMech"))
            {
                if (debug && actualCombining)
                {
                    RogueFramework.LogDebug("---- Triggered \"EmptyMech\" inventory check.");
                    RogueFramework.LogDebug("---- Targeting was prevented by an inventory check.");
                }
                __result = false;
                return(false);
            }

            __result = custom is IItemTargetable targetable
                                ? targetable.TargetFilter(otherObject)
                                : new ItemFunctions().TargetObject(__instance, __instance.agent, otherObject, string.Empty);

            if (actualCombining)
            {
                OnItemTargetingArgs args = new OnItemTargetingArgs(__instance, otherObject, __instance.agent);
                if (InventoryChecks.onItemTargeting.Raise(args, custom?.ItemInfo.IgnoredChecks))
                {
                    otherObject = args.Target;
                    using (AgentSwapper swapper = new AgentSwapper(__instance, args.User))
                    {
                        if (custom is IItemTargetable targetable2)
                        {
                            bool success = targetable2.TargetObject(otherObject);
                            if (debug)
                            {
                                RogueFramework.LogDebug($"---- Targeting {(success ? "was successful" : "failed")}.");
                            }
                            if (success)
                            {
                                new ItemFunctions().UseItemAnim(__instance, __instance.agent);
                            }
                        }
                        else
                        {
                            if (debug)
                            {
                                RogueFramework.LogDebug("---- Running the original method.");
                            }
                            new ItemFunctions().TargetObject(__instance, __instance.agent, otherObject, "Combine");
                        }

                        if (__instance.invItemCount < 1 || !__instance.database.InvItemList.Contains(__instance) &&
                            InventoryChecks.IsCheckAllowed(custom, "StopOnZero"))
                        {
                            if (debug)
                            {
                                RogueFramework.LogDebug("---- Triggered \"StopOnZero\" inventory check.");
                            }
                            __instance.agent.mainGUI.invInterface.HideDraggedItem();
                            __instance.agent.mainGUI.invInterface.HideTarget();
                        }
                    }
                }
                else
                {
                    if (debug)
                    {
                        RogueFramework.LogDebug("---- Targeting was prevented by an inventory check.");
                    }
                }
            }
            return(false);
        }
Example #28
0
#pragma warning disable CS0618 // Type or member is obsolete
        public static void InitializeUnlockWrappers()
        {
            GameController gc  = GameController.gameController;
            SessionDataBig sdb = gc.sessionDataBig;

            foreach (Unlock unlock in sdb.unlocks.ToList())
            {
                // wrapping original unlocks
                if (string.IsNullOrEmpty(gc.unlocks.GetSpecialUnlockInfo(unlock.unlockName, unlock)))
                {
                    unlock.cost = -2;
                    if (RogueFramework.IsDebugEnabled(DebugFlags.Unlocks))
                    {
                        RogueFramework.LogDebug($"\"{unlock.unlockName}\" ({unlock.unlockType}) has special unlock conditions.");
                    }
                }

                UnlockWrapper wrapper;
                if (unlock.unlockType == UnlockTypes.Mutator)
                {
                    unlock.unavailable = false;
                    wrapper            = new MutatorUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Item)
                {
                    if (unlock.onlyInCharacterCreation && !unlock.unavailable)
                    {
                        unlock.unavailable = true;
                    }
                    if (!unlock.unavailable && !unlock.onlyInCharacterCreation && !unlock.freeItem)
                    {
                        unlock.onlyInCharacterCreation = unlock.freeItem = true;
                    }
                    wrapper = new ItemUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Trait)
                {
                    if (unlock.onlyInCharacterCreation && !unlock.unavailable)
                    {
                        unlock.unavailable = true;
                    }
                    wrapper = new TraitUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Ability)
                {
                    if (unlock.onlyInCharacterCreation && !unlock.unavailable)
                    {
                        unlock.unavailable = true;
                    }
                    wrapper = new AbilityUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Floor)
                {
                    wrapper = new FloorUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.BigQuest)
                {
                    wrapper = new BigQuestUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Extra)
                {
                    wrapper = new ExtraUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Agent)
                {
                    wrapper = new AgentUnlock(unlock)
                    {
                        IsSSA = unlock.unlockName == VanillaAgents.SuperCop || unlock.unlockName == VanillaAgents.UpperCruster ||
                                unlock.unlockName == VanillaAgents.Supergoon
                    };
                }
                else if (unlock.unlockType == "Achievement")
                {
                    wrapper = new AchievementUnlock(unlock);
                }
                else if (unlock.unlockType == "HomeBase")
                {
                    wrapper = new HomeBaseUnlock(unlock);
                }
                else if (unlock.unlockType == "Loadout")
                {
                    wrapper = new LoadoutUnlock(unlock);
                }
                else
                {
                    RogueFramework.LogError($"Unknown unlock type \"{unlock.unlockName}\" ({unlock.unlockType})");
                    sdb.unlocks.Remove(unlock);
                    continue;
                }
                if (wrapper is IUnlockInCC inCC && !inCC.IsAvailableInCC)
                {
                    inCC.IsAvailableInCC = wrapper.IsAvailable;
                }
                RogueFramework.Unlocks.Add(wrapper);
                AddUnlockFull(wrapper, true);
            }
            FixPrerequisites();
            foreach (UnlockWrapper wrapper in RogueFramework.CustomUnlocks)
            {
                if (RogueFramework.IsDebugEnabled(DebugFlags.Unlocks))
                {
                    RogueFramework.LogDebug($"Initializing custom unlock \"{wrapper.Name}\" ({wrapper.Type}).");
                }
                RogueFramework.Unlocks.Add(wrapper);
                AddUnlockFull(wrapper);
            }
        }
Example #29
0
        public static void InvInterface_TargetAnywhere(InvInterface __instance, Vector2 myPos, bool pressedButton)
        {
            __instance.cursorTextString3.color = Color.white;

            bool    debug   = RogueFramework.IsDebugEnabled(DebugFlags.Items);
            InvItem invItem = __instance.mainGUI.targetItem;

            if (invItem != null)
            {
                CustomItem custom = invItem.GetHook <CustomItem>();
                __instance.cursorHighlightTargetObjects = custom is IItemTargetable;
                if (custom is IItemTargetableAnywhere targetable)
                {
                    if (debug && pressedButton)
                    {
                        RogueFramework.LogDebug($"Targeting {custom} ({invItem.invItemName}) anywhere:");
                    }

                    bool filter = targetable.TargetFilter(myPos);
                    __instance.cursorHighlight = filter;
                    __instance.cursorHighlightTargetAnywhere           = filter;
                    __instance.mainGUI.agent.targetImage.tr.localScale = Vector3.one;

                    CustomTooltip tooltip = targetable.TargetCursorText(myPos);
                    __instance.cursorTextCanvas3.enabled = !string.IsNullOrEmpty(tooltip.Text);
                    __instance.cursorTextString3.text    = tooltip.Text ?? string.Empty;
                    __instance.cursorTextString3.color   = tooltip.Color ?? Color.white;

                    if (pressedButton)
                    {
                        OnItemTargetingAnywhereArgs args = new OnItemTargetingAnywhereArgs(invItem, myPos, invItem.agent);
                        if (InventoryChecks.onItemTargetingAnywhere.Raise(args, custom?.ItemInfo.IgnoredChecks))
                        {
                            myPos = args.Target;
                            using (AgentSwapper swapper = new AgentSwapper(invItem, args.User))
                            {
                                bool success = targetable.TargetPosition(myPos);
                                if (debug)
                                {
                                    RogueFramework.LogDebug($"---- Targeting {(success ? "was successful" : "failed")}.");
                                }
                                if (success)
                                {
                                    new ItemFunctions().UseItemAnim(invItem, invItem.agent);
                                }

                                if (custom.Count < 1 || !custom.Inventory.InvItemList.Contains(custom.Item) &&
                                    InventoryChecks.IsCheckAllowed(custom, "StopOnZero"))
                                {
                                    if (debug)
                                    {
                                        RogueFramework.LogDebug("---- Triggered \"StopOnZero\" inventory check.");
                                    }
                                    __instance.HideDraggedItem();
                                    __instance.HideTarget();
                                }
                            }
                        }
                        else
                        {
                            if (debug)
                            {
                                RogueFramework.LogDebug("---- Targeting was prevented by an inventory check.");
                            }
                        }
                    }
                }
            }
        }
Example #30
0
        public static bool ItemFunctions_UseItem(InvItem item, Agent agent)
        {
            bool       debug  = RogueFramework.IsDebugEnabled(DebugFlags.Items);
            CustomItem custom = item.GetHook <CustomItem>();

            if (custom is IItemTargetable || custom is IItemTargetableAnywhere)
            {
                if (debug)
                {
                    RogueFramework.LogDebug($"Showing target for {custom} ({item.invItemName}).");
                }
                item.invInterface.ShowOrHideTarget(item);
                return(false);
            }

            if (debug)
            {
                RogueFramework.LogDebug($"Using {custom} ({item.invItemName}):");
            }

            Agent           originalAgent = agent;
            OnItemUsingArgs args          = new OnItemUsingArgs(item, agent);

            if (InventoryChecks.onItemUsing.Raise(args, custom?.ItemInfo.IgnoredChecks))
            {
                agent = args.User;
                // in case an inventory check redirected the use of an item on someone else
                using (AgentSwapper swapper = new AgentSwapper(item, agent))
                {
                    if (agent.localPlayer)
                    {
                        if (!originalAgent.inventory.HasItem(item.invItemName) &&
                            originalAgent.inventory.equippedSpecialAbility?.invItemName != item.invItemName)
                        {
                            return(false);
                        }
                        else if (!item.used && (item.Categories.Contains(RogueCategories.Usable) || item.itemType == ItemTypes.Consumable))
                        {
                            item.used = true;
                            if (agent.isPlayer > 0)
                            {
                                agent.gc.sessionData.endStats[agent.isPlayer].itemsUsed++;
                            }
                        }
                    }
                    // if it's not a custom item, run the original method
                    if (!(custom is IItemUsable usable))
                    {
                        if (debug)
                        {
                            RogueFramework.LogDebug("---- Running the original method.");
                        }
                        return(true);
                    }

                    bool success = usable.UseItem();
                    if (debug)
                    {
                        RogueFramework.LogDebug($"---- Usage {(success ? "was successful" : "failed")}.");
                    }
                    if (success)
                    {
                        new ItemFunctions().UseItemAnim(item, agent);
                    }
                }
            }
            else
            {
                if (debug)
                {
                    RogueFramework.LogDebug("---- Usage was prevented by an inventory check.");
                }
            }
            return(false);
        }