Skip to content

Commit

Permalink
2.3.4: RPC PvP implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpw1991 committed Jan 7, 2024
1 parent 79231f6 commit 304364d
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 17 deletions.
14 changes: 12 additions & 2 deletions ChebsMercenaries/BasePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using BepInEx.Configuration;
using ChebsMercenaries.Items;
using ChebsMercenaries.Minions;
using ChebsMercenaries.PvP;
using ChebsMercenaries.Structure;
using ChebsValheimLibrary;
using HarmonyLib;
Expand All @@ -27,11 +28,11 @@ public class BasePlugin : BaseUnityPlugin
{
public const string PluginGuid = "com.chebgonaz.chebsmercenaries";
public const string PluginName = "ChebsMercenaries";
public const string PluginVersion = "2.2.3";
public const string PluginVersion = "2.3.4";
private const string ConfigFileName = PluginGuid + ".cfg";
private static readonly string ConfigFileFullPath = Path.Combine(Paths.ConfigPath, ConfigFileName);

public readonly System.Version ChebsValheimLibraryVersion = new("2.4.0");
public readonly System.Version ChebsValheimLibraryVersion = new("2.4.1");

private readonly Harmony harmony = new(PluginGuid);

Expand All @@ -43,6 +44,7 @@ public class BasePlugin : BaseUnityPlugin
};

public static ConfigEntry<bool> PvPAllowed;
public static ConfigEntry<string> PvPFriendsList;

// if set to true, the particle effects that for some reason hurt radeon are dynamically disabled
public static ConfigEntry<bool> RadeonFriendly, HeavyLogging;
Expand Down Expand Up @@ -111,6 +113,13 @@ private void CreateConfigValues()
PvPAllowed = Config.Bind("General (Server Synced)", "PvPAllowed",
false, new ConfigDescription("Whether minions will target and attack other players and their minions.", null,
new ConfigurationManagerAttributes { IsAdminOnly = true }));
PvPFriendsList = Config.Bind("General (Client)", "PvPFriendsList",
"", new ConfigDescription("A comma delimited list of player names who your minions are friendly to eg. Jane,Bob,Istvan"));
PvPFriendsList.SettingChanged += ((sender, args) =>
{
if (HeavyLogging.Value) Logger.LogInfo("PvP Friends list updated");
PvPManager.UpdatePlayerFriendsDict(PvPFriendsList.Value);
});

