Skip to content

Commit

Permalink
Added Scarlet Edge CE support, initial implementation of CE AP calc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicguru committed Apr 15, 2023
1 parent f878bae commit 69b7022
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 49 deletions.
61 changes: 61 additions & 0 deletions Patch_CombatExtended/1.4/Patches/CE_Melee_Weebstick.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Patch>

<Operation Class="PatchOperationSequence">
<operations>

<!-- === AM_Weebstick === -->

<li Class="PatchOperationReplace">
<xpath>/Defs/ThingDef[defName="AM_Weebstick"]/tools</xpath>
<value>
<tools>
<li Class="CombatExtended.ToolCE">
<label>point</label>
<capacities>
<li>Stab</li>
</capacities>
<power>25</power>
<cooldownTime>1.8</cooldownTime>
<chanceFactor>0.9</chanceFactor>
<armorPenetrationBlunt>22</armorPenetrationBlunt>
<armorPenetrationSharp>29</armorPenetrationSharp>
<linkedBodyPartsGroup>Point</linkedBodyPartsGroup>
</li>
<li Class="CombatExtended.ToolCE">
<label>edge</label>
<capacities>
<li>Cut</li>
</capacities>
<power>28</power>
<cooldownTime>2</cooldownTime>
<chanceFactor>0.50</chanceFactor>
<armorPenetrationBlunt>20</armorPenetrationBlunt>
<armorPenetrationSharp>27</armorPenetrationSharp>
<linkedBodyPartsGroup>Edge</linkedBodyPartsGroup>
</li>
</tools>
</value>
</li>

<li Class="PatchOperationAdd">
<xpath>/Defs/ThingDef[defName="AM_Weebstick"]/statBases</xpath>
<value>
<Bulk>15</Bulk>
<MeleeCounterParryBonus>1.1</MeleeCounterParryBonus>
</value>
</li>

<li Class="PatchOperationAdd">
<xpath>Defs/ThingDef[defName="AM_Weebstick"]/equippedStatOffsets</xpath>
<value>
<MeleeCritChance>0.8</MeleeCritChance>
<MeleeParryChance>0.9</MeleeParryChance>
<MeleeDodgeChance>0.55</MeleeDodgeChance>
</value>
</li>

</operations>
</Operation>

