Skip to content

Commit

Permalink
Merge pull request #59 from Alexejhero/edf
Browse files Browse the repository at this point in the history
add EDF (Ermfish Defense Force)
  • Loading branch information
Govorunb authored May 12, 2024
2 parents 4f48093 + e4cb0e1 commit de53a7c
Show file tree
Hide file tree
Showing 13 changed files with 481 additions and 12 deletions.
17 changes: 13 additions & 4 deletions SCHIZO/Creatures/Ermshark/Ermshark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ private void Mitosis(Vector3 position, GameObject hurtEffect)
const float splitScaleModifier = 0.69f;
if (!_ermsharkPrefab)
{
LOGGER.LogError($"No prefab for mitosis, committing Minecraft");
LOGGER.LogWarning("No prefab for mitosis, committing Minecraft");
mitosisRemaining = 0;
SOS();
return;
}

liveMixin.ResetHealth();
transform.position = position + Random.insideUnitSphere * 0.5f;
transform.GetChild(0).localScale *= splitScaleModifier;
Transform model = transform.GetChild(0);
model.localScale *= splitScaleModifier;
// if the shark gets small enough, carrying other fish looks weird (bc they're bigger than it)
if (model.localScale.x < 0.3f) DisableCarry(gameObject);

mitosisRemaining--;
SpawnDecoy(position);
Expand All @@ -93,7 +96,13 @@ private void SpawnDecoy(Vector3 position)

ermshark.mitosisRemaining = mitosisRemaining;

CarryCreature carry = decoy.GetComponent<CarryCreature>();
if (carry) carry.enabled = false;
DisableCarry(decoy);
}

private static void DisableCarry(GameObject shark)
{
// forgor there are actually two of them on the shark
foreach (CarryCreature carry in shark.GetComponents<CarryCreature>())
Destroy(carry);
}
}
4 changes: 3 additions & 1 deletion SCHIZO/Creatures/Ermshark/ErmsharkAttack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public override void OnTouch(Collider collider)
if (player)
{
GameObject heldObject = Inventory.main.GetHeldObject();
if (heldObject && canBeFed && player.CanBeAttacked() && TryEat(heldObject, true))
if (heldObject && canBeFed && player.CanBeAttacked()
&& !heldObject.GetComponent<Carryable>() // otherwise decoy ermsharks eat ermfish from your hands
&& TryEat(heldObject, true))
{
if (this.GetBiteSound()) Utils.PlayEnvSound(this.GetBiteSound(), mouth.transform.position);
gameObject.SendMessage("OnMeleeAttack", heldObject, SendMessageOptions.DontRequireReceiver);
Expand Down
2 changes: 1 addition & 1 deletion SCHIZO/Events/Ermcon/Ermcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial class Ermcon
private float _lastSearchTime;
public float stareTime;

private void Start()
protected override void Start()
{
instance = this;
conMembers = [];
Expand Down
47 changes: 47 additions & 0 deletions SCHIZO/Events/ErmfishDefenseForce/EdfConsoleCommands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using Nautilus.Commands;
using SCHIZO.ConsoleCommands;
using SCHIZO.Helpers;

namespace SCHIZO.Events.ErmfishDefenseForce;

[RegisterConsoleCommands]
public static class EdfConsoleCommands
{
private const string CommandName = "edf";
[ConsoleCommand(CommandName)]
public static string EdfCommand(params string[] args)
{
if (args is [])
return "subcommands:\naggro\nreset";
string subCommand = args[0].ToLower();
return subCommand switch
{
"aggro" => Aggro(args),
"reset" => Reset(),
//"spawn" => ForceSpawn(args),
_ => null,
};
}

public static string Aggro(IReadOnlyList<string> args)
{
if (args.Count > 1)
{
string arg = args[1];
if (!float.TryParse(arg, out float value))
goto syntax;

ErmfishDefenseForce.instance.SetAggro(value, $"{CommandName} aggro");
}
return MessageHelpers.GetCommandOutput(ErmfishDefenseForce.instance.CurrentAggro.ToString());

syntax: return $"Syntax: {CommandName} aggro [value]";
}

public static string Reset()
{
ErmfishDefenseForce.instance.Reset();
return null;
}
}
72 changes: 72 additions & 0 deletions SCHIZO/Events/ErmfishDefenseForce/EdfPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using UnityEngine;

namespace SCHIZO.Events.ErmfishDefenseForce;

[HarmonyPatch]
public static class EdfPatches
{
[HarmonyPatch(typeof(Survival), nameof(Survival.Eat))]
[HarmonyPostfix]
public static void OnEat(Survival __instance, GameObject useObj)
{
if (!ErmfishDefenseForce.instance) return;
if (!__instance.GetComponent<Player>()) return;

ErmfishDefenseForce.instance.OnEat(CraftData.GetTechType(useObj));
}

[HarmonyPatch(typeof(LiveMixin), nameof(LiveMixin.TakeDamage))]
[HarmonyPostfix]
public static void OnAttack(LiveMixin __instance, GameObject dealer)
{
if (!ErmfishDefenseForce.instance) return;
if (dealer != Player.main.gameObject) return;

ErmfishDefenseForce.instance.OnAttack(CraftData.GetTechType(__instance.gameObject));
}

[HarmonyPatch(typeof(Crafter), nameof(Crafter.OnCraftingBegin))]
[HarmonyPostfix]
public static void OnCook(TechType techType)
{
if (!ErmfishDefenseForce.instance) return;

#if BELOWZERO
IEnumerable<NIngredient> ingredients = TechData.GetIngredients(techType);
#else
NTechData techData = CraftData.techData[techType];
IEnumerable<NIngredient> ingredients = techData._ingredients;
#endif
foreach (NIngredient ingredient in ingredients)
{
for (int i = 0; i < ingredient.amount; i++)
ErmfishDefenseForce.instance.OnCook(ingredient.techType);
}
}

[HarmonyPatch(typeof(Pickupable), nameof(Pickupable.Pickup))]
[HarmonyPostfix]
public static void OnPickup(Pickupable __instance)
{
if (!ErmfishDefenseForce.instance) return;

ErmfishDefenseForce.instance.OnPickup(__instance.GetTechType());
}

[HarmonyPatch(typeof(LiveMixin), nameof(LiveMixin.NotifyAllAttachedDamageReceivers))]
[HarmonyPostfix]
public static void ClearKarmaOnPlayerDeathByDefenders(LiveMixin __instance, DamageInfo inDamage)
{
if (__instance.gameObject != Player.main.gameObject) return;
if (__instance.health > 0) return;

GameObject dealerDefender = ErmfishDefenseForce.instance.ActiveDefenders
.Find(def => inDamage.dealer.transform.IsChildOf(def.transform));
if (!dealerDefender) return;

ErmfishDefenseForce.instance.OnPlayerKilledByDefender(dealerDefender);
}
}
Loading

0 comments on commit de53a7c

Please sign in to comment.