-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP CE compat, added outcome pct readout.
- Loading branch information
Showing
6 changed files
with
163 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using RimWorld; | ||
using System.Collections.Generic; | ||
using Verse; | ||
|
||
namespace AM.Outcome; | ||
|
||
public interface IOutcomeWorker | ||
{ | ||
IEnumerable<PossibleMeleeAttack> GetMeleeAttacksFor(ThingWithComps weapon, Pawn pawn); | ||
|
||
float GetChanceToPenAprox(Pawn pawn, BodyPartRecord bodyPart, StatDef armorType, float armorPen); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Verse; | ||
|
||
namespace AM.Outcome; | ||
|
||
public readonly struct PossibleMeleeAttack | ||
{ | ||
public Pawn Pawn { get; init; } | ||
public float Damage { get; init; } | ||
public float ArmorPen { get; init; } | ||
public DamageDef DamageDef { get; init; } | ||
public Verb Verb { get; init; } | ||
public ThingWithComps Weapon { get; init; } | ||
|
||
public override string ToString() => Verb.ToString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using RimWorld; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using Verse; | ||
|
||
namespace AM.Outcome; | ||
|
||
public sealed class VanillaOutcomeWorker : 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 = verb.verbProps.AdjustedMeleeDamageAmount(verb.tool, pawn, weapon, verb.HediffCompSource); | ||
float ap = verb.verbProps.AdjustedArmorPenetration(verb.tool, pawn, weapon, verb.HediffCompSource); | ||
yield return new PossibleMeleeAttack | ||
{ | ||
Damage = dmg, | ||
ArmorPen = ap, | ||
Pawn = pawn, | ||
DamageDef = verb.GetDamageDef(), | ||
Verb = verb, | ||
Weapon = weapon | ||
}; | ||
} | ||
} | ||
|
||
public float GetChanceToPenAprox(Pawn pawn, BodyPartRecord bodyPart, StatDef armorType, float armorPen) | ||
{ | ||
// Get skin & hediff chance-to-pen. | ||
float pawnArmor = pawn.GetStatValue(armorType) - armorPen; | ||
float chance = Mathf.Clamp01(1f - pawnArmor); | ||
|
||
if (pawn?.apparel == null) | ||
return chance; | ||
|
||
// Get apparel chance-to-pen. | ||
foreach (var a in pawn.apparel.WornApparel) | ||
{ | ||
if (!a.def.apparel.CoversBodyPart(bodyPart)) | ||
continue; | ||
|
||
var armor = a.GetStatValue(armorType); | ||
if (armor <= 0) | ||
continue; | ||
|
||
chance *= Mathf.Clamp01(1f - (armor - armorPen)); | ||
} | ||
|
||
return chance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters