Skip to content

Commit

Permalink
AbilityUser should now report when line of sight failure takes place …
Browse files Browse the repository at this point in the history
…for abilities. Extra damages no longer gives errors in combat logs.(via RimWorld Mod Release Tool)
  • Loading branch information
jecrell committed Mar 15, 2020
1 parent cbe5d7a commit 6050754
Show file tree
Hide file tree
Showing 30 changed files with 156 additions and 27 deletions.
8 changes: 6 additions & 2 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</li>
</v1.1>
</modDependenciesByVersion>
<description>1.1.0.20 (03-07-2020)
<description>1.1.1.0 (03-15-2020)

Adds modding components to RimWorld: vehicles, spell casting, weapon slots, oversized weapons, and more!

Expand Down Expand Up @@ -72,11 +72,15 @@ Extensive hours of testing, debugging, and fixes by Xen.
Thank you to my Patrons for supporting me in my efforts. Without you, none of this would be possible.

These are the most excellent rim dwellers who support me:
Marcus Bell, RainerWingel, Dalton Johnson, Chris Seieroe, Robin Gleeson, Robert Alessi, Lea Stannard, Teres, David Silberstein, Sam, Kiya Nicoll, Matt Harris, Paul Fenwick, Grendalloffen, Don Homer, Josh McCabe, Elodie, Gothi, J, Michael Paugh, Audrin Navarro, Михаил Юрченко, Calum, Tim Stillson, Adam Bliss, Populous25, Marcus Sireanu, Maaxar, John Kanady, Midgeman, Dick Jones, Patrick, TinyFloatingTurtle, Nathan Getman, LionsFate, Sharp Spook, Cristina Shaver, Mark, George Chong Chuang Ming, Oliver White, roxxploxx, Emily Shaw, Karol Rybak, Justin Andres, Marcus Regan, Robin Hager, Allic, Austin Harbert, E_T, Alex Mederer, Alexander, Toss Antilles
Cade Perkinson, Jay Sacane, John Pahl, Tankok1998 also known as the Shermanlover, Vahl Kilmer, Zsolt Biró, Genaeve, JD2.0, Olteanu Laurentiu, Penelope Charli Whitman, Charlie Garnham, Steven Pretswell, Sultan Saltlick, RainerWingel, Daniel Paseka, Kyben, Charles Morris, Chris Seieroe, Robin Gleeson, Lea Stannard, Teres, David Silberstein, Kiya Nicoll, Matt Harris, Paul Fenwick, Michael Whitehead, Robert Alessi, Elodie, Gothi, Audrin Navarro, Михаил Юрченко, Calum, Tim Stillson, Populous25, Don Homer, Adam Bliss, Maaxar, Christopher, TinyFloatingTurtle, John Kanady, Midgeman, Nathan Getman, Sharp Spook, LionsFate, Cristina Shaver, Mark, George Chong Chuang Ming, Oliver White, roxxploxx, Emily Shaw, Justin Andres, Robin Hager, Kevin Reagan, Austin Harbert, Marcus Regan, E_T, Alex Mederer, Alexander, Toss Antilles

========================
Changelog
========================
1.1.1.0 (03-15-2020)
========================
AbilityUser should now report when line of sight failure takes place for abilities. Extra damages no longer gives errors in combat logs.

1.1.0.20 (03-07-2020)
========================
DefModExtension_ExtraSounds is now processed in the CompExtraSounds Harmony patch. Different pawns with DefModExtension_ExtraSounds in their PawnKindDef can make extra on-hit attack sounds.
Expand Down
4 changes: 4 additions & 0 deletions About/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.1.1.0 (03-15-2020)
========================
AbilityUser should now report when line of sight failure takes place for abilities. Extra damages no longer gives errors in combat logs.

