-
-
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 #11 from IngoHHacks/follower-commands
Follower commands
- Loading branch information
Showing
10 changed files
with
240 additions
and
5 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
36 changes: 36 additions & 0 deletions
36
COTL_API/CustomFollowerCommand/CustomFollowerCommandItem.cs
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,36 @@ | ||
using COTL_API.Helpers; | ||
using Lamb.UI.FollowerInteractionWheel; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using UnityEngine; | ||
|
||
namespace COTL_API.CustomFollowerCommand | ||
{ | ||
public abstract class CustomFollowerCommandItem : CommandItem | ||
{ | ||
public virtual string InternalName { get; set; } | ||
public Sprite Icon { get; internal set; } | ||
|
||
public virtual List<FollowerCommandCategory> GetCategories() { return new List<FollowerCommandCategory>() { FollowerCommandCategory.DEFAULT_COMMAND }; } | ||
|
||
public string ModPrefix; | ||
|
||
public virtual List<CommandItem> GetSubCommands() | ||
{ | ||
return new List<CommandItem>(); | ||
} | ||
|
||
public virtual bool CheckSelectionPreconditions(Follower follower) | ||
{ | ||
return true; | ||
} | ||
|
||
public abstract bool Execute(interaction_FollowerInteraction interaction, FollowerCommands finalCommand = FollowerCommands.None); | ||
|
||
public CustomFollowerCommandItem() | ||
{ | ||
Icon = TextureHelper.CreateSpriteFromPath(PluginPaths.ResolveAssetPath("placeholder.png")); | ||
} | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
COTL_API/CustomFollowerCommand/CustomFollowerCommandManager.cs
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,107 @@ | ||
using COTL_API.CustomInventory; | ||
using COTL_API.Guid; | ||
using HarmonyLib; | ||
using Lamb.UI.FollowerInteractionWheel; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace COTL_API.CustomFollowerCommand; | ||
|
||
[HarmonyPatch] | ||
public class CustomFollowerCommandManager | ||
{ | ||
internal static Dictionary<FollowerCommands, CustomFollowerCommandItem> customCommands = new Dictionary<FollowerCommands, CustomFollowerCommandItem>(); | ||
|
||
public static FollowerCommands Add(CustomFollowerCommandItem item) | ||
{ | ||
var guid = TypeManager.GetModIdFromCallstack(Assembly.GetCallingAssembly()); | ||
|
||
var followerCommand = GuidManager.GetEnumValue<FollowerCommands>(guid, item.InternalName); | ||
item.Command = followerCommand; | ||
item.SubCommands = item.GetSubCommands(); | ||
item.ModPrefix = guid; | ||
|
||
customCommands.Add(followerCommand, item); | ||
|
||
return followerCommand; | ||
} | ||
|
||
[HarmonyPatch(typeof(FollowerCommandGroups), "DefaultCommands", new Type[] { typeof(Follower) })] | ||
[HarmonyPostfix] | ||
public static void FollowerCommandGroups_DefaultCommands(Follower follower, List<CommandItem> __result) | ||
{ | ||
customCommands.Values.Do(c => { if (c.GetCategories().Contains(FollowerCommandCategory.DEFAULT_COMMAND) && c.CheckSelectionPreconditions(follower)) __result.Add(c); }); | ||
} | ||
|
||
[HarmonyPatch(typeof(FollowerCommandGroups), "GiveWorkerCommands", new Type[] { typeof(Follower) })] | ||
[HarmonyPostfix] | ||
public static void FollowerCommandGroups_GiveWorkerCommands(Follower follower, List<CommandItem> __result) | ||
{ | ||
customCommands.Values.Do(c => { if (c.GetCategories().Contains(FollowerCommandCategory.GIVE_WORKER_COMMAND) && c.CheckSelectionPreconditions(follower)) __result.Add(c); }); | ||
} | ||
|
||
[HarmonyPatch(typeof(FollowerCommandGroups), "MakeDemandCommands", new Type[] { typeof(Follower) })] | ||
[HarmonyPostfix] | ||
public static void FollowerCommandGroups_MakeDemandCommands(Follower follower, List<CommandItem> __result) | ||
{ | ||
customCommands.Values.Do(c => { if (c.GetCategories().Contains(FollowerCommandCategory.MAKE_DEMAND_COMMAND) && c.CheckSelectionPreconditions(follower)) __result.Add(c); }); | ||
} | ||
|
||
[HarmonyPatch(typeof(FollowerCommandGroups), "WakeUpCommands", new Type[] { })] | ||
[HarmonyPostfix] | ||
public static void FollowerCommandGroups_WakeUpCommands(List<CommandItem> __result) | ||
{ | ||
customCommands.Values.Do(c => { if (c.GetCategories().Contains(FollowerCommandCategory.WAKE_UP_COMMAND)) __result.Add(c); }); | ||
} | ||
|
||
[HarmonyPatch(typeof(FollowerCommandGroups), "OldAgeCommands", new Type[] { typeof(Follower) })] | ||
[HarmonyPostfix] | ||
public static void FollowerCommandGroups_OldAgeCommands(Follower follower, List<CommandItem> __result) | ||
{ | ||
customCommands.Values.Do(c => { if (c.GetCategories().Contains(FollowerCommandCategory.OLD_AGE_COMMAND) && c.CheckSelectionPreconditions(follower)) __result.Add(c); }); | ||
} | ||
|
||
[HarmonyPatch(typeof(FollowerCommandGroups), "DissenterCommands", new Type[] { typeof(Follower) })] | ||
[HarmonyPostfix] | ||
public static void FollowerCommandGroups_DissenterCommands(Follower follower, List<CommandItem> __result) | ||
{ | ||
customCommands.Values.Do(c => { if (c.GetCategories().Contains(FollowerCommandCategory.DISSENTER_COMMAND) && c.CheckSelectionPreconditions(follower)) __result.Add(c); }); | ||
} | ||
|
||
[HarmonyPatch(typeof(interaction_FollowerInteraction), "OnFollowerCommandFinalized", new Type[] { typeof(FollowerCommands[]) })] | ||
[HarmonyPrefix] | ||
public static bool interaction_FollowerInteraction_OnFollowerCommandFinalized(interaction_FollowerInteraction __instance, FollowerCommands[] followerCommands) | ||
{ | ||
FollowerCommands command = followerCommands[0]; | ||
FollowerCommands preFinalCommand = ((followerCommands.Length > 1) ? followerCommands[1] : FollowerCommands.None); | ||
|
||
if (customCommands.ContainsKey(command) || customCommands.ContainsKey(preFinalCommand)) | ||
{ | ||
bool shouldClose = true; | ||
if (customCommands.ContainsKey(preFinalCommand)) | ||
{ | ||
shouldClose = customCommands[preFinalCommand].Execute(__instance, command); | ||
} | ||
else | ||
{ | ||
shouldClose = customCommands[command].Execute(__instance); | ||
} | ||
__instance.Close(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
[HarmonyPatch(typeof(FontImageNames), "IconForCommand", new Type[] { typeof(FollowerCommands) })] | ||
[HarmonyPrefix] | ||
public static bool interaction_FollowerInteraction_OnFollowerCommandFinalized(FollowerCommands followerCommands, ref string __result) | ||
{ | ||
if (customCommands.ContainsKey(followerCommands)) | ||
{ | ||
__result = $"<sprite name=\"icon_FCOMMAND_{customCommands[followerCommands].ModPrefix}.${customCommands[followerCommands].InternalName}\">"; | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
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,12 @@ | ||
namespace COTL_API.CustomFollowerCommand | ||
{ | ||
public enum FollowerCommandCategory | ||
{ | ||
DEFAULT_COMMAND, | ||
DISSENTER_COMMAND, | ||
GIVE_WORKER_COMMAND, | ||
MAKE_DEMAND_COMMAND, | ||
OLD_AGE_COMMAND, | ||
WAKE_UP_COMMAND | ||
} | ||
} |
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,28 @@ | ||
using COTL_API.CustomFollowerCommand; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace COTL_API.INDEV | ||
{ | ||
public class DEBUG_FOLLOWER_COMMAND_CLASS : CustomFollowerCommandItem | ||
{ | ||
public override string InternalName { get => "DEBUG_FOLLOWER_COMMAND"; } | ||
|
||
public override bool CheckSelectionPreconditions(Follower follower) | ||
{ | ||
return base.CheckSelectionPreconditions(follower); | ||
} | ||
|
||
public override bool Execute(interaction_FollowerInteraction interaction, FollowerCommands finalCommand = FollowerCommands.None) | ||
{ | ||
interaction.StartCoroutine(interaction.FrameDelayCallback(delegate | ||
{ | ||
interaction.eventListener.PlayFollowerVO(interaction.generalAcknowledgeVO); | ||
interaction.follower.Brain.HardSwapToTask(new FollowerTask_InstantPoop()); | ||
})); | ||
|
||
return true; | ||
} | ||
} | ||
} |
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,34 @@ | ||
using COTL_API.CustomFollowerCommand; | ||
using Lamb.UI.FollowerInteractionWheel; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace COTL_API.INDEV | ||
{ | ||
public class DEBUG_FOLLOWER_COMMAND_CLASS_2 : CustomFollowerCommandItem | ||
{ | ||
public override string InternalName { get => "DEBUG_FOLLOWER_COMMAND_2"; } | ||
|
||
public override List<FollowerCommandCategory> GetCategories() | ||
{ | ||
return new List<FollowerCommandCategory>() { FollowerCommandCategory.MAKE_DEMAND_COMMAND }; | ||
} | ||
|
||
public override bool CheckSelectionPreconditions(Follower follower) | ||
{ | ||
return base.CheckSelectionPreconditions(follower); | ||
} | ||
|
||
public override bool Execute(interaction_FollowerInteraction interaction, FollowerCommands finalCommand = FollowerCommands.None) | ||
{ | ||
interaction.follower.Brain.MakeDissenter(); | ||
return true; | ||
} | ||
|
||
public override List<CommandItem> GetSubCommands() | ||
{ | ||
return FollowerCommandGroups.AreYouSureCommands(); | ||
} | ||
} | ||
} |
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