fix neutral killing issues and rename some properties in ICustomRole to clear confusion

This commit is contained in:
XtraCube committed 2024-09-02 00:12:50 -04:00
1 parent f8bb63483f
commit f207849e5e
6 files changed
+107 -17

No files matched your search

@@ -0,0 +1,27 @@
using MiraAPI.Roles;
using UnityEngine;
namespace MiraAPI.Example.Roles;
[RegisterCustomRole]
public class NeutralKillerRole : ImpostorRole, ICustomRole
{
public string RoleName => "Neutral Killer";
public string RoleDescription => "Neutral who can kill.";
public string RoleLongDescription => RoleDescription;
public Color RoleColor => Color.magenta;
public ModdedRoleTeams Team => ModdedRoleTeams.Neutral;
public bool CanUseKill => true;
public bool CanGetKilled => true;
public bool CanUseVent => true;
public override void SpawnTaskHeader(PlayerControl playerControl)
{
// remove existing task header.
}
public override bool DidWin(GameOverReason gameOverReason)
{
return GameManager.Instance.DidHumansWin(gameOverReason);
}
}
+10 -10
View File
@@ -1,10 +1,11 @@
using AmongUs.GameOptions;
using System.Collections;
using System.Linq;
using AmongUs.GameOptions;
using Assets.CoreScripts;
using BepInEx.Unity.IL2CPP.Utils;
using Reactor.Networking.Attributes;
using Reactor.Utilities;
using Reactor.Utilities.Extensions;
using System.Collections;
using System.Linq;
using UnityEngine;
namespace MiraAPI.Networking;
@@ -71,7 +72,7 @@ public static class CustomMurderRpc
bool playKillSound = true)
{
source.isKilling = false;
Logger<MiraApiPlugin>.Debug($"{source.PlayerId} trying to murder {target.PlayerId}");
Logger<MiraApiPlugin>.Error($"{source.PlayerId} trying to murder {target.PlayerId}");
var data = target.Data;
if (resultFlags.HasFlag(MurderResultFlags.FailedError))
{
@@ -104,7 +105,7 @@ public static class CustomMurderRpc
target.RemoveProtection();
}
Logger<MiraApiPlugin>.Debug($"{source.PlayerId} failed to murder {target.PlayerId} due to guardian angel protection");
Logger<MiraApiPlugin>.Error($"{source.PlayerId} failed to murder {target.PlayerId} due to guardian angel protection");
return;
}
@@ -134,8 +135,7 @@ public static class CustomMurderRpc
if (resetKillTimer)
{
source.SetKillTimer(
GameOptionsManager.Instance.CurrentGameOptions.GetFloat(FloatOptionNames.KillCooldown));
source.SetKillTimer(GameOptionsManager.Instance.CurrentGameOptions.GetFloat(FloatOptionNames.KillCooldown));
}
}
@@ -172,8 +172,8 @@ public static class CustomMurderRpc
source.CurrentOutfitType == PlayerOutfitType.Shapeshifted,
source.shapeshiftTargetPlayerId,
target.PlayerId);
Coroutines.Start(source.KillAnimations.Random()?.CoPerformCustomKill(source, target, createDeadBody, teleportMurderer));
Logger<MiraApiPlugin>.Debug($"{source.PlayerId} succeeded in murdering {target.PlayerId}");
source.MyPhysics.StartCoroutine(source.KillAnimations.Random()?.CoPerformCustomKill(source, target, createDeadBody, teleportMurderer));
Logger<MiraApiPlugin>.Error($"{source.PlayerId} succeeded in murdering {target.PlayerId}");
}
/// <summary>
@@ -262,7 +262,7 @@ public static class CustomMurderRpc
if (cam != null)
{
cam.Locked = true;
cam.Locked = false;
}
PlayerControl.LocalPlayer.isKilling = false;
-2
View File
@@ -1,7 +1,5 @@
using HarmonyLib;
using InnerNet;
using MiraAPI.Hud;
using MiraAPI.Roles;
using Reactor.Utilities.Extensions;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -0,0 +1,65 @@
using HarmonyLib;
using Il2CppSystem;
using MiraAPI.Networking;
using MiraAPI.Roles;
using UnityEngine;
namespace MiraAPI.Patches.Roles;
/// <summary>
/// Fix kill button issues for neutral killers.
/// </summary>
[HarmonyPatch(typeof(KillButton))]
public static class KillButtonPatches
{
[HarmonyPrefix]
[HarmonyPatch(nameof(KillButton.SetTarget))]
public static bool SetTargetPrefix(KillButton __instance, PlayerControl target)
{
if (!PlayerControl.LocalPlayer || PlayerControl.LocalPlayer.Data == null || !PlayerControl.LocalPlayer.Data.Role)
{
return false;
}
if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole customRole)
{
return true;
}
if (__instance.currentTarget && __instance.currentTarget != target)
{
__instance.currentTarget.cosmetics.SetOutline(false, new Nullable<Color>(Color.clear));
}
__instance.currentTarget = target;
if (__instance.currentTarget)
{
__instance.currentTarget.cosmetics.SetOutline(true, new Nullable<Color>(customRole.RoleColor));
__instance.SetEnabled();
return false;
}
__instance.SetDisabled();
return false;
}
[HarmonyPrefix]
[HarmonyPatch(nameof(KillButton.DoClick))]
public static bool DoClickPrefix(KillButton __instance)
{
if (PlayerControl.LocalPlayer.Data.Role is not ICustomRole)
{
return true;
}
if (!__instance.isActiveAndEnabled || !__instance.currentTarget || __instance.isCoolingDown ||
PlayerControl.LocalPlayer.Data.IsDead || !PlayerControl.LocalPlayer.CanMove)
{
return false;
}
PlayerControl.LocalPlayer.RpcCustomMurder(__instance.currentTarget);
__instance.SetTarget(null);
return false;
}
}
+1 -1
View File
@@ -84,7 +84,7 @@ public static class CustomRoleManager
roleBehaviour.StringName = CustomStringName.CreateAndRegister(customRole.RoleName);
roleBehaviour.BlurbName = CustomStringName.CreateAndRegister(customRole.RoleDescription);
roleBehaviour.BlurbNameLong = CustomStringName.CreateAndRegister(customRole.RoleLongDescription);
roleBehaviour.AffectedByLightAffectors = customRole.AffectedByLight;
roleBehaviour.AffectedByLightAffectors = customRole.AffectedByLightOnAirship;
roleBehaviour.CanBeKilled = customRole.CanGetKilled;
roleBehaviour.CanUseKillButton = customRole.CanUseKill;
roleBehaviour.TasksCountTowardProgress = customRole.TasksCountForProgress;
+4 -4
View File
@@ -68,9 +68,9 @@ public interface ICustomRole
ConfigDefinition ChanceConfigDefinition => new("Roles", $"Chance {GetType().FullName}");
/// <summary>
/// Gets a value indicating whether the role is affected by light sabotages.
/// Gets a value indicating whether the role is affected by light affectors on Airship.
/// </summary>
bool AffectedByLight => Team == ModdedRoleTeams.Crewmate;
bool AffectedByLightOnAirship => Team == ModdedRoleTeams.Crewmate;
/// <summary>
/// Gets a value indicating whether the role can be killed by others.
@@ -80,7 +80,7 @@ public interface ICustomRole
/// <summary>
/// Gets a value indicating whether the role can kill others.
/// </summary>
bool CanKill => Team == ModdedRoleTeams.Impostor;
bool CanUseKill => Team == ModdedRoleTeams.Impostor;
/// <summary>
/// Gets a value indicating whether the role can use vents.
@@ -90,7 +90,7 @@ public interface ICustomRole
/// <summary>
/// Gets a value indicating whether the role's tasks count towards task progress.
/// </summary>
bool TasksCount => Team == ModdedRoleTeams.Crewmate;
bool TasksCountForProgress => Team == ModdedRoleTeams.Crewmate;
/// <summary>
/// Gets a value indicating whether the role is a Ghost.