Skip to content

Commit

Permalink
v1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
XeoNovaDan committed Mar 4, 2020
1 parent 494b57e commit ecd6941
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 48 deletions.
Binary file modified 1.1/Assemblies/TurretExtensions.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<li>1.0</li>
<li>1.1</li>
</supportedVersions>
<description>Current Version: v1.3.2.0 (3rd March 2020)\n\nA resource which allows modders to create turret mods with more flair, as well as various bugfixes and quality-of-life improvements.</description>
<description>Current Version: v1.3.2.0 (4th March 2020)\n\nA resource which allows modders to create turret mods with more flair, as well as various bugfixes and quality-of-life improvements.</description>
<modDependencies>
<li>
<packageId>brrainz.harmony</packageId>
Expand Down
Binary file modified Source/TurretExtensions/.vs/TurretExtensions/v16/.suo
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ public CompProperties_Upgradable()
public override void ResolveReferences(ThingDef parentDef)
{
base.ResolveReferences(parentDef);
var extensionValues = TurretFrameworkExtension.Get(parentDef);

// If canForceAttack is unassigned, match it to DefModExtension
if (!canForceAttack.HasValue)
canForceAttack = extensionValues.canForceAttack;

// If firing arc is unchanged, match it to DefModExtension
if (firingArc == -1)
firingArc = TurretFrameworkExtension.Get(parentDef).FiringArc;
firingArc = extensionValues.FiringArc;
}

public override IEnumerable<string> ConfigErrors(ThingDef parentDef)
Expand Down Expand Up @@ -80,8 +85,8 @@ public override IEnumerable<string> ConfigErrors(ThingDef parentDef)
public float turretBurstCooldownTimeFactor = 1;
public ThingDef turretGunDef;
private float firingArc = -1;
public float manningPawnShootingAccuracyOffsetBonus = 0;
public bool canForceAttack = false;
public float manningPawnShootingAccuracyOffset = 0;
public bool? canForceAttack;
public bool? affectedByEMP;

public float FiringArc => Mathf.Clamp(firingArc, 0, 360);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,7 @@ public static class TryStartShootSomething

public static void Postfix(Building_TurretGun __instance, ref int ___burstWarmupTicksLeft)
{
var extensionValues = TurretFrameworkExtension.Get(__instance.def);

// Multiply the burstWarmupTicksLeft by the manning pawn's aiming delay factor if applicable
if (extensionValues.useManningPawnAimingDelayFactor)
{
var mannableComp = __instance.TryGetComp<CompMannable>();
if (mannableComp != null)
{
var manner = mannableComp.ManningPawn;
if (manner != null)
{
float mannerAimingDelayFactor = manner.GetStatValue(StatDefOf.AimingDelayFactor);
___burstWarmupTicksLeft = Mathf.RoundToInt(___burstWarmupTicksLeft * mannerAimingDelayFactor);
}
}
}

// Multiply based on upgrade
if (__instance.IsUpgraded(out CompUpgradable upgradableComp))
___burstWarmupTicksLeft = Mathf.RoundToInt(___burstWarmupTicksLeft * upgradableComp.Props.turretBurstWarmupTimeFactor);
___burstWarmupTicksLeft = TurretExtensionsUtility.AdjustedTurretBurstWarmupTicks(___burstWarmupTicksLeft, __instance);
}

}
Expand All @@ -217,7 +198,9 @@ public static void Postfix(Building_TurretGun __instance, ref bool __result)
var extensionValues = TurretFrameworkExtension.Get(__instance.def);
var upgradableComp = __instance.TryGetComp<CompUpgradable>();

