Skip to content

Commit

Permalink
Move to nested namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Safairette committed Sep 17, 2024
1 parent 9197969 commit b8ab6f2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,62 @@
using Verse;
using RimWorld;

namespace CombatExtended.Compatibility.PsyBlastersCompat;

public class PsychicBlasterBulletCE : BulletCE //Basically just duplicating the original behavior to the CE class
namespace CombatExtended.Compatibility.PsyBlastersCompat
{
private PsyBlasterBulletComp _psyBlasterBulletComp => GetComp<PsyBlasterBulletComp>();

private bool CanConsumeResources(Pawn launcherPawn)
{
return _psyBlasterBulletComp != null &&
launcherPawn is { HasPsylink: true, psychicEntropy.CurrentPsyfocus: > 0 };
}

public override float DamageAmount
public class PsychicBlasterBulletCE : BulletCE //Basically just duplicating the original behavior to the CE class
{
get
private PsyBlasterBulletComp _psyBlasterBulletComp => GetComp<PsyBlasterBulletComp>();

private bool CanConsumeResources(Pawn launcherPawn)
{
var damMulti = equipment?.GetStatValue(StatDefOf.RangedWeapon_DamageMultiplier) ?? 1f;
if (CanConsumeResources(launcher as Pawn))
return _psyBlasterBulletComp != null &&
launcherPawn is { HasPsylink: true, psychicEntropy.CurrentPsyfocus: > 0 };
}

public override float DamageAmount
{
get
{
damMulti += _psyBlasterBulletComp.PsyDamageMulti;
var damMulti = equipment?.GetStatValue(StatDefOf.RangedWeapon_DamageMultiplier) ?? 1f;
if (CanConsumeResources(launcher as Pawn))
{
damMulti += _psyBlasterBulletComp.PsyDamageMulti;
}

return def.projectile.GetDamageAmount(damMulti);
}

return def.projectile.GetDamageAmount(damMulti);
}
}

public override float PenetrationAmount
{
get

public override float PenetrationAmount
{
var projectilePropsCE = (ProjectilePropertiesCE)def.projectile;
var isSharp = def.projectile.damageDef.armorCategory == DamageArmorCategoryDefOf.Sharp;
var penMulti = equipment?.GetStatValue(StatDefOf.RangedWeapon_DamageMultiplier) ?? 1f;
if (CanConsumeResources(launcher as Pawn))
get
{
penMulti += _psyBlasterBulletComp.PsyPenMulti;
var projectilePropsCE = (ProjectilePropertiesCE)def.projectile;
var isSharp = def.projectile.damageDef.armorCategory == DamageArmorCategoryDefOf.Sharp;
var penMulti = equipment?.GetStatValue(StatDefOf.RangedWeapon_DamageMultiplier) ?? 1f;
if (CanConsumeResources(launcher as Pawn))
{
penMulti += _psyBlasterBulletComp.PsyPenMulti;
}

return penMulti *
(isSharp ? projectilePropsCE.armorPenetrationSharp : projectilePropsCE.armorPenetrationBlunt);
}

return penMulti *
(isSharp ? projectilePropsCE.armorPenetrationSharp : projectilePropsCE.armorPenetrationBlunt);
}
}

public override void Impact(Thing hitThing)
{
base.Impact(hitThing);

if (hitThing is not Pawn && Rand.Chance(0.66f) //don't look at me, it was like that in the original code
|| launcher is not Pawn launcherPawn
|| !CanConsumeResources(launcherPawn)
|| launcherPawn.psychicEntropy.limitEntropyAmount && launcherPawn.psychicEntropy.WouldOverflowEntropy(_psyBlasterBulletComp.EntropyCost)) return;

launcherPawn.psychicEntropy.OffsetPsyfocusDirectly(-_psyBlasterBulletComp.PsyCost);
launcherPawn.psychicEntropy.TryAddEntropy(_psyBlasterBulletComp.EntropyCost);

public override void Impact(Thing hitThing)
{
base.Impact(hitThing);
if (hitThing is not Pawn && Rand.Chance(0.66f) //don't look at me, it was like that in the original code

Check failure on line 52 in Source/PsyblastersCompat/PsyBlastersCompat/PsychicBlasterBulletCE.cs

View workflow job for this annotation

GitHub Actions / build

Add braces to 'if' statement.
|| launcher is not Pawn launcherPawn
|| !CanConsumeResources(launcherPawn)
|| launcherPawn.psychicEntropy.limitEntropyAmount && launcherPawn.psychicEntropy.WouldOverflowEntropy(_psyBlasterBulletComp.EntropyCost)) return;

launcherPawn.psychicEntropy.OffsetPsyfocusDirectly(-_psyBlasterBulletComp.PsyCost);
launcherPawn.psychicEntropy.TryAddEntropy(_psyBlasterBulletComp.EntropyCost);
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,43 @@
using RimWorld;
using Verse;

namespace CombatExtended.Compatibility.PsyBlastersCompat;

public class PsychicBlasterRocketCE : ProjectileCE_Explosive
namespace CombatExtended.Compatibility.PsyBlastersCompat
{
PsyBlasterBulletComp _psyBlasterBulletComp => GetComp<PsyBlasterBulletComp>();

private bool CanConsumeResources(Pawn launcherPawn)
public class PsychicBlasterRocketCE : ProjectileCE_Explosive
{
return _psyBlasterBulletComp != null && launcherPawn is { HasPsylink: true };
}

public override float DamageAmount
{
get
PsyBlasterBulletComp _psyBlasterBulletComp => GetComp<PsyBlasterBulletComp>();

private bool CanConsumeResources(Pawn launcherPawn)
{
return _psyBlasterBulletComp != null && launcherPawn is { HasPsylink: true };
}

public override float DamageAmount
{
if (CanConsumeResources(launcher as Pawn))
get
{
return def.projectile.GetDamageAmount(
equipment?.GetStatValue(StatDefOf.RangedWeapon_DamageMultiplier) ?? 1f) +
((((Pawn)launcher).psychicEntropy.MaxPotentialEntropy -
((Pawn)launcher).psychicEntropy.EntropyValue) * _psyBlasterBulletComp.PsyDamageMulti);
if (CanConsumeResources(launcher as Pawn))
{
return def.projectile.GetDamageAmount(
equipment?.GetStatValue(StatDefOf.RangedWeapon_DamageMultiplier) ?? 1f) +
((((Pawn)launcher).psychicEntropy.MaxPotentialEntropy -
((Pawn)launcher).psychicEntropy.EntropyValue) * _psyBlasterBulletComp.PsyDamageMulti);
}
return 0;
}
return 0;
}

public override void Impact(Thing hitThing) //that's also copied from the original
{
base.Impact(hitThing);

if (!CanConsumeResources(launcher as Pawn)) return;

Check failure on line 36 in Source/PsyblastersCompat/PsyBlastersCompat/PsychicBlasterRocketCE.cs

View workflow job for this annotation

GitHub Actions / build

Add braces to 'if' statement.

var launcherPawn = (Pawn)launcher;
Traverse.Create(launcherPawn).Field("psychicEntropy").Field("currentEntropy")
.SetValue(launcherPawn.psychicEntropy.MaxPotentialEntropy * 5.5f);
}
}

public override void Impact(Thing hitThing) //that's also copied from the original
{
base.Impact(hitThing);

if (!CanConsumeResources(launcher as Pawn)) return;

var launcherPawn = (Pawn)launcher;
Traverse.Create(launcherPawn).Field("psychicEntropy").Field("currentEntropy")
.SetValue(launcherPawn.psychicEntropy.MaxPotentialEntropy * 5.5f);
}
}

0 comments on commit b8ab6f2

Please sign in to comment.