1.1.0.20 (03-07-2020)
========================
DefModExtension_ExtraSounds is now processed in the CompExtraSounds Harmony patch. Different pawns with DefModExtension_ExtraSounds in their PawnKindDef can make extra on-hit attack sounds.
Expand Down
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>JecsTools</identifier>
<version>1.1.0.20</version>
<version>1.1.1.0</version>
<dependencies />
<incompatibleWith />
<loadBefore>
Expand Down
2 changes: 1 addition & 1 deletion About/Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0.20
1.1.1.0
Binary file modified Assemblies/0JecsTools.dll
Binary file not shown.
Binary file modified Assemblies/AbilityUser.dll
Binary file not shown.
Binary file modified Assemblies/AbilityUserAI.dll
Binary file not shown.
Binary file modified Assemblies/CompActivatableEffect.dll
Binary file not shown.
Binary file modified Assemblies/CompAnimated.dll
Binary file not shown.
Binary file modified Assemblies/CompBalloon.dll
Binary file not shown.
Binary file modified Assemblies/CompBigBox.dll
Binary file not shown.
Binary file modified Assemblies/CompDeflector.dll
Binary file not shown.
Binary file modified Assemblies/CompDelayedSpawner.dll
Binary file not shown.
Binary file modified Assemblies/CompExtraSounds.dll
Binary file not shown.
Binary file modified Assemblies/CompInstalledPart.dll
Binary file not shown.
Binary file modified Assemblies/CompLumbering.dll
Binary file not shown.
Binary file modified Assemblies/CompOverlays.dll
Binary file not shown.
Binary file modified Assemblies/CompOversizedWeapon.dll
Binary file not shown.
Binary file modified Assemblies/CompSlotLoadable.dll
Binary file not shown.
Binary file modified Assemblies/CompToggleDef.dll
Binary file not shown.
Binary file modified Assemblies/CompVehicle.dll
Binary file not shown.
Binary file modified Assemblies/PawnShields.dll
Binary file not shown.
Binary file modified Assemblies/ThinkNodes.dll
Binary file not shown.
4 changes: 3 additions & 1 deletion Languages/English/Keyed/AbilityUser.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>

<AU_NoTargets>No targets available.</AU_NoTargets>
<AU_NoLineOfSight>No line of sight</AU_NoLineOfSight>

<AU_NoTargets>No targets available</AU_NoTargets>

<AU_DISABLED>DISABLED</AU_DISABLED>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ protected override IEnumerable<Toil> MakeNewToils()

var verb = pawn.CurJob.verbToUse as Verb_UseAbility;
Find.Targeter.targetingSource = verb;
yield return Toils_Combat.CastVerb(TargetIndex.A, false);
yield return new Toil
{
initAction = delegate { verb.Ability.PostAbilityAttempt(); },
defaultCompleteMode = ToilCompleteMode.Instant
};
yield return Toils_Combat.CastVerb(TargetIndex.A, false);
yield return new Toil
{
initAction = delegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public int CooldownTicksLeft

public virtual void Notify_AbilityFailed(bool refund)
{
AbilityUser.AbilityUser.jobs.StopAll();
if (refund)
CooldownTicksLeft = -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,90 @@ protected virtual void UpdateTargets()
}
}

private bool CausesTimeSlowdown(LocalTargetInfo castTarg)
{
if (!verbProps.CausesTimeSlowdown)
{
return false;
}
if (!castTarg.HasThing)
{
return false;
}
Thing thing = castTarg.Thing;
if (thing.def.category != ThingCategory.Pawn && (thing.def.building == null || !thing.def.building.IsTurret))
{
return false;
}
bool flag = (thing as Pawn)?.Downed ?? false;
if (thing.Faction != Faction.OfPlayer || !caster.HostileTo(Faction.OfPlayer))
{
if (caster.Faction == Faction.OfPlayer && thing.HostileTo(Faction.OfPlayer))
{
return !flag;
}
return false;
}
return true;
}

public bool PreCastShotCheck(LocalTargetInfo castTarg, LocalTargetInfo destTarg, bool surpriseAttack, bool canHitNonTargetPawns)
{
if (caster == null)
{
Log.Error("Verb " + GetUniqueLoadID() + " needs caster to work (possibly lost during saving/loading).");
return false;
}
if (!caster.Spawned)
{
return false;
}
if (state == VerbState.Bursting || (!CanHitTarget(castTarg) && verbProps.requireLineOfSight))
{
return false;
}
if (CausesTimeSlowdown(castTarg))
{
Find.TickManager.slower.SignalForceNormalSpeed();
}

this.surpriseAttack = surpriseAttack;
this.canHitNonTargetPawnsNow = canHitNonTargetPawns;
this.currentTarget = castTarg;
this.currentDestination = destTarg;
if (CasterIsPawn && verbProps.warmupTime > 0f)
{
if (verbProps.requireLineOfSight)
{
ShootLine resultingLine;
if (!TryFindShootLineFromTo(caster.Position, castTarg, out resultingLine))
{
Messages.Message("AU_NoLineOfSight".Translate(), MessageTypeDefOf.RejectInput);
return false;
}
CasterPawn.Drawer.Notify_WarmingCastAlongLine(resultingLine, caster.Position);
}
float statValue = CasterPawn.GetStatValue(StatDefOf.AimingDelayFactor);
int ticks = (verbProps.warmupTime * statValue).SecondsToTicks();
CasterPawn.stances.SetStance(new Stance_Warmup(ticks, castTarg, this));
}
else
{
WarmupComplete();
}
return true;
}

