Ignoring local player's pointers option

Settings hide
This commit is contained in:
SDraw 2023-04-15 13:51:12 +03:00
parent fa5a0334b9
commit f983f2909c
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
3 changed files with 28 additions and 2 deletions

View file

@ -16,6 +16,7 @@ Optional mod's settings with [BTKUILib](https://github.com/BTK-Development/BTKUI
* **Use gravity:** enables/disables gravity for ragdoll; `true` by default. * **Use gravity:** enables/disables gravity for ragdoll; `true` by default.
* Note: Forcibly enabled in worlds that don't allow flight. * Note: Forcibly enabled in worlds that don't allow flight.
* **Pointers reaction:** enables ragdoll state when player collides with trigger colliders with CVRPointer component of `ragdoll` type (avatars, props and world included); `true` by default. * **Pointers reaction:** enables ragdoll state when player collides with trigger colliders with CVRPointer component of `ragdoll` type (avatars, props and world included); `true` by default.
* **Ignore local pointers:** enables/disables ignoring of CVRPointer components of `ragdoll` type on local player's avatar; `true` by default.
* **Combat reaction:** enables ragdoll state upon death in worlds with combat system; `true` by default. * **Combat reaction:** enables ragdoll state upon death in worlds with combat system; `true` by default.
* **Auto recover:** enables automatic recovering after specific time delay; `false` by default. * **Auto recover:** enables automatic recovering after specific time delay; `false` by default.
* **Velocity multiplier:** velocity force multiplier based on player's movement direction; `2.0` by default. * **Velocity multiplier:** velocity force multiplier based on player's movement direction; `2.0` by default.

View file

@ -1,4 +1,5 @@
using ABI.CCK.Components; using ABI.CCK.Components;
using ABI_RC.Core.Player;
using UnityEngine; using UnityEngine;
namespace ml_prm namespace ml_prm
@ -32,7 +33,7 @@ namespace ml_prm
void OnTriggerEnter(Collider p_other) void OnTriggerEnter(Collider p_other)
{ {
CVRPointer l_pointer = p_other.GetComponent<CVRPointer>(); CVRPointer l_pointer = p_other.GetComponent<CVRPointer>();
if((l_pointer != null) && (l_pointer.type == "ragdoll") && (m_lastTrigger != p_other)) if((l_pointer != null) && (l_pointer.type == "ragdoll") && !IsIgnored(l_pointer.transform) && (m_lastTrigger != p_other))
{ {
m_lastTrigger = p_other; m_lastTrigger = p_other;
m_triggered = true; m_triggered = true;
@ -51,5 +52,10 @@ namespace ml_prm
m_triggered = false; m_triggered = false;
return l_state; return l_state;
} }
static bool IsIgnored(Transform p_transform)
{
return (Settings.IgnoreLocal && (p_transform.root == PlayerSetup.Instance.transform));
}
} }
} }

View file