if (((upgradableComp != null || !upgradableComp.upgraded) && extensionValues.canForceAttack) || (upgradableComp.upgraded && upgradableComp.Props.canForceAttack))
// Upgradable comp doesn't exist/isn't upgraded and can force attack, or exists and upgraded and can force attack
if (((upgradableComp == null || !upgradableComp.upgraded) && extensionValues.canForceAttack) ||
(upgradableComp != null && upgradableComp.upgraded && upgradableComp.Props.canForceAttack.Value))
{
if (!__instance.def.HasComp(typeof(CompMannable)))
__result = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static void Postfix(ThingDef __instance, StatRequest req, ref IEnumerable
upgradableString = (tDef.IsUpgradable(out upgradableCompProps) ? "TurretExtensions.YesClickForDetails" : "No").Translate();

var upgradeHyperlinks = new List<Dialog_InfoCard.Hyperlink>();
if (upgradableCompProps.turretGunDef != null)
if (upgradableCompProps?.turretGunDef != null)
upgradeHyperlinks.Add(new Dialog_InfoCard.Hyperlink(upgradableCompProps.turretGunDef));

gunStatList.Add(new StatDrawEntry(RimWorld.StatCategoryDefOf.BasicsNonPawn, "TurretExtensions.Upgradable".Translate(), upgradableString,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using RimWorld;
using Verse;
using HarmonyLib;
using UnityEngine;

namespace TurretExtensions
{

public static class Patch_VerbProperties
{

[HarmonyPatch(typeof(VerbProperties), nameof(VerbProperties.AdjustedFullCycleTime))]
public static class AdjustedFullCycleTime
{

public static bool Prefix(VerbProperties __instance, Verb ownerVerb, Pawn attacker, ref float __result)
{
// Vanilla gun turret
if (ownerVerb.Caster is Building_TurretGun gunTurret)
{
__result = TurretExtensionsUtility.AdjustedTurretBurstWarmupTicks(gunTurret.def.building.turretBurstWarmupTime.SecondsToTicks(), gunTurret).TicksToSeconds() +
NonPublicMethods.Building_TurretGun_BurstCooldownTime(gunTurret) + ((__instance.burstShotCount - 1) * __instance.ticksBetweenBurstShots).TicksToSeconds();
return false;
}

return true;
}

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,19 @@ public override void TransformValue(StatRequest req, ref float val)
if (ShouldApply(req, out Building_Turret turret))
{
var extensionValues = TurretFrameworkExtension.Get(turret.def);
val += extensionValues.manningPawnShootingAccuracyOffset;
if (turret.IsUpgraded(out CompUpgradable uC))
val += uC.Props.manningPawnShootingAccuracyOffsetBonus;
val += turret.IsUpgraded(out var upgradableComp) ? upgradableComp.Props.manningPawnShootingAccuracyOffset : extensionValues.manningPawnShootingAccuracyOffset;
}
}

public override string ExplanationPart(StatRequest req)
{
if (ShouldApply(req, out Building_Turret turret))
{
var extensionValues = turret.def.GetModExtension<TurretFrameworkExtension>();
var extensionValues = TurretFrameworkExtension.Get(req.Def);
float offset = turret.IsUpgraded(out var upgradableComp) ? upgradableComp.Props.manningPawnShootingAccuracyOffset : extensionValues.manningPawnShootingAccuracyOffset;

float totalOffset = 0f;
if (extensionValues != null)
totalOffset += extensionValues.manningPawnShootingAccuracyOffset;
if (turret.IsUpgraded(out CompUpgradable uC))
totalOffset += uC.Props.manningPawnShootingAccuracyOffsetBonus;

return $"{turret.def.LabelCap}: {totalOffset.ToStringByStyle(parentStat.ToStringStyleUnfinalized, ToStringNumberSense.Offset)}";
if (offset != 0)
return $"{turret.def.LabelCap}: {offset.ToStringByStyle(parentStat.ToStringStyleUnfinalized, ToStringNumberSense.Offset)}";
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,31 @@ public class StatPart_ValueFromUpgrade : StatPart
{
public override void TransformValue(StatRequest req, ref float val)
{
if (req.Thing?.GetInnerIfMinified() is Building_Turret turret && turret.IsUpgradable(out CompUpgradable uC))
int failPoint = 1;
try
{
if (!uC.finalCostList.NullOrEmpty())
if (req.HasThing && req.Thing.GetInnerIfMinified() is Building_Turret turret && turret.IsUpgradable(out CompUpgradable uC))
{
for (int i = 0; i < uC.innerContainer.Count; i++)
failPoint = 2;
if (!uC.finalCostList.NullOrEmpty())
{
var thing = uC.innerContainer[i];
val += thing.MarketValue * thing.stackCount;
failPoint = 3;
for (int i = 0; i < uC.innerContainer.Count; i++)
{
failPoint = 4;
var thing = uC.innerContainer[i];
failPoint = 5;
val += thing.MarketValue * thing.stackCount;
}
}
failPoint = 6;
val += Math.Min(uC.upgradeWorkDone, uC.upgradeWorkTotal) * StatWorker_MarketValue.ValuePerWork;
}
val += Math.Min(uC.upgradeWorkDone, uC.upgradeWorkTotal) * StatWorker_MarketValue.ValuePerWork;

}
catch (Exception ex)
{
Log.Message($"Exception in getting value from upgrade (failPoint={failPoint}): {ex.ToString()}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\workshop\content\294100\2009463077\Assemblies\0Harmony.dll</HintPath>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\workshop\content\294100\2009463077\v1.1\Assemblies\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
Expand All @@ -64,6 +64,7 @@
<Compile Include="HarmonyPatches\HarmonyPatchesUtility.cs" />
<Compile Include="HarmonyPatches\Patch_Building_Turret.cs" />
<Compile Include="HarmonyPatches\Patch_JobDriver_ManTurret.cs" />
<Compile Include="HarmonyPatches\Patch_VerbProperties.cs" />
<Compile Include="HarmonyPatches\Patch_Verb_Shoot.cs" />
<Compile Include="HarmonyPatches\Patch_Verb.cs" />
<Compile Include="HarmonyPatches\Patch_Pawn_RotationTracker.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,33 @@ public static float AdjustedFuelCapacity(float baseFuelCapacity, Thing t)
return baseFuelCapacity;
}

public static int AdjustedTurretBurstWarmupTicks(int warmupTicks, Building_Turret turret)
{
var extensionValues = TurretFrameworkExtension.Get(turret.def);
float warmupTicksFloat = warmupTicks;

// Multiply the burstWarmupTicksLeft by the manning pawn's aiming delay factor if applicable
if (extensionValues.useManningPawnAimingDelayFactor)
{
var mannableComp = turret.TryGetComp<CompMannable>();
if (mannableComp != null)
{
var manningPawn = mannableComp.ManningPawn;
if (manningPawn != null)
{
float manningPawnAimingDelayFactor = manningPawn.GetStatValue(StatDefOf.AimingDelayFactor);
warmupTicksFloat *= manningPawnAimingDelayFactor;
}
}
}

// Multiply based on upgrade
if (turret.IsUpgraded(out CompUpgradable upgradableComp))
warmupTicksFloat *= upgradableComp.Props.turretBurstWarmupTimeFactor;

return Mathf.RoundToInt(warmupTicksFloat);
}

public static string ToStringDegrees(this float degrees) => degrees.ToString("0.#") + "°";

public static bool WithinFiringArcOf(this IntVec3 pos, Thing thing)
Expand Down Expand Up @@ -109,6 +136,7 @@ public static string UpgradeReadoutReportText(StatRequest req)
// First paragraph
var reportBuilder = new StringBuilder();
reportBuilder.AppendLine("TurretExtensions.TurretUpgradeBenefitsMain".Translate());
reportBuilder.AppendLine();

// Upgradable
if (upgradeProps != null)
Expand All @@ -119,7 +147,6 @@ public static string UpgradeReadoutReportText(StatRequest req)
bool hasThing = req.HasThing;

// Description
reportBuilder.AppendLine();
reportBuilder.AppendLine($"{"Description".Translate()}: {upgradeProps.description}");

// Resource requirements
Expand Down Expand Up @@ -211,15 +238,15 @@ public static string UpgradeReadoutReportText(StatRequest req)
reportBuilder.AppendLine($"- {"TurretExtensions.FiringArc".Translate()}: {extensionValues.FiringArc.ToStringDegrees()} => {upgradeProps.FiringArc.ToStringDegrees()}");

// User accuracy modifier
if (upgradeProps.manningPawnShootingAccuracyOffsetBonus != 0 && tDef.HasComp(typeof(CompMannable)))
if ((extensionValues.manningPawnShootingAccuracyOffset != 0 || upgradeProps.manningPawnShootingAccuracyOffset != 0) && tDef.HasComp(typeof(CompMannable)))
reportBuilder.AppendLine($"- {"TurretExtensions.UserShootingAccuracyModifier".Translate()}: " +
$"{extensionValues.manningPawnShootingAccuracyOffset.ToStringByStyle(ToStringStyle.FloatOne, ToStringNumberSense.Offset)} => " +
$"{(extensionValues.manningPawnShootingAccuracyOffset + upgradeProps.manningPawnShootingAccuracyOffsetBonus).ToStringByStyle(ToStringStyle.FloatOne, ToStringNumberSense.Offset)}");
$"{(upgradeProps.manningPawnShootingAccuracyOffset).ToStringByStyle(ToStringStyle.FloatOne, ToStringNumberSense.Offset)}");

// Manually controllable
if (extensionValues.canForceAttack != upgradeProps.canForceAttack && !tDef.HasComp(typeof(CompMannable)))
{
if (upgradeProps.canForceAttack)
if (upgradeProps.canForceAttack.Value)
reportBuilder.AppendLine($"- {"TurretExtensions.TurretManuallyControllable".Translate()}");
else
reportBuilder.AppendLine($"- {"TurretExtensions.TurretNotManuallyControllable".Translate()}");
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit ecd6941

Please sign in to comment.