Skip to content

Commit

Permalink
Merge pull request #50 from jpw1991/45-pvp-siege-minions-eg-battering…
Browse files Browse the repository at this point in the history
…-ram-siege-troll

implement catapult minion
  • Loading branch information
jpw1991 authored Jun 10, 2024
2 parents db0eece + 0d310dd commit 7a0254e
Show file tree
Hide file tree
Showing 27 changed files with 239 additions and 123 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,4 @@ Environment.props

/ChebsMercenaries/libs/
*.backup
SitInChair.*
17 changes: 12 additions & 5 deletions ChebsMercenaries/BasePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Configuration;
Expand Down Expand Up @@ -72,6 +68,8 @@ public class BasePlugin : BaseUnityPlugin
"ChebGonaz_HumanWarriorTier2Female.prefab",
"ChebGonaz_HumanWarriorTier3Female.prefab",
"ChebGonaz_HumanWarriorTier4Female.prefab",

"ChebGonaz_Catapult.prefab",
};

#region ConfigStuff
Expand Down Expand Up @@ -124,6 +122,8 @@ private void CreateConfigValues()
HeavyLogging = Config.Bind("General (Client)", "HeavyLogging",
false, new ConfigDescription("Turn this on for debugging. Lots of things will get logged."));

MercenaryMinion.CreateConfigs(this);

HumanMinion.CreateConfigs(this);
HumanWoodcutterMinion.CreateConfigs(this);
HumanMinerMinion.CreateConfigs(this);
Expand All @@ -135,6 +135,8 @@ private void CreateConfigValues()
MercenaryWarriorTier2Minion.CreateConfigs(this);
MercenaryWarriorTier3Minion.CreateConfigs(this);
MercenaryWarriorTier4Minion.CreateConfigs(this);

CatapultMinion.CreateConfigs(this);

MercenaryChest.CreateConfigs(this);

Expand Down Expand Up @@ -296,6 +298,11 @@ private void LoadChebGonazAssetBundle()
if (HeavyLogging.Value) Jotunn.Logger.LogInfo($"Adding MercenaryArcherTier3Minion component to {prefabName}.");
prefab.AddComponent<MercenaryArcherTier3Minion>();
break;
case "ChebGonaz_Catapult.prefab":
if (HeavyLogging.Value) Jotunn.Logger.LogInfo($"Adding CatapultMinion component to {prefabName}.");
prefab.AddComponent<CatapultMinion>();
break;
default:
if (HeavyLogging.Value) Jotunn.Logger.LogInfo($"Adding HumanMinion component to {prefabName}.");
Expand Down
4 changes: 1 addition & 3 deletions ChebsMercenaries/Commands/PvP/PvPAddFriend.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using ChebsValheimLibrary.PvP;
using ChebsValheimLibrary.PvP;
using Jotunn.Entities;

namespace ChebsMercenaries.Commands.PvP
Expand Down
3 changes: 1 addition & 2 deletions ChebsMercenaries/Commands/PvP/PvPListFriends.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using ChebsValheimLibrary.PvP;
using ChebsValheimLibrary.PvP;
using Jotunn.Entities;

namespace ChebsMercenaries.Commands.PvP
Expand Down
4 changes: 1 addition & 3 deletions ChebsMercenaries/Commands/PvP/PvPRemoveFriend.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using ChebsValheimLibrary.PvP;
using ChebsValheimLibrary.PvP;
using Jotunn.Entities;

namespace ChebsMercenaries.Commands.PvP
Expand Down
3 changes: 1 addition & 2 deletions ChebsMercenaries/Items/WeaponOfCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using BepInEx;
using BepInEx;
using BepInEx.Configuration;
using ChebsValheimLibrary.Items;
using ChebsValheimLibrary.Minions;
Expand Down
50 changes: 50 additions & 0 deletions ChebsMercenaries/Minions/CatapultMinion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using BepInEx.Configuration;
using ChebsValheimLibrary.Common;
using Jotunn;

