static bool Prefix(Thing t) { if (Multiplayer.Client == null || t.Map == null) { return(true); } AsyncTimeComp comp = t.Map.AsyncTime(); TickerType tickerType = t.def.tickerType; if (tickerType == TickerType.Normal) { comp.tickListNormal.RegisterThing(t); } else if (tickerType == TickerType.Rare) { comp.tickListRare.RegisterThing(t); } else if (tickerType == TickerType.Long) { comp.tickListLong.RegisterThing(t); } return(false); }
/// <summary> /// Runs QuestTick() on all quests cached for a specific map /// </summary> /// <param name="mapAsyncTimeComp">Map to tick Quests for</param> public static void TickMapQuests(AsyncTimeComp mapAsyncTimeComp) { if (mapQuestsCache.TryGetValue(mapAsyncTimeComp, out var quests)) { TickQuests(quests); } }
/// <summary> /// Tries to remove Map from cache, then moves all Quests cached to that map to WorldQuestsCache /// </summary> /// <param name="mapAsyncTimeComp">Map to remove</param> /// <returns>If map is found in cache</returns> public static bool TryRemoveCachedMap(AsyncTimeComp mapAsyncTimeComp) { if (mapQuestsCache.TryGetValue(mapAsyncTimeComp, out var quests)) { worldQuestsCache.AddRange(quests); return(mapQuestsCache.Remove(mapAsyncTimeComp)); } return(false); }
static void Prefix(Quest __instance, ref AsyncTimeComp __state) { if (Multiplayer.Client == null) { return; } if (!Multiplayer.GameComp.asyncTime) { return; } __state = MultiplayerAsyncQuest.TryGetCachedQuestMap(__instance); __state?.PreContext(); }
/// <summary> /// Attempts to update or insert a new cache for a Map and Quest, will always attempt to remove the quest before adding in case it existed on another map. /// </summary> /// <param name="mapAsyncTimeComp">Map that will hold the quest</param> /// <param name="quest">Quest for the map</param> private static void UpsertQuestMap(AsyncTimeComp mapAsyncTimeComp, Quest quest) { //if there is more then one map with the quest something went wrong - removes quest object in case it changes map TryRemoveCachedQuest(quest); if (mapQuestsCache.TryGetValue(mapAsyncTimeComp, out var quests)) { quests.Add(quest); } else { mapQuestsCache[mapAsyncTimeComp] = new List <Quest> { quest }; } }
static void Prefix(Quest __instance, ref AsyncTimeComp __state) { if (Multiplayer.Client == null) { return; } //Make sure quest is accepted and async time is enabled and there are parts to this quest if (__instance.State != QuestState.NotYetAccepted || !Multiplayer.GameComp.asyncTime || __instance.parts == null) { return; } __state = MultiplayerAsyncQuest.CacheQuest(__instance); __state?.PreContext(); }
static void Postfix(Map __instance) { if (Multiplayer.Client == null) { return; } var asyncTime = __instance.AsyncTime(); var comp = __instance.MpComp(); if (Scribe.mode == LoadSaveMode.LoadingVars || Scribe.mode == LoadSaveMode.Saving) { Scribe_Deep.Look(ref asyncTime, "mpAsyncTime", __instance); Scribe_Deep.Look(ref comp, "mpMapComp", __instance); } if (Scribe.mode == LoadSaveMode.LoadingVars) { if (asyncTime == null) { Log.Error($"{typeof(AsyncTimeComp)} missing during loading"); // This is just so the game doesn't completely freeze asyncTime = new AsyncTimeComp(__instance); } Multiplayer.game.asyncTimeComps.Add(asyncTime); if (comp == null) { Log.Error($"{typeof(MultiplayerMapComp)} missing during loading"); comp = new MultiplayerMapComp(__instance); } Multiplayer.game.mapComps.Add(comp); } }
static void Postfix(AsyncTimeComp __state) => __state?.PostContext();