1+ using System ;
12using System . Collections . Generic ;
23using System . Linq ;
34using System . Reflection ;
@@ -20,6 +21,13 @@ public static class QuestUtils
2021 private static FieldInfo _playerQuestControllerField = AccessTools . Field ( typeof ( Player ) , "_questController" ) ;
2122 private static PropertyInfo _questControllerQuestsProperty = AccessTools . Property ( typeof ( AbstractQuestControllerClass ) , "Quests" ) ;
2223 private static FieldInfo _questsListField = AccessTools . Field ( _questControllerQuestsProperty . PropertyType , "list_1" ) ;
24+
25+ private static MethodInfo _questsGetConditionalMethod = AccessTools . Method ( _questControllerQuestsProperty . PropertyType , "GetConditional" , new Type [ ] { typeof ( string ) } ) ;
26+
27+ private static Type _questType = _questControllerQuestsProperty . PropertyType . BaseType . GetGenericArguments ( ) [ 0 ] ;
28+ private static PropertyInfo _questNecessaryConditions = AccessTools . Property ( _questType , "NecessaryConditions" ) ;
29+ private static MethodInfo _questIsConditionDone = AccessTools . Method ( _questType , "IsConditionDone" ) ;
30+
2331 private static FieldInfo _conditionCounterTemplateField = AccessTools . Field ( typeof ( ConditionCounterCreator ) , "_templateConditions" ) ;
2432 private static FieldInfo _templateConditionsConditionsField = AccessTools . Field ( _conditionCounterTemplateField . FieldType , "Conditions" ) ;
2533 private static FieldInfo _conditionListField = AccessTools . Field ( _templateConditionsConditionsField . FieldType , "list_0" ) ;
@@ -82,17 +90,17 @@ internal static IEnumerable<MapMarkerDef> GetMarkerDefsForPlayer(Player player)
8290 var quests = GetIncompleteQuests ( player ) ;
8391 foreach ( var quest in quests )
8492 {
85- markers . AddRange ( GetMarkerDefsForQuest ( quest ) ) ;
93+ markers . AddRange ( GetMarkerDefsForQuest ( player , quest ) ) ;
8694 }
8795
8896 return markers ;
8997 }
9098
91- internal static IEnumerable < MapMarkerDef > GetMarkerDefsForQuest ( QuestDataClass quest )
99+ internal static IEnumerable < MapMarkerDef > GetMarkerDefsForQuest ( Player player , QuestDataClass quest )
92100 {
93101 var markers = new List < MapMarkerDef > ( ) ;
94102
95- var conditions = GetIncompleteQuestConditions ( quest ) ;
103+ var conditions = GetIncompleteQuestConditions ( player , quest ) ;
96104 foreach ( var condition in conditions )
97105 {
98106 var questName = quest . Template . NameLocaleKey . BSGLocalized ( ) ;
@@ -242,7 +250,7 @@ private static IEnumerable<Vector3> GetPositionsForQuestItems(IEnumerable<string
242250 }
243251 }
244252
245- internal static IEnumerable < Condition > GetIncompleteQuestConditions ( QuestDataClass quest )
253+ private static IEnumerable < Condition > GetIncompleteQuestConditions ( Player player , QuestDataClass quest )
246254 {
247255 // TODO: Template.Conditions is a GClass reference
248256 if ( quest ? . Template ? . Conditions == null )
@@ -267,7 +275,7 @@ internal static IEnumerable<Condition> GetIncompleteQuestConditions(QuestDataCla
267275 }
268276
269277 // filter out completed conditions
270- if ( quest . CompletedConditions . Contains ( condition . id ) )
278+ if ( IsConditionCompleted ( player , quest , condition ) )
271279 {
272280 continue ;
273281 }
@@ -276,7 +284,7 @@ internal static IEnumerable<Condition> GetIncompleteQuestConditions(QuestDataCla
276284 }
277285 }
278286
279- internal static IEnumerable < QuestDataClass > GetIncompleteQuests ( Player player )
287+ private static IEnumerable < QuestDataClass > GetIncompleteQuests ( Player player )
280288 {
281289 var questController = _playerQuestControllerField . GetValue ( player ) ;
282290 if ( questController == null )
@@ -322,6 +330,47 @@ internal static IEnumerable<QuestDataClass> GetIncompleteQuests(Player player)
322330 }
323331 }
324332
333+ private static bool IsConditionCompleted ( Player player , QuestDataClass questData , Condition condition )
334+ {
335+ if ( ! questData . CompletedConditions . Contains ( condition . id ) )
336+ {
337+ return false ;
338+ }
339+
340+ var questController = _playerQuestControllerField . GetValue ( player ) ;
341+ if ( questController == null )
342+ {
343+ return false ;
344+ }
345+
346+ var quests = _questControllerQuestsProperty . GetValue ( questController ) ;
347+ if ( quests == null )
348+ {
349+ return false ;
350+ }
351+
352+ var quest = _questsGetConditionalMethod . Invoke ( quests , new object [ ] { questData . Id } ) ;
353+ if ( quest == null )
354+ {
355+ return false ;
356+ }
357+
358+ var necessaryConditions = _questNecessaryConditions . GetValue ( quest ) as IEnumerable < Condition > ;
359+ if ( necessaryConditions == null )
360+ {
361+ return false ;
362+ }
363+
364+ var matchingCondition = necessaryConditions . FirstOrDefault ( c => c . id == condition . id ) ;
365+ if ( matchingCondition == null )
366+ {
367+ return false ;
368+ }
369+
370+ var isComplete = ( bool ) _questIsConditionDone . Invoke ( quest , new object [ ] { matchingCondition } ) ;
371+ return isComplete ;
372+ }
373+
325374 private static IEnumerable < TriggerWithId > GetZoneTriggers ( this IEnumerable < TriggerWithId > triggerWithIds , string zoneId )
326375 {
327376 return triggerWithIds . Where ( t => t . Id == zoneId ) ;
0 commit comments