public DropModificationContext(GameObject drop, DropTemplate template) { Drop = drop; Template = template; ItemDrop = new(drop); }
private static IEnumerable <ItemDrop.ItemData> ConvertTemplateToItem(DropTemplate template) { try { ItemDrop.ItemData itemData = template.Drop.m_item.GetComponent <ItemDrop>().m_itemData.Clone(); int minAmount = Math.Max(1, template.Drop.m_stackMin); int maxAmount = Math.Min(itemData.m_shared.m_maxStackSize, template.Drop.m_stackMax) + 1; itemData.m_dropPrefab = template.Drop.m_item.Wrap(); itemData.m_stack = UnityEngine.Random.Range(minAmount, maxAmount); itemData.m_quality = template.Config?.SetQualityLevel ?? 1; itemData.m_durability = (template.Config?.SetDurability ?? -1f) >= 0 ? template.Config.SetDurability : itemData.m_durability; //Use whatever is default // Store reference to both wrapped prefab and ItemData object, to ensure we can keep track of it. DropTemplateCache.RegisterTemplate(itemData, template); DropTemplateCache.RegisterTemplate(itemData.m_dropPrefab, template); Item[0] = itemData; return(Item); } catch (Exception e) { Log.LogError("Error while attempting to prepare new item data", e); return(Enumerable.Empty <ItemDrop.ItemData>()); } }
private static IEnumerable <GameObject> ConvertTemplateToDrop(DropTemplate template) { var drop = template.Drop.m_item.Wrap(); DropTemplateCache.RegisterTemplate(drop, template); int minAmount = Math.Max(1, template.Drop.m_stackMin); int maxAmount = template.Drop.m_stackMax + 1; int amount = UnityEngine.Random.Range(minAmount, maxAmount); GameObject[] result = new GameObject[amount]; for (int i = 0; i < amount; ++i) { result[i] = drop; } return(result); }