Skip to content

Commit 938554a

Browse files
committedMar 8, 2025
rally
1 parent 419435f commit 938554a

11 files changed

+314
-1
lines changed
 

‎1.5/Assemblies/VFEMedieval.dll

6.5 KB
Binary file not shown.
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Defs>
3+
4+
<HediffDef Name="VFEM_RallyHediffBase" Abstract="True">
5+
<hediffClass>HediffWithComps</hediffClass>
6+
<defaultLabelColor>(128, 0, 128)</defaultLabelColor>
7+
<isBad>false</isBad>
8+
<comps>
9+
<li Class="HediffCompProperties_DisappearsOnDeath" />
10+
</comps>
11+
</HediffDef>
12+
13+
<ThingDef ParentName="MoteBase">
14+
<defName>VFEM_Mote_CombatCommand</defName>
15+
<thingClass>MoteAttached</thingClass>
16+
<altitudeLayer>LightingOverlay</altitudeLayer>
17+
<drawOffscreen>true</drawOffscreen>
18+
<mote>
19+
<solidTime>9999999</solidTime>
20+
<needsMaintenance>true</needsMaintenance>
21+
</mote>
22+
<graphicData>
23+
<graphicClass>Graphic_Mote</graphicClass>
24+
<texPath>Things/Mote/VFEM2_CombatCommandMask</texPath>
25+
<shaderType>MoteGlow</shaderType>
26+
<color>(128, 0, 128)</color> <!-- Purple color -->
27+
<drawSize>20</drawSize>
28+
</graphicData>
29+
</ThingDef>
30+
31+
<ThingDef ParentName="MoteBase">
32+
<defName>VFEM_Mote_CombatCommandLinkLine</defName>
33+
<thingClass>MoteDualAttached</thingClass>
34+
<altitudeLayer>MoteLow</altitudeLayer>
35+
<mote>
36+
<fadeInTime>0.1</fadeInTime>
37+
<fadeOutTime>0.1</fadeOutTime>
38+
<solidTime>999999</solidTime>
39+
<needsMaintenance>True</needsMaintenance>
40+
<rotateTowardsTarget>True</rotateTowardsTarget>
41+
<scaleToConnectTargets>True</scaleToConnectTargets>
42+
</mote>
43+
<graphicData>
44+
<shaderType>MoteGlow</shaderType>
45+
<texPath>Things/Mote/VFEM2_CombatCommandLinkLine</texPath>
46+
<color>(128, 0, 128)</color> <!-- Purple color -->
47+
</graphicData>
48+
</ThingDef>
49+
50+
<HediffDef ParentName="VFEM_RallyHediffBase">
51+
<defName>VFEM_RallyWearerHediff</defName>
52+
<label>rally</label>
53+
<description>Aura that rallies everyone nearby, stopping their mental breaks and preventing them from breaking again.</description>
54+
<comps>
55+
<li Class="HediffCompProperties_Disappears">
56+
<showRemainingTime>True</showRemainingTime>
57+
</li>
58+
<li Class="HediffCompProperties_GiveHediffsInRange">
59+
<range>9.9</range>
60+
<hideMoteWhenNotDrafted>false</hideMoteWhenNotDrafted>
61+
<targetingParameters>
62+
<canTargetBuildings>false</canTargetBuildings>
63+
<canTargetAnimals>false</canTargetAnimals>
64+
<canTargetMechs>false</canTargetMechs>
65+
<onlyTargetColonists>true</onlyTargetColonists>
66+
</targetingParameters>
67+
<hediff>VFEM_RallyAuraBuffHediff</hediff>
68+
<mote>VFEM_Mote_CombatCommand</mote>
69+
</li>
70+
</comps>
71+
</HediffDef>
72+
73+
<HediffDef ParentName="VFEM_RallyHediffBase">
74+
<defName>VFEM_RallyAuraBuffHediff</defName>
75+
<label>rally aura</label>
76+
<description>Rallying aura that prevents mental breaks.</description>
77+
<comps>
78+
<li Class="HediffCompProperties_Link">
79+
<requireLinkOnOtherPawn>false</requireLinkOnOtherPawn>
80+
<maxDistance>9.9</maxDistance>
81+
<customMote>VFEM_Mote_CombatCommandLinkLine</customMote>
82+
</li>
83+
<li Class="HediffCompProperties_Disappears">
84+
<showRemainingTime>false</showRemainingTime>
85+
</li>
86+
<li Class="VFEMedieval.HediffCompProperties_MentalStatePrevention">
87+
<preventMentalStates>
88+
<li>Binging_Food</li>
89+
<li>Wander_Sad</li>
90+
<li>Wander_OwnRoom</li>
91+
<li>InsultingSpree</li>
92+
<li>TargetedInsultingSpree</li>
93+
<li>Binging_DrugMajor</li>
94+
<li>Wander_Psychotic</li>
95+
<li>Tantrum</li>
96+
<li>TargetedTantrum</li>
97+
<li>BedroomTantrum</li>
98+
<li>SadisticRage</li>
99+
<li>CorpseObsession</li>
100+
<li MayRequire="Ludeon.RimWorld.Anomaly">EntityKiller</li>
101+
<li>Berserk</li>
102+
<li>FireStartingSpree</li>
103+
<li>Binging_DrugExtreme</li>
104+
<li>Jailbreaker</li>
105+
<li>Slaughterer</li>
106+
<li>MurderousRage</li>
107+
<li>GiveUpExit</li>
108+
</preventMentalStates>
109+
</li>
110+
</comps>
111+
</HediffDef>
112+
113+
</Defs>

