private void OnTreeChopped(BaseEntity treeEntity, BasePlayer player)
        {
            try
            {
                var hitInfo = _hitInfos.FirstOrDefault(e => e.TreeInstanceId == treeEntity.GetInstanceID());
                if (hitInfo != null)
                {
                    _hitInfos.Remove(hitInfo);
                }

                var treeConfig = _config.Trees.FirstOrDefault(e => e.Prefab == treeEntity.PrefabName);

                if (treeConfig == null)
                {
                    return;
                }

                if (!permission.UserHasPermission(player.UserIDString, PermGather))
                {
                    return;
                }

                if (Random.Range(0, 1000) <= _config.GatherSaplingChance * 1000)
                {
                    var gatherAmount = Random.Range(_config.MinSaplingGather, _config.MaxSaplingGather + 1);
                    for (var i = 0; i < gatherAmount; i++)
                    {
                        if (_config.RandomizeSaplingGather)
                        {
                            var treesForEnv =
                                _config.Trees.FindAll(e => e.Env == treeConfig.Env && e.Type == treeConfig.Type);
                            treeConfig = treesForEnv.ElementAt(Random.Range(0, treesForEnv.Count() - 1));
                        }

                        var item = CreateItem(BuildItemName(treeConfig));

                        if (item != null)
                        {
                            player.GiveItem(item);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Puts(e.ToString());
            }
        }
Пример #2
0
 /// <summary>
 /// Returns a random value from an array of strings
 /// </summary>
 /// <param name="array"></param>
 /// <returns></returns>
 public static string Sample(this string[] array) => array[Random.Range(0, array.Length)];
Пример #3
0
 /// <summary>
 /// Returns a random value from an array of integers
 /// </summary>
 /// <param name="array"></param>
 /// <returns></returns>
 public static int Sample(this int[] array) => array[Random.Range(0, array.Length)];
Пример #4
0
 /// <summary>
 /// Returns a random value from an array of objects
 /// </summary>
 /// <param name="array"></param>
 /// <returns></returns>
 public static object Sample(this object[] array) => array[Random.Range(0, array.Length)];