Skip to content

Commit

Permalink
Merge pull request #184 from jpw1991/183-worker-ai-standing-around
Browse files Browse the repository at this point in the history
3.0.2: hopefully fix worker AI problem
  • Loading branch information
jpw1991 authored Apr 11, 2023
2 parents 718e59d + 15ed855 commit 1f857f9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
5 changes: 4 additions & 1 deletion ChebsNecromancy/BasePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class BasePlugin : BaseUnityPlugin
{
public const string PluginGuid = "com.chebgonaz.ChebsNecromancy";
public const string PluginName = "ChebsNecromancy";
public const string PluginVersion = "3.0.1";
public const string PluginVersion = "3.0.3";
private const string ConfigFileName = PluginGuid + ".cfg";
private static readonly string ConfigFileFullPath = Path.Combine(Paths.ConfigPath, ConfigFileName);

Expand Down Expand Up @@ -112,6 +112,9 @@ private void Awake()
CommandManager.Instance.AddConsoleCommand(new KillAllNeckros());
CommandManager.Instance.AddConsoleCommand(new SetMinionOwnership());
CommandManager.Instance.AddConsoleCommand(new SetNeckroHome());

SkeletonMinerMinion.SyncInternalsWithConfigs();
SkeletonWoodcutterMinion.SyncInternalsWithConfigs();

SetupWatcher();
}
Expand Down
2 changes: 1 addition & 1 deletion ChebsNecromancy/Package/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ChebsNecromancy",
"description": "Cheb's Necromancy adds Necromancy to Valheim via craftable wands and structures. Minions will follow you, guard your base, and perform menial tasks.",
"version_number": "3.0.1",
"version_number": "3.0.3",
"website_url": "https://github.com/jpw1991/chebs-necromancy",
"dependencies": [
"ValheimModding-Jotunn-2.11.2"
Expand Down
36 changes: 25 additions & 11 deletions ChebsNecromancy/Patches/TameablePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,31 @@ static bool InteractPrefix(Humanoid user, bool hold, bool alt, Tameable __instan
return false; // deny base method completion
}

var currentStatus = undeadMinion.Status;
var nextStatus = currentStatus switch
{
ChebGonazMinion.State.Following => ChebGonazMinion.State.Waiting,
ChebGonazMinion.State.Waiting => ChebGonazMinion.State.Roaming,
_ => ChebGonazMinion.State.Following
};

// use the minion methods to ensure the ZDO is updated
if (undeadMinion.Status == ChebGonazMinion.State.Following)
if (nextStatus.Equals(ChebGonazMinion.State.Following))
{
user.Message(MessageHud.MessageType.Center, "$friendlyskeletonwand_skeletonwaiting");
undeadMinion.Wait(player.transform.position);
user.Message(MessageHud.MessageType.Center, "$chebgonaz_following");
undeadMinion.Follow(player.gameObject);
return false; // deny base method completion
}
else
if (nextStatus.Equals(ChebGonazMinion.State.Waiting))
{
user.Message(MessageHud.MessageType.Center, "$friendlyskeletonwand_skeletonfollowing");
undeadMinion.Follow(player.gameObject);
user.Message(MessageHud.MessageType.Center, "$chebgonaz_waiting");
undeadMinion.Wait(player.transform.position);
return false; // deny base method completion
}

user.Message(MessageHud.MessageType.Center, "$chebgonaz_roaming");
undeadMinion.Roam();
return false; // deny base method completion
}

return true; // permit base method to complete
Expand All @@ -68,13 +80,15 @@ static void Postfix(Tameable __instance, ref string __result)
{
if (__instance.m_nview.IsValid()
&& __instance.m_commandable
&& __instance.TryGetComponent(out UndeadMinion _)
&& __instance.TryGetComponent(out MonsterAI monsterAI)
&& __instance.TryGetComponent(out UndeadMinion undeadMinion)
&& Player.m_localPlayer != null)
{
__result = monsterAI.GetFollowTarget() == Player.m_localPlayer.gameObject
? Localization.instance.Localize("$chebgonaz_wait")
: Localization.instance.Localize("$chebgonaz_follow");
__result = undeadMinion.Status switch
{
ChebGonazMinion.State.Following => Localization.instance.Localize("$chebgonaz_wait"),
ChebGonazMinion.State.Waiting => Localization.instance.Localize("$chebgonaz_roam"),
_ => Localization.instance.Localize("$chebgonaz_follow")
};
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions ChebsNecromancy/Structures/NeckroGathererPylon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class NeckroGathererPylon : Structure
public static ConfigEntry<float> SpawnInterval;
public static ConfigEntry<int> NeckTailsConsumedPerSpawn;

protected Container Container;
private Container _container;

public new static ChebsRecipe ChebsRecipeConfig = new()
{
Expand Down Expand Up @@ -56,7 +56,7 @@ public static void CreateConfigs(BasePlugin plugin)
private void Awake()
#pragma warning restore IDE0051 // Remove unused private members
{
Container = GetComponent<Container>();
_container = GetComponent<Container>();
StartCoroutine(SpawnNeckros());
}

Expand Down Expand Up @@ -88,10 +88,10 @@ protected void SpawnNeckro()
return;
}

int neckTailsInInventory = Container.GetInventory().CountItems("$item_necktail");
int neckTailsInInventory = _container.GetInventory().CountItems("$item_necktail");
if (neckTailsInInventory < NeckTailsConsumedPerSpawn.Value) return;

Container.GetInventory().RemoveItem("$item_necktail", NeckTailsConsumedPerSpawn.Value);
_container.GetInventory().RemoveItem("$item_necktail", NeckTailsConsumedPerSpawn.Value);

int quality = 1;

Expand Down
5 changes: 5 additions & 0 deletions Translations/English/chebsnecromancy.english.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"chebgonaz_spiritpylon_name": "Spirit Pylon",
"chebgonaz_spiritpylonghost": "Spirit Pylon Ghost",
"chebgonaz_wait": "Wait",
"chebgonaz_roam": "Roam",
"chebgonaz_follow": "Follow",
"chebgonaz_roaming": "Roaming, master...",
"chebgonaz_waiting": "Waiting, master...",
"chebgonaz_following": "Following, master...",
"friendlyskeletonwand_attack": "Attack",
"friendlyskeletonwand_attacktarget": "Target",
"friendlyskeletonwand_create": "Create Minion",
Expand Down

0 comments on commit 1f857f9

Please sign in to comment.