22using System . Reflection ;
33using UnityEngine ;
44
5- namespace CleverGirl . Patches {
5+ namespace CleverGirl . Patches
6+ {
67
7- [ HarmonyPatch ]
8- static class GenerateJumpMoveCandidatesNode_Tick {
8+ [ HarmonyPatch ( typeof ( GenerateJumpMoveCandidatesNode ) , nameof ( GenerateJumpMoveCandidatesNode . Tick ) ) ]
9+ static class GenerateJumpMoveCandidatesNode_Tick
10+ {
911
10- static MethodBase TargetMethod ( ) {
11- var type = AccessTools . TypeByName ( "GenerateJumpMoveCandidatesNode" ) ;
12- return AccessTools . Method ( type , "Tick" ) ;
13- }
1412
1513 // Duplication of HBS code, avoiding prefix=true for now.
1614 [ HarmonyPostfix ]
17- static void Postfix ( ref BehaviorTreeResults __result , string ___name , BehaviorTree ___tree , AbstractActor ___unit ) {
15+ static void Postfix ( GenerateJumpMoveCandidatesNode __instance , ref BehaviorTreeResults __result )
16+ {
1817 Mod . Log . Trace ? . Write ( "CJMCN:T - entered" ) ;
1918
20- Mech mech = ___unit as Mech ;
21- if ( mech != null && mech . WorkingJumpjets > 0 ) {
22- string stayInsideRegionGUID = RegionUtil . GetStayInsideRegionGUID ( ___unit ) ;
23-
19+ BehaviorTree nodeBehaviorTree = __instance . tree ;
20+ AbstractActor nodeContextUnit = __instance . unit ;
21+
22+ Mech mech = nodeContextUnit as Mech ;
23+ if ( mech != null && mech . WorkingJumpjets > 0 )
24+ {
25+ string stayInsideRegionGUID = RegionUtil . GetStayInsideRegionGUID ( nodeContextUnit ) ;
26+
2427 float acceptableHeat = AIUtil . GetAcceptableHeatLevelForMech ( mech ) ;
2528 float currentHeat = ( float ) mech . CurrentHeat ;
2629 Mod . Log . Info ? . Write ( $ "CJMCN:T - === actor:{ mech . DistinctId ( ) } has currentHeat:{ currentHeat } and acceptableHeat:{ acceptableHeat } ") ;
2730
28- List < PathNode > sampledPathNodes = ___unit . JumpPathing . GetSampledPathNodes ( ) ;
31+ List < PathNode > sampledPathNodes = nodeContextUnit . JumpPathing . GetSampledPathNodes ( ) ;
2932 Mod . Log . Info ? . Write ( $ "CJMCN:T - calculating { sampledPathNodes . Count } nodes") ;
30- for ( int i = 0 ; i < sampledPathNodes . Count ; i ++ ) {
33+ for ( int i = 0 ; i < sampledPathNodes . Count ; i ++ )
34+ {
3135 Vector3 candidatePos = sampledPathNodes [ i ] . Position ;
32- float distanceBetween2D = AIUtil . Get2DDistanceBetweenVector3s ( candidatePos , ___unit . CurrentPosition ) ;
33- float distanceBetween3D = Vector3 . Distance ( candidatePos , ___unit . CurrentPosition ) ;
36+ float distanceBetween2D = AIUtil . Get2DDistanceBetweenVector3s ( candidatePos , nodeContextUnit . CurrentPosition ) ;
37+ float distanceBetween3D = Vector3 . Distance ( candidatePos , nodeContextUnit . CurrentPosition ) ;
3438 Mod . Log . Info ? . Write ( $ "CJMCN:T - calculated distances 2D:'{ distanceBetween2D } ' 3D:'{ distanceBetween3D } ") ;
35- if ( distanceBetween2D >= 1f ) {
36- float magnitude = ( candidatePos - ___unit . CurrentPosition ) . magnitude ;
39+ if ( distanceBetween2D >= 1f )
40+ {
41+ float magnitude = ( candidatePos - nodeContextUnit . CurrentPosition ) . magnitude ;
3742 float jumpHeat = ( float ) mech . CalcJumpHeat ( magnitude ) ;
3843 Mod . Log . Info ? . Write ( $ "CJMCN:T - calculated jumpHeat:'{ jumpHeat } ' from magnitude:'{ magnitude } . ") ;
3944
4045 Mod . Log . Info ? . Write ( $ "CJMCN:T - comparing heat: [jumpHeat:'{ jumpHeat } ' + currentHeat:'{ currentHeat } '] <= acceptableHeat:'{ acceptableHeat } . ") ;
41- if ( jumpHeat + ( float ) mech . CurrentHeat <= acceptableHeat ) {
46+ if ( jumpHeat + ( float ) mech . CurrentHeat <= acceptableHeat )
47+ {
4248
43- if ( stayInsideRegionGUID != null ) {
44- MapTerrainDataCell cellAt = ___unit . Combat . MapMetaData . GetCellAt ( candidatePos ) ;
45- if ( cellAt != null ) {
49+ if ( stayInsideRegionGUID != null )
50+ {
51+ MapTerrainDataCell cellAt = nodeContextUnit . Combat . MapMetaData . GetCellAt ( candidatePos ) ;
52+ if ( cellAt != null )
53+ {
4654 MapEncounterLayerDataCell mapEncounterLayerDataCell = cellAt . MapEncounterLayerDataCell ;
47- if ( mapEncounterLayerDataCell != null
48- && mapEncounterLayerDataCell . regionGuidList != null
49- && ! mapEncounterLayerDataCell . regionGuidList . Contains ( stayInsideRegionGUID ) ) {
55+ if ( mapEncounterLayerDataCell != null
56+ && mapEncounterLayerDataCell . regionGuidList != null
57+ && ! mapEncounterLayerDataCell . regionGuidList . Contains ( stayInsideRegionGUID ) )
58+ {
5059
5160 // Skip this loop iteration if
5261 Mod . Log . Info ? . Write ( $ "CJMCN:T - candidate outside of constraint region, ignoring.") ;
@@ -56,7 +65,7 @@ static void Postfix(ref BehaviorTreeResults __result, string ___name, BehaviorTr
5665 }
5766
5867 Mod . Log . Info ? . Write ( $ "CJMCN:T - adding candidate position:{ candidatePos } ") ;
59- ___tree . movementCandidateLocations . Add ( new MoveDestination ( sampledPathNodes [ i ] , MoveType . Jumping ) ) ;
68+ nodeBehaviorTree . movementCandidateLocations . Add ( new MoveDestination ( sampledPathNodes [ i ] , MoveType . Jumping ) ) ;
6069 }
6170 }
6271
0 commit comments