private static void CarryExtended(List <KeyValuePair <GameObject, int> > dropItems, CharacterDrop.Drop drop, CharacterDrop characterDrop) { try { if (dropItems is null) { #if DEBUG Log.LogWarning("Unable to carry drop due to dropitems being null."); #endif } if (drop is null) { #if DEBUG Log.LogWarning($"Unable to carry drop due to being null for {characterDrop}."); #endif return; } var extended = DropExtended.GetExtension(drop); if (extended is not null && dropItems is not null) { #if DEBUG Log.LogDebug($"Carrying configs for drop {extended.Config.SectionKey}:{characterDrop.GetHashCode()}"); Log.LogDebug($"Carrying configs for drop {drop.m_prefab.name}"); #endif TempDropListCache.SetDrop(characterDrop, dropItems.Count - 1, extended); } #if DEBUG else if (dropItems is null) { Log.LogDebug("Disregard. No items to carry"); //Log.LogDebug($"Carrying configs for drop {drop.m_prefab.name}"); } else if (extended is null) { Log.LogDebug($"Disregard. No config to carry for item {drop}:{(drop.m_prefab.IsNull() ? "" : drop.m_prefab.name)}"); } #endif }
private static void MoveConfigReferenceFromComponentToDrop(CharacterDrop __instance, List <KeyValuePair <GameObject, int> > __result) { try { var instanceReferences = TempDropListCache.GetDrops(__instance); if (instanceReferences is not null) { //Re-associate result with configs. foreach (var reference in instanceReferences.ConfigByIndex) { TempDropListCache.SetDrop(__result, reference.Key, reference.Value); } } } catch (Exception e) { Log.LogWarning("Error while attempting to keep track of drops.", e); } }
private static void LoadConfigReferences(ZDO zdo, List <KeyValuePair <GameObject, int> > dropList) { try { #if DEBUG Log.LogDebug($"Unpacking config references for zdo {zdo.m_uid}"); #endif if (dropList is null) { #if DEBUG Log.LogDebug($"Drop list is empty. Skipping unpacking of zdo {zdo.m_uid}"); #endif return; } var serialized = zdo.GetByteArray(ZDOKey); if (serialized is null) { #if DEBUG Log.LogDebug($"Found nothing to unpack for zdo {zdo.m_uid}"); #endif return; } using (MemoryStream memStream = new MemoryStream(serialized)) { BinaryFormatter binaryFormatter = new BinaryFormatter(); var responseObject = binaryFormatter.Deserialize(memStream); if (responseObject is List <DropConfig> configPackage) { #if DEBUG Log.LogDebug($"Deserialized config package for zdo {zdo.m_uid}"); Log.LogDebug($"\t" + configPackage.Join(x => $"{x.Index}:{x.ConfigKey}")); #endif foreach (var entry in configPackage) { var configSections = entry.ConfigKey.SplitBy('.'); if (configSections.Count != 2) { Log.LogWarning($"Incorrect Drop That config section header '{entry.ConfigKey}' for zdo {zdo.m_uid}"); return; } if (entry.IsList) { if (ConfigurationManager.CharacterDropLists.TryGet(configSections[0], out CharacterDropListConfiguration listConfig)) { if (listConfig.TryGet(configSections[1], out CharacterDropItemConfiguration itemConfig)) { TempDropListCache.SetDrop(dropList, entry.Index, new DropExtended { Config = itemConfig, }); } } } else if (ConfigurationManager.CharacterDropConfigs.TryGet(configSections[0], out CharacterDropMobConfiguration mobConfig)) { if (mobConfig.TryGet(configSections[1], out CharacterDropItemConfiguration itemConfig)) { TempDropListCache.SetDrop(dropList, entry.Index, new DropExtended { Config = itemConfig, }); } } } } } } catch (Exception e) { Log.LogError("Error while attempting to attach and apply configurations to items.", e); } }