public bool PreCastShot(LocalTargetInfo castTarg, LocalTargetInfo destTarg, bool surpriseAttack, bool canHitNonTargetPawns)
{
if (PreCastShotCheck(castTarg, destTarg, surpriseAttack, canHitNonTargetPawns))
{
return true;
}
Ability.Notify_AbilityFailed(true);
return false;
}

public virtual void PostCastShot(bool inResult, out bool outResult)
{
outResult = inResult;
Expand All @@ -100,7 +184,6 @@ public virtual void PostCastShot(bool inResult, out bool outResult)

protected override bool TryCastShot()
{
Log.Message("Try Cast Shot Called");
//Log.Message("Cast");
var result = false;
TargetsAoE.Clear();
Expand All @@ -120,7 +203,7 @@ protected override bool TryCastShot()
// {
if (verbProps.defaultProjectile != null) //ranged attacks WILL have projectiles
{
Log.Message("Yes Projectile");
//Log.Message("Yes Projectile");
var attempt = TryLaunchProjectile(verbProps.defaultProjectile, TargetsAoE[i]);
////Log.Message(TargetsAoE[i].ToString());
if (attempt != null)
Expand All @@ -131,22 +214,22 @@ protected override bool TryCastShot()
}
else //melee attacks WON'T have projectiles
{
Log.Message("No Projectile");
//Log.Message("No Projectile");
var victim = TargetsAoE[i].Thing;
if (victim != null)
{
Log.Message("Yes victim");
//Log.Message("Yes victim");
if (victim is Pawn pawnVictim)
{
Log.Message("Yes victim is pawn");
//Log.Message("Yes victim is pawn");
AbilityEffectUtility.ApplyMentalStates(pawnVictim, CasterPawn, UseAbilityProps.mentalStatesToApply, UseAbilityProps.abilityDef, null);
AbilityEffectUtility.ApplyHediffs(pawnVictim, CasterPawn, UseAbilityProps.hediffsToApply, null);
AbilityEffectUtility.SpawnSpawnables(UseAbilityProps.thingsToSpawn, pawnVictim, victim.MapHeld, victim.PositionHeld);
}
}
else
{
Log.Message("Victim is null");
//Log.Message("Victim is null");
AbilityEffectUtility.SpawnSpawnables(UseAbilityProps.thingsToSpawn, CasterPawn, CasterPawn.MapHeld, CasterPawn.PositionHeld);
}
}
Expand All @@ -168,18 +251,18 @@ private void DebugMessage(string s)
if (debugMode) Log.Message(s);
}

protected bool? TryLaunchProjectile(ThingDef projectileDef, LocalTargetInfo launchTarget)

public bool TryLaunchProjectileCheck(ThingDef projectileDef, LocalTargetInfo launchTarget)
{
DebugMessage(launchTarget.ToString());
var flag = TryFindShootLineFromTo(caster.Position, launchTarget, out var shootLine);
if (verbProps.stopBurstWithoutLos && !flag)
if (verbProps.requireLineOfSight && verbProps.stopBurstWithoutLos && !flag)
{
DebugMessage("Targeting cancelled");
Messages.Message("AU_NoLineOfSight".Translate(), MessageTypeDefOf.RejectInput);
return false;
}
var drawPos = caster.DrawPos;
var projectile = (Projectile_AbilityBase) GenSpawn.Spawn(projectileDef, shootLine.Source, caster.Map);
var projectile = (Projectile_AbilityBase)GenSpawn.Spawn(projectileDef, shootLine.Source, caster.Map);
projectile.extraDamages = UseAbilityProps.extraDamages;
projectile.localSpawnThings = UseAbilityProps.thingsToSpawn;
verbProps.soundCast?.PlayOneShot(new TargetInfo(caster.Position, caster.Map, false));
Expand All @@ -201,6 +284,16 @@ private void DebugMessage(string s)
UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn);
return true;
}

protected bool? TryLaunchProjectile(ThingDef projectileDef, LocalTargetInfo launchTarget)
{
if (TryLaunchProjectileCheck(projectileDef, launchTarget))
{
return true;
}
Ability.Notify_AbilityFailed(true);
return false;
}

public override void WarmupComplete()
{
Expand Down
18 changes: 18 additions & 0 deletions Source/AllModdingComponents/CompAbilityUser/_HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ public AbilityUserMod(ModContentPack content) : base(content)
AccessTools.Property(typeof(Verb), nameof(Verb.DirectOwner))
.GetGetMethod(),
new HarmonyMethod(typeof(AbilityUserMod), nameof(get_DirectOwner_Prefix)), null);

