Skip to content

Commit 2bbe4b5

Browse files
authored
Merge pull request #44 from jpw1991/18-permit-minions-to-attack-other-players-that-are-not-the-owner
2.2.3: Permit PvP - if enabled, minions will attack players and creat…
2 parents 580cebc + a21582d commit 2bbe4b5

22 files changed

+270
-29
lines changed

ChebsMercenaries/BasePlugin.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
using System.Security.Cryptography;
77
using BepInEx;
88
using BepInEx.Configuration;
9+
using ChebsMercenaries.Commands.PvP;
910
using ChebsMercenaries.Items;
1011
using ChebsMercenaries.Minions;
1112
using ChebsMercenaries.Structure;
1213
using ChebsValheimLibrary;
14+
using ChebsValheimLibrary.PvP;
1315
using HarmonyLib;
1416
using Jotunn;
1517
using Jotunn.Entities;
@@ -27,11 +29,11 @@ public class BasePlugin : BaseUnityPlugin
2729
{
2830
public const string PluginGuid = "com.chebgonaz.chebsmercenaries";
2931
public const string PluginName = "ChebsMercenaries";
30-
public const string PluginVersion = "2.2.2";
32+
public const string PluginVersion = "2.3.7";
3133
private const string ConfigFileName = PluginGuid + ".cfg";
3234
private static readonly string ConfigFileFullPath = Path.Combine(Paths.ConfigPath, ConfigFileName);
3335

34-
public readonly System.Version ChebsValheimLibraryVersion = new("2.4.0");
36+
public readonly System.Version ChebsValheimLibraryVersion = new("2.5.2");
3537

3638
private readonly Harmony harmony = new(PluginGuid);
3739

@@ -41,6 +43,8 @@ public class BasePlugin : BaseUnityPlugin
4143
new MaceOfCommand(),
4244
new SwordOfCommand(),
4345
};
46+
47+
public static ConfigEntry<bool> PvPAllowed;
4448