namespace ChebsMercenaries.Minions
{
internal class CatapultMinion : MercenaryMinion
{
public new static ConfigEntry<float> Health;
public static MemoryConfigEntry<string, List<string>> ItemsCost;

public new static void CreateConfigs(BasePlugin plugin)
{
const string serverSynced = "CatapultMinion (Server Synced)";

var itemsCost = plugin.ModConfig(serverSynced, "ItemsCost", "Wood:25,RoundLog:5,Bronze:1",
"The items that are consumed when creating a minion. Please use a comma-delimited list of prefab names with a : and integer for amount. Alternative items can be specified with a | eg. Wood|Coal:5 to mean wood and/or coal.",
null, true);
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').Select(str => str.Trim()).ToList());
Health = plugin.Config.Bind(serverSynced, "Health",
250f, new ConfigDescription("How much health the mercenary has.", null,
new ConfigurationManagerAttributes { IsAdminOnly = true }));
}

public sealed override void Awake()
{
base.Awake();

AfterAwake();
}

public virtual void AfterAwake()
{
ConfigureHealth();
}

protected virtual void ConfigureHealth()
{
if (TryGetComponent(out Humanoid humanoid))
{
humanoid.SetMaxHealth(Health.Value);
humanoid.SetHealth(Health.Value);
}
else
{
Logger.LogError("Error: Failed to get Humanoid component to set health value.");
}
}
}
}
2 changes: 0 additions & 2 deletions ChebsMercenaries/Minions/HumanMinerMinion.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
using ChebsMercenaries.Minions.WorkerAI;
using ChebsValheimLibrary.Common;
Expand Down
45 changes: 2 additions & 43 deletions ChebsMercenaries/Minions/HumanMinion.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
using ChebsMercenaries.Structure;
using ChebsValheimLibrary.Common;
Expand All @@ -11,49 +9,17 @@

namespace ChebsMercenaries.Minions
{
public class HumanMinion : ChebGonazMinion
public class HumanMinion : MercenaryMinion
{
public static ConfigEntry<DropType> DropOnDeath;
public static ConfigEntry<bool> PackDropItemsIntoCargoCrate;
public static ConfigEntry<bool> Commandable;
public static ConfigEntry<float> FollowDistance, RunDistance, RoamRange;
public static ConfigEntry<float> ChanceOfFemale;
public static MemoryConfigEntry<string, List<Vector3>> HairColors, SkinColors;

public static ConfigEntry<float> Health;

private static List<ItemDrop> _hairs, _beards;

public static void CreateConfigs(BasePlugin plugin)
public new static void CreateConfigs(BasePlugin plugin)
{
const string serverSync = "HumanMinion (Server Synced)";
const string client = "HumanMinion (Client)";
DropOnDeath = plugin.Config.Bind(serverSync,
"DropOnDeath",
DropType.JustResources, new ConfigDescription("Whether a minion refunds anything when it dies.", null,
new ConfigurationManagerAttributes { IsAdminOnly = true }));

PackDropItemsIntoCargoCrate = plugin.Config.Bind(serverSync,
"PackDroppedItemsIntoCargoCrate",
true, new ConfigDescription(
"If set to true, dropped items will be packed into a cargo crate. This means they won't sink in water, which is useful for more valuable drops like Surtling Cores and metal ingots.",
null,
new ConfigurationManagerAttributes { IsAdminOnly = true }));

Commandable = plugin.Config.Bind(client, "Commandable",
true,
new ConfigDescription(
"If true, minions can be commanded individually with E (or equivalent) keybind."));

FollowDistance = plugin.Config.Bind(client, "FollowDistance",
3f,
new ConfigDescription(
"How closely a minion will follow you (0 = standing on top of you, 3 = default)."));

RunDistance = plugin.Config.Bind(client, "RunDistance",
3f,
new ConfigDescription(
"How close a following minion needs to be to you before it stops running and starts walking (0 = always running, 10 = default)."));

ChanceOfFemale = plugin.ModConfig(serverSync, "ChanceOfFemale", 0.5f,
"Chance of a mercenary spawning being female. 0 = 0%, 1 = 100% (Default = 0.5 = 50%)",
Expand All @@ -80,13 +46,6 @@ public static void CreateConfigs(BasePlugin plugin)
: Vector3.zero).ToList();
return cols;
});

RoamRange = plugin.Config.Bind(client, "RoamRange",
10f, new ConfigDescription("How far a unit is allowed to roam from its current position."));

Health = plugin.Config.Bind(serverSync, "Health",
50f, new ConfigDescription("How much health the mercenary has (default fallback value).", null,
new ConfigurationManagerAttributes { IsAdminOnly = true }));
}

public enum MercenaryType
Expand Down
2 changes: 0 additions & 2 deletions ChebsMercenaries/Minions/HumanWoodcutterMinion.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
using ChebsMercenaries.Minions.WorkerAI;
using ChebsValheimLibrary.Common;
Expand Down
5 changes: 2 additions & 3 deletions ChebsMercenaries/Minions/MercenaryArcherTier1Minion.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
using ChebsValheimLibrary.Common;
using Jotunn;

