예제 #1
0
        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>());
            }
        }
예제 #2
0
        private static void ModifyDrop(GameObject drop)
        {
            try
            {
                DropTemplate template = DropTemplateCache.GetTemplate(_currentWrapped);

                if (template is null)
                {
                    return;
                }

                DropModificationContext context = new DropModificationContext(drop, template);

                foreach (var modifier in template.Modifiers)
                {
                    try
                    {
                        modifier.Modify(context);
                    }
                    catch (Exception e)
                    {
                        Log.LogError($"Error while attempting to apply modifier '{modifier.GetType().Name}' to drop '{drop}'. Skipping modifier.", e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.LogError($"Error while preparing to modify drop '{drop}'. Skipping modifiers.", e);
            }

            _currentWrapped = null;
        }
예제 #3
0
        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);
        }
예제 #4
0
        private static ItemDrop.ItemData ModifyContainerItem(ItemDrop.ItemData item, Container container)
        {
            try
            {
                // Make sure item has its prefab unwrapped.
                item.m_dropPrefab = item.m_dropPrefab.Unwrap();

                DropTemplate template = DropTemplateCache.GetTemplate(item);

                if (template is null)
                {
#if DEBUG
                    Log.LogDebug($"Failed to find template for {item?.m_dropPrefab}");
#endif
                    return(item);
                }

                foreach (var modifier in template.Modifiers)
                {
                    try
                    {
#if DEBUG
                        Log.LogTrace($"Applying modifier '{modifier.GetType().Name}'");
#endif

                        modifier.Modify(ref item, template, container.transform.position);
                    }
                    catch (Exception e)
                    {
                        Log.LogError($"Error while attempting to apply modifier '{modifier.GetType().Name}' to drop '{item.m_dropPrefab.name}'. Skipping modifier.", e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.LogError($"Error while preparing to modify drop '{item.m_dropPrefab.name}'. Skipping modifiers.", e);
            }

            return(item);
        }