‎1.5/Defs/ThingDefs_Misc/Weapons/MeleeMedieval.xml

+8
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@
367367
</recipeMaker>
368368
<comps>
369369
<li Class="VFEMedieval.CompProperties_EditHeraldic" />
370+
<li Class="VFEMedieval.CompProperties_RallyAbility">
371+
<gizmoLabel>Rally</gizmoLabel>
372+
<gizmoDescription>Create an aura that rallies everyone nearby, stopping their mental breaks and preventing them from breaking again. The effect lasts 12 hours and remains attached to the standard-bearer for the duration.</gizmoDescription>
373+
<icon>UI/HeraldicRally</icon>
374+
<hediffWearer>VFEM_RallyWearerHediff</hediffWearer>
375+
<disabledReason>Can’t use Rally: No enemies on the map.</disabledReason>
376+
<disabledReasonAlreadyUsing>Already using Rally.</disabledReasonAlreadyUsing>
377+
</li>
370378
</comps>
371379
<modExtensions>
372380
<li Class="VFECore.DynamicGraphicProps">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using RimWorld;
4+
using UnityEngine;
5+
using Verse;
6+
7+
namespace VFEMedieval
8+
{
9+
public class CompRallyAbility : ThingComp
10+
{
11+
public CompProperties_RallyAbility Props => props as CompProperties_RallyAbility;
12+
13+
public Gizmo GetRallyGizmo()
14+
{
15+
var enemiesPresent = EnemiesPresent();
16+
var alreadyHasHediff = AlreadyHasHediff();
17+
return new Command_Action()
18+
{
19+
defaultLabel = Props.gizmoLabel,
20+
defaultDesc = Props.gizmoDescription,
21+
icon = ContentFinder<Texture2D>.Get(Props.icon),
22+
action = ActivateAbility,
23+
disabled = enemiesPresent is false || alreadyHasHediff,
24+
disabledReason = enemiesPresent is false ? Props.disabledReason : Props.disabledReasonAlreadyUsing
25+
};
26+
}
27+
28+
private bool AlreadyHasHediff()
29+
{
30+
Pawn wearer = Wearer;
31+
return wearer != null && wearer.health.hediffSet.HasHediff(Props.hediffWearer);
32+
}
33+
34+
private bool EnemiesPresent()
35+
{
36+
Pawn wearer = Wearer;
37+
if (wearer != null)
38+
{
39+
return wearer.Map.attackTargetsCache.GetPotentialTargetsFor(wearer).Any(t => t.Thing is Pawn targetPawn && targetPawn.HostileTo(wearer.Faction));
40+
}
41+
return false;
42+
}
43+
44+
private void ActivateAbility()
45+
{
46+
if (!EnemiesPresent()) return;
47+
48+
ApplyRallyHediffToWearer();
49+
}
50+
51+
private void ApplyRallyHediffToWearer()
52+
{
53+
Pawn wearer = Wearer;
54+
if (wearer != null)
55+
{
56+
Hediff hediff = HediffMaker.MakeHediff(Props.hediffWearer, wearer);
57+
HediffComp_Disappears disappearsComp = hediff.TryGetComp<HediffComp_Disappears>();
58+
if (disappearsComp != null)
59+
{
60+
disappearsComp.ticksToDisappear = 30000;
61+
}
62+
wearer.health.AddHediff(hediff);
63+
}
64+
}
65+
66+
67+
public Pawn Wearer => parent.ParentHolder is Pawn_EquipmentTracker equipmentTracker ? equipmentTracker.pawn : null;
68+
}
69+
public class CompProperties_RallyAbility : CompProperties
70+
{
71+
public string gizmoLabel;
72+
public string gizmoDescription;
73+
public string icon;
74+
public HediffDef hediffWearer;
75+
public string disabledReason;
76+
public string disabledReasonAlreadyUsing;
77+
public CompProperties_RallyAbility()
78+
{
79+
compClass = typeof(CompRallyAbility);
80+
}
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using HarmonyLib;
2+
using RimWorld;
3+
using Verse;
4+
using System.Collections.Generic;
5+
6+
namespace VFEMedieval
7+
{
8+
[HarmonyPatch(typeof(CompEquippable), "CompGetEquippedGizmosExtra")]
9+
public static class CompEquippable_CompGetEquippedGizmosExtra_Patch
10+
{
11+
public static IEnumerable<Gizmo> Postfix(IEnumerable<Gizmo> __result, CompEquippable __instance)
12+
{
13+
foreach (var gizmo in __result)
14+
{
15+
yield return gizmo;
16+
}
17+
if (__instance.parent.TryGetComp<CompRallyAbility>() is CompRallyAbility rallyComp)
18+
{
19+
yield return rallyComp.GetRallyGizmo();
20+
}
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using HarmonyLib;
2+
using RimWorld;
3+
using Verse;
4+
using Verse.AI;
5+
6+
namespace VFEMedieval
7+
{
8+
[HarmonyPatch(typeof(MentalBreakWorker), "TryStart")]
9+
public static class MentalBreakWorker_TryStart_Patch
10+
{
11+
public static bool Prefix(Pawn pawn, MentalBreakWorker __instance)
12+
{
13+
foreach (Hediff hediff in pawn.health.hediffSet.hediffs)
14+
{
15+
if (hediff.TryGetComp<HediffComp_MentalStatePrevention>() is HediffComp_MentalStatePrevention comp)
16+
{
17+
if (comp.Props.preventMentalStates.Contains(__instance.def.mentalState))
18+
{
19+
return false;
20+
}
21+
}
22+
}
23+
return true;
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using HarmonyLib;
2+
using RimWorld;
3+
using Verse;
4+
using Verse.AI;
5+
6+
namespace VFEMedieval
7+
{
8+
[HarmonyPatch(typeof(MentalStateHandler), "TryStartMentalState")]
9+
public static class MentalStateHandler_TryStartMentalState_Patch
10+
{
11+
public static bool Prefix(Pawn ___pawn, MentalStateDef stateDef)
12+
{
13+
foreach (Hediff hediff in ___pawn.health.hediffSet.hediffs)
14+
{
15+
if (hediff.TryGetComp<HediffComp_MentalStatePrevention>() is HediffComp_MentalStatePrevention comp)
16+
{
17+
if (comp.Props.preventMentalStates.Contains(stateDef))
18+
{
19+
return false;
20+
}
21+
}
22+
}
23+
return true;
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections.Generic;
2+
using RimWorld;
3+
using Verse;
4+
5+
namespace VFEMedieval
6+
{
7+
public class HediffComp_MentalStatePrevention : HediffComp
8+
{
9+
public HediffCompProperties_MentalStatePrevention Props => (HediffCompProperties_MentalStatePrevention)props;
10+
11+
public override void CompPostPostAdd(DamageInfo? dinfo)
12+
{
13+
base.CompPostPostAdd(dinfo);
14+
if (Pawn.MentalState != null)
15+
{
16+
Pawn.MentalState.RecoverFromState();
17+
}
18+
}
19+
}
20+
21+
public class HediffCompProperties_MentalStatePrevention : HediffCompProperties
22+
{
23+
public List<MentalStateDef> preventMentalStates = new List<MentalStateDef>();
24+
25+
public HediffCompProperties_MentalStatePrevention()
26+
{
27+
compClass = typeof(HediffComp_MentalStatePrevention);
28+
}
29+
}
30+
}

‎1.5/Source/VFEMedieval/ScenPart_MedievalScenario.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ public override void GenerateIntoMap(Map map)
119119
GenSpawn.Spawn(item, spawnPos, map);
120120
}
121121
}
122-
FloodFillerFog.DebugRefogMap(map);
122+
FloodFillerFog.DebugRefogMap(map);
123+
124+
foreach (var item in map.listerThings.AllThings.Where(x => x.def.category == ThingCategory.Item).ToList())
125+
{
126+
item.SetForbidden(true, false);
127+
}
123128
}
124129
}
125130
}
Loading
3.45 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.