@ -16,6 +16,7 @@ namespace ml_prm
AngularDrag, AngularDrag,
Gravity, Gravity,
PointersReaction, PointersReaction,
IgnoreLocal,
CombatReaction, CombatReaction,
AutoRecover, AutoRecover,
RecoverDelay RecoverDelay
@ -27,6 +28,7 @@ namespace ml_prm
RestorePosition, RestorePosition,
Gravity, Gravity,
PointersReaction, PointersReaction,
IgnoreLocal,
CombatReaction, CombatReaction,
AutoRecover, AutoRecover,
VelocityMultiplier, VelocityMultiplier,
@ -42,6 +44,7 @@ namespace ml_prm
public static float AngularDrag { get; private set; } = 2f; public static float AngularDrag { get; private set; } = 2f;
public static bool Gravity { get; private set; } = true; public static bool Gravity { get; private set; } = true;
public static bool PointersReaction { get; private set; } = true; public static bool PointersReaction { get; private set; } = true;
public static bool IgnoreLocal { get; private set; } = true;
public static bool CombatReaction { get; private set; } = true; public static bool CombatReaction { get; private set; } = true;
public static bool AutoRecover { get; private set; } = false; public static bool AutoRecover { get; private set; } = false;
public static float RecoverDelay { get; private set; } = 3f; public static float RecoverDelay { get; private set; } = 3f;
@ -54,6 +57,7 @@ namespace ml_prm
static public event Action<float> AngularDragChange; static public event Action<float> AngularDragChange;
static public event Action<bool> GravityChange; static public event Action<bool> GravityChange;
static public event Action<bool> PointersReactionChange; static public event Action<bool> PointersReactionChange;
static public event Action<bool> IgnoreLocalChange;
static public event Action<bool> CombatReactionChange; static public event Action<bool> CombatReactionChange;
static public event Action<bool> AutoRecoverChange; static public event Action<bool> AutoRecoverChange;
static public event Action<float> RecoverDelayChange; static public event Action<float> RecoverDelayChange;
@ -65,7 +69,7 @@ namespace ml_prm
internal static void Init() internal static void Init()
{ {
ms_category = MelonLoader.MelonPreferences.CreateCategory("PRM"); ms_category = MelonLoader.MelonPreferences.CreateCategory("PRM", null, true);
ms_entries = new List<MelonLoader.MelonPreferences_Entry>() ms_entries = new List<MelonLoader.MelonPreferences_Entry>()
{ {
ms_category.CreateEntry(ModSetting.Hotkey.ToString(), Hotkey), ms_category.CreateEntry(ModSetting.Hotkey.ToString(), Hotkey),
@ -75,6 +79,7 @@ namespace ml_prm
ms_category.CreateEntry(ModSetting.AngularDrag.ToString(), AngularDrag), ms_category.CreateEntry(ModSetting.AngularDrag.ToString(), AngularDrag),
ms_category.CreateEntry(ModSetting.Gravity.ToString(), Gravity), ms_category.CreateEntry(ModSetting.Gravity.ToString(), Gravity),
ms_category.CreateEntry(ModSetting.PointersReaction.ToString(), PointersReaction), ms_category.CreateEntry(ModSetting.PointersReaction.ToString(), PointersReaction),
ms_category.CreateEntry(ModSetting.IgnoreLocal.ToString(), IgnoreLocal),
ms_category.CreateEntry(ModSetting.CombatReaction.ToString(), CombatReaction), ms_category.CreateEntry(ModSetting.CombatReaction.ToString(), CombatReaction),
ms_category.CreateEntry(ModSetting.AutoRecover.ToString(), AutoRecover), ms_category.CreateEntry(ModSetting.AutoRecover.ToString(), AutoRecover),
ms_category.CreateEntry(ModSetting.RecoverDelay.ToString(), RecoverDelay) ms_category.CreateEntry(ModSetting.RecoverDelay.ToString(), RecoverDelay)
@ -87,6 +92,7 @@ namespace ml_prm
AngularDrag = Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f); AngularDrag = Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f);
Gravity = (bool)ms_entries[(int)ModSetting.Gravity].BoxedValue; Gravity = (bool)ms_entries[(int)ModSetting.Gravity].BoxedValue;
PointersReaction = (bool)ms_entries[(int)ModSetting.PointersReaction].BoxedValue; PointersReaction = (bool)ms_entries[(int)ModSetting.PointersReaction].BoxedValue;
IgnoreLocal = (bool)ms_entries[(int)ModSetting.IgnoreLocal].BoxedValue;
CombatReaction = (bool)ms_entries[(int)ModSetting.CombatReaction].BoxedValue; CombatReaction = (bool)ms_entries[(int)ModSetting.CombatReaction].BoxedValue;
AutoRecover = (bool)ms_entries[(int)ModSetting.AutoRecover].BoxedValue; AutoRecover = (bool)ms_entries[(int)ModSetting.AutoRecover].BoxedValue;
RecoverDelay = Mathf.Clamp((float)ms_entries[(int)ModSetting.RecoverDelay].BoxedValue, 1f, 10f); RecoverDelay = Mathf.Clamp((float)ms_entries[(int)ModSetting.RecoverDelay].BoxedValue, 1f, 10f);
@ -141,6 +147,14 @@ namespace ml_prm
PointersReactionChange?.Invoke(state); PointersReactionChange?.Invoke(state);
}; };
ms_uiElements.Add(l_categoryMod.AddToggle("Ignore local pointers", "Ignore local avatar's CVRPointer components of 'ragdoll' type", IgnoreLocal));
(ms_uiElements[(int)UiElementIndex.IgnoreLocal] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) =>
{
IgnoreLocal = state;
ms_entries[(int)ModSetting.IgnoreLocal].BoxedValue = state;
IgnoreLocalChange?.Invoke(state);
};
ms_uiElements.Add(l_categoryMod.AddToggle("Combat reaction", "Ragdoll upon combat system death", CombatReaction)); ms_uiElements.Add(l_categoryMod.AddToggle("Combat reaction", "Ragdoll upon combat system death", CombatReaction));
(ms_uiElements[(int)UiElementIndex.CombatReaction] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) => (ms_uiElements[(int)UiElementIndex.CombatReaction] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) =>
{ {
@ -211,6 +225,11 @@ namespace ml_prm
(ms_uiElements[(int)UiElementIndex.PointersReaction] as BTKUILib.UIObjects.Components.ToggleButton).ToggleValue = true; (ms_uiElements[(int)UiElementIndex.PointersReaction] as BTKUILib.UIObjects.Components.ToggleButton).ToggleValue = true;
PointersReactionChange?.Invoke(true); PointersReactionChange?.Invoke(true);
IgnoreLocal = true;
ms_entries[(int)ModSetting.IgnoreLocal].BoxedValue = true;
(ms_uiElements[(int)UiElementIndex.IgnoreLocal] as BTKUILib.UIObjects.Components.ToggleButton).ToggleValue = true;
IgnoreLocalChange?.Invoke(true);
CombatReaction = true; CombatReaction = true;
ms_entries[(int)ModSetting.CombatReaction].BoxedValue = true; ms_entries[(int)ModSetting.CombatReaction].BoxedValue = true;
(ms_uiElements[(int)UiElementIndex.CombatReaction] as BTKUILib.UIObjects.Components.ToggleButton).ToggleValue = true; (ms_uiElements[(int)UiElementIndex.CombatReaction] as BTKUILib.UIObjects.Components.ToggleButton).ToggleValue = true;