namespace ChebsMercenaries.Minions
{
Expand Down Expand Up @@ -37,7 +36,7 @@ protected override void ConfigureHealth()
}
else
{
Jotunn.Logger.LogError("Error: Failed to get Humanoid component to set health value.");
Logger.LogError("Error: Failed to get Humanoid component to set health value.");
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions ChebsMercenaries/Minions/MercenaryArcherTier2Minion.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
using ChebsValheimLibrary.Common;
using Jotunn;

namespace ChebsMercenaries.Minions
{
Expand Down Expand Up @@ -37,7 +36,7 @@ protected override void ConfigureHealth()
}
else
{
Jotunn.Logger.LogError("Error: Failed to get Humanoid component to set health value.");
Logger.LogError("Error: Failed to get Humanoid component to set health value.");
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions ChebsMercenaries/Minions/MercenaryArcherTier3Minion.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
using ChebsValheimLibrary.Common;
using Jotunn;

namespace ChebsMercenaries.Minions
{
Expand Down Expand Up @@ -37,7 +36,7 @@ protected override void ConfigureHealth()
}
else
{
Jotunn.Logger.LogError("Error: Failed to get Humanoid component to set health value.");
Logger.LogError("Error: Failed to get Humanoid component to set health value.");
}
}
}
Expand Down
54 changes: 54 additions & 0 deletions ChebsMercenaries/Minions/MercenaryMinion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using BepInEx.Configuration;
using ChebsValheimLibrary.Minions;

namespace ChebsMercenaries.Minions
{
public class MercenaryMinion : ChebGonazMinion
{
public static ConfigEntry<DropType> DropOnDeath;
public static ConfigEntry<bool> PackDropItemsIntoCargoCrate;
public static ConfigEntry<bool> Commandable;
public static ConfigEntry<float> FollowDistance, RunDistance, RoamRange;

public static ConfigEntry<float> Health;

public static void CreateConfigs(BasePlugin plugin)
{
const string serverSync = "MercenaryMinion (Server Synced)";
const string client = "MercenaryMinion (Client)";
DropOnDeath = plugin.Config.Bind(serverSync,
"DropOnDeath",
DropType.JustResources, new ConfigDescription("Whether a minion refunds anything when it dies.", null,
new ConfigurationManagerAttributes { IsAdminOnly = true }));

PackDropItemsIntoCargoCrate = plugin.Config.Bind(serverSync,
"PackDroppedItemsIntoCargoCrate",
true, new ConfigDescription(
"If set to true, dropped items will be packed into a cargo crate. This means they won't sink in water, which is useful for more valuable drops like Surtling Cores and metal ingots.",
null,
new ConfigurationManagerAttributes { IsAdminOnly = true }));

Commandable = plugin.Config.Bind(client, "Commandable",
true,
new ConfigDescription(
"If true, minions can be commanded individually with E (or equivalent) keybind."));

FollowDistance = plugin.Config.Bind(client, "FollowDistance",
3f,
new ConfigDescription(
"How closely a minion will follow you (0 = standing on top of you, 3 = default)."));

RunDistance = plugin.Config.Bind(client, "RunDistance",
3f,
new ConfigDescription(
"How close a following minion needs to be to you before it stops running and starts walking (0 = always running, 10 = default)."));

RoamRange = plugin.Config.Bind(client, "RoamRange",
10f, new ConfigDescription("How far a unit is allowed to roam from its current position."));

Health = plugin.Config.Bind(serverSync, "Health",
50f, new ConfigDescription("How much health the mercenary has (default fallback value).", null,
new ConfigurationManagerAttributes { IsAdminOnly = true }));
}
}
}
5 changes: 2 additions & 3 deletions ChebsMercenaries/Minions/MercenaryWarriorTier1Minion.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
using ChebsValheimLibrary.Common;
using Jotunn;

namespace ChebsMercenaries.Minions
{
Expand Down Expand Up @@ -37,7 +36,7 @@ protected override void ConfigureHealth()
}
else
{
Jotunn.Logger.LogError("Error: Failed to get Humanoid component to set health value.");
Logger.LogError("Error: Failed to get Humanoid component to set health value.");
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions ChebsMercenaries/Minions/MercenaryWarriorTier2Minion.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
using ChebsValheimLibrary.Common;
using Jotunn;

namespace ChebsMercenaries.Minions
{
Expand Down Expand Up @@ -37,7 +36,7 @@ protected override void ConfigureHealth()
}
else
{
Jotunn.Logger.LogError("Error: Failed to get Humanoid component to set health value.");
Logger.LogError("Error: Failed to get Humanoid component to set health value.");
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions ChebsMercenaries/Minions/MercenaryWarriorTier3Minion.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
using ChebsValheimLibrary.Common;
using Jotunn;

namespace ChebsMercenaries.Minions
{
Expand Down Expand Up @@ -37,7 +36,7 @@ protected override void ConfigureHealth()
}
else
{
Jotunn.Logger.LogError("Error: Failed to get Humanoid component to set health value.");
Logger.LogError("Error: Failed to get Humanoid component to set health value.");
}
}
}
Expand Down
Loading

0 comments on commit 7a0254e

Please sign in to comment.