</Patch>
4 changes: 4 additions & 0 deletions Source/AnimationMod.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompatibilityReportGenerato
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CAI5000Patch", "CAI5000Patch\CAI5000Patch.csproj", "{0B91E675-3505-4587-94BB-6FEFC5ADB24D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CombatExtendedPatch", "CombatExtendedPatch\CombatExtendedPatch.csproj", "{BBB0D084-8A32-458E-8A7F-48E7D90F0489}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
v1.4|Any CPU = v1.4|Any CPU
Expand All @@ -39,6 +41,8 @@ Global
{67701E3B-9094-4CA2-9DD8-42EBAFCB9F4A}.v1.4|Any CPU.Build.0 = Debug|Any CPU
{0B91E675-3505-4587-94BB-6FEFC5ADB24D}.v1.4|Any CPU.ActiveCfg = v1.4|Any CPU
{0B91E675-3505-4587-94BB-6FEFC5ADB24D}.v1.4|Any CPU.Build.0 = v1.4|Any CPU
{BBB0D084-8A32-458E-8A7F-48E7D90F0489}.v1.4|Any CPU.ActiveCfg = v1.4|Any CPU
{BBB0D084-8A32-458E-8A7F-48E7D90F0489}.v1.4|Any CPU.Build.0 = v1.4|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
77 changes: 77 additions & 0 deletions Source/CombatExtendedPatch/CombatExtendedOutcomeWorker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using AM.Outcome;
using CombatExtended;
using RimWorld;
using System.Collections.Generic;
using Verse;

namespace AM.CombatExtendedPatch;

public sealed class CombatExtendedOutcomeWorker : IOutcomeWorker
{
public IEnumerable<PossibleMeleeAttack> GetMeleeAttacksFor(ThingWithComps weapon, Pawn pawn)
{
var comp = weapon?.GetComp<CompEquippable>();
if (comp == null)
yield break;

foreach (var verb in comp.AllVerbs)
{
if (!verb.IsMeleeAttack)
continue;

float dmg = GetDamage(weapon, verb, pawn);
float ap = GetPen(weapon, verb, pawn);

yield return new PossibleMeleeAttack
{
Damage = dmg,
ArmorPen = ap,
Pawn = pawn,
DamageDef = verb.GetDamageDef(),
Verb = verb,
Weapon = weapon
};
}
}

public float GetPen(ThingWithComps weapon, Verb verb, Pawn attacker)
{
var tool = verb.tool as ToolCE;
if (tool == null)
return verb.tool.armorPenetration * GetPenetrationFactor(weapon);

var isBlunt = verb.GetDamageDef()?.armorCategory?.armorRatingStat == StatDefOf.ArmorRating_Blunt;
if (isBlunt)
return tool.armorPenetrationBlunt * GetPenetrationFactor(weapon);
return tool.armorPenetrationSharp * GetPenetrationFactor(weapon);
}

public float GetDamage(ThingWithComps weapon, Verb verb, Pawn attacker)
=> verb.verbProps.AdjustedMeleeDamageAmount(verb.tool, attacker, weapon, verb.HediffCompSource);

private float GetPenetrationFactor(Thing weapon)
=> weapon?.GetStatValue(CE_StatDefOf.MeleePenetrationFactor) ?? 1f;

public float GetChanceToPenAprox(Pawn pawn, BodyPartRecord bodyPart, StatDef armorType, float armorPen)
{
// Get skin & hediff chance-to-pen.
float armor = pawn.GetStatValue(armorType);

if (pawn.apparel != null)
{
// Get apparel chance-to-pen.
foreach (var a in pawn.apparel.WornApparel)
{
if (!a.def.apparel.CoversBodyPart(bodyPart))
continue;

armor += a.GetStatValue(armorType);
}
}

// 75% of the required pen gives 0% pen chance, increasing to 100% at 100% required pen.
// Not perfect, but a reasonable approximation.
float rawPct = armor <= 0f ? 1f : armorPen / armor;
return OutcomeUtility.RemapClamped(0.75f, 1f, 0f, 1f, rawPct);
}
}
54 changes: 54 additions & 0 deletions Source/CombatExtendedPatch/CombatExtendedPatch.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<OutputType>Library</OutputType>
<LangVersion>preview</LangVersion>
<NoStdLib>false</NoStdLib>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<Configurations>v1.4</Configurations>
<RootNamespace>AM.CombatExtendedPatch</RootNamespace>
<AssemblyName>zz.AM.CombatExtendedPatch</AssemblyName>
<Nullable>disable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>none</DebugType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ThingGenerator\AnimationMod.csproj">
<CopyLocal>False</CopyLocal>
<Private>False</Private>
<ExcludeAssets>all</ExcludeAssets>
</ProjectReference>
</ItemGroup>

<!-- _____ 1.4 _____ -->
<ItemGroup Condition="'$(Configuration)'=='v1.4'">
<PackageReference Include="Krafs.Rimworld.Ref">
<Version>1.4.3641</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="CombatExtended">
<HintPath>CombatExtended_14.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</Reference>
</ItemGroup>

<!-- Output -->
<PropertyGroup Condition="'$(Configuration)'=='v1.4'">
<DebugType>none</DebugType>
<OutputPath>..\..\Patch_CombatExtended\1.4\Assemblies\</OutputPath>
<Optimize>true</Optimize>
<DefineConstants>TRACE;V14</DefineConstants>
</PropertyGroup>

</Project>
Binary file added Source/CombatExtendedPatch/CombatExtended_14.dll
Binary file not shown.
23 changes: 23 additions & 0 deletions Source/CombatExtendedPatch/PatchCore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using JetBrains.Annotations;
using Verse;

namespace AM.CombatExtendedPatch;

[UsedImplicitly]
[HotSwapAll]
public class PatchCore : Mod
{
public static void Log(string msg)
{
Core.Log($"[<color=#63e0ff>CE Patch</color>] {msg}");
}

public PatchCore(ModContentPack content) : base(content)
{
// Replace the vanilla outcome worker with the combat extended one,
// which uses the combat extended armor system.
OutcomeUtility.OutcomeWorker = new CombatExtendedOutcomeWorker();

Log("Loaded and applied CE patch.");
}
}
2 changes: 1 addition & 1 deletion Source/ThingGenerator/AnimationMod.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
Expand Down
26 changes: 13 additions & 13 deletions Source/ThingGenerator/Core.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AM.Retexture;
using AM.AMSettings;
using AM.Patches;
using AM.Retexture;
using AM.Tweaks;
using GistAPI;
using GistAPI.Models;
using HarmonyLib;
using ModRequestAPI;
using RimWorld;
using UnityEngine;
using Verse;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using AM.AMSettings;
using System.IO;
using GistAPI.Models;
using GistAPI;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;

namespace AM
{
Expand Down Expand Up @@ -135,7 +135,6 @@ public Core(ModContentPack content) : base(content)
{
AnimRenderer.DefaultCutout ??= new Material(ThingDefOf.AIPersonaCore.graphic.Shader);
AnimRenderer.DefaultTransparent ??= new Material(ShaderTypeDefOf.Transparent.Shader);
//AnimRenderer.DefaultTransparent ??= new Material(DefDatabase<ShaderTypeDef>.GetNamed("Mote").Shader);
});

AddLateLoadAction(false, "Checking for Simple Sidearms install...", CheckSimpleSidearms);
Expand All @@ -149,6 +148,7 @@ public Core(ModContentPack content) : base(content)
AddLateLoadAction(true, "Matching textures with mods...", PreCacheAllRetextures);
AddLateLoadAction(true, "Loading weapon tweak data...", LoadAllTweakData);
AddLateLoadAction(true, "Patch VBE", PatchVBE);
AddLateLoadAction(true, "Apply final patches", Patch_Verb_MeleeAttack_ApplyMeleeDamageToTarget.PatchAll);

AddLateLoadEvents();
}
Expand Down
6 changes: 3 additions & 3 deletions Source/ThingGenerator/Idle/IdleControllerComp.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using AM.AMSettings;
using AM.Patches;
using AM.Processing;
using AM.Tweaks;
using JetBrains.Annotations;
using RimWorld;
using UnityEngine;
using Verse;
using Patch = AM.Patches.Patch_Verb_MeleeAttackDamage_ApplyMeleeDamageToTarget;

