public static void UpdateCache() // Run this in a Modworld that is NOT the target of a subworld to update, can use check to make sure you aren't in subworlds { mod = SGAmod.Instance; if (!SubworldCache.postCacheFields || SubworldCache.cache.Count < 1) { return; } for (int i = 0; i < SubworldCache.cache.Count; i += 1) { SubworldCacheClass cachee = SubworldCache.cache[i]; SGAmod.Instance.Logger.Debug("Mod: " + mod.GetType().Name + " World: " + cachee.modwld + " bool: " + cachee.mybool); Type modwld = mod.GetModWorld(cachee.modwld).GetType(); FieldInfo fild = modwld.GetField(cachee.field, BindingFlags.Static | BindingFlags.Public); if (cachee.myint != null) { fild.SetValue(mod.GetModWorld(cachee.modwld), (int)cachee.myint); } else { fild.SetValue(mod.GetModWorld(cachee.modwld), (bool)cachee.mybool); } } SubworldCache.postCacheFields = false; cache.Clear(); }
//Run this alongside code that marks your boss as downed, do make sure to run it AFTER you set the bool/int so you know, it gets set to what it should be //SubworldCache.AddCache("SGAmod", "SGAWorld", "downedSharkvern", SGAWorld.downedBoss); example public static bool AddCache(string mod, string modWorld, string field, bool?mybool, int?myint) { SubworldCacheClass newone = new SubworldCacheClass(mod, modWorld, field, mybool, myint); SubworldCache.cache.Add(newone); SubworldCache.postCacheFields = true; SGAmod.Instance.Logger.Debug("Added---- Mod: " + mod.GetType().Name + " World: " + modWorld + " bool: " + mybool); return(true); }