RadeonFriendly = Config.Bind("General (Client)", "RadeonFriendly",
false, new ConfigDescription("ONLY set this to true if you have graphical issues with " +
Expand Down Expand Up @@ -189,6 +198,7 @@ private void Awake()
}

CreateConfigValues();
PvPManager.ConfigureRPC();
LoadChebGonazAssetBundle();
harmony.PatchAll();

Expand Down
10 changes: 6 additions & 4 deletions ChebsMercenaries/ChebsMercenaries.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\JotunnLib.2.15.0\build\JotunnLib.props" Condition="Exists('..\packages\JotunnLib.2.15.0\build\JotunnLib.props')" />
<Import Project="..\packages\JotunnLib.2.16.1\build\JotunnLib.props" Condition="Exists('..\packages\JotunnLib.2.16.1\build\JotunnLib.props')" />
<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')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -65,8 +65,8 @@
<Reference Include="ChebsValheimLibrary">
<HintPath>..\..\chebs-valheim-library\ChebsValheimLibrary\bin\Release\ChebsValheimLibrary.dll</HintPath>
</Reference>
<Reference Include="Jotunn, Version=2.15.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\JotunnLib.2.15.0\lib\net462\Jotunn.dll</HintPath>
<Reference Include="Jotunn, Version=2.16.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\JotunnLib.2.16.1\lib\net462\Jotunn.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil, Version=0.11.5.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.5\lib\net40\Mono.Cecil.dll</HintPath>
Expand Down Expand Up @@ -156,13 +156,15 @@
<Compile Include="Patches\CharacterDropPatches.cs" />
<Compile Include="Patches\CharacterPatches.cs" />
<Compile Include="Patches\ImpactEffectPatches.cs" />
<Compile Include="Patches\PlayerProfilePatches.cs" />
<Compile Include="Patches\TameablePatches.cs" />
<Compile Include="Patches\VisEquipmentPatches.cs" />
<Compile Include="Patches\WearNTearPatches.cs" />
<Compile Include="Patches\ZNetScenePatches.cs" />
<Compile Include="Properties\IgnoreAccessModifiers.cs" />
<Compile Include="BasePlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PvP\PvPManager.cs" />
<Compile Include="Structure\MercenaryChest.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -196,6 +198,6 @@
<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>
</PropertyGroup>
<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'))" />
<Error Condition="!Exists('..\packages\JotunnLib.2.15.0\build\JotunnLib.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\JotunnLib.2.15.0\build\JotunnLib.props'))" />
<Error Condition="!Exists('..\packages\JotunnLib.2.16.1\build\JotunnLib.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\JotunnLib.2.16.1\build\JotunnLib.props'))" />
</Target>
</Project>
3 changes: 3 additions & 0 deletions ChebsMercenaries/Package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Cheb's Mercenaries adds mercenaries to Valheim that you can purchase with gold a

It is related to my other mod called [Cheb's Necromancy](https://github.com/jpw1991/chebs-necromancy) and shares a lot of concepts and functionality. It's basically for people that want living human minions rather than the undead.

**Attention:** PvP is a new feature in 2.2.3 and needs testing. By default, it is disabled. To turn it on, set `PvPAllowed` to true in the config. Your minions should now be hostile to other players. Please report problems [here](https://github.com/jpw1991/chebs-mercenaries/pull/44).

## About Me

[![image1](https://imgur.com/Fahi6sP.png)](https://necrobase.chebgonaz.com)
Expand Down Expand Up @@ -138,6 +140,7 @@ You can find the github [here](https://github.com/jpw1991/chebs-mercenaries).

Date | Version | Notes
--- | --- | ---
22/12/2023 | 2.2.3 | Permit PvP - if enabled, minions will attack players and creatures that are not their owner.
29/11/2023 | 2.2.2 | Fix issue of configs not syncing reliably
07/10/2023 | 2.2.1 | update missing custom shader in chebgonaz bundle
06/10/2023 | 2.2.0 | update for hildr's
Expand Down
4 changes: 2 additions & 2 deletions ChebsMercenaries/Package/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "ChebsMercenaries",
"description": "Cheb's Mercenaries adds mercenaries to Valheim that you can purchase with gold and upgrade with materials to fight (warriors, archers) or perform work (lumberjacks, miners).",
"version_number": "2.2.3",
"version_number": "2.3.4",
"website_url": "https://github.com/jpw1991/chebs-mercenaries",
"dependencies": [
"ValheimModding-Jotunn-2.14.4"
"ValheimModding-Jotunn-2.16.1"
]
}
17 changes: 12 additions & 5 deletions ChebsMercenaries/Patches/BaseAIPatches.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ChebsMercenaries.Minions;
using ChebsMercenaries.PvP;
using ChebsValheimLibrary.Minions;
using HarmonyLib;
using UnityEngine;
Expand Down Expand Up @@ -48,7 +49,7 @@ static void Postfix(GameObject go, float dt, BaseAI __instance)
}
}

[HarmonyPatch(typeof(BaseAI))]
[HarmonyPatch(typeof(BaseAI))]
class BaseAIPatch2
{
[HarmonyPatch(nameof(BaseAI.IsEnemy), new []{typeof(Character), typeof(Character)})]
Expand Down Expand Up @@ -84,10 +85,12 @@ static void Postfix(Character a, Character b, ref bool __result)
__result = false;
return;
}

if (minionMasterA != minionMasterB)
{
__result = true;
var minionAFriendlyToMinionB = PvPManager.Friendly(minionMasterA, minionMasterB);
var minionBFriendlyToMinionA = PvPManager.Friendly(minionMasterB, minionMasterA);
__result = !(minionAFriendlyToMinionB && minionBFriendlyToMinionA);
}
}
else if (minionB != null)
Expand All @@ -96,7 +99,9 @@ static void Postfix(Character a, Character b, ref bool __result)
&& minionMasterB != "" // do nothing if unclaimed minion
&& minionMasterB != player.GetPlayerName())
{
__result = true;
var friendly = PvPManager.Friendly(player.GetPlayerName(), minionMasterB);
//if (BasePlugin.HeavyLogging.Value) Jotunn.Logger.LogInfo($"Friendly = {friendly}");
__result = !friendly;
}
// B is a player owned thing of some kind
// for now, defer to default handling
Expand All @@ -107,7 +112,9 @@ static void Postfix(Character a, Character b, ref bool __result)
&& minionMasterA != "" // do nothing if unclaimed minion
&& minionMasterA != player.GetPlayerName())
{
__result = true;
var friendly = PvPManager.Friendly(player.GetPlayerName(), minionMasterA);
//if (BasePlugin.HeavyLogging.Value) Jotunn.Logger.LogInfo($"Friendly = {friendly}");
__result = !friendly;
}
// A is a player owned thing of some kind
// for now, defer to default handling
Expand Down
34 changes: 34 additions & 0 deletions ChebsMercenaries/Patches/PlayerProfilePatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using ChebsMercenaries.PvP;
using HarmonyLib;
using Jotunn;

// ReSharper disable InconsistentNaming
// ReSharper disable UnusedParameter.Local

// Harmony patching is very sensitive regarding parameter names. Everything in this region should be hand crafted
// and not touched by well-meaning but clueless IDE optimizations.
// eg.
// * __instance MUST be named with exactly two underscores.
// * ___m_drops MUST be named with exactly three underscores.
// * Unused parameters must be left there because they must match the method to override
// * All patch methods need to be static
//
// This is because all of this has a special meaning to Harmony.

namespace ChebsMercenaries.Patches
{
public class PlayerProfilePatches
{
[HarmonyPatch(typeof(PlayerProfile))]
class PlayerProfilePatch1
{
[HarmonyPatch(nameof(PlayerProfile.LoadPlayerData))]
[HarmonyPostfix]
static void Postfix(Player __instance)
{
if (BasePlugin.HeavyLogging.Value) Logger.LogInfo($"PlayerProfile.LoadPlayerData postfix - update pvp friends list...");
PvPManager.UpdatePlayerFriendsDict(BasePlugin.PvPFriendsList.Value);
}
}
}
}
4 changes: 2 additions & 2 deletions ChebsMercenaries/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.3.0")]
[assembly: AssemblyFileVersion("2.2.3.0")]
[assembly: AssemblyVersion("2.3.4.0")]
[assembly: AssemblyFileVersion("2.3.4.0")]
Loading

0 comments on commit 304364d

Please sign in to comment.