namespace AM.Idle;

Expand Down Expand Up @@ -353,7 +353,7 @@ public void NotifyPawnDidMeleeAttack(Thing target, Verb_MeleeAttack verbUsed)

// Attempt to get an attack animation for current weapon and stance.
var rot = pawn.Rotation;
bool didHit = target != null && Patch.lastTarget == target;
bool didHit = target != null && Patch_Verb_MeleeAttack_ApplyMeleeDamageToTarget.lastTarget == target;

// Get list of attack animations.
var anims = tweak.GetAttackAnimations(rot);
Expand Down Expand Up @@ -383,7 +383,7 @@ public void NotifyPawnDidMeleeAttack(Thing target, Verb_MeleeAttack verbUsed)
pauseTicks = (int)Core.Settings.AttackPauseDuration;
}

Patch.lastTarget = null;
Patch_Verb_MeleeAttack_ApplyMeleeDamageToTarget.lastTarget = null;

// Play animation.
var args = new AnimationStartParameters(anim, pawn)
Expand Down
4 changes: 4 additions & 0 deletions Source/ThingGenerator/Outcome/IOutcomeWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public interface IOutcomeWorker
IEnumerable<PossibleMeleeAttack> GetMeleeAttacksFor(ThingWithComps weapon, Pawn pawn);

float GetChanceToPenAprox(Pawn pawn, BodyPartRecord bodyPart, StatDef armorType, float armorPen);

float GetPen(ThingWithComps weapon, Verb verb, Pawn attacker);

float GetDamage(ThingWithComps weapon, Verb verb, Pawn attacker);
}
Loading

0 comments on commit 69b7022

Please sign in to comment.