-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from Alexejhero/edf
add EDF (Ermfish Defense Force)
- Loading branch information
Showing
13 changed files
with
481 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.