4549
// if set to true, the particle effects that for some reason hurt radeon are dynamically disabled
4650
public static ConfigEntry<bool> RadeonFriendly, HeavyLogging;
@@ -105,6 +109,10 @@ public ConfigEntry<T> ModConfig<T>(
105109
private void CreateConfigValues()
106110
{
107111
Config.SaveOnConfigSet = true;
112+
113+
PvPAllowed = Config.Bind("General (Server Synced)", "PvPAllowed",
114+
false, new ConfigDescription("Whether minions will target and attack other players and their minions.", null,
115+
new ConfigurationManagerAttributes { IsAdminOnly = true }));
108116

109117
RadeonFriendly = Config.Bind("General (Client)", "RadeonFriendly",
110118
false, new ConfigDescription("ONLY set this to true if you have graphical issues with " +
@@ -183,18 +191,35 @@ private void Awake()
183191
}
184192

185193
CreateConfigValues();
194+
PvPManager.ConfigureRPC();
186195
LoadChebGonazAssetBundle();
187196
harmony.PatchAll();
197+
198+
var pvpCommands = new List<ConsoleCommand>()
199+
{ new PvPAddFriend(), new PvPRemoveFriend(), new PvPListFriends() };
200+
foreach (var pvpCommand in pvpCommands)
201+
{
202+
if (!CommandManager.Instance.CustomCommands
203+
.ToList().Exists(c => c.Name == pvpCommand.Name))
204+
CommandManager.Instance.AddConsoleCommand(pvpCommand);
205+
}
188206

189207
SynchronizationManager.OnConfigurationSynchronized += (obj, attr) =>
190208
{
191209
Logger.LogInfo(!attr.InitialSynchronization
192210
? "Syncing configuration changes from server..."
193211
: "Syncing initial configuration...");
212+
StartCoroutine(RequestPvPDict());
194213
};
195214

196215
StartCoroutine(WatchConfigFile());
197216
}
217+
218+
private IEnumerator RequestPvPDict()
219+
{
220+
yield return new WaitUntil(() => ZNet.instance != null && Player.m_localPlayer != null);
221+
PvPManager.InitialFriendsListRequest();
222+
}
198223

199224
private void LoadChebGonazAssetBundle()
200225
{

ChebsMercenaries/ChebsMercenaries.csproj

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\JotunnLib.2.15.0\build\JotunnLib.props" Condition="Exists('..\packages\JotunnLib.2.15.0\build\JotunnLib.props')" />
3+
<Import Project="..\packages\JotunnLib.2.16.1\build\JotunnLib.props" Condition="Exists('..\packages\JotunnLib.2.16.1\build\JotunnLib.props')" />
44
<Import Project="..\packages\BepInEx.AssemblyPublicizer.MSBuild.0.4.1\build\BepInEx.AssemblyPublicizer.MSBuild.props" Condition="Exists('..\packages\BepInEx.AssemblyPublicizer.MSBuild.0.4.1\build\BepInEx.AssemblyPublicizer.MSBuild.props')" />
55
<PropertyGroup>
66
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -65,8 +65,8 @@
6565
<Reference Include="ChebsValheimLibrary">
6666
<HintPath>..\..\chebs-valheim-library\ChebsValheimLibrary\bin\Release\ChebsValheimLibrary.dll</HintPath>
6767
</Reference>
68-
<Reference Include="Jotunn, Version=2.15.0.0, Culture=neutral, processorArchitecture=MSIL">
69-
<HintPath>..\packages\JotunnLib.2.15.0\lib\net462\Jotunn.dll</HintPath>
68+
<Reference Include="Jotunn, Version=2.16.1.0, Culture=neutral, processorArchitecture=MSIL">
69+
<HintPath>..\packages\JotunnLib.2.16.1\lib\net462\Jotunn.dll</HintPath>
7070
</Reference>
7171
<Reference Include="Mono.Cecil, Version=0.11.5.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
7272
<HintPath>..\packages\Mono.Cecil.0.11.5\lib\net40\Mono.Cecil.dll</HintPath>
@@ -135,6 +135,9 @@
135135
</Reference>
136136
</ItemGroup>
137137
<ItemGroup>
138+
<Compile Include="Commands\PvP\PvPAddFriend.cs" />
139+
<Compile Include="Commands\PvP\PvPListFriends.cs" />
140+
<Compile Include="Commands\PvP\PvPRemoveFriend.cs" />
138141
<Compile Include="Items\AxeOfCommand.cs" />
139142
<Compile Include="Items\MaceOfCommand.cs" />
140143
<Compile Include="Items\SwordOfCommand.cs" />
@@ -196,6 +199,6 @@
196199
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
197200
</PropertyGroup>
198201
<Error Condition="!Exists('..\packages\BepInEx.AssemblyPublicizer.MSBuild.0.4.1\build\BepInEx.AssemblyPublicizer.MSBuild.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\BepInEx.AssemblyPublicizer.MSBuild.0.4.1\build\BepInEx.AssemblyPublicizer.MSBuild.props'))" />
199-
<Error Condition="!Exists('..\packages\JotunnLib.2.15.0\build\JotunnLib.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\JotunnLib.2.15.0\build\JotunnLib.props'))" />
202+
<Error Condition="!Exists('..\packages\JotunnLib.2.16.1\build\JotunnLib.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\JotunnLib.2.16.1\build\JotunnLib.props'))" />
200203
</Target>
201204
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using ChebsValheimLibrary.PvP;
4+
using Jotunn.Entities;
5+
6+
namespace ChebsMercenaries.Commands.PvP
7+
{
8+
public class PvPAddFriend : ConsoleCommand
9+
{
10+
public override string Name => "chebgonaz_pvp_friend_add";
11+
12+
public override string Help => "Registers a fellow player as your ally. If both you and your ally register " +
13+
"each other in this way, your minions won't fight each other.\n" +
14+
$"Usage: {Name} [NAME1] [NAME2] ...\n" +
15+
$"eg. {Name} Bob Billy Jane";
16+
17+
public override void Run(string[] args)
18+
{
19+
if (args.Length < 1)
20+
{
21+
Console.instance.Print(Help);
22+
return;
23+
}
24+
25+
var playerNames = args.Select(s => s.Trim()).ToList();
26+
var friends = PvPManager.GetPlayerFriends();
27+
foreach (var playerName in playerNames)
28+
{
29+
if (!friends.Contains(playerName))
30+
{
31+
friends.Add(playerName);
32+
}
33+
}
34+
PvPManager.UpdatePlayerFriendsDict(friends);
35+
}
36+
37+
public override List<string> CommandOptionList()
38+
{
39+
return ZNetScene.instance?.GetPrefabNames();
40+
}
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections.Generic;
2+
using ChebsValheimLibrary.PvP;
3+
using Jotunn.Entities;
4+
5+
namespace ChebsMercenaries.Commands.PvP
6+
{
7+
public class PvPListFriends : ConsoleCommand
8+
{
9+
public override string Name => "chebgonaz_pvp_friend_list";
10+
11+
public override string Help => "Lists your current PvP friends.";
12+
13+
public override void Run(string[] args)
14+
{
15+
var friends = PvPManager.GetPlayerFriends();
16+
Console.instance.Print(string.Join(" ", friends));
17+
}
18+
19+
public override List<string> CommandOptionList()
20+
{
21+
return ZNetScene.instance?.GetPrefabNames();
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using ChebsValheimLibrary.PvP;
4+
using Jotunn.Entities;
5+
6+
namespace ChebsMercenaries.Commands.PvP
7+
{
8+
public class PvPRemoveFriend : ConsoleCommand
9+
{
10+
public override string Name => "chebgonaz_pvp_friend_remove";
11+
12+
public override string Help => "Removes a fellow player as your ally.\n" +
13+
$"Usage: {Name} [NAME1] [NAME2] ...\n" +
14+
$"eg. {Name} Bob Billy Jane";
15+
16+
public override void Run(string[] args)
17+
{
18+
if (args.Length < 1)
19+
{
20+
Console.instance.Print(Help);
21+
return;
22+
}
23+
24+
var playerNames = args.Select(s => s.Trim()).ToList();
25+
var friends = PvPManager.GetPlayerFriends();
26+
friends.RemoveAll(friend => playerNames.Contains(friend));
27+
28+
PvPManager.UpdatePlayerFriendsDict(friends);
29+
}
30+
31+
public override List<string> CommandOptionList()
32+
{
33+
return ZNetScene.instance?.GetPrefabNames();
34+
}
35+
}
36+
}

ChebsMercenaries/Minions/HumanMinerMinion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class HumanMinerMinion : HumanMinion
3939
var itemsCost = plugin.ModConfig(serverSynced, "ItemsCost", "CookedMeat|Coins:5,HardAntler:1",
4040
"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.",
4141
null, true);
42-
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').ToList());
42+
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').Select(str => str.Trim()).ToList());
4343
Health = plugin.Config.Bind(serverSynced, "Health",
4444
50f, new ConfigDescription("How much health the mercenary has.", null,
4545
new ConfigurationManagerAttributes { IsAdminOnly = true }));

ChebsMercenaries/Minions/HumanMinion.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static void CreateConfigs(BasePlugin plugin)
6262
"Comma delimited list of HTML color codes.", null, true);
6363
HairColors = new MemoryConfigEntry<string, List<Vector3>>(hairColors, s =>
6464
{
65-
var cols = s?.Split(',').ToList().Select(colorCode =>
65+
var cols = s?.Split(',').Select(str => str.Trim()).ToList().Select(colorCode =>
6666
ColorUtility.TryParseHtmlString(colorCode, out Color color)
6767
? Utils.ColorToVec3(color)
6868
: Vector3.zero).ToList();
@@ -73,7 +73,7 @@ public static void CreateConfigs(BasePlugin plugin)
7373
"Comma delimited list of HTML color codes.", null, true);
7474
SkinColors = new MemoryConfigEntry<string, List<Vector3>>(skinColors, s =>
7575
{
76-
var cols = s?.Split(',').ToList().Select(colorCode =>
76+
var cols = s?.Split(',').Select(str => str.Trim()).ToList().Select(colorCode =>
7777
ColorUtility.TryParseHtmlString(colorCode, out Color color)
7878
? Utils.ColorToVec3(color)
7979
: Vector3.zero).ToList();

ChebsMercenaries/Minions/HumanWoodcutterMinion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class HumanWoodcutterMinion : HumanMinion
3131
var itemsCost = plugin.ModConfig(serverSynced, "ItemsCost", "CookedMeat|Coins:5,Flint:1",
3232
"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.",
3333
null, true);
34-
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').ToList());
34+
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').Select(str => str.Trim()).ToList());
3535
Health = plugin.Config.Bind(serverSynced, "Health",
3636
50f, new ConfigDescription("How much health the mercenary has.", null,
3737
new ConfigurationManagerAttributes { IsAdminOnly = true }));

ChebsMercenaries/Minions/MercenaryArcherTier1Minion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class MercenaryArcherTier1Minion : HumanMinion
1717
var itemsCost = plugin.ModConfig(serverSynced, "ItemsCost", "CookedMeat|Coins:5,ArrowWood:20",
1818
"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.",
1919
null, true);
20-
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').ToList());
20+
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').Select(str => str.Trim()).ToList());
2121
Health = plugin.Config.Bind(serverSynced, "Health",
2222
50f, new ConfigDescription("How much health the mercenary has.", null,
2323
new ConfigurationManagerAttributes { IsAdminOnly = true }));

ChebsMercenaries/Minions/MercenaryArcherTier2Minion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class MercenaryArcherTier2Minion : HumanMinion
1717
var itemsCost = plugin.ModConfig(serverSynced, "ItemsCost", "Coins:50,ArrowBronze:10",
1818
"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.",
1919
null, true);
20-
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').ToList());
20+
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').Select(str => str.Trim()).ToList());
2121
Health = plugin.Config.Bind(serverSynced, "Health",
2222
100f, new ConfigDescription("How much health the mercenary has.", null,
2323
new ConfigurationManagerAttributes { IsAdminOnly = true }));

ChebsMercenaries/Minions/MercenaryArcherTier3Minion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class MercenaryArcherTier3Minion : HumanMinion
1717
var itemsCost = plugin.ModConfig(serverSynced, "ItemsCost", "Coins:100,ArrowIron:10",
1818
"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.",
1919
null, true);
20-
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').ToList());
20+
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').Select(str => str.Trim()).ToList());
2121
Health = plugin.Config.Bind(serverSynced, "Health",
2222
200f, new ConfigDescription("How much health the mercenary has.", null,
2323
new ConfigurationManagerAttributes { IsAdminOnly = true }));

ChebsMercenaries/Minions/MercenaryWarriorTier1Minion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class MercenaryWarriorTier1Minion : HumanMinion
1717
var itemsCost = plugin.ModConfig(serverSynced, "ItemsCost", "CookedMeat|Coins:5",
1818
"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.",
1919
null, true);
20-
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').ToList());
20+
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').Select(str => str.Trim()).ToList());
2121
Health = plugin.Config.Bind(serverSynced, "Health",
2222
50f, new ConfigDescription("How much health the mercenary has.", null,
2323
new ConfigurationManagerAttributes { IsAdminOnly = true }));

ChebsMercenaries/Minions/MercenaryWarriorTier2Minion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class MercenaryWarriorTier2Minion : HumanMinion
1717
var itemsCost = plugin.ModConfig(serverSynced, "ItemsCost", "Coins:25",
1818
"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.",
1919
null, true);
20-
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').ToList());
20+
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').Select(str => str.Trim()).ToList());
2121
Health = plugin.Config.Bind(serverSynced, "Health",
2222
100f, new ConfigDescription("How much health the mercenary has.", null,
2323
new ConfigurationManagerAttributes { IsAdminOnly = true }));

ChebsMercenaries/Minions/MercenaryWarriorTier3Minion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class MercenaryWarriorTier3Minion : HumanMinion
1717
var itemsCost = plugin.ModConfig(serverSynced, "ItemsCost", "Coins:50",
1818
"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.",
1919
null, true);
20-
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').ToList());
20+
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').Select(str => str.Trim()).ToList());
2121
Health = plugin.Config.Bind(serverSynced, "Health",
2222
200f, new ConfigDescription("How much health the mercenary has.", null,
2323
new ConfigurationManagerAttributes { IsAdminOnly = true }));

ChebsMercenaries/Minions/MercenaryWarriorTier4Minion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class MercenaryWarriorTier4Minion : HumanMinion
1717
var itemsCost = plugin.ModConfig(serverSynced, "ItemsCost", "Coins:100",
1818
"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.",
1919
null, true);
20-
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').ToList());
20+
ItemsCost = new MemoryConfigEntry<string, List<string>>(itemsCost, s => s?.Split(',').Select(str => str.Trim()).ToList());
2121
Health = plugin.Config.Bind(serverSynced, "Health",
2222
400f, new ConfigDescription("How much health the mercenary has.", null,
2323
new ConfigurationManagerAttributes { IsAdminOnly = true }));

0 commit comments

Comments
 (0)