mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
Merge branch 'refs/heads/dev'
This commit is contained in:
commit
f1639a784d
20 files changed
+299
-145
No files matched your search
@@ -1,29 +0,0 @@
|
||||
using MiraAPI.Example.Modifiers;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Buttons;
|
||||
|
||||
[RegisterButton]
|
||||
public class ExampleButton : CustomActionButton
|
||||
{
|
||||
public override string Name => "Example Button";
|
||||
public override float Cooldown => 5f;
|
||||
public override float EffectDuration => 0f;
|
||||
public override int MaxUses => 5;
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
public override ButtonLocation Location => ButtonLocation.BottomRight;
|
||||
|
||||
protected override void OnClick()
|
||||
{
|
||||
Logger<ExamplePlugin>.Info("Example button clicked!");
|
||||
}
|
||||
|
||||
public override bool Enabled(RoleBehaviour role)
|
||||
{
|
||||
return PlayerControl.LocalPlayer.HasModifier<GameModifierExample>();
|
||||
}
|
||||
}
|
||||
+13
-9
@@ -1,20 +1,24 @@
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Example.Modifiers.Freezer;
|
||||
using MiraAPI.Example.Roles;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Buttons;
|
||||
namespace MiraAPI.Example.Buttons.Freezer;
|
||||
|
||||
public class ExampleTargetButton : CustomActionButton<PlayerControl>
|
||||
[RegisterButton]
|
||||
public class FreezeButton : CustomActionButton<PlayerControl>
|
||||
{
|
||||
public override string Name => "Shoot";
|
||||
public override float Cooldown => 0f;
|
||||
public override string Name => "Freeze";
|
||||
public override float Cooldown => 5f;
|
||||
public override float EffectDuration => 0f;
|
||||
public override int MaxUses => 0;
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
|
||||
protected override void OnClick()
|
||||
{
|
||||
PlayerControl.LocalPlayer.CmdCheckMurder(Target);
|
||||
Target.AddModifier<FreezeModifier>();
|
||||
}
|
||||
|
||||
public override PlayerControl GetTarget()
|
||||
@@ -24,17 +28,17 @@ public class ExampleTargetButton : CustomActionButton<PlayerControl>
|
||||
|
||||
public override void SetOutline(bool active)
|
||||
{
|
||||
Target?.cosmetics.SetOutline(active, new Il2CppSystem.Nullable<Color>(Color.red));
|
||||
Target?.cosmetics.SetOutline(active, new Il2CppSystem.Nullable<Color>(Palette.Blue));
|
||||
}
|
||||
|
||||
public override bool IsTargetValid(PlayerControl target)
|
||||
{
|
||||
return PlayerControl.LocalPlayer.Data.Role.IsValidTarget(target.Data);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Enabled(RoleBehaviour role)
|
||||
{
|
||||
return role.IsImpostor;
|
||||
return role is FreezerRole;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using MiraAPI.Example;
|
||||
using MiraAPI.Example.Modifiers;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
[RegisterButton]
|
||||
public class MeetingButton : CustomActionButton
|
||||
{
|
||||
public override string Name => "Call Meeting";
|
||||
|
||||
public override float Cooldown => 15;
|
||||
|
||||
public override float EffectDuration => 0;
|
||||
|
||||
public override int MaxUses => 3;
|
||||
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
|
||||
public override bool Enabled(RoleBehaviour role)
|
||||
{
|
||||
return PlayerControl.LocalPlayer.HasModifier<CaptainModifier>();
|
||||
}
|
||||
|
||||
protected override void OnClick()
|
||||
{
|
||||
var bt = ShipStatus.Instance.EmergencyButton;
|
||||
|
||||
PlayerControl.LocalPlayer.NetTransform.Halt();
|
||||
var minigame = Object.Instantiate(bt.MinigamePrefab, Camera.main!.transform, false);
|
||||
|
||||
var taskAdderGame = minigame as TaskAdderGame;
|
||||
if (taskAdderGame != null)
|
||||
{
|
||||
taskAdderGame.SafePositionWorld = bt.SafePositionLocal + (Vector2)bt.transform.position;
|
||||
}
|
||||
|
||||
minigame.transform.localPosition = new Vector3(0f, 0f, -50f);
|
||||
minigame.Begin(null);
|
||||
|
||||
if (UsesLeft == 0 && PlayerControl.LocalPlayer.HasModifier<CaptainModifier>())
|
||||
{
|
||||
PlayerControl.LocalPlayer.RemoveModifier<CaptainModifier>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using MiraAPI.Example.Options.Roles;
|
||||
using MiraAPI.Example.Roles;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Buttons.Teleporter;
|
||||
[RegisterButton]
|
||||
public class TeleportButton : CustomActionButton
|
||||
{
|
||||
public override string Name => "Teleport";
|
||||
|
||||
public override float Cooldown => OptionGroupSingleton<TeleporterOptions>.Instance.TeleportCooldown;
|
||||
|
||||
public override float EffectDuration => OptionGroupSingleton<TeleporterOptions>.Instance.TeleportDuration;
|
||||
|
||||
public override int MaxUses => 0;
|
||||
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
public static bool IsZoom { get; private set; }
|
||||
|
||||
public override bool Enabled(RoleBehaviour role)
|
||||
{
|
||||
return role is TeleporterRole;
|
||||
}
|
||||
protected override void OnClick()
|
||||
{
|
||||
Coroutines.Start(ZoomOutCoroutine());
|
||||
}
|
||||
|
||||
public override void OnEffectEnd()
|
||||
{
|
||||
Coroutines.Start(ZoomInCoroutine());
|
||||
}
|
||||
|
||||
protected override void FixedUpdate(PlayerControl playerControl)
|
||||
{
|
||||
base.FixedUpdate(playerControl);
|
||||
|
||||
if (!EffectActive) return;
|
||||
|
||||
if (Input.GetKey(KeyCode.Mouse0))
|
||||
{
|
||||
playerControl.NetTransform.RpcSnapTo(Camera.main.ScreenToWorldPoint(Input.mousePosition));
|
||||
ResetCooldown();
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerator ZoomOutCoroutine()
|
||||
{
|
||||
HudManager.Instance.ShadowQuad.gameObject.SetActive(false);
|
||||
IsZoom = true;
|
||||
var zoomDistance = OptionGroupSingleton<TeleporterOptions>.Instance.ZoomDistance;
|
||||
for (var ft = Camera.main!.orthographicSize; ft < zoomDistance; ft += 0.3f)
|
||||
{
|
||||
Camera.main.orthographicSize = MeetingHud.Instance ? 3f : ft;
|
||||
ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen);
|
||||
foreach (var cam in Camera.allCameras) cam.orthographicSize = Camera.main.orthographicSize;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
foreach (var cam in Camera.allCameras) cam.orthographicSize = zoomDistance;
|
||||
ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen);
|
||||
}
|
||||
|
||||
private static IEnumerator ZoomInCoroutine()
|
||||
{
|
||||
for (var ft = Camera.main!.orthographicSize; ft > 3f; ft -= 0.3f)
|
||||
{
|
||||
Camera.main.orthographicSize = MeetingHud.Instance ? 3f : ft;
|
||||
ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen);
|
||||
foreach (var cam in Camera.allCameras) cam.orthographicSize = Camera.main.orthographicSize;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
foreach (var cam in Camera.allCameras) cam.orthographicSize = 3f;
|
||||
HudManager.Instance.ShadowQuad.gameObject.SetActive(true);
|
||||
IsZoom = false;
|
||||
|
||||
ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Example.Modifiers;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using Reactor.Utilities.ImGui;
|
||||
using System;
|
||||
using MiraAPI.Example.Modifiers;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example;
|
||||
@@ -13,11 +13,11 @@ public class MiraDebugWindow(IntPtr ptr) : MonoBehaviour(ptr)
|
||||
{
|
||||
if (GUILayout.Button("Test modifier"))
|
||||
{
|
||||
PlayerControl.LocalPlayer.AddModifier<ModifierTimerExample>();
|
||||
//PlayerControl.LocalPlayer.AddModifier<ModifierTimerExample>();
|
||||
}
|
||||
if (GUILayout.Button("Remove modifier"))
|
||||
{
|
||||
PlayerControl.LocalPlayer.RemoveModifier<ModifierTimerExample>();
|
||||
//PlayerControl.LocalPlayer.RemoveModifier<ModifierTimerExample>();
|
||||
}
|
||||
})
|
||||
{
|
||||
|
||||
+2
-8
@@ -4,15 +4,9 @@ using MiraAPI.Modifiers.Types;
|
||||
namespace MiraAPI.Example.Modifiers;
|
||||
|
||||
[RegisterModifier]
|
||||
public class GameModifierExample : GameModifier
|
||||
public class CaptainModifier : GameModifier
|
||||
{
|
||||
public override string ModifierName => "Example Game Modifier";
|
||||
|
||||
public override bool CanVent()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string ModifierName => "Captain";
|
||||
public override int GetAmountPerGame()
|
||||
{
|
||||
return 1;
|
||||
@@ -0,0 +1,30 @@
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Modifiers.Types;
|
||||
|
||||
namespace MiraAPI.Example.Modifiers.Freezer;
|
||||
|
||||
[RegisterModifier]
|
||||
public class FreezeModifier : TimedModifier
|
||||
{
|
||||
public override string ModifierName => "Freezed";
|
||||
public override bool HideOnUi => false;
|
||||
public override float Duration => 15f;
|
||||
public override bool AutoStart => true;
|
||||
public override bool RemoveOnComplete => true;
|
||||
|
||||
public override void OnActivate()
|
||||
{
|
||||
if (Player.AmOwner)
|
||||
{
|
||||
Player.moveable = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnTimerComplete()
|
||||
{
|
||||
if (Player.AmOwner)
|
||||
{
|
||||
Player.moveable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Modifiers.Types;
|
||||
|
||||
namespace MiraAPI.Example.Modifiers;
|
||||
|
||||
[RegisterModifier]
|
||||
public class ModifierTimerExample : TimedModifier
|
||||
{
|
||||
public override string ModifierName => "Color Changer";
|
||||
public override bool HideOnUi => false;
|
||||
public override float Duration => 10f;
|
||||
public override bool AutoStart => true;
|
||||
|
||||
private readonly System.Random _rand = new();
|
||||
|
||||
public override void OnTimerComplete()
|
||||
{
|
||||
Player.RpcSetColor((byte)_rand.Next(0, Palette.PlayerColors.Count));
|
||||
StartTimer();
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public class CustomRole2Settings : AbstractOptionGroup
|
||||
{
|
||||
public override string GroupName => "Custom Role";
|
||||
|
||||
public override Type AdvancedRole => typeof(CustomRole2);
|
||||
public override Type AdvancedRole => typeof(FreezerRole);
|
||||
|
||||
[ModdedToggleOption("Teleportation ability")] public bool Teleport { get; set; } = true;
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using MiraAPI.Example.Roles;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.Example.Options.Roles;
|
||||
|
||||
public class CustomRoleSettings : AbstractOptionGroup
|
||||
{
|
||||
public override string GroupName => "Custom Role";
|
||||
|
||||
public override Type AdvancedRole => typeof(CustomRole);
|
||||
|
||||
[ModdedNumberOption("Number Opt", min: 3, max: 9)] public float NumberOpt { get; set; } = 4;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using MiraAPI.Example.Roles;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using MiraAPI.Utilities;
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.Example.Options.Roles;
|
||||
|
||||
public class TeleporterOptions : AbstractOptionGroup
|
||||
{
|
||||
public override string GroupName => "Teleporter";
|
||||
|
||||
public override Type AdvancedRole => typeof(TeleporterRole);
|
||||
|
||||
[ModdedNumberOption("Teleport Cooldown", 5, 60, 2.5f, MiraNumberSuffixes.Seconds)]
|
||||
public float TeleportCooldown { get; set; } = 5;
|
||||
|
||||
[ModdedNumberOption("Teleport Duration", 5, 25, 1, MiraNumberSuffixes.Seconds)]
|
||||
public float TeleportDuration { get; set; } = 10;
|
||||
|
||||
[ModdedNumberOption("Zoom Distance", 4, 15)]
|
||||
public float ZoomDistance { get; set; } = 6;
|
||||
}
|
||||
@@ -5,12 +5,12 @@ using UnityEngine;
|
||||
namespace MiraAPI.Example.Roles;
|
||||
|
||||
[RegisterCustomRole]
|
||||
public class CustomRole : ImpostorRole, ICustomRole
|
||||
public class FreezerRole : ImpostorRole, ICustomRole
|
||||
{
|
||||
public string RoleName => "Custom Role";
|
||||
public string RoleLongDescription => "Eliminate everyone with your special ability!";
|
||||
public string RoleName => "Freezer";
|
||||
public string RoleLongDescription => "Freeze another player for a duration of time.";
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.Black;
|
||||
public Color RoleColor => Palette.Blue;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Impostor;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
|
||||
@@ -5,12 +5,12 @@ using UnityEngine;
|
||||
namespace MiraAPI.Example.Roles;
|
||||
|
||||
[RegisterCustomRole]
|
||||
public class CustomRole2 : CrewmateRole, ICustomRole
|
||||
public class TeleporterRole : CrewmateRole, ICustomRole
|
||||
{
|
||||
public string RoleName => "Custom Role 2";
|
||||
public string RoleLongDescription => "Save everyone from dying!";
|
||||
public string RoleName => "Teleporter";
|
||||
public string RoleLongDescription => "Zoom out and teleport across the map!";
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.AcceptedGreen;
|
||||
public Color RoleColor => new Color32(221, 176, 152, 255);
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class CustomActionButton
|
||||
/// The button object in game. This is created by Mira API automatically.
|
||||
/// </summary>
|
||||
protected ActionButton? Button { get; private set; }
|
||||
|
||||
|
||||
internal void CreateButton(Transform parent)
|
||||
{
|
||||
if (Button)
|
||||
@@ -110,10 +110,10 @@ public abstract class CustomActionButton
|
||||
{
|
||||
OnEffectEnd();
|
||||
}
|
||||
|
||||
|
||||
EffectActive = false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A utility function to override the sprite of the button.
|
||||
/// </summary>
|
||||
@@ -240,7 +240,7 @@ public abstract class CustomActionButton
|
||||
{
|
||||
Button?.SetDisabled();
|
||||
}
|
||||
|
||||
|
||||
Button?.SetCoolDown(Timer, EffectActive ? EffectDuration : Cooldown);
|
||||
|
||||
FixedUpdate(playerControl);
|
||||
@@ -257,12 +257,12 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
|
||||
/// The target object of the button.
|
||||
/// </summary>
|
||||
public T? Target { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The distance the player must be from the target object to use the button.
|
||||
/// </summary>
|
||||
public virtual float Distance => PlayerControl.LocalPlayer.Data.Role.GetAbilityDistance();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// An optional collider tag to filter the target object by.
|
||||
/// </summary>
|
||||
@@ -286,8 +286,8 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
|
||||
/// </summary>
|
||||
/// <param name="active">Should the outline be active</param>
|
||||
public abstract void SetOutline(bool active);
|
||||
|
||||
|
||||
|
||||
|
||||
public override bool CanUse()
|
||||
{
|
||||
var newTarget = GetTarget();
|
||||
@@ -298,7 +298,7 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
|
||||
|
||||
Target = IsTargetValid(newTarget) ? newTarget : null;
|
||||
SetOutline(true);
|
||||
|
||||
|
||||
return base.CanUse() && Target;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public partial class MiraApiPlugin : BasePlugin
|
||||
{
|
||||
Harmony.PatchAll();
|
||||
|
||||
ReactorCredits.Register("Mira API", Version.Truncate(11, "") ?? Version, true, ReactorCredits.AlwaysShow);
|
||||
ReactorCredits.Register("Mira API", Version, true, ReactorCredits.AlwaysShow);
|
||||
|
||||
PluginManager = new MiraPluginManager();
|
||||
PluginManager.Initialize();
|
||||
|
||||
@@ -84,7 +84,7 @@ public class ModifierComponent(IntPtr ptr) : MonoBehaviour(ptr)
|
||||
|
||||
var modifierComponent = target.GetModifierComponent();
|
||||
|
||||
var modifier = modifierComponent.ActiveModifiers.Find(x => x.GetType() == type);
|
||||
var modifier = modifierComponent?.ActiveModifiers.Find(x => x.GetType() == type);
|
||||
|
||||
if (modifier is null)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ using Reactor.Utilities.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Reactor.Utilities;
|
||||
using Random = System.Random;
|
||||
|
||||
namespace MiraAPI.Modifiers;
|
||||
@@ -41,12 +42,27 @@ public static class ModifierManager
|
||||
|
||||
List<uint> filteredModifiers = [];
|
||||
|
||||
foreach (var modifier in IdToTypeModifiers.Where(pair => pair.Value.GetType() == typeof(GameModifier)))
|
||||
foreach (var modifier in IdToTypeModifiers.Where(pair => pair.Value.IsAssignableTo(typeof(GameModifier))))
|
||||
{
|
||||
var mod = (GameModifier)Activator.CreateInstance(modifier.Value);
|
||||
var num = mod.GetAmountPerGame();
|
||||
var chance = mod.GetAssignmentChance();
|
||||
|
||||
if (mod is null)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to create instance of {modifier.Value.Name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!plrs.Any(x=>IsGameModifierValid(x, mod, modifier.Key)))
|
||||
{
|
||||
Logger<MiraApiPlugin>.Warning("No players are valid for modifier: " + mod.ModifierName);
|
||||
continue;
|
||||
}
|
||||
|
||||
var maxCount = plrs.Count(x=>IsGameModifierValid(x, mod, modifier.Key));
|
||||
|
||||
var num = Math.Clamp(mod.GetAmountPerGame(), 0, maxCount);
|
||||
var chance = mod.GetAssignmentChance();
|
||||
|
||||
for (var i = 0; i < num; i++)
|
||||
{
|
||||
var randomNum = rand.Next(100);
|
||||
@@ -63,23 +79,28 @@ public static class ModifierManager
|
||||
{
|
||||
shuffledModifiers = shuffledModifiers.GetRange(0, plrs.Count);
|
||||
}
|
||||
|
||||
|
||||
while (shuffledModifiers.Count > 0)
|
||||
{
|
||||
var id = shuffledModifiers[0];
|
||||
|
||||
var mod = (GameModifier)Activator.CreateInstance(IdToTypeModifiers[id]);
|
||||
|
||||
if (mod is null)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"Failed to create instance of {IdToTypeModifiers[id].Name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!plrs.Any(x=>IsGameModifierValid(x, mod, id)))
|
||||
{
|
||||
shuffledModifiers.RemoveAt(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
var plr = plrs.Random();
|
||||
|
||||
if (plr.Data.Role is ICustomRole modRole)
|
||||
{
|
||||
if (!modRole.IsModifierApplicable(mod))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (plr.HasModifier(id) || mod.IsModifierValidOn(plr.Data.Role))
|
||||
if (!IsGameModifierValid(plr, mod, id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -89,6 +110,13 @@ public static class ModifierManager
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsGameModifierValid(PlayerControl player, GameModifier modifier, uint modifierId)
|
||||
{
|
||||
return (player.Data.Role is not ICustomRole role || role.IsModifierApplicable(modifier)) &&
|
||||
modifier.IsModifierValidOn(player.Data.Role) &&
|
||||
!player.HasModifier(modifierId);
|
||||
}
|
||||
|
||||
internal static void SyncAllModifiers(int targetId = -1)
|
||||
{
|
||||
var data = new List<NetData>();
|
||||
|
||||
@@ -6,6 +6,7 @@ public abstract class TimedModifier : BaseModifier
|
||||
{
|
||||
public abstract float Duration { get; }
|
||||
public virtual bool AutoStart => false;
|
||||
public virtual bool RemoveOnComplete => true;
|
||||
public abstract void OnTimerComplete();
|
||||
|
||||
public bool TimerActive { get; protected set; }
|
||||
@@ -28,6 +29,11 @@ public abstract class TimedModifier : BaseModifier
|
||||
TimerActive = false;
|
||||
TimeRemaining = Duration;
|
||||
OnTimerComplete();
|
||||
|
||||
if (RemoveOnComplete)
|
||||
{
|
||||
ModifierComponent.RpcRemoveModifier(Player, ModifierId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using HarmonyLib;
|
||||
#nullable enable
|
||||
using HarmonyLib;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities.Extensions;
|
||||
@@ -17,9 +18,9 @@ public static class GameSettingMenuPatches
|
||||
{
|
||||
public static int CurrentSelectedMod { get; private set; }
|
||||
|
||||
public static MiraPluginInfo SelectedMod { get; private set; }
|
||||
public static MiraPluginInfo? SelectedMod { get; private set; }
|
||||
|
||||
private static TextMeshPro _text;
|
||||
private static TextMeshPro? _text;
|
||||
|
||||
private static Vector3 _roleBtnOgPos;
|
||||
|
||||
@@ -80,12 +81,12 @@ public static class GameSettingMenuPatches
|
||||
|
||||
private static void UpdateText(GameSettingMenu menu, GameOptionsMenu settings, RolesSettingsMenu roles)
|
||||
{
|
||||
if (CurrentSelectedMod == 0)
|
||||
if (_text is not null && CurrentSelectedMod == 0)
|
||||
{
|
||||
_text.text = "Default";
|
||||
_text.fontSizeMax = 3.2f;
|
||||
}
|
||||
else
|
||||
else if (_text is not null)
|
||||
{
|
||||
_text.fontSizeMax = 2.3f;
|
||||
SelectedMod = MiraPluginManager.Instance.RegisteredPlugins.ElementAt(CurrentSelectedMod - 1).Value;
|
||||
@@ -153,7 +154,7 @@ public static class GameSettingMenuPatches
|
||||
roles.scrollBar.ScrollToTop();
|
||||
}
|
||||
|
||||
if (settings?.Children != null && SelectedMod?.OptionGroups.Count != 0)
|
||||
if (settings.Children != null && SelectedMod?.OptionGroups.Count != 0)
|
||||
{
|
||||
foreach (var child in settings.Children)
|
||||
{
|
||||
|
||||
@@ -263,27 +263,28 @@ public static class RoleSettingMenuPatches
|
||||
roleOptionSetting.titleText.transform.localPosition = new Vector3(-0.5376f, -0.2923f, 0f);
|
||||
roleOptionSetting.titleText.color = customRole.RoleColor.GetAlternateColor();
|
||||
roleOptionSetting.titleText.horizontalAlignment = HorizontalAlignmentOptions.Left;
|
||||
|
||||
var newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform);
|
||||
newButton.name = "ConfigButton";
|
||||
newButton.transform.localPosition = new Vector3(0.4473f, -0.3f, -2f);
|
||||
newButton.transform.FindChild("Text_TMP").gameObject.DestroyImmediate();
|
||||
newButton.activeSprites.Destroy();
|
||||
|
||||
var btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent<SpriteRenderer>();
|
||||
btnRend.sprite = MiraAssets.Cog.LoadAsset();
|
||||
|
||||
var passiveButton = newButton.GetComponent<GameOptionButton>();
|
||||
passiveButton.OnClick = new ButtonClickedEvent();
|
||||
passiveButton.interactableColor = btnRend.color = customRole.RoleColor.GetAlternateColor();
|
||||
passiveButton.interactableHoveredColor = Color.white;
|
||||
|
||||
passiveButton.OnClick.AddListener((UnityAction)(() =>
|
||||
|
||||
if (GameSettingMenuPatches.SelectedMod is null ||
|
||||
GameSettingMenuPatches.SelectedMod.Options.Any(x => x.AdvancedRole != null && x.AdvancedRole.IsInstanceOfType(role)))
|
||||
{
|
||||
ChangeTab(role, __instance);
|
||||
}));
|
||||
var newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform);
|
||||
newButton.name = "ConfigButton";
|
||||
newButton.transform.localPosition = new Vector3(0.4473f, -0.3f, -2f);
|
||||
newButton.transform.FindChild("Text_TMP").gameObject.DestroyImmediate();
|
||||
newButton.activeSprites.Destroy();
|
||||
|
||||
if (index < GameSettingMenuPatches.SelectedMod.CustomRoles.Count - 1)
|
||||
var btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent<SpriteRenderer>();
|
||||
btnRend.sprite = MiraAssets.Cog.LoadAsset();
|
||||
|
||||
var passiveButton = newButton.GetComponent<GameOptionButton>();
|
||||
passiveButton.OnClick = new ButtonClickedEvent();
|
||||
passiveButton.interactableColor = btnRend.color = customRole.RoleColor.GetAlternateColor();
|
||||
passiveButton.interactableHoveredColor = Color.white;
|
||||
|
||||
passiveButton.OnClick.AddListener((UnityAction)(() => { ChangeTab(role, __instance); }));
|
||||
}
|
||||
|
||||
if (index < GameSettingMenuPatches.SelectedMod?.CustomRoles.Count - 1)
|
||||
{
|
||||
yPos += -0.43f;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user