Skip to content

Commit

Permalink
Causes the local player's creepers to blink periodically if team colo…
Browse files Browse the repository at this point in the history
…red creepers are on.
  • Loading branch information
CCraigen authored and roncli committed Feb 26, 2023
1 parent 2860b66 commit e41396a
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions GameMod/MPTeams.cs
Expand Up @@ -1457,7 +1457,7 @@ static void Postfix(Projectile __instance)

__instance.c_go.GetComponent<Light>().color = teamcolor;

foreach (var rend in __instance.c_go.GetComponentsInChildren<Renderer>())
foreach (var rend in __instance.c_go.GetComponentsInChildren<Renderer>(includeInactive: true))
{
if (rend.name == "_glow" || rend.name == "extra_glow")
{
Expand All @@ -1479,7 +1479,7 @@ static void Postfix(Projectile __instance)
}
else
{
foreach (var x in __instance.c_go.GetComponentsInChildren<ParticleSystem>())
foreach (var x in __instance.c_go.GetComponentsInChildren<ParticleSystem>(includeInactive: true))
{
var m = x.main;
switch (x.name)
Expand All @@ -1500,6 +1500,45 @@ static void Postfix(Projectile __instance)
}
}

// if team-coloured creepers are on and friendly fire isn't, causes the player's creepers to blink periodically
[HarmonyPatch(typeof(Projectile), "FixedUpdateDynamic")]
static class MPTeams_Projectile_UpdateDynamic
{
const float offTime = 0.2f;
const float cycleTime = 1.2f;

static bool glowOn = false;
static float nextOff = offTime;
static float nextTime = 0f;
static float tempNext = 0f;

static void Postfix(Projectile __instance)
{
if (GameplayManager.IsMultiplayerActive && Menus.mms_creeper_colors && MenuManager.mms_friendly_fire != 1 && __instance.m_type == ProjPrefab.missile_creeper && __instance.m_owner_player.isLocalPlayer)
{
if (nextTime <= Time.time)
{
if (!glowOn)
{
nextOff = Time.time + offTime;
tempNext = Time.time + cycleTime;
glowOn = true;
}
__instance.m_robot_only_extra_mesh.SetActive(true);
}
if (__instance.m_robot_only_extra_mesh.activeSelf && nextOff <= Time.time)
{
if (glowOn)
{
nextTime = tempNext;
glowOn = false;
}
__instance.m_robot_only_extra_mesh.SetActive(false);
}
}
}
}

// resets the projectile list between rounds
[HarmonyPatch(typeof(GameplayManager), "StartLevel")]
class MPTeams_GameplayManager_StartLevel
Expand Down

0 comments on commit e41396a

Please sign in to comment.