harmony.Patch(
AccessTools.Method(typeof(Verb), nameof(Verb.TryStartCastOn), new Type[] { typeof(LocalTargetInfo), typeof(LocalTargetInfo), typeof(bool), typeof(bool) })
,
new HarmonyMethod(typeof(AbilityUserMod), nameof(TryStartCastOn_Prefix), null));
}


public static bool TryStartCastOn_Prefix(Verb __instance, LocalTargetInfo castTarg, LocalTargetInfo destTarg, bool surpriseAttack, bool canHitNonTargetPawns, ref bool __result)
{
if (!(__instance is Verb_UseAbility vua))
return true;
else
{
var result = vua.PreCastShot(castTarg, destTarg, surpriseAttack, canHitNonTargetPawns);
__result = result;
return false;
}
}

public static bool get_DirectOwner_Prefix(Verb __instance, ref IVerbOwner __result)
Expand Down
13 changes: 10 additions & 3 deletions Source/AllModdingComponents/JecsTools/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public static bool PreApplyDamage_PrePatch(Pawn_HealthTracker __instance, ref Da
{
try
{
if (PreApplyDamage_ApplyExtraDamages(out absorbed, instigator, pawn)) return false;
if (PreApplyDamage_ApplyExtraDamages(dinfo, out absorbed, instigator, pawn)) return false;
}
catch (NullReferenceException e)
{
Expand Down Expand Up @@ -555,7 +555,7 @@ private static void PreApplyDamage_ApplyKnockback(Pawn instigator, Pawn pawn)
}
}

private static bool PreApplyDamage_ApplyExtraDamages(out bool absorbed, Pawn instigator, Pawn pawn)
private static bool PreApplyDamage_ApplyExtraDamages(DamageInfo dinfo, out bool absorbed, Pawn instigator, Pawn pawn)
{
var extraDamagesHediff =
instigator.health.hediffSet.hediffs.FirstOrDefault(y =>
Expand All @@ -573,7 +573,14 @@ private static bool PreApplyDamage_ApplyExtraDamages(out bool absorbed, Pawn ins
return true;
}

pawn.TakeDamage(new DamageInfo(dmg.def, dmg.amount, dmg.armorPenetration, -1, instigator));
BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = new BattleLogEntry_MeleeCombat(dinfo.Def.combatLogRules, true,
instigator, pawn, ImplementOwnerTypeDefOf.Bodypart, (dinfo.Weapon != null) ? dinfo.Weapon.label : dinfo.Def.label );
DamageWorker.DamageResult damageResult = new DamageWorker.DamageResult();
damageResult = pawn.TakeDamage(new DamageInfo(dmg.def, dmg.amount, dmg.armorPenetration, -1, instigator));
damageResult.AssociateWithLog(battleLogEntry_MeleeCombat);
battleLogEntry_MeleeCombat.def = LogEntryDefOf.MeleeAttack;
Find.BattleLog.Add(battleLogEntry_MeleeCombat);

}

StopPreApplyDamageCheck = false;
Expand Down
14 changes: 7 additions & 7 deletions updateinfo
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
==========Steam Format========
==============================

Doors Expanded
1.23.0.0 (03-07-2020)
========================
A 1.1 compatible version of Doors Expanded, rewritten and recreated by lbmaian to be even better than before.
JecsTools Update
v1.1.0.20 (03-07-2020)
====================

DefModExtension_ExtraSounds is now processed in the CompExtraSounds Harmony patch. Different pawns with DefModExtension_ExtraSounds in their PawnKindDef can make extra on-hit attack sounds.
--------------------

Download now on...
Expand All @@ -25,9 +25,9 @@ Discuss the mod on...
[img width=260]https://raw.githubusercontent.com/jecrell/JecsTools/master/About/Preview.png[/img]
[hr]
[b]JecsTools
Version: 1.1.0.19
Updated: 02-29-2020
Description: [color=orange]Hotfix for adding compatibility between the newest version of RimWorld and the previous version of 1.0.[/color]
Version: 1.1.0.20
Updated: 03-07-2020
Description: [color=orange]DefModExtension_ExtraSounds is now processed in the CompExtraSounds Harmony patch. Different pawns with DefModExtension_ExtraSounds in their PawnKindDef can make extra on-hit attack sounds.[/color]
[hr]
[b]Download now on...[/b]
[url=https://www.patreon.com/posts/34452021]Patreon[/url]
Expand Down

0 comments on commit 6050754